feat: rework SettingsCategoryItem, and add visual appearance settings

This commit is contained in:
LucasGGamerM 2023-04-23 12:47:49 -03:00
parent 1d25d80186
commit cd749e9c9c
4 changed files with 121 additions and 114 deletions

View File

@ -1,9 +0,0 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M22,12c0,-5.523 -4.477,-10 -10,-10S2,6.477 2,12a9.96,9.96 0,0 0,1.115 4.592l-1.068,3.823a1.25,1.25 0,0 0,1.54 1.54l3.826,-1.067a9.96,9.96 0,0 0,5.368 1.082,6.518 6.518,0 0,1 -1.051,-1.474 8.449,8.449 0,0 1,-3.863 -1.066l-0.27,-0.15 -3.986,1.111 1.113,-3.984 -0.151,-0.27A8.458,8.458 0,0 1,3.5 12a8.5,8.5 0,0 1,16.996 -0.27c0.54,0.281 1.036,0.636 1.474,1.05 0.02,-0.257 0.03,-0.517 0.03,-0.78ZM12.837,16.472a2,2 0,0 0,1.441 -2.496l-0.198,-0.687a5.28,5.28 0,0 1,1.483 -0.912l0.499,0.524a2,2 0,0 0,2.899 0.001l0.493,-0.518a5.28,5.28 0,0 1,1.484 0.921l-0.186,0.631a2,2 0,0 0,1.45 2.51l0.539,0.13a5.732,5.732 0,0 1,0.006 1.808l-0.584,0.144a2,2 0,0 0,-1.44 2.496l0.197,0.686c-0.439,0.383 -0.939,0.693 -1.483,0.913l-0.498,-0.525a2,2 0,0 0,-2.9 0l-0.493,0.519a5.28,5.28 0,0 1,-1.484 -0.922l0.187,-0.631a2,2 0,0 0,-1.45 -2.51l-0.54,-0.13a5.718,5.718 0,0 1,-0.006 -1.808l0.584,-0.144ZM18.95,17.5c0,-0.828 -0.65,-1.5 -1.45,-1.5 -0.8,0 -1.45,0.672 -1.45,1.5S16.7,19 17.5,19c0.8,0 1.45,-0.672 1.45,-1.5Z"
android:fillColor="#212121"/>
</vector>

View File

