Skip to content

Commit 290f2b3

Browse files
Merge pull request #276 from appdevforall/fix/ADFA-4910-getmore-storage
ADFA-4910: Get More storage projection counts maps + adaptive size units
2 parents 7077d4d + 97f1052 commit 290f2b3

47 files changed

Lines changed: 126 additions & 106 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,17 +148,23 @@ 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+
org.iiab.controller.util.ByteFormatter.humanGb(used),
153+
org.iiab.controller.util.ByteFormatter.humanGb(systemGb),
154+
org.iiab.controller.util.ByteFormatter.humanGb(picksGb),
155+
org.iiab.controller.util.ByteFormatter.humanGb(freeAfter)));
152156
}
153157

154-
/** GB the wizard picks will add: ZIM by real catalog bytes; books are tiny EPUBs (~few MB). */
158+
/** GB the wizard picks will add: ZIM by real catalog bytes; maps by the banked catalog size;
159+
* books are tiny EPUBs (~few MB, estimated since the catalog has no per-book size). */
155160
private double picksGb() {
156161
double gb = 0;
157162
org.json.JSONArray z = ZimWishlist.all(requireContext());
158163
for (int i = 0; i < z.length(); i++) {
159164
org.json.JSONObject o = z.optJSONObject(i);
160165
if (o != null) gb += o.optLong("bytes", 0) / (1024.0 * 1024.0 * 1024.0);
161166
}
167+
gb += MapsWishlist.mb(requireContext()) / 1024.0; // ADFA-4910: count the banked maps size
162168
gb += BooksWishlist.size(requireContext()) * 0.003;
163169
return gb;
164170
}

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import android.system.StructStat;
2121

2222
import java.io.File;
23-
import java.util.Locale;
2423

2524
public final class LibrarySize {
2625

@@ -62,11 +61,9 @@ private static long du(File f) {
6261
return 0L;
6362
}
6463

65-
/** Compact size label: "1.7 GB" for >= 1 GB, else "820 MB". */
64+
/** Compact size label: "1.7 GB" for >= 1 GB, "820 MB", or "512 KB". ADFA-4910: one standard
65+
* formatter shared with the rest of the UI. */
6666
public static String human(long bytes) {
67-
double gb = bytes / (1024.0 * 1024.0 * 1024.0);
68-
if (gb >= 1.0) return String.format(Locale.US, "%.1f GB", gb);
69-
double mb = bytes / (1024.0 * 1024.0);
70-
return String.format(Locale.US, "%.0f MB", mb);
67+
return org.iiab.controller.util.ByteFormatter.humanGb(bytes / (1024.0 * 1024.0 * 1024.0));
7168
}
7269
}

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636

3737
import org.iiab.controller.R;
3838

39-
import java.util.Locale;
4039

4140
public class MapsChooseFragment extends Fragment {
4241

@@ -279,8 +278,7 @@ private void refresh() {
279278
download.setText(getString(R.string.k2go_maps_download, fmt(t)));
280279
}
281280

282-
private String fmt(long mb) {
283-
if (mb >= 1024) return String.format(Locale.US, "%.1f GB", mb / 1024.0);
284-
return mb + " MB";
281+
private String fmt(long mb) { // ADFA-4910: one standard size formatter for the whole UI
282+
return org.iiab.controller.util.ByteFormatter.humanMb(mb);
285283
}
286284
}

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727

2828
import org.iiab.controller.R;
2929

30-
import java.util.Locale;
3130

3231
public class MapsConfirmFragment extends Fragment {
3332

@@ -73,6 +72,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
7372
}
7473
box.addView(row(getString(R.string.k2go_maps_total), "", fmt(total), true));
7574

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

7878
// ADFA-4900: in the wizard (pre-install) Maps banks the selection; post-install it installs.
@@ -84,7 +84,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
8484
start.setOnClickListener(v -> {
8585
if (getActivity() instanceof SetupLibraryActivity) {
8686
SetupLibraryActivity act = (SetupLibraryActivity) getActivity();
87-
if (act.isMapsWizard()) act.mapsWizardConfirm(levels);
87+
if (act.isMapsWizard()) act.mapsWizardConfirm(levels, totalMb);
8888
else act.openMapsPreparing(levels);
8989
}
9090
});
@@ -138,8 +138,7 @@ private View divider() {
138138
return d;
139139
}
140140

141-
private String fmt(long mb) {
142-
if (mb >= 1024) return String.format(Locale.US, "%.1f GB", mb / 1024.0);
143-
return mb + " MB";
141+
private String fmt(long mb) { // ADFA-4910: one standard size formatter for the whole UI
142+
return org.iiab.controller.util.ByteFormatter.humanMb(mb);
144143
}
145144
}

‎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/java/org/iiab/controller/redesign/Step1SystemFragment.java‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,9 @@ private void applyBar(double systemGb) {
154154
setWeight(barSystem, (float) systemGb);
155155
setWeight(barFree, (float) freeAfter);
156156
legend.setText(getString(R.string.k2go_legend_sys_free,
157-
used, systemGb, freeAfter));
157+
org.iiab.controller.util.ByteFormatter.humanGb(used),
158+
org.iiab.controller.util.ByteFormatter.humanGb(systemGb),
159+
org.iiab.controller.util.ByteFormatter.humanGb(freeAfter)));
158160
}
159161

160162
private void setWeight(View v, float w) {

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.iiab.controller.redesign;
22

33
import android.content.Context;
4-
import java.util.Locale;
54
import java.util.Set;
65
import org.iiab.controller.InstallationPlanner;
76
import org.iiab.controller.R;
@@ -65,7 +64,6 @@ public static String primary(Set<String> selected) {
6564

6665
public static String gb(double s) {
6766
if (s < 0) return "—";
68-
if (s >= 1) return String.format(Locale.US, "%.1f GB", s);
69-
return Math.round(s * 1000) + " MB";
67+
return org.iiab.controller.util.ByteFormatter.humanGb(s); // ADFA-4910: one standard formatter
7068
}
7169
}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,7 @@ private void pickLanguage() {
380380
});
381381
}
382382

383-
private String gb(long mb) {
384-
if (mb >= 1024) return String.format(Locale.US, "%.1f GB", mb / 1024.0);
385-
return mb + " MB";
383+
private String gb(long mb) { // ADFA-4910: one standard size formatter for the whole UI
384+
return org.iiab.controller.util.ByteFormatter.humanMb(mb);
386385
}
387386
}

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import androidx.fragment.app.Fragment;
2929

3030
import java.util.LinkedHashMap;
31-
import java.util.Locale;
3231
import java.util.Map;
3332

3433
import org.iiab.controller.R;
@@ -142,8 +141,7 @@ private View divider() {
142141
return d;
143142
}
144143

145-
private String gb(long mb) {
146-
if (mb >= 1024) return String.format(Locale.US, "%.1f GB", mb / 1024.0);
147-
return mb + " MB";
144+
private String gb(long mb) { // ADFA-4910: one standard size formatter for the whole UI
145+
return org.iiab.controller.util.ByteFormatter.humanMb(mb);
148146
}
149147
}

0 commit comments

Comments
 (0)