Merge pull request #5875 from ByteHamster/fix-swipe-download

Fix swiping away not yet downloaded items from downloads screen
This commit is contained in:
ByteHamster 2022-05-07 21:53:08 +02:00 committed by GitHub
commit fb3f8949a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 22 additions and 18 deletions

View File

@ -12,7 +12,6 @@ import android.widget.ProgressBar;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar;
import androidx.core.util.ObjectsCompat;
import androidx.fragment.app.Fragment;
import com.google.android.material.snackbar.Snackbar;
import com.leinardi.android.speeddial.SpeedDialView;
@ -48,6 +47,7 @@ import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
@ -188,7 +188,7 @@ public class CompletedDownloadsFragment extends Fragment
if (event.hasChangedFeedUpdateStatus(isUpdatingFeeds)) {
refreshToolbarState();
}
if (!ObjectsCompat.equals(event.update.mediaIds, runningDownloads)) {
if (!Arrays.equals(event.update.mediaIds, runningDownloads)) {
runningDownloads = event.update.mediaIds;
loadItems();
return; // Refreshed anyway

View File

@ -41,7 +41,7 @@ public class AddToQueueSwipeAction implements SwipeAction {
}
@Override
public boolean willRemove(FeedItemFilter filter) {
public boolean willRemove(FeedItemFilter filter, FeedItem item) {
return filter.showQueued || filter.showNew;
}
}

View File

@ -31,11 +31,14 @@ public class DeleteSwipeAction implements SwipeAction {
@Override
public void performAction(FeedItem item, Fragment fragment, FeedItemFilter filter) {
if (!item.isDownloaded()) {
return;
}
DBWriter.deleteFeedMediaOfItem(fragment.requireContext(), item.getMedia().getId());
}
@Override
public boolean willRemove(FeedItemFilter filter) {
return filter.showDownloaded;
public boolean willRemove(FeedItemFilter filter, FeedItem item) {
return filter.showDownloaded && item.isDownloaded();
}
}

View File

@ -37,7 +37,7 @@ public class MarkFavoriteSwipeAction implements SwipeAction {
}
@Override
public boolean willRemove(FeedItemFilter filter) {
public boolean willRemove(FeedItemFilter filter, FeedItem item) {
return filter.showIsFavorite || filter.showNotFavorite;
}
}

View File

@ -34,12 +34,12 @@ public class RemoveFromInboxSwipeAction implements SwipeAction {
@Override
public void performAction(FeedItem item, Fragment fragment, FeedItemFilter filter) {
if (item.isNew()) {
FeedItemMenuHandler.markReadWithUndo(fragment, item, FeedItem.UNPLAYED, willRemove(filter));
FeedItemMenuHandler.markReadWithUndo(fragment, item, FeedItem.UNPLAYED, willRemove(filter, item));
}
}
@Override
public boolean willRemove(FeedItemFilter filter) {
public boolean willRemove(FeedItemFilter filter, FeedItem item) {
return filter.showNew;
}
}

View File

@ -41,7 +41,7 @@ public class RemoveFromQueueSwipeAction implements SwipeAction {
DBWriter.removeQueueItem(fragment.requireActivity(), true, item);
if (willRemove(filter)) {
if (willRemove(filter, item)) {
((MainActivity) fragment.requireActivity()).showSnackbarAbovePlayer(
fragment.getResources().getQuantityString(R.plurals.removed_from_queue_batch_label, 1, 1),
Snackbar.LENGTH_LONG)
@ -51,7 +51,7 @@ public class RemoveFromQueueSwipeAction implements SwipeAction {
}
@Override
public boolean willRemove(FeedItemFilter filter) {
public boolean willRemove(FeedItemFilter filter, FeedItem item) {
return filter.showQueued || filter.showNotQueued;
}
}

View File

@ -36,7 +36,7 @@ public class ShowFirstSwipeDialogAction implements SwipeAction {
}
@Override
public boolean willRemove(FeedItemFilter filter) {
public boolean willRemove(FeedItemFilter filter, FeedItem item) {
return false;
}
}

View File

@ -38,7 +38,7 @@ public class StartDownloadSwipeAction implements SwipeAction {
}
@Override
public boolean willRemove(FeedItemFilter filter) {
public boolean willRemove(FeedItemFilter filter, FeedItem item) {
return false;
}
}

View File

@ -31,5 +31,5 @@ public interface SwipeAction {
void performAction(FeedItem item, Fragment fragment, FeedItemFilter filter);
boolean willRemove(FeedItemFilter filter);
boolean willRemove(FeedItemFilter filter, FeedItem item);
}

View File

@ -158,8 +158,9 @@ public class SwipeActions extends ItemTouchHelper.SimpleCallback implements Life
}
//check if it will be removed
boolean rightWillRemove = right.willRemove(filter);
boolean leftWillRemove = left.willRemove(filter);
FeedItem item = ((EpisodeItemViewHolder) viewHolder).getFeedItem();
boolean rightWillRemove = right.willRemove(filter, item);
boolean leftWillRemove = left.willRemove(filter, item);
boolean wontLeave = (dx > 0 && !rightWillRemove) || (dx < 0 && !leftWillRemove);
//Limit swipe if it's not removed
@ -251,7 +252,7 @@ public class SwipeActions extends ItemTouchHelper.SimpleCallback implements Life
String[] actions = prefs.split(",");
if (actions.length == 2) {
this.right = Stream.of(swipeActions)
.filter(a -> a.getId().equals(actions[0])).single();;
.filter(a -> a.getId().equals(actions[0])).single();
this.left = Stream.of(swipeActions)
.filter(a -> a.getId().equals(actions[1])).single();
}

View File

@ -34,11 +34,11 @@ public class TogglePlaybackStateSwipeAction implements SwipeAction {
@Override
public void performAction(FeedItem item, Fragment fragment, FeedItemFilter filter) {
int newState = item.getPlayState() == FeedItem.UNPLAYED ? FeedItem.PLAYED : FeedItem.UNPLAYED;
FeedItemMenuHandler.markReadWithUndo(fragment, item, newState, willRemove(filter));
FeedItemMenuHandler.markReadWithUndo(fragment, item, newState, willRemove(filter, item));
}
@Override
public boolean willRemove(FeedItemFilter filter) {
public boolean willRemove(FeedItemFilter filter, FeedItem item) {
return filter.showUnplayed || filter.showPlayed || filter.showNew;
}
}