Pref settings customization of messages

This commit is contained in:
Thomas 2022-12-08 18:10:51 +01:00
parent 724813407d
commit 5337841da0
10 changed files with 385 additions and 2 deletions

View file

@ -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"

View file

@ -36,6 +36,7 @@ class SettingsActivity : BaseBarActivity() {
val navController = findNavController(R.id.fragment_container)
appBarConfiguration = AppBarConfiguration.Builder().build()
setupActionBarWithNavController(navController, appBarConfiguration)
}

View file

@ -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 <http://www.gnu.org/licenses>. */
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);
}
}

View file

@ -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 <http://www.gnu.org/licenses>. */
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);
}
}

View file

@ -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;
});
}
}
}

View file

@ -105,6 +105,17 @@
android:name="app.fedilab.android.ui.fragment.settings.FragmentLanguageSettings"
android:label="@string/languages" />
<fragment
android:id="@+id/FragmentCustomLightSettings"
android:name="app.fedilab.android.ui.fragment.settings.FragmentCustomLightSettings"
android:label="@string/light_custom_colors" />
<fragment
android:id="@+id/FragmentCustomDarkSettings"
android:name="app.fedilab.android.ui.fragment.settings.FragmentCustomDarkSettings"
android:label="@string/cark_custom_colors" />
<activity
android:id="@+id/EditProfileActivity"
android:name="app.fedilab.android.activities.EditProfileActivity" />

View file

@ -1298,9 +1298,30 @@
<string name="SET_THEME_BASE" translatable="false">SET_THEME_BASE</string>
<string name="SET_DYNAMICCOLOR" translatable="false">SET_DYNAMICCOLOR</string>
<string name="SET_CARDVIEW" translatable="false">SET_CARDVIEW</string>
<string name="SET_CUSTOMIZE_LIGHT_COLORS" translatable="false">SET_CUSTOMIZE_LIGHT_COLORS</string>
<string name="SET_CUSTOMIZE_LIGHT_COLORS_ACTION" translatable="false">SET_CUSTOMIZE_LIGHT_COLORS_ACTION</string>
<string name="SET_CUSTOMIZE_DARK_COLORS" translatable="false">SET_CUSTOMIZE_DARK_COLORS</string>
<string name="SET_CUSTOMIZE_DARK_COLORS_ACTION" translatable="false">SET_CUSTOMIZE_DARK_COLORS_ACTION</string>
<string name="SET_THEME_DEFAULT_LIGHT" translatable="false">SET_THEME_DEFAULT_LIGHT</string>
<string name="SET_THEME_DEFAULT_DARK" translatable="false">SET_THEME_DEFAULT_DARK</string>
<string name="SET_DARK_BACKGROUND" translatable="false">SET_DARK_BACKGROUND</string>
<string name="SET_DARK_TEXT" translatable="false">SET_DARK_TEXT</string>
<string name="SET_DARK_BOOST_HEADER" translatable="false">SET_DARK_BOOST_HEADER</string>
<string name="SET_DARK_DISPLAY_NAME" translatable="false">SET_DARK_DISPLAY_NAME</string>
<string name="SET_DARK_USERNAME" translatable="false">SET_DARK_USERNAME</string>
<string name="SET_DARK_LINK" translatable="false">SET_DARK_LINK</string>
<string name="SET_DARK_ICON" translatable="false">SET_DARK_ICON</string>
<string name="SET_LIGHT_BACKGROUND" translatable="false">SET_LIGHT_BACKGROUND</string>
<string name="SET_LIGHT_TEXT" translatable="false">SET_LIGHT_TEXT</string>
<string name="SET_LIGHT_BOOST_HEADER" translatable="false">SET_LIGHT_BOOST_HEADER</string>
<string name="SET_LIGHT_DISPLAY_NAME" translatable="false">SET_LIGHT_DISPLAY_NAME</string>
<string name="SET_LIGHT_USERNAME" translatable="false">SET_LIGHT_USERNAME</string>
<string name="SET_LIGHT_LINK" translatable="false">SET_LIGHT_LINK</string>
<string name="SET_LIGHT_ICON" translatable="false">SET_LIGHT_ICON</string>
<string name="SET_DEFAULT_THEME" translatable="false">SYSTEM</string>
@ -2018,4 +2039,11 @@
<string name="type_default_theme_dark">Default dark theme</string>
<string name="set_cardview">Elevated cards</string>
<string name="set_cardview_indication">When enabled, items in timelines will have a shadow and an elevation.</string>
<string name="set_customize_light">Customize Light Theme</string>
<string name="set_customize_light_indication">Allows to customize some elements in messages for the light theme.</string>
<string name="set_customize_dark">Customize Dark Theme</string>
<string name="set_customize_dark_indication">Allows to customize some elements in messages for the dark theme.</string>
<string name="set_custom_colors">Set custom colors</string>
<string name="light_custom_colors">Light - Custom colors</string>
<string name="cark_custom_colors">Dark - Custom colors</string>
</resources>

