fixed issue with system theme applying + crashes
This commit is contained in:
@@ -8,6 +8,7 @@ import com.vk.core.dialogs.alert.VkAlertDialog;
|
||||
import com.vtosters.lite.R;
|
||||
import ru.vtosters.lite.concurrent.VTExecutors;
|
||||
import ru.vtosters.lite.downloaders.notifications.NotificationChannels;
|
||||
import ru.vtosters.lite.hooks.ui.SystemThemeChangerHook;
|
||||
import ru.vtosters.lite.ssfs.UsersList;
|
||||
import ru.vtosters.lite.themes.ThemesManager;
|
||||
import ru.vtosters.lite.ui.dialogs.DisableBattery;
|
||||
@@ -20,11 +21,9 @@ import static ru.vtosters.lite.ui.dialogs.ServerDialog.sendRequest;
|
||||
import static ru.vtosters.lite.utils.CacheUtils.getInstance;
|
||||
import static ru.vtosters.lite.utils.NewsFeedFiltersUtils.setupFilters;
|
||||
import static ru.vtosters.lite.utils.Preferences.checkupdates;
|
||||
import static ru.vtosters.lite.utils.ThemesUtils.setNeededTheme;
|
||||
|
||||
public class MainActivityInjector {
|
||||
public static void inject(Activity activity) {
|
||||
setNeededTheme(activity);
|
||||
sendRequest();
|
||||
UsersList.getUsersList();
|
||||
|
||||
|
||||
@@ -7,18 +7,16 @@ import com.vk.core.ui.themes.VKTheme;
|
||||
|
||||
import com.vk.core.ui.themes.VKThemeHelper;
|
||||
import com.vtosters.lite.data.ThemeTracker;
|
||||
import ru.vtosters.lite.utils.LifecycleUtils;
|
||||
import ru.vtosters.lite.utils.Preferences;
|
||||
import ru.vtosters.lite.utils.ThemesUtils;
|
||||
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getCenterScreenCoords;
|
||||
|
||||
public class SystemThemeChangerHook {
|
||||
private static int sPrevUiMode = 0;
|
||||
|
||||
public static void onThemeChanged(Configuration configuration) {
|
||||
if (Preferences.systemtheme()) {
|
||||
var uiMode = configuration.uiMode & Configuration.UI_MODE_NIGHT_MASK;
|
||||
if (uiMode == sPrevUiMode) return;
|
||||
|
||||
VKTheme theme = null;
|
||||
if (uiMode == Configuration.UI_MODE_NIGHT_YES)
|
||||
@@ -29,28 +27,13 @@ public class SystemThemeChangerHook {
|
||||
|
||||
if (theme != null && theme != ThemesUtils.getCurrentTheme()) {
|
||||
ThemesUtils.applyTheme(theme);
|
||||
sPrevUiMode = uiMode;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void themeOnStart(Activity activity) {
|
||||
if (Preferences.systemtheme()) {
|
||||
var uiMode = activity.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
|
||||
if (uiMode == sPrevUiMode) return;
|
||||
if (activity == null) activity = LifecycleUtils.getCurrentActivity();
|
||||
|
||||
VKTheme theme = null;
|
||||
if (uiMode == Configuration.UI_MODE_NIGHT_YES)
|
||||
theme = ThemesUtils.getDarkTheme();
|
||||
else if (uiMode == Configuration.UI_MODE_NIGHT_UNDEFINED
|
||||
|| uiMode == Configuration.UI_MODE_NIGHT_NO)
|
||||
theme = ThemesUtils.getLightTheme();
|
||||
|
||||
if (theme != null && theme != ThemesUtils.getCurrentTheme()) {
|
||||
VKThemeHelper.theme(theme, activity, getCenterScreenCoords());
|
||||
ThemeTracker.a();
|
||||
sPrevUiMode = uiMode;
|
||||
}
|
||||
}
|
||||
onThemeChanged(activity.getResources().getConfiguration());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,13 +14,13 @@ public class ThemeChanging {
|
||||
.setMessage(R.string.system_theme_warning)
|
||||
.setCancelable(false)
|
||||
.setPositiveButton(R.string.proxy_disable, (dialogInterface, i) -> { // Отключить
|
||||
ThemesUtils.setThemeFL(!ThemesUtils.isDarkTheme() ? ThemesUtils.getDarkTheme() : ThemesUtils.getLightTheme(), activity, f);
|
||||
ThemesUtils.setThemeFL(!ThemesUtils.isDarkTheme() ? ThemesUtils.getDarkTheme() : ThemesUtils.getLightTheme(), activity, f, true);
|
||||
Preferences.getPreferences().edit().putBoolean("system_theme", false).commit();
|
||||
})
|
||||
.setNeutralButton(R.string.cancel, null)
|
||||
.show();
|
||||
} else {
|
||||
ThemesUtils.setThemeFL(!ThemesUtils.isDarkTheme() ? ThemesUtils.getDarkTheme() : ThemesUtils.getLightTheme(), activity, f);
|
||||
ThemesUtils.setThemeFL(!ThemesUtils.isDarkTheme() ? ThemesUtils.getDarkTheme() : ThemesUtils.getLightTheme(), activity, f, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ public class VTSettings extends TrackedMaterialPreferenceToolbarFragment impleme
|
||||
}
|
||||
|
||||
private void switchTheme(boolean isDarkTheme) {
|
||||
ThemesUtils.setTheme(isDarkTheme ? ThemesUtils.getDarkTheme() : ThemesUtils.getLightTheme(), requireActivity());
|
||||
ThemesUtils.setTheme(isDarkTheme ? ThemesUtils.getDarkTheme() : ThemesUtils.getLightTheme(), requireActivity(), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -42,7 +42,7 @@ import static ru.vtosters.lite.utils.Preferences.*;
|
||||
public class ThemesUtils {
|
||||
public static void applyTheme(VKTheme theme) {
|
||||
try {
|
||||
setTheme(theme, LifecycleUtils.getCurrentActivity());
|
||||
setTheme(theme, LifecycleUtils.getCurrentActivity(), true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -64,16 +64,16 @@ public class ThemesUtils {
|
||||
AppCompatDelegate.setDefaultNightMode(theme);
|
||||
}
|
||||
|
||||
public static void setTheme(VKTheme theme, Activity activity) {
|
||||
setThemeFL(theme, activity, getCenterScreenCoords());
|
||||
public static void setTheme(VKTheme theme, Activity activity, Boolean restartActivity) {
|
||||
setThemeFL(theme, activity, getCenterScreenCoords(), restartActivity);
|
||||
} // apply changed theme
|
||||
|
||||
public static void setThemeFL(VKTheme theme, Activity activity, float[] fl) {
|
||||
public static void setThemeFL(VKTheme theme, Activity activity, float[] fl, Boolean restartActivity) {
|
||||
if (activity == null) {
|
||||
activity = LifecycleUtils.getCurrentActivity();
|
||||
}
|
||||
VKThemeHelper.theme(theme, activity, fl);
|
||||
activity.recreate();
|
||||
if (restartActivity) activity.recreate();
|
||||
ThemeTracker.a();
|
||||
VKUIHook.isLoaded = false;
|
||||
new WebView(activity).clearCache(true);
|
||||
@@ -373,29 +373,6 @@ public class ThemesUtils {
|
||||
return VKThemeHelper.l();
|
||||
}
|
||||
|
||||
public static void setNeededTheme(Activity activity) {
|
||||
var currentTheme = getCurrentTheme();
|
||||
if (milkshake()) {
|
||||
if (currentTheme == VKTheme.VKAPP_LIGHT) {
|
||||
setTheme(VKTheme.VKAPP_MILK_LIGHT, activity);
|
||||
}
|
||||
|
||||
if (currentTheme == VKTheme.VKAPP_DARK) {
|
||||
setTheme(VKTheme.VKAPP_MILK_DARK, activity);
|
||||
}
|
||||
} else {
|
||||
if (currentTheme == VKTheme.VKAPP_MILK_LIGHT) {
|
||||
setTheme(VKTheme.VKAPP_LIGHT, activity);
|
||||
}
|
||||
|
||||
if (currentTheme == VKTheme.VKAPP_MILK_DARK) {
|
||||
setTheme(VKTheme.VKAPP_DARK, activity);
|
||||
}
|
||||
}
|
||||
|
||||
SystemThemeChangerHook.themeOnStart(activity);
|
||||
}
|
||||
|
||||
public static void setNavbarColor(Window window, int i) {
|
||||
if (navbar()) {
|
||||
window.setNavigationBarColor(getTabbarBackground());
|
||||
|
||||
@@ -546,6 +546,8 @@
|
||||
invoke-virtual {p0, p1, v0}, Landroidx/fragment/app/FragmentActivity;->startActivityForResult(Landroid/content/Intent;I)V
|
||||
|
||||
:goto_1
|
||||
invoke-static {p0}, Lru/vtosters/lite/hooks/ui/SystemThemeChangerHook;->themeOnStart(Landroid/app/Activity;)V
|
||||
|
||||
return-void
|
||||
.end method
|
||||
|
||||
|
||||
Reference in New Issue
Block a user