diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index b38b91d1..ea3259c4 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -288,15 +288,15 @@ android:name=".activities.InstanceActivity" android:configChanges="keyboardHidden|orientation|screenSize" android:label="@string/action_about_instance" - android:theme="@style/AlertDialog" /> + android:theme="@style/AppThemeAlertDialog" /> + android:theme="@style/AppThemeAlertDialog" /> + android:theme="@style/AppThemeAlertDialog" /> @@ -306,12 +306,12 @@ + android:theme="@style/Transparent" /> + android:theme="@style/AppThemeAlertDialog" /> Build.VERSION_CODES.N) { + final Configuration override = new Configuration(newBase.getResources().getConfiguration()); + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(newBase); + override.fontScale = prefs.getFloat(newBase.getString(R.string.SET_FONT_SCALE), 1.1f); + applyOverrideConfiguration(override); + } + super.attachBaseContext(newBase); + } } diff --git a/app/src/main/java/app/fedilab/android/activities/BaseAlertDialogActivity.java b/app/src/main/java/app/fedilab/android/activities/BaseAlertDialogActivity.java new file mode 100644 index 00000000..220526dc --- /dev/null +++ b/app/src/main/java/app/fedilab/android/activities/BaseAlertDialogActivity.java @@ -0,0 +1,123 @@ +package app.fedilab.android.activities; +/* Copyright 2021 Thomas Schneider + * + * This file is a part of Fedilab + * + * This program is free software; you can redistribute it and/or modify it under the terms of the + * GNU General Public License as published by the Free Software Foundation; either version 3 of the + * License, or (at your option) any later version. + * + * Fedilab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even + * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + * Public License for more details. + * + * You should have received a copy of the GNU General Public License along with Fedilab; if not, + * see . */ + + +import android.annotation.SuppressLint; +import android.content.Context; +import android.content.SharedPreferences; +import android.content.res.Configuration; +import android.os.Build; +import android.os.Bundle; + +import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.app.AppCompatDelegate; +import androidx.preference.PreferenceManager; + +import com.vanniktech.emoji.EmojiManager; +import com.vanniktech.emoji.one.EmojiOneProvider; + +import app.fedilab.android.R; +import app.fedilab.android.helper.Helper; +import app.fedilab.android.helper.ThemeHelper; + + +@SuppressLint("Registered") +public class BaseAlertDialogActivity extends AppCompatActivity { + + static { + Helper.installProvider(); + EmojiManager.install(new EmojiOneProvider()); + } + + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + + final SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(this); + String currentTheme = sharedpreferences.getString(getString(R.string.SET_THEME_BASE), getString(R.string.SET_DEFAULT_THEME)); + //Default automatic switch + if (currentTheme.equals(getString(R.string.SET_DEFAULT_THEME))) { + + int currentNightMode = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK; + switch (currentNightMode) { + case Configuration.UI_MODE_NIGHT_NO: + String defaultLight = sharedpreferences.getString(getString(R.string.SET_THEME_DEFAULT_LIGHT), "LIGHT"); + switch (defaultLight) { + case "LIGHT": + setTheme(R.style.AppThemeAlertDialog); + break; + case "SOLARIZED_LIGHT": + setTheme(R.style.SolarizedAlertDialog); + break; + } + break; + case Configuration.UI_MODE_NIGHT_YES: + String defaultDark = sharedpreferences.getString(getString(R.string.SET_THEME_DEFAULT_DARK), "DARK"); + switch (defaultDark) { + case "DARK": + setTheme(R.style.AppThemeAlertDialog); + break; + case "SOLARIZED_DARK": + setTheme(R.style.SolarizedAlertDialog); + break; + case "BLACK": + setTheme(R.style.BlackAlertDialog); + break; + } + break; + } + } else { + switch (currentTheme) { + case "LIGHT": + AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO); + setTheme(R.style.AppThemeAlertDialog); + break; + case "DARK": + AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES); + setTheme(R.style.AppThemeAlertDialog); + break; + case "SOLARIZED_LIGHT": + AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO); + setTheme(R.style.SolarizedAlertDialog); + break; + case "SOLARIZED_DARK": + AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES); + setTheme(R.style.SolarizedAlertDialog); + break; + case "BLACK": + AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES); + setTheme(R.style.BlackAlertDialog); + break; + } + } + super.onCreate(savedInstanceState); + if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.N) { + ThemeHelper.adjustFontScale(this, getResources().getConfiguration()); + } + Helper.setLocale(this); + } + + @Override + protected void attachBaseContext(Context newBase) { + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N) { + final Configuration override = new Configuration(newBase.getResources().getConfiguration()); + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(newBase); + override.fontScale = prefs.getFloat(newBase.getString(R.string.SET_FONT_SCALE), 1.1f); + applyOverrideConfiguration(override); + } + super.attachBaseContext(newBase); + } +} diff --git a/app/src/main/java/app/fedilab/android/activities/BaseBarActivity.java b/app/src/main/java/app/fedilab/android/activities/BaseBarActivity.java index 5c058f6d..dce37269 100644 --- a/app/src/main/java/app/fedilab/android/activities/BaseBarActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/BaseBarActivity.java @@ -16,8 +16,10 @@ package app.fedilab.android.activities; import android.annotation.SuppressLint; +import android.content.Context; import android.content.SharedPreferences; import android.content.res.Configuration; +import android.os.Build; import android.os.Bundle; import androidx.annotation.Nullable; @@ -102,8 +104,23 @@ public class BaseBarActivity extends AppCompatActivity { } } super.onCreate(savedInstanceState); - ThemeHelper.adjustFontScale(this, getResources().getConfiguration()); + if (android.os.Build.VERSION.SDK_INT <= Build.VERSION_CODES.N) { + ThemeHelper.adjustFontScale(this, getResources().getConfiguration()); + } Helper.setLocale(this); } + @Override + protected void attachBaseContext(Context newBase) { + + if (android.os.Build.VERSION.SDK_INT > Build.VERSION_CODES.N) { + final Configuration override = new Configuration(newBase.getResources().getConfiguration()); + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(newBase); + override.fontScale = prefs.getFloat(newBase.getString(R.string.SET_FONT_SCALE), 1.1f); + applyOverrideConfiguration(override); + } + + + super.attachBaseContext(newBase); + } } diff --git a/app/src/main/java/app/fedilab/android/activities/BaseTransparentActivity.java b/app/src/main/java/app/fedilab/android/activities/BaseTransparentActivity.java new file mode 100644 index 00000000..12f89e80 --- /dev/null +++ b/app/src/main/java/app/fedilab/android/activities/BaseTransparentActivity.java @@ -0,0 +1,126 @@ +package app.fedilab.android.activities; +/* Copyright 2022 Thomas Schneider + * + * This file is a part of Fedilab + * + * This program is free software; you can redistribute it and/or modify it under the terms of the + * GNU General Public License as published by the Free Software Foundation; either version 3 of the + * License, or (at your option) any later version. + * + * Fedilab is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even + * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + * Public License for more details. + * + * You should have received a copy of the GNU General Public License along with Fedilab; if not, + * see . */ + + +import android.annotation.SuppressLint; +import android.content.Context; +import android.content.SharedPreferences; +import android.content.res.Configuration; +import android.os.Build; +import android.os.Bundle; + +import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.app.AppCompatDelegate; +import androidx.preference.PreferenceManager; + +import com.vanniktech.emoji.EmojiManager; +import com.vanniktech.emoji.one.EmojiOneProvider; + +import app.fedilab.android.R; +import app.fedilab.android.helper.Helper; +import app.fedilab.android.helper.ThemeHelper; + + +@SuppressLint("Registered") +public class BaseTransparentActivity extends AppCompatActivity { + + static { + Helper.installProvider(); + EmojiManager.install(new EmojiOneProvider()); + } + + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + final SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(this); + String currentTheme = sharedpreferences.getString(getString(R.string.SET_THEME_BASE), getString(R.string.SET_DEFAULT_THEME)); + //Default automatic switch + if (currentTheme.equals(getString(R.string.SET_DEFAULT_THEME))) { + + int currentNightMode = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK; + switch (currentNightMode) { + case Configuration.UI_MODE_NIGHT_NO: + String defaultLight = sharedpreferences.getString(getString(R.string.SET_THEME_DEFAULT_LIGHT), "LIGHT"); + switch (defaultLight) { + case "LIGHT": + setTheme(R.style.Transparent); + break; + case "SOLARIZED_LIGHT": + setTheme(R.style.TransparentSolarized); + break; + } + break; + case Configuration.UI_MODE_NIGHT_YES: + String defaultDark = sharedpreferences.getString(getString(R.string.SET_THEME_DEFAULT_DARK), "DARK"); + switch (defaultDark) { + case "DARK": + setTheme(R.style.Transparent); + break; + case "SOLARIZED_DARK": + setTheme(R.style.TransparentSolarized); + break; + case "BLACK": + setTheme(R.style.TransparentBlack); + break; + } + break; + } + + } else { + switch (currentTheme) { + case "LIGHT": + AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO); + setTheme(R.style.Transparent); + break; + case "DARK": + AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES); + setTheme(R.style.Transparent); + break; + case "SOLARIZED_LIGHT": + AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO); + setTheme(R.style.TransparentSolarized); + break; + case "SOLARIZED_DARK": + AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES); + setTheme(R.style.TransparentSolarized); + break; + case "BLACK": + AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES); + setTheme(R.style.TransparentBlack); + break; + } + } + super.onCreate(savedInstanceState); + if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.N) { + ThemeHelper.adjustFontScale(this, getResources().getConfiguration()); + } + Helper.setLocale(this); + } + + @Override + protected void attachBaseContext(Context newBase) { + + if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N) { + final Configuration override = new Configuration(newBase.getResources().getConfiguration()); + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(newBase); + override.fontScale = prefs.getFloat(newBase.getString(R.string.SET_FONT_SCALE), 1.1f); + applyOverrideConfiguration(override); + } + + + super.attachBaseContext(newBase); + } +} diff --git a/app/src/main/java/app/fedilab/android/activities/InstanceActivity.java b/app/src/main/java/app/fedilab/android/activities/InstanceActivity.java index 3f16837d..27f13a7a 100644 --- a/app/src/main/java/app/fedilab/android/activities/InstanceActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/InstanceActivity.java @@ -48,7 +48,7 @@ import app.fedilab.android.helper.ThemeHelper; import app.fedilab.android.viewmodel.mastodon.InstancesVM; -public class InstanceActivity extends BaseActivity { +public class InstanceActivity extends BaseAlertDialogActivity { ActivityInstanceBinding binding; diff --git a/app/src/main/java/app/fedilab/android/activities/InstanceHealthActivity.java b/app/src/main/java/app/fedilab/android/activities/InstanceHealthActivity.java index 25f450c1..85de47a2 100644 --- a/app/src/main/java/app/fedilab/android/activities/InstanceHealthActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/InstanceHealthActivity.java @@ -37,7 +37,7 @@ import app.fedilab.android.helper.ThemeHelper; import app.fedilab.android.viewmodel.mastodon.InstanceSocialVM; -public class InstanceHealthActivity extends BaseActivity { +public class InstanceHealthActivity extends BaseAlertDialogActivity { private ActivityInstanceSocialBinding binding; diff --git a/app/src/main/java/app/fedilab/android/activities/InstanceProfileActivity.java b/app/src/main/java/app/fedilab/android/activities/InstanceProfileActivity.java index cc2ea674..327cf968 100644 --- a/app/src/main/java/app/fedilab/android/activities/InstanceProfileActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/InstanceProfileActivity.java @@ -31,7 +31,7 @@ import app.fedilab.android.helper.Helper; import app.fedilab.android.viewmodel.mastodon.NodeInfoVM; import es.dmoral.toasty.Toasty; -public class InstanceProfileActivity extends BaseActivity { +public class InstanceProfileActivity extends BaseAlertDialogActivity { private String instance; diff --git a/app/src/main/java/app/fedilab/android/activities/MediaActivity.java b/app/src/main/java/app/fedilab/android/activities/MediaActivity.java index 16a9f538..2577ac92 100644 --- a/app/src/main/java/app/fedilab/android/activities/MediaActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/MediaActivity.java @@ -68,7 +68,7 @@ import app.fedilab.android.ui.fragment.media.FragmentMedia; import es.dmoral.toasty.Toasty; -public class MediaActivity extends BaseActivity implements OnDownloadInterface { +public class MediaActivity extends BaseTransparentActivity implements OnDownloadInterface { int flags; private ArrayList attachments; diff --git a/app/src/main/java/app/fedilab/android/activities/ProxyActivity.java b/app/src/main/java/app/fedilab/android/activities/ProxyActivity.java index f039f13d..2ffa6120 100644 --- a/app/src/main/java/app/fedilab/android/activities/ProxyActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/ProxyActivity.java @@ -29,7 +29,7 @@ import app.fedilab.android.R; import app.fedilab.android.databinding.ActivityProxyBinding; -public class ProxyActivity extends BaseActivity { +public class ProxyActivity extends BaseAlertDialogActivity { private ActivityProxyBinding binding; private int position; diff --git a/app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentThemingSettings.java b/app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentThemingSettings.java index 019cda75..ebe91c19 100644 --- a/app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentThemingSettings.java +++ b/app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentThemingSettings.java @@ -63,6 +63,7 @@ public class FragmentThemingSettings extends PreferenceFragmentCompat implements if (SET_THEME_BASE != null) { ThemeHelper.switchTo(SET_THEME_BASE.getValue()); requireActivity().recreate(); + Helper.recreateMainActivity(requireActivity()); } } //TODO: check if can be removed diff --git a/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java b/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java index 4da7fedc..23651375 100644 --- a/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java +++ b/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonTimeline.java @@ -210,16 +210,15 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter. if (initialStatuses != null) { initializeStatusesCommonView(initialStatuses); } else { - router(null); } } else { if (isNotPinnedTimeline && lockForResumeCall == 0) { router(null); lockForResumeCall++; - } else if (!isNotPinnedTimeline) { + } /*else if (!isNotPinnedTimeline) { router(null); - } + }*/ } if (timelineStatuses != null && timelineStatuses.size() > 0) { route(DIRECTION.FETCH_NEW, true); diff --git a/app/src/main/res/values-night/themes.xml b/app/src/main/res/values-night/themes.xml index 6a2a76ee..c4cddf76 100644 --- a/app/src/main/res/values-night/themes.xml +++ b/app/src/main/res/values-night/themes.xml @@ -28,9 +28,7 @@ @color/md_theme_dark_inverseOnSurface @color/md_theme_dark_inversePrimary - - ?attr/background - ?attr/background + ?android:colorBackground false false false @@ -40,16 +38,13 @@ @android:transition/explode @android:transition/explode - - @transition/change_image_transform + @transition/change_image_transform - - @transition/change_image_transform + @transition/change_image_transform - - - + + + + + + + + @@ -75,28 +70,50 @@ @color/md_theme_light_inverseOnSurface @color/md_theme_light_inversePrimary - ?attr/background - ?attr/background + ?android:colorBackground true true true - - - + + +