From 80c9c591fc5cd9026353ea2a28fea590c6baa5ea Mon Sep 17 00:00:00 2001 From: FineFindus Date: Thu, 18 May 2023 22:11:54 +0200 Subject: [PATCH] feat(settings): add updater --- ...eFragment.java => AppearanceFragment.java} | 0 .../settings/SettingsMainFragment.java | 27 +++++++++++++++---- 2 files changed, 22 insertions(+), 5 deletions(-) rename mastodon/src/main/java/org/joinmastodon/android/fragments/settings/{SettingsAppearanceFragment.java => AppearanceFragment.java} (100%) diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsAppearanceFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/AppearanceFragment.java similarity index 100% rename from mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsAppearanceFragment.java rename to mastodon/src/main/java/org/joinmastodon/android/fragments/settings/AppearanceFragment.java diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsMainFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsMainFragment.java index a9eb8798d..f44209b22 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsMainFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsMainFragment.java @@ -1,20 +1,28 @@ package org.joinmastodon.android.fragments.settings; -import android.graphics.Color; -import android.os.Build; import android.os.Bundle; -import android.util.TypedValue; import android.view.View; +import org.joinmastodon.android.E; import org.joinmastodon.android.R; +import org.joinmastodon.android.updater.GithubSelfUpdater; import java.util.ArrayList; -public class SettingsMainFragment extends SettingsBaseFragment{ +public class SettingsMainFragment extends SettingsBaseFragment { @Override public void addItems(ArrayList items) { items.add(new GiantHeaderItem(getContext().getString(R.string.settings))); - items.add(new SettingsCategoryItem(R.string.settings_theme, SettingsAppearanceFragment.class, R.drawable.ic_fluent_color_24_regular)); + + if (GithubSelfUpdater.needSelfUpdating()) { + GithubSelfUpdater updater = GithubSelfUpdater.getInstance(); + GithubSelfUpdater.UpdateState state = updater.getState(); + if (state != GithubSelfUpdater.UpdateState.NO_UPDATE && state != GithubSelfUpdater.UpdateState.CHECKING && updater.getUpdateInfo() != null) { + items.add(new SettingsBaseFragment.UpdateItem()); + } + } + + items.add(new SettingsCategoryItem(R.string.settings_theme, AppearanceFragment.class, R.drawable.ic_fluent_color_24_regular)); items.add(new SettingsCategoryItem(R.string.settings_behavior, BehaviourFragment.class, R.drawable.ic_fluent_chat_settings_24_regular)); items.add(new SettingsCategoryItem(R.string.sk_timelines, TimeLineFragment.class, R.drawable.ic_fluent_timeline_24_regular)); items.add(new SettingsCategoryItem(R.string.settings_notifications, NotificationsFragment.class, R.drawable.ic_fluent_alert_28_regular_badged)); @@ -26,6 +34,15 @@ public class SettingsMainFragment extends SettingsBaseFragment{ @Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); + if (GithubSelfUpdater.needSelfUpdating()) + E.register(this); hideToolbar(); } + + @Override + public void onDestroy() { + super.onDestroy(); + if (GithubSelfUpdater.needSelfUpdating()) + E.unregister(this); + } }