From 5a26207fdbc8631e53d19b11d32e685866a9dd22 Mon Sep 17 00:00:00 2001 From: ByteHamster Date: Wed, 5 Feb 2020 11:48:49 +0100 Subject: [PATCH] Removed unnecessary ItemAccess --- .../adapter/AllEpisodesRecycleAdapter.java | 32 +++++++-------- .../fragment/EpisodesListFragment.java | 39 +++---------------- 2 files changed, 19 insertions(+), 52 deletions(-) diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/AllEpisodesRecycleAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/AllEpisodesRecycleAdapter.java index 8e232a17f..c9b8e5ab2 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/AllEpisodesRecycleAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/AllEpisodesRecycleAdapter.java @@ -11,13 +11,15 @@ import androidx.recyclerview.widget.RecyclerView; import de.danoeh.antennapod.R; import de.danoeh.antennapod.activity.MainActivity; import de.danoeh.antennapod.core.feed.FeedItem; -import de.danoeh.antennapod.core.util.LongList; +import de.danoeh.antennapod.core.util.FeedItemUtil; import de.danoeh.antennapod.fragment.ItemPagerFragment; import de.danoeh.antennapod.menuhandler.FeedItemMenuHandler; import de.danoeh.antennapod.view.EpisodeItemViewHolder; import org.apache.commons.lang3.ArrayUtils; import java.lang.ref.WeakReference; +import java.util.ArrayList; +import java.util.List; /** * List adapter for the list of new episodes. @@ -26,14 +28,18 @@ public class AllEpisodesRecycleAdapter extends RecyclerView.Adapter mainActivityRef; - private final ItemAccess itemAccess; + private List episodes = new ArrayList<>(); private FeedItem selectedItem; - public AllEpisodesRecycleAdapter(MainActivity mainActivity, ItemAccess itemAccess) { + public AllEpisodesRecycleAdapter(MainActivity mainActivity) { super(); this.mainActivityRef = new WeakReference<>(mainActivity); - this.itemAccess = itemAccess; + } + + public void updateItems(List items) { + episodes = items; + notifyDataSetChanged(); } @NonNull @@ -46,7 +52,7 @@ public class AllEpisodesRecycleAdapter extends RecyclerView.Adapter { selectedItem = item; @@ -55,7 +61,7 @@ public class AllEpisodesRecycleAdapter extends RecyclerView.Adapter { MainActivity activity = mainActivityRef.get(); if (activity != null) { - long[] ids = itemAccess.getQueueIds().toArray(); + long[] ids = FeedItemUtil.getIds(episodes); int position = ArrayUtils.indexOf(ids, item.getId()); activity.loadChildFragment(ItemPagerFragment.newInstance(ids, position)); } @@ -71,13 +77,13 @@ public class AllEpisodesRecycleAdapter extends RecyclerView.Adapter episodes = new ArrayList<>(); - @NonNull - private List downloaderList = new ArrayList<>(); private boolean isUpdatingFeeds; boolean isMenuInvalidationAllowed = false; @@ -344,10 +342,10 @@ public abstract class EpisodesListFragment extends Fragment { } protected void onFragmentLoaded(List episodes) { - listAdapter.notifyDataSetChanged(); - if (episodes.size() == 0) { createRecycleAdapter(recyclerView, emptyView); + } else { + listAdapter.updateItems(episodes); } restoreScrollPosition(); @@ -360,40 +358,13 @@ public abstract class EpisodesListFragment extends Fragment { */ private void createRecycleAdapter(RecyclerView recyclerView, EmptyViewHandler emptyViewHandler) { MainActivity mainActivity = (MainActivity) getActivity(); - listAdapter = new AllEpisodesRecycleAdapter(mainActivity, itemAccess); + listAdapter = new AllEpisodesRecycleAdapter(mainActivity); listAdapter.setHasStableIds(true); + listAdapter.updateItems(episodes); recyclerView.setAdapter(listAdapter); emptyViewHandler.updateAdapter(listAdapter); } - private final AllEpisodesRecycleAdapter.ItemAccess itemAccess = new AllEpisodesRecycleAdapter.ItemAccess() { - - @Override - public int getCount() { - return episodes.size(); - } - - @Override - public FeedItem getItem(int position) { - if (0 <= position && position < episodes.size()) { - return episodes.get(position); - } - return null; - } - - @Override - public LongList getQueueIds() { - LongList queueIds = new LongList(); - for (FeedItem item : episodes) { - if (item.isTagged(FeedItem.TAG_QUEUE)) { - queueIds.add(item.getId()); - } - } - return queueIds; - } - - }; - @Subscribe(threadMode = ThreadMode.MAIN) public void onEventMainThread(FeedItemEvent event) { Log.d(TAG, "onEventMainThread() called with: " + "event = [" + event + "]"); @@ -432,7 +403,7 @@ public abstract class EpisodesListFragment extends Fragment { public void onEventMainThread(DownloadEvent event) { Log.d(TAG, "onEventMainThread() called with: " + "event = [" + event + "]"); DownloaderUpdate update = event.update; - downloaderList = update.downloaders; + List downloaderList = update.downloaders; if (isMenuInvalidationAllowed && event.hasChangedFeedUpdateStatus(isUpdatingFeeds)) { requireActivity().invalidateOptionsMenu(); }