From b5893f3fa3a0926edc0286e102464e1a0a5a08b0 Mon Sep 17 00:00:00 2001 From: ThetaDev Date: Thu, 13 Apr 2023 21:55:37 +0200 Subject: [PATCH] fix: notification menu option disappears when switching tabs --- .../fragments/list/channel/ChannelFragment.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java index 9de143518..2947cdb16 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java @@ -97,6 +97,7 @@ public class ChannelFragment extends BaseStateFragment private MenuItem menuRssButton; private MenuItem menuNotifyButton; + private SubscriptionEntity channelSubscription; public static ChannelFragment getInstance(final int serviceId, final String url, final String name) { @@ -193,8 +194,14 @@ public class ChannelFragment extends BaseStateFragment Log.d(TAG, "onCreateOptionsMenu() called with: " + "menu = [" + menu + "], inflater = [" + inflater + "]"); } + } + + @Override + public void onPrepareOptionsMenu(final @NonNull Menu menu) { + super.onPrepareOptionsMenu(menu); menuRssButton = menu.findItem(R.id.menu_item_rss); menuNotifyButton = menu.findItem(R.id.menu_item_notify); + updateNotifyButton(channelSubscription); } @Override @@ -346,15 +353,17 @@ public class ChannelFragment extends BaseStateFragment info.getAvatarUrl(), info.getDescription(), info.getSubscriberCount()); + channelSubscription = null; updateNotifyButton(null); subscribeButtonMonitor = monitorSubscribeButton(mapOnSubscribe(channel, info)); } else { if (DEBUG) { Log.d(TAG, "Found subscription to this channel!"); } - final SubscriptionEntity subscription = subscriptionEntities.get(0); - updateNotifyButton(subscription); - subscribeButtonMonitor = monitorSubscribeButton(mapOnUnsubscribe(subscription)); + channelSubscription = subscriptionEntities.get(0); + updateNotifyButton(channelSubscription); + subscribeButtonMonitor = + monitorSubscribeButton(mapOnUnsubscribe(channelSubscription)); } }; }