diff --git a/controller/app/src/main/java/org/iiab/controller/kolibri/presentation/KolibriSeedingFragment.java b/controller/app/src/main/java/org/iiab/controller/kolibri/presentation/KolibriSeedingFragment.java index 3901ae669..c8f8ab359 100644 --- a/controller/app/src/main/java/org/iiab/controller/kolibri/presentation/KolibriSeedingFragment.java +++ b/controller/app/src/main/java/org/iiab/controller/kolibri/presentation/KolibriSeedingFragment.java @@ -68,6 +68,8 @@ public void onViewCreated(@NonNull View v, @Nullable Bundle savedInstanceState) detailView = v.findViewById(R.id.k2go_kseed_detail); bar = v.findViewById(R.id.k2go_kseed_bar); list = v.findViewById(R.id.k2go_kseed_list); + org.iiab.controller.util.ProgressVisuals.apply( + v, org.iiab.controller.system.domain.ContentType.COURSES); // ADFA-5074 footer = v.findViewById(R.id.k2go_kseed_footer); footerNote = v.findViewById(R.id.k2go_kseed_footer_note); done = v.findViewById(R.id.k2go_kseed_done); diff --git a/controller/app/src/main/java/org/iiab/controller/redesign/MapsPreparingFragment.java b/controller/app/src/main/java/org/iiab/controller/redesign/MapsPreparingFragment.java index 8992c20f7..d9d1a6258 100644 --- a/controller/app/src/main/java/org/iiab/controller/redesign/MapsPreparingFragment.java +++ b/controller/app/src/main/java/org/iiab/controller/redesign/MapsPreparingFragment.java @@ -127,6 +127,7 @@ && getActivity() instanceof SetupLibraryActivity // ADFA-4901: collapsible live log. The status line mirrors the latest line; expanding shows // the full terminal (LogRepository snapshot + live appends), auto-scrolled. logLabel = root.findViewById(R.id.k2go_prep_log_label); + org.iiab.controller.util.ProgressVisuals.apply(root, org.iiab.controller.system.domain.ContentType.MAPS); // ADFA-5074 logChevron = root.findViewById(R.id.k2go_prep_log_chevron); logScroll = root.findViewById(R.id.k2go_prep_log_scroll); logText = root.findViewById(R.id.k2go_prep_log_text); diff --git a/controller/app/src/main/java/org/iiab/controller/redesign/ModuleInstallFragment.java b/controller/app/src/main/java/org/iiab/controller/redesign/ModuleInstallFragment.java index 4977d7827..2eaffea12 100644 --- a/controller/app/src/main/java/org/iiab/controller/redesign/ModuleInstallFragment.java +++ b/controller/app/src/main/java/org/iiab/controller/redesign/ModuleInstallFragment.java @@ -68,6 +68,8 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c status = root.findViewById(R.id.k2go_modinst_status); logLabel = root.findViewById(R.id.k2go_modinst_log_label); + // ADFA-5074: the key is passed so a module that earns its own art can be matched. + org.iiab.controller.util.ProgressVisuals.applyForModule(root, key); logChevron = root.findViewById(R.id.k2go_modinst_log_chevron); logScroll = root.findViewById(R.id.k2go_modinst_log_scroll); logText = root.findViewById(R.id.k2go_modinst_log_text); diff --git a/controller/app/src/main/java/org/iiab/controller/redesign/ZimPreparingFragment.java b/controller/app/src/main/java/org/iiab/controller/redesign/ZimPreparingFragment.java index 0c1deb3b3..ad820b39d 100644 --- a/controller/app/src/main/java/org/iiab/controller/redesign/ZimPreparingFragment.java +++ b/controller/app/src/main/java/org/iiab/controller/redesign/ZimPreparingFragment.java @@ -76,6 +76,8 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c detail = root.findViewById(R.id.k2go_zprep_detail); bar = root.findViewById(R.id.k2go_zprep_bar); listv = root.findViewById(R.id.k2go_zprep_list); + // ADFA-5074: the shared animation block declares no asset; the rule picks it. + org.iiab.controller.util.ProgressVisuals.apply(root, org.iiab.controller.system.domain.ContentType.ZIM); runBgBtn = root.findViewById(R.id.k2go_zprep_run_bg); runBgBtn.setOnClickListener(v -> { diff --git a/controller/app/src/main/java/org/iiab/controller/system/domain/ProgressVisual.java b/controller/app/src/main/java/org/iiab/controller/system/domain/ProgressVisual.java new file mode 100644 index 000000000..3796aa13b --- /dev/null +++ b/controller/app/src/main/java/org/iiab/controller/system/domain/ProgressVisual.java @@ -0,0 +1,101 @@ +/* + * ============================================================================ + * Name : ProgressVisual.java + * Author : AppDevForAll + * Copyright : Copyright (c) 2026 AppDevForAll + * Description : Which animation a running operation gets, decided from what the + * operation is. Pure JVM, no Android (ADFA-5074). + * ============================================================================ + */ +package org.iiab.controller.system.domain; + +/** + * What the progress screen should be showing while an operation runs. + * + *

