fix: notification menu option disappears when switching tabs

This commit is contained in:
ThetaDev 2023-04-13 21:55:37 +02:00 committed by Stypox
parent e3614cb932
commit b5893f3fa3
No known key found for this signature in database
GPG Key ID: 4BDF1B40A49FDD23
1 changed files with 12 additions and 3 deletions

View File

@ -97,6 +97,7 @@ public class ChannelFragment extends BaseStateFragment<ChannelInfo>
private MenuItem menuRssButton; private MenuItem menuRssButton;
private MenuItem menuNotifyButton; private MenuItem menuNotifyButton;
private SubscriptionEntity channelSubscription;
public static ChannelFragment getInstance(final int serviceId, final String url, public static ChannelFragment getInstance(final int serviceId, final String url,
final String name) { final String name) {
@ -193,8 +194,14 @@ public class ChannelFragment extends BaseStateFragment<ChannelInfo>
Log.d(TAG, "onCreateOptionsMenu() called with: " Log.d(TAG, "onCreateOptionsMenu() called with: "
+ "menu = [" + menu + "], inflater = [" + inflater + "]"); + "menu = [" + menu + "], inflater = [" + inflater + "]");
} }
}
@Override
public void onPrepareOptionsMenu(final @NonNull Menu menu) {
super.onPrepareOptionsMenu(menu);
menuRssButton = menu.findItem(R.id.menu_item_rss); menuRssButton = menu.findItem(R.id.menu_item_rss);
menuNotifyButton = menu.findItem(R.id.menu_item_notify); menuNotifyButton = menu.findItem(R.id.menu_item_notify);
updateNotifyButton(channelSubscription);
} }
@Override @Override
@ -346,15 +353,17 @@ public class ChannelFragment extends BaseStateFragment<ChannelInfo>
info.getAvatarUrl(), info.getAvatarUrl(),
info.getDescription(), info.getDescription(),
info.getSubscriberCount()); info.getSubscriberCount());
channelSubscription = null;
updateNotifyButton(null); updateNotifyButton(null);
subscribeButtonMonitor = monitorSubscribeButton(mapOnSubscribe(channel, info)); subscribeButtonMonitor = monitorSubscribeButton(mapOnSubscribe(channel, info));
} else { } else {
if (DEBUG) { if (DEBUG) {
Log.d(TAG, "Found subscription to this channel!"); Log.d(TAG, "Found subscription to this channel!");
} }
final SubscriptionEntity subscription = subscriptionEntities.get(0); channelSubscription = subscriptionEntities.get(0);
updateNotifyButton(subscription); updateNotifyButton(channelSubscription);
subscribeButtonMonitor = monitorSubscribeButton(mapOnUnsubscribe(subscription)); subscribeButtonMonitor =
monitorSubscribeButton(mapOnUnsubscribe(channelSubscription));
} }
}; };
} }