Revert to using before/after boolean to accomodate delays

Move drag transparency to start of drag
drag-tabs
Steven Knipe 3 years ago
parent ae79fc327f
commit 9d371f7fd5

@ -60,12 +60,13 @@ interface TabsTrayController {
fun handleMultipleTabsDeletion(tabs: Collection<TabSessionState>)
/**
* Moves [tabId] to replace position of [targetId]
* Moves [tabId] next to before/after [targetId]
*
* @param tabId The tabs to be moved
* @param targetId The id of the tab that the [tab] will replace
* @param targetId The id of the tab that the [tab] will be placed next to
* @param placeAfter Place [tabs] before or after the target
*/
fun handleTabsMove(tabId: String, targetId: String?)
fun handleTabsMove(tabId: String, targetId: String?, placeAfter: Boolean)
/**
* Navigate from TabsTray to Recently Closed section in the History fragment.
@ -181,17 +182,19 @@ class DefaultTabsTrayController(
}
/**
* Moves [tabId] to replace position of [targetId]
* Moves [tabId] next to before/after [targetId]
*
* @param tabId The tabs to be moved
* @param targetId The id of the tab that the [tab] will replace
* @param targetId The id of the tab that the [tab] will be placed next to
* @param placeAfter Place [tabs] before or after the target
*/
override fun handleTabsMove(
tabId: String,
targetId: String?,
placeAfter: Boolean
) {
if (targetId != null && tabId != targetId) {
tabsUseCases.moveTabs(tabId, targetId)
tabsUseCases.moveTabs(listOf(tabId), targetId, placeAfter)
}
}

@ -36,12 +36,12 @@ interface TabsTrayInteractor {
fun onInactiveDebugClicked(tabs: Collection<TabSessionState>)
/**
* Invoked when [tabId] should be moved replace [targetId]'s position
* due to a drag-drop operation
* Invoked when [tabId] should be moved to before/after [targetId] from a drag-drop operation
*/
fun onTabsMove(
tabId: String,
targetId: String?,
placeAfter: Boolean
)
/**
@ -77,8 +77,9 @@ class DefaultTabsTrayInteractor(
override fun onTabsMove(
tabId: String,
targetId: String?,
placeAfter: Boolean
) {
controller.handleTabsMove(tabId, targetId)
controller.handleTabsMove(tabId, targetId, placeAfter)
}
override fun onInactiveDebugClicked(tabs: Collection<TabSessionState>) {

@ -245,7 +245,6 @@ abstract class AbstractBrowserTabViewHolder(
// startDragAndDrop is the non-deprecated version, but requires API 24
@Suppress("DEPRECATION")
itemView.startDrag(null, shadow, item, 0)
view.alpha = DRAG_TRANSPARENCY // Make the dragged tab mostly invisible
}
}
else -> view.onTouchEvent(motionEvent)
@ -255,7 +254,6 @@ abstract class AbstractBrowserTabViewHolder(
}
companion object {
internal const val DRAG_TRANSPARENCY = 0.2f
internal const val PLAY_PAUSE_BUTTON_EXTRA_DPS = 24
internal const val GRID_ITEM_CLOSE_BUTTON_EXTRA_DPS = 24
}

@ -75,28 +75,31 @@ abstract class AbstractBrowserTrayList @JvmOverloads constructor(
}
// Find the closest item to the x/y position of the drop.
private fun getDropPosition(x: Float, y: Float): String? {
private fun getDropPosition(x: Float, y: Float, source: String): Pair<String, Boolean>? {
if (childCount < 2) return null // If there's 0 or 1 tabs visible, can't reorder
var bestDist = Float.MAX_VALUE
var bestId: String? = null
var bestOut: Pair<String, Boolean>? = null
var seenSource = false
for (i in 0 until childCount) {
val proposedTarget = getChildAt(i)
val targetHolder = findContainingViewHolder(proposedTarget)
if (targetHolder is TabViewHolder) {
var rect = Rect() // Use layoutManager to get post-animation positioning
var rect = Rect() // Get post-animation positioning
getDecoratedBoundsWithMargins(proposedTarget, rect)
val targetX = (rect.left + rect.right) / 2
val targetY = (rect.top + rect.bottom) / 2
val xDiff = x - targetX
val yDiff = y - targetY
val dist = abs(xDiff) + abs(yDiff)
if (dist < bestDist) {
val id = targetHolder.tab?.id
if (id == source) seenSource = true
if (dist < bestDist && id != null) {
bestDist = dist
bestId = targetHolder.tab?.id
bestOut = Pair(id, seenSource)
}
}
}
return bestId
return bestOut
}
private fun findSourceView(id: String): View? {
for (i in 0 until childCount) {
@ -111,16 +114,24 @@ abstract class AbstractBrowserTrayList @JvmOverloads constructor(
private val dragListen = OnDragListener { _, event ->
when (event.action) {
DragEvent.ACTION_DRAG_STARTED -> {
(event.localState is TabSessionState)
if (event.localState is TabSessionState) {
val id = (event.localState as TabSessionState).id
val sourceView = findSourceView(id)
if (sourceView != null) {
sourceView.alpha = DRAG_TRANSPARENCY
}
true
} else false
}
DragEvent.ACTION_DRAG_ENTERED -> {
true
}
DragEvent.ACTION_DRAG_LOCATION -> {
val target = getDropPosition(event.x, event.y)
val source = (event.localState as TabSessionState)
val target = getDropPosition(event.x, event.y, source.id)
if (target != null) {
val source = (event.localState as TabSessionState)
interactor.onTabsMove(source.id, target)
val (id, placeAfter) = target
interactor.onTabsMove(source.id, id, placeAfter)
}
true
}
@ -128,10 +139,11 @@ abstract class AbstractBrowserTrayList @JvmOverloads constructor(
true
}
DragEvent.ACTION_DROP -> {
val target = getDropPosition(event.x, event.y)
val source = (event.localState as TabSessionState)
val target = getDropPosition(event.x, event.y, source.id)
if (target != null) {
val source = (event.localState as TabSessionState)
interactor.onTabsMove(source.id, target)
val (id, placeAfter) = target
interactor.onTabsMove(source.id, id, placeAfter)
}
true
}
@ -140,7 +152,7 @@ abstract class AbstractBrowserTrayList @JvmOverloads constructor(
val id = (event.localState as TabSessionState).id
val sourceView = findSourceView(id)
if (sourceView != null) {
sourceView.alpha = 1.0f
sourceView.alpha = 1f
}
true
}
@ -149,4 +161,7 @@ abstract class AbstractBrowserTrayList @JvmOverloads constructor(
}
}
}
companion object {
internal const val DRAG_TRANSPARENCY = 0.2f
}
}

Loading…
Cancel
Save