Swipe actions on the downloads screen (#5870)

This commit is contained in:
ByteHamster 2022-05-07 20:23:46 +02:00 committed by GitHub
parent 77ced35dff
commit 25679c2aae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 74 additions and 6 deletions

View File

@ -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;

View File

@ -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 {

View File

@ -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

View File

@ -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;
}
}

View File

@ -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();

View File

@ -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;

View File

@ -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"/>