diff options
author | ByteHamster <info@bytehamster.com> | 2020-02-19 16:08:30 +0100 |
---|---|---|
committer | ByteHamster <info@bytehamster.com> | 2020-02-19 16:08:30 +0100 |
commit | 32c0af7e6cd7cf13833b0c0617682afe63b03391 (patch) | |
tree | 96b172a63024a26701b766c3a1c17809a155779d /app/src/main/java/de/danoeh/antennapod/fragment | |
parent | 4e26749757088a9f32fd1b6f89c28a186a9d32dd (diff) | |
download | AntennaPod-32c0af7e6cd7cf13833b0c0617682afe63b03391.zip |
Fixed flashing refresh button
Diffstat (limited to 'app/src/main/java/de/danoeh/antennapod/fragment')
4 files changed, 32 insertions, 34 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/AllEpisodesFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/AllEpisodesFragment.java index edcc566f2..216c8cc57 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/AllEpisodesFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/AllEpisodesFragment.java @@ -62,7 +62,7 @@ public class AllEpisodesFragment extends EpisodesListFragment { public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); menu.findItem(R.id.filter_items).setVisible(true); - menu.findItem(R.id.mark_all_read_item).setVisible(!episodes.isEmpty()); + menu.findItem(R.id.mark_all_read_item).setVisible(true); } @Override diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/EpisodesFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/EpisodesFragment.java index 8cdec9f38..49398d104 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/EpisodesFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/EpisodesFragment.java @@ -4,6 +4,7 @@ import android.content.Context; import android.content.SharedPreferences; import android.content.res.Resources; import android.os.Bundle; +import androidx.annotation.NonNull; import com.google.android.material.tabs.TabLayout; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; @@ -47,7 +48,7 @@ public class EpisodesFragment extends Fragment { View rootView = inflater.inflate(R.layout.pager_fragment, container, false); viewPager = rootView.findViewById(R.id.viewpager); - viewPager.setAdapter(new EpisodesPagerAdapter(getChildFragmentManager(), getResources())); + viewPager.setAdapter(new EpisodesPagerAdapter()); // Give the TabLayout the ViewPager tabLayout = rootView.findViewById(R.id.sliding_tabs); @@ -76,23 +77,23 @@ public class EpisodesFragment extends Fragment { viewPager.setCurrentItem(lastPosition); } - public static class EpisodesPagerAdapter extends FragmentPagerAdapter { + public class EpisodesPagerAdapter extends FragmentPagerAdapter { - private final Resources resources; - private final EpisodesListFragment[] fragments = { - new NewEpisodesFragment(), - new AllEpisodesFragment(), - new FavoriteEpisodesFragment() - }; - - public EpisodesPagerAdapter(FragmentManager fm, Resources resources) { - super(fm); - this.resources = resources; + public EpisodesPagerAdapter() { + super(getChildFragmentManager()); } @Override + @NonNull public Fragment getItem(int position) { - return fragments[position]; + switch (position) { + case 0: + return new NewEpisodesFragment(); + case 1: + return new AllEpisodesFragment(); + default: + return new FavoriteEpisodesFragment(); + } } @Override @@ -104,23 +105,14 @@ public class EpisodesFragment extends Fragment { public CharSequence getPageTitle(int position) { switch (position) { case POS_ALL_EPISODES: - return resources.getString(R.string.all_episodes_short_label); + return getString(R.string.all_episodes_short_label); case POS_NEW_EPISODES: - return resources.getString(R.string.new_episodes_label); + return getString(R.string.new_episodes_label); case POS_FAV_EPISODES: - return resources.getString(R.string.favorite_episodes_label); + return getString(R.string.favorite_episodes_label); default: 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); - } - } } } diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/EpisodesListFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/EpisodesListFragment.java index 6176ca410..7258aec8e 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/EpisodesListFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/EpisodesListFragment.java @@ -81,9 +81,8 @@ public abstract class EpisodesListFragment extends Fragment { @NonNull List<FeedItem> episodes = new ArrayList<>(); - private boolean isUpdatingFeeds; - boolean isMenuInvalidationAllowed = false; - + private volatile boolean isUpdatingFeeds; + private boolean isMenuVisible = true; protected Disposable disposable; private LinearLayoutManager layoutManager; protected TextView txtvInformation; @@ -157,6 +156,12 @@ public abstract class EpisodesListFragment extends Fragment { () -> DownloadService.isRunning && DownloadRequester.getInstance().isDownloadingFeeds(); @Override + public void setMenuVisibility(final boolean visible) { + super.setMenuVisibility(visible); + isMenuVisible = visible; + } + + @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { if (!isAdded()) { return; @@ -346,7 +351,9 @@ public abstract class EpisodesListFragment extends Fragment { } restoreScrollPosition(); - requireActivity().invalidateOptionsMenu(); + if (isMenuVisible && isUpdatingFeeds != updateRefreshMenuItemChecker.isRefreshing()) { + requireActivity().invalidateOptionsMenu(); + } } /** @@ -400,8 +407,7 @@ public abstract class EpisodesListFragment extends Fragment { public void onEventMainThread(DownloadEvent event) { Log.d(TAG, "onEventMainThread() called with: " + "event = [" + event + "]"); DownloaderUpdate update = event.update; - List<Downloader> downloaderList = update.downloaders; - if (isMenuInvalidationAllowed && event.hasChangedFeedUpdateStatus(isUpdatingFeeds)) { + if (isMenuVisible && event.hasChangedFeedUpdateStatus(isUpdatingFeeds)) { requireActivity().invalidateOptionsMenu(); } if (update.mediaIds.length > 0) { @@ -416,7 +422,7 @@ public abstract class EpisodesListFragment extends Fragment { private void updateUi() { loadItems(); - if (isUpdatingFeeds != updateRefreshMenuItemChecker.isRefreshing()) { + if (isMenuVisible && isUpdatingFeeds != updateRefreshMenuItemChecker.isRefreshing()) { requireActivity().invalidateOptionsMenu(); } } diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/NewEpisodesFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/NewEpisodesFragment.java index 33e686a90..94f71894b 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/NewEpisodesFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/NewEpisodesFragment.java @@ -40,7 +40,7 @@ public class NewEpisodesFragment extends EpisodesListFragment { @Override public void onPrepareOptionsMenu(Menu menu) { super.onPrepareOptionsMenu(menu); - menu.findItem(R.id.remove_all_new_flags_item).setVisible(!episodes.isEmpty()); + menu.findItem(R.id.remove_all_new_flags_item).setVisible(true); } @NonNull |