From da9d00be7d5bcda1a3cb587f8edc9c1f83a2d8aa Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Wed, 30 Jan 2019 17:11:32 -0500 Subject: [PATCH] Update Topic --- .../java/com/topjohnwu/magisk/utils/Topic.java | 15 ++++++--------- .../topjohnwu/magisk/components/BaseActivity.java | 3 +++ .../topjohnwu/magisk/components/BaseFragment.java | 5 ++++- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/app-core/src/main/java/com/topjohnwu/magisk/utils/Topic.java b/app-core/src/main/java/com/topjohnwu/magisk/utils/Topic.java index 0c78abe2b..ef267aa4a 100644 --- a/app-core/src/main/java/com/topjohnwu/magisk/utils/Topic.java +++ b/app-core/src/main/java/com/topjohnwu/magisk/utils/Topic.java @@ -15,16 +15,15 @@ public class Topic { public static final int MODULE_LOAD_DONE = 1; public static final int REPO_LOAD_DONE = 2; public static final int UPDATE_CHECK_DONE = 3; - public static final int SNET_CHECK_DONE = 4; - public static final int LOCALE_FETCH_DONE = 5; + public static final int LOCALE_FETCH_DONE = 4; @IntDef({MAGISK_HIDE_DONE, MODULE_LOAD_DONE, REPO_LOAD_DONE, - UPDATE_CHECK_DONE, SNET_CHECK_DONE, LOCALE_FETCH_DONE}) + UPDATE_CHECK_DONE, LOCALE_FETCH_DONE}) @Retention(RetentionPolicy.SOURCE) public @interface TopicID {} // We will not dynamically add topics, so use arrays instead of hash tables - private static Store[] topicList = new Store[6]; + private static Store[] topicList = new Store[5]; public static void subscribe(Subscriber sub, @TopicID int... topics) { for (int topic : topics) { @@ -38,8 +37,7 @@ public class Topic { } public static void subscribe(AutoSubscriber sub) { - if (sub instanceof Subscriber) - subscribe((Subscriber) sub, sub.getSubscribedTopics()); + subscribe(sub, sub.getSubscribedTopics()); } public static void unsubscribe(Subscriber sub, @TopicID int... topics) { @@ -51,8 +49,7 @@ public class Topic { } public static void unsubscribe(AutoSubscriber sub) { - if (sub instanceof Subscriber) - unsubscribe((Subscriber) sub, sub.getSubscribedTopics()); + unsubscribe(sub, sub.getSubscribedTopics()); } public static void publish(@TopicID int topic, Object... results) { @@ -100,7 +97,7 @@ public class Topic { void onPublish(int topic, Object[] result); } - public interface AutoSubscriber { + public interface AutoSubscriber extends Subscriber { @TopicID int[] getSubscribedTopics(); } diff --git a/app/src/full/java/com/topjohnwu/magisk/components/BaseActivity.java b/app/src/full/java/com/topjohnwu/magisk/components/BaseActivity.java index eac5571c5..0d0f82a77 100644 --- a/app/src/full/java/com/topjohnwu/magisk/components/BaseActivity.java +++ b/app/src/full/java/com/topjohnwu/magisk/components/BaseActivity.java @@ -43,6 +43,9 @@ public abstract class BaseActivity extends AppCompatActivity implements Topic.Au return EMPTY_INT_ARRAY; } + @Override + public void onPublish(int topic, Object[] result) {} + @StyleRes public int getDarkTheme() { return -1; diff --git a/app/src/full/java/com/topjohnwu/magisk/components/BaseFragment.java b/app/src/full/java/com/topjohnwu/magisk/components/BaseFragment.java index 5669b4f29..a3c0e8b6d 100644 --- a/app/src/full/java/com/topjohnwu/magisk/components/BaseFragment.java +++ b/app/src/full/java/com/topjohnwu/magisk/components/BaseFragment.java @@ -8,7 +8,7 @@ import com.topjohnwu.magisk.utils.Topic; import androidx.fragment.app.Fragment; import butterknife.Unbinder; -public class BaseFragment extends Fragment implements Topic.AutoSubscriber { +public abstract class BaseFragment extends Fragment implements Topic.AutoSubscriber { public App app = App.self; protected Unbinder unbinder = null; @@ -49,4 +49,7 @@ public class BaseFragment extends Fragment implements Topic.AutoSubscriber { public int[] getSubscribedTopics() { return BaseActivity.EMPTY_INT_ARRAY; } + + @Override + public void onPublish(int topic, Object[] result) {} }