diff --git a/app/src/main/java/ru/vtosters/lite/ui/fragments/IconsFragment.java b/app/src/main/java/ru/vtosters/lite/ui/fragments/IconsFragment.java new file mode 100644 index 000000000..a4c0fb9cb --- /dev/null +++ b/app/src/main/java/ru/vtosters/lite/ui/fragments/IconsFragment.java @@ -0,0 +1,132 @@ +package ru.vtosters.lite.ui.fragments; + +import static ru.vtosters.lite.utils.Globals.convertDpToPixel; +import static ru.vtosters.lite.utils.Globals.edit; +import static ru.vtosters.lite.utils.Globals.getDrawableFromUrl; +import static ru.vtosters.lite.utils.Globals.getIdentifier; +import static ru.vtosters.lite.utils.Globals.getPackageName; +import static ru.vtosters.lite.utils.Globals.getPrefsValue; +import static ru.vtosters.lite.utils.Globals.getUserPhoto; +import static ru.vtosters.lite.utils.Globals.getUsername; +import static ru.vtosters.lite.utils.Globals.restartApplication; +import static ru.vtosters.lite.utils.Globals.sendToast; +import static ru.vtosters.lite.utils.IconManager.*; +import static ru.vtosters.lite.utils.Preferences.DoNotUseOldIcons; +import static ru.vtosters.lite.utils.Preferences.hasVerification; +import static ru.vtosters.lite.utils.Preferences.preferences; +import static ru.vtosters.lite.utils.Proxy.isZaboronaEnabled; +import static ru.vtosters.lite.utils.Themes.getAccentColor; +import static ru.vtosters.lite.utils.Themes.getAlertStyle; +import static ru.vtosters.lite.utils.Themes.getTextAttr; + +import android.annotation.SuppressLint; +import android.content.Context; +import android.content.DialogInterface; +import android.content.Intent; +import android.os.Bundle; +import android.util.TypedValue; +import android.widget.RadioButton; +import android.widget.RadioGroup; + +import androidx.appcompat.app.AlertDialog; +import androidx.appcompat.view.ContextThemeWrapper; + +import com.vk.bridges.AuthBridge; +import com.vk.navigation.Navigator; +import com.vtosters.lite.fragments.w2.BlacklistFragment; +import com.vtosters.lite.general.fragments.MaterialPreferenceToolbarFragment; + +import ru.vtosters.lite.ui.PreferencesUtil; +import ru.vtosters.lite.utils.Globals; +import ru.vtosters.lite.utils.IconManager; + +public class IconsFragment extends MaterialPreferenceToolbarFragment{ + @SuppressLint("UseCompatLoadingForDrawables") + @Override + public void onCreate(Bundle bundle){ + super.onCreate(bundle); + PreferencesUtil.addPreferenceCategory(this, Globals.getString("sett_debug")); + + for (var i = 0; i < icons().size(); i++) { + if (icons().get(i) == null || iconsValues().get(i) == null) return; + + String icon = icons().get(i); + String iconname = iconsValues().get(i); + + PreferencesUtil.addPreference(this, icon, iconname, "", "ic_bug_outline_28", preference -> { + sendToast(icon); + + callSelectDialog(this.getContext(), icon); + return false; + }); + + } + } + + @SuppressLint("SetTextI18n") + public static void callSelectDialog(Context ctx, String appicon){ + RadioGroup rg = new RadioGroup(ctx); + + RadioButton rgDefault = new RadioButton(new ContextThemeWrapper(ctx, com.vtosters.lite.R.style.Widget_AppCompat_CompoundButton_RadioButton)); + RadioButton rgVK = new RadioButton(new ContextThemeWrapper(ctx, com.vtosters.lite.R.style.Widget_AppCompat_CompoundButton_RadioButton)); + RadioButton rgVKontakte = new RadioButton(new ContextThemeWrapper(ctx, com.vtosters.lite.R.style.Widget_AppCompat_CompoundButton_RadioButton)); + + rg.addView(rgDefault); + rg.addView(rgVK); + rg.addView(rgVKontakte); + + rgDefault.setTextSize(TypedValue.COMPLEX_UNIT_PX, convertDpToPixel(14f)); + rgVK.setTextSize(TypedValue.COMPLEX_UNIT_PX, convertDpToPixel(14f)); + rgVKontakte.setTextSize(TypedValue.COMPLEX_UNIT_PX, convertDpToPixel(14f)); + + rg.setPadding(convertDpToPixel(18f), convertDpToPixel(12f), convertDpToPixel(18f), 0); + + rgDefault.setText("VTLite"); + rgDefault.setTextColor(getTextAttr()); + + rgVK.setText("VK"); + rgVK.setTextColor(getTextAttr()); + + rgVKontakte.setText("VKontakte"); + rgVKontakte.setTextColor(getTextAttr()); + + rgVKontakte.setChecked(isZaboronaEnabled()); + rgVK.setChecked(isZaboronaEnabled()); + rgDefault.setChecked(!isZaboronaEnabled()); + + AlertDialog.Builder builder = new AlertDialog.Builder(ctx, getAlertStyle()); + builder.setTitle("Выберите название приложения"); + builder.setView(rg); + builder.setPositiveButton("Применить", ((dialog, which) -> { + var defname = preferences.getString("appname", "vt"); + var deficon = preferences.getString("selectedicon", "vt"); + + if (rgDefault.isChecked()) { + edit().putString("appname", "vt").commit(); + edit().putString("selectedicon", appicon).commit(); + + switchComponent(appicon, "vt", deficon, defname); + } else if (rgVK.isChecked()) { + edit().putString("appname", "vk").commit(); + edit().putString("selectedicon", appicon).commit(); + + switchComponent(appicon, "vk", deficon, defname); + } else if (rgVKontakte.isChecked()) { + edit().putString("appname", "vkontakte").commit(); + edit().putString("selectedicon", appicon).commit(); + + switchComponent(appicon, "vkontakte", deficon, defname); + } + })); + builder.setNegativeButton("Отмена", ((dialog, which) -> { + dialog.dismiss(); + })); + + var alert = builder.create(); + + alert.show(); + + alert.getButton(DialogInterface.BUTTON_POSITIVE).setTextColor(getAccentColor()); + alert.getButton(DialogInterface.BUTTON_NEUTRAL).setTextColor(getAccentColor()); + } +} diff --git a/app/src/main/java/ru/vtosters/lite/ui/fragments/ThemesFragment.java b/app/src/main/java/ru/vtosters/lite/ui/fragments/ThemesFragment.java index e6331050e..a780ae076 100644 --- a/app/src/main/java/ru/vtosters/lite/ui/fragments/ThemesFragment.java +++ b/app/src/main/java/ru/vtosters/lite/ui/fragments/ThemesFragment.java @@ -4,12 +4,17 @@ import static ru.vtosters.lite.utils.Globals.edit; import static ru.vtosters.lite.utils.Globals.getIdentifier; import static ru.vtosters.lite.utils.Globals.restartApplicationWithTimer; +import android.content.Context; +import android.content.Intent; import android.os.Bundle; import androidx.preference.Preference; +import com.vk.navigation.Navigator; import com.vtosters.lite.general.fragments.MaterialPreferenceToolbarFragment; +import ru.vtosters.lite.ui.wallpapers.WallpaperMenuFragment; + public class ThemesFragment extends MaterialPreferenceToolbarFragment{ @@ -25,6 +30,18 @@ public class ThemesFragment extends MaterialPreferenceToolbarFragment{ findPreference("milkshake").setOnPreferenceClickListener(new restart()); findPreference("darktheme").setOnPreferenceChangeListener(new restartdark()); findPreference("lighttheme").setOnPreferenceChangeListener(new restartlight()); + findPreference("iconmanager").setOnPreferenceClickListener(new openicons()); + } + + public class openicons implements Preference.OnPreferenceClickListener{ + @Override + public boolean onPreferenceClick(Preference preference){ + Context context = getContext(); + Intent a2 = new Navigator(IconsFragment.class).b(context); + a2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + context.startActivity(a2); + return true; + } } public static class restart implements Preference.OnPreferenceClickListener{ 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 620262ed9..4f7884737 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 @@ -184,14 +184,6 @@ 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(); - IconManager.switchComponent(o.toString(), "standard"); - return false; - }); - } - if (!isGmsInstalled()) { PreferencesUtil.addPreference(this, "", Globals.getString("installgms"), "", "ic_warning_24", 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 55ffbf386..f4e65c806 100644 --- a/app/src/main/java/ru/vtosters/lite/utils/IconManager.java +++ b/app/src/main/java/ru/vtosters/lite/utils/IconManager.java @@ -52,28 +52,25 @@ public class IconManager { "VK", "VTLite", "VKontakte" ); - public static CharSequence[] icons() { - return (hasVerification() && isValidSignature() ? sIconsPlusNames : sIconsNames).toArray(new CharSequence[0]); + public static List icons() { + return hasVerification() && isValidSignature() ? sIconsPlusNames : sIconsNames; } - public static CharSequence[] iconsValues() { - return (hasVerification() && isValidSignature() ? sIconsPlus : sIcons).toArray(new CharSequence[0]); + public static List iconsValues() { + return hasVerification() && isValidSignature() ? sIconsPlus : sIcons; } - public static CharSequence[] appname() { - return (hasVerification() && isValidSignature() ? sLabelsPlusNames : sLabelsNames).toArray(new CharSequence[0]); - } + public static void switchComponent(String icon, String appName, String oldIcon, String oldAppName) { - public static CharSequence[] appnameValues() { - return (hasVerification() && isValidSignature() ? sLabelsPlus : sLabels).toArray(new CharSequence[0]); - } - - public static void switchComponent(String icon, String appName) { // def value for standard icon var iconIndex = 1; // def value for standard label var labelIndex = 1; + var oldIconIndex = -1; + + var oldLabelIndex = -1; + Log.d("IconManager", "iconSwitcher: icon = " + icon + ", appname = " + appName); List iconsList; @@ -87,6 +84,11 @@ public class IconManager { labelsList = sLabels; } + if (oldIcon != null && oldAppName != null) { + oldIconIndex = iconsList.indexOf(oldIcon); + oldLabelIndex = labelsList.indexOf(oldAppName); + } + // check if icon is exist if (iconsList.contains(icon)) // get icon index @@ -98,6 +100,11 @@ public class IconManager { labelIndex = labelsList.indexOf(appName); String currentState = getPreferences().getString("components_enabled", "11"); + + if (oldIconIndex != -1 && oldLabelIndex != -1) { + currentState = oldIconIndex + "" + oldLabelIndex; + } + String newState = iconIndex + "" + labelIndex; // check if current component is equal to custom value or if custom value is not exist diff --git a/smali/res/xml/preferences_themes.xml b/smali/res/xml/preferences_themes.xml index 586f43bfd..30721ced1 100644 --- a/smali/res/xml/preferences_themes.xml +++ b/smali/res/xml/preferences_themes.xml @@ -26,6 +26,9 @@ android:title="@string/appearance_theme_light_theme" /> +