Possibility to remove a single episode from playback history (#6184)
This commit is contained in:
parent
97889a46ed
commit
88289d02ae
@ -27,6 +27,7 @@ import de.danoeh.antennapod.fragment.AllEpisodesFragment;
|
||||
import de.danoeh.antennapod.fragment.CompletedDownloadsFragment;
|
||||
import de.danoeh.antennapod.fragment.FeedItemlistFragment;
|
||||
import de.danoeh.antennapod.fragment.InboxFragment;
|
||||
import de.danoeh.antennapod.fragment.PlaybackHistoryFragment;
|
||||
import de.danoeh.antennapod.fragment.QueueFragment;
|
||||
import de.danoeh.antennapod.fragment.swipeactions.SwipeAction;
|
||||
import de.danoeh.antennapod.fragment.swipeactions.SwipeActions;
|
||||
@ -62,22 +63,32 @@ public class SwipeActionsDialog {
|
||||
case InboxFragment.TAG:
|
||||
forFragment = context.getString(R.string.inbox_label);
|
||||
keys = Stream.of(keys).filter(a -> !a.getId().equals(SwipeAction.TOGGLE_PLAYED)
|
||||
&& !a.getId().equals(SwipeAction.DELETE)).toList();
|
||||
&& !a.getId().equals(SwipeAction.DELETE)
|
||||
&& !a.getId().equals(SwipeAction.REMOVE_FROM_HISTORY)).toList();
|
||||
break;
|
||||
case AllEpisodesFragment.TAG:
|
||||
forFragment = context.getString(R.string.episodes_label);
|
||||
keys = Stream.of(keys).filter(a -> !a.getId().equals(SwipeAction.REMOVE_FROM_HISTORY)).toList();
|
||||
break;
|
||||
case CompletedDownloadsFragment.TAG:
|
||||
forFragment = context.getString(R.string.downloads_label);
|
||||
keys = Stream.of(keys).filter(a -> !a.getId().equals(SwipeAction.REMOVE_FROM_INBOX)).toList();
|
||||
keys = Stream.of(keys).filter(a -> !a.getId().equals(SwipeAction.REMOVE_FROM_INBOX)
|
||||
&& !a.getId().equals(SwipeAction.REMOVE_FROM_HISTORY)
|
||||
&& !a.getId().equals(SwipeAction.START_DOWNLOAD)).toList();
|
||||
break;
|
||||
case FeedItemlistFragment.TAG:
|
||||
forFragment = context.getString(R.string.feeds_label);
|
||||
keys = Stream.of(keys).filter(a -> !a.getId().equals(SwipeAction.REMOVE_FROM_HISTORY)).toList();
|
||||
break;
|
||||
case QueueFragment.TAG:
|
||||
forFragment = context.getString(R.string.queue_label);
|
||||
keys = Stream.of(keys).filter(a -> !a.getId().equals(SwipeAction.ADD_TO_QUEUE)
|
||||
&& !a.getId().equals(SwipeAction.REMOVE_FROM_INBOX)).toList();
|
||||
&& !a.getId().equals(SwipeAction.REMOVE_FROM_INBOX)
|
||||
&& !a.getId().equals(SwipeAction.REMOVE_FROM_HISTORY)).toList();
|
||||
break;
|
||||
case PlaybackHistoryFragment.TAG:
|
||||
forFragment = context.getString(R.string.playback_history_label);
|
||||
keys = Stream.of(keys).filter(a -> !a.getId().equals(SwipeAction.REMOVE_FROM_INBOX)).toList();
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
|
@ -32,7 +32,6 @@ public class PlaybackHistoryFragment extends EpisodesListFragment {
|
||||
emptyView.setIcon(R.drawable.ic_history);
|
||||
emptyView.setTitle(R.string.no_history_head_label);
|
||||
emptyView.setMessage(R.string.no_history_label);
|
||||
swipeActions.detach();
|
||||
return root;
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,7 @@ import de.danoeh.antennapod.fragment.AllEpisodesFragment;
|
||||
import de.danoeh.antennapod.fragment.CompletedDownloadsFragment;
|
||||
import de.danoeh.antennapod.fragment.FeedItemlistFragment;
|
||||
import de.danoeh.antennapod.fragment.InboxFragment;
|
||||
import de.danoeh.antennapod.fragment.PlaybackHistoryFragment;
|
||||
import de.danoeh.antennapod.fragment.QueueFragment;
|
||||
|
||||
public class SwipePreferencesFragment extends PreferenceFragmentCompat {
|
||||
@ -17,6 +18,7 @@ public class SwipePreferencesFragment extends PreferenceFragmentCompat {
|
||||
private static final String PREF_SWIPE_EPISODES = "prefSwipeEpisodes";
|
||||
private static final String PREF_SWIPE_DOWNLOADS = "prefSwipeDownloads";
|
||||
private static final String PREF_SWIPE_FEED = "prefSwipeFeed";
|
||||
private static final String PREF_SWIPE_HISTORY = "prefSwipeHistory";
|
||||
|
||||
@Override
|
||||
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
||||
@ -42,6 +44,10 @@ public class SwipePreferencesFragment extends PreferenceFragmentCompat {
|
||||
new SwipeActionsDialog(requireContext(), FeedItemlistFragment.TAG).show(() -> { });
|
||||
return true;
|
||||
});
|
||||
findPreference(PREF_SWIPE_HISTORY).setOnPreferenceClickListener(preference -> {
|
||||
new SwipeActionsDialog(requireContext(), PlaybackHistoryFragment.TAG).show(() -> { });
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -0,0 +1,58 @@
|
||||
package de.danoeh.antennapod.fragment.swipeactions;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import de.danoeh.antennapod.R;
|
||||
import de.danoeh.antennapod.activity.MainActivity;
|
||||
import de.danoeh.antennapod.core.storage.DBWriter;
|
||||
import de.danoeh.antennapod.model.feed.FeedItem;
|
||||
import de.danoeh.antennapod.model.feed.FeedItemFilter;
|
||||
|
||||
public class RemoveFromHistorySwipeAction implements SwipeAction {
|
||||
|
||||
public static final String TAG = "RemoveFromHistorySwipeAction";
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return REMOVE_FROM_HISTORY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getActionIcon() {
|
||||
return R.drawable.ic_history_remove;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getActionColor() {
|
||||
return R.attr.icon_purple;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTitle(Context context) {
|
||||
return context.getString(R.string.remove_history_label);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void performAction(FeedItem item, Fragment fragment, FeedItemFilter filter) {
|
||||
|
||||
Date playbackCompletionDate = item.getMedia().getPlaybackCompletionDate();
|
||||
|
||||
DBWriter.deleteFromPlaybackHistory(item);
|
||||
|
||||
((MainActivity) fragment.requireActivity())
|
||||
.showSnackbarAbovePlayer(R.string.removed_history_label, Snackbar.LENGTH_LONG)
|
||||
.setAction(fragment.getString(R.string.undo),
|
||||
v -> DBWriter.addItemToPlaybackHistory(item.getMedia(), playbackCompletionDate));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean willRemove(FeedItemFilter filter, FeedItem item) {
|
||||
return true;
|
||||
}
|
||||
}
|
@ -18,6 +18,7 @@ public interface SwipeAction {
|
||||
String TOGGLE_PLAYED = "MARK_PLAYED";
|
||||
String REMOVE_FROM_QUEUE = "REMOVE_FROM_QUEUE";
|
||||
String DELETE = "DELETE";
|
||||
String REMOVE_FROM_HISTORY = "REMOVE_FROM_HISTORY";
|
||||
|
||||
String getId();
|
||||
|
||||
|
@ -24,6 +24,7 @@ import de.danoeh.antennapod.dialog.SwipeActionsDialog;
|
||||
import de.danoeh.antennapod.fragment.AllEpisodesFragment;
|
||||
import de.danoeh.antennapod.fragment.CompletedDownloadsFragment;
|
||||
import de.danoeh.antennapod.fragment.InboxFragment;
|
||||
import de.danoeh.antennapod.fragment.PlaybackHistoryFragment;
|
||||
import de.danoeh.antennapod.fragment.QueueFragment;
|
||||
import de.danoeh.antennapod.model.feed.FeedItem;
|
||||
import de.danoeh.antennapod.model.feed.FeedItemFilter;
|
||||
@ -40,7 +41,7 @@ public class SwipeActions extends ItemTouchHelper.SimpleCallback implements Life
|
||||
Arrays.asList(new AddToQueueSwipeAction(), new RemoveFromInboxSwipeAction(),
|
||||
new StartDownloadSwipeAction(), new MarkFavoriteSwipeAction(),
|
||||
new TogglePlaybackStateSwipeAction(), new RemoveFromQueueSwipeAction(),
|
||||
new DeleteSwipeAction())
|
||||
new DeleteSwipeAction(), new RemoveFromHistorySwipeAction())
|
||||
);
|
||||
|
||||
private final Fragment fragment;
|
||||
@ -105,6 +106,9 @@ public class SwipeActions extends ItemTouchHelper.SimpleCallback implements Life
|
||||
case CompletedDownloadsFragment.TAG:
|
||||
defaultActions = SwipeAction.DELETE + "," + SwipeAction.DELETE;
|
||||
break;
|
||||
case PlaybackHistoryFragment.TAG:
|
||||
defaultActions = SwipeAction.REMOVE_FROM_HISTORY + "," + SwipeAction.REMOVE_FROM_HISTORY;
|
||||
break;
|
||||
default:
|
||||
case AllEpisodesFragment.TAG:
|
||||
defaultActions = SwipeAction.MARK_FAV + "," + SwipeAction.START_DOWNLOAD;
|
||||
|
@ -17,6 +17,10 @@
|
||||
android:key="prefSwipeDownloads"
|
||||
android:title="@string/downloads_label"/>
|
||||
|
||||
<Preference
|
||||
android:key="prefSwipeHistory"
|
||||
android:title="@string/playback_history_label"/>
|
||||
|
||||
<Preference
|
||||
android:key="prefSwipeFeed"
|
||||
android:title="@string/feeds_label"/>
|
||||
|
@ -257,6 +257,9 @@ public class DBWriter {
|
||||
});
|
||||
}
|
||||
|
||||
public static Future<?> deleteFromPlaybackHistory(FeedItem feedItem) {
|
||||
return addItemToPlaybackHistory(feedItem.getMedia(), new Date(0));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a FeedMedia object to the playback history. A FeedMedia object is in the playback history if
|
||||
@ -265,10 +268,22 @@ public class DBWriter {
|
||||
*
|
||||
* @param media FeedMedia that should be added to the playback history.
|
||||
*/
|
||||
public static Future<?> addItemToPlaybackHistory(final FeedMedia media) {
|
||||
public static Future<?> addItemToPlaybackHistory(FeedMedia media) {
|
||||
return addItemToPlaybackHistory(media, new Date());
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a FeedMedia object to the playback history. A FeedMedia object is in the playback history if
|
||||
* its playback completion date is set to a non-null value. This method will set the playback completion date to the
|
||||
* current date regardless of the current value.
|
||||
*
|
||||
* @param media FeedMedia that should be added to the playback history.
|
||||
* @param date PlaybackCompletionDate for <code>media</code>
|
||||
*/
|
||||
public static Future<?> addItemToPlaybackHistory(final FeedMedia media, Date date) {
|
||||
return dbExec.submit(() -> {
|
||||
Log.d(TAG, "Adding new item to playback history");
|
||||
media.setPlaybackCompletionDate(new Date());
|
||||
Log.d(TAG, "Adding item to playback history");
|
||||
media.setPlaybackCompletionDate(date);
|
||||
|
||||
PodDBAdapter adapter = PodDBAdapter.getInstance();
|
||||
adapter.open();
|
||||
|
12
core/src/main/res/drawable/ic_history_remove.xml
Normal file
12
core/src/main/res/drawable/ic_history_remove.xml
Normal file
@ -0,0 +1,12 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:pathData="M13,3C8.03,3 4,7.03 4,12H1L4.89,15.89L4.96,16.03L9,12H6C6,8.13 9.13,5 13,5C16.87,5 20,8.13 20,12C20,15.87 16.87,19 13,19C11.07,19 9.32,18.21 8.06,16.94L6.64,18.36C8.27,19.99 10.51,21 13,21C17.97,21 22,16.97 22,12C22,7.03 17.97,3 13,3Z"
|
||||
android:fillColor="?attr/action_icon_color"/>
|
||||
<path
|
||||
android:pathData="M10.93 15.2 13 13.13 15.07 15.2 16.2 14.07 14.13 12 16.2 9.93 15.07 8.8 13 10.87 10.93 8.8 9.8 9.93 11.87 12 9.8 14.07 10.93 15.2Z"
|
||||
android:fillColor="?attr/action_icon_color"/>
|
||||
</vector>
|
@ -93,6 +93,8 @@
|
||||
<!-- Playback history -->
|
||||
<string name="clear_history_label">Clear History</string>
|
||||
<string name="clear_playback_history_msg">This will clear the entire playback history. Are you sure you want to proceed?</string>
|
||||
<string name="remove_history_label">Remove from history</string>
|
||||
<string name="removed_history_label">Removed from history</string>
|
||||
|
||||
<!-- Other -->
|
||||
<string name="confirm_label">Confirm</string>
|
||||
|
Loading…
x
Reference in New Issue
Block a user