Loading app/src/main/java/app/fedilab/android/MainApplication.java +3 −0 Original line number Diff line number Diff line Loading @@ -30,6 +30,7 @@ import org.acra.config.DialogConfigurationBuilder; import org.acra.config.MailSenderConfigurationBuilder; import org.acra.data.StringFormat; import app.fedilab.android.helper.ThemeHelper; import es.dmoral.toasty.Toasty; Loading Loading @@ -68,6 +69,8 @@ public class MainApplication extends MultiDexApplication { MultiDex.install(MainApplication.this); SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(MainApplication.this); boolean send_crash_reports = sharedpreferences.getBoolean(getString(R.string.SET_SEND_CRASH_REPORTS), false); String currentTheme = sharedpreferences.getString(getString(R.string.SET_THEME_BASE), getString(R.string.SET_DEFAULT_THEME)); ThemeHelper.switchTo(currentTheme); if (send_crash_reports) { ACRA.init(this, new CoreConfigurationBuilder() //core configuration: Loading app/src/main/java/app/fedilab/android/helper/ThemeHelper.java +21 −0 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import android.content.res.ColorStateList; import android.content.res.Configuration; import android.content.res.Resources; import android.content.res.TypedArray; import android.os.Build; import android.util.DisplayMetrics; import android.util.TypedValue; import android.view.View; Loading @@ -32,6 +33,7 @@ import android.view.animation.TranslateAnimation; import androidx.annotation.AttrRes; import androidx.annotation.ColorInt; import androidx.appcompat.app.AppCompatDelegate; import androidx.core.content.ContextCompat; import androidx.preference.PreferenceManager; Loading Loading @@ -264,6 +266,25 @@ public class ThemeHelper { activity.getBaseContext().getResources().updateConfiguration(configuration, metrics); } public static void switchTo(String themePref) { if (themes.LIGHT.name().equals(themePref)) { AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO); } else if (themes.DARK.name().equals(themePref)) { AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES); } else { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM); } else { AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY); } } } public enum themes { LIGHT, DARK, SYSTEM } public interface SlideAnimation { void onAnimationEnded(); Loading app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentThemingSettings.java +8 −7 Original line number Diff line number Diff line Loading @@ -60,6 +60,7 @@ import java.util.List; import app.fedilab.android.R; import app.fedilab.android.activities.ComposeActivity; import app.fedilab.android.databinding.ActivityThemeSettingsBinding; import app.fedilab.android.databinding.PopupStatusThemeBinding; import app.fedilab.android.helper.Helper; import app.fedilab.android.helper.ThemeHelper; Loading @@ -72,7 +73,6 @@ public class FragmentThemingSettings extends PreferenceFragmentCompat implements private List<LinkedHashMap<String, String>> listOfThemes; private SharedPreferences appPref; private SharedPreferences cyneaPref; private boolean shouldRestart; @Override public void onCreatePreferences(Bundle bundle, String s) { Loading @@ -80,7 +80,6 @@ public class FragmentThemingSettings extends PreferenceFragmentCompat implements appPref = PreferenceManager.getDefaultSharedPreferences(requireActivity()); createPref(); listOfThemes = ThemeHelper.getContributorsTheme(requireActivity()); shouldRestart = false; } Loading Loading @@ -109,7 +108,12 @@ public class FragmentThemingSettings extends PreferenceFragmentCompat implements if (key.equals("use_custom_theme")) { createPref(); } shouldRestart = true; if (key.compareTo(getString(R.string.SET_THEME_BASE)) == 0) { ListPreference SET_THEME_BASE = findPreference(getString(R.string.SET_THEME_BASE)); if (SET_THEME_BASE != null) { ThemeHelper.switchTo(SET_THEME_BASE.getValue()); } } Helper.recreateMainActivity(requireActivity()); } Loading Loading @@ -300,8 +304,7 @@ public class FragmentThemingSettings extends PreferenceFragmentCompat implements Preference launch_custom_theme = findPreference("launch_custom_theme"); if (launch_custom_theme != null) { launch_custom_theme.setOnPreferenceClickListener(preference -> { shouldRestart = true; startActivity(new Intent(requireActivity(), ActivityThemeSettingsBinding.class)); return false; }); Loading Loading @@ -418,7 +421,6 @@ public class FragmentThemingSettings extends PreferenceFragmentCompat implements ComposeActivity.MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE); return true; } shouldRestart = true; Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.addCategory(Intent.CATEGORY_OPENABLE); intent.setType("*/*"); Loading @@ -439,7 +441,6 @@ public class FragmentThemingSettings extends PreferenceFragmentCompat implements createPref(); }); shouldRestart = true; dialogBuilder.setNegativeButton(R.string.cancel, (dialog, id) -> dialog.dismiss()); AlertDialog alertDialog = dialogBuilder.create(); alertDialog.setCancelable(false); Loading app/src/main/res/navigation/nav_graph_settings.xml +9 −5 Original line number Diff line number Diff line Loading @@ -55,7 +55,11 @@ <action android:id="@+id/categories_to_theming" app:destination="@id/ThemeSettingsActivity" /> app:destination="@id/FragmentThemingSettings" app:enterAnim="@anim/enter" app:exitAnim="@anim/exit" app:popEnterAnim="@anim/pop_enter" app:popExitAnim="@anim/pop_exit" /> <action android:id="@+id/categories_to_language" Loading Loading @@ -91,6 +95,10 @@ android:name="app.fedilab.android.ui.fragment.settings.FragmentPrivacySettings" android:label="@string/action_privacy" /> <fragment android:id="@+id/FragmentThemingSettings" android:name="app.fedilab.android.ui.fragment.settings.FragmentThemingSettings" android:label="@string/theming" /> <fragment android:id="@+id/FragmentLanguageSettings" Loading @@ -101,8 +109,4 @@ android:id="@+id/EditProfileActivity" android:name="app.fedilab.android.activities.EditProfileActivity" /> <activity android:id="@+id/ThemeSettingsActivity" android:name="app.fedilab.android.activities.ThemeSettingsActivity" /> </navigation> app/src/main/res/values/strings.xml +18 −0 Original line number Diff line number Diff line Loading @@ -695,6 +695,18 @@ <string name="not_valid_list_name">List name is not valid!</string> <string name="no_account_in_list">No accounts found for this list!</string> <string name="scheduled">Scheduled</string> <string-array name="set_theme_mode_value"> <item>Light</item> <item>Dark</item> <item>System default</item> </string-array> <string-array name="SET_THEME_MODE_VALUE" translatable="false"> <item>LIGHT</item> <item>DARK</item> <item>SYSTEM</item> </string-array> <string-array name="set_notification_type_value"> <item>Push notifications</item> <item>Fetch at fixed times</item> Loading Loading @@ -1252,6 +1264,9 @@ <string name="SET_SHOW_REPLIES" translatable="false">SET_SHOW_REPLIES</string> <string name="SET_DISABLE_ANIMATED_EMOJI" translatable="false">SET_DISABLE_ANIMATED_EMOJI</string> <string name="SET_CAPITALIZE" translatable="false">SET_CAPITALIZE</string> <string name="SET_THEME_BASE" translatable="false">SET_THEME_BASE</string> <string name="SET_DEFAULT_THEME" translatable="false">SYSTEM</string> <string name="SET_FULL_PREVIEW" translatable="false">SET_FULL_PREVIEW</string> <string name="SET_SHARE_DETAILS" translatable="false">SET_SHARE_DETAILS</string> <string name="SET_CUSTOM_SHARING" translatable="false">SET_CUSTOM_SHARING</string> Loading Loading @@ -1957,4 +1972,7 @@ <string name="saved_changes">Changes have been saved!</string> <string name="create_domain_block">Create domain block</string> <string name="mute_tag">Are you sure to mute the tag %1$s?</string> <string name="type_of_theme">Pickup a mode for the theme</string> <string name="pref_customize">Customize colors</string> <string name="pref_customize_summary">Allow to set your custom colors for themes.</string> </resources> No newline at end of file Loading
app/src/main/java/app/fedilab/android/MainApplication.java +3 −0 Original line number Diff line number Diff line Loading @@ -30,6 +30,7 @@ import org.acra.config.DialogConfigurationBuilder; import org.acra.config.MailSenderConfigurationBuilder; import org.acra.data.StringFormat; import app.fedilab.android.helper.ThemeHelper; import es.dmoral.toasty.Toasty; Loading Loading @@ -68,6 +69,8 @@ public class MainApplication extends MultiDexApplication { MultiDex.install(MainApplication.this); SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(MainApplication.this); boolean send_crash_reports = sharedpreferences.getBoolean(getString(R.string.SET_SEND_CRASH_REPORTS), false); String currentTheme = sharedpreferences.getString(getString(R.string.SET_THEME_BASE), getString(R.string.SET_DEFAULT_THEME)); ThemeHelper.switchTo(currentTheme); if (send_crash_reports) { ACRA.init(this, new CoreConfigurationBuilder() //core configuration: Loading
app/src/main/java/app/fedilab/android/helper/ThemeHelper.java +21 −0 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import android.content.res.ColorStateList; import android.content.res.Configuration; import android.content.res.Resources; import android.content.res.TypedArray; import android.os.Build; import android.util.DisplayMetrics; import android.util.TypedValue; import android.view.View; Loading @@ -32,6 +33,7 @@ import android.view.animation.TranslateAnimation; import androidx.annotation.AttrRes; import androidx.annotation.ColorInt; import androidx.appcompat.app.AppCompatDelegate; import androidx.core.content.ContextCompat; import androidx.preference.PreferenceManager; Loading Loading @@ -264,6 +266,25 @@ public class ThemeHelper { activity.getBaseContext().getResources().updateConfiguration(configuration, metrics); } public static void switchTo(String themePref) { if (themes.LIGHT.name().equals(themePref)) { AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO); } else if (themes.DARK.name().equals(themePref)) { AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES); } else { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM); } else { AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY); } } } public enum themes { LIGHT, DARK, SYSTEM } public interface SlideAnimation { void onAnimationEnded(); Loading
app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentThemingSettings.java +8 −7 Original line number Diff line number Diff line Loading @@ -60,6 +60,7 @@ import java.util.List; import app.fedilab.android.R; import app.fedilab.android.activities.ComposeActivity; import app.fedilab.android.databinding.ActivityThemeSettingsBinding; import app.fedilab.android.databinding.PopupStatusThemeBinding; import app.fedilab.android.helper.Helper; import app.fedilab.android.helper.ThemeHelper; Loading @@ -72,7 +73,6 @@ public class FragmentThemingSettings extends PreferenceFragmentCompat implements private List<LinkedHashMap<String, String>> listOfThemes; private SharedPreferences appPref; private SharedPreferences cyneaPref; private boolean shouldRestart; @Override public void onCreatePreferences(Bundle bundle, String s) { Loading @@ -80,7 +80,6 @@ public class FragmentThemingSettings extends PreferenceFragmentCompat implements appPref = PreferenceManager.getDefaultSharedPreferences(requireActivity()); createPref(); listOfThemes = ThemeHelper.getContributorsTheme(requireActivity()); shouldRestart = false; } Loading Loading @@ -109,7 +108,12 @@ public class FragmentThemingSettings extends PreferenceFragmentCompat implements if (key.equals("use_custom_theme")) { createPref(); } shouldRestart = true; if (key.compareTo(getString(R.string.SET_THEME_BASE)) == 0) { ListPreference SET_THEME_BASE = findPreference(getString(R.string.SET_THEME_BASE)); if (SET_THEME_BASE != null) { ThemeHelper.switchTo(SET_THEME_BASE.getValue()); } } Helper.recreateMainActivity(requireActivity()); } Loading Loading @@ -300,8 +304,7 @@ public class FragmentThemingSettings extends PreferenceFragmentCompat implements Preference launch_custom_theme = findPreference("launch_custom_theme"); if (launch_custom_theme != null) { launch_custom_theme.setOnPreferenceClickListener(preference -> { shouldRestart = true; startActivity(new Intent(requireActivity(), ActivityThemeSettingsBinding.class)); return false; }); Loading Loading @@ -418,7 +421,6 @@ public class FragmentThemingSettings extends PreferenceFragmentCompat implements ComposeActivity.MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE); return true; } shouldRestart = true; Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.addCategory(Intent.CATEGORY_OPENABLE); intent.setType("*/*"); Loading @@ -439,7 +441,6 @@ public class FragmentThemingSettings extends PreferenceFragmentCompat implements createPref(); }); shouldRestart = true; dialogBuilder.setNegativeButton(R.string.cancel, (dialog, id) -> dialog.dismiss()); AlertDialog alertDialog = dialogBuilder.create(); alertDialog.setCancelable(false); Loading
app/src/main/res/navigation/nav_graph_settings.xml +9 −5 Original line number Diff line number Diff line Loading @@ -55,7 +55,11 @@ <action android:id="@+id/categories_to_theming" app:destination="@id/ThemeSettingsActivity" /> app:destination="@id/FragmentThemingSettings" app:enterAnim="@anim/enter" app:exitAnim="@anim/exit" app:popEnterAnim="@anim/pop_enter" app:popExitAnim="@anim/pop_exit" /> <action android:id="@+id/categories_to_language" Loading Loading @@ -91,6 +95,10 @@ android:name="app.fedilab.android.ui.fragment.settings.FragmentPrivacySettings" android:label="@string/action_privacy" /> <fragment android:id="@+id/FragmentThemingSettings" android:name="app.fedilab.android.ui.fragment.settings.FragmentThemingSettings" android:label="@string/theming" /> <fragment android:id="@+id/FragmentLanguageSettings" Loading @@ -101,8 +109,4 @@ android:id="@+id/EditProfileActivity" android:name="app.fedilab.android.activities.EditProfileActivity" /> <activity android:id="@+id/ThemeSettingsActivity" android:name="app.fedilab.android.activities.ThemeSettingsActivity" /> </navigation>
app/src/main/res/values/strings.xml +18 −0 Original line number Diff line number Diff line Loading @@ -695,6 +695,18 @@ <string name="not_valid_list_name">List name is not valid!</string> <string name="no_account_in_list">No accounts found for this list!</string> <string name="scheduled">Scheduled</string> <string-array name="set_theme_mode_value"> <item>Light</item> <item>Dark</item> <item>System default</item> </string-array> <string-array name="SET_THEME_MODE_VALUE" translatable="false"> <item>LIGHT</item> <item>DARK</item> <item>SYSTEM</item> </string-array> <string-array name="set_notification_type_value"> <item>Push notifications</item> <item>Fetch at fixed times</item> Loading Loading @@ -1252,6 +1264,9 @@ <string name="SET_SHOW_REPLIES" translatable="false">SET_SHOW_REPLIES</string> <string name="SET_DISABLE_ANIMATED_EMOJI" translatable="false">SET_DISABLE_ANIMATED_EMOJI</string> <string name="SET_CAPITALIZE" translatable="false">SET_CAPITALIZE</string> <string name="SET_THEME_BASE" translatable="false">SET_THEME_BASE</string> <string name="SET_DEFAULT_THEME" translatable="false">SYSTEM</string> <string name="SET_FULL_PREVIEW" translatable="false">SET_FULL_PREVIEW</string> <string name="SET_SHARE_DETAILS" translatable="false">SET_SHARE_DETAILS</string> <string name="SET_CUSTOM_SHARING" translatable="false">SET_CUSTOM_SHARING</string> Loading Loading @@ -1957,4 +1972,7 @@ <string name="saved_changes">Changes have been saved!</string> <string name="create_domain_block">Create domain block</string> <string name="mute_tag">Are you sure to mute the tag %1$s?</string> <string name="type_of_theme">Pickup a mode for the theme</string> <string name="pref_customize">Customize colors</string> <string name="pref_customize_summary">Allow to set your custom colors for themes.</string> </resources> No newline at end of file