From cdeeb24eac998c28370b2af101398d4398eee6b4 Mon Sep 17 00:00:00 2001 From: FineFindus Date: Sun, 23 Apr 2023 15:20:57 +0200 Subject: [PATCH] refactor(settings): add red header item --- .../fragments/settings/AboutFragment.java | 6 +--- .../settings/SettingsBaseFragment.java | 28 ++++++++++++++++++- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/AboutFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/AboutFragment.java index c8cdb82bf..e902d8d7c 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/AboutFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/AboutFragment.java @@ -40,10 +40,6 @@ public class AboutFragment extends SettingsBaseFragment{ public void addItems(ArrayList 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); diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsBaseFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsBaseFragment.java index a31cac8b1..efb29350a 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsBaseFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsBaseFragment.java @@ -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) 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);