diff options
author | Martin Fietz <Martin.Fietz@gmail.com> | 2016-03-28 18:08:26 +0200 |
---|---|---|
committer | Martin Fietz <Martin.Fietz@gmail.com> | 2016-04-14 18:40:01 +0200 |
commit | bf52c4945ce146ac666bf1f3c505cfec3ac80be1 (patch) | |
tree | 7274bb7c42e1da99e290f89f2f8e92e906ea463f /app/src/main/java/de/danoeh | |
parent | 8683277627f4cf60b4093c8b8e5276264af65845 (diff) | |
download | AntennaPod-bf52c4945ce146ac666bf1f3c505cfec3ac80be1.zip |
Don't use LongLists, use tags directly
Diffstat (limited to 'app/src/main/java/de/danoeh')
9 files changed, 26 insertions, 115 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 408a32f17..69cceb6b7 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/AllEpisodesRecycleAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/AllEpisodesRecycleAdapter.java @@ -289,8 +289,7 @@ public class AllEpisodesRecycleAdapter extends RecyclerView.Adapter<AllEpisodesR item1.setVisible(visible); } }; - FeedItemMenuHandler.onPrepareMenu(contextMenuInterface, item, true, - itemAccess.getQueueIds(), itemAccess.getFavoritesIds()); + FeedItemMenuHandler.onPrepareMenu(contextMenuInterface, item, true, null); } } @@ -307,10 +306,6 @@ public class AllEpisodesRecycleAdapter extends RecyclerView.Adapter<AllEpisodesR boolean isInQueue(FeedItem item); - LongList getQueueIds(); - - LongList getFavoritesIds(); - } /** diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/FeedItemlistAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/FeedItemlistAdapter.java index 0de1ca1ff..bc6cb9730 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/FeedItemlistAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/FeedItemlistAdapter.java @@ -147,6 +147,8 @@ public class FeedItemlistAdapter extends BaseAdapter { String pubDateStr = DateUtils.formatAbbrev(context, item.getPubDate()); holder.published.setText(pubDateStr); + boolean isInQueue = item.isTagged(FeedItem.TAG_QUEUE); + FeedMedia media = item.getMedia(); if (media == null) { holder.episodeProgress.setVisibility(View.GONE); @@ -157,7 +159,7 @@ public class FeedItemlistAdapter extends BaseAdapter { AdapterUtils.updateEpisodePlaybackProgress(item, holder.lenSize, holder.episodeProgress); - if (itemAccess.isInQueue(item)) { + if (isInQueue) { holder.inPlaylist.setVisibility(View.VISIBLE); } else { holder.inPlaylist.setVisibility(View.INVISIBLE); @@ -198,7 +200,6 @@ public class FeedItemlistAdapter extends BaseAdapter { } } - boolean isInQueue = itemAccess.isInQueue(item); actionButtonUtils.configureActionButton(holder.butAction, item, isInQueue); holder.butAction.setFocusable(false); holder.butAction.setTag(item); @@ -232,8 +233,6 @@ public class FeedItemlistAdapter extends BaseAdapter { public interface ItemAccess { - boolean isInQueue(FeedItem item); - int getItemDownloadProgressPercent(FeedItem item); int getCount(); diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/QueueRecyclerAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/QueueRecyclerAdapter.java index 0e3f82e37..8a590a24e 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/QueueRecyclerAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/QueueRecyclerAdapter.java @@ -188,8 +188,7 @@ public class QueueRecyclerAdapter extends RecyclerView.Adapter<QueueRecyclerAdap item1.setVisible(visible); } }; - FeedItemMenuHandler.onPrepareMenu(contextMenuInterface, item, true, - itemAccess.getQueueIds(), itemAccess.getFavoritesIds()); + FeedItemMenuHandler.onPrepareMenu(contextMenuInterface, item, true, itemAccess.getQueueIds()); } @Override @@ -317,7 +316,6 @@ public class QueueRecyclerAdapter extends RecyclerView.Adapter<QueueRecyclerAdap long getItemDownloadSize(FeedItem item); int getItemDownloadProgressPercent(FeedItem item); LongList getQueueIds(); - LongList getFavoritesIds(); } /** 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 51fb8f86f..fabe14174 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/AllEpisodesFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/AllEpisodesFragment.java @@ -378,33 +378,6 @@ public class AllEpisodesFragment extends Fragment { return item != null && item.isTagged(FeedItem.TAG_QUEUE); } - @Override - public LongList getQueueIds() { - LongList queueIds = new LongList(); - if(episodes == null) { - return queueIds; - } - for(FeedItem item : episodes) { - if(item.isTagged(FeedItem.TAG_QUEUE)) { - queueIds.add(item.getId()); - } - } - return queueIds; - } - - @Override - public LongList getFavoritesIds() { - LongList favoritesIds = new LongList(); - if(episodes == null) { - return favoritesIds; - } - for(FeedItem item : episodes) { - if(item.isTagged(FeedItem.TAG_FAVORITE)) { - favoritesIds.add(item.getId()); - } - } - return favoritesIds; - } }; public void onEventMainThread(FeedItemEvent event) { diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/ItemFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/ItemFragment.java index eca6db34e..7fa799a3d 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/ItemFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/ItemFragment.java @@ -59,7 +59,6 @@ import de.danoeh.antennapod.core.storage.DownloadRequester; import de.danoeh.antennapod.core.util.Converter; import de.danoeh.antennapod.core.util.DateUtils; import de.danoeh.antennapod.core.util.IntentUtils; -import de.danoeh.antennapod.core.util.LongList; import de.danoeh.antennapod.core.util.ShareUtils; import de.danoeh.antennapod.core.util.playback.Timeline; import de.danoeh.antennapod.menuhandler.FeedItemMenuHandler; @@ -116,8 +115,6 @@ public class ItemFragment extends Fragment implements OnSwipeGesture { private long[] feedItems; private int feedItemPos; private FeedItem item; - private LongList queue; - private LongList favorites; private String webviewData; private List<Downloader> downloaderList; @@ -313,10 +310,10 @@ public class ItemFragment extends Fragment implements OnSwipeGesture { inflater.inflate(R.menu.feeditem_options, menu); popupMenu = menu; if (item.hasMedia()) { - FeedItemMenuHandler.onPrepareMenu(popupMenuInterface, item, true, queue, favorites); + FeedItemMenuHandler.onPrepareMenu(popupMenuInterface, item, true, null); } else { // these are already available via button1 and button2 - FeedItemMenuHandler.onPrepareMenu(popupMenuInterface, item, true, queue, favorites, + FeedItemMenuHandler.onPrepareMenu(popupMenuInterface, item, true, null, R.id.mark_read_item, R.id.visit_website_item); } } @@ -582,10 +579,8 @@ public class ItemFragment extends Fragment implements OnSwipeGesture { .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(result -> { - item = (FeedItem) result[0]; - queue = (LongList) result[1]; - favorites = (LongList) result[2]; progbarLoading.setVisibility(View.GONE); + item = result; if (!itemsLoaded) { itemsLoaded = true; onFragmentLoaded(); @@ -597,25 +592,13 @@ public class ItemFragment extends Fragment implements OnSwipeGesture { }); } - private Object[] loadInBackground() { + private FeedItem loadInBackground() { FeedItem feedItem = DBReader.getFeedItem(feedItems[feedItemPos]); if (feedItem != null) { Timeline t = new Timeline(getActivity(), feedItem); webviewData = t.processShownotes(false); } - LongList queue; - if(feedItem.isTagged(FeedItem.TAG_QUEUE)) { - queue = LongList.of(feedItem.getId()); - } else { - queue = new LongList(0); - } - LongList favorites; - if(feedItem.isTagged(FeedItem.TAG_FAVORITE)) { - favorites = LongList.of(feedItem.getId()); - } else { - favorites = new LongList(0); - } - return new Object[] { feedItem, queue, favorites }; + return feedItem; } } diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/ItemlistFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/ItemlistFragment.java index d304f3872..a6ab77e6f 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/ItemlistFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/ItemlistFragment.java @@ -66,7 +66,6 @@ import de.danoeh.antennapod.core.storage.DBTasks; import de.danoeh.antennapod.core.storage.DownloadRequestException; import de.danoeh.antennapod.core.storage.DownloadRequester; import de.danoeh.antennapod.core.util.FeedItemUtil; -import de.danoeh.antennapod.core.util.LongList; import de.danoeh.antennapod.core.util.gui.MoreContentListFooterUtil; import de.danoeh.antennapod.dialog.EpisodesApplyActionFragment; import de.danoeh.antennapod.menuhandler.FeedItemMenuHandler; @@ -98,8 +97,6 @@ public class ItemlistFragment extends ListFragment { private long feedID; private Feed feed; - private LongList queuedItemsIds; - private LongList favoritedItemsId; private boolean itemsLoaded = false; private boolean viewsCreated = false; @@ -321,8 +318,7 @@ public class ItemlistFragment extends ListFragment { contextMenu = menu; lastMenuInfo = (AdapterView.AdapterContextMenuInfo) menuInfo; - FeedItemMenuHandler.onPrepareMenu(contextMenuInterface, item, true, queuedItemsIds, - favoritedItemsId); + FeedItemMenuHandler.onPrepareMenu(contextMenuInterface, item, true, null); } @Override @@ -599,11 +595,6 @@ public class ItemlistFragment extends ListFragment { } @Override - public boolean isInQueue(FeedItem item) { - return (queuedItemsIds != null) && queuedItemsIds.contains(item.getId()); - } - - @Override public int getItemDownloadProgressPercent(FeedItem item) { if (downloaderList != null) { for (Downloader downloader : downloaderList) { @@ -627,9 +618,7 @@ public class ItemlistFragment extends ListFragment { .observeOn(AndroidSchedulers.mainThread()) .subscribe(result -> { if (result != null) { - feed = (Feed) result[0]; - queuedItemsIds = (LongList) result[1]; - favoritedItemsId = (LongList) result[2]; + feed = result; itemsLoaded = true; if (viewsCreated) { onFragmentLoaded(); @@ -640,15 +629,14 @@ public class ItemlistFragment extends ListFragment { }); } - private Object[] loadData() { + private Feed loadData() { Feed feed = DBReader.getFeed(feedID); + DBReader.loadAdditionalFeedItemListData(feed.getItems()); if(feed != null && feed.getItemFilter() != null) { FeedItemFilter filter = feed.getItemFilter(); feed.setItems(filter.filter(feed.getItems())); } - LongList queuedItemsIds = DBReader.getQueueIDList(); - LongList favoritedItemsId = DBReader.getFavoriteIDList(); - return new Object[] { feed, queuedItemsIds, favoritedItemsId }; + return feed; } } diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/PlaybackHistoryFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/PlaybackHistoryFragment.java index 1d882aee1..491646c74 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/PlaybackHistoryFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/PlaybackHistoryFragment.java @@ -4,7 +4,6 @@ import android.content.Context; import android.content.res.TypedArray; import android.os.Bundle; import android.support.v4.app.ListFragment; -import android.support.v4.util.Pair; import android.support.v4.view.MenuItemCompat; import android.util.Log; import android.view.Menu; @@ -29,7 +28,7 @@ import de.danoeh.antennapod.core.service.download.Downloader; import de.danoeh.antennapod.core.storage.DBReader; import de.danoeh.antennapod.core.storage.DBWriter; import de.danoeh.antennapod.core.util.FeedItemUtil; -import de.danoeh.antennapod.core.util.LongList; + import de.greenrobot.event.EventBus; import rx.Observable; import rx.Subscription; @@ -44,7 +43,6 @@ public class PlaybackHistoryFragment extends ListFragment { EventDistributor.PLAYER_STATUS_UPDATE; private List<FeedItem> playbackHistory; - private LongList queue; private FeedItemlistAdapter adapter; private boolean itemsLoaded = false; @@ -218,10 +216,6 @@ public class PlaybackHistoryFragment extends ListFragment { } private FeedItemlistAdapter.ItemAccess itemAccess = new FeedItemlistAdapter.ItemAccess() { - @Override - public boolean isInQueue(FeedItem item) { - return (queue != null) && queue.contains(item.getId()); - } @Override public int getItemDownloadProgressPercent(FeedItem item) { @@ -260,8 +254,7 @@ public class PlaybackHistoryFragment extends ListFragment { .observeOn(AndroidSchedulers.mainThread()) .subscribe(result -> { if (result != null) { - playbackHistory = result.first; - queue = result.second; + playbackHistory = result; itemsLoaded = true; if (viewsCreated) { onFragmentLoaded(); @@ -272,11 +265,10 @@ public class PlaybackHistoryFragment extends ListFragment { }); } - private Pair<List<FeedItem>, LongList> loadData() { + private List<FeedItem> loadData() { List<FeedItem> history = DBReader.getPlaybackHistory(); - LongList queue = DBReader.getQueueIDList(); DBReader.loadAdditionalFeedItemListData(history); - return Pair.create(history, queue); + return history; } } diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java index fcec00ca6..08e681c99 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java @@ -568,20 +568,6 @@ public class QueueFragment extends Fragment { public LongList getQueueIds() { return queue != null ? LongList.of(FeedItemUtil.getIds(queue)) : new LongList(0); } - - @Override - public LongList getFavoritesIds() { - LongList favoritesIds = new LongList(); - if(queue == null) { - return favoritesIds; - } - for(FeedItem item : queue) { - if(item.isTagged(FeedItem.TAG_FAVORITE)) { - favoritesIds.add(item.getId()); - } - } - return favoritesIds; - } }; private EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() { diff --git a/app/src/main/java/de/danoeh/antennapod/menuhandler/FeedItemMenuHandler.java b/app/src/main/java/de/danoeh/antennapod/menuhandler/FeedItemMenuHandler.java index c1f94acc5..b80213459 100644 --- a/app/src/main/java/de/danoeh/antennapod/menuhandler/FeedItemMenuHandler.java +++ b/app/src/main/java/de/danoeh/antennapod/menuhandler/FeedItemMenuHandler.java @@ -3,6 +3,7 @@ package de.danoeh.antennapod.menuhandler; import android.content.Context; import android.content.Intent; import android.net.Uri; +import android.support.annotation.Nullable; import android.util.Log; import android.widget.Toast; @@ -54,14 +55,14 @@ public class FeedItemMenuHandler { * @param showExtendedMenu True if MenuItems that let the user share information about * the FeedItem and visit its website should be set visible. This * parameter should be set to false if the menu space is limited. - * @param queueAccess Used for testing if the queue contains the selected item + * @param queueAccess Used for testing if the queue contains the selected item; only used for + * move to top/bottom in the queue * @return Returns true if selectedItem is not null. */ public static boolean onPrepareMenu(MenuInterface mi, FeedItem selectedItem, boolean showExtendedMenu, - LongList queueAccess, - LongList favorites) { + @Nullable LongList queueAccess) { if (selectedItem == null) { return false; } @@ -72,10 +73,7 @@ public class FeedItemMenuHandler { mi.setItemVisibility(R.id.skip_episode_item, false); } - boolean isInQueue = false; - if(queueAccess != null) { - isInQueue = queueAccess.contains(selectedItem.getId()); - } + boolean isInQueue = selectedItem.isTagged(FeedItem.TAG_QUEUE); if(queueAccess == null || queueAccess.size() == 0 || queueAccess.get(0) == selectedItem.getId()) { mi.setItemVisibility(R.id.move_to_top_item, false); } @@ -126,7 +124,7 @@ public class FeedItemMenuHandler { mi.setItemVisibility(R.id.support_item, false); } - boolean isFavorite = favorites != null && favorites.contains(selectedItem.getId()); + boolean isFavorite = selectedItem.isTagged(FeedItem.TAG_FAVORITE); mi.setItemVisibility(R.id.add_to_favorites_item, !isFavorite); mi.setItemVisibility(R.id.remove_from_favorites_item, isFavorite); @@ -144,9 +142,8 @@ public class FeedItemMenuHandler { FeedItem selectedItem, boolean showExtendedMenu, LongList queueAccess, - LongList favorites, int... excludeIds) { - boolean rc = onPrepareMenu(mi, selectedItem, showExtendedMenu, queueAccess, favorites); + boolean rc = onPrepareMenu(mi, selectedItem, showExtendedMenu, queueAccess); if (rc && excludeIds != null) { for (int id : excludeIds) { mi.setItemVisibility(id, false); |