Reinstate CorrectedPreferenceFragment item backgrounds

This commit is contained in:
andrew 2023-06-16 11:38:27 +09:30
parent 3a46e4c573
commit 628847e00f
4 changed files with 77 additions and 1 deletions

View File

@ -125,6 +125,29 @@ public abstract class CorrectedPreferenceFragment extends PreferenceFragmentComp
return next instanceof PreferenceCategory;
}
public Drawable getBackground(Context context, int position) {
int viewType = getPreferenceType(position);
Drawable background;
switch (viewType) {
case SINGLE_TYPE:
background = ContextCompat.getDrawable(context, R.drawable.preference_single);
break;
case TOP_TYPE:
background = ContextCompat.getDrawable(context, R.drawable.preference_top);
break;
case MIDDLE_TYPE:
background = ContextCompat.getDrawable(context, R.drawable.preference_middle);
break;
case BOTTOM_TYPE:
background = ContextCompat.getDrawable(context, R.drawable.preference_bottom);
break;
default:
background = null;
break;
}
return background;
}
@Override
public void onBindViewHolder(PreferenceViewHolder holder, int position) {
super.onBindViewHolder(holder, position);
@ -140,9 +163,11 @@ public abstract class CorrectedPreferenceFragment extends PreferenceFragmentComp
if (iconFrame != null) {
iconFrame.setVisibility(preference.getIcon() == null ? View.GONE : View.VISIBLE);
}
Drawable background = getBackground(holder.itemView.getContext(), position);
holder.itemView.setBackground(background);
TextView titleView = holder.itemView.findViewById(android.R.id.title);
if (titleView != null) {
titleView.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
((TextView) titleView).setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
}
boolean isTop = isTop(position);
boolean isBottom = isBottom(position);

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:left="@dimen/medium_spacing"
android:right="@dimen/medium_spacing"
android:bottom="@dimen/small_spacing"
>
<shape android:shape="rectangle">
<solid android:color="?colorSettingsBackground"/>
<corners android:bottomLeftRadius="?preferenceCornerRadius"
android:bottomRightRadius="?preferenceCornerRadius"/>
</shape>
</item>
</layer-list>

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:left="@dimen/medium_spacing"
android:right="@dimen/medium_spacing">
<shape android:shape="rectangle">
<solid android:color="?colorSettingsBackground"/>
</shape>
</item>
<item android:gravity="bottom"
android:left="@dimen/large_spacing"
android:right="@dimen/large_spacing">
<shape android:shape="rectangle" android:tint="?android:textColorPrimary">
<size android:height="1dp"/>
<solid android:color="@color/transparent_white_15"/>
</shape>
</item>
</layer-list>

View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:left="@dimen/medium_spacing"
android:right="@dimen/medium_spacing"
android:top="@dimen/small_spacing"
>
<shape android:shape="rectangle">
<solid android:color="?colorSettingsBackground"/>
<corners android:topLeftRadius="?preferenceCornerRadius"
android:topRightRadius="?preferenceCornerRadius"/>
</shape>
</item>
<item android:gravity="bottom"
android:left="@dimen/large_spacing"
android:right="@dimen/large_spacing">
<shape android:shape="rectangle" android:tint="?android:textColorPrimary">
<size android:height="1dp"/>
<solid android:color="@color/transparent_white_15"/>
</shape>
</item>
</layer-list>