@ -1,22 +1,29 @@
package org.joinmastodon.android.fragments.settings; package org.joinmastodon.android.fragments.settings;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.os.Build; import android.os.Build;
import android.view.Gravity; import android.view.Gravity;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.PopupMenu; import android.widget.PopupMenu;
import androidx.recyclerview.widget.RecyclerView;
import org.joinmastodon.android.GlobalUserPreferences; import org.joinmastodon.android.GlobalUserPreferences;
import org.joinmastodon.android.MastodonApp;
import org.joinmastodon.android.R; import org.joinmastodon.android.R;
import org.joinmastodon.android.ui.utils.UiUtils;
import java.util.ArrayList; import java.util.ArrayList;
public class SettingsAppearanceFragment extends SettingsBaseFragment { public class SettingsAppearanceFragment extends SettingsBaseFragment {
@Override @Override
public void addItems(ArrayList<Item> items) { public void addItems(ArrayList<Item> items) {
themeItem = new ThemeItem(); items.add(themeItem = new SettingsBaseFragment.ThemeItem());
items.add(themeItem); items.add(new SettingsBaseFragment.ButtonItem(R.string.sk_settings_color_palette, R.drawable.ic_fluent_color_24_regular, b -> {
items.add(new ButtonItem(R.string.sk_settings_color_palette, R.drawable.ic_fluent_color_24_regular, b -> {
PopupMenu popupMenu = new PopupMenu(getActivity(), b, Gravity.CENTER_HORIZONTAL); PopupMenu popupMenu = new PopupMenu(getActivity(), b, Gravity.CENTER_HORIZONTAL);
popupMenu.inflate(R.menu.color_palettes); popupMenu.inflate(R.menu.color_palettes);
popupMenu.getMenu().findItem(R.id.m3_color).setVisible(Build.VERSION.SDK_INT >= Build.VERSION_CODES.S); popupMenu.getMenu().findItem(R.id.m3_color).setVisible(Build.VERSION.SDK_INT >= Build.VERSION_CODES.S);
@ -35,43 +42,43 @@ public class SettingsAppearanceFragment extends SettingsBaseFragment {
case NORD -> R.string.mo_color_palette_nord; case NORD -> R.string.mo_color_palette_nord;
}); });
})); }));
items.add(new SwitchItem(R.string.theme_true_black, R.drawable.ic_fluent_dark_theme_24_regular, GlobalUserPreferences.trueBlackTheme, this::onTrueBlackThemeChanged)); items.add(new SettingsBaseFragment.SwitchItem(R.string.theme_true_black, R.drawable.ic_fluent_dark_theme_24_regular, GlobalUserPreferences.trueBlackTheme, this::onTrueBlackThemeChanged));
items.add(new SwitchItem(R.string.sk_disable_marquee, R.drawable.ic_fluent_text_more_24_regular, GlobalUserPreferences.disableMarquee, i -> { items.add(new SettingsBaseFragment.SwitchItem(R.string.sk_disable_marquee, R.drawable.ic_fluent_text_more_24_regular, GlobalUserPreferences.disableMarquee, i -> {
GlobalUserPreferences.disableMarquee = i.checked; GlobalUserPreferences.disableMarquee = i.checked;
GlobalUserPreferences.save(); GlobalUserPreferences.save();
needAppRestart = true; needAppRestart = true;
})); }));
items.add(new SwitchItem(R.string.sk_settings_uniform_icon_for_notifications, R.drawable.ic_ntf_logo, GlobalUserPreferences.uniformNotificationIcon, i -> { items.add(new SettingsBaseFragment.SwitchItem(R.string.sk_settings_uniform_icon_for_notifications, R.drawable.ic_ntf_logo, GlobalUserPreferences.uniformNotificationIcon, i -> {
GlobalUserPreferences.uniformNotificationIcon = i.checked; GlobalUserPreferences.uniformNotificationIcon = i.checked;
GlobalUserPreferences.save(); GlobalUserPreferences.save();
})); }));
items.add(new SwitchItem(R.string.sk_settings_reduce_motion, R.drawable.ic_fluent_star_emphasis_24_regular, GlobalUserPreferences.reduceMotion, i -> { items.add(new SettingsBaseFragment.SwitchItem(R.string.sk_settings_reduce_motion, R.drawable.ic_fluent_star_emphasis_24_regular, GlobalUserPreferences.reduceMotion, i -> {
GlobalUserPreferences.reduceMotion = i.checked; GlobalUserPreferences.reduceMotion = i.checked;
GlobalUserPreferences.save(); GlobalUserPreferences.save();
needAppRestart = true; needAppRestart = true;
})); }));
} }
private boolean onColorPreferenceClick(MenuItem item) { protected boolean onColorPreferenceClick(MenuItem item){
GlobalUserPreferences.ColorPreference pref = null; GlobalUserPreferences.ColorPreference pref = null;
int id = item.getItemId(); int id = item.getItemId();
if (id == R.id.m3_color) pref = GlobalUserPreferences.ColorPreference.MATERIAL3; if (id == R.id.m3_color) pref = GlobalUserPreferences.ColorPreference.MATERIAL3;
else if (id == R.id.pink_color) pref = GlobalUserPreferences.ColorPreference.PINK; else if (id == R.id.pink_color) pref = GlobalUserPreferences.ColorPreference.PINK;
else if (id == R.id.purple_color) pref = GlobalUserPreferences.ColorPreference.PURPLE; else if (id == R.id.purple_color) pref = GlobalUserPreferences.ColorPreference.PURPLE;
else if (id == R.id.green_color) pref = GlobalUserPreferences.ColorPreference.GREEN; else if (id == R.id.green_color) pref = GlobalUserPreferences.ColorPreference.GREEN;
else if (id == R.id.blue_color) pref = GlobalUserPreferences.ColorPreference.BLUE; else if (id == R.id.blue_color) pref = GlobalUserPreferences.ColorPreference.BLUE;
else if (id == R.id.brown_color) pref = GlobalUserPreferences.ColorPreference.BROWN; else if (id == R.id.brown_color) pref = GlobalUserPreferences.ColorPreference.BROWN;
else if (id == R.id.red_color) pref = GlobalUserPreferences.ColorPreference.RED; else if (id == R.id.red_color) pref = GlobalUserPreferences.ColorPreference.RED;
else if (id == R.id.yellow_color) pref = GlobalUserPreferences.ColorPreference.YELLOW; else if (id == R.id.yellow_color) pref = GlobalUserPreferences.ColorPreference.YELLOW;
else if (id == R.id.nord_color) pref = GlobalUserPreferences.ColorPreference.NORD; else if (id == R.id.nord_color) pref = GlobalUserPreferences.ColorPreference.NORD;
if (pref == null) return false; if (pref == null) return false;
GlobalUserPreferences.color=pref; GlobalUserPreferences.color=pref;
GlobalUserPreferences.save(); GlobalUserPreferences.save();
restartActivityToApplyNewTheme(); restartActivityToApplyNewTheme();
return true; return true;
} }
} }

