feat(settings): add summary label to switch

This commit is contained in:
FineFindus 2023-05-16 21:31:06 +02:00
parent 35477055a9
commit 1fab3d3743
No known key found for this signature in database
GPG Key ID: 64873EE210FF8E6B
2 changed files with 50 additions and 16 deletions

View File

@ -179,21 +179,30 @@ public abstract class SettingsBaseFragment extends MastodonToolbarFragment imple
protected class SwitchItem extends Item{ protected class SwitchItem extends Item{
private String text; private String title;
private String summary;
private int icon; private int icon;
boolean checked; boolean checked;
private Consumer<SwitchItem> onChanged; private Consumer<SwitchItem> onChanged;
protected boolean enabled=true; protected boolean enabled=true;
public SwitchItem(@StringRes int text, @DrawableRes int icon, boolean checked, Consumer<SwitchItem> onChanged){ public SwitchItem(@StringRes int title, @DrawableRes int icon, boolean checked, Consumer<SwitchItem> onChanged){
this.text=getString(text); this.title=getString(title);
this.icon=icon; this.icon=icon;
this.checked=checked; this.checked=checked;
this.onChanged=onChanged; this.onChanged=onChanged;
} }
public SwitchItem(@StringRes int text, @DrawableRes int icon, boolean checked, Consumer<SwitchItem> onChanged, boolean enabled){ public SwitchItem(@StringRes int title, @StringRes int summary, @DrawableRes int icon, boolean checked, Consumer<SwitchItem> onChanged){
this.text=getString(text); this.title=getString(title);
this.summary=getString(summary);
this.icon=icon;
this.checked=checked;
this.onChanged=onChanged;
}
public SwitchItem(@StringRes int title, @DrawableRes int icon, boolean checked, Consumer<SwitchItem> onChanged, boolean enabled){
this.title=getString(title);
this.icon=icon; this.icon=icon;
this.checked=checked; this.checked=checked;
this.onChanged=onChanged; this.onChanged=onChanged;
@ -573,20 +582,28 @@ public abstract class SettingsBaseFragment extends MastodonToolbarFragment imple
} }
protected class SwitchViewHolder extends BindableViewHolder<SwitchItem> implements UsableRecyclerView.DisableableClickable{ protected class SwitchViewHolder extends BindableViewHolder<SwitchItem> implements UsableRecyclerView.DisableableClickable{
private final TextView text; private final TextView title;
private final TextView summary;
private final ImageView icon; private final ImageView icon;
private final Switch checkbox; private final Switch checkbox;
public SwitchViewHolder(){ public SwitchViewHolder(){
super(getActivity(), R.layout.item_settings_switch, list); super(getActivity(), R.layout.item_settings_switch, list);
text=findViewById(R.id.text); title=findViewById(R.id.title);
summary=findViewById(R.id.summary);
icon=findViewById(R.id.icon); icon=findViewById(R.id.icon);
checkbox=findViewById(R.id.checkbox); checkbox=findViewById(R.id.checkbox);
} }
@Override @Override
public void onBind(SwitchItem item){ public void onBind(SwitchItem item){
text.setText(item.text); title.setText(item.title);
if (item.summary != null) {
summary.setText(item.summary);
summary.setVisibility(View.VISIBLE);
}
if (item.icon == 0) { if (item.icon == 0) {
icon.setVisibility(View.GONE); icon.setVisibility(View.GONE);
} else { } else {

View File

@ -17,16 +17,33 @@
android:tint="?android:textColorPrimary" android:tint="?android:textColorPrimary"
tools:src="@drawable/ic_fluent_star_24_regular"/> tools:src="@drawable/ic_fluent_star_24_regular"/>
<TextView <RelativeLayout
android:id="@+id/text"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_marginStart="15dip"
android:layout_marginStart="16dp" android:layout_marginEnd="6dip"
android:paddingVertical="8dp" android:layout_marginTop="6dip"
android:textSize="16sp" android:layout_marginBottom="6dip"
android:layout_weight="1">
<TextView android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="marquee"
android:textColor="?android:textColorPrimary" android:textColor="?android:textColorPrimary"
tools:text="@string/theme_true_black"/> android:fadingEdge="horizontal"
android:text=""/>
<TextView android:id="@+id/summary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/title"
android:layout_alignStart="@id/title"
android:visibility="gone"
android:maxLines="4" />
</RelativeLayout>
<Switch <Switch
android:id="@+id/checkbox" android:id="@+id/checkbox"