From 5337841da0d308b5929122744c2eaebf1200a002 Mon Sep 17 00:00:00 2001 From: Thomas Date: Thu, 8 Dec 2022 18:10:51 +0100 Subject: [PATCH] Pref settings customization of messages --- app/build.gradle | 4 +- .../android/activities/SettingsActivity.kt | 1 + .../settings/FragmentCustomDarkSettings.java | 57 ++++++++++++ .../settings/FragmentCustomLightSettings.java | 57 ++++++++++++ .../settings/FragmentThemingSettings.java | 24 ++++++ .../res/navigation/nav_graph_settings.xml | 11 +++ app/src/main/res/values/strings.xml | 28 ++++++ app/src/main/res/xml/pref_custom_dark.xml | 86 +++++++++++++++++++ app/src/main/res/xml/pref_custom_light.xml | 86 +++++++++++++++++++ app/src/main/res/xml/pref_theming.xml | 33 +++++++ 10 files changed, 385 insertions(+), 2 deletions(-) create mode 100644 app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentCustomDarkSettings.java create mode 100644 app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentCustomLightSettings.java create mode 100644 app/src/main/res/xml/pref_custom_dark.xml create mode 100644 app/src/main/res/xml/pref_custom_light.xml diff --git a/app/build.gradle b/app/build.gradle index 0f180da4d..3e592ea7c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -81,8 +81,8 @@ dependencies { implementation 'androidx.appcompat:appcompat:1.5.1' implementation 'com.google.android.material:material:1.7.0' - implementation "androidx.compose.material3:material3:1.0.1" - implementation "androidx.compose.material3:material3-window-size-class:1.0.1" + + implementation "com.github.skydoves:colorpickerpreference:2.0.6" implementation 'androidx.constraintlayout:constraintlayout:2.1.4' implementation "com.google.code.gson:gson:2.9.1" diff --git a/app/src/main/java/app/fedilab/android/activities/SettingsActivity.kt b/app/src/main/java/app/fedilab/android/activities/SettingsActivity.kt index 955b615cf..32edbad45 100644 --- a/app/src/main/java/app/fedilab/android/activities/SettingsActivity.kt +++ b/app/src/main/java/app/fedilab/android/activities/SettingsActivity.kt @@ -36,6 +36,7 @@ class SettingsActivity : BaseBarActivity() { val navController = findNavController(R.id.fragment_container) appBarConfiguration = AppBarConfiguration.Builder().build() setupActionBarWithNavController(navController, appBarConfiguration) + } diff --git a/app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentCustomDarkSettings.java b/app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentCustomDarkSettings.java new file mode 100644 index 000000000..7a1e37728 --- /dev/null +++ b/app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentCustomDarkSettings.java @@ -0,0 +1,57 @@ +package app.fedilab.android.ui.fragment.settings; +/* 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.content.SharedPreferences; +import android.os.Bundle; + +import androidx.preference.PreferenceFragmentCompat; + +import app.fedilab.android.R; + +public class FragmentCustomDarkSettings extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener { + + @Override + public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { + addPreferencesFromResource(R.xml.pref_custom_dark); + createPref(); + } + + private void createPref() { + } + + @Override + public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { + + } + + @Override + public void onResume() { + super.onResume(); + + getPreferenceScreen().getSharedPreferences() + .registerOnSharedPreferenceChangeListener(this); + } + + @Override + public void onPause() { + super.onPause(); + getPreferenceScreen().getSharedPreferences() + .unregisterOnSharedPreferenceChangeListener(this); + } + + +} diff --git a/app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentCustomLightSettings.java b/app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentCustomLightSettings.java new file mode 100644 index 000000000..d35e5cf8b --- /dev/null +++ b/app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentCustomLightSettings.java @@ -0,0 +1,57 @@ +package app.fedilab.android.ui.fragment.settings; +/* 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.content.SharedPreferences; +import android.os.Bundle; + +import androidx.preference.PreferenceFragmentCompat; + +import app.fedilab.android.R; + +public class FragmentCustomLightSettings extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener { + + @Override + public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { + addPreferencesFromResource(R.xml.pref_custom_light); + createPref(); + } + + private void createPref() { + } + + @Override + public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { + + } + + @Override + public void onResume() { + super.onResume(); + + getPreferenceScreen().getSharedPreferences() + .registerOnSharedPreferenceChangeListener(this); + } + + @Override + public void onPause() { + super.onPause(); + getPreferenceScreen().getSharedPreferences() + .unregisterOnSharedPreferenceChangeListener(this); + } + + +} 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 72f635331..7141514a8 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 @@ -18,7 +18,10 @@ package app.fedilab.android.ui.fragment.settings; import android.content.SharedPreferences; import android.os.Bundle; +import androidx.navigation.NavOptions; +import androidx.navigation.Navigation; import androidx.preference.ListPreference; +import androidx.preference.Preference; import androidx.preference.PreferenceFragmentCompat; import app.fedilab.android.R; @@ -89,6 +92,27 @@ public class FragmentThemingSettings extends PreferenceFragmentCompat implements if (SET_THEME_DEFAULT_DARK != null) { SET_THEME_DEFAULT_DARK.getContext().setTheme(Helper.dialogStyle()); } + + Preference SET_CUSTOMIZE_LIGHT_COLORS_ACTION = findPreference(getString(R.string.SET_CUSTOMIZE_LIGHT_COLORS_ACTION)); + if (SET_CUSTOMIZE_LIGHT_COLORS_ACTION != null) { + SET_CUSTOMIZE_LIGHT_COLORS_ACTION.setOnPreferenceClickListener(preference -> { + NavOptions.Builder navBuilder = new NavOptions.Builder(); + navBuilder.setEnterAnim(R.anim.enter).setExitAnim(R.anim.exit).setPopEnterAnim(R.anim.pop_enter).setPopExitAnim(R.anim.pop_exit); + + Navigation.findNavController(requireActivity(), R.id.fragment_container).navigate(R.id.FragmentCustomLightSettings, null, navBuilder.build()); + return true; + }); + } + + Preference SET_CUSTOMIZE_DARK_COLORS_ACTION = findPreference(getString(R.string.SET_CUSTOMIZE_DARK_COLORS_ACTION)); + if (SET_CUSTOMIZE_DARK_COLORS_ACTION != null) { + SET_CUSTOMIZE_DARK_COLORS_ACTION.setOnPreferenceClickListener(preference -> { + NavOptions.Builder navBuilder = new NavOptions.Builder(); + navBuilder.setEnterAnim(R.anim.enter).setExitAnim(R.anim.exit).setPopEnterAnim(R.anim.pop_enter).setPopExitAnim(R.anim.pop_exit); + Navigation.findNavController(requireActivity(), R.id.fragment_container).navigate(R.id.FragmentCustomDarkSettings, null, navBuilder.build()); + return true; + }); + } } } diff --git a/app/src/main/res/navigation/nav_graph_settings.xml b/app/src/main/res/navigation/nav_graph_settings.xml index 56b5caf27..729f2caf4 100644 --- a/app/src/main/res/navigation/nav_graph_settings.xml +++ b/app/src/main/res/navigation/nav_graph_settings.xml @@ -105,6 +105,17 @@ android:name="app.fedilab.android.ui.fragment.settings.FragmentLanguageSettings" android:label="@string/languages" /> + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4796c6543..e6a907bfb 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1298,9 +1298,30 @@ SET_THEME_BASE SET_DYNAMICCOLOR SET_CARDVIEW + SET_CUSTOMIZE_LIGHT_COLORS + SET_CUSTOMIZE_LIGHT_COLORS_ACTION + SET_CUSTOMIZE_DARK_COLORS + SET_CUSTOMIZE_DARK_COLORS_ACTION SET_THEME_DEFAULT_LIGHT SET_THEME_DEFAULT_DARK + SET_DARK_BACKGROUND + SET_DARK_TEXT + SET_DARK_BOOST_HEADER + SET_DARK_DISPLAY_NAME + SET_DARK_USERNAME + SET_DARK_LINK + SET_DARK_ICON + + + SET_LIGHT_BACKGROUND + SET_LIGHT_TEXT + SET_LIGHT_BOOST_HEADER + SET_LIGHT_DISPLAY_NAME + SET_LIGHT_USERNAME + SET_LIGHT_LINK + SET_LIGHT_ICON + SYSTEM @@ -2018,4 +2039,11 @@ Default dark theme Elevated cards When enabled, items in timelines will have a shadow and an elevation. + Customize Light Theme + Allows to customize some elements in messages for the light theme. + Customize Dark Theme + Allows to customize some elements in messages for the dark theme. + Set custom colors + Light - Custom colors + Dark - Custom colors \ No newline at end of file diff --git a/app/src/main/res/xml/pref_custom_dark.xml b/app/src/main/res/xml/pref_custom_dark.xml new file mode 100644 index 000000000..f9135bf9d --- /dev/null +++ b/app/src/main/res/xml/pref_custom_dark.xml @@ -0,0 +1,86 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/xml/pref_custom_light.xml b/app/src/main/res/xml/pref_custom_light.xml new file mode 100644 index 000000000..70d33cc64 --- /dev/null +++ b/app/src/main/res/xml/pref_custom_light.xml @@ -0,0 +1,86 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/xml/pref_theming.xml b/app/src/main/res/xml/pref_theming.xml index 7c8b1cc7f..f8ba554ff 100644 --- a/app/src/main/res/xml/pref_theming.xml +++ b/app/src/main/res/xml/pref_theming.xml @@ -53,4 +53,37 @@ app:summary="@string/set_cardview_indication" app:title="@string/set_cardview" /> + + + + + + + + +