diff options
author | Stefan Niedermann <info@niedermann.it> | 2020-04-03 17:32:03 +0300 |
---|---|---|
committer | Stefan Niedermann <info@niedermann.it> | 2020-04-03 17:38:46 +0300 |
commit | 556bbd17c08e91441fa5594394ff4b62b2e7bbac (patch) | |
tree | 1df30d00c64317768be394c2b7e8436936feedb5 /app/src/main/java/it/niedermann/nextcloud/deck/ui/helper/dnd/CrossTabDragAndDrop.java | |
parent | f72fb775da0ce16c991044a477270ab8eeefcd07 (diff) |
#333 Refactor drawer and main and use viewpager2
Performance enhancements
Signed-off-by: Stefan Niedermann <info@niedermann.it>
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 | 31 |
1 files changed, 16 insertions, 15 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 54a2b9508..26af567bc 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 @@ -1,6 +1,8 @@ package it.niedermann.nextcloud.deck.ui.helper.dnd; import android.content.Context; +import android.content.res.Resources; +import android.util.DisplayMetrics; import android.util.Log; import android.view.DragEvent; import android.view.View; @@ -29,20 +31,25 @@ public class CrossTabDragAndDrop< private static final String TAG = CrossTabDragAndDrop.class.getCanonicalName(); private static final ScrollHelper SCROLL_HELPER = new ScrollHelper(); - private final Context context; private final float pxToReact; + private final float pxToReactTopBottom; + private final float dragAndDropMsToReact; + private final float dragAndDropMsToReactTopBottom; + private final int displayX; private long lastSwap = 0; private long lastMove = 0; - private final float pxToReactTopBottom; - private final Set<ItemMovedByDragListener<ItemModel>> moveListenerList = new HashSet<>(1); public CrossTabDragAndDrop(@NonNull Context context) { - this.context = context; - final float density = context.getResources().getDisplayMetrics().density; - this.pxToReact = context.getResources().getInteger(R.integer.drag_n_drop_dp_to_react) * density; - this.pxToReactTopBottom = context.getResources().getInteger(R.integer.drag_n_drop_dp_to_react_top_bottom) * density; + final Resources resources = context.getResources(); + final DisplayMetrics metrics = resources.getDisplayMetrics(); + + this.pxToReact = context.getResources().getInteger(R.integer.drag_n_drop_dp_to_react) * metrics.density; + this.pxToReactTopBottom = context.getResources().getInteger(R.integer.drag_n_drop_dp_to_react_top_bottom) * metrics.density; + this.displayX = metrics.widthPixels; + this.dragAndDropMsToReact = resources.getInteger(R.integer.drag_n_drop_ms_to_react); + this.dragAndDropMsToReactTopBottom = resources.getInteger(R.integer.drag_n_drop_dp_to_react_top_bottom); } public void register(final ViewPager2 viewPager, TabLayout stackLayout, FragmentManager fm) { @@ -59,10 +66,8 @@ public class CrossTabDragAndDrop< RecyclerView currentRecyclerView = draggedItemLocalState.getRecyclerView(); ItemAdapter itemAdapter = draggedItemLocalState.getItemAdapter(); - final int displayX = context.getResources().getDisplayMetrics().widthPixels; - long now = System.currentTimeMillis(); - if (lastSwap + context.getResources().getInteger(R.integer.drag_n_drop_ms_to_react) < now) { // don't change Tabs so fast! + if (lastSwap + dragAndDropMsToReact < now) { // don't change Tabs so fast! int oldTabPosition = viewPager.getCurrentItem(); boolean shouldSwitchTab = true; @@ -94,8 +99,7 @@ public class CrossTabDragAndDrop< SCROLL_HELPER.stopScroll(); } - - if (lastMove + context.getResources().getInteger(R.integer.drag_n_drop_dp_to_react_top_bottom) < now) { + if (lastMove + dragAndDropMsToReactTopBottom < now) { //push around the other items View viewUnder = currentRecyclerView.findChildViewUnder(dragEvent.getX(), dragEvent.getY()); @@ -116,7 +120,6 @@ public class CrossTabDragAndDrop< case DragEvent.ACTION_DROP: { draggedItemLocalState.getRecyclerView().removeOnChildAttachStateChangeListener(draggedItemLocalState.getInsertedListener()); SCROLL_HELPER.stopScroll(); - // FIXME Fires sometimes BEFORE OnChildAttachStateChangeListener draggedView.setVisibility(View.VISIBLE); notifyListeners(draggedItemLocalState); break; @@ -137,7 +140,6 @@ public class CrossTabDragAndDrop< RecyclerView.OnChildAttachStateChangeListener onChildAttachStateChangeListener = new RecyclerView.OnChildAttachStateChangeListener() { @Override public void onChildViewAttachedToWindow(@NonNull View view) { - // FIXME Fires sometimes AFTER ACTION_DROP recyclerView.removeOnChildAttachStateChangeListener(this); draggedItemLocalState.setInsertedListener(null); view.setVisibility(View.INVISIBLE); @@ -150,7 +152,6 @@ public class CrossTabDragAndDrop< draggedItemLocalState.setInsertedListener(onChildAttachStateChangeListener); recyclerView.addOnChildAttachStateChangeListener(onChildAttachStateChangeListener); - //insert item in new tab View firstVisibleView = recyclerView.getChildAt(0); int positionToInsert = firstVisibleView == null ? 0 : recyclerView.getChildAdapterPosition(firstVisibleView) + 1; |