implement custom preference category element

This commit is contained in:
dkanada 2021-05-21 08:41:34 +09:00
commit abcb807518
12 changed files with 74 additions and 14 deletions

View file

@ -59,9 +59,11 @@ public class SettingsActivity extends AbsBaseActivity implements ColorChooserDia
switch (dialog.getTitle()) {
case R.string.pref_title_primary_color:
ThemeStore.editTheme(this).primaryColor(selectedColor).commit();
PreferenceUtil.getInstance(this).setPrimaryColor(selectedColor);
break;
case R.string.pref_title_accent_color:
ThemeStore.editTheme(this).accentColor(selectedColor).commit();
PreferenceUtil.getInstance(this).setAccentColor(selectedColor);
break;
}
@ -175,6 +177,8 @@ public class SettingsActivity extends AbsBaseActivity implements ColorChooserDia
case PreferenceUtil.COLORED_SHORTCUTS:
new DynamicShortcutManager(requireContext()).updateDynamicShortcuts();
break;
case PreferenceUtil.PRIMARY_COLOR:
case PreferenceUtil.ACCENT_COLOR:
case PreferenceUtil.GENERAL_THEME:
// apply theme before reloading shortcuts to apply the new icon colors
requireActivity().setTheme(PreferenceUtil.getThemeResource(key));

View file

@ -130,6 +130,14 @@ public final class PreferenceUtil {
}
}
public void setPrimaryColor(int color) {
mPreferences.edit().putInt(PRIMARY_COLOR, color).apply();
}
public void setAccentColor(int color) {
mPreferences.edit().putInt(ACCENT_COLOR, color).apply();
}
public final int getPageSize() {
return Integer.parseInt(mPreferences.getString(PAGE_SIZE, "100"));
}

View file

@ -0,0 +1,34 @@
package com.dkanada.gramophone.views.settings;
import android.content.Context;
import android.content.SharedPreferences;
import android.util.AttributeSet;
import android.widget.TextView;
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceManager;
import androidx.preference.PreferenceViewHolder;
import com.dkanada.gramophone.R;
import com.dkanada.gramophone.util.PreferenceUtil;
public class JellyPreferenceCategory extends PreferenceCategory {
public JellyPreferenceCategory(Context context, AttributeSet attrs) {
super(context, attrs);
setLayoutResource(R.layout.preference_category);
}
@Override
public void onBindViewHolder(PreferenceViewHolder holder) {
super.onBindViewHolder(holder);
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getContext());
TextView textView = (TextView) holder.findViewById(android.R.id.title);
int defaultColor = getContext().getResources().getColor(R.color.color_accent);
int accentColor = preferences.getInt(PreferenceUtil.ACCENT_COLOR, defaultColor);
textView.setTextColor(accentColor);
}
}

View file

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:paddingStart="16dp"
android:paddingTop="16dp"
android:paddingEnd="16dp"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textColor="?android:textColorSecondary" />

View file

@ -1,6 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="color_primary">#3F51B5</color>
<color name="color_accent">#F50057</color>
<!-- Pink A400 -->
<color name="color_favorite">#F50057</color>

View file

@ -2,7 +2,7 @@
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<com.kabouzeid.appthemehelper.common.prefs.supportv7.ATEPreferenceCategory android:title="@string/pref_header_cache">
<com.dkanada.gramophone.views.settings.JellyPreferenceCategory android:title="@string/pref_header_cache">
<com.kabouzeid.appthemehelper.common.prefs.supportv7.ATEListPreference
app:iconSpaceReserved="false"
@ -24,6 +24,6 @@
android:positiveButtonText="@null"
android:title="@string/pref_title_media_cache_size" />
</com.kabouzeid.appthemehelper.common.prefs.supportv7.ATEPreferenceCategory>
</com.dkanada.gramophone.views.settings.JellyPreferenceCategory>
</androidx.preference.PreferenceScreen>

View file

