implement custom preference category element
This commit is contained in:
parent
d8a0ba23b6
commit
abcb807518
12 changed files with 74 additions and 14 deletions
|
|
@ -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));
|
||||
|
|
|
|||
|
|
@ -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"));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue