Merge pull request #5875 from ByteHamster/fix-swipe-download
Fix swiping away not yet downloaded items from downloads screen
This commit is contained in:
commit
fb3f8949a3
|
@ -12,7 +12,6 @@ import android.widget.ProgressBar;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.appcompat.widget.Toolbar;
|
import androidx.appcompat.widget.Toolbar;
|
||||||
import androidx.core.util.ObjectsCompat;
|
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import com.google.android.material.snackbar.Snackbar;
|
import com.google.android.material.snackbar.Snackbar;
|
||||||
import com.leinardi.android.speeddial.SpeedDialView;
|
import com.leinardi.android.speeddial.SpeedDialView;
|
||||||
|
@ -48,6 +47,7 @@ import org.greenrobot.eventbus.Subscribe;
|
||||||
import org.greenrobot.eventbus.ThreadMode;
|
import org.greenrobot.eventbus.ThreadMode;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -188,7 +188,7 @@ public class CompletedDownloadsFragment extends Fragment
|
||||||
if (event.hasChangedFeedUpdateStatus(isUpdatingFeeds)) {
|
if (event.hasChangedFeedUpdateStatus(isUpdatingFeeds)) {
|
||||||
refreshToolbarState();
|
refreshToolbarState();
|
||||||
}
|
}
|
||||||
if (!ObjectsCompat.equals(event.update.mediaIds, runningDownloads)) {
|
if (!Arrays.equals(event.update.mediaIds, runningDownloads)) {
|
||||||
runningDownloads = event.update.mediaIds;
|
runningDownloads = event.update.mediaIds;
|
||||||
loadItems();
|
loadItems();
|
||||||
return; // Refreshed anyway
|
return; // Refreshed anyway
|
||||||
|
|
|
@ -41,7 +41,7 @@ public class AddToQueueSwipeAction implements SwipeAction {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean willRemove(FeedItemFilter filter) {
|
public boolean willRemove(FeedItemFilter filter, FeedItem item) {
|
||||||
return filter.showQueued || filter.showNew;
|
return filter.showQueued || filter.showNew;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,11 +31,14 @@ public class DeleteSwipeAction implements SwipeAction {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void performAction(FeedItem item, Fragment fragment, FeedItemFilter filter) {
|
public void performAction(FeedItem item, Fragment fragment, FeedItemFilter filter) {
|
||||||
|
if (!item.isDownloaded()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
DBWriter.deleteFeedMediaOfItem(fragment.requireContext(), item.getMedia().getId());
|
DBWriter.deleteFeedMediaOfItem(fragment.requireContext(), item.getMedia().getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean willRemove(FeedItemFilter filter) {
|
public boolean willRemove(FeedItemFilter filter, FeedItem item) {
|
||||||
return filter.showDownloaded;
|
return filter.showDownloaded && item.isDownloaded();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ public class MarkFavoriteSwipeAction implements SwipeAction {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean willRemove(FeedItemFilter filter) {
|
public boolean willRemove(FeedItemFilter filter, FeedItem item) {
|
||||||
return filter.showIsFavorite || filter.showNotFavorite;
|
return filter.showIsFavorite || filter.showNotFavorite;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,12 +34,12 @@ public class RemoveFromInboxSwipeAction implements SwipeAction {
|
||||||
@Override
|
@Override
|
||||||
public void performAction(FeedItem item, Fragment fragment, FeedItemFilter filter) {
|
public void performAction(FeedItem item, Fragment fragment, FeedItemFilter filter) {
|
||||||
if (item.isNew()) {
|
if (item.isNew()) {
|
||||||
FeedItemMenuHandler.markReadWithUndo(fragment, item, FeedItem.UNPLAYED, willRemove(filter));
|
FeedItemMenuHandler.markReadWithUndo(fragment, item, FeedItem.UNPLAYED, willRemove(filter, item));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean willRemove(FeedItemFilter filter) {
|
public boolean willRemove(FeedItemFilter filter, FeedItem item) {
|
||||||
return filter.showNew;
|
return filter.showNew;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@ public class RemoveFromQueueSwipeAction implements SwipeAction {
|
||||||
|
|
||||||
DBWriter.removeQueueItem(fragment.requireActivity(), true, item);
|
DBWriter.removeQueueItem(fragment.requireActivity(), true, item);
|
||||||
|
|
||||||
if (willRemove(filter)) {
|
if (willRemove(filter, item)) {
|
||||||
((MainActivity) fragment.requireActivity()).showSnackbarAbovePlayer(
|
((MainActivity) fragment.requireActivity()).showSnackbarAbovePlayer(
|
||||||
fragment.getResources().getQuantityString(R.plurals.removed_from_queue_batch_label, 1, 1),
|
fragment.getResources().getQuantityString(R.plurals.removed_from_queue_batch_label, 1, 1),
|
||||||
Snackbar.LENGTH_LONG)
|
Snackbar.LENGTH_LONG)
|
||||||
|
@ -51,7 +51,7 @@ public class RemoveFromQueueSwipeAction implements SwipeAction {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean willRemove(FeedItemFilter filter) {
|
public boolean willRemove(FeedItemFilter filter, FeedItem item) {
|
||||||
return filter.showQueued || filter.showNotQueued;
|
return filter.showQueued || filter.showNotQueued;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ public class ShowFirstSwipeDialogAction implements SwipeAction {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean willRemove(FeedItemFilter filter) {
|
public boolean willRemove(FeedItemFilter filter, FeedItem item) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ public class StartDownloadSwipeAction implements SwipeAction {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean willRemove(FeedItemFilter filter) {
|
public boolean willRemove(FeedItemFilter filter, FeedItem item) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,5 +31,5 @@ public interface SwipeAction {
|
||||||
|
|
||||||
void performAction(FeedItem item, Fragment fragment, FeedItemFilter filter);
|
void performAction(FeedItem item, Fragment fragment, FeedItemFilter filter);
|
||||||
|
|
||||||
boolean willRemove(FeedItemFilter filter);
|
boolean willRemove(FeedItemFilter filter, FeedItem item);
|
||||||
}
|
}
|
||||||
|
|
|
@ -158,8 +158,9 @@ public class SwipeActions extends ItemTouchHelper.SimpleCallback implements Life
|
||||||
}
|
}
|
||||||
|
|
||||||
//check if it will be removed
|
//check if it will be removed
|
||||||
boolean rightWillRemove = right.willRemove(filter);
|
FeedItem item = ((EpisodeItemViewHolder) viewHolder).getFeedItem();
|
||||||
boolean leftWillRemove = left.willRemove(filter);
|
boolean rightWillRemove = right.willRemove(filter, item);
|
||||||
|
boolean leftWillRemove = left.willRemove(filter, item);
|
||||||
boolean wontLeave = (dx > 0 && !rightWillRemove) || (dx < 0 && !leftWillRemove);
|
boolean wontLeave = (dx > 0 && !rightWillRemove) || (dx < 0 && !leftWillRemove);
|
||||||
|
|
||||||
//Limit swipe if it's not removed
|
//Limit swipe if it's not removed
|
||||||
|
@ -251,7 +252,7 @@ public class SwipeActions extends ItemTouchHelper.SimpleCallback implements Life
|
||||||
String[] actions = prefs.split(",");
|
String[] actions = prefs.split(",");
|
||||||
if (actions.length == 2) {
|
if (actions.length == 2) {
|
||||||
this.right = Stream.of(swipeActions)
|
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)
|
this.left = Stream.of(swipeActions)
|
||||||
.filter(a -> a.getId().equals(actions[1])).single();
|
.filter(a -> a.getId().equals(actions[1])).single();
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,11 +34,11 @@ public class TogglePlaybackStateSwipeAction implements SwipeAction {
|
||||||
@Override
|
@Override
|
||||||
public void performAction(FeedItem item, Fragment fragment, FeedItemFilter filter) {
|
public void performAction(FeedItem item, Fragment fragment, FeedItemFilter filter) {
|
||||||
int newState = item.getPlayState() == FeedItem.UNPLAYED ? FeedItem.PLAYED : FeedItem.UNPLAYED;
|
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
|
@Override
|
||||||
public boolean willRemove(FeedItemFilter filter) {
|
public boolean willRemove(FeedItemFilter filter, FeedItem item) {
|
||||||
return filter.showUnplayed || filter.showPlayed || filter.showNew;
|
return filter.showUnplayed || filter.showPlayed || filter.showNew;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue