From 49c1ca45c8626988c6067f74fa2179080d00059e Mon Sep 17 00:00:00 2001 From: gdlbo <41114720+gdlbo@users.noreply.github.com> Date: Thu, 7 Jul 2022 16:26:19 +0300 Subject: [PATCH] IconManager codebase --- .../ru/vtosters/lite/utils/IconManager.java | 46 +++++++++++++++++++ .../ru/vtosters/lite/utils/JsonInjectors.java | 2 +- 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 app/src/main/java/ru/vtosters/lite/utils/IconManager.java diff --git a/app/src/main/java/ru/vtosters/lite/utils/IconManager.java b/app/src/main/java/ru/vtosters/lite/utils/IconManager.java new file mode 100644 index 000000000..4b192d801 --- /dev/null +++ b/app/src/main/java/ru/vtosters/lite/utils/IconManager.java @@ -0,0 +1,46 @@ +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 java.util.Arrays; +import java.util.List; + +public class IconManager{ + public static List icons = Arrays.asList( + "standard", "vt" // available icons list + ); + + public static List appnames = Arrays.asList( + "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 void iconSwitcher(String icon, String appname){ + var iconComponent = 1; // def value for standard icon + var appNameComponent = 1; // def value for standard appname + + var getCurrComponent = getPreferences().getInt("component_enabled", 11); // get current component value + + if(icons.contains(icon)){ // check if icon is exist + iconComponent = icons.indexOf(icon); // get icon index + } + + if(appnames.contains(appname)){ // check if appname is exist + appNameComponent = appnames.indexOf(appname); // get appname index + } + + if(getCurrComponent == iconComponent + appNameComponent || availablecomponents.get(iconComponent + appNameComponent) == null) return; // check if current component is equal to custom value or if custom value is not exist + + if(getCurrComponent != iconComponent + appNameComponent){ // check if current component is not equal to custom value + componentSwitcher("id." + getCurrComponent, false); // disable current component to prevent conflict with custom value + } + + edit().putInt("component_enabled", iconComponent + appNameComponent).commit(); // save custom value + + componentSwitcher("id." + iconComponent + appNameComponent, true); // enable custom value + } +} diff --git a/app/src/main/java/ru/vtosters/lite/utils/JsonInjectors.java b/app/src/main/java/ru/vtosters/lite/utils/JsonInjectors.java index 83f5311a5..05dd14ab7 100644 --- a/app/src/main/java/ru/vtosters/lite/utils/JsonInjectors.java +++ b/app/src/main/java/ru/vtosters/lite/utils/JsonInjectors.java @@ -36,7 +36,7 @@ public class JsonInjectors{ } public static JSONObject convBar(JSONObject orig) throws JSONException{ - if(!dev()) return orig.optJSONObject("conversation_bar"); + if(!dev()) return orig.optJSONObject("conversation_bar"); // TODO Make it server-side var peerid = Objects.requireNonNull(orig.optJSONObject("peer")).optInt("id"); var pic = "https://image.pngaaa.com/641/326641-middle.png"; // can be null