1 /**
2  * Copyright (C) 2022 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5  * in compliance with the License. You may obtain a copy of the License at
6  *
7  * ```
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  * ```
10  *
11  * Unless required by applicable law or agreed to in writing, software distributed under the License
12  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13  * or implied. See the License for the specific language governing permissions and limitations under
14  * the License.
15  */
16 package com.android.healthconnect.controller.permissiontypes.prioritylist
17 
18 import android.graphics.Canvas
19 import androidx.recyclerview.widget.ItemTouchHelper
20 import androidx.recyclerview.widget.RecyclerView
21 
22 internal class PriorityListItemMoveCallback(private val adapter: PriorityListAdapter) :
23     ItemTouchHelper.Callback() {
24 
isLongPressDragEnablednull25     override fun isLongPressDragEnabled(): Boolean = false
26 
27     override fun isItemViewSwipeEnabled(): Boolean = false
28 
29     override fun getMovementFlags(
30         recyclerView: RecyclerView,
31         viewHolder: RecyclerView.ViewHolder
32     ): Int {
33         val dragFlags: Int = ItemTouchHelper.UP or ItemTouchHelper.DOWN
34         return makeMovementFlags(dragFlags, /* swipeFlags= */ 0)
35     }
36 
onMovenull37     override fun onMove(
38         recyclerView: RecyclerView,
39         viewHolder: RecyclerView.ViewHolder,
40         target: RecyclerView.ViewHolder
41     ): Boolean {
42         return adapter.onItemMove(viewHolder.bindingAdapterPosition, target.bindingAdapterPosition)
43     }
44 
onSwipednull45     override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) {}
46 
onChildDrawnull47     override fun onChildDraw(
48         c: Canvas,
49         recyclerView: RecyclerView,
50         viewHolder: RecyclerView.ViewHolder,
51         dX: Float,
52         dY: Float,
53         actionState: Int,
54         isCurrentlyActive: Boolean
55     ) {
56         val topY: Float = viewHolder.itemView.top + dY
57         val bottomY: Float = topY + viewHolder.itemView.height
58 
59         // Only redraw child if it is inbounds of view
60         if (topY > 0 && bottomY < recyclerView.height) {
61             super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive)
62         }
63     }
64 }
65