refactor: use SettingsCategory to move between pages
This commit is contained in:
parent
78a0c60600
commit
6343da1410
|
@ -2,6 +2,7 @@ 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;
|
||||||
|
@ -50,6 +51,7 @@ 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;
|
||||||
|
@ -274,42 +276,21 @@ 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;
|
||||||
|
|
||||||
public SettingsCategoryItem(@StringRes int text, Runnable onClick) {
|
private Class<? extends Fragment> fragmentClass;
|
||||||
this(text, null, onClick, false, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public SettingsCategoryItem(@StringRes int text, Runnable onClick, @DrawableRes int icon) {
|
public SettingsCategoryItem(@StringRes int text, Class<? extends Fragment> fragmentClass, @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.text = getString(text);
|
||||||
this.onClick=onClick;
|
this.fragmentClass=fragmentClass;
|
||||||
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;
|
this.icon=icon;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SettingsCategoryItem(@StringRes int text, Class<? extends Fragment> fragmentClass) {
|
||||||
|
this(text, fragmentClass, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getViewType(){
|
public int getViewType(){
|
||||||
return Type.SETTINGS_CATEGORY.ordinal();
|
return Type.SETTINGS_CATEGORY.ordinal();
|
||||||
|
@ -650,7 +631,7 @@ public abstract class SettingsBaseFragment extends MastodonToolbarFragment imple
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class SettingsCategoryViewHolder extends BindableViewHolder<SettingsCategoryItem>{
|
private class SettingsCategoryViewHolder extends BindableViewHolder<SettingsCategoryItem> implements UsableRecyclerView.Clickable{
|
||||||
private final ImageView icon;
|
private final ImageView icon;
|
||||||
private final TextView text;
|
private final TextView text;
|
||||||
|
|
||||||
|
@ -665,7 +646,11 @@ public abstract class SettingsBaseFragment extends MastodonToolbarFragment imple
|
||||||
public void onBind(SettingsCategoryItem item){
|
public void onBind(SettingsCategoryItem item){
|
||||||
text.setText(item.text);
|
text.setText(item.text);
|
||||||
icon.setImageResource(item.icon);
|
icon.setImageResource(item.icon);
|
||||||
item.onClick.run();
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick() {
|
||||||
|
Nav.go(getActivity(), item.fragmentClass, getArguments());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,8 +7,6 @@ import java.util.ArrayList;
|
||||||
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 SettingsBaseFragment.SettingsCategoryItem(R.string.settings_theme, () -> {
|
items.add(new SettingsCategoryItem(R.string.settings_theme, SettingsAppearanceFragment.class, R.drawable.ic_fluent_color_24_regular));
|
||||||
System.out.println("YAY");
|
|
||||||
}, R.drawable.ic_fluent_color_24_regular));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue