refactor(settings): add red header item

This commit is contained in:
FineFindus 2023-04-23 15:20:57 +02:00
parent 5a5181fde8
commit cdeeb24eac
No known key found for this signature in database
GPG Key ID: 64873EE210FF8E6B
2 changed files with 28 additions and 6 deletions

View File

@ -40,10 +40,6 @@ public class AboutFragment extends SettingsBaseFragment{
public void addItems(ArrayList<Item> items) {
items.add(new HeaderItem(R.string.sk_settings_about));
// if(BuildConfig.BUILD_TYPE.equals("nightly")){
// items.add(new TextItem(R.string.mo_download_latest_nightly_release, ()->UiUtils.launchWebBrowser(getActivity(), "https://nightly.link/LucasGGamerM/moshidon/workflows/nightly-builds/master/moshidon-nightly.apk.zip"), R.drawable.ic_fluent_open_24_regular));
// }
items.add(new TextItem(R.string.mo_settings_contribute, ()->UiUtils.launchWebBrowser(getActivity(), "https://github.com/LucasGGamerM/moshidon"), R.drawable.ic_fluent_open_24_regular));
items.add(new TextItem(R.string.sk_settings_donate, ()->UiUtils.launchWebBrowser(getActivity(), "https://github.com/sponsors/LucasGGamerM"), R.drawable.ic_fluent_heart_24_regular));
@ -70,7 +66,7 @@ public class AboutFragment extends SettingsBaseFragment{
}));
if(BuildConfig.DEBUG){
items.add(new HeaderItem("Debug options"));
items.add(new RedHeaderItem("Debug options"));
items.add(new TextItem("Test E-Mail confirmation flow", ()->{
AccountSession sess=AccountSessionManager.getInstance().getAccount(accountID);

View File

@ -161,6 +161,23 @@ 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{
private String text;
private int icon;
@ -329,6 +346,7 @@ public abstract class SettingsBaseFragment extends MastodonToolbarFragment imple
public enum Type{
HEADER,
RED_HEADER,
SWITCH,
THEME,
TEXT,
@ -337,7 +355,7 @@ public abstract class SettingsBaseFragment extends MastodonToolbarFragment imple
BUTTON,
SMALL_TEXT,
UPDATER,
SETTINGS_CATEGORY
SETTINGS_CATEGORY;
}
@ -349,6 +367,7 @@ public abstract class SettingsBaseFragment extends MastodonToolbarFragment imple
//noinspection unchecked
return (BindableViewHolder<Item>) switch(Type.values()[viewType]){
case HEADER -> new HeaderViewHolder();
case RED_HEADER -> new HeaderViewHolder(true);
case SWITCH -> new SwitchViewHolder();
case THEME -> new ThemeViewHolder();
case TEXT -> new TextViewHolder();
@ -384,6 +403,13 @@ public abstract class SettingsBaseFragment extends MastodonToolbarFragment imple
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
public void onBind(HeaderItem item){
text.setText(item.text);