fix system theme changer
This commit is contained in:
@@ -1,12 +1,17 @@
|
||||
package ru.vtosters.lite.hooks.ui;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.res.Configuration;
|
||||
|
||||
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.Preferences;
|
||||
import ru.vtosters.lite.utils.ThemesUtils;
|
||||
|
||||
import static ru.vtosters.lite.utils.AndroidUtils.getCenterScreenCoords;
|
||||
|
||||
public class SystemThemeChangerHook {
|
||||
private static int sPrevUiMode = 0;
|
||||
|
||||
@@ -28,4 +33,24 @@ public class SystemThemeChangerHook {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void themeOnStart(Activity activity) {
|
||||
if (Preferences.systemtheme()) {
|
||||
var uiMode = activity.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
|
||||
if (uiMode == sPrevUiMode) return;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ import com.vtosters.lite.R;
|
||||
import com.vtosters.lite.data.ThemeTracker;
|
||||
import ru.vtosters.lite.deviceinfo.OEMDetector;
|
||||
import ru.vtosters.lite.hooks.VKUIHook;
|
||||
import ru.vtosters.lite.hooks.ui.SystemThemeChangerHook;
|
||||
import ru.vtosters.lite.themes.ThemesHacks;
|
||||
import ru.vtosters.lite.themes.ThemesManager;
|
||||
import ru.vtosters.lite.ui.wallpapers.WallpapersHooks;
|
||||
@@ -384,6 +385,8 @@ public class ThemesUtils {
|
||||
setTheme(VKTheme.VKAPP_DARK, activity);
|
||||
}
|
||||
}
|
||||
|
||||
SystemThemeChangerHook.themeOnStart(activity);
|
||||
}
|
||||
|
||||
public static void setNavbarColor(Window window, int i) {
|
||||
|
||||
@@ -546,18 +546,6 @@
|
||||
invoke-virtual {p0, p1, v0}, Landroidx/fragment/app/FragmentActivity;->startActivityForResult(Landroid/content/Intent;I)V
|
||||
|
||||
:goto_1
|
||||
# ru.vtosters.lite.hooks.ui.SystemThemeChangerHook.onThemeChanged(activity.getResources().getConfiguration());
|
||||
|
||||
invoke-virtual {p0}, Lcom/vtosters/lite/MainActivity;->getResources()Landroid/content/res/Resources;
|
||||
|
||||
move-result-object v0
|
||||
|
||||
invoke-virtual {v0}, Landroid/content/res/Resources;->getConfiguration()Landroid/content/res/Configuration;
|
||||
|
||||
move-result-object v0
|
||||
|
||||
invoke-static {v0}, Lru/vtosters/lite/hooks/ui/SystemThemeChangerHook;->onThemeChanged(Landroid/content/res/Configuration;)V
|
||||
|
||||
return-void
|
||||
.end method
|
||||
|
||||
|
||||
Reference in New Issue
Block a user