feat(settings): add summary label to button
This commit is contained in:
parent
e94364ecf6
commit
f7c76f7503
|
@ -8,10 +8,10 @@ import android.graphics.Canvas;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.text.TextUtils;
|
||||||
import android.util.TypedValue;
|
import android.util.TypedValue;
|
||||||
import android.view.Gravity;
|
import android.view.Gravity;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.MenuItem;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.WindowInsets;
|
import android.view.WindowInsets;
|
||||||
|
@ -241,12 +241,20 @@ public abstract class SettingsBaseFragment extends MastodonToolbarFragment imple
|
||||||
|
|
||||||
|
|
||||||
protected class ButtonItem extends Item{
|
protected class ButtonItem extends Item{
|
||||||
private int text;
|
private int title;
|
||||||
|
private int summary;
|
||||||
private int icon;
|
private int icon;
|
||||||
private Consumer<Button> buttonConsumer;
|
private Consumer<Button> buttonConsumer;
|
||||||
|
|
||||||
public ButtonItem(@StringRes int text, @DrawableRes int icon, Consumer<Button> buttonConsumer) {
|
public ButtonItem(@StringRes int title, @DrawableRes int icon, Consumer<Button> buttonConsumer) {
|
||||||
this.text = text;
|
this.title = title;
|
||||||
|
this.icon = icon;
|
||||||
|
this.buttonConsumer = buttonConsumer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ButtonItem(@StringRes int title, @StringRes int summary, @DrawableRes int icon, Consumer<Button> buttonConsumer) {
|
||||||
|
this.title = title;
|
||||||
|
this.summary = summary;
|
||||||
this.icon = icon;
|
this.icon = icon;
|
||||||
this.buttonConsumer = buttonConsumer;
|
this.buttonConsumer = buttonConsumer;
|
||||||
}
|
}
|
||||||
|
@ -714,19 +722,27 @@ public abstract class SettingsBaseFragment extends MastodonToolbarFragment imple
|
||||||
protected class ButtonViewHolder extends BindableViewHolder<ButtonItem>{
|
protected class ButtonViewHolder extends BindableViewHolder<ButtonItem>{
|
||||||
private final Button button;
|
private final Button button;
|
||||||
private final ImageView icon;
|
private final ImageView icon;
|
||||||
private final TextView text;
|
private final TextView title;
|
||||||
|
private final TextView summary;
|
||||||
|
|
||||||
@SuppressLint("ClickableViewAccessibility")
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
public ButtonViewHolder(){
|
public ButtonViewHolder(){
|
||||||
super(getActivity(), R.layout.item_settings_button, list);
|
super(getActivity(), R.layout.item_settings_button, 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);
|
||||||
button=findViewById(R.id.button);
|
button=findViewById(R.id.button);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBind(ButtonItem item){
|
public void onBind(ButtonItem item){
|
||||||
text.setText(item.text);
|
title.setText(item.title);
|
||||||
|
|
||||||
|
if (item.summary != 0) {
|
||||||
|
summary.setText(item.summary);
|
||||||
|
summary.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
|
||||||
icon.setImageResource(item.icon);
|
icon.setImageResource(item.icon);
|
||||||
item.buttonConsumer.accept(button);
|
item.buttonConsumer.accept(button);
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,24 +13,39 @@
|
||||||
android:layout_width="24dp"
|
android:layout_width="24dp"
|
||||||
android:layout_height="24dp"
|
android:layout_height="24dp"
|
||||||
android:layout_marginStart="16dp"
|
android:layout_marginStart="16dp"
|
||||||
android:layout_marginEnd="16dp"
|
android:layout_marginEnd="32dp"
|
||||||
android:importantForAccessibility="no"
|
android:importantForAccessibility="no"
|
||||||
android:tint="?android:textColorPrimary"
|
android:tint="?android:textColorPrimary"
|
||||||
tools:src="@drawable/ic_fluent_color_24_regular"/>
|
tools:src="@drawable/ic_fluent_color_24_regular"/>
|
||||||
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/text"
|
<RelativeLayout
|
||||||
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="16dp"
|
|
||||||
android:layout_marginEnd="8dp"
|
android:layout_marginEnd="8dp"
|
||||||
android:paddingVertical="8dp"
|
android:paddingVertical="8dp"
|
||||||
android:gravity="center_vertical"
|
android:layout_weight="1">
|
||||||
android:textColor="?android:textColorPrimary"
|
|
||||||
android:textSize="16sp" />
|
|
||||||
|
|
||||||
|
<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:textSize="16sp"
|
||||||
|
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>
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/button"
|
android:id="@+id/button"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
|
Loading…
Reference in New Issue