feat(settings): add summary label to switch
This commit is contained in:
parent
35477055a9
commit
1fab3d3743
|
@ -179,21 +179,30 @@ public abstract class SettingsBaseFragment extends MastodonToolbarFragment imple
|
|||
|
||||
|
||||
protected class SwitchItem extends Item{
|
||||
private String text;
|
||||
private String title;
|
||||
private String summary;
|
||||
private int icon;
|
||||
boolean checked;
|
||||
private Consumer<SwitchItem> onChanged;
|
||||
protected boolean enabled=true;
|
||||
|
||||
public SwitchItem(@StringRes int text, @DrawableRes int icon, boolean checked, Consumer<SwitchItem> onChanged){
|
||||
this.text=getString(text);
|
||||
public SwitchItem(@StringRes int title, @DrawableRes int icon, boolean checked, Consumer<SwitchItem> onChanged){
|
||||
this.title=getString(title);
|
||||
this.icon=icon;
|
||||
this.checked=checked;
|
||||
this.onChanged=onChanged;
|
||||
}
|
||||
|
||||
public SwitchItem(@StringRes int text, @DrawableRes int icon, boolean checked, Consumer<SwitchItem> onChanged, boolean enabled){
|
||||
this.text=getString(text);
|
||||
public SwitchItem(@StringRes int title, @StringRes int summary, @DrawableRes int icon, boolean checked, Consumer<SwitchItem> onChanged){
|
||||
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.checked=checked;
|
||||
this.onChanged=onChanged;
|
||||
|
@ -573,20 +582,28 @@ public abstract class SettingsBaseFragment extends MastodonToolbarFragment imple
|
|||
}
|
||||
|
||||
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 Switch checkbox;
|
||||
|
||||
public SwitchViewHolder(){
|
||||
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);
|
||||
checkbox=findViewById(R.id.checkbox);
|
||||
}
|
||||
|
||||
@Override
|
||||
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) {
|
||||
icon.setVisibility(View.GONE);
|
||||
} else {
|
||||
|
|
|
@ -17,16 +17,33 @@
|
|||
android:tint="?android:textColorPrimary"
|
||||
tools:src="@drawable/ic_fluent_star_24_regular"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text"
|
||||
<RelativeLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:layout_marginStart="16dp"
|
||||
android:paddingVertical="8dp"
|
||||
android:textSize="16sp"
|
||||
android:layout_marginStart="15dip"
|
||||
android:layout_marginEnd="6dip"
|
||||
android:layout_marginTop="6dip"
|
||||
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"
|
||||
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
|
||||
android:id="@+id/checkbox"
|
||||
|
|
Loading…
Reference in New Issue