diff options
author | stefan-niedermann <info@niedermann.it> | 2019-05-08 16:46:37 +0300 |
---|---|---|
committer | stefan-niedermann <info@niedermann.it> | 2019-05-08 16:46:37 +0300 |
commit | 01a5792f0ac448d75e35b5018e5679259a03b836 (patch) | |
tree | b95e007c10c1258d659fa5976e44f3fdc78a224d /app/src/main/java/it/niedermann/nextcloud/deck/ui/helper/dnd/CrossTabDragAndDrop.java | |
parent | d59c742723a6a9640c6a184146267696eac5e92a (diff) |
Refactor DnD
Diffstat (limited to 'app/src/main/java/it/niedermann/nextcloud/deck/ui/helper/dnd/CrossTabDragAndDrop.java')
-rw-r--r-- | app/src/main/java/it/niedermann/nextcloud/deck/ui/helper/dnd/CrossTabDragAndDrop.java | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/helper/dnd/CrossTabDragAndDrop.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/helper/dnd/CrossTabDragAndDrop.java index 5f09bfc5f..373a73aec 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/helper/dnd/CrossTabDragAndDrop.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/helper/dnd/CrossTabDragAndDrop.java @@ -76,13 +76,15 @@ public class CrossTabDragAndDrop { } //push around the other cards - View viewUnder = currentRecyclerView.findChildViewUnder(dragEvent.getX(), dragEvent.getY()); CardView newCardViewToSearch = findInvisibleCardView(currentRecyclerView); + DeckLog.log("dnd card count:" + ((CardAdapter) currentRecyclerView.getAdapter()).getCardList().size()); if (newCardViewToSearch == null) { +// DeckLog.log("dnd skipping"); return true; } + View viewUnder = currentRecyclerView.findChildViewUnder(dragEvent.getX(), dragEvent.getY()); if (viewUnder != null) { int viewUnderPosition = currentRecyclerView.getChildAdapterPosition(viewUnder); @@ -110,10 +112,19 @@ public class CrossTabDragAndDrop { CardAdapter cardAdapter = (CardAdapter) recyclerView.getAdapter(); //insert card in new tab - View viewUnder = recyclerView.getChildAt(0); - int insertedPosition = viewUnder == null ? 0 : recyclerView.getChildAdapterPosition(viewUnder); + View firstVisibleView = recyclerView.getChildAt(0); + int positionToInsert = firstVisibleView == null ? 0 : recyclerView.getChildAdapterPosition(firstVisibleView); + +// //already present? +// for (int i = 0; i < cardAdapter.getItemCount(); i++) { +// FullCard fullCard = cardAdapter.getItem(i); +// if (itemToMove.getCard().getLocalId().equals(fullCard.getCard().getLocalId())){ +// cardAdapter.removeItem(i); +// DeckLog.log("dnd removed afterwards"); +// } +// } - cardAdapter.addItem(itemToMove, insertedPosition); + cardAdapter.addItem(itemToMove, positionToInsert); recyclerView.addOnChildAttachStateChangeListener(new RecyclerView.OnChildAttachStateChangeListener() { @Override @@ -121,14 +132,14 @@ public class CrossTabDragAndDrop { recyclerView.removeOnChildAttachStateChangeListener(this); CardView cardView = (CardView) view; cardView.setVisibility(View.INVISIBLE); - DeckLog.log("dnd there it is"); + DeckLog.log("dnd there it is! pos: "+positionToInsert); } @Override public void onChildViewDetachedFromWindow(@NonNull View view) {/* do nothing */} }); - cardAdapter.notifyItemInserted(insertedPosition); + cardAdapter.notifyItemInserted(positionToInsert); lastSwap = now; } |