@ -1,7 +1,7 @@
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<com.kabouzeid.appthemehelper.common.prefs.supportv7.ATEPreferenceCategory android:title="@string/pref_header_colors">
<com.dkanada.gramophone.views.settings.JellyPreferenceCategory android:title="@string/pref_header_colors">
<com.kabouzeid.appthemehelper.common.prefs.supportv7.ATEListPreference
app:iconSpaceReserved="false"
@ -34,6 +34,6 @@
android:summary="@string/pref_summary_colored_shortcuts"
android:title="@string/pref_title_colored_shortcuts" />
</com.kabouzeid.appthemehelper.common.prefs.supportv7.ATEPreferenceCategory>
</com.dkanada.gramophone.views.settings.JellyPreferenceCategory>
</androidx.preference.PreferenceScreen>

View file

@ -1,7 +1,7 @@
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<com.kabouzeid.appthemehelper.common.prefs.supportv7.ATEPreferenceCategory android:title="@string/pref_header_library">
<com.dkanada.gramophone.views.settings.JellyPreferenceCategory android:title="@string/pref_header_library">
<Preference
app:iconSpaceReserved="false"
@ -26,6 +26,6 @@
android:summary="@string/pref_summary_remember_tab"
android:title="@string/pref_title_remember_tab" />
</com.kabouzeid.appthemehelper.common.prefs.supportv7.ATEPreferenceCategory>
</com.dkanada.gramophone.views.settings.JellyPreferenceCategory>
</androidx.preference.PreferenceScreen>

View file

@ -1,7 +1,7 @@
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<com.kabouzeid.appthemehelper.common.prefs.supportv7.ATEPreferenceCategory android:title="@string/pref_header_lock_screen">
<com.dkanada.gramophone.views.settings.JellyPreferenceCategory android:title="@string/pref_header_lock_screen">
<com.kabouzeid.appthemehelper.common.prefs.supportv7.ATESwitchPreference
app:iconSpaceReserved="false"
@ -18,6 +18,6 @@
android:summary="@string/pref_summary_blur_album_art"
android:title="@string/pref_title_blur_album_art" />
</com.kabouzeid.appthemehelper.common.prefs.supportv7.ATEPreferenceCategory>
</com.dkanada.gramophone.views.settings.JellyPreferenceCategory>
</androidx.preference.PreferenceScreen>

View file

@ -1,7 +1,7 @@
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<com.kabouzeid.appthemehelper.common.prefs.supportv7.ATEPreferenceCategory android:title="@string/pref_header_notification">
<com.dkanada.gramophone.views.settings.JellyPreferenceCategory android:title="@string/pref_header_notification">
<com.kabouzeid.appthemehelper.common.prefs.supportv7.ATESwitchPreference
app:iconSpaceReserved="false"
@ -17,6 +17,6 @@
android:summary="@string/pref_summary_colored_notification"
android:title="@string/pref_title_colored_notification" />
</com.kabouzeid.appthemehelper.common.prefs.supportv7.ATEPreferenceCategory>
</com.dkanada.gramophone.views.settings.JellyPreferenceCategory>
</androidx.preference.PreferenceScreen>

View file

@ -2,13 +2,13 @@
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<com.kabouzeid.appthemehelper.common.prefs.supportv7.ATEPreferenceCategory android:title="@string/pref_header_now_playing_screen">
<com.dkanada.gramophone.views.settings.JellyPreferenceCategory android:title="@string/pref_header_now_playing_screen">
<Preference
app:iconSpaceReserved="false"
android:key="now_playing_screen"
android:title="@string/pref_title_now_playing_appearance" />
</com.kabouzeid.appthemehelper.common.prefs.supportv7.ATEPreferenceCategory>
</com.dkanada.gramophone.views.settings.JellyPreferenceCategory>
</androidx.preference.PreferenceScreen>

View file

@ -2,7 +2,7 @@
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<com.kabouzeid.appthemehelper.common.prefs.supportv7.ATEPreferenceCategory android:title="@string/pref_header_audio">
<com.dkanada.gramophone.views.settings.JellyPreferenceCategory android:title="@string/pref_header_audio">
<com.kabouzeid.appthemehelper.common.prefs.supportv7.ATEListPreference
app:iconSpaceReserved="false"
@ -51,6 +51,6 @@
android:summary="@string/pref_summary_remember_queue"
android:title="@string/pref_title_remember_queue" />
</com.kabouzeid.appthemehelper.common.prefs.supportv7.ATEPreferenceCategory>
</com.dkanada.gramophone.views.settings.JellyPreferenceCategory>
</androidx.preference.PreferenceScreen>