Skip to content

Commit e1365fb

Browse files
K2GO-449 refactor(app): ModuleActions registry; drop per-module update-action ifs
ModuleActionSheet and ModuleDetailFragment no longer carry a per-module if for the installed update action (code_addons, code_assets): both read the action from a ModuleActions registry (label + icon + handler, keyed by module key). A new content module registers one entry instead of editing two shared UI files. Behavior-preserving; Forgejo's repos action stays special (status-gated). Static registry, no runtime state. compileStandardDebug clean.
1 parent 7a1c3af commit e1365fb

3 files changed

Lines changed: 73 additions & 30 deletions

File tree

‎controller/app/src/main/java/org/appdevforall/k2go/redesign/ModuleActionSheet.java‎

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -223,19 +223,13 @@ public static void show(Activity act, String endpoint, String title, int iconRes
223223
});
224224
});
225225
}
226-
// K2GO-99: an installed add-ons gallery offers a live refresh here (the module action
227-
// menu). No status gate (installed means there is a gallery); the shared flow gates
228-
// internet, then runs the refresh IN the sheet (it does NOT dismiss).
229-
if ("code_addons".equals(key)) {
230-
content.addView(row(ctx, R.drawable.ic_refresh,
231-
act.getString(R.string.k2go_code_addons_update), Emphasis.ACCENT, null, false,
232-
v -> org.appdevforall.k2go.addons.presentation.AddonsRefresh.start(act, v)));
233-
}
234-
// K2GO-437: an installed build-assets tree offers the same live refresh here.
235-
if ("code_assets".equals(key)) {
236-
content.addView(row(ctx, R.drawable.ic_refresh,
237-
act.getString(R.string.k2go_code_assets_update), Emphasis.ACCENT, null, false,
238-
v -> org.appdevforall.k2go.codeassets.presentation.CodeAssetsRefresh.start(act, v)));
226+
// K2GO-449: an installed content module's update action comes from the ModuleActions
227+
// registry (code_addons, code_assets, ...), so this sheet no longer carries one if per
228+
// module. Forgejo's repos action stays special above (status-gated).
229+
ModuleActions.InstalledAction ia = ModuleActions.installed(key);
230+
if (ia != null) {
231+
content.addView(row(ctx, ia.iconRes, act.getString(ia.labelRes),
232+
Emphasis.ACCENT, null, false, v -> ia.handler.run(act, v)));
239233
}
240234
break;
241235
case SCHEDULED: {
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* ============================================================================
3+
* Name : ModuleActions.java
4+
* Author : AppDevForAll
5+
* Copyright : Copyright (c) 2026 AppDevForAll
6+
* Description : K2GO-449. One place that declares a content module's "installed" action (the update
7+
* action shown once the module is installed), so ModuleActionSheet and
8+
* ModuleDetailFragment iterate it instead of each carrying a per-module if block. A new
9+
* content module registers an entry here; the shared UI files stop changing per module.
10+
* Static config only, no runtime state. Forgejo's repos action stays special for now (it
11+
* is status-gated / async), so it is not in this registry yet.
12+
* ============================================================================
13+
*/
14+
package org.appdevforall.k2go.redesign;
15+
16+
import android.app.Activity;
17+
import android.view.View;
18+
19+
import androidx.annotation.Nullable;
20+
21+
import org.appdevforall.k2go.R;
22+
23+
import java.util.HashMap;
24+
import java.util.Map;
25+
26+
public final class ModuleActions {
27+
28+
private ModuleActions() {}
29+
30+
/** Runs a module's installed action, anchored to a view (for the snackbar / inline progress). */
31+
public interface Handler { void run(Activity act, View anchor); }
32+
33+
/** The update action a module offers once installed: a labeled, iconed row that runs {@link #handler}. */
34+
public static final class InstalledAction {
35+
public final int labelRes;
36+
public final int iconRes;
37+
public final Handler handler;
38+
InstalledAction(int labelRes, int iconRes, Handler handler) {
39+
this.labelRes = labelRes; this.iconRes = iconRes; this.handler = handler;
40+
}
41+
}
42+
43+
// Keyed by the module's YAML key (ModuleCards.Card.key()).
44+
private static final Map<String, InstalledAction> INSTALLED = new HashMap<>();
45+
static {
46+
INSTALLED.put("code_addons", new InstalledAction(
47+
R.string.k2go_code_addons_update, R.drawable.ic_refresh,
48+
(act, v) -> org.appdevforall.k2go.addons.presentation.AddonsRefresh.start(act, v)));
49+
INSTALLED.put("code_assets", new InstalledAction(
50+
R.string.k2go_code_assets_update, R.drawable.ic_refresh,
51+
(act, v) -> org.appdevforall.k2go.codeassets.presentation.CodeAssetsRefresh.start(act, v)));
52+
}
53+
54+
/** The installed action for {@code key}, or null when the module has none (or is handled specially). */
55+
@Nullable
56+
public static InstalledAction installed(@Nullable String key) {
57+
return key == null ? null : INSTALLED.get(key);
58+
}
59+
}

‎controller/app/src/main/java/org/appdevforall/k2go/redesign/ModuleDetailFragment.java‎

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,6 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
112112
final com.google.android.material.checkbox.MaterialCheckBox forgejoRepos =
113113
root.findViewById(R.id.k2go_moddet_forgejo_repos);
114114
final boolean isForgejo = "forgejo".equals(c.key());
115-
final boolean isCodeAddons = "code_addons".equals(c.key());
116-
final boolean isCodeAssets = "code_assets".equals(c.key());
117115
// K2GO-417: the repos opt-in is an INSTALL-TIME choice, so it is shown ONLY in the installable
118116
// branch below (default-checked in the layout). Once the module is installed it stays GONE:
119117
// toggling it would do nothing (roles are not reinstalled from here, and unchecking cannot remove
@@ -199,21 +197,13 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
199197
});
200198
});
201199
}
202-
if (isCodeAddons) {
203-
// K2GO-99: an installed add-ons gallery offers a live refresh (re-mirror the
204-
// published gallery). Minimal inline progress via the shared flow; no status gate
205-
// (unlike Forgejo there is no sub-state: installed means there is a gallery).
206-
installNowBtn.setText(R.string.k2go_code_addons_update);
207-
installNowBtn.setOnClickListener(v ->
208-
org.appdevforall.k2go.addons.presentation.AddonsRefresh.start(requireActivity(), installNowBtn));
209-
installNowBtn.setVisibility(View.VISIBLE);
210-
}
211-
if (isCodeAssets) {
212-
// K2GO-437: an installed build-assets tree offers the same live refresh (re-mirror
213-
// the release build set). Shared flow, like the add-ons update.
214-
installNowBtn.setText(R.string.k2go_code_assets_update);
215-
installNowBtn.setOnClickListener(v ->
216-
org.appdevforall.k2go.codeassets.presentation.CodeAssetsRefresh.start(requireActivity(), installNowBtn));
200+
// K2GO-449: an installed content module's update action comes from the ModuleActions
201+
// registry (code_addons, code_assets, ...), so this fragment no longer carries one if
202+
// per module. Forgejo's repos action stays special above (status-gated).
203+
ModuleActions.InstalledAction ia = ModuleActions.installed(c.key());
204+
if (ia != null) {
205+
installNowBtn.setText(ia.labelRes);
206+
installNowBtn.setOnClickListener(v -> ia.handler.run(requireActivity(), installNowBtn));
217207
installNowBtn.setVisibility(View.VISIBLE);
218208
}
219209
return; // a module cannot be uninstalled or reinstalled here (repos action aside)

0 commit comments

Comments
 (0)