From e50c836e84c1e9f3a36da8c59fada99936b436b1 Mon Sep 17 00:00:00 2001 From: Luis Guzman Date: Wed, 5 Aug 2026 18:56:05 -0600 Subject: [PATCH 1/2] ADFA-5033: redesign the ZIM catalog browse to 'breathe' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Category index (ZimLandingFragment): a "MOST CONTENT" top-6 + "See all N categories" default, a grouped See-all with theme section headers, theme filter chips on one horizontally-scrollable line (never wraps; ≥48dp targets), flat hairline rows with a right-aligned count column instead of per-row cards, and unavailable categories collapsed out of the flow (muted line / single collapsed row) instead of greyed in place. Category detail (ZimCategoryFragment): flat item rows with a hairline between them — the only rounded/filled shape is the selected row's highlight (live on tap). The item count moves to its own line with the list controls ("N items" -> "N results" while searching), dropping the redundant " · N" title pill. Both screens now share ONE language control: a whole-row selector (two lines, source in Title-Case "From System" / "Manually Selected", caret, no inner Change button) — resolves the button-in-button. - KiwixGroups: static category->theme-group map (chip + header labels). - docs/CATALOG_BROWSE_TEMPLATE.md: the agreed conventions, so Kolibri / Books reuse this shape instead of reinventing it. Styling/adherence only — no catalog/data-source change; counts, availability and ordering still come from KiwixCatalog. New strings are translatable=false pending design sign-off, then localized. --- .../iiab/controller/redesign/KiwixGroups.java | 73 +++++ .../redesign/ZimCategoryFragment.java | 81 +++-- .../redesign/ZimLandingFragment.java | 281 ++++++++++++++---- .../res/layout/fragment_k2go_zim_category.xml | 64 ++-- .../res/layout/fragment_k2go_zim_landing.xml | 41 ++- .../app/src/main/res/values/strings_k2go.xml | 25 ++ controller/docs/CATALOG_BROWSE_TEMPLATE.md | 86 ++++++ 7 files changed, 516 insertions(+), 135 deletions(-) create mode 100644 controller/app/src/main/java/org/iiab/controller/redesign/KiwixGroups.java create mode 100644 controller/docs/CATALOG_BROWSE_TEMPLATE.md diff --git a/controller/app/src/main/java/org/iiab/controller/redesign/KiwixGroups.java b/controller/app/src/main/java/org/iiab/controller/redesign/KiwixGroups.java new file mode 100644 index 000000000..894044b4a --- /dev/null +++ b/controller/app/src/main/java/org/iiab/controller/redesign/KiwixGroups.java @@ -0,0 +1,73 @@ +/* + * ============================================================================ + * Name : KiwixGroups.java + * Author : AppDevForAll + * Copyright : Copyright (c) 2026 AppDevForAll + * Description : ADFA-5033. Static theme grouping for the ZIM catalog category index. Maps each of the + * ~23 categories (KiwixCategories) to one of 5 groups, used by the browse screen's filter + * chips (short label) and the "See all" section headers (longer label). Pure client-side + * table shipped with the app; the same shape is meant to back other content types (e.g. + * Kolibri) later. A category not listed falls into "media" (the catch-all) so the grouped + * view is always complete. DRAFT map — under team review (ADFA-5033). + * + * Template conventions (respect when copying this pattern to Kolibri/Books): + * controller/docs/CATALOG_BROWSE_TEMPLATE.md + * ============================================================================ + */ +package org.iiab.controller.redesign; + +import org.iiab.controller.R; + +import java.util.HashMap; +import java.util.Map; + +public final class KiwixGroups { + private KiwixGroups() {} + + /** A theme group: a short chip label and a longer section header, both string resources. */ + public static final class Group { + public final String key; + public final int chipLabel; // short — used on the filter chip + public final int headerLabel; // longer — used as the "See all" section header + Group(String key, int chipLabel, int headerLabel) { + this.key = key; this.chipLabel = chipLabel; this.headerLabel = headerLabel; + } + } + + /** Display + filter order (chips and See-all sections follow this). */ + public static final Group[] ALL = { + new Group("reference", R.string.k2go_zim_grp_reference, R.string.k2go_zim_grp_reference_hdr), + new Group("learning", R.string.k2go_zim_grp_learning, R.string.k2go_zim_grp_learning_hdr), + new Group("tools", R.string.k2go_zim_grp_tools, R.string.k2go_zim_grp_tools_hdr), + new Group("media", R.string.k2go_zim_grp_media, R.string.k2go_zim_grp_media_hdr), + new Group("kids", R.string.k2go_zim_grp_kids, R.string.k2go_zim_grp_kids_hdr), + }; + + private static final String CATCH_ALL = "media"; + + // category key -> group key. DRAFT (ADFA-5033); balance/placement pending team review. + private static final Map MAP = new HashMap<>(); + static { + put("reference", "wikipedia", "wiktionary", "wikiquote", "wikisource", "wikinews", "psiram"); + put("learning", "freecodecamp", "phet", "wikiversity", "wikibooks", "libretexts", "mooc"); + put("tools", "devdocs", "stack_exchange", "ifixit"); + put("media", "ted", "videos", "gutenberg", "zimit", "wikivoyage", "other", "maps"); + put("kids", "vikidia"); + } + + private static void put(String group, String... catKeys) { + for (String k : catKeys) MAP.put(k, group); + } + + /** Group key for a category (catch-all "media" if unmapped, so grouping is always complete). */ + public static String groupOf(String categoryKey) { + String g = MAP.get(categoryKey); + return g != null ? g : CATCH_ALL; + } + + /** Look up a group by key (null if unknown). */ + public static Group byKey(String groupKey) { + for (Group g : ALL) if (g.key.equals(groupKey)) return g; + return null; + } +} diff --git a/controller/app/src/main/java/org/iiab/controller/redesign/ZimCategoryFragment.java b/controller/app/src/main/java/org/iiab/controller/redesign/ZimCategoryFragment.java index 34b87cbb5..d1bcb74a2 100644 --- a/controller/app/src/main/java/org/iiab/controller/redesign/ZimCategoryFragment.java +++ b/controller/app/src/main/java/org/iiab/controller/redesign/ZimCategoryFragment.java @@ -72,7 +72,7 @@ private static final class Entry { private long freeMb = 0, totalMb = 0; private LinearLayout list; - private TextView freeLabel, sortSize, sortName, sortGroup, langChip, langCurrent, langSub; + private TextView freeLabel, sortSize, sortName, sortGroup, count, langCurrent, langSub; private ProgressBar bar; private Button add; @@ -101,10 +101,10 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c sortSize = root.findViewById(R.id.k2go_zc_sort_size); sortName = root.findViewById(R.id.k2go_zc_sort_name); sortGroup = root.findViewById(R.id.k2go_zc_sort_group); - langChip = root.findViewById(R.id.k2go_zc_lang); // informative label only (not a button) + count = root.findViewById(R.id.k2go_zc_count); // ADFA-5033: item count, list metadata langCurrent = root.findViewById(R.id.k2go_zc_lang_current); langSub = root.findViewById(R.id.k2go_zc_lang_sub); - root.findViewById(R.id.k2go_zc_change).setOnClickListener(v -> pickLanguage()); + root.findViewById(R.id.k2go_zc_lang_box).setOnClickListener(v -> pickLanguage()); // ADFA-5033: whole-row control android.widget.EditText search = root.findViewById(R.id.k2go_zc_search); search.setHint(getString(R.string.k2go_zc_search_hint, cat != null ? cat.title : project)); @@ -181,11 +181,14 @@ private String label(String creator, String flavour) { } private void render() { - langChip.setText(getString(R.string.k2go_zc_lang_fmt, langDisplay(lang), entries.size())); + int shownCount = 0; + for (Entry e : entries) if (passes(e)) shownCount++; + // ADFA-5033: "N items" normally, live "N results" while searching — no language (that's the selector). + count.setText(getString(query.isEmpty() ? R.string.k2go_zc_count_items : R.string.k2go_zc_count_results, shownCount)); langCurrent.setText(getString(R.string.k2go_zim_lang_fmt, langDisplay(lang))); boolean manual = (getActivity() instanceof SetupLibraryActivity) && ((SetupLibraryActivity) getActivity()).isZimLangManual(); - langSub.setText(manual ? R.string.k2go_zim_lang_sub_manual : R.string.k2go_zim_lang_sub); + langSub.setText(manual ? R.string.k2go_zim_lang_state_manual : R.string.k2go_zim_lang_state_system); sortSize.setText(getString(R.string.k2go_zc_sort_size) + (sizeDir < 0 ? " ▼" : " ▲")); sortName.setText((nameDir > 0 ? getString(R.string.k2go_zc_sort_name) : getString(R.string.k2go_zc_sort_name_desc)) + (nameDir > 0 ? " ▼" : " ▲")); @@ -279,57 +282,91 @@ private void chip(TextView t, boolean on) { t.setTextColor(ContextCompat.getColor(requireContext(), on ? android.R.color.white : R.color.k2go_ink)); } + // ADFA-5033: flat list row (spec §10) — a simple line with a hairline between rows, NOT a card. + // The only rounded/filled shape is the SELECTED row's highlight; unselected rows are plain. private View row(Entry e, String labelText, int indent) { boolean fits = freeMb <= 0 || (e.bytes / (1024L * 1024L)) <= freeMb; + boolean selected = e.checked && fits; - LinearLayout r = new LinearLayout(requireContext()); - r.setOrientation(LinearLayout.VERTICAL); - LinearLayout.LayoutParams rlp = new LinearLayout.LayoutParams( + LinearLayout wrap = new LinearLayout(requireContext()); + wrap.setOrientation(LinearLayout.VERTICAL); + LinearLayout.LayoutParams wlp = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); - rlp.bottomMargin = px(8); rlp.leftMargin = indent; - r.setLayoutParams(rlp); - r.setBackgroundResource(R.drawable.k2go_card_bg); - r.setPadding(px(12), px(10), px(12), px(10)); + wlp.leftMargin = indent; + wrap.setLayoutParams(wlp); + + LinearLayout content = new LinearLayout(requireContext()); + content.setOrientation(LinearLayout.VERTICAL); + content.setPadding(px(12), px(10), px(12), px(10)); + if (selected) content.setBackground(selectedHighlight()); // the one rounded/filled shape LinearLayout top = new LinearLayout(requireContext()); top.setOrientation(LinearLayout.HORIZONTAL); top.setGravity(Gravity.CENTER_VERTICAL); + top.setMinimumHeight(px(36)); CheckBox cb = new CheckBox(requireContext()); - cb.setChecked(e.checked && fits); + cb.setChecked(selected); cb.setEnabled(fits); cb.setClickable(false); cb.setFocusable(false); top.addView(cb); TextView name = new TextView(requireContext()); - name.setTextAppearance(com.google.android.material.R.style.TextAppearance_Material3_BodyMedium); + name.setTextAppearance(com.google.android.material.R.style.TextAppearance_Material3_BodyLarge); name.setText(labelText); name.setTextColor(ContextCompat.getColor(requireContext(), R.color.k2go_ink)); + if (selected) name.setTypeface(name.getTypeface(), android.graphics.Typeface.BOLD); LinearLayout.LayoutParams nlp = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1f); - nlp.leftMargin = px(6); + nlp.leftMargin = px(8); top.addView(name, nlp); TextView size = new TextView(requireContext()); - size.setTextAppearance(com.google.android.material.R.style.TextAppearance_Material3_BodySmall); + size.setTextAppearance(com.google.android.material.R.style.TextAppearance_Material3_BodyMedium); size.setText(gb(e.bytes / (1024L * 1024L))); size.setTextColor(ContextCompat.getColor(requireContext(), R.color.k2go_muted)); + size.setGravity(Gravity.END); top.addView(size); - r.addView(top); + content.addView(top); if (!fits) { TextView warn = new TextView(requireContext()); warn.setTextAppearance(com.google.android.material.R.style.TextAppearance_Material3_BodySmall); warn.setText(getString(R.string.k2go_zc_nospace, gb(e.bytes / (1024L * 1024L)), gb(freeMb))); warn.setTextColor(ContextCompat.getColor(requireContext(), R.color.k2go_amber_text)); - LinearLayout.LayoutParams wlp = new LinearLayout.LayoutParams( + LinearLayout.LayoutParams warnLp = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); - wlp.topMargin = px(2); wlp.leftMargin = px(34); - r.addView(warn, wlp); + warnLp.topMargin = px(2); warnLp.leftMargin = px(36); + content.addView(warn, warnLp); } else { - r.setOnClickListener(v -> { e.checked = !e.checked; cb.setChecked(e.checked); updateTotals(); }); + content.setOnClickListener(v -> { + e.checked = !e.checked; + cb.setChecked(e.checked); // fits is true in this branch + content.setBackground(e.checked ? selectedHighlight() : null); + name.setTypeface(null, e.checked ? android.graphics.Typeface.BOLD : android.graphics.Typeface.NORMAL); + updateTotals(); + }); } - return r; + + wrap.addView(content); + wrap.addView(hairline()); + return wrap; + } + + /** Rounded, subtly-filled highlight for the selected row (the only non-flat shape in the list). */ + private android.graphics.drawable.GradientDrawable selectedHighlight() { + android.graphics.drawable.GradientDrawable g = new android.graphics.drawable.GradientDrawable(); + g.setCornerRadius(px(10)); + g.setColor(androidx.core.graphics.ColorUtils.setAlphaComponent( + ContextCompat.getColor(requireContext(), R.color.k2go_teal), 0x33)); + return g; + } + + private View hairline() { + View v = new View(requireContext()); + v.setBackgroundColor(ContextCompat.getColor(requireContext(), R.color.k2go_hairline)); + v.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, px(1))); + return v; } private long checkedMb() { diff --git a/controller/app/src/main/java/org/iiab/controller/redesign/ZimLandingFragment.java b/controller/app/src/main/java/org/iiab/controller/redesign/ZimLandingFragment.java index 856db0c39..becc4576e 100644 --- a/controller/app/src/main/java/org/iiab/controller/redesign/ZimLandingFragment.java +++ b/controller/app/src/main/java/org/iiab/controller/redesign/ZimLandingFragment.java @@ -41,17 +41,19 @@ public class ZimLandingFragment extends Fragment { - private static final int COLLAPSED = 15; + private static final int TOP_N = 6; // ADFA-5033: categories shown by default before "See all" private JSONObject catalog; private long freeMb = 0, totalMb = 0; private LinearLayout cats; + private LinearLayout chipRow; private TextView status, langLabel, langSub, storageLabel; private ProgressBar storageBar; private Button review; private View bottomBar; private String query = ""; private boolean expanded = false; + private String selectedGroup = null; // ADFA-5033: null = "All"; otherwise a KiwixGroups key private int px(int dp) { return Math.round(dp * getResources().getDisplayMetrics().density); } @@ -72,6 +74,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c back.setOnClickListener(v -> requireActivity().getSupportFragmentManager().popBackStack()); cats = root.findViewById(R.id.k2go_zim_cats); + chipRow = root.findViewById(R.id.k2go_zim_chips); status = root.findViewById(R.id.k2go_zim_status); langLabel = root.findViewById(R.id.k2go_zim_lang); langSub = root.findViewById(R.id.k2go_zim_lang_sub); @@ -92,7 +95,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c } @Override public void afterTextChanged(android.text.Editable s) {} }); - root.findViewById(R.id.k2go_zim_change).setOnClickListener(v -> pickLanguage()); + root.findViewById(R.id.k2go_zim_lang_box).setOnClickListener(v -> pickLanguage()); try { StatFs st = new StatFs(requireContext().getFilesDir().getPath()); @@ -102,6 +105,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c updateLangLabel(); updateStorage(); + buildChips(); status.setText(R.string.k2go_zim_loading); KiwixCatalog.getOrFetch(requireContext(), new KiwixCatalog.Listener() { @@ -129,10 +133,12 @@ public void onResume() { } private void updateLangLabel() { + // ADFA-5033: one-control selector — bold language + a muted source sub-line ("From system" / + // "Manually selected"); the "· filters the catalog" clause is dropped (redundant). langLabel.setText(getString(R.string.k2go_zim_lang_fmt, langDisplay(lang()))); boolean manual = (getActivity() instanceof SetupLibraryActivity) && ((SetupLibraryActivity) getActivity()).isZimLangManual(); - langSub.setText(manual ? R.string.k2go_zim_lang_sub_manual : R.string.k2go_zim_lang_sub); + langSub.setText(manual ? R.string.k2go_zim_lang_state_manual : R.string.k2go_zim_lang_state_system); } private String langDisplay(String code) { @@ -169,33 +175,126 @@ private String gb(long mb) { // ADFA-4910: one standard size formatter for the return org.iiab.controller.util.ByteFormatter.humanMb(mb); } + // ADFA-5033: "breathe" — show less by default (top-N + See all), group in See-all, filter by chip, + // and collapse unavailable categories out of the flow instead of greying them in place. private void buildRows() { + if (catalog == null) return; cats.removeAllViews(); - String lang = lang(); - - // Counts + ordering reflect the SELECTED language (not the all-languages total), so the - // language selector is meaningful: e.g. Wikipedia in Spanish shows its ~dozens, not 2,465. - final String L = lang; - List ordered = new ArrayList<>(); - Collections.addAll(ordered, KiwixCategories.ALL); - Collections.sort(ordered, (a, b) -> - Integer.compare(KiwixCatalog.count(catalog, b.key, L), KiwixCatalog.count(catalog, a.key, L))); - - List shown = new ArrayList<>(); - for (KiwixCategories.Category c : ordered) if (matches(c, query)) shown.add(c); - - // Collapse to the first 15 only when not searching; searching shows every match so a - // low-count category (e.g. TED) is always findable even though it sorts far down. - boolean limiting = query.isEmpty() && !expanded && shown.size() > COLLAPSED; - int limit = limiting ? COLLAPSED : shown.size(); - - for (int i = 0; i < limit; i++) { - KiwixCategories.Category c = shown.get(i); - cats.addView(categoryRow(c, KiwixCatalog.count(catalog, c.key, L))); + final String L = lang(); + + // Search overrides everything: a flat list of matching categories across the whole catalog. + if (!query.isEmpty()) { + int shown = 0; + for (KiwixCategories.Category c : availableSorted(L)) { + if (!matches(c, query)) continue; + cats.addView(categoryRow(c, countOf(c, L))); + shown++; + } + status.setText(shown == 0 ? getString(R.string.k2go_zim_no_match) : ""); + return; + } + status.setText(""); + + List available = availableSorted(L); + int unavailable = KiwixCategories.ALL.length - available.size(); + + // A group chip is selected: just that group's available categories (already filtered). Add the + // header only once we know the group has at least one available category (no empty header). + if (selectedGroup != null) { + KiwixGroups.Group g = KiwixGroups.byKey(selectedGroup); + boolean headerAdded = false; + for (KiwixCategories.Category c : available) { + if (!selectedGroup.equals(KiwixGroups.groupOf(c.key))) continue; + if (!headerAdded && g != null) { cats.addView(sectionHeader(getString(g.headerLabel))); headerAdded = true; } + cats.addView(categoryRow(c, countOf(c, L))); + } + // Nothing in this group is available in the current language → offer to change language. + if (!headerAdded && unavailable > 0) cats.addView(unavailableLine(unavailable, L)); + return; + } + + // "All": default = MOST CONTENT top-N + See all; expanded = grouped by theme. + if (!expanded) { + cats.addView(sectionHeader(getString(R.string.k2go_zim_most_content))); + int top = Math.min(TOP_N, available.size()); + for (int i = 0; i < top; i++) cats.addView(categoryRow(available.get(i), countOf(available.get(i), L))); + cats.addView(seeAllRow(KiwixCategories.ALL.length)); + if (unavailable > 0) cats.addView(unavailableLine(unavailable, L)); + } else { + for (KiwixGroups.Group g : KiwixGroups.ALL) { + boolean headerAdded = false; + for (KiwixCategories.Category c : available) { + if (!g.key.equals(KiwixGroups.groupOf(c.key))) continue; + if (!headerAdded) { cats.addView(sectionHeader(getString(g.headerLabel))); headerAdded = true; } + cats.addView(categoryRow(c, countOf(c, L))); + } + } + if (unavailable > 0) cats.addView(unavailableRow(unavailable, L)); + } + } + + private int countOf(KiwixCategories.Category c, String L) { return KiwixCatalog.count(catalog, c.key, L); } + + /** Categories with content in the current language, most first. Unavailable ones drop out here. */ + private List availableSorted(String L) { + List list = new ArrayList<>(); + for (KiwixCategories.Category c : KiwixCategories.ALL) if (countOf(c, L) > 0) list.add(c); + Collections.sort(list, (a, b) -> Integer.compare(countOf(b, L), countOf(a, L))); + return list; + } + + // ---- chips (one horizontally-scrollable line; never wraps) ----------------------------------- + + private void buildChips() { + if (chipRow == null) return; + chipRow.removeAllViews(); + chipRow.addView(chip(getString(R.string.k2go_zim_grp_all), null)); + for (KiwixGroups.Group g : KiwixGroups.ALL) chipRow.addView(chip(getString(g.chipLabel), g.key)); + } + + private View chip(String label, String groupKey) { + boolean selected = (groupKey == null) ? (selectedGroup == null) : groupKey.equals(selectedGroup); + int teal = ContextCompat.getColor(requireContext(), R.color.k2go_teal); + TextView t = new TextView(requireContext()); + t.setText(label); + t.setTextAppearance(com.google.android.material.R.style.TextAppearance_Material3_LabelLarge); + t.setGravity(Gravity.CENTER); + t.setMinHeight(px(48)); // ADFA-5033: ≥48dp tap target (spec §9) + t.setPadding(px(14), px(6), px(14), px(6)); + android.graphics.drawable.GradientDrawable bg = new android.graphics.drawable.GradientDrawable(); + bg.setShape(android.graphics.drawable.GradientDrawable.RECTANGLE); + bg.setCornerRadius(px(24)); // full pill at 48dp + if (selected) { + bg.setColor(teal); + t.setTextColor(android.graphics.Color.WHITE); + } else { + bg.setColor(android.graphics.Color.TRANSPARENT); + bg.setStroke(Math.max(1, Math.round(1.4f * getResources().getDisplayMetrics().density)), teal); + t.setTextColor(teal); } - if (limiting) cats.addView(seeAllRow(ordered.size(), totalItems(ordered, L))); - if (shown.isEmpty()) status.setText(getString(R.string.k2go_zim_no_match)); - else status.setText(""); + t.setBackground(bg); + LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams( + LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); + lp.rightMargin = px(8); + t.setLayoutParams(lp); + t.setOnClickListener(v -> { + selectedGroup = groupKey; + expanded = false; + buildChips(); + buildRows(); + }); + return t; + } + + /** Teal caps section header (MOST CONTENT / group headers). */ + private View sectionHeader(String label) { + TextView t = new TextView(requireContext()); + t.setText(label); + t.setTextAppearance(com.google.android.material.R.style.TextAppearance_Material3_LabelMedium); + t.setTextColor(ContextCompat.getColor(requireContext(), R.color.k2go_teal)); + t.setLetterSpacing(0.06f); + t.setPadding(0, px(16), 0, px(8)); + return t; } /** Material icon per category (first pass; the team can refine the set later). */ @@ -233,43 +332,95 @@ private boolean matches(KiwixCategories.Category c, String q) { || c.key.toLowerCase(Locale.ROOT).contains(q); } - private int totalItems(List all, String lang) { - int n = 0; - for (KiwixCategories.Category c : all) n += KiwixCatalog.count(catalog, c.key, lang); - return n; + /** "See all N categories ›" — expands the default list into the grouped view. */ + private View seeAllRow(int catCount) { + LinearLayout wrap = new LinearLayout(requireContext()); + wrap.setOrientation(LinearLayout.VERTICAL); + LinearLayout row = flatRow(); + TextView label = new TextView(requireContext()); + label.setTextAppearance(com.google.android.material.R.style.TextAppearance_Material3_LabelLarge); + label.setTextColor(ContextCompat.getColor(requireContext(), R.color.k2go_teal)); + label.setText(getString(R.string.k2go_zim_see_all_cats_fmt, catCount)); + row.addView(label, new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1f)); + row.addView(chevron()); + row.setOnClickListener(v -> { expanded = true; buildRows(); }); + wrap.addView(row); + wrap.addView(hairline()); + return wrap; } - private View seeAllRow(int catCount, int itemCount) { + /** Default state: one muted line summarizing the categories hidden by the current language. */ + private View unavailableLine(int count, String L) { TextView t = new TextView(requireContext()); - t.setText(getString(R.string.k2go_zim_see_all_fmt, catCount, itemCount)); - t.setGravity(Gravity.CENTER); - t.setPadding(px(12), px(12), px(12), px(12)); - t.setTextColor(ContextCompat.getColor(requireContext(), R.color.k2go_teal)); - t.setTypeface(t.getTypeface(), android.graphics.Typeface.BOLD); - t.setClickable(true); - t.setOnClickListener(v -> { expanded = true; buildRows(); }); + t.setText(getString(R.string.k2go_zim_unavail_line_fmt, count, langDisplay(L))); + t.setTextAppearance(com.google.android.material.R.style.TextAppearance_Material3_BodySmall); + t.setTextColor(ContextCompat.getColor(requireContext(), R.color.k2go_muted)); + t.setPadding(0, px(14), 0, px(4)); + t.setOnClickListener(v -> pickLanguage()); return t; } - private View categoryRow(KiwixCategories.Category c, int n) { - boolean enabled = n > 0; + /** See-all state: the unavailable categories collapsed into a single muted row (tap = change lang). */ + private View unavailableRow(int count, String L) { + LinearLayout wrap = new LinearLayout(requireContext()); + wrap.setOrientation(LinearLayout.VERTICAL); + LinearLayout row = flatRow(); + TextView label = new TextView(requireContext()); + label.setTextAppearance(com.google.android.material.R.style.TextAppearance_Material3_BodyLarge); + label.setTextColor(ContextCompat.getColor(requireContext(), R.color.k2go_muted)); + label.setText(getString(R.string.k2go_zim_unavail_row_fmt, langDisplay(L))); + row.addView(label, new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1f)); + TextView n = new TextView(requireContext()); + n.setTextAppearance(com.google.android.material.R.style.TextAppearance_Material3_BodyMedium); + n.setTextColor(ContextCompat.getColor(requireContext(), R.color.k2go_muted)); + n.setText(String.valueOf(count)); + row.addView(n); + row.addView(chevron()); + row.setOnClickListener(v -> pickLanguage()); + wrap.addView(row); + wrap.addView(hairline()); + return wrap; + } + /** A flat, horizontal content row (no card): centred vertically, ≥56dp, grid padding. */ + private LinearLayout flatRow() { LinearLayout row = new LinearLayout(requireContext()); row.setOrientation(LinearLayout.HORIZONTAL); row.setGravity(Gravity.CENTER_VERTICAL); - LinearLayout.LayoutParams rlp = new LinearLayout.LayoutParams( - LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); - rlp.bottomMargin = px(8); - row.setLayoutParams(rlp); - row.setBackgroundResource(R.drawable.k2go_card_bg); - row.setPadding(px(14), px(12), px(14), px(12)); - row.setAlpha(enabled ? 1f : 0.5f); + row.setMinimumHeight(px(56)); + row.setPadding(0, px(10), 0, px(10)); + return row; + } + + private View hairline() { + View v = new View(requireContext()); + v.setBackgroundColor(ContextCompat.getColor(requireContext(), R.color.k2go_hairline)); + v.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, px(1))); + return v; + } + + private TextView chevron() { + TextView ch = new TextView(requireContext()); + ch.setText("›"); + ch.setTextAppearance(com.google.android.material.R.style.TextAppearance_Material3_TitleMedium); + ch.setTextColor(ContextCompat.getColor(requireContext(), R.color.k2go_muted)); + ch.setPadding(px(10), 0, 0, 0); + return ch; + } + + // ADFA-5033: flat, light row — no per-row card. Icon + name/subtitle + right-aligned count column + // (teal, redundant with the number) + chevron, over a hairline. Only available categories reach here. + private View categoryRow(KiwixCategories.Category c, int n) { + LinearLayout wrap = new LinearLayout(requireContext()); + wrap.setOrientation(LinearLayout.VERTICAL); + + LinearLayout row = flatRow(); ImageView icon = new ImageView(requireContext()); icon.setImageResource(iconFor(c.key)); icon.setColorFilter(ContextCompat.getColor(requireContext(), R.color.k2go_teal)); - LinearLayout.LayoutParams ilp = new LinearLayout.LayoutParams(px(26), px(26)); - ilp.rightMargin = px(12); + LinearLayout.LayoutParams ilp = new LinearLayout.LayoutParams(px(24), px(24)); + ilp.rightMargin = px(16); row.addView(icon, ilp); LinearLayout text = new LinearLayout(requireContext()); @@ -278,20 +429,24 @@ private View categoryRow(KiwixCategories.Category c, int n) { text.addView(text(c.subtitle, R.color.k2go_muted, false)); row.addView(text, new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1f)); - TextView right = new TextView(requireContext()); - right.setTextAppearance(com.google.android.material.R.style.TextAppearance_Material3_BodyMedium); - right.setTextColor(ContextCompat.getColor(requireContext(), enabled ? R.color.k2go_ink : R.color.k2go_muted)); - right.setText(enabled ? (n + " ›") : getString(R.string.k2go_zim_cat_unavailable)); - row.addView(right); + TextView count = new TextView(requireContext()); + count.setTextAppearance(com.google.android.material.R.style.TextAppearance_Material3_BodyMedium); + count.setTextColor(ContextCompat.getColor(requireContext(), R.color.k2go_teal)); + count.setText(String.valueOf(n)); + count.setGravity(Gravity.END); + count.setMinWidth(px(28)); + row.addView(count); + row.addView(chevron()); + + row.setOnClickListener(v -> { + if (getActivity() instanceof SetupLibraryActivity) { + ((SetupLibraryActivity) getActivity()).openZimCategory(c.key); + } + }); - if (enabled) { - row.setOnClickListener(v -> { - if (getActivity() instanceof SetupLibraryActivity) { - ((SetupLibraryActivity) getActivity()).openZimCategory(c.key); - } - }); - } - return row; + wrap.addView(row); + wrap.addView(hairline()); + return wrap; } private TextView text(String s, int color, boolean bold) { diff --git a/controller/app/src/main/res/layout/fragment_k2go_zim_category.xml b/controller/app/src/main/res/layout/fragment_k2go_zim_category.xml index c2ae8c5c5..3d524484d 100644 --- a/controller/app/src/main/res/layout/fragment_k2go_zim_category.xml +++ b/controller/app/src/main/res/layout/fragment_k2go_zim_category.xml @@ -24,43 +24,27 @@ android:textAppearance="?attr/textAppearanceBodyMedium" android:textColor="@color/k2go_teal" /> - + + android:textAppearance="?attr/textAppearanceHeadlineMedium" + android:textColor="@color/k2go_ink" /> - - - - - - - + @@ -82,18 +66,17 @@ android:id="@+id/k2go_zc_lang_sub" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:text="@string/k2go_zim_lang_sub" android:textAppearance="?attr/textAppearanceBodySmall" android:textColor="@color/k2go_muted" /> -