Feed view: Add "Add/Remove to/from Favorites" to context menu
This commit is contained in:
parent
8ffe2caf33
commit
ab0782b456
@ -10,7 +10,6 @@ import android.graphics.LightingColorFilter;
|
|||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.ListFragment;
|
import android.support.v4.app.ListFragment;
|
||||||
import android.support.v4.util.Pair;
|
|
||||||
import android.support.v4.view.MenuItemCompat;
|
import android.support.v4.view.MenuItemCompat;
|
||||||
import android.support.v7.widget.SearchView;
|
import android.support.v7.widget.SearchView;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@ -48,6 +47,7 @@ import de.danoeh.antennapod.core.dialog.ConfirmationDialog;
|
|||||||
import de.danoeh.antennapod.core.dialog.DownloadRequestErrorDialogCreator;
|
import de.danoeh.antennapod.core.dialog.DownloadRequestErrorDialogCreator;
|
||||||
import de.danoeh.antennapod.core.event.DownloadEvent;
|
import de.danoeh.antennapod.core.event.DownloadEvent;
|
||||||
import de.danoeh.antennapod.core.event.DownloaderUpdate;
|
import de.danoeh.antennapod.core.event.DownloaderUpdate;
|
||||||
|
import de.danoeh.antennapod.core.event.FavoritesEvent;
|
||||||
import de.danoeh.antennapod.core.event.FeedItemEvent;
|
import de.danoeh.antennapod.core.event.FeedItemEvent;
|
||||||
import de.danoeh.antennapod.core.event.QueueEvent;
|
import de.danoeh.antennapod.core.event.QueueEvent;
|
||||||
import de.danoeh.antennapod.core.feed.EventDistributor;
|
import de.danoeh.antennapod.core.feed.EventDistributor;
|
||||||
@ -99,6 +99,7 @@ public class ItemlistFragment extends ListFragment {
|
|||||||
private long feedID;
|
private long feedID;
|
||||||
private Feed feed;
|
private Feed feed;
|
||||||
private LongList queuedItemsIds;
|
private LongList queuedItemsIds;
|
||||||
|
private LongList favoritedItemsId;
|
||||||
|
|
||||||
private boolean itemsLoaded = false;
|
private boolean itemsLoaded = false;
|
||||||
private boolean viewsCreated = false;
|
private boolean viewsCreated = false;
|
||||||
@ -324,7 +325,8 @@ public class ItemlistFragment extends ListFragment {
|
|||||||
|
|
||||||
contextMenu = menu;
|
contextMenu = menu;
|
||||||
lastMenuInfo = (AdapterView.AdapterContextMenuInfo) menuInfo;
|
lastMenuInfo = (AdapterView.AdapterContextMenuInfo) menuInfo;
|
||||||
FeedItemMenuHandler.onPrepareMenu(getActivity(), contextMenuInterface, item, true, queuedItemsIds);
|
FeedItemMenuHandler.onPrepareMenu(contextMenuInterface, item, true, queuedItemsIds,
|
||||||
|
favoritedItemsId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -389,6 +391,11 @@ public class ItemlistFragment extends ListFragment {
|
|||||||
loadItems();
|
loadItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void onEvent(FavoritesEvent event) {
|
||||||
|
Log.d(TAG, "onEvent() called with: " + "event = [" + event + "]");
|
||||||
|
loadItems();
|
||||||
|
}
|
||||||
|
|
||||||
public void onEvent(FeedEvent event) {
|
public void onEvent(FeedEvent event) {
|
||||||
Log.d(TAG, "onEvent() called with: " + "event = [" + event + "]");
|
Log.d(TAG, "onEvent() called with: " + "event = [" + event + "]");
|
||||||
if(event.feedId == feedID) {
|
if(event.feedId == feedID) {
|
||||||
@ -626,8 +633,9 @@ public class ItemlistFragment extends ListFragment {
|
|||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
.subscribe(result -> {
|
.subscribe(result -> {
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
feed = result.first;
|
feed = (Feed) result[0];
|
||||||
queuedItemsIds = result.second;
|
queuedItemsIds = (LongList) result[1];
|
||||||
|
favoritedItemsId = (LongList) result[2];
|
||||||
itemsLoaded = true;
|
itemsLoaded = true;
|
||||||
if (viewsCreated) {
|
if (viewsCreated) {
|
||||||
onFragmentLoaded();
|
onFragmentLoaded();
|
||||||
@ -638,14 +646,15 @@ public class ItemlistFragment extends ListFragment {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private Pair<Feed, LongList> loadData() {
|
private Object[] loadData() {
|
||||||
Feed feed = DBReader.getFeed(feedID);
|
Feed feed = DBReader.getFeed(feedID);
|
||||||
if(feed != null && feed.getItemFilter() != null) {
|
if(feed != null && feed.getItemFilter() != null) {
|
||||||
FeedItemFilter filter = feed.getItemFilter();
|
FeedItemFilter filter = feed.getItemFilter();
|
||||||
feed.setItems(filter.filter(feed.getItems()));
|
feed.setItems(filter.filter(feed.getItems()));
|
||||||
}
|
}
|
||||||
LongList queuedItemsIds = DBReader.getQueueIDList();
|
LongList queuedItemsIds = DBReader.getQueueIDList();
|
||||||
return Pair.create(feed, queuedItemsIds);
|
LongList favoritedItemsId = DBReader.getFavoriteIDList();
|
||||||
|
return new Object[] { feed, queuedItemsIds, favoritedItemsId };
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -57,16 +57,16 @@ public class FeedItemMenuHandler {
|
|||||||
* @param queueAccess Used for testing if the queue contains the selected item
|
* @param queueAccess Used for testing if the queue contains the selected item
|
||||||
* @return Returns true if selectedItem is not null.
|
* @return Returns true if selectedItem is not null.
|
||||||
*/
|
*/
|
||||||
public static boolean onPrepareMenu(Context context, MenuInterface mi, FeedItem selectedItem,
|
public static boolean onPrepareMenu(MenuInterface mi,
|
||||||
boolean showExtendedMenu, LongList queueAccess) {
|
FeedItem selectedItem,
|
||||||
|
boolean showExtendedMenu,
|
||||||
|
LongList queueAccess,
|
||||||
|
LongList favorites) {
|
||||||
if (selectedItem == null) {
|
if (selectedItem == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
boolean hasMedia = selectedItem.getMedia() != null;
|
boolean hasMedia = selectedItem.getMedia() != null;
|
||||||
boolean isPlaying = hasMedia
|
boolean isPlaying = hasMedia && selectedItem.getState() == FeedItem.State.PLAYING;
|
||||||
&& selectedItem.getState() == FeedItem.State.PLAYING;
|
|
||||||
|
|
||||||
FeedItem.State state = selectedItem.getState();
|
|
||||||
|
|
||||||
if (!isPlaying) {
|
if (!isPlaying) {
|
||||||
mi.setItemVisibility(R.id.skip_episode_item, false);
|
mi.setItemVisibility(R.id.skip_episode_item, false);
|
||||||
@ -126,7 +126,7 @@ public class FeedItemMenuHandler {
|
|||||||
mi.setItemVisibility(R.id.support_item, false);
|
mi.setItemVisibility(R.id.support_item, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isFavorite = selectedItem.isTagged(FeedItem.TAG_FAVORITE);
|
boolean isFavorite = favorites != null && favorites.contains(selectedItem.getId());
|
||||||
mi.setItemVisibility(R.id.add_to_favorites_item, !isFavorite);
|
mi.setItemVisibility(R.id.add_to_favorites_item, !isFavorite);
|
||||||
mi.setItemVisibility(R.id.remove_from_favorites_item, isFavorite);
|
mi.setItemVisibility(R.id.remove_from_favorites_item, isFavorite);
|
||||||
|
|
||||||
|
@ -25,6 +25,15 @@
|
|||||||
android:menuCategory="container"
|
android:menuCategory="container"
|
||||||
android:title="@string/remove_from_queue_label" />
|
android:title="@string/remove_from_queue_label" />
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/add_to_favorites_item"
|
||||||
|
android:menuCategory="container"
|
||||||
|
android:title="@string/add_to_favorite_label" />
|
||||||
|
<item
|
||||||
|
android:id="@+id/remove_from_favorites_item"
|
||||||
|
android:menuCategory="container"
|
||||||
|
android:title="@string/remove_from_favorite_label" />
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/reset_position"
|
android:id="@+id/reset_position"
|
||||||
android:menuCategory="container"
|
android:menuCategory="container"
|
||||||
|
@ -408,7 +408,7 @@ public final class DBReader {
|
|||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
static LongList getFavoriteIDList() {
|
public static LongList getFavoriteIDList() {
|
||||||
Log.d(TAG, "getFavoriteIDList() called");
|
Log.d(TAG, "getFavoriteIDList() called");
|
||||||
PodDBAdapter adapter = PodDBAdapter.getInstance();
|
PodDBAdapter adapter = PodDBAdapter.getInstance();
|
||||||
adapter.open();
|
adapter.open();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user