From 171f955526b645e3d3d25cf94e5e76766fc59032 Mon Sep 17 00:00:00 2001 From: Mathias-Boulay Date: Sun, 19 Jan 2025 22:00:59 +0100 Subject: [PATCH] fix(preferences): memory allocation by increments of 8MB --- .../kdt/pojavlaunch/prefs/CustomSeekBarPreference.java | 10 +++++++++- .../net/kdt/pojavlaunch/prefs/LauncherPreferences.java | 10 +++++----- .../prefs/screens/LauncherPreferenceJavaFragment.java | 2 +- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/CustomSeekBarPreference.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/CustomSeekBarPreference.java index 5bb1bd131f..9fc6242a2b 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/CustomSeekBarPreference.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/CustomSeekBarPreference.java @@ -23,6 +23,8 @@ public class CustomSeekBarPreference extends SeekBarPreference { private int mMin; /** The textview associated by default to the preference */ private TextView mTextView; + /** Seekbar increment in case the max gets set */ + private final int mIncrement; @SuppressLint("PrivateResource") @@ -31,6 +33,7 @@ public CustomSeekBarPreference(Context context, AttributeSet attrs, int defStyle try (TypedArray a = context.obtainStyledAttributes( attrs, R.styleable.SeekBarPreference, defStyleAttr, defStyleRes)) { mMin = a.getInt(R.styleable.SeekBarPreference_min, 0); + mIncrement = a.getInt(R.styleable.SeekBarPreference_seekBarIncrement, 0); } } @@ -111,7 +114,12 @@ public void setSuffix(String suffix) { */ public void setRange(int min, int max){ setMin(min); - setMax(max); + setMaxKeepIncrement(max); + } + + public void setMaxKeepIncrement(int max) { + super.setMax(max); + setSeekBarIncrement(mIncrement); } diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/LauncherPreferences.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/LauncherPreferences.java index e61f6c8df5..e7796c34a4 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/LauncherPreferences.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/LauncherPreferences.java @@ -141,14 +141,14 @@ public static void loadPreferences(Context ctx) { */ private static int findBestRAMAllocation(Context ctx){ int deviceRam = Tools.getTotalDeviceMemory(ctx); - if (deviceRam < 1024) return 300; - if (deviceRam < 1536) return 450; - if (deviceRam < 2048) return 600; + if (deviceRam < 1024) return 296; + if (deviceRam < 1536) return 448; + if (deviceRam < 2048) return 656; // Limit the max for 32 bits devices more harshly - if (is32BitsDevice()) return 700; + if (is32BitsDevice()) return 696; if (deviceRam < 3064) return 936; - if (deviceRam < 4096) return 1148; + if (deviceRam < 4096) return 1144; if (deviceRam < 6144) return 1536; return 2048; //Default RAM allocation for 64 bits } diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/screens/LauncherPreferenceJavaFragment.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/screens/LauncherPreferenceJavaFragment.java index 245bf84855..975ec8e089 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/screens/LauncherPreferenceJavaFragment.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/prefs/screens/LauncherPreferenceJavaFragment.java @@ -38,7 +38,7 @@ public void onCreatePreferences(Bundle b, String str) { if(is32BitsDevice() || deviceRam < 2048) maxRAM = Math.min(1024, deviceRam); else maxRAM = deviceRam - (deviceRam < 3064 ? 800 : 1024); //To have a minimum for the device to breathe - memorySeekbar.setMax(maxRAM); + memorySeekbar.setMaxKeepIncrement(maxRAM); memorySeekbar.setValue(ramAllocation); memorySeekbar.setSuffix(" MB");