feat(settings): add summary label to button

This commit is contained in:
FineFindus 2023-05-16 21:50:54 +02:00
parent e94364ecf6
commit f7c76f7503
No known key found for this signature in database
GPG Key ID: 64873EE210FF8E6B
2 changed files with 50 additions and 19 deletions

View File

@ -8,10 +8,10 @@ import android.graphics.Canvas;
import android.graphics.Rect;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowInsets;
@ -241,12 +241,20 @@ public abstract class SettingsBaseFragment extends MastodonToolbarFragment imple
protected class ButtonItem extends Item{
private int text;
private int title;
private int summary;
private int icon;
private Consumer<Button> buttonConsumer;
public ButtonItem(@StringRes int text, @DrawableRes int icon, Consumer<Button> buttonConsumer) {
this.text = text;
public ButtonItem(@StringRes int title, @DrawableRes int icon, Consumer<Button> buttonConsumer) {
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.buttonConsumer = buttonConsumer;
}
@ -714,19 +722,27 @@ public abstract class SettingsBaseFragment extends MastodonToolbarFragment imple
protected class ButtonViewHolder extends BindableViewHolder<ButtonItem>{
private final Button button;
private final ImageView icon;
private final TextView text;
private final TextView title;
private final TextView summary;
@SuppressLint("ClickableViewAccessibility")
public ButtonViewHolder(){
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);
button=findViewById(R.id.button);
}
@Override
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);
item.buttonConsumer.accept(button);
}

View File

@ -13,24 +13,39 @@
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_marginEnd="32dp"
android:importantForAccessibility="no"
android:tint="?android:textColorPrimary"
tools:src="@drawable/ic_fluent_color_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:layout_marginEnd="8dp"
android:paddingVertical="8dp"
android:gravity="center_vertical"
android:textColor="?android:textColorPrimary"
android:textSize="16sp" />
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: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
android:id="@+id/button"
android:layout_width="wrap_content"