Why this is resolved rather than placed. The working animation lived in one + * fragment's layout — ZIM's — so Courses had none and Maps had none. Copying it into each + * layout would have recreated the drift this exists to remove: hand-kept copies that agree + * until someone edits one. Putting a single animation in the shared host instead would have + * traded that duplication for a lie: the art is a cloud sending data to the device, which is + * literal for ZIM, Books and Courses and false for Maps, an Ansible runrole building tiles + * with the server stopped. + * + *

So it is shared along the axis that already exists. The + * {@link Operation.ExecutionClass} decides: live work is a download, stopped work is a + * build. One rule, no per-type layout owning an animation. + * + *

Where a per-module exception goes. Inside {@link #forOperation}, as a case on + * the platform name before the class fallback. Nothing needs one today; the point + * of resolving rather than placing is that when something does, it is a line here and no + * layout is touched. + * + *

This enum names the intent, not a file. Which asset each intent maps to is a + * presentation concern, so this stays testable on a plain JVM. + */ +public enum ProgressVisual { + + /** Something is coming down from the network. The server does the transfer. */ + DOWNLOAD, + + /** + * Something is being built on the device, with the box stopped — a runrole. Deliberately + * mapped to the same asset as {@link #DOWNLOAD} for now: Maps wants art of its own and + * does not have it yet, and a placeholder beats a second copy. Changing that is one line + * in the presentation mapping. + */ + BUILD; + + /** + * @param op what is running; null answers {@link #DOWNLOAD}, the common case, rather + * than throwing at a screen that only wants something to draw + */ + public static ProgressVisual forOperation(Operation op) { + if (op == null) { + return DOWNLOAD; + } + // A per-platform exception would go here, on op.platform(), before the fallback. + return op.isLive() ? DOWNLOAD : BUILD; + } + + /** The visual for adding content of this type. */ + public static ProgressVisual forContent(ContentType type) { + return type == null ? DOWNLOAD : forOperation(type.operation()); + } + + /** The visual for installing a platform's app — a runrole, so always a build. */ + public static ProgressVisual forModuleInstall(String moduleKey) { + return forOperation(Operation.appInstall(moduleKey == null ? "" : moduleKey)); + } + + /** + * The visual for one of the progress index's row keys. + * + *

The keys are {@code "zim"}, {@code "books"}, {@code "kolibri"}, {@code "maps"} and + * {@code "mod:"} for a proot module. {@link ContentType} already owns the first + * four, so the prefix is parsed here rather than in presentation — and the parsing is + * the part that breaks quietly, so it is the part with a test. + * + *

An unrecognised key is treated as content, which is the case three of the four + * types are in. + */ + public static ProgressVisual forKey(String key) { + if (key == null) { + return DOWNLOAD; + } + if (key.startsWith(MODULE_PREFIX)) { + return forModuleInstall(key.substring(MODULE_PREFIX.length())); + } + return forContent(ContentType.byKey(key)); + } + + /** Prefix the progress index uses for a proot module row. */ + public static final String MODULE_PREFIX = "mod:"; + + // TODO(ADFA-5074): this model is deliberately incomplete. The app has four working + // animations — k2go_working_loop, k2go_backup_loop, k2go_restore_loop — and this enum + // names two. BackupJobFragment (ADFA-4961) already resolves its own from the mode, by + // the same principle: the layout declares no asset and the code decides from what the + // operation is. It was written first and is not folded in here because backup and + // restore are system operations rather than content, which is a wider change. Whoever + // extends this should extend that precedent rather than build a third mechanism. +} diff --git a/controller/app/src/main/java/org/iiab/controller/util/ProgressVisuals.java b/controller/app/src/main/java/org/iiab/controller/util/ProgressVisuals.java new file mode 100644 index 000000000..64214b006 --- /dev/null +++ b/controller/app/src/main/java/org/iiab/controller/util/ProgressVisuals.java @@ -0,0 +1,98 @@ +/* + * ============================================================================ + * Name : ProgressVisuals.java + * Author : AppDevForAll + * Copyright : Copyright (c) 2026 AppDevForAll + * Description : Turns a resolved ProgressVisual into the asset that plays it. + * The one place a file name appears (ADFA-5074). + * ============================================================================ + */ +package org.iiab.controller.util; + +import androidx.annotation.RawRes; + +import org.iiab.controller.R; +import org.iiab.controller.system.domain.ContentType; +import org.iiab.controller.system.domain.ProgressVisual; + +/** + * The Android half of the progress animation: which raw resource plays which intent, and + * how a progress row's key becomes an operation to ask about. + * + *

Kept apart from {@link ProgressVisual} so the rule — live work downloads, stopped work + * builds — stays unit-testable without a device, and so a file name appears exactly once in + * the app. + */ +public final class ProgressVisuals { + + private ProgressVisuals() { + } + + /** + * The asset for an intent. + * + *

{@code BUILD} deliberately plays the download art for now: Maps wants something of + * its own and does not have it yet, and a placeholder beats a second copy of the same + * file. Giving it one is this line, and no layout changes. + */ + @RawRes + public static int rawResFor(ProgressVisual visual) { + switch (visual) { + case BUILD: + case DOWNLOAD: + default: + return R.raw.k2go_working_loop; + } + } + + + /** The asset for one of the index's row keys, in one call. */ + @RawRes + public static int rawResForKey(String key) { + return rawResFor(ProgressVisual.forKey(key)); + } + + /** + * Loads the right animation into a card that included + * {@code view_k2go_working_anim}. + * + *

One line per card, and the only line any card needs: the block itself declares no + * asset, so nothing plays until this runs. That is deliberate — a layout that could show + * an animation on its own is a layout that can disagree with the rule. + * + * @param root the inflated card + * @param type what the card is adding; null falls back to the download art + */ + public static void apply(android.view.View root, ContentType type) { + if (root == null) { + return; + } + com.airbnb.lottie.LottieAnimationView anim = root.findViewById(R.id.k2go_working_anim); + if (anim == null) { + return; // a card that chose not to include the block + } + anim.setAnimation(rawResFor(ProgressVisual.forContent(type))); + anim.playAnimation(); + } + + /** + * The same, for a proot module install. + * + * @param moduleKey which module. Passed on rather than dropped: the per-platform + * exception in {@link ProgressVisual#forOperation} matches on the + * platform name, and a module is the likeliest thing to want art of + * its own — handing it an empty name would have made that hook + * unreachable from the one place it is for. + */ + public static void applyForModule(android.view.View root, String moduleKey) { + if (root == null) { + return; + } + com.airbnb.lottie.LottieAnimationView anim = root.findViewById(R.id.k2go_working_anim); + if (anim == null) { + return; + } + anim.setAnimation(rawResFor(ProgressVisual.forModuleInstall(moduleKey))); + anim.playAnimation(); + } +} diff --git a/controller/app/src/main/res/layout/fragment_k2go_kolibri_seeding.xml b/controller/app/src/main/res/layout/fragment_k2go_kolibri_seeding.xml index 6973e304d..7033ae582 100644 --- a/controller/app/src/main/res/layout/fragment_k2go_kolibri_seeding.xml +++ b/controller/app/src/main/res/layout/fragment_k2go_kolibri_seeding.xml @@ -45,6 +45,10 @@ android:textAppearance="?attr/textAppearanceBodyMedium" android:textColor="@color/k2go_muted" /> + + + - - - - - - - - - - - - - - - - - - - - - - + + - requires restating width and height. --> + - - - - - - - - - - - - - - - - - - - + android:layout_marginTop="16dp" /> - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/controller/app/src/test/java/org/iiab/controller/system/domain/ProgressVisualTest.java b/controller/app/src/test/java/org/iiab/controller/system/domain/ProgressVisualTest.java new file mode 100644 index 000000000..8dc3e7d44 --- /dev/null +++ b/controller/app/src/test/java/org/iiab/controller/system/domain/ProgressVisualTest.java @@ -0,0 +1,92 @@ +package org.iiab.controller.system.domain; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +/** + * Unit tests for {@link ProgressVisual} — which animation an operation gets, and why it is + * the execution class that decides rather than the content type. Pure JVM. + */ +public class ProgressVisualTest { + + @Test + public void whatDownloadsGetsTheDownloadArt() { + // ZIM, Books and Courses are all REST: the server pulls the bytes, and the cloud + // sending data to the device is literally what is happening. + assertEquals(ProgressVisual.DOWNLOAD, ProgressVisual.forContent(ContentType.ZIM)); + assertEquals(ProgressVisual.DOWNLOAD, ProgressVisual.forContent(ContentType.BOOKS)); + assertEquals(ProgressVisual.DOWNLOAD, ProgressVisual.forContent(ContentType.COURSES)); + } + + @Test + public void whatBuildsDoesNotClaimToBeDownloading() { + // Maps is a runrole assembling tiles with the box stopped. Showing it a download + // animation would describe something that is not happening — which is the reason + // this is resolved from the class instead of one asset being shared by all four. + assertEquals(ProgressVisual.BUILD, ProgressVisual.forContent(ContentType.MAPS)); + } + + @Test + public void installingAPlatformIsABuildWhateverItsContentIs() { + // The Courses app is a proot module while its channels are REST. The visual follows + // the operation in hand, not the platform's name. + assertEquals(ProgressVisual.BUILD, + ProgressVisual.forOperation(Operation.appInstall("kolibri"))); + assertEquals(ProgressVisual.DOWNLOAD, + ProgressVisual.forOperation(Operation.content("kolibri"))); + } + + @Test + public void replacingTheSystemIsABuild() { + assertEquals(ProgressVisual.BUILD, ProgressVisual.forOperation(Operation.system())); + } + + // ---- the row keys ------------------------------------------------------ + + @Test + public void theIndexRowKeysMapToTheRightVisual() { + assertEquals(ProgressVisual.DOWNLOAD, ProgressVisual.forKey("zim")); + assertEquals(ProgressVisual.DOWNLOAD, ProgressVisual.forKey("books")); + assertEquals(ProgressVisual.DOWNLOAD, ProgressVisual.forKey("kolibri")); + assertEquals(ProgressVisual.BUILD, ProgressVisual.forKey("maps")); + } + + @Test + public void aModuleRowIsABuildWhateverTheModuleIs() { + // "mod:" is how the index names a proot module row. The prefix is the part + // that breaks quietly — an off-by-one in the substring would silently classify + // every module as content and show it a download animation. + assertEquals(ProgressVisual.BUILD, ProgressVisual.forKey("mod:calibreweb")); + assertEquals(ProgressVisual.BUILD, ProgressVisual.forKey("mod:kolibri")); + assertEquals(ProgressVisual.BUILD, ProgressVisual.forKey("mod:")); + } + + @Test + public void anUnknownKeyIsTreatedAsContent() { + // Not a crash and not a build: three of the four types are downloads, so an + // unrecognised row draws the common case rather than claiming to build something. + assertEquals(ProgressVisual.DOWNLOAD, ProgressVisual.forKey("banana")); + assertEquals(ProgressVisual.DOWNLOAD, ProgressVisual.forKey("")); + assertEquals(ProgressVisual.DOWNLOAD, ProgressVisual.forKey(null)); + } + + @Test + public void aModuleKeyReachesThePerPlatformHook() { + // The reason forModuleInstall takes the name at all: the exception point in + // forOperation matches on platform(), so handing it an empty name would make the + // hook unreachable from the one place most likely to need it. + assertEquals("calibreweb", + Operation.appInstall("calibreweb").platform()); + assertEquals(ProgressVisual.BUILD, ProgressVisual.forModuleInstall("calibreweb")); + assertEquals(ProgressVisual.BUILD, ProgressVisual.forModuleInstall(null)); + } + + @Test + public void nothingToGoOnFallsBackToTheCommonCase() { + // A screen asking this only wants something to draw; refusing to answer would be + // worse than answering with the case three of the four types are in. + assertEquals(ProgressVisual.DOWNLOAD, ProgressVisual.forOperation(null)); + assertEquals(ProgressVisual.DOWNLOAD, ProgressVisual.forContent(null)); + } +} diff --git a/controller/docs/ADR-5061-rest-vs-proot-operation-model.md b/controller/docs/ADR-5061-rest-vs-proot-operation-model.md index e77f6ff15..21e38f77e 100644 --- a/controller/docs/ADR-5061-rest-vs-proot-operation-model.md +++ b/controller/docs/ADR-5061-rest-vs-proot-operation-model.md @@ -327,6 +327,32 @@ most expensive by the third platform. A is B done safely over time. in background" that Courses lacks while Courses has a terminal action and a retry-before-leaving note the others lack. **ADFA-5074 owns this.** + **The progress animation is resolved, not placed.** Today the Lottie + (`k2go_working_loop` — cloud sending data to the device) lives in + `fragment_k2go_zim_preparing.xml` and nowhere else, so Courses has none. Copying it + into the Courses layout would recreate exactly the drift this item exists to remove: + two hand-kept copies that agree until someone edits one. + + But "one animation for all four" would trade a duplication for a lie. That cloud is + literal for ZIM, Books and Courses — the server downloads. Maps is an Ansible + runrole building tiles with the server stopped, and it already has its own + collapsible log; a download animation over it would describe something that is not + happening. + + So it is shared along the axis that already exists: **the execution class decides**, + not the content type. The shape agreed with Luis (ADFA-5074): + - the domain answers *which visual* an operation gets — an enum (`DOWNLOAD` for + LIVE, `BUILD` for STOPPED), pure and unit-testable, with room for a per-module + override when one earns it; + - presentation maps that answer to a raw resource, in one place; + - the host reads it and puts it above the fragment slot, so no per-type layout owns + an animation and ZIM's copy goes away. + + For now `BUILD` deliberately resolves to the same file: Maps wants a different one + and does not have it yet, and shipping a placeholder beats shipping a second copy. + The point of the indirection is that changing it later is one line, and that a + module which turns out to need its own can have it without anyone touching a layout. + Also decide **which lifetime each piece of state gets**. Three mechanisms are in use and nothing says which is for what: a `ViewModel` (survives a configuration change only), a `SavedStateHandle` (also survives a process death, riding the task's instance state), and diff --git a/controller/docs/content-execution-order.svg b/controller/docs/content-execution-order.svg index da8e3e74b..6ef5c2704 100644 --- a/controller/docs/content-execution-order.svg +++ b/controller/docs/content-execution-order.svg @@ -1,4 +1,4 @@ - + Content installation — mechanism and order How the four content types install: which mechanism each uses, why they are serialised, where the server is stopped, and what is still unsolved. Companion to operation-model-roadmap.svg, which tracks ticket state rather than behaviour. Update when the behaviour changes, not when a ticket moves. @@ -30,7 +30,7 @@ - + Content installation — mechanism and order Four content types, two mechanisms. What runs when, what waits for what, and why. @@ -101,7 +101,7 @@ ZimConfirmFragment:94 · MapsChooseFragment:270 · KolibriConfirmFragment:211 — three readings, three moments, no total - + OPEN Five landings for one kind of work — owned by ADFA-5074 @@ -109,7 +109,8 @@ Get More: ZIM → ZimPreparingFragment inside SetupLibraryActivity · Books → the index, with a hint that jumps straight to the detail · Maps → the index list · Courses → KolibriSeedingFragment inside SetupLibraryActivity. The screens are NOT duplicated: SetupProgressActivity.openDetail() hosts those same fragments, with a fromIndex flag for the chrome. -What differs is the host — so Back walks out of a live download, a notification returns you elsewhere, and nothing opens the index at all. +What differs is the host, so Back still walks out of a live download and a notification returns you to a different screen than you left. +Closed already: the Home header opens the index (PR 1) · a finished session no longer gates anything (PR 2). Hosting is what remains. diff --git a/controller/docs/operation-model-roadmap.svg b/controller/docs/operation-model-roadmap.svg index 20e9124ff..88aad0369 100644 --- a/controller/docs/operation-model-roadmap.svg +++ b/controller/docs/operation-model-roadmap.svg @@ -135,7 +135,7 @@ Front door + re-entry (onNewIntent) A session gates only work in flight -Get More notices a platform arriving +Get More notices a platform arriving One host for every progress screen Do not close 4758 as superseded: the migration half