From fd6bc82214755de53848576921ab3a86a9cd17ac Mon Sep 17 00:00:00 2001 From: Balazs Toldi Date: Sun, 22 Oct 2023 09:51:30 +0200 Subject: [PATCH] Make icon toggleable This commit adds an option to choose between the original and the new icon --- app/src/main/AndroidManifest.xml | 29 +++++++++++++- .../MiscellaneousPreferenceFragment.java | 39 +++++++++++++++++++ .../utils/SharedPreferencesUtils.java | 2 + .../original_ic_launcher.xml | 6 +++ .../original_ic_launcher_round.xml | 6 +++ app/src/main/res/values/arrays.xml | 9 +++++ app/src/main/res/values/strings.xml | 2 + .../res/xml/miscellaneous_preferences.xml | 7 ++++ 8 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 app/src/main/res/mipmap-anydpi-v26/original_ic_launcher.xml create mode 100644 app/src/main/res/mipmap-anydpi-v26/original_ic_launcher_round.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 1dd230b6..a3b05a9f 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -441,11 +441,36 @@ android:theme="@style/AppTheme.Launcher" android:windowSoftInputMode="adjustPan"> - - + + + + + + + + + + + + + + + { @@ -102,5 +105,41 @@ public class MiscellaneousPreferenceFragment extends CustomFontPreferenceFragmen return true; }); } + + if (iconPreference != null) { + iconPreference.setOnPreferenceChangeListener((preference, newValue) -> { + updateIcon((String) newValue); + return true; + }); + } } + + private void updateIcon(String iconValue) { + PackageManager pm = getActivity().getPackageManager(); + + // Disable all the alternative icons + pm.setComponentEnabledSetting( + new ComponentName(getActivity(), "eu.toldi.infinityforlemmy.OriginalIcon"), + PackageManager.COMPONENT_ENABLED_STATE_DISABLED, + PackageManager.DONT_KILL_APP); + + pm.setComponentEnabledSetting( + new ComponentName(getActivity(), "eu.toldi.infinityforlemmy.DefaultIcon"), + PackageManager.COMPONENT_ENABLED_STATE_DISABLED, + PackageManager.DONT_KILL_APP); + + // Enable the chosen icon + if ("original_icon".equals(iconValue)) { + pm.setComponentEnabledSetting( + new ComponentName(getActivity(), "eu.toldi.infinityforlemmy.OriginalIcon"), + PackageManager.COMPONENT_ENABLED_STATE_ENABLED, + PackageManager.DONT_KILL_APP); + } else { + pm.setComponentEnabledSetting( + new ComponentName(getActivity(), "eu.toldi.infinityforlemmy.DefaultIcon"), + PackageManager.COMPONENT_ENABLED_STATE_ENABLED, + PackageManager.DONT_KILL_APP); + } + } + } \ No newline at end of file diff --git a/app/src/main/java/eu/toldi/infinityforlemmy/utils/SharedPreferencesUtils.java b/app/src/main/java/eu/toldi/infinityforlemmy/utils/SharedPreferencesUtils.java index 0073a9d2..a362cc39 100644 --- a/app/src/main/java/eu/toldi/infinityforlemmy/utils/SharedPreferencesUtils.java +++ b/app/src/main/java/eu/toldi/infinityforlemmy/utils/SharedPreferencesUtils.java @@ -420,4 +420,6 @@ public class SharedPreferencesUtils { public static final String SHOW_POST_AND_COMMENT_SCORE = "show_score"; public static final String SHARE_LINK_ON_LOCAL_INSTANCE = "share_link_on_local_instance"; + + public static final String ICON_PREFERENCE = "icon_preference"; } diff --git a/app/src/main/res/mipmap-anydpi-v26/original_ic_launcher.xml b/app/src/main/res/mipmap-anydpi-v26/original_ic_launcher.xml new file mode 100644 index 00000000..012b9716 --- /dev/null +++ b/app/src/main/res/mipmap-anydpi-v26/original_ic_launcher.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-anydpi-v26/original_ic_launcher_round.xml b/app/src/main/res/mipmap-anydpi-v26/original_ic_launcher_round.xml new file mode 100644 index 00000000..012b9716 --- /dev/null +++ b/app/src/main/res/mipmap-anydpi-v26/original_ic_launcher_round.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index 84105410..c41311df 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -691,4 +691,13 @@ 1 + + Cosmic Lemmy + Galactic Cruiser Lemmy + + + + default_icon + original_icon + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f87ff46a..ad1d030a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1386,4 +1386,6 @@ Hide user instance Share links on your local instance rather than the original creation instance. Share links on your local instance + + Original Icon \ No newline at end of file diff --git a/app/src/main/res/xml/miscellaneous_preferences.xml b/app/src/main/res/xml/miscellaneous_preferences.xml index 95a6f980..4fc2b6fa 100644 --- a/app/src/main/res/xml/miscellaneous_preferences.xml +++ b/app/src/main/res/xml/miscellaneous_preferences.xml @@ -52,6 +52,13 @@ app:title="@string/share_links_on_your_local_instance" app:summary="@string/share_links_on_your_local_instance_rather_than_the_original_creation_instance" /> + +