From 36fbefee59d09a189615af8825f599258c95613c Mon Sep 17 00:00:00 2001 From: Luis Guzman Date: Fri, 21 Aug 2026 04:20:51 -0600 Subject: [PATCH 1/3] ADFA-4896 feat(maps): pause/resume in the FQR download overlay Add a Pause/Resume control to the FQR maps overlay, driving the REST job's pause/resume endpoints (ADFA-4894). MapsRegionClient gains pause()/resume(), a 'paused' poll case, and an onPaused() listener hook; FqrController shows the button next to Cancel, flips its label on state, and renders "Paused - X%". Reuses the existing ADFA-5119 strings, so no new i18n. --- .../controller/redesign/FqrController.java | 41 ++++++++++++++++++- .../controller/redesign/MapsRegionClient.java | 31 +++++++++++++- 2 files changed, 70 insertions(+), 2 deletions(-) diff --git a/controller/app/src/main/java/org/iiab/controller/redesign/FqrController.java b/controller/app/src/main/java/org/iiab/controller/redesign/FqrController.java index 99308ab6a..b5b7e3d45 100644 --- a/controller/app/src/main/java/org/iiab/controller/redesign/FqrController.java +++ b/controller/app/src/main/java/org/iiab/controller/redesign/FqrController.java @@ -90,6 +90,10 @@ public final class FqrController { private TextView overlayPct, overlayTitle; private TextView overlayMin; private boolean overlayMinimized = false; + // ADFA-4894: the Pause/Resume control on the overlay. overlayPaused is the last state the poll + // reported, so the button toggles between pause() and resume(). + private com.google.android.material.button.MaterialButton overlayPause; + private boolean overlayPaused = false; // Delete: unified list bottom-sheet (~55%) fed by the manual trash tool. private View deleteSheet; @@ -357,7 +361,23 @@ private void startDownload(String name) { if (box == null) return; showOverlay(name, pendingArchive); client.download(name, box, new MapsRegionClient.DownloadListener() { - @Override public void onProgress(int percent, long speed) { updateOverlay(percent, speed); } + @Override public void onProgress(int percent, long speed) { + if (overlayPaused) { // resumed: back to normal + overlayPaused = false; + if (overlayPause != null) overlayPause.setText(R.string.k2go_dl_pause); + } + updateOverlay(percent, speed); + } + @Override public void onPaused(int percent) { + overlayPaused = true; + if (overlayPause != null) overlayPause.setText(R.string.k2go_dl_resume); + if (overlayPct != null) overlayPct.setText(str(R.string.k2go_dl_paused_notif) + + (percent >= 0 ? " · " + str(R.string.k2go_fqr_percent, percent) : "")); + if (overlayBar != null && percent >= 0) { + if (overlayBar.isIndeterminate()) setBarMode(false); + overlayBar.setProgressCompat(percent, true); + } + } @Override public void onDone() { updateOverlay(100, 0); if (overlayTitle != null) overlayTitle.setText(R.string.k2go_fqr_region_added); // may be gone if hidden @@ -416,6 +436,14 @@ private void showOverlay(String name, long sizeBytes) { overlayPct.setText(R.string.k2go_fqr_starting); M3Text.apply(overlayPct, com.google.android.material.R.style.TextAppearance_Material3_BodyMedium, cOnSurfaceVariant); row.addView(overlayPct, new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, 1f)); + // ADFA-4894: Pause/Resume beside Cancel. The button label follows the reported state; the tap + // fires the matching verb and the poll (onPaused/onProgress) is the source of truth. + overlayPaused = false; + overlayPause = new MaterialButton(themed, null, + com.google.android.material.R.attr.materialButtonOutlinedStyle); + overlayPause.setText(R.string.k2go_dl_pause); + overlayPause.setOnClickListener(v -> togglePause()); + row.addView(overlayPause); MaterialButton cancel = new MaterialButton(themed, null, com.google.android.material.R.attr.materialButtonOutlinedStyle); cancel.setText(R.string.k2go_cancel); @@ -432,6 +460,15 @@ private void showOverlay(String name, long sizeBytes) { activity.addContentView(overlay, params); } + /** ADFA-4894: fire pause or resume based on the last reported state; the poll callbacks + * (onPaused / onProgress) then reconcile the label and the status line. The optimistic flip + * here just gives instant feedback on the tap. */ + private void togglePause() { + if (overlayPaused) client.resume(); else client.pause(); + overlayPaused = !overlayPaused; + if (overlayPause != null) overlayPause.setText(overlayPaused ? R.string.k2go_dl_resume : R.string.k2go_dl_pause); + } + private void toggleMinimize() { if (overlay == null) return; overlayMinimized = !overlayMinimized; @@ -480,7 +517,9 @@ private void hideOverlay() { ViewGroup parent = (ViewGroup) overlay.getParent(); if (parent != null) parent.removeView(overlay); overlay = null; overlayBar = null; overlayPct = null; overlayTitle = null; overlayMin = null; + overlayPause = null; overlayMinimized = false; + overlayPaused = false; } // ---- Delete: unified list bottom-sheet + manual capture ---------------------------------- diff --git a/controller/app/src/main/java/org/iiab/controller/redesign/MapsRegionClient.java b/controller/app/src/main/java/org/iiab/controller/redesign/MapsRegionClient.java index 29613f0a7..c196d5a53 100644 --- a/controller/app/src/main/java/org/iiab/controller/redesign/MapsRegionClient.java +++ b/controller/app/src/main/java/org/iiab/controller/redesign/MapsRegionClient.java @@ -11,7 +11,8 @@ * POST /api/maps/download {items:[{name,box}]} -> { id, ... } * GET /api/maps/jobs/:id -> { phase, percent, detail, error } * POST /api/maps/jobs/:id/cancel -> { ok:true } - * phase is one of: queued|downloading|indexing|processing|done|error|canceled. + * POST /api/maps/jobs/:id/{pause,resume} -> { ok:true } | 409 (ADFA-4894) + * phase is one of: queued|downloading|indexing|processing|paused|done|error|canceled. * Only reachable on-device (localhost); the box denies /api to remote clients. * ============================================================================ */ @@ -47,6 +48,9 @@ public interface DownloadListener { void onProgress(int percent, long speedBytesPerSec); // percent may be -1; speed 0 if unknown void onDone(); void onError(String message); + /** ADFA-4894: the job is paused (partial kept on the box); resume() continues it. Default + * no-op so existing callers keep compiling; the overlay overrides it to show the control. */ + default void onPaused(int percent) {} } private static final String BASE = BoxEndpoints.API + "/maps"; @@ -114,6 +118,11 @@ private void pollOnce() { case "canceled": fail("canceled"); return; + case "paused": { // ADFA-4894: stopped-but-resumable; report it and keep polling + final int pp = percent; + deliver(() -> dl.onPaused(pp)); + break; + } default: { // queued / downloading / processing: report progress if known final int p = percent; final long sp = j.optLong("speed", 0L); @@ -182,6 +191,26 @@ public void cancel() { teardown(); } + /** ADFA-4894: pause the in-flight download (keeps the partial). Polling keeps running, so the + * next poll reports 'paused' via onPaused(); resume() picks it back up. */ + public void pause() { + final String id = jobId; + if (id == null || id.isEmpty()) return; + AppExecutors.get().io().execute(() -> { + try { httpJson("POST", BASE + "/jobs/" + id + "/pause", null); } catch (Exception ignore) { /* best effort */ } + }); + } + + /** ADFA-4894: resume a paused download; the server continues it via --continue, and the poll + * reports progress again via onProgress(). */ + public void resume() { + final String id = jobId; + if (id == null || id.isEmpty()) return; + AppExecutors.get().io().execute(() -> { + try { httpJson("POST", BASE + "/jobs/" + id + "/resume", null); } catch (Exception ignore) { /* best effort */ } + }); + } + private void done() { if (finished) return; finished = true; From cfe0dd123ebdfe34fb3b4a174e486f15210cc49f Mon Sep 17 00:00:00 2001 From: Luis Guzman Date: Fri, 21 Aug 2026 06:09:04 -0600 Subject: [PATCH 2/3] ADFA-4896 fix(maps): label the FQR control Stop/Retry, not Pause/Resume There is no maps checkpoint, so resume re-extracts from 0 -- calling it Pause/Resume implied a continuation that doesn't happen. Relabel to Stop (running) -> Retry (stopped), with status "Stopped" (no percent, which would imply a resume point). Behavior and endpoints are unchanged; reuses existing translated strings (no new i18n). Real pause/continue would need changes to the upstream tile-extract.py (ADFA-4898). --- .../controller/redesign/FqrController.java | 62 +++++++++---------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/controller/app/src/main/java/org/iiab/controller/redesign/FqrController.java b/controller/app/src/main/java/org/iiab/controller/redesign/FqrController.java index b5b7e3d45..87c969ec4 100644 --- a/controller/app/src/main/java/org/iiab/controller/redesign/FqrController.java +++ b/controller/app/src/main/java/org/iiab/controller/redesign/FqrController.java @@ -90,10 +90,11 @@ public final class FqrController { private TextView overlayPct, overlayTitle; private TextView overlayMin; private boolean overlayMinimized = false; - // ADFA-4894: the Pause/Resume control on the overlay. overlayPaused is the last state the poll - // reported, so the button toggles between pause() and resume(). - private com.google.android.material.button.MaterialButton overlayPause; - private boolean overlayPaused = false; + // ADFA-4896: the Stop/Retry control on the overlay. It drives the server pause/resume endpoints, + // but there is no maps checkpoint yet (resume re-extracts from 0), so we present it honestly as + // Stop -> Retry, not Pause -> Resume. overlayStopped is the last state the poll reported. + private com.google.android.material.button.MaterialButton overlayStop; + private boolean overlayStopped = false; // Delete: unified list bottom-sheet (~55%) fed by the manual trash tool. private View deleteSheet; @@ -362,21 +363,19 @@ private void startDownload(String name) { showOverlay(name, pendingArchive); client.download(name, box, new MapsRegionClient.DownloadListener() { @Override public void onProgress(int percent, long speed) { - if (overlayPaused) { // resumed: back to normal - overlayPaused = false; - if (overlayPause != null) overlayPause.setText(R.string.k2go_dl_pause); + if (overlayStopped) { // retried/running again: back to normal + overlayStopped = false; + if (overlayStop != null) overlayStop.setText(R.string.k2go_clone_stop_confirm); } updateOverlay(percent, speed); } @Override public void onPaused(int percent) { - overlayPaused = true; - if (overlayPause != null) overlayPause.setText(R.string.k2go_dl_resume); - if (overlayPct != null) overlayPct.setText(str(R.string.k2go_dl_paused_notif) - + (percent >= 0 ? " · " + str(R.string.k2go_fqr_percent, percent) : "")); - if (overlayBar != null && percent >= 0) { - if (overlayBar.isIndeterminate()) setBarMode(false); - overlayBar.setProgressCompat(percent, true); - } + // Server phase is 'paused', but with no checkpoint this is a full stop: show "Stopped" + // and offer Retry (which re-extracts from 0). No percent -- it would imply a resume + // point that doesn't exist. + overlayStopped = true; + if (overlayStop != null) overlayStop.setText(R.string.k2go_dl_retry); + if (overlayPct != null) overlayPct.setText(R.string.k2go_card_stopped); } @Override public void onDone() { updateOverlay(100, 0); @@ -436,14 +435,14 @@ private void showOverlay(String name, long sizeBytes) { overlayPct.setText(R.string.k2go_fqr_starting); M3Text.apply(overlayPct, com.google.android.material.R.style.TextAppearance_Material3_BodyMedium, cOnSurfaceVariant); row.addView(overlayPct, new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, 1f)); - // ADFA-4894: Pause/Resume beside Cancel. The button label follows the reported state; the tap - // fires the matching verb and the poll (onPaused/onProgress) is the source of truth. - overlayPaused = false; - overlayPause = new MaterialButton(themed, null, + // ADFA-4896: Stop/Retry beside Cancel. The label follows the reported state; the tap fires the + // matching verb and the poll (onPaused/onProgress) is the source of truth. + overlayStopped = false; + overlayStop = new MaterialButton(themed, null, com.google.android.material.R.attr.materialButtonOutlinedStyle); - overlayPause.setText(R.string.k2go_dl_pause); - overlayPause.setOnClickListener(v -> togglePause()); - row.addView(overlayPause); + overlayStop.setText(R.string.k2go_clone_stop_confirm); + overlayStop.setOnClickListener(v -> toggleStop()); + row.addView(overlayStop); MaterialButton cancel = new MaterialButton(themed, null, com.google.android.material.R.attr.materialButtonOutlinedStyle); cancel.setText(R.string.k2go_cancel); @@ -460,13 +459,14 @@ private void showOverlay(String name, long sizeBytes) { activity.addContentView(overlay, params); } - /** ADFA-4894: fire pause or resume based on the last reported state; the poll callbacks - * (onPaused / onProgress) then reconcile the label and the status line. The optimistic flip - * here just gives instant feedback on the tap. */ - private void togglePause() { - if (overlayPaused) client.resume(); else client.pause(); - overlayPaused = !overlayPaused; - if (overlayPause != null) overlayPause.setText(overlayPaused ? R.string.k2go_dl_resume : R.string.k2go_dl_pause); + /** ADFA-4896: Stop the extract, or Retry (restart) a stopped one, based on the last reported + * state. Drives the server pause/resume endpoints — resume re-extracts from 0 (no maps + * checkpoint), which is why it reads as Retry, not Resume. The poll (onPaused/onProgress) + * reconciles; the optimistic flip here just gives instant feedback on the tap. */ + private void toggleStop() { + if (overlayStopped) client.resume(); else client.pause(); + overlayStopped = !overlayStopped; + if (overlayStop != null) overlayStop.setText(overlayStopped ? R.string.k2go_dl_retry : R.string.k2go_clone_stop_confirm); } private void toggleMinimize() { @@ -517,9 +517,9 @@ private void hideOverlay() { ViewGroup parent = (ViewGroup) overlay.getParent(); if (parent != null) parent.removeView(overlay); overlay = null; overlayBar = null; overlayPct = null; overlayTitle = null; overlayMin = null; - overlayPause = null; + overlayStop = null; overlayMinimized = false; - overlayPaused = false; + overlayStopped = false; } // ---- Delete: unified list bottom-sheet + manual capture ---------------------------------- From 2193f363e63928b60951ed441f882d2353176bbe Mon Sep 17 00:00:00 2001 From: Luis Guzman Date: Fri, 21 Aug 2026 07:14:58 -0600 Subject: [PATCH 3/3] ADFA-4896 fix(maps): remove Stop/Retry flicker; freeze bar when stopped Code-review follow-ups on the FQR control: - The optimistic label flip in toggleStop fought the poll, bouncing the button for ~1 cycle. The poll (onPaused/onProgress) is now the SOLE writer of the label/state; the tap only fires the verb and disables the button until the next poll confirms (re-enabled there). No more flicker. - onPaused freezes the progress bar (determinate) so it stops animating under "Stopped". --- .../controller/redesign/FqrController.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/controller/app/src/main/java/org/iiab/controller/redesign/FqrController.java b/controller/app/src/main/java/org/iiab/controller/redesign/FqrController.java index 87c969ec4..4e160185d 100644 --- a/controller/app/src/main/java/org/iiab/controller/redesign/FqrController.java +++ b/controller/app/src/main/java/org/iiab/controller/redesign/FqrController.java @@ -363,10 +363,11 @@ private void startDownload(String name) { showOverlay(name, pendingArchive); client.download(name, box, new MapsRegionClient.DownloadListener() { @Override public void onProgress(int percent, long speed) { - if (overlayStopped) { // retried/running again: back to normal + if (overlayStopped) { // retried/running again: back to Stop overlayStopped = false; if (overlayStop != null) overlayStop.setText(R.string.k2go_clone_stop_confirm); } + if (overlayStop != null) overlayStop.setEnabled(true); // re-enable after a Stop/Retry tap updateOverlay(percent, speed); } @Override public void onPaused(int percent) { @@ -374,8 +375,11 @@ private void startDownload(String name) { // and offer Retry (which re-extracts from 0). No percent -- it would imply a resume // point that doesn't exist. overlayStopped = true; - if (overlayStop != null) overlayStop.setText(R.string.k2go_dl_retry); + if (overlayStop != null) { overlayStop.setText(R.string.k2go_dl_retry); overlayStop.setEnabled(true); } if (overlayPct != null) overlayPct.setText(R.string.k2go_card_stopped); + // #2: freeze the bar (determinate, no animation) so it doesn't keep animating under "Stopped". + if (overlayBar != null && overlayBar.isIndeterminate()) setBarMode(false); + if (overlayBar != null && percent >= 0) overlayBar.setProgressCompat(percent, false); } @Override public void onDone() { updateOverlay(100, 0); @@ -459,14 +463,13 @@ private void showOverlay(String name, long sizeBytes) { activity.addContentView(overlay, params); } - /** ADFA-4896: Stop the extract, or Retry (restart) a stopped one, based on the last reported - * state. Drives the server pause/resume endpoints — resume re-extracts from 0 (no maps - * checkpoint), which is why it reads as Retry, not Resume. The poll (onPaused/onProgress) - * reconciles; the optimistic flip here just gives instant feedback on the tap. */ + /** ADFA-4896: fire Stop (server pause) or Retry (server resume — re-extracts from 0, no maps + * checkpoint). The poll (onPaused/onProgress) is the SOLE writer of the label/state; here we only + * fire the verb and disable the button until the next poll confirms, so the label never flickers + * between the tap and the server catching up. */ private void toggleStop() { + if (overlayStop != null) overlayStop.setEnabled(false); if (overlayStopped) client.resume(); else client.pause(); - overlayStopped = !overlayStopped; - if (overlayStop != null) overlayStop.setText(overlayStopped ? R.string.k2go_dl_retry : R.string.k2go_clone_stop_confirm); } private void toggleMinimize() {