icon changer test

appname cursed
This commit is contained in:
gdlbo
2022-07-12 21:55:20 +03:00
parent 34787ffb5b
commit 7157a0c664
4 changed files with 304 additions and 22 deletions
@@ -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)
@@ -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();
@@ -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<String> 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<String> 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<String> appnamesPlus = Arrays.asList(
"standard", "vt", "vkontakte" // available appnames list for verified users
);
public static List<String> 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
}
}