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..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 @@ -90,6 +90,11 @@ public final class FqrController { private TextView overlayPct, overlayTitle; private TextView overlayMin; private boolean overlayMinimized = 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; @@ -357,7 +362,25 @@ 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 (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) { + // 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); 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); if (overlayTitle != null) overlayTitle.setText(R.string.k2go_fqr_region_added); // may be gone if hidden @@ -416,6 +439,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-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); + 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); @@ -432,6 +463,15 @@ private void showOverlay(String name, long sizeBytes) { activity.addContentView(overlay, params); } + /** 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(); + } + private void toggleMinimize() { if (overlay == null) return; overlayMinimized = !overlayMinimized; @@ -480,7 +520,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; + overlayStop = null; overlayMinimized = false; + overlayStopped = 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;