Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Adds swipe to delete tab #10355

Merged
merged 2 commits into from
May 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
})
8 changes: 2 additions & 6 deletions app/src/main/res/layout/tab_tray_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
android:textSize="16sp"
android:paddingTop="22dp"
android:paddingStart="16dp"
android:layout_marginEnd="20dp"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintEnd_toStartOf="@id/mozac_browser_tabstray_close"
app:layout_constraintStart_toEndOf="@id/mozac_browser_tabstray_card"
Expand All @@ -59,18 +58,15 @@
android:lines="1"
android:textSize="14sp"
android:paddingStart="16dp"
android:layout_marginEnd="20dp"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintEnd_toStartOf="@id/mozac_browser_tabstray_close"
app:layout_constraintStart_toEndOf="@id/mozac_browser_tabstray_card"
app:layout_constraintTop_toBottomOf="@id/mozac_browser_tabstray_title" />

<androidx.appcompat.widget.AppCompatImageButton
android:id="@+id/mozac_browser_tabstray_close"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginTop="32dp"
android:layout_marginEnd="16dp"
android:layout_width="56dp"
android:layout_height="match_parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
Expand Down