refactored icon switcher
This commit is contained in:
@@ -16,9 +16,6 @@ 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;
|
||||
@@ -70,6 +67,7 @@ import ru.vtosters.lite.ui.fragments.tgstickers.StickersFragment;
|
||||
import ru.vtosters.lite.ui.vkui.VBottomSheetBuilder;
|
||||
import ru.vtosters.lite.utils.CacheUtils;
|
||||
import ru.vtosters.lite.utils.Globals;
|
||||
import ru.vtosters.lite.utils.IconManager;
|
||||
import ru.vtosters.lite.utils.SSFS;
|
||||
import ru.vtosters.lite.utils.VKUIwrapper;
|
||||
|
||||
@@ -187,7 +185,7 @@ 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");
|
||||
IconManager.switchComponent(o.toString(), "standard");
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -120,11 +120,6 @@ public class Globals{
|
||||
fos.write(content);
|
||||
}
|
||||
|
||||
public static void componentSwitcher(String component, Boolean enabled){
|
||||
var packageManager = Objects.requireNonNull(getContext()).getPackageManager();
|
||||
packageManager.setComponentEnabledSetting(new ComponentName(getPackageName(), getPackageName() + "." + component), enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
|
||||
} // Component switcher for changing app icon
|
||||
|
||||
public static String getPrefsValue(String pref){
|
||||
return getPreferences().getString(pref, "");
|
||||
} // Get pref value as string
|
||||
|
||||
@@ -1,86 +1,98 @@
|
||||
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.getContext;
|
||||
import static ru.vtosters.lite.utils.Globals.getPackageName;
|
||||
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.content.ComponentName;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class IconManager{
|
||||
public static List<String> icons = Arrays.asList(
|
||||
"standard", "vt" // available icons list
|
||||
public class IconManager {
|
||||
|
||||
// available icons list
|
||||
public static List<String> sIcons = Arrays.asList(
|
||||
"standard", "vt"
|
||||
);
|
||||
|
||||
public static List<String> appnames = Arrays.asList(
|
||||
"standard", "vt", "vkontakte" // available appnames list
|
||||
// available labels list
|
||||
public static List<String> sLabels = Arrays.asList(
|
||||
"standard", "vt", "vkontakte"
|
||||
);
|
||||
|
||||
public static List<String> iconsPlus = Arrays.asList(
|
||||
"standard", "vt", "navy", "tiger", "spring", "sea", "sakura", "party", "paint", "flamingo" // available icons list for verified users
|
||||
// available icons list for verified users
|
||||
public static List<String> sIconsPlus = Arrays.asList(
|
||||
"standard", "vt", "navy", "tiger", "spring", "sea", "sakura", "party", "paint", "flamingo"
|
||||
);
|
||||
|
||||
public static List<String> appnamesPlus = Arrays.asList(
|
||||
"standard", "vt", "vkontakte" // available appnames list for verified users
|
||||
// available labels list for verified users
|
||||
public static List<String> sLabelsPlus = Arrays.asList(
|
||||
"standard", "vt", "vkontakte"
|
||||
);
|
||||
|
||||
public static CharSequence[] icons() {
|
||||
var iconsList = icons;
|
||||
|
||||
if (hasVerification() && isValidSignature()) {
|
||||
iconsList = iconsPlus;
|
||||
}
|
||||
|
||||
return iconsList.toArray(new CharSequence[0]);
|
||||
return (hasVerification() && isValidSignature() ? sIconsPlus : sIcons).toArray(new CharSequence[0]);
|
||||
}
|
||||
|
||||
public static CharSequence[] iconsValues() {
|
||||
var iconsList = icons;
|
||||
|
||||
|
||||
if (hasVerification() && isValidSignature()) {
|
||||
iconsList = iconsPlus;
|
||||
}
|
||||
|
||||
return iconsList.toArray(new CharSequence[0]);
|
||||
return (hasVerification() && isValidSignature() ? sIconsPlus : sIcons).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
|
||||
public static void switchComponent(String icon, String appName) {
|
||||
// def value for standard icon
|
||||
var iconIndex = 1;
|
||||
// def value for standard label
|
||||
var labelIndex = 1;
|
||||
|
||||
Log.d("IconManager", "iconSwitcher: icon = " + icon + ", appname = " + appname);
|
||||
Log.d("IconManager", "iconSwitcher: icon = " + icon + ", appname = " + appName);
|
||||
|
||||
var iconsList = icons;
|
||||
var appnamesList = appnames;
|
||||
List<String> iconsList;
|
||||
List<String> labelsList;
|
||||
|
||||
if (hasVerification() && isValidSignature()) {
|
||||
iconsList = iconsPlus;
|
||||
appnamesList = appnamesPlus;
|
||||
iconsList = sIconsPlus;
|
||||
labelsList = sLabelsPlus;
|
||||
} else {
|
||||
iconsList = sIcons;
|
||||
labelsList = sLabels;
|
||||
}
|
||||
|
||||
if (iconsList.contains(icon)) { // check if icon is exist
|
||||
iconComponent = iconsList.indexOf(icon); // get icon index
|
||||
}
|
||||
// check if icon is exist
|
||||
if (iconsList.contains(icon))
|
||||
// get icon index
|
||||
iconIndex = iconsList.indexOf(icon);
|
||||
|
||||
if (appnamesList.contains(appname)) { // check if appname is exist
|
||||
appNameComponent = appnamesList.indexOf(appname); // get appname index
|
||||
}
|
||||
// check if labels is exist
|
||||
if (labelsList.contains(appName))
|
||||
// get labels index
|
||||
labelIndex = labelsList.indexOf(appName);
|
||||
|
||||
String oldint = getPreferences().getString("components_enabled", "11");
|
||||
String newint = iconComponent + "" + appNameComponent;
|
||||
String currentState = getPreferences().getString("components_enabled", "11");
|
||||
String newState = iconIndex + "" + labelIndex;
|
||||
|
||||
if (oldint == newint)
|
||||
return; // check if current component is equal to custom value or if custom value is not exist
|
||||
// check if current component is equal to custom value or if custom value is not exist
|
||||
if (currentState.equals(newState))
|
||||
return;
|
||||
|
||||
componentSwitcher("id" + oldint, false); // disable current component to prevent conflict with custom value
|
||||
// disable current component to prevent conflict with custom value
|
||||
switchIcon("id" + currentState, false);
|
||||
// save custom value
|
||||
edit().putString("components_enabled", newState).commit();
|
||||
// enable custom value
|
||||
switchIcon("id" + newState, true);
|
||||
}
|
||||
|
||||
edit().putString("components_enabled", newint).commit(); // save custom value
|
||||
|
||||
componentSwitcher("id" + newint, true); // enable custom value
|
||||
// Component switcher for changing app icon
|
||||
public static void switchIcon(String componentName, Boolean enabled) {
|
||||
getContext().getPackageManager().setComponentEnabledSetting(
|
||||
new ComponentName(getPackageName(), getPackageName() + "." + componentName),
|
||||
enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
|
||||
PackageManager.DONT_KILL_APP);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user