From d60900e2f9cbe1697fa5ef19e311fd93903cbc7a Mon Sep 17 00:00:00 2001 From: Thomas Date: Sat, 23 Dec 2023 16:37:47 +0100 Subject: [PATCH] Fix custom colors for Android 14 --- app/src/main/java/app/fedilab/android/BaseMainActivity.java | 2 ++ .../fedilab/android/mastodon/activities/BaseActivity.java | 5 ++++- .../fedilab/android/mastodon/activities/BaseBarActivity.java | 4 +++- .../android/mastodon/activities/BaseTransparentActivity.java | 4 +++- .../app/fedilab/android/mastodon/helper/SpannableHelper.java | 2 +- .../app/fedilab/android/mastodon/helper/ThemeHelper.java | 2 +- .../android/mastodon/ui/drawer/ConversationAdapter.java | 3 ++- .../android/mastodon/ui/drawer/NotificationAdapter.java | 3 +-- .../fedilab/android/mastodon/ui/drawer/StatusAdapter.java | 2 +- 9 files changed, 18 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/app/fedilab/android/BaseMainActivity.java b/app/src/main/java/app/fedilab/android/BaseMainActivity.java index 0e64e353b..850de4dec 100644 --- a/app/src/main/java/app/fedilab/android/BaseMainActivity.java +++ b/app/src/main/java/app/fedilab/android/BaseMainActivity.java @@ -36,6 +36,7 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.SharedPreferences; +import android.content.res.Configuration; import android.database.MatrixCursor; import android.graphics.PorterDuff; import android.graphics.drawable.BitmapDrawable; @@ -214,6 +215,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt public static BaseAccount currentAccount; public static iconLauncher mLauncher = iconLauncher.BUBBLES; public static boolean headerMenuOpen; + public static int currentNightMode; Fragment currentFragment; private AppBarConfiguration mAppBarConfiguration; private ActivityMainBinding binding; diff --git a/app/src/main/java/app/fedilab/android/mastodon/activities/BaseActivity.java b/app/src/main/java/app/fedilab/android/mastodon/activities/BaseActivity.java index 963f7a338..6ab76c086 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/activities/BaseActivity.java +++ b/app/src/main/java/app/fedilab/android/mastodon/activities/BaseActivity.java @@ -15,6 +15,8 @@ package app.fedilab.android.mastodon.activities; * see . */ +import static app.fedilab.android.BaseMainActivity.currentNightMode; + import android.annotation.SuppressLint; import android.content.Context; import android.content.SharedPreferences; @@ -37,6 +39,7 @@ import org.conscrypt.Conscrypt; import java.security.Security; +import app.fedilab.android.BaseMainActivity; import app.fedilab.android.R; import app.fedilab.android.mastodon.helper.Helper; import app.fedilab.android.mastodon.helper.ThemeHelper; @@ -70,7 +73,7 @@ public class BaseActivity extends AppCompatActivity { String currentTheme = sharedpreferences.getString(getString(R.string.SET_THEME_BASE), getString(R.string.SET_DEFAULT_THEME)); //Default automatic switch - int currentNightMode = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK; + currentNightMode = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK; if (currentTheme.equals(getString(R.string.SET_DEFAULT_THEME))) { switch (currentNightMode) { case Configuration.UI_MODE_NIGHT_NO -> { diff --git a/app/src/main/java/app/fedilab/android/mastodon/activities/BaseBarActivity.java b/app/src/main/java/app/fedilab/android/mastodon/activities/BaseBarActivity.java index eb50d386e..6a1dc0fad 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/activities/BaseBarActivity.java +++ b/app/src/main/java/app/fedilab/android/mastodon/activities/BaseBarActivity.java @@ -15,6 +15,8 @@ package app.fedilab.android.mastodon.activities; * see . */ +import static app.fedilab.android.BaseMainActivity.currentNightMode; + import android.annotation.SuppressLint; import android.content.Context; import android.content.SharedPreferences; @@ -65,7 +67,7 @@ public class BaseBarActivity extends AppCompatActivity { } String currentTheme = sharedpreferences.getString(getString(R.string.SET_THEME_BASE), getString(R.string.SET_DEFAULT_THEME)); //Default automatic switch - int currentNightMode = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK; + currentNightMode = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK; if (currentTheme.equals(getString(R.string.SET_DEFAULT_THEME))) { switch (currentNightMode) { case Configuration.UI_MODE_NIGHT_NO -> { diff --git a/app/src/main/java/app/fedilab/android/mastodon/activities/BaseTransparentActivity.java b/app/src/main/java/app/fedilab/android/mastodon/activities/BaseTransparentActivity.java index 6da2715e7..28f76db53 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/activities/BaseTransparentActivity.java +++ b/app/src/main/java/app/fedilab/android/mastodon/activities/BaseTransparentActivity.java @@ -15,6 +15,8 @@ package app.fedilab.android.mastodon.activities; * see . */ +import static app.fedilab.android.BaseMainActivity.currentNightMode; + import android.annotation.SuppressLint; import android.content.Context; import android.content.SharedPreferences; @@ -65,7 +67,7 @@ public class BaseTransparentActivity extends AppCompatActivity { } String currentTheme = sharedpreferences.getString(getString(R.string.SET_THEME_BASE), getString(R.string.SET_DEFAULT_THEME)); //Default automatic switch - int currentNightMode = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK; + currentNightMode = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK; if (currentTheme.equals(getString(R.string.SET_DEFAULT_THEME))) { switch (currentNightMode) { diff --git a/app/src/main/java/app/fedilab/android/mastodon/helper/SpannableHelper.java b/app/src/main/java/app/fedilab/android/mastodon/helper/SpannableHelper.java index c9918a702..de58d977a 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/helper/SpannableHelper.java +++ b/app/src/main/java/app/fedilab/android/mastodon/helper/SpannableHelper.java @@ -16,6 +16,7 @@ package app.fedilab.android.mastodon.helper; import static app.fedilab.android.BaseMainActivity.currentAccount; +import static app.fedilab.android.BaseMainActivity.currentNightMode; import android.app.Activity; import android.content.ClipData; @@ -113,7 +114,6 @@ public class SpannableHelper { return null; } SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context); - int currentNightMode = context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK; boolean customLight = sharedpreferences.getBoolean(context.getString(R.string.SET_CUSTOMIZE_LIGHT_COLORS), false); boolean customDark = sharedpreferences.getBoolean(context.getString(R.string.SET_CUSTOMIZE_DARK_COLORS), false); underlineLinks = sharedpreferences.getBoolean(context.getString(R.string.SET_UNDERLINE_CLICKABLE), false); diff --git a/app/src/main/java/app/fedilab/android/mastodon/helper/ThemeHelper.java b/app/src/main/java/app/fedilab/android/mastodon/helper/ThemeHelper.java index be9ebd975..db4c32fd5 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/helper/ThemeHelper.java +++ b/app/src/main/java/app/fedilab/android/mastodon/helper/ThemeHelper.java @@ -16,6 +16,7 @@ package app.fedilab.android.mastodon.helper; import static android.content.Context.WINDOW_SERVICE; import static app.fedilab.android.BaseMainActivity.currentInstance; +import static app.fedilab.android.BaseMainActivity.currentNightMode; import static app.fedilab.android.BaseMainActivity.currentUserID; import android.app.Activity; @@ -286,7 +287,6 @@ public class ThemeHelper { } public static void applyThemeColor(Activity activity) { - int currentNightMode = activity.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK; final SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(activity); boolean dynamicColor = sharedpreferences.getBoolean(activity.getString(R.string.SET_DYNAMICCOLOR), false); boolean customAccentEnabled = sharedpreferences.getBoolean(activity.getString(R.string.SET_CUSTOM_ACCENT) + currentUserID + currentInstance, false); diff --git a/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/ConversationAdapter.java b/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/ConversationAdapter.java index 3192d2863..08a2b11aa 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/ConversationAdapter.java +++ b/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/ConversationAdapter.java @@ -15,6 +15,8 @@ package app.fedilab.android.mastodon.ui.drawer; * see . */ +import static app.fedilab.android.BaseMainActivity.currentNightMode; + import android.annotation.SuppressLint; import android.content.Context; import android.content.Intent; @@ -72,7 +74,6 @@ public class ConversationAdapter extends RecyclerView.Adapter. */ +import static app.fedilab.android.BaseMainActivity.currentNightMode; import static app.fedilab.android.mastodon.ui.drawer.StatusAdapter.statusManagement; import android.app.Activity; @@ -82,7 +83,6 @@ public class NotificationAdapter extends RecyclerView.Adapter public static void applyColor(Context context, StatusViewHolder holder) { SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context); - int currentNightMode = context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK; boolean customLight = sharedpreferences.getBoolean(context.getString(R.string.SET_CUSTOMIZE_LIGHT_COLORS), false); boolean customDark = sharedpreferences.getBoolean(context.getString(R.string.SET_CUSTOMIZE_DARK_COLORS), false); int theme_icons_color = -1;