View file

@ -0,0 +1,86 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.skydoves.colorpickerpreference.ColorPickerPreference
android:key="@string/SET_DARK_BACKGROUND"
app:default_color="?android:colorBackground"
app:iconSpaceReserved="false"
app:preference_attachAlphaSlideBar="false"
app:preference_attachBrightnessSlideBar="false"
app:preference_dialog_negative="@string/cancel"
app:preference_dialog_positive="@string/save"
app:summary="@string/background_status"
app:title="@string/background_status_title" />
<com.skydoves.colorpickerpreference.ColorPickerPreference
android:key="@string/SET_DARK_BOOST_HEADER"
app:default_color="?android:colorBackground"
app:iconSpaceReserved="false"
app:preference_attachAlphaSlideBar="false"
app:preference_attachBrightnessSlideBar="false"
app:preference_dialog_negative="@string/cancel"
app:preference_dialog_positive="@string/save"
app:summary="@string/boost_header_color"
app:title="@string/boost_header_color_title" />
<com.skydoves.colorpickerpreference.ColorPickerPreference
android:key="@string/SET_DARK_DISPLAY_NAME"
app:default_color="?colorOnBackground"
app:iconSpaceReserved="false"
app:preference_attachAlphaSlideBar="false"
app:preference_attachBrightnessSlideBar="false"
app:preference_dialog_negative="@string/cancel"
app:preference_dialog_positive="@string/save"
app:summary="@string/displayname_title"
app:title="@string/display_name" />
<com.skydoves.colorpickerpreference.ColorPickerPreference
android:key="@string/SET_DARK_USERNAME"
app:default_color="?colorOnBackground"
app:iconSpaceReserved="false"
app:preference_attachAlphaSlideBar="false"
app:preference_attachBrightnessSlideBar="false"
app:preference_dialog_negative="@string/cancel"
app:preference_dialog_positive="@string/save"
app:summary="@string/username_title"
app:title="@string/username" />
<com.skydoves.colorpickerpreference.ColorPickerPreference
android:key="@string/SET_DARK_TEXT"
app:default_color="?colorOnBackground"
app:iconSpaceReserved="false"
app:preference_attachAlphaSlideBar="false"
app:preference_attachBrightnessSlideBar="false"
app:preference_dialog_negative="@string/cancel"
app:preference_dialog_positive="@string/save"
app:summary="@string/text_color"
app:title="@string/text_color_title" />
<com.skydoves.colorpickerpreference.ColorPickerPreference
android:key="@string/SET_DARK_LINK"
app:default_color="?linkColor"
app:iconSpaceReserved="false"
app:preference_attachAlphaSlideBar="false"
app:preference_attachBrightnessSlideBar="false"
app:preference_dialog_negative="@string/cancel"
app:preference_dialog_positive="@string/save"
app:summary="@string/link_color"
app:title="@string/link_color_title" />
<com.skydoves.colorpickerpreference.ColorPickerPreference
android:key="@string/SET_DARK_ICON"
app:default_color="?colorControlNormal"
app:iconSpaceReserved="false"
app:preference_attachAlphaSlideBar="false"
app:preference_attachBrightnessSlideBar="false"
app:preference_dialog_negative="@string/cancel"
app:preference_dialog_positive="@string/save"
app:summary="@string/icons_color"
app:title="@string/icons_color_title" />
</androidx.preference.PreferenceScreen>

View file

