Merge pull request #2304 from ByteHamster/start-once

Only allow menu invalidations from active fragment
This commit is contained in:
Martin Fietz 2017-04-17 09:03:55 +02:00 committed by GitHub
commit dcb3b578ac
2 changed files with 17 additions and 10 deletions

View File

@ -80,6 +80,7 @@ public class AllEpisodesFragment extends Fragment {
private boolean viewsCreated = false;
private boolean isUpdatingFeeds;
protected boolean isMenuInvalidationAllowed = false;
protected Subscription subscription;
private LinearLayoutManager layoutManager;
@ -430,7 +431,7 @@ public class AllEpisodesFragment extends Fragment {
Log.d(TAG, "onEventMainThread() called with: " + "event = [" + event + "]");
DownloaderUpdate update = event.update;
downloaderList = update.downloaders;
if (isUpdatingFeeds != update.feedIds.length > 0) {
if (isMenuInvalidationAllowed && isUpdatingFeeds != update.feedIds.length > 0) {
getActivity().supportInvalidateOptionsMenu();
}
if(listAdapter != null && update.mediaIds.length > 0) {

View File

@ -79,6 +79,11 @@ public class EpisodesFragment extends Fragment {
public static class EpisodesPagerAdapter extends FragmentPagerAdapter {
private final Resources resources;
private AllEpisodesFragment[] fragments = {
new NewEpisodesFragment(),
new AllEpisodesFragment(),
new FavoriteEpisodesFragment()
};
public EpisodesPagerAdapter(FragmentManager fm, Resources resources) {
super(fm);
@ -87,15 +92,7 @@ public class EpisodesFragment extends Fragment {
@Override
public Fragment getItem(int position) {
switch (position) {
case POS_ALL_EPISODES:
return new AllEpisodesFragment();
case POS_NEW_EPISODES:
return new NewEpisodesFragment();
case POS_FAV_EPISODES:
return new FavoriteEpisodesFragment();
}
return null;
return fragments[position];
}
@Override
@ -116,5 +113,14 @@ public class EpisodesFragment extends Fragment {
return super.getPageTitle(position);
}
}
@Override
public void setPrimaryItem(ViewGroup container, int position, Object object) {
super.setPrimaryItem(container, position, object);
for (int i = 0; i < TOTAL_COUNT; i++) {
// Invalidating the OptionsMenu is only allowed for the currently active fragment
fragments[i].isMenuInvalidationAllowed = (i == position);
}
}
}
}