Skip to content

Commit

Permalink
For mozilla-mobile#10331 - Adds swipe to delete to the tab tray
Browse files Browse the repository at this point in the history
  • Loading branch information
boek committed May 1, 2020
1 parent f596e5e commit 69bcfaf
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/src/main/java/org/mozilla/fenix/HomeActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import androidx.navigation.NavDirections
import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.ui.AppBarConfiguration
import androidx.navigation.ui.NavigationUI
import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.LinearLayoutManager
import kotlinx.android.synthetic.main.activity_home.*
import kotlinx.coroutines.CoroutineScope
Expand Down Expand Up @@ -77,6 +78,7 @@ import org.mozilla.fenix.utils.RunWhenReadyQueue
import mozilla.components.concept.tabstray.TabsTray
import mozilla.components.browser.tabstray.TabsAdapter
import mozilla.components.browser.tabstray.BrowserTabsTray
import org.mozilla.fenix.home.sessioncontrol.SwipeToDeleteCallback
import org.mozilla.fenix.tabtray.TabTrayFragmentDirections

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import org.mozilla.fenix.ext.requireComponents
import androidx.navigation.fragment.findNavController
import mozilla.components.browser.session.Session
import mozilla.components.browser.session.SessionManager
import mozilla.components.browser.tabstray.BrowserTabsTray
import mozilla.components.concept.tabstray.Tab
import mozilla.components.concept.tabstray.TabsTray
import org.mozilla.fenix.BrowserDirection
Expand Down Expand Up @@ -51,6 +52,10 @@ class TabTrayFragment : Fragment(R.layout.fragment_tab_tray), TabsTray.Observer,
showToolbar(getString(R.string.tab_tray_title))
onTabsChanged()

(tabsTray as? BrowserTabsTray)?.also { tray ->
TabsTouchHelper(tray.tabsAdapter).attachToRecyclerView(tray)
}

sessionManager.register(observer = object : SessionManager.Observer {
override fun onSessionAdded(session: Session) {
onTabsChanged()
Expand Down
17 changes: 17 additions & 0 deletions app/src/main/java/org/mozilla/fenix/tabtray/TabsTouchHelper.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package org.mozilla.fenix.tabtray

import androidx.recyclerview.widget.ItemTouchHelper
import mozilla.components.browser.tabstray.TabTouchCallback
import mozilla.components.concept.tabstray.TabsTray
import mozilla.components.support.base.observer.Observable

class TabsTouchHelper(observable: Observable<TabsTray.Observer>) :
ItemTouchHelper(object : TabTouchCallback(observable) {
override fun alphaForItemSwipe(dX: Float, distanceToAlphaMin: Int): Float {
return 1f - 2f * Math.abs(dX) / distanceToAlphaMin
}
})

0 comments on commit 69bcfaf

Please sign in to comment.