@ -0,0 +1,86 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.skydoves.colorpickerpreference.ColorPickerPreference
android:key="@string/SET_LIGHT_BACKGROUND"
app:default_color="?android:colorBackground"
app:iconSpaceReserved="false"
app:preference_attachAlphaSlideBar="false"
app:preference_attachBrightnessSlideBar="false"
app:preference_dialog_negative="@string/cancel"
app:preference_dialog_positive="@string/save"
app:summary="@string/background_status"
app:title="@string/background_status_title" />
<com.skydoves.colorpickerpreference.ColorPickerPreference
android:key="@string/SET_LIGHT_BOOST_HEADER"
app:default_color="?android:colorBackground"
app:iconSpaceReserved="false"
app:preference_attachAlphaSlideBar="false"
app:preference_attachBrightnessSlideBar="false"
app:preference_dialog_negative="@string/cancel"
app:preference_dialog_positive="@string/save"
app:summary="@string/boost_header_color"
app:title="@string/boost_header_color_title" />
<com.skydoves.colorpickerpreference.ColorPickerPreference
android:key="@string/SET_LIGHT_DISPLAY_NAME"
app:default_color="?colorOnBackground"
app:iconSpaceReserved="false"
app:preference_attachAlphaSlideBar="false"
app:preference_attachBrightnessSlideBar="false"
app:preference_dialog_negative="@string/cancel"
app:preference_dialog_positive="@string/save"
app:summary="@string/displayname_title"
app:title="@string/display_name" />
<com.skydoves.colorpickerpreference.ColorPickerPreference
android:key="@string/SET_LIGHT_USERNAME"
app:default_color="?colorOnBackground"
app:iconSpaceReserved="false"
app:preference_attachAlphaSlideBar="false"
app:preference_attachBrightnessSlideBar="false"
app:preference_dialog_negative="@string/cancel"
app:preference_dialog_positive="@string/save"
app:summary="@string/username_title"
app:title="@string/username" />
<com.skydoves.colorpickerpreference.ColorPickerPreference
android:key="@string/SET_LIGHT_TEXT"
app:default_color="?colorOnBackground"
app:iconSpaceReserved="false"
app:preference_attachAlphaSlideBar="false"
app:preference_attachBrightnessSlideBar="false"
app:preference_dialog_negative="@string/cancel"
app:preference_dialog_positive="@string/save"
app:summary="@string/text_color"
app:title="@string/text_color_title" />
<com.skydoves.colorpickerpreference.ColorPickerPreference
android:key="@string/SET_LIGHT_LINK"
app:default_color="?linkColor"
app:iconSpaceReserved="false"
app:preference_attachAlphaSlideBar="false"
app:preference_attachBrightnessSlideBar="false"
app:preference_dialog_negative="@string/cancel"
app:preference_dialog_positive="@string/save"
app:summary="@string/link_color"
app:title="@string/link_color_title" />
<com.skydoves.colorpickerpreference.ColorPickerPreference
android:key="@string/SET_LIGHT_ICON"
app:default_color="?colorControlNormal"
app:iconSpaceReserved="false"
app:preference_attachAlphaSlideBar="false"
app:preference_attachBrightnessSlideBar="false"
app:preference_dialog_negative="@string/cancel"
app:preference_dialog_positive="@string/save"
app:summary="@string/icons_color"
app:title="@string/icons_color_title" />
</androidx.preference.PreferenceScreen>

View file

@ -53,4 +53,37 @@
app:summary="@string/set_cardview_indication"
app:title="@string/set_cardview" />
<SwitchPreferenceCompat
app:defaultValue="false"
app:iconSpaceReserved="false"
app:key="@string/SET_CUSTOMIZE_LIGHT_COLORS"
app:singleLineTitle="false"
app:summary="@string/set_customize_light_indication"
app:title="@string/set_customize_light" />
<Preference
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:title="@string/set_custom_colors"
app:dependency="@string/SET_CUSTOMIZE_LIGHT_COLORS"
app:iconSpaceReserved="false"
app:key="@string/SET_CUSTOMIZE_LIGHT_COLORS_ACTION" />
<SwitchPreferenceCompat
app:defaultValue="false"
app:iconSpaceReserved="false"
app:key="@string/SET_CUSTOMIZE_DARK_COLORS"
app:singleLineTitle="false"
app:summary="@string/set_customize_dark_indication"
app:title="@string/set_customize_dark" />
<Preference
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:title="@string/set_custom_colors"
app:dependency="@string/SET_CUSTOMIZE_DARK_COLORS"
app:iconSpaceReserved="false"
app:key="@string/SET_CUSTOMIZE_DARK_COLORS_ACTION" />
</androidx.preference.PreferenceScreen>