Skip to content

Commit 47a80a8

Browse files
ADFA-4910: Get More storage projection counts maps + adaptive size units
'Your picks' summed only ZIM (real bytes) + a tiny books estimate, so a maps-heavy selection still read 0.0 GB and small picks rounded to 0.0. - Bank the maps selection's total size (from the catalog) into MapsWishlist and add it to picksGb() so maps counts toward the projection. - Show KB/MB/GB adaptively in the legend so sub-GB picks are visible (switch the k2go_legend_your_picks placeholders from %.1f to %s across the base string and all locales to carry pre-formatted, unit-aware values). - Books stay an estimate (the Gutenberg catalog exposes no per-book size).
1 parent 7077d4d commit 47a80a8

38 files changed

Lines changed: 59 additions & 41 deletions

File tree

‎controller/app/src/main/java/org/iiab/controller/redesign/GetMoreHubFragment.java‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,21 +148,33 @@ private void refreshStorage(View root) {
148148
setW(root.findViewById(R.id.k2go_gm_bar_picks), (float) picksGb);
149149
setW(root.findViewById(R.id.k2go_gm_bar_free), (float) freeAfter);
150150
((TextView) root.findViewById(R.id.k2go_gm_legend)).setText(
151-
getString(R.string.k2go_legend_your_picks, used, systemGb, picksGb, freeAfter));
151+
getString(R.string.k2go_legend_your_picks,
152+
human(used), human(systemGb), human(picksGb), human(freeAfter)));
152153
}
153154

154-
/** GB the wizard picks will add: ZIM by real catalog bytes; books are tiny EPUBs (~few MB). */
155+
/** GB the wizard picks will add: ZIM by real catalog bytes; maps by the banked catalog size;
156+
* books are tiny EPUBs (~few MB, estimated since the catalog has no per-book size). */
155157
private double picksGb() {
156158
double gb = 0;
157159
org.json.JSONArray z = ZimWishlist.all(requireContext());
158160
for (int i = 0; i < z.length(); i++) {
159161
org.json.JSONObject o = z.optJSONObject(i);
160162
if (o != null) gb += o.optLong("bytes", 0) / (1024.0 * 1024.0 * 1024.0);
161163
}
164+
gb += MapsWishlist.mb(requireContext()) / 1024.0; // ADFA-4910: count the banked maps size
162165
gb += BooksWishlist.size(requireContext()) * 0.003;
163166
return gb;
164167
}
165168

169+
/** ADFA-4910: adaptive size unit so small picks aren't rounded to "0.0 GB". Steps up at ~1024:
170+
* KB < 1 MB, MB < 1 GB, else GB. Input is in GB. */
171+
private String human(double gb) {
172+
double mb = gb * 1024.0;
173+
if (mb >= 1024) return String.format(java.util.Locale.US, "%.1f GB", mb / 1024.0);
174+
if (mb >= 1) return String.format(java.util.Locale.US, "%.0f MB", mb);
175+
return String.format(java.util.Locale.US, "%.0f KB", Math.max(0, mb * 1024.0));
176+
}
177+
166178
private void setW(View v, float w) {
167179
LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) v.getLayoutParams();
168180
lp.weight = w;

‎controller/app/src/main/java/org/iiab/controller/redesign/MapsConfirmFragment.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
7373
}
7474
box.addView(row(getString(R.string.k2go_maps_total), "", fmt(total), true));
7575

76+
final long totalMb = total; // ADFA-4910: banked so Get More "Your picks" counts maps
7677
final String[] levels = a != null ? a.getStringArray(ARG_LEVELS) : null;
7778

7879
// ADFA-4900: in the wizard (pre-install) Maps banks the selection; post-install it installs.
@@ -84,7 +85,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
8485
start.setOnClickListener(v -> {
8586
if (getActivity() instanceof SetupLibraryActivity) {
8687
SetupLibraryActivity act = (SetupLibraryActivity) getActivity();
87-
if (act.isMapsWizard()) act.mapsWizardConfirm(levels);
88+
if (act.isMapsWizard()) act.mapsWizardConfirm(levels, totalMb);
8889
else act.openMapsPreparing(levels);
8990
}
9091
});

‎controller/app/src/main/java/org/iiab/controller/redesign/MapsWishlist.java‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,17 @@ private static SharedPreferences prefs(Context ctx) {
2525
}
2626