View File

@ -2,7 +2,6 @@ package org.joinmastodon.android.fragments.settings;
import android.animation.ObjectAnimator; import android.animation.ObjectAnimator;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.Fragment;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Rect; import android.graphics.Rect;
@ -42,7 +41,6 @@ import org.joinmastodon.android.api.session.AccountSession;
import org.joinmastodon.android.api.session.AccountSessionManager; import org.joinmastodon.android.api.session.AccountSessionManager;
import org.joinmastodon.android.fragments.DomainDisplay; import org.joinmastodon.android.fragments.DomainDisplay;
import org.joinmastodon.android.fragments.MastodonToolbarFragment; import org.joinmastodon.android.fragments.MastodonToolbarFragment;
import org.joinmastodon.android.model.Instance;
import org.joinmastodon.android.model.PushNotification; import org.joinmastodon.android.model.PushNotification;
import org.joinmastodon.android.model.PushSubscription; import org.joinmastodon.android.model.PushSubscription;
import org.joinmastodon.android.ui.OutlineProviders; import org.joinmastodon.android.ui.OutlineProviders;
@ -52,7 +50,6 @@ import org.joinmastodon.android.updater.GithubSelfUpdater;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.function.Consumer; import java.util.function.Consumer;
import me.grishka.appkit.Nav;
import me.grishka.appkit.utils.BindableViewHolder; import me.grishka.appkit.utils.BindableViewHolder;
import me.grishka.appkit.utils.V; import me.grishka.appkit.utils.V;
import me.grishka.appkit.views.UsableRecyclerView; import me.grishka.appkit.views.UsableRecyclerView;
@ -66,15 +63,12 @@ public abstract class SettingsBaseFragment extends MastodonToolbarFragment imple
protected ThemeItem themeItem; protected ThemeItem themeItem;
protected boolean needAppRestart; protected boolean needAppRestart;
private Instance instance;
private String instanceName;
protected NotificationPolicyItem notificationPolicyItem; protected SettingsBaseFragment.NotificationPolicyItem notificationPolicyItem;
protected PushSubscription pushSubscription; protected PushSubscription pushSubscription;
protected ArrayList<Item> items=new ArrayList<>(); protected ArrayList<Item> items=new ArrayList<>();
protected String accountID; protected String accountID;
protected AccountSession session;
protected boolean needUpdateNotificationSettings; protected boolean needUpdateNotificationSettings;
@ -88,9 +82,7 @@ public abstract class SettingsBaseFragment extends MastodonToolbarFragment imple
setTitle(R.string.settings); setTitle(R.string.settings);
accountID=getArguments().getString("account"); accountID=getArguments().getString("account");
session = AccountSessionManager.getInstance().getAccount(accountID); AccountSession session = AccountSessionManager.getInstance().getAccount(accountID);
instance = AccountSessionManager.getInstance().getInstanceInfo(session.domain);
instanceName = UiUtils.getInstanceName(accountID);
DomainManager.getInstance().setCurrentDomain(session.domain + "/settings"); DomainManager.getInstance().setCurrentDomain(session.domain + "/settings");
addItems(items); addItems(items);
@ -131,14 +123,6 @@ public abstract class SettingsBaseFragment extends MastodonToolbarFragment imple
this.view = view; this.view = view;
} }
protected Instance getInstance() {
return instance;
}
protected String getInstanceName() {
return instanceName;
}
static abstract class Item{ static abstract class Item{
public abstract int getViewType(); public abstract int getViewType();
@ -161,29 +145,12 @@ public abstract class SettingsBaseFragment extends MastodonToolbarFragment imple
} }
} }
protected class RedHeaderItem extends HeaderItem {
public RedHeaderItem(int text){
super(text);
}
public RedHeaderItem(String text){
super(text);
}
@Override
public int getViewType(){
return Type.RED_HEADER.ordinal();
}
}
protected class SwitchItem extends Item{ protected class SwitchItem extends Item{
private String text; private String text;
private int icon; private int icon;
boolean checked; boolean checked;
private Consumer<SwitchItem> onChanged; private Consumer<SwitchItem> onChanged;
protected boolean enabled=true; private boolean enabled=true;
public SwitchItem(@StringRes int text, @DrawableRes int icon, boolean checked, Consumer<SwitchItem> onChanged){ public SwitchItem(@StringRes int text, @DrawableRes int icon, boolean checked, Consumer<SwitchItem> onChanged){
this.text=getString(text); this.text=getString(text);
@ -206,7 +173,7 @@ public abstract class SettingsBaseFragment extends MastodonToolbarFragment imple
} }
} }
protected class UpdateItem extends Item { protected class UpdateItem extends SettingsBaseFragment.Item {
@Override @Override
public int getViewType(){ public int getViewType(){
@ -214,7 +181,7 @@ public abstract class SettingsBaseFragment extends MastodonToolbarFragment imple
} }
} }
protected static class ThemeItem extends Item { protected static class ThemeItem extends SettingsBaseFragment.Item {
@Override @Override
public int getViewType(){ public int getViewType(){
@ -222,7 +189,7 @@ public abstract class SettingsBaseFragment extends MastodonToolbarFragment imple
} }
} }
protected static class NotificationPolicyItem extends Item { protected static class NotificationPolicyItem extends SettingsBaseFragment.Item {
@Override @Override
public int getViewType(){ public int getViewType(){
@ -263,7 +230,7 @@ public abstract class SettingsBaseFragment extends MastodonToolbarFragment imple
protected class TextItem extends Item{ protected class TextItem extends Item{
private String text; private String text;
protected String secondaryText; private String secondaryText;
private Runnable onClick; private Runnable onClick;
private boolean loading; private boolean loading;
private int icon; private int icon;
@ -307,20 +274,41 @@ public abstract class SettingsBaseFragment extends MastodonToolbarFragment imple
protected class SettingsCategoryItem extends Item{ protected class SettingsCategoryItem extends Item{
private String text; private String text;
private String secondaryText;
private Runnable onClick;
private boolean loading;
private int icon; private int icon;
private Class<? extends Fragment> fragmentClass; public SettingsCategoryItem(@StringRes int text, Runnable onClick) {
this(text, null, onClick, false, 0);
}
public SettingsCategoryItem(@StringRes int text, Class<? extends Fragment> fragmentClass, @DrawableRes int icon) { public SettingsCategoryItem(@StringRes int text, Runnable onClick, @DrawableRes int icon) {
this.text = getString(text); this(text, null, onClick, false, icon);
this.fragmentClass=fragmentClass; }
this.icon=icon;
}
public SettingsCategoryItem(@StringRes int text, Class<? extends Fragment> fragmentClass) { public SettingsCategoryItem(@StringRes int text, String secondaryText, Runnable onClick, @DrawableRes int icon) {
this(text, fragmentClass, 0); 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 @Override
public int getViewType(){ public int getViewType(){
@ -346,7 +334,6 @@ public abstract class SettingsBaseFragment extends MastodonToolbarFragment imple
public enum Type{ public enum Type{
HEADER, HEADER,
RED_HEADER,
SWITCH, SWITCH,
THEME, THEME,
TEXT, TEXT,
@ -355,7 +342,7 @@ public abstract class SettingsBaseFragment extends MastodonToolbarFragment imple
BUTTON, BUTTON,
SMALL_TEXT, SMALL_TEXT,
UPDATER, UPDATER,
SETTINGS_CATEGORY; SETTINGS_CATEGORY
} }
@ -367,7 +354,6 @@ public abstract class SettingsBaseFragment extends MastodonToolbarFragment imple
//noinspection unchecked //noinspection unchecked
return (BindableViewHolder<Item>) switch(Type.values()[viewType]){ return (BindableViewHolder<Item>) switch(Type.values()[viewType]){
case HEADER -> new HeaderViewHolder(); case HEADER -> new HeaderViewHolder();
case RED_HEADER -> new HeaderViewHolder(true);
case SWITCH -> new SwitchViewHolder(); case SWITCH -> new SwitchViewHolder();
case THEME -> new ThemeViewHolder(); case THEME -> new ThemeViewHolder();
case TEXT -> new TextViewHolder(); case TEXT -> new TextViewHolder();
@ -403,19 +389,34 @@ public abstract class SettingsBaseFragment extends MastodonToolbarFragment imple
text=(TextView) itemView; text=(TextView) itemView;
} }
public HeaderViewHolder(boolean red){
super(getActivity(), R.layout.item_settings_header, list);
text=(TextView) itemView;
if(red)
text.setTextColor(getResources().getColor(UiUtils.isDarkTheme() ? R.color.error_400 : R.color.error_700));
}
@Override @Override
public void onBind(HeaderItem item){ public void onBind(HeaderItem item){
text.setText(item.text); text.setText(item.text);
} }
} }
protected boolean onColorPreferenceClick(MenuItem item){
GlobalUserPreferences.ColorPreference pref = null;
int id = item.getItemId();
if (id == R.id.m3_color) pref = GlobalUserPreferences.ColorPreference.MATERIAL3;
else if (id == R.id.pink_color) pref = GlobalUserPreferences.ColorPreference.PINK;
else if (id == R.id.purple_color) pref = GlobalUserPreferences.ColorPreference.PURPLE;
else if (id == R.id.green_color) pref = GlobalUserPreferences.ColorPreference.GREEN;
else if (id == R.id.blue_color) pref = GlobalUserPreferences.ColorPreference.BLUE;
else if (id == R.id.brown_color) pref = GlobalUserPreferences.ColorPreference.BROWN;
else if (id == R.id.red_color) pref = GlobalUserPreferences.ColorPreference.RED;
else if (id == R.id.yellow_color) pref = GlobalUserPreferences.ColorPreference.YELLOW;
else if (id == R.id.nord_color) pref = GlobalUserPreferences.ColorPreference.NORD;
if (pref == null) return false;
GlobalUserPreferences.color=pref;
GlobalUserPreferences.save();
restartActivityToApplyNewTheme();
return true;
}
protected void onThemePreferenceClick(GlobalUserPreferences.ThemePreference theme){ protected void onThemePreferenceClick(GlobalUserPreferences.ThemePreference theme){
GlobalUserPreferences.theme=theme; GlobalUserPreferences.theme=theme;
GlobalUserPreferences.save(); GlobalUserPreferences.save();
@ -455,13 +456,13 @@ public abstract class SettingsBaseFragment extends MastodonToolbarFragment imple
} }
protected void onTrueBlackThemeChanged(SwitchItem item){ protected void onTrueBlackThemeChanged(SettingsBaseFragment.SwitchItem item){
GlobalUserPreferences.trueBlackTheme=item.checked; GlobalUserPreferences.trueBlackTheme=item.checked;
GlobalUserPreferences.save(); GlobalUserPreferences.save();
RecyclerView.ViewHolder themeHolder=list.findViewHolderForAdapterPosition(items.indexOf(themeItem)); RecyclerView.ViewHolder themeHolder=list.findViewHolderForAdapterPosition(items.indexOf(themeItem));
if(themeHolder!=null){ if(themeHolder!=null){
((ThemeViewHolder)themeHolder).bindSubitems(); ((SettingsBaseFragment.ThemeViewHolder)themeHolder).bindSubitems();
}else{ }else{
list.getAdapter().notifyItemChanged(items.indexOf(themeItem)); list.getAdapter().notifyItemChanged(items.indexOf(themeItem));
} }
@ -503,7 +504,7 @@ public abstract class SettingsBaseFragment extends MastodonToolbarFragment imple
} }
@Override @Override
public void onBind(NotificationPolicyItem item){ public void onBind(SettingsBaseFragment.NotificationPolicyItem item){
button.setText(switch(getPushSubscription().policy){ button.setText(switch(getPushSubscription().policy){
case ALL -> R.string.notify_anyone; case ALL -> R.string.notify_anyone;
case FOLLOWED -> R.string.notify_followed; case FOLLOWED -> R.string.notify_followed;
@ -522,7 +523,7 @@ public abstract class SettingsBaseFragment extends MastodonToolbarFragment imple
int index=items.indexOf(notificationPolicyItem); int index=items.indexOf(notificationPolicyItem);
RecyclerView.ViewHolder policyHolder=list.findViewHolderForAdapterPosition(index); RecyclerView.ViewHolder policyHolder=list.findViewHolderForAdapterPosition(index);
if(policyHolder!=null){ if(policyHolder!=null){
((NotificationPolicyViewHolder)policyHolder).rebind(); ((SettingsBaseFragment.NotificationPolicyViewHolder)policyHolder).rebind();
}else{ }else{
list.getAdapter().notifyItemChanged(index); list.getAdapter().notifyItemChanged(index);
} }
@ -532,7 +533,7 @@ public abstract class SettingsBaseFragment extends MastodonToolbarFragment imple
onNotificationsChanged(value, newState); onNotificationsChanged(value, newState);
} }
index++; index++;
while(items.size() > index && items.get(index) instanceof SwitchItem si){ while(items.get(index) instanceof SettingsBaseFragment.SwitchItem si){
si.enabled=si.checked=newState; si.enabled=si.checked=newState;
RecyclerView.ViewHolder holder=list.findViewHolderForAdapterPosition(index); RecyclerView.ViewHolder holder=list.findViewHolderForAdapterPosition(index);
if(holder!=null) if(holder!=null)
@ -572,7 +573,7 @@ public abstract class SettingsBaseFragment extends MastodonToolbarFragment imple
return pushSubscription; return pushSubscription;
} }
protected class SwitchViewHolder extends BindableViewHolder<SwitchItem> implements UsableRecyclerView.DisableableClickable{ private class SwitchViewHolder extends BindableViewHolder<SwitchItem> implements UsableRecyclerView.DisableableClickable{
private final TextView text; private final TextView text;
private final ImageView icon; private final ImageView icon;
private final Switch checkbox; private final Switch checkbox;
@ -621,7 +622,7 @@ public abstract class SettingsBaseFragment extends MastodonToolbarFragment imple
} }
@Override @Override
public void onBind(ThemeItem item){ public void onBind(SettingsBaseFragment.ThemeItem item){
bindSubitems(); bindSubitems();
} }
@ -671,7 +672,7 @@ public abstract class SettingsBaseFragment extends MastodonToolbarFragment imple
} }
} }
private class SettingsCategoryViewHolder extends BindableViewHolder<SettingsCategoryItem> implements UsableRecyclerView.Clickable{ private class SettingsCategoryViewHolder extends BindableViewHolder<SettingsCategoryItem> implements UsableRecyclerView.DisableableClickable{
private final ImageView icon; private final ImageView icon;
private final TextView text; private final TextView text;
@ -688,11 +689,16 @@ public abstract class SettingsBaseFragment extends MastodonToolbarFragment imple
icon.setImageResource(item.icon); icon.setImageResource(item.icon);
} }
@Override @Override
public void onClick() { public void onClick() {
Nav.go(getActivity(), item.fragmentClass, getArguments()); item.onClick.run();
} }
}
@Override
public boolean isEnabled(){
return true;
}
}
protected class ButtonViewHolder extends BindableViewHolder<ButtonItem>{ protected class ButtonViewHolder extends BindableViewHolder<ButtonItem>{
private final Button button; private final Button button;
@ -715,7 +721,7 @@ public abstract class SettingsBaseFragment extends MastodonToolbarFragment imple
} }
} }
protected class TextViewHolder extends BindableViewHolder<TextItem> implements UsableRecyclerView.Clickable{ private class TextViewHolder extends BindableViewHolder<TextItem> implements UsableRecyclerView.Clickable{
private final TextView text, secondaryText; private final TextView text, secondaryText;
private final ProgressBar progress; private final ProgressBar progress;
private final ImageView icon; private final ImageView icon;
@ -813,7 +819,7 @@ public abstract class SettingsBaseFragment extends MastodonToolbarFragment imple
} }
@Override @Override
public void onBind(UpdateItem item){ public void onBind(SettingsBaseFragment.UpdateItem item){
GithubSelfUpdater updater=GithubSelfUpdater.getInstance(); GithubSelfUpdater updater=GithubSelfUpdater.getInstance();
GithubSelfUpdater.UpdateState state=updater.getState(); GithubSelfUpdater.UpdateState state=updater.getState();
if (state == GithubSelfUpdater.UpdateState.CHECKING) return; if (state == GithubSelfUpdater.UpdateState.CHECKING) return;

View File

@ -1,17 +1,20 @@
package org.joinmastodon.android.fragments.settings; package org.joinmastodon.android.fragments.settings;
import android.os.Bundle;
import org.joinmastodon.android.R; import org.joinmastodon.android.R;
import java.util.ArrayList; import java.util.ArrayList;
import me.grishka.appkit.Nav;
public class SettingsMainFragment extends SettingsBaseFragment{ public class SettingsMainFragment extends SettingsBaseFragment{
@Override @Override
public void addItems(ArrayList<SettingsBaseFragment.Item> items) { public void addItems(ArrayList<SettingsBaseFragment.Item> items) {
items.add(new SettingsCategoryItem(R.string.settings_theme, SettingsAppearanceFragment.class, R.drawable.ic_fluent_color_24_regular)); items.add(new SettingsBaseFragment.SettingsCategoryItem(R.string.settings_theme, () -> {
items.add(new SettingsCategoryItem(R.string.settings_behavior, BehaviourFragment.class, R.drawable.ic_fluent_chat_settings_24_regular)); Bundle args = new Bundle();
items.add(new SettingsCategoryItem(R.string.sk_timelines, TimeLineFragment.class, R.drawable.ic_fluent_timeline_24_regular)); args.putString("account", accountID);
items.add(new SettingsCategoryItem(R.string.settings_notifications, NotificationsFragment.class, R.drawable.ic_fluent_alert_28_regular_badged)); Nav.go(getActivity(), SettingsAppearanceFragment.class, args);
items.add(new SettingsCategoryItem(R.string.settings_account, AccountFragment.class, R.drawable.ic_fluent_person_28_regular)); }, R.drawable.ic_fluent_color_24_regular));
items.add(new SettingsCategoryItem(R.string.sk_settings_about, AboutFragment.class, R.drawable.ic_fluent_info_24_regular));
} }
} }