From 75f03ac207b10bdc335ce09832771333f1741891 Mon Sep 17 00:00:00 2001 From: gdlbo <41114720+gdlbo@users.noreply.github.com> Date: Tue, 12 Jul 2022 21:55:20 +0300 Subject: [PATCH] icon changer test appname cursed --- .../ru/vtosters/lite/ui/PreferencesUtil.java | 4 +- .../lite/ui/fragments/VTSettings.java | 15 +- .../ru/vtosters/lite/utils/IconManager.java | 49 ++-- smali/AndroidManifest.xml | 258 +++++++++++++++++- 4 files changed, 304 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/ru/vtosters/lite/ui/PreferencesUtil.java b/app/src/main/java/ru/vtosters/lite/ui/PreferencesUtil.java index 3bf607d45..070a44f79 100644 --- a/app/src/main/java/ru/vtosters/lite/ui/PreferencesUtil.java +++ b/app/src/main/java/ru/vtosters/lite/ui/PreferencesUtil.java @@ -48,7 +48,7 @@ public class PreferencesUtil{ fragment.getPreferenceScreen().addPreference(preference); // fragment.getPreferenceScreen().addPreference(preference) } - public static void addListPreferenceIcon(MaterialPreferenceToolbarFragment fragment, String key, String def, CharSequence title, String icon, CharSequence summary, CharSequence[] entries, CharSequence[] entriesValue){ + public static void addListPreferenceIcon(MaterialPreferenceToolbarFragment fragment, String key, String def, CharSequence title, String icon, CharSequence summary, CharSequence[] entries, CharSequence[] entriesValue, Preference.OnPreferenceChangeListener listener){ ListPreference preference = new ListPreference(getContext()); preference.setEntries(entries); preference.setEntryValues(entriesValue); @@ -57,6 +57,8 @@ public class PreferencesUtil{ preference.setDialogTitle(title); // setDialogTitle preference.setKey(key); // setKey preference.setDefaultValue(def); // setDefaultValue + preference.setOnPreferenceChangeListener(listener); + if (icon != null) preference.setIcon(setTint(getContext(), getDrawable(getContext(), icon))); // preference.setIcon fragment.getPreferenceScreen().addPreference(preference); // fragment.getPreferenceScreen().addPreference(preference) diff --git a/app/src/main/java/ru/vtosters/lite/ui/fragments/VTSettings.java b/app/src/main/java/ru/vtosters/lite/ui/fragments/VTSettings.java index bdf5d6f63..6038c5845 100644 --- a/app/src/main/java/ru/vtosters/lite/ui/fragments/VTSettings.java +++ b/app/src/main/java/ru/vtosters/lite/ui/fragments/VTSettings.java @@ -16,6 +16,10 @@ import static ru.vtosters.lite.utils.Globals.getUserPhoto; import static ru.vtosters.lite.utils.Globals.getUsername; import static ru.vtosters.lite.utils.Globals.isGmsInstalled; import static ru.vtosters.lite.utils.Globals.restartApplication; +import static ru.vtosters.lite.utils.IconManager.iconSwitcher; +import static ru.vtosters.lite.utils.IconManager.icons; +import static ru.vtosters.lite.utils.IconManager.iconsPlus; +import static ru.vtosters.lite.utils.IconManager.iconsValues; import static ru.vtosters.lite.utils.Preferences.DoNotUseOldIcons; import static ru.vtosters.lite.utils.Preferences.ads; import static ru.vtosters.lite.utils.Preferences.devmenu; @@ -180,6 +184,14 @@ public class VTSettings extends MaterialPreferenceToolbarFragment{ }); } + if (Build.VERSION.SDK_INT >= 26) { + PreferencesUtil.addListPreferenceIcon(this, "selectedicon", "vt", "Icons", "ic_vk_logo_48", "", icons(), iconsValues(), (preference, o) -> { + edit().putString("selectedicon", o.toString()).apply(); + iconSwitcher(o.toString(), "standard"); + return false; + }); + } + if (!isGmsInstalled()) { PreferencesUtil.addPreference(this, "", Globals.getString("installgms"), "", "ic_warning_24", preference -> { Context context = getContext(); @@ -384,8 +396,7 @@ public class VTSettings extends MaterialPreferenceToolbarFragment{ Globals.getString("autoclearcachedisabled"), "100 MB", "500 MB", "1 GB", "2 GB", "5 GB" }, new String[] { "Default", "100mb", "500mb", "1gb", "2gb", "5gb" - }); - + }, null); PreferencesUtil.addPreference(this, "", Globals.getString("vtlother"), othersumm, !DoNotUseOldIcons() ? "ic_more_24" : "ic_more_horizontal_28", preference -> { Context context = getContext(); diff --git a/app/src/main/java/ru/vtosters/lite/utils/IconManager.java b/app/src/main/java/ru/vtosters/lite/utils/IconManager.java index b30a30a07..c5ba40063 100644 --- a/app/src/main/java/ru/vtosters/lite/utils/IconManager.java +++ b/app/src/main/java/ru/vtosters/lite/utils/IconManager.java @@ -2,9 +2,12 @@ package ru.vtosters.lite.utils; import static ru.vtosters.lite.utils.Globals.componentSwitcher; import static ru.vtosters.lite.utils.Globals.edit; import static ru.vtosters.lite.utils.Globals.getPreferences; +import static ru.vtosters.lite.utils.Globals.sendToast; import static ru.vtosters.lite.utils.Preferences.hasVerification; import static ru.vtosters.lite.utils.Preferences.isValidSignature; +import android.util.Log; + import java.util.Arrays; import java.util.List; @@ -17,36 +20,47 @@ public class IconManager{ "standard", "vt", "vkontakte" // available appnames list ); - public static List availablecomponents = Arrays.asList( - "00", "01", "02", "03", "10", "11", "12" // 00 - standard standard, 01 - standard vt, 02 - standard vkontakte, 10 - vt standard, 11 - vt vt, 12 - vt vkontakte - ); - public static List iconsPlus = Arrays.asList( - "standard", "vt", "dev" // available icons list for verified users + "standard", "vt", "navy", "tiger", "spring", "sea", "sakura", "party", "paint", "flamingo" // available icons list for verified users ); public static List appnamesPlus = Arrays.asList( "standard", "vt", "vkontakte" // available appnames list for verified users ); - public static List availablecomponentsPlus = Arrays.asList( - "00", "01", "02", "03", "10", "11", "12", "20", "21", "22" // 00 - standard standard, 01 - standard vt, 02 - standard vkontakte, 10 - vt standard, 11 - vt vt, 12 - vt vkontakte, 20 - dev standard, 21 - dev vt, 22 - dev vkontakte - ); + public static CharSequence[] icons() { + var iconsList = icons; + + if (hasVerification() && isValidSignature()) { + iconsList = iconsPlus; + } + + return iconsList.toArray(new CharSequence[0]); + } + + public static CharSequence[] iconsValues() { + var iconsList = icons; + + + if (hasVerification() && isValidSignature()) { + iconsList = iconsPlus; + } + + return iconsList.toArray(new CharSequence[0]); + } public static void iconSwitcher(String icon, String appname){ var iconComponent = 1; // def value for standard icon var appNameComponent = 1; // def value for standard appname + Log.d("IconManager", "iconSwitcher: icon = " + icon + ", appname = " + appname); + var iconsList = icons; var appnamesList = appnames; - var availablecomponentsList = availablecomponents; - - var getCurrComponent = getPreferences().getInt("component_enabled", 11); // get current component value if (hasVerification() && isValidSignature()) { iconsList = iconsPlus; appnamesList = appnamesPlus; - availablecomponentsList = availablecomponentsPlus; } if (iconsList.contains(icon)) { // check if icon is exist @@ -57,13 +71,16 @@ public class IconManager{ appNameComponent = appnamesList.indexOf(appname); // get appname index } - if (getCurrComponent == iconComponent + appNameComponent || availablecomponentsList.get(iconComponent + appNameComponent) == null) + var oldint = getPreferences().getInt("component_enabled", 11); + var newint = Integer.parseInt(iconComponent + "" + appNameComponent); + + if (oldint == newint) return; // check if current component is equal to custom value or if custom value is not exist - componentSwitcher("id" + getCurrComponent, false); // disable current component to prevent conflict with custom value + componentSwitcher("id" + oldint, false); // disable current component to prevent conflict with custom value - edit().putInt("component_enabled", iconComponent + appNameComponent).commit(); // save custom value + edit().putInt("component_enabled", newint).commit(); // save custom value - componentSwitcher("id" + iconComponent + appNameComponent, true); // enable custom value + componentSwitcher("id" + newint, true); // enable custom value } } diff --git a/smali/AndroidManifest.xml b/smali/AndroidManifest.xml index 3d1623c94..ed4107d01 100644 --- a/smali/AndroidManifest.xml +++ b/smali/AndroidManifest.xml @@ -275,7 +275,7 @@ @@ -287,7 +287,7 @@ @@ -299,7 +299,7 @@ @@ -309,6 +309,258 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +