From 523477fc2b547e4b426d209ee8c19272d42f24e5 Mon Sep 17 00:00:00 2001 From: Somethingweirdhere Date: Mon, 9 Jul 2018 22:52:50 +0200 Subject: [PATCH] Added swiping to remove, which is enabled by long-pressing --- .../newpipe/settings/ChoseTabsFragment.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/settings/ChoseTabsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/ChoseTabsFragment.java index d779b410f..d6238c7c4 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/ChoseTabsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/ChoseTabsFragment.java @@ -1,7 +1,6 @@ package org.schabi.newpipe.settings; import android.app.Dialog; -import android.content.DialogInterface; import android.content.SharedPreferences; import android.content.res.ColorStateList; import android.os.Bundle; @@ -23,7 +22,6 @@ import android.widget.ImageView; import android.widget.TextView; import org.schabi.newpipe.R; -import org.schabi.newpipe.info_list.InfoItemDialog; import org.schabi.newpipe.util.ThemeHelper; import java.util.ArrayList; @@ -235,19 +233,17 @@ public class ChoseTabsFragment extends Fragment { private View.OnLongClickListener getOnLongClickListener(TabViewHolder holder) { return (view) -> { - int position = holder.getAdapterPosition(); - selectedTabs.remove(position); - notifyItemRemoved(position); - saveChanges(); + if(itemTouchHelper != null) itemTouchHelper.startSwipe(holder); return false; }; } + } } private ItemTouchHelper.SimpleCallback getItemTouchCallback() { return new ItemTouchHelper.SimpleCallback(ItemTouchHelper.UP | ItemTouchHelper.DOWN, - ItemTouchHelper.ACTION_STATE_IDLE) { + ItemTouchHelper.START | ItemTouchHelper.END) { @Override public int interpolateOutOfBoundsScroll(RecyclerView recyclerView, int viewSize, int viewSizeOutOfBounds, int totalSize, @@ -284,7 +280,12 @@ public class ChoseTabsFragment extends Fragment { } @Override - public void onSwiped(RecyclerView.ViewHolder viewHolder, int swipeDir) {} + public void onSwiped(RecyclerView.ViewHolder viewHolder, int swipeDir) { + int position = viewHolder.getAdapterPosition(); + selectedTabs.remove(position); + selectedTabsAdapter.notifyItemRemoved(position); + saveChanges(); + } }; } }