Swipe actions on the downloads screen (#5870)
This commit is contained in:
parent
77ced35dff
commit
25679c2aae
|
@ -22,6 +22,7 @@ import de.danoeh.antennapod.databinding.SwipeactionsDialogBinding;
|
|||
import de.danoeh.antennapod.databinding.SwipeactionsPickerBinding;
|
||||
import de.danoeh.antennapod.databinding.SwipeactionsPickerItemBinding;
|
||||
import de.danoeh.antennapod.databinding.SwipeactionsRowBinding;
|
||||
import de.danoeh.antennapod.fragment.CompletedDownloadsFragment;
|
||||
import de.danoeh.antennapod.fragment.EpisodesFragment;
|
||||
import de.danoeh.antennapod.fragment.FeedItemlistFragment;
|
||||
import de.danoeh.antennapod.fragment.InboxFragment;
|
||||
|
@ -64,6 +65,9 @@ public class SwipeActionsDialog {
|
|||
case EpisodesFragment.TAG:
|
||||
forFragment = context.getString(R.string.episodes_label);
|
||||
break;
|
||||
case CompletedDownloadsFragment.TAG:
|
||||
forFragment = context.getString(R.string.downloads_label);
|
||||
break;
|
||||
case FeedItemlistFragment.TAG:
|
||||
forFragment = context.getString(R.string.feeds_label);
|
||||
break;
|
||||
|
|
|
@ -32,8 +32,10 @@ import de.danoeh.antennapod.event.PlayerStatusEvent;
|
|||
import de.danoeh.antennapod.event.UnreadItemsUpdateEvent;
|
||||
import de.danoeh.antennapod.event.playback.PlaybackPositionEvent;
|
||||
import de.danoeh.antennapod.fragment.actions.EpisodeMultiSelectActionHandler;
|
||||
import de.danoeh.antennapod.fragment.swipeactions.SwipeActions;
|
||||
import de.danoeh.antennapod.menuhandler.FeedItemMenuHandler;
|
||||
import de.danoeh.antennapod.model.feed.FeedItem;
|
||||
import de.danoeh.antennapod.model.feed.FeedItemFilter;
|
||||
import de.danoeh.antennapod.view.EmptyViewHandler;
|
||||
import de.danoeh.antennapod.view.EpisodeItemListRecyclerView;
|
||||
import de.danoeh.antennapod.view.viewholder.EpisodeItemViewHolder;
|
||||
|
@ -68,6 +70,7 @@ public class CompletedDownloadsFragment extends Fragment
|
|||
private boolean isUpdatingFeeds = false;
|
||||
private SpeedDialView speedDialView;
|
||||
private Toolbar toolbar;
|
||||
private SwipeActions swipeActions;
|
||||
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
|
||||
|
@ -89,6 +92,8 @@ public class CompletedDownloadsFragment extends Fragment
|
|||
adapter = new CompletedDownloadsListAdapter((MainActivity) getActivity());
|
||||
adapter.setOnSelectModeListener(this);
|
||||
recyclerView.setAdapter(adapter);
|
||||
swipeActions = new SwipeActions(this, TAG).attachTo(recyclerView);
|
||||
swipeActions.setFilter(new FeedItemFilter(FeedItemFilter.DOWNLOADED));
|
||||
progressBar = root.findViewById(R.id.progLoading);
|
||||
progressBar.setVisibility(View.VISIBLE);
|
||||
|
||||
|
@ -312,6 +317,7 @@ public class CompletedDownloadsFragment extends Fragment
|
|||
|
||||
@Override
|
||||
public void onStartSelectMode() {
|
||||
swipeActions.detach();
|
||||
speedDialView.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
|
@ -319,6 +325,7 @@ public class CompletedDownloadsFragment extends Fragment
|
|||
public void onEndSelectMode() {
|
||||
speedDialView.close();
|
||||
speedDialView.setVisibility(View.GONE);
|
||||
swipeActions.attachTo(recyclerView);
|
||||
}
|
||||
|
||||
private class CompletedDownloadsListAdapter extends EpisodeItemListAdapter {
|
||||
|
|
|
@ -5,23 +5,21 @@ import androidx.preference.PreferenceFragmentCompat;
|
|||
import de.danoeh.antennapod.R;
|
||||
import de.danoeh.antennapod.activity.PreferenceActivity;
|
||||
import de.danoeh.antennapod.dialog.SwipeActionsDialog;
|
||||
import de.danoeh.antennapod.fragment.CompletedDownloadsFragment;
|
||||
import de.danoeh.antennapod.fragment.FeedItemlistFragment;
|
||||
import de.danoeh.antennapod.fragment.InboxFragment;
|
||||
import de.danoeh.antennapod.fragment.QueueFragment;
|
||||
|
||||
public class SwipePreferencesFragment extends PreferenceFragmentCompat {
|
||||
private static final String PREF_SWIPE_FEED = "prefSwipeFeed";
|
||||
private static final String PREF_SWIPE_QUEUE = "prefSwipeQueue";
|
||||
private static final String PREF_SWIPE_INBOX = "prefSwipeInbox";
|
||||
private static final String PREF_SWIPE_DOWNLOADS = "prefSwipeDownloads";
|
||||
private static final String PREF_SWIPE_FEED = "prefSwipeFeed";
|
||||
|
||||
@Override
|
||||
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
||||
addPreferencesFromResource(R.xml.preferences_swipe);
|
||||
|
||||
findPreference(PREF_SWIPE_FEED).setOnPreferenceClickListener(preference -> {
|
||||
new SwipeActionsDialog(requireContext(), FeedItemlistFragment.TAG).show(() -> { });
|
||||
return true;
|
||||
});
|
||||
findPreference(PREF_SWIPE_QUEUE).setOnPreferenceClickListener(preference -> {
|
||||
new SwipeActionsDialog(requireContext(), QueueFragment.TAG).show(() -> { });
|
||||
return true;
|
||||
|
@ -30,6 +28,14 @@ public class SwipePreferencesFragment extends PreferenceFragmentCompat {
|
|||
new SwipeActionsDialog(requireContext(), InboxFragment.TAG).show(() -> { });
|
||||
return true;
|
||||
});
|
||||
findPreference(PREF_SWIPE_DOWNLOADS).setOnPreferenceClickListener(preference -> {
|
||||
new SwipeActionsDialog(requireContext(), CompletedDownloadsFragment.TAG).show(() -> { });
|
||||
return true;
|
||||
});
|
||||
findPreference(PREF_SWIPE_FEED).setOnPreferenceClickListener(preference -> {
|
||||
new SwipeActionsDialog(requireContext(), FeedItemlistFragment.TAG).show(() -> { });
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
package de.danoeh.antennapod.fragment.swipeactions;
|
||||
|
||||
import android.content.Context;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import de.danoeh.antennapod.R;
|
||||
import de.danoeh.antennapod.core.storage.DBWriter;
|
||||
import de.danoeh.antennapod.model.feed.FeedItem;
|
||||
import de.danoeh.antennapod.model.feed.FeedItemFilter;
|
||||
|
||||
public class DeleteSwipeAction implements SwipeAction {
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return DELETE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getActionIcon() {
|
||||
return R.drawable.ic_delete;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getActionColor() {
|
||||
return R.attr.icon_red;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTitle(Context context) {
|
||||
return context.getString(R.string.delete_episode_label);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void performAction(FeedItem item, Fragment fragment, FeedItemFilter filter) {
|
||||
DBWriter.deleteFeedMediaOfItem(fragment.requireContext(), item.getMedia().getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean willRemove(FeedItemFilter filter) {
|
||||
return filter.showDownloaded;
|
||||
}
|
||||
}
|
|
@ -17,6 +17,7 @@ public interface SwipeAction {
|
|||
String MARK_FAV = "MARK_FAV";
|
||||
String TOGGLE_PLAYED = "MARK_PLAYED";
|
||||
String REMOVE_FROM_QUEUE = "REMOVE_FROM_QUEUE";
|
||||
String DELETE = "DELETE";
|
||||
|
||||
String getId();
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ import java.util.List;
|
|||
|
||||
import de.danoeh.antennapod.R;
|
||||
import de.danoeh.antennapod.dialog.SwipeActionsDialog;
|
||||
import de.danoeh.antennapod.fragment.CompletedDownloadsFragment;
|
||||
import de.danoeh.antennapod.fragment.EpisodesFragment;
|
||||
import de.danoeh.antennapod.fragment.InboxFragment;
|
||||
import de.danoeh.antennapod.fragment.QueueFragment;
|
||||
|
@ -38,7 +39,8 @@ public class SwipeActions extends ItemTouchHelper.SimpleCallback implements Life
|
|||
public static final List<SwipeAction> swipeActions = Collections.unmodifiableList(
|
||||
Arrays.asList(new AddToQueueSwipeAction(), new RemoveFromInboxSwipeAction(),
|
||||
new StartDownloadSwipeAction(), new MarkFavoriteSwipeAction(),
|
||||
new TogglePlaybackStateSwipeAction(), new RemoveFromQueueSwipeAction())
|
||||
new TogglePlaybackStateSwipeAction(), new RemoveFromQueueSwipeAction(),
|
||||
new DeleteSwipeAction())
|
||||
);
|
||||
|
||||
private final Fragment fragment;
|
||||
|
@ -100,6 +102,9 @@ public class SwipeActions extends ItemTouchHelper.SimpleCallback implements Life
|
|||
case QueueFragment.TAG:
|
||||
defaultActions = SwipeAction.REMOVE_FROM_QUEUE + "," + SwipeAction.REMOVE_FROM_QUEUE;
|
||||
break;
|
||||
case CompletedDownloadsFragment.TAG:
|
||||
defaultActions = SwipeAction.DELETE + "," + SwipeAction.DELETE;
|
||||
break;
|
||||
default:
|
||||
case EpisodesFragment.TAG:
|
||||
defaultActions = SwipeAction.MARK_FAV + "," + SwipeAction.START_DOWNLOAD;
|
||||
|
|
|
@ -9,6 +9,10 @@
|
|||
android:key="prefSwipeInbox"
|
||||
android:title="@string/inbox_label"/>
|
||||
|
||||
<Preference
|
||||
android:key="prefSwipeDownloads"
|
||||
android:title="@string/downloads_label"/>
|
||||
|
||||
<Preference
|
||||
android:key="prefSwipeFeed"
|
||||
android:title="@string/feeds_label"/>
|
||||
|
|
Loading…
Reference in New Issue