From 8b614f786d6606c91ff0e02be1cdec2fc2617437 Mon Sep 17 00:00:00 2001 From: aliveoutside <53598473+aliveoutside@users.noreply.github.com> Date: Sun, 18 Sep 2022 00:54:22 +0300 Subject: [PATCH] 100% fix crash on start --- .../ru/vtosters/lite/utils/ThemesUtils.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/ru/vtosters/lite/utils/ThemesUtils.java b/app/src/main/java/ru/vtosters/lite/utils/ThemesUtils.java index b2453ed15..56dc058bb 100644 --- a/app/src/main/java/ru/vtosters/lite/utils/ThemesUtils.java +++ b/app/src/main/java/ru/vtosters/lite/utils/ThemesUtils.java @@ -46,7 +46,14 @@ public class ThemesUtils { ); public static void applyTheme(VKTheme theme) { - VKThemeHelper.theme(theme, LifecycleUtils.getCurrentActivity(), getCenterScreenCoords()); + var currentActivity = LifecycleUtils.getCurrentActivity(); + if (currentActivity != null) { + try { + VKThemeHelper.theme(theme, currentActivity, getCenterScreenCoords()); + } catch (Exception e) { + e.printStackTrace(); + } + } } // Apply VKTheme and ImTheme (hard applying without dynamic theme changing) public static void setTheme(VKTheme theme, Activity activity) { @@ -326,20 +333,21 @@ public class ThemesUtils { } public static void setNeededTheme(Activity activity) { + var currentTheme = getCurrentTheme(); if (milkshake()) { - if (getCurrentTheme() == VKTheme.VKAPP_LIGHT) { + if (currentTheme == VKTheme.VKAPP_LIGHT) { setTheme(VKTheme.VKAPP_MILK_LIGHT, activity); } - if (getCurrentTheme() == VKTheme.VKAPP_DARK) { + if (currentTheme == VKTheme.VKAPP_DARK) { setTheme(VKTheme.VKAPP_MILK_DARK, activity); } } else { - if (getCurrentTheme() == VKTheme.VKAPP_MILK_LIGHT) { + if (currentTheme == VKTheme.VKAPP_MILK_LIGHT) { setTheme(VKTheme.VKAPP_LIGHT, activity); } - if (getCurrentTheme() == VKTheme.VKAPP_MILK_DARK) { + if (currentTheme == VKTheme.VKAPP_MILK_DARK) { setTheme(VKTheme.VKAPP_DARK, activity); } }