From f29fa939ab6ab96ef8e25555ef8c34cae6af3318 Mon Sep 17 00:00:00 2001 From: Somethingweirdhere Date: Tue, 19 Jun 2018 15:13:38 +0200 Subject: [PATCH] Removing by long pressing no longer removes a random tab, but the pressed one. --- .../newpipe/settings/ContentSettingsMain.java | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsMain.java b/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsMain.java index 98bf20112..e4a80ab0f 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsMain.java +++ b/app/src/main/java/org/schabi/newpipe/settings/ContentSettingsMain.java @@ -161,12 +161,12 @@ public class ContentSettingsMain extends Fragment { itemTouchHelper = mItemTouchHelper; } - public boolean swapItems(int fromPosition, int toPosition) { + public void swapItems(int fromPosition, int toPosition) { String temp = usedTabs.get(fromPosition); usedTabs.set(fromPosition, usedTabs.get(toPosition)); usedTabs.set(toPosition, temp); notifyItemMoved(fromPosition, toPosition); - return true; + saveChanges(); } @Override @@ -208,6 +208,8 @@ public class ContentSettingsMain extends Fragment { handle.setImageResource(ThemeHelper.getIconByAttr(R.attr.drag_handle, getContext())); handle.setOnTouchListener(getOnTouchListener(holder)); + view.setOnLongClickListener(getOnLongClickListener(holder)); + if(usedTabs.get(position).startsWith("6\t")) { String channelInfo[] = usedTabs.get(position).split("\t"); String channelName = ""; @@ -228,6 +230,16 @@ public class ContentSettingsMain extends Fragment { return false; }; } + + private View.OnLongClickListener getOnLongClickListener(TabViewHolder holder) { + return (view) -> { + int position = holder.getAdapterPosition(); + usedTabs.remove(position); + notifyItemRemoved(position); + saveChanges(); + return false; + }; + } } } @@ -255,9 +267,8 @@ public class ContentSettingsMain extends Fragment { final int sourceIndex = source.getAdapterPosition(); final int targetIndex = target.getAdapterPosition(); - final boolean isSwapped = usedAdapter.swapItems(sourceIndex, targetIndex); - if (isSwapped) saveChanges(); - return isSwapped; + usedAdapter.swapItems(sourceIndex, targetIndex); + return true; } @Override