2727
/** Bank the wizard selection. Layer keys use the maps role's values; satellite/terrain "none"
28-
* = off, and {@code search} = the static pop-1k-cities engine on/off. */
29-
public static void save(Context ctx, String base, String sat, String terrain, boolean search) {
28+
* = off, and {@code search} = the static pop-1k-cities engine on/off. {@code mb} is the total
29+
* download size of the selection (from the maps catalog), used by the Get More storage
30+
* projection so "Your picks" reflects the real maps size. */
31+
public static void save(Context ctx, String base, String sat, String terrain, boolean search, long mb) {
3032
prefs(ctx).edit()
3133
.putBoolean("has", true)
3234
.putString("base", base == null ? "osm-z11" : base)
3335
.putString("sat", sat == null ? "none" : sat)
3436
.putString("terrain", terrain == null ? "none" : terrain)
3537
.putBoolean("search", search)
38+
.putLong("mb", Math.max(0, mb))
3639
.apply();
3740
}
3841

@@ -41,6 +44,8 @@ public static void save(Context ctx, String base, String sat, String terrain, bo
4144
public static String sat(Context ctx) { return prefs(ctx).getString("sat", "none"); }
4245
public static String terrain(Context ctx) { return prefs(ctx).getString("terrain", "none"); }
4346
public static boolean search(Context ctx) { return prefs(ctx).getBoolean("search", false); }
47+
/** Total download size (MB) of the banked selection; 0 if unknown. */
48+
public static long mb(Context ctx) { return prefs(ctx).getLong("mb", 0); }
4449

4550
public static void clear(Context ctx) { prefs(ctx).edit().clear().apply(); }
4651
}

‎controller/app/src/main/java/org/iiab/controller/redesign/SetupLibraryActivity.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,12 +337,12 @@ public void openMapsPreparing(String[] levels) {
337337

338338
/** ADFA-4900: Maps Confirm terminal in wizard mode — bank the per-layer selection to MapsWishlist
339339
* (MapsProvisioner applies it post-install) and return to the Get More hub. No live runrole. */
340-
public void mapsWizardConfirm(String[] levels) {
340+
public void mapsWizardConfirm(String[] levels, long totalMb) {
341341
String base = levels != null && levels.length > 0 && levels[0] != null ? levels[0] : "osm-z11";
342342
String sat = levels != null && levels.length > 1 && levels[1] != null ? levels[1] : "none";
343343
String ter = levels != null && levels.length > 2 && levels[2] != null ? levels[2] : "none";
344344
boolean search = levels != null && levels.length > 3 && levels[3] != null;
345-
MapsWishlist.save(this, base, sat, ter, search);
345+
MapsWishlist.save(this, base, sat, ter, search, totalMb);
346346
getSupportFragmentManager().popBackStack("getmore_maps",
347347
androidx.fragment.app.FragmentManager.POP_BACK_STACK_INCLUSIVE);
348348
}

‎controller/app/src/main/res/values-ar/strings.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,7 @@
802802
<string name="k2go_badge_copy">نسخ</string>
803803
<!-- ADFA-4795: storage bar legend l10n. machine translation. -->
804804
<string name="k2go_legend_sys_free">مستخدَم %1$.1f · النظام %2$.1f · خالٍ %3$.1f</string>
805-
<string name="k2go_legend_your_picks">مستخدَم %1$.1f · النظام %2$.1f · اختياراتك %3$.1f · خالٍ %4$.1f</string>
805+
<string name="k2go_legend_your_picks">مستخدَم %1$s · النظام %2$s · اختياراتك %3$s · خالٍ %4$s</string>
806806
<string name="k2go_legend_picks">مستخدَم %1$.1f · النظام %2$.1f · الاختيارات %3$.1f · خالٍ %4$.1f</string>
807807
<string name="k2go_perm_granted">تم المنح</string> <!-- machine translation -->
808808
<!-- ADFA-4795: clone header/ready/step/hint, Soon, force-crash l10n. machine translation. -->

‎controller/app/src/main/res/values-az/strings.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@
809809
<string name="k2go_badge_copy">Kopyala</string>
810810
<!-- ADFA-4795: storage bar legend l10n. review — machine, verify. -->
811811
<string name="k2go_legend_sys_free">İstifadə %1$.1f · Sistem %2$.1f · Boş %3$.1f</string>
812-
<string name="k2go_legend_your_picks">İstifadə %1$.1f · Sistem %2$.1f · Sizin seçimləriniz %3$.1f · Boş %4$.1f</string>
812+
<string name="k2go_legend_your_picks">İstifadə %1$s · Sistem %2$s · Sizin seçimləriniz %3$s · Boş %4$s</string>
813813
<string name="k2go_legend_picks">İstifadə %1$.1f · Sistem %2$.1f · Seçimlər %3$.1f · Boş %4$.1f</string>
814814
<string name="k2go_perm_granted">Verildi</string> <!-- review — machine, verify -->
815815
<!-- ADFA-4795: clone header/ready/step/hint, Soon, force-crash l10n. review — machine, verify. -->

‎controller/app/src/main/res/values-bg/strings.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@
809809
<string name="k2go_badge_copy">Копирай</string>
810810
<!-- ADFA-4795: storage bar legend l10n. machine translation. -->
811811
<string name="k2go_legend_sys_free">Използвано %1$.1f · Система %2$.1f · Свободно %3$.1f</string>
812-
<string name="k2go_legend_your_picks">Използвано %1$.1f · Система %2$.1f · Вашият избор %3$.1f · Свободно %4$.1f</string>
812+
<string name="k2go_legend_your_picks">Използвано %1$s · Система %2$s · Вашият избор %3$s · Свободно %4$s</string>
813813
<string name="k2go_legend_picks">Използвано %1$.1f · Система %2$.1f · Избор %3$.1f · Свободно %4$.1f</string>
814814
<string name="k2go_perm_granted">Предоставено</string> <!-- machine translation -->
815815
<!-- ADFA-4795: clone header/ready/step/hint, Soon, force-crash l10n. machine translation. -->

‎controller/app/src/main/res/values-bn/strings.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,7 @@
802802
<string name="k2go_badge_copy">কপি করুন</string>
803803
<!-- ADFA-4795: storage bar legend l10n. review — machine, verify. -->
804804
<string name="k2go_legend_sys_free">ব্যবহৃত %1$.1f · সিস্টেম %2$.1f · ফাঁকা %3$.1f</string>
805-
<string name="k2go_legend_your_picks">ব্যবহৃত %1$.1f · সিস্টেম %2$.1f · আপনার পছন্দ %3$.1f · ফাঁকা %4$.1f</string>
805+
<string name="k2go_legend_your_picks">ব্যবহৃত %1$s · সিস্টেম %2$s · আপনার পছন্দ %3$s · ফাঁকা %4$s</string>
806806
<string name="k2go_legend_picks">ব্যবহৃত %1$.1f · সিস্টেম %2$.1f · পছন্দ %3$.1f · ফাঁকা %4$.1f</string>
807807
<string name="k2go_perm_granted">মঞ্জুর</string> <!-- review — machine, verify -->
808808
<!-- ADFA-4795: clone header/ready/step/hint, Soon, force-crash l10n. review — machine, verify. -->

‎controller/app/src/main/res/values-cs/strings.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@
809809
<string name="k2go_badge_copy">Kopírovat</string>
810810
<!-- ADFA-4795: storage bar legend l10n. machine translation. -->
811811
<string name="k2go_legend_sys_free">Použito %1$.1f · Systém %2$.1f · Volné %3$.1f</string>
812-
<string name="k2go_legend_your_picks">Použito %1$.1f · Systém %2$.1f · Váš výběr %3$.1f · Volné %4$.1f</string>
812+
<string name="k2go_legend_your_picks">Použito %1$s · Systém %2$s · Váš výběr %3$s · Volné %4$s</string>
813813
<string name="k2go_legend_picks">Použito %1$.1f · Systém %2$.1f · Výběr %3$.1f · Volné %4$.1f</string>
814814
<string name="k2go_perm_granted">Uděleno</string> <!-- machine translation -->
815815
<!-- ADFA-4795: clone header/ready/step/hint, Soon, force-crash l10n. machine translation. -->

‎controller/app/src/main/res/values-de/strings.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,7 @@
802802
<string name="k2go_badge_copy">Kopieren</string>
803803
<!-- ADFA-4795: storage bar legend l10n. machine translation. -->
804804
<string name="k2go_legend_sys_free">Belegt %1$.1f · System %2$.1f · Frei %3$.1f</string>
805-
<string name="k2go_legend_your_picks">Belegt %1$.1f · System %2$.1f · Deine Auswahl %3$.1f · Frei %4$.1f</string>
805+
<string name="k2go_legend_your_picks">Belegt %1$s · System %2$s · Deine Auswahl %3$s · Frei %4$s</string>
806806
<string name="k2go_legend_picks">Belegt %1$.1f · System %2$.1f · Auswahl %3$.1f · Frei %4$.1f</string>
807807
<string name="k2go_perm_granted">Erteilt</string> <!-- machine translation -->
808808
<!-- ADFA-4795: clone header/ready/step/hint, Soon, force-crash l10n. machine translation. -->

0 commit comments

Comments
 (0)