feat: add settings category view holder
Also adds a small proof of concept
This commit is contained in:
parent
44b1bc70af
commit
fc9ffc9aef
|
@ -47,6 +47,7 @@ import org.joinmastodon.android.events.ListDeletedEvent;
|
|||
import org.joinmastodon.android.events.ListUpdatedCreatedEvent;
|
||||
import org.joinmastodon.android.events.SelfUpdateStateChangedEvent;
|
||||
import org.joinmastodon.android.fragments.settings.SettingsFragment;
|
||||
import org.joinmastodon.android.fragments.settings.SettingsMainFragment;
|
||||
import org.joinmastodon.android.model.Announcement;
|
||||
import org.joinmastodon.android.model.Hashtag;
|
||||
import org.joinmastodon.android.model.HeaderPaginationList;
|
||||
|
@ -462,7 +463,7 @@ public class HomeTabFragment extends MastodonToolbarFragment implements Scrollab
|
|||
getToolbar().post(() -> overflowPopup.show());
|
||||
return true;
|
||||
} else if (id == R.id.settings || id == R.id.settings_action) {
|
||||
Nav.go(getActivity(), SettingsFragment.class, args);
|
||||
Nav.go(getActivity(), SettingsMainFragment.class, args);
|
||||
} else if (id == R.id.announcements || id == R.id.announcements_action) {
|
||||
Nav.goForResult(getActivity(), AnnouncementsFragment.class, args, ANNOUNCEMENTS_RESULT, this);
|
||||
} else if (id == R.id.edit_timelines) {
|
||||
|
|
|
@ -118,11 +118,11 @@ public abstract class SettingsBaseFragment extends MastodonToolbarFragment imple
|
|||
}
|
||||
|
||||
|
||||
private static abstract class Item{
|
||||
static abstract class Item{
|
||||
public abstract int getViewType();
|
||||
}
|
||||
|
||||
private class HeaderItem extends Item{
|
||||
protected class HeaderItem extends Item{
|
||||
private String text;
|
||||
|
||||
public HeaderItem(@StringRes int text){
|
||||
|
@ -139,7 +139,7 @@ public abstract class SettingsBaseFragment extends MastodonToolbarFragment imple
|
|||
}
|
||||
}
|
||||
|
||||
private class SwitchItem extends Item{
|
||||
protected class SwitchItem extends Item{
|
||||
private String text;
|
||||
private int icon;
|
||||
private boolean checked;
|
||||
|
@ -167,7 +167,7 @@ public abstract class SettingsBaseFragment extends MastodonToolbarFragment imple
|
|||
}
|
||||
}
|
||||
|
||||
private class UpdateItem extends SettingsBaseFragment.Item {
|
||||
protected class UpdateItem extends SettingsBaseFragment.Item {
|
||||
|
||||
@Override
|
||||
public int getViewType(){
|
||||
|
@ -175,7 +175,7 @@ public abstract class SettingsBaseFragment extends MastodonToolbarFragment imple
|
|||
}
|
||||
}
|
||||
|
||||
private static class ThemeItem extends SettingsBaseFragment.Item {
|
||||
protected static class ThemeItem extends SettingsBaseFragment.Item {
|
||||
|
||||
@Override
|
||||
public int getViewType(){
|
||||
|
@ -183,7 +183,7 @@ public abstract class SettingsBaseFragment extends MastodonToolbarFragment imple
|
|||
}
|
||||
}
|
||||
|
||||
private static class NotificationPolicyItem extends SettingsBaseFragment.Item {
|
||||
protected static class NotificationPolicyItem extends SettingsBaseFragment.Item {
|
||||
|
||||
@Override
|
||||
public int getViewType(){
|
||||
|
@ -192,7 +192,7 @@ public abstract class SettingsBaseFragment extends MastodonToolbarFragment imple
|
|||
}
|
||||
|
||||
|
||||
public class ButtonItem extends Item{
|
||||
protected class ButtonItem extends Item{
|
||||
private int text;
|
||||
private int icon;
|
||||
private Consumer<Button> buttonConsumer;
|
||||
|
@ -209,7 +209,7 @@ public abstract class SettingsBaseFragment extends MastodonToolbarFragment imple
|
|||
}
|
||||
}
|
||||
|
||||
private class SmallTextItem extends Item {
|
||||
protected class SmallTextItem extends Item {
|
||||
private String text;
|
||||
|
||||
public SmallTextItem(String text) {
|
||||
|
@ -222,7 +222,7 @@ public abstract class SettingsBaseFragment extends MastodonToolbarFragment imple
|
|||
}
|
||||
}
|
||||
|
||||
private class TextItem extends Item{
|
||||
protected class TextItem extends Item{
|
||||
private String text;
|
||||
private String secondaryText;
|
||||
private Runnable onClick;
|
||||
|
@ -266,7 +266,52 @@ public abstract class SettingsBaseFragment extends MastodonToolbarFragment imple
|
|||
}
|
||||
}
|
||||
|
||||
private class FooterItem extends Item{
|
||||
protected class SettingsCategoryItem extends Item{
|
||||
private String text;
|
||||
private String secondaryText;
|
||||
private Runnable onClick;
|
||||
private boolean loading;
|
||||
private int icon;
|
||||
|
||||
public SettingsCategoryItem(@StringRes int text, Runnable onClick) {
|
||||
this(text, null, onClick, false, 0);
|
||||
}
|
||||
|
||||
public SettingsCategoryItem(@StringRes int text, Runnable onClick, @DrawableRes int icon) {
|
||||
this(text, null, onClick, false, icon);
|
||||
}
|
||||
|
||||
public SettingsCategoryItem(@StringRes int text, String secondaryText, Runnable onClick, @DrawableRes int icon) {
|
||||
this(text, secondaryText, onClick, false, icon);
|
||||
}
|
||||
|
||||
public SettingsCategoryItem(@StringRes int text, String secondaryText, Runnable onClick, boolean loading, @DrawableRes int icon){
|
||||
this.text=getString(text);
|
||||
this.onClick=onClick;
|
||||
this.loading=loading;
|
||||
this.icon=icon;
|
||||
this.secondaryText = secondaryText;
|
||||
}
|
||||
|
||||
public SettingsCategoryItem(String text, Runnable onClick){
|
||||
this.text=text;
|
||||
this.onClick=onClick;
|
||||
}
|
||||
|
||||
public SettingsCategoryItem(String text, Runnable onClick, @DrawableRes int icon){
|
||||
this.text=text;
|
||||
this.onClick=onClick;
|
||||
this.icon=icon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getViewType(){
|
||||
return Type.SETTINGS_CATEGORY.ordinal();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected class FooterItem extends Item{
|
||||
private String text;
|
||||
private Runnable onClick;
|
||||
|
||||
|
@ -290,7 +335,8 @@ public abstract class SettingsBaseFragment extends MastodonToolbarFragment imple
|
|||
FOOTER,
|
||||
BUTTON,
|
||||
SMALL_TEXT,
|
||||
UPDATER
|
||||
UPDATER,
|
||||
SETTINGS_CATEGORY
|
||||
}
|
||||
|
||||
|
||||
|
@ -310,6 +356,7 @@ public abstract class SettingsBaseFragment extends MastodonToolbarFragment imple
|
|||
case BUTTON -> new ButtonViewHolder();
|
||||
case SMALL_TEXT -> new SmallTextViewHolder();
|
||||
case UPDATER -> new UpdateViewHolder();
|
||||
case SETTINGS_CATEGORY -> new SettingsCategoryViewHolder();
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -571,6 +618,25 @@ public abstract class SettingsBaseFragment extends MastodonToolbarFragment imple
|
|||
}
|
||||
}
|
||||
|
||||
private class SettingsCategoryViewHolder extends BindableViewHolder<SettingsCategoryItem>{
|
||||
private final ImageView icon;
|
||||
private final TextView text;
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
public SettingsCategoryViewHolder(){
|
||||
super(getActivity(), R.layout.item_settings_category, list);
|
||||
text=findViewById(R.id.text);
|
||||
icon=findViewById(R.id.icon);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBind(SettingsCategoryItem item){
|
||||
text.setText(item.text);
|
||||
icon.setImageResource(item.icon);
|
||||
item.onClick.run();
|
||||
}
|
||||
}
|
||||
|
||||
private class ButtonViewHolder extends BindableViewHolder<ButtonItem>{
|
||||
private final Button button;
|
||||
private final ImageView icon;
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
package org.joinmastodon.android.fragments.settings;
|
||||
|
||||
import org.joinmastodon.android.R;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class SettingsMainFragment extends SettingsBaseFragment{
|
||||
@Override
|
||||
public void addItems(ArrayList<SettingsBaseFragment.Item> items) {
|
||||
items.add(new SettingsBaseFragment.SettingsCategoryItem(R.string.settings_theme, () -> {
|
||||
System.out.println("YAY");
|
||||
}, R.drawable.ic_fluent_color_24_regular));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="48dp"
|
||||
android:gravity="center_vertical"
|
||||
android:layoutDirection="locale">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/icon"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:layout_marginStart="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"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:paddingVertical="8dp"
|
||||
android:gravity="center_vertical"
|
||||
android:textColor="?android:textColorPrimary"
|
||||
android:textSize="16sp" />
|
||||
</LinearLayout>
|
Loading…
Reference in New Issue