For #20310 - Adds Recently Closed button to tabsTray

upstream-sync
codrut.topliceanu 3 years ago committed by mergify[bot]
parent 37be7915d4
commit 4b21f52db4

@ -58,6 +58,11 @@ interface TabsTrayController {
*/
fun handleMultipleTabsDeletion(tabs: Collection<Tab>)
/**
* Navigate from TabsTray to Recently Closed section in the History fragment.
*/
fun handleNavigateToRecentlyClosed()
/**
* Set the list of [tabs] into the inactive state.
*
@ -160,6 +165,15 @@ class DefaultTabsTrayController(
showUndoSnackbarForTab(isPrivate)
}
/**
* Dismisses the tabs tray and navigates to the Recently Closed section in the History fragment.
*/
override fun handleNavigateToRecentlyClosed() {
dismissTray()
navController.navigate(R.id.recentlyClosedFragment)
}
/**
* Marks all the [tabs] with the [TabSessionState.lastAccess] to 5 days; enough time to
* have a tab considered as inactive.

@ -30,6 +30,11 @@ interface BrowserTrayInteractor : SelectionInteractor<Tab>, UserInteractionHandl
* TabTray's Floating Action Button clicked.
*/
fun onFabClicked(isPrivate: Boolean)
/**
* Recently Closed item is clicked.
*/
fun onRecentlyClosedClicked()
}
/**
@ -103,4 +108,11 @@ class DefaultBrowserTrayInteractor(
override fun onFabClicked(isPrivate: Boolean) {
controller.handleOpeningNewTab(isPrivate)
}
/**
* See [BrowserTrayInteractor.onRecentlyClosedClicked]
*/
override fun onRecentlyClosedClicked() {
controller.handleNavigateToRecentlyClosed()
}
}

@ -11,6 +11,7 @@ import mozilla.components.browser.toolbar.MAX_URI_LENGTH
import mozilla.components.concept.tabstray.Tab
import org.mozilla.fenix.R
import org.mozilla.fenix.databinding.InactiveFooterItemBinding
import org.mozilla.fenix.databinding.InactiveRecentlyClosedItemBinding
import org.mozilla.fenix.databinding.InactiveTabListItemBinding
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.loadIntoView
@ -61,6 +62,28 @@ sealed class InactiveTabViewHolder(itemView: View) : RecyclerView.ViewHolder(ite
}
}
class RecentlyClosedHolder(
itemView: View,
private val browserTrayInteractor: BrowserTrayInteractor,
) : InactiveTabViewHolder(itemView) {
val binding = InactiveRecentlyClosedItemBinding.bind(itemView)
fun bind() {
val context = itemView.context
binding.inactiveRecentlyClosedText.text =
context.getString(R.string.tab_tray_inactive_recently_closed)
binding.inactiveRecentlyClosed.setOnClickListener {
browserTrayInteractor.onRecentlyClosedClicked()
}
}
companion object {
const val LAYOUT_ID = R.layout.inactive_recently_closed_item
}
}
class FooterHolder(itemView: View) : InactiveTabViewHolder(itemView) {
val binding = InactiveFooterItemBinding.bind(itemView)

@ -15,6 +15,7 @@ import mozilla.components.concept.tabstray.TabsTray
import mozilla.components.support.base.observer.ObserverRegistry
import org.mozilla.fenix.tabstray.browser.InactiveTabViewHolder.FooterHolder
import org.mozilla.fenix.tabstray.browser.InactiveTabViewHolder.HeaderHolder
import org.mozilla.fenix.tabstray.browser.InactiveTabViewHolder.RecentlyClosedHolder
import org.mozilla.fenix.tabstray.browser.InactiveTabViewHolder.TabViewHolder
import org.mozilla.fenix.tabstray.ext.autoCloseInterval
import mozilla.components.support.base.observer.Observable as ComponentObservable
@ -46,6 +47,7 @@ class InactiveTabsAdapter(
HeaderHolder.LAYOUT_ID -> HeaderHolder(view)
TabViewHolder.LAYOUT_ID -> TabViewHolder(view, browserTrayInteractor)
FooterHolder.LAYOUT_ID -> FooterHolder(view)
RecentlyClosedHolder.LAYOUT_ID -> RecentlyClosedHolder(view, browserTrayInteractor)
else -> throw IllegalStateException("Unknown viewType: $viewType")
}
}
@ -63,12 +65,16 @@ class InactiveTabsAdapter(
is HeaderHolder -> {
// do nothing.
}
is RecentlyClosedHolder -> {
holder.bind()
}
}
}
override fun getItemViewType(position: Int): Int {
return when (position) {
0 -> HeaderHolder.LAYOUT_ID
itemCount - 2 -> RecentlyClosedHolder.LAYOUT_ID
itemCount - 1 -> FooterHolder.LAYOUT_ID
else -> TabViewHolder.LAYOUT_ID
}
@ -84,7 +90,7 @@ class InactiveTabsAdapter(
val items = tabs.list.map { Item.Tab(it) }
val footer = Item.Footer(context.autoCloseInterval)
submitList(listOf(Item.Header) + items + listOf(footer))
submitList(listOf(Item.Header) + items + listOf(Item.RecentlyClosed, footer))
}
override fun isTabSelected(tabs: Tabs, position: Int): Boolean = false
@ -123,6 +129,11 @@ class InactiveTabsAdapter(
*/
data class Tab(val tab: TabsTrayTab) : Item()
/**
* A button that leads to the Recently Closed section in History.
*/
object RecentlyClosed : Item()
/**
* A footer for the inactive tab section. This may be seen only
* when at least one inactive tab is present.

@ -0,0 +1,45 @@
<?xml version="1.0" encoding="utf-8"?><!-- 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/. -->
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/inactive_recently_closed"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:background="?above"
android:foreground="?android:attr/selectableItemBackground"
android:minHeight="@dimen/mozac_widget_site_item_height">
<TextView
android:id="@+id/inactive_recently_closed_text"
style="@style/Mozac.Widgets.SiteItem.Label"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:importantForAccessibility="no"
android:text="@string/tab_tray_inactive_recently_closed"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/arrowhead_right"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="RecentlyClosed" />
<ImageView
android:id="@+id/arrowhead_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginEnd="12dp"
android:importantForAccessibility="no"
app:srcCompat="@drawable/ic_arrowhead_right"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

@ -641,6 +641,8 @@
<string name="tab_tray_menu_item_share">Share all tabs</string>
<!-- Text shown in the menu to view recently closed tabs -->
<string name="tab_tray_menu_recently_closed">Recently closed tabs</string>
<!-- Text shown in the tabs tray inactive tabs section -->
<string name="tab_tray_inactive_recently_closed">Recently closed</string>
<!-- Text shown in the menu to view account settings -->
<string name="tab_tray_menu_account_settings">Account settings</string>
<!-- Text shown in the menu to view tab settings -->

Loading…
Cancel
Save