diff options
author | Martin Fietz <Martin.Fietz@gmail.com> | 2015-05-11 17:14:42 +0200 |
---|---|---|
committer | Martin Fietz <Martin.Fietz@gmail.com> | 2015-05-19 11:58:38 +0200 |
commit | 4561f16f11ed2f27d711d3ea42f5e84bcccc002c (patch) | |
tree | ed439456b9d56a2c2981876d27e14b30a89c1315 /app | |
parent | c829a4e9b2cf7ccee117269769d71c40432f92fa (diff) | |
download | AntennaPod-4561f16f11ed2f27d711d3ea42f5e84bcccc002c.zip |
Redone new indicator
Diffstat (limited to 'app')
-rw-r--r-- | app/src/androidTest/java/de/test/antennapod/storage/DBReaderTest.java | 9 | ||||
-rw-r--r-- | app/src/main/java/de/danoeh/antennapod/adapter/AllEpisodesListAdapter.java (renamed from app/src/main/java/de/danoeh/antennapod/adapter/NewEpisodesListAdapter.java) | 12 | ||||
-rw-r--r-- | app/src/main/java/de/danoeh/antennapod/adapter/FeedItemlistAdapter.java | 6 | ||||
-rw-r--r-- | app/src/main/java/de/danoeh/antennapod/config/StorageCallbacksImpl.java | 6 | ||||
-rw-r--r-- | app/src/main/java/de/danoeh/antennapod/fragment/AllEpisodesFragment.java | 33 | ||||
-rw-r--r-- | app/src/main/java/de/danoeh/antennapod/fragment/ItemlistFragment.java | 31 | ||||
-rw-r--r-- | app/src/main/java/de/danoeh/antennapod/fragment/PlaybackHistoryFragment.java | 5 | ||||
-rw-r--r-- | app/src/main/java/de/danoeh/antennapod/menuhandler/FeedItemMenuHandler.java | 2 |
8 files changed, 75 insertions, 29 deletions
diff --git a/app/src/androidTest/java/de/test/antennapod/storage/DBReaderTest.java b/app/src/androidTest/java/de/test/antennapod/storage/DBReaderTest.java index ca4f2620f..b00817ba1 100644 --- a/app/src/androidTest/java/de/test/antennapod/storage/DBReaderTest.java +++ b/app/src/androidTest/java/de/test/antennapod/storage/DBReaderTest.java @@ -301,7 +301,7 @@ public class DBReaderTest extends InstrumentationTestCase { } } - public void testGetUnreadItemIds() { + public void testGetNewItemIds() { final Context context = getInstrumentation().getTargetContext(); final int numItems = 10; @@ -310,10 +310,11 @@ public class DBReaderTest extends InstrumentationTestCase { for (int i = 0; i < unread.size(); i++) { unreadIds[i] = unread.get(i).getId(); } - long[] unreadSaved = DBReader.getUnreadItemIds(context); + LongList unreadSaved = DBReader.getNewItemIds(context); assertNotNull(unreadSaved); - assertTrue(unread.size() == unreadSaved.length); - for (long savedId : unreadSaved) { + assertTrue(unread.size() == unreadSaved.size()); + for(int i=0; i < unreadSaved.size(); i++) { + long savedId = unreadSaved.get(i); boolean found = false; for (long id : unreadIds) { if (id == savedId) { diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/NewEpisodesListAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/AllEpisodesListAdapter.java index 7ad40340d..ea0c96be9 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/NewEpisodesListAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/AllEpisodesListAdapter.java @@ -22,19 +22,22 @@ import de.danoeh.antennapod.core.util.Converter; /** * List adapter for the list of new episodes */ -public class NewEpisodesListAdapter extends BaseAdapter { +public class AllEpisodesListAdapter extends BaseAdapter { private final Context context; private final ItemAccess itemAccess; private final ActionButtonCallback actionButtonCallback; private final ActionButtonUtils actionButtonUtils; + private final boolean showOnlyNewEpisodes; - public NewEpisodesListAdapter(Context context, ItemAccess itemAccess, ActionButtonCallback actionButtonCallback) { + public AllEpisodesListAdapter(Context context, ItemAccess itemAccess, ActionButtonCallback actionButtonCallback, + boolean showOnlyNewEpisodes) { super(); this.context = context; this.itemAccess = itemAccess; this.actionButtonUtils = new ActionButtonUtils(context); this.actionButtonCallback = actionButtonCallback; + this.showOnlyNewEpisodes = showOnlyNewEpisodes; } @Override @@ -88,7 +91,7 @@ public class NewEpisodesListAdapter extends BaseAdapter { holder.title.setText(item.getTitle()); holder.pubDate.setText(DateUtils.formatDateTime(context, item.getPubDate().getTime(), DateUtils.FORMAT_ABBREV_ALL)); - if (item.isRead()) { + if (showOnlyNewEpisodes || item.isRead() || false == itemAccess.isNew(item)) { holder.statusUnread.setVisibility(View.INVISIBLE); } else { holder.statusUnread.setVisibility(View.VISIBLE); @@ -175,5 +178,8 @@ public class NewEpisodesListAdapter extends BaseAdapter { int getItemDownloadProgressPercent(FeedItem item); boolean isInQueue(FeedItem item); + + boolean isNew(FeedItem item); + } } 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 30e0b0b57..4a640f112 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/FeedItemlistAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/FeedItemlistAdapter.java @@ -110,7 +110,9 @@ public class FeedItemlistAdapter extends BaseAdapter { } holder.title.setText(buffer.toString()); - if(item.isRead()) { + if(false == item.isRead() && itemAccess.isNew(item)) { + holder.statusUnread.setVisibility(View.VISIBLE); + } else { holder.statusUnread.setVisibility(View.INVISIBLE); } @@ -214,6 +216,8 @@ public class FeedItemlistAdapter extends BaseAdapter { FeedItem getItem(int position); + boolean isNew(FeedItem item); + } } diff --git a/app/src/main/java/de/danoeh/antennapod/config/StorageCallbacksImpl.java b/app/src/main/java/de/danoeh/antennapod/config/StorageCallbacksImpl.java index 3445b109f..943e05690 100644 --- a/app/src/main/java/de/danoeh/antennapod/config/StorageCallbacksImpl.java +++ b/app/src/main/java/de/danoeh/antennapod/config/StorageCallbacksImpl.java @@ -142,6 +142,12 @@ public class StorageCallbacksImpl implements StorageCallbacks { db.execSQL("ALTER TABLE " + PodDBAdapter.TABLE_NAME_FEEDS + " ADD COLUMN " + PodDBAdapter.KEY_LAST_UPDATE_FAILED + " INTEGER DEFAULT 0"); + // create indexes + db.execSQL(PodDBAdapter.CREATE_INDEX_FEEDITEMS_FEED); + db.execSQL(PodDBAdapter.CREATE_INDEX_FEEDITEMS_IMAGE); + db.execSQL(PodDBAdapter.CREATE_INDEX_FEEDMEDIA_FEEDITEM); + db.execSQL(PodDBAdapter.CREATE_INDEX_QUEUE_FEEDITEM); + db.execSQL(PodDBAdapter.CREATE_INDEX_SIMPLECHAPTERS_FEEDITEM); } } } 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 91e3df106..8a5cad137 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/AllEpisodesFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/AllEpisodesFragment.java @@ -29,7 +29,7 @@ import java.util.concurrent.atomic.AtomicReference; import de.danoeh.antennapod.R; import de.danoeh.antennapod.activity.MainActivity; import de.danoeh.antennapod.adapter.DefaultActionButtonCallback; -import de.danoeh.antennapod.adapter.NewEpisodesListAdapter; +import de.danoeh.antennapod.adapter.AllEpisodesListAdapter; import de.danoeh.antennapod.core.asynctask.DownloadObserver; import de.danoeh.antennapod.core.dialog.ConfirmationDialog; import de.danoeh.antennapod.core.feed.EventDistributor; @@ -64,12 +64,13 @@ public class AllEpisodesFragment extends Fragment { private String prefName; protected DragSortListView listView; - private NewEpisodesListAdapter listAdapter; + private AllEpisodesListAdapter listAdapter; private TextView txtvEmpty; private ProgressBar progLoading; private List<FeedItem> episodes; - private LongList queueAccess; + private LongList queuedItemsIds; + private LongList newItemsIds; private List<Downloader> downloaderList; private boolean itemsLoaded = false; @@ -308,7 +309,8 @@ public class AllEpisodesFragment extends Fragment { private void onFragmentLoaded() { if (listAdapter == null) { - listAdapter = new NewEpisodesListAdapter(activity.get(), itemAccess, new DefaultActionButtonCallback(activity.get())); + listAdapter = new AllEpisodesListAdapter(activity.get(), itemAccess, + new DefaultActionButtonCallback(activity.get()), showOnlyNewEpisodes); listView.setAdapter(listAdapter); listView.setEmptyView(txtvEmpty); downloadObserver = new DownloadObserver(activity.get(), new Handler(), downloadObserverCallback); @@ -337,7 +339,7 @@ public class AllEpisodesFragment extends Fragment { } }; - private NewEpisodesListAdapter.ItemAccess itemAccess = new NewEpisodesListAdapter.ItemAccess() { + private AllEpisodesListAdapter.ItemAccess itemAccess = new AllEpisodesListAdapter.ItemAccess() { @Override public int getCount() { @@ -371,7 +373,17 @@ public class AllEpisodesFragment extends Fragment { @Override public boolean isInQueue(FeedItem item) { if (itemsLoaded) { - return queueAccess.contains(item.getId()); + return queuedItemsIds.contains(item.getId()); + } else { + return false; + } + } + + @Override + public boolean isNew(FeedItem item) { + if (itemsLoaded) { + // should actually never be called in NewEpisodesFragment, but better safe than sorry + return showOnlyNewEpisodes || newItemsIds.contains(item.getId()); } else { return false; } @@ -436,12 +448,14 @@ public class AllEpisodesFragment extends Fragment { if(showOnlyNewEpisodes) { return new Object[] { DBReader.getNewItemsList(context), - DBReader.getQueueIDList(context) + DBReader.getQueueIDList(context), + null // see ItemAccess.isNew }; } else { return new Object[]{ DBReader.getRecentlyPublishedEpisodes(context, RECENT_EPISODES_LIMIT), - DBReader.getQueueIDList(context) + DBReader.getQueueIDList(context), + DBReader.getNewItemIds(context) }; } } else { @@ -457,7 +471,8 @@ public class AllEpisodesFragment extends Fragment { if (lists != null) { episodes = (List<FeedItem>) lists[0]; - queueAccess = (LongList) lists[1]; + queuedItemsIds = (LongList) lists[1]; + newItemsIds = (LongList) lists[2]; itemsLoaded = true; if (viewsCreated && activity.get() != null) { onFragmentLoaded(); 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 aaa8cd645..463d06376 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/ItemlistFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/ItemlistFragment.java @@ -9,8 +9,8 @@ import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.support.v4.app.ListFragment; -import android.support.v4.util.Pair; import android.support.v4.view.MenuItemCompat; + import android.support.v7.app.ActionBarActivity; import android.support.v7.widget.SearchView; import android.util.Log; @@ -85,7 +85,9 @@ public class ItemlistFragment extends ListFragment { private long feedID; private Feed feed; - private LongList queue; + private LongList queuedItemsIds; + private LongList newItemsIds; + private boolean itemsLoaded = false; private boolean viewsCreated = false; @@ -299,7 +301,7 @@ public class ItemlistFragment extends ListFragment { } contextMenu = menu; - FeedItemMenuHandler.onPrepareMenu(contextMenuInterface, item, false, queue); + FeedItemMenuHandler.onPrepareMenu(contextMenuInterface, item, false, queuedItemsIds); } @Override @@ -547,7 +549,12 @@ public class ItemlistFragment extends ListFragment { @Override public boolean isInQueue(FeedItem item) { - return (queue != null) && queue.contains(item.getId()); + return (queuedItemsIds != null) && queuedItemsIds.contains(item.getId()); + } + + @Override + public boolean isNew(FeedItem item) { + return (newItemsIds != null) && newItemsIds.contains(item.getId()); } @Override @@ -580,9 +587,9 @@ public class ItemlistFragment extends ListFragment { } } - private class ItemLoader extends AsyncTask<Long, Void, Pair<Feed,LongList>> { + private class ItemLoader extends AsyncTask<Long, Void, Object[]> { @Override - protected Pair<Feed,LongList> doInBackground(Long... params) { + protected Object[] doInBackground(Long... params) { long feedID = params[0]; Context context = getActivity(); if (context != null) { @@ -591,19 +598,21 @@ public class ItemlistFragment extends ListFragment { FeedItemFilter filter = feed.getItemFilter(); feed.setItems(filter.filter(context, feed.getItems())); } - LongList queue = DBReader.getQueueIDList(context); - return Pair.create(feed, queue); + LongList queuedItemsIds = DBReader.getQueueIDList(context); + LongList newItemsIds = DBReader.getNewItemIds(context); + return new Object[] { feed, queuedItemsIds, newItemsIds }; } else { return null; } } @Override - protected void onPostExecute(Pair<Feed,LongList> res) { + protected void onPostExecute(Object[] res) { super.onPostExecute(res); if (res != null) { - feed = res.first; - queue = res.second; + feed = (Feed) res[0]; + queuedItemsIds = (LongList) res[1]; + newItemsIds = res[2] == null ? null : (LongList) res[2]; itemsLoaded = true; if (viewsCreated) { onFragmentLoaded(); 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 440e38636..9099829d8 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/PlaybackHistoryFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/PlaybackHistoryFragment.java @@ -226,6 +226,11 @@ public class PlaybackHistoryFragment extends ListFragment { } @Override + public boolean isNew(FeedItem item) { + return false; + } + + @Override public int getItemDownloadProgressPercent(FeedItem item) { if (downloaderList != null) { for (Downloader downloader : downloaderList) { 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 974a7d4bf..a58666056 100644 --- a/app/src/main/java/de/danoeh/antennapod/menuhandler/FeedItemMenuHandler.java +++ b/app/src/main/java/de/danoeh/antennapod/menuhandler/FeedItemMenuHandler.java @@ -88,7 +88,7 @@ public class FeedItemMenuHandler { mi.setItemVisibility(R.id.share_link_item, false); } - if (!(state == FeedItem.State.NEW || state == FeedItem.State.IN_PROGRESS)) { + if (!(state == FeedItem.State.UNREAD || state == FeedItem.State.IN_PROGRESS)) { mi.setItemVisibility(R.id.mark_read_item, false); } if (!(state == FeedItem.State.IN_PROGRESS || state == FeedItem.State.READ)) { |