parent
5ba9cc6ec9
commit
a249334976
|
@ -12,6 +12,7 @@ import android.view.View
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import mozilla.components.concept.engine.prompt.ShareData
|
import mozilla.components.concept.engine.prompt.ShareData
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
|
import androidx.lifecycle.lifecycleScope
|
||||||
import mozilla.components.feature.tabs.tabstray.TabsFeature
|
import mozilla.components.feature.tabs.tabstray.TabsFeature
|
||||||
import kotlinx.android.synthetic.main.fragment_tab_tray.tabsTray
|
import kotlinx.android.synthetic.main.fragment_tab_tray.tabsTray
|
||||||
import kotlinx.android.synthetic.main.fragment_tab_tray.view.*
|
import kotlinx.android.synthetic.main.fragment_tab_tray.view.*
|
||||||
|
@ -32,6 +33,7 @@ import org.mozilla.fenix.ext.components
|
||||||
import org.mozilla.fenix.ext.nav
|
import org.mozilla.fenix.ext.nav
|
||||||
import org.mozilla.fenix.ext.sessionsOfType
|
import org.mozilla.fenix.ext.sessionsOfType
|
||||||
import org.mozilla.fenix.ext.showToolbar
|
import org.mozilla.fenix.ext.showToolbar
|
||||||
|
import org.mozilla.fenix.utils.allowUndo
|
||||||
|
|
||||||
@SuppressWarnings("TooManyFunctions", "LargeClass")
|
@SuppressWarnings("TooManyFunctions", "LargeClass")
|
||||||
class TabTrayFragment : Fragment(R.layout.fragment_tab_tray), TabsTray.Observer, UserInteractionHandler {
|
class TabTrayFragment : Fragment(R.layout.fragment_tab_tray), TabsTray.Observer, UserInteractionHandler {
|
||||||
|
@ -130,16 +132,47 @@ class TabTrayFragment : Fragment(R.layout.fragment_tab_tray), TabsTray.Observer,
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
R.id.tab_tray_close_menu_item -> {
|
R.id.tab_tray_close_menu_item -> {
|
||||||
val tabs = getListOfSessions()
|
closeAllTabs()
|
||||||
tabs.forEach {
|
|
||||||
sessionManager.remove(it)
|
|
||||||
}
|
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
else -> super.onOptionsItemSelected(item)
|
else -> super.onOptionsItemSelected(item)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun closeAllTabs() {
|
||||||
|
val tabs = getListOfSessions()
|
||||||
|
|
||||||
|
val selectedIndex = sessionManager
|
||||||
|
.selectedSession?.let { sessionManager.sessions.indexOf(it) } ?: 0
|
||||||
|
|
||||||
|
val snapshot = tabs
|
||||||
|
.map(sessionManager::createSessionSnapshot)
|
||||||
|
.map { it.copy(engineSession = null, engineSessionState = it.engineSession?.saveState()) }
|
||||||
|
.let { SessionManager.Snapshot(it, selectedIndex) }
|
||||||
|
|
||||||
|
tabs.forEach {
|
||||||
|
sessionManager.remove(it)
|
||||||
|
}
|
||||||
|
|
||||||
|
val isPrivate = (activity as HomeActivity).browsingModeManager.mode.isPrivate
|
||||||
|
val snackbarMessage = if (isPrivate) {
|
||||||
|
getString(R.string.snackbar_private_tabs_closed)
|
||||||
|
} else {
|
||||||
|
getString(R.string.snackbar_tabs_closed)
|
||||||
|
}
|
||||||
|
|
||||||
|
viewLifecycleOwner.lifecycleScope.allowUndo(
|
||||||
|
requireView(),
|
||||||
|
snackbarMessage,
|
||||||
|
getString(R.string.snackbar_deleted_undo),
|
||||||
|
{
|
||||||
|
sessionManager.restore(snapshot)
|
||||||
|
},
|
||||||
|
operation = { },
|
||||||
|
anchorView = view?.tab_tray_controls
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
private fun saveToCollection() {
|
private fun saveToCollection() {
|
||||||
val tabs = getListOfSessions()
|
val tabs = getListOfSessions()
|
||||||
val tabIds = tabs.map { it.id }.toList().toTypedArray()
|
val tabIds = tabs.map { it.id }.toList().toTypedArray()
|
||||||
|
@ -169,15 +202,15 @@ class TabTrayFragment : Fragment(R.layout.fragment_tab_tray), TabsTray.Observer,
|
||||||
override fun onStart() {
|
override fun onStart() {
|
||||||
super.onStart()
|
super.onStart()
|
||||||
|
|
||||||
tabsFeature?.start()
|
|
||||||
tabsTray.register(this)
|
tabsTray.register(this)
|
||||||
|
tabsFeature?.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStop() {
|
override fun onStop() {
|
||||||
super.onStop()
|
super.onStop()
|
||||||
|
|
||||||
tabsFeature?.stop()
|
|
||||||
tabsTray.unregister(this)
|
tabsTray.unregister(this)
|
||||||
|
tabsFeature?.stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onBackPressed(): Boolean {
|
override fun onBackPressed(): Boolean {
|
||||||
|
@ -196,7 +229,30 @@ class TabTrayFragment : Fragment(R.layout.fragment_tab_tray), TabsTray.Observer,
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onTabClosed(tab: Tab) {
|
override fun onTabClosed(tab: Tab) {
|
||||||
// noop
|
val snapshot = sessionManager
|
||||||
|
.findSessionById(tab.id)?.let {
|
||||||
|
sessionManager.createSessionSnapshot(it)
|
||||||
|
} ?: return
|
||||||
|
|
||||||
|
val state = snapshot.engineSession?.saveState()
|
||||||
|
val isSelected = tab.id == requireComponents.core.store.state.selectedTabId ?: false
|
||||||
|
|
||||||
|
val snackbarMessage = if (snapshot.session.private) {
|
||||||
|
getString(R.string.snackbar_private_tab_closed)
|
||||||
|
} else {
|
||||||
|
getString(R.string.snackbar_tab_closed)
|
||||||
|
}
|
||||||
|
|
||||||
|
viewLifecycleOwner.lifecycleScope.allowUndo(
|
||||||
|
requireView(),
|
||||||
|
snackbarMessage,
|
||||||
|
getString(R.string.snackbar_deleted_undo),
|
||||||
|
{
|
||||||
|
sessionManager.add(snapshot.session, isSelected, engineSessionState = state)
|
||||||
|
},
|
||||||
|
operation = { },
|
||||||
|
anchorView = view?.tab_tray_controls
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onTabSelected(tab: Tab) {
|
override fun onTabSelected(tab: Tab) {
|
||||||
|
|
|
@ -2,109 +2,114 @@
|
||||||
<!-- This Source Code Form is subject to the terms of the Mozilla Public
|
<!-- 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
|
- 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/. -->
|
- 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"
|
<androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:mozac="http://schemas.android.com/apk/res-auto"
|
xmlns:mozac="http://schemas.android.com/apk/res-auto"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent">
|
||||||
android:background="?tabTrayItemBackground">
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/tab_tray_empty_view"
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="0dp"
|
|
||||||
android:gravity="center"
|
|
||||||
android:text="@string/no_open_tabs_description"
|
|
||||||
android:textColor="?secondaryText"
|
|
||||||
android:textSize="16sp"
|
|
||||||
android:visibility="gone"
|
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
|
||||||
|
|
||||||
<mozilla.components.concept.tabstray.TabsTray
|
|
||||||
android:id="@+id/tabsTray"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="0dp"
|
android:layout_height="match_parent"
|
||||||
app:layout_constraintBottom_toTopOf="@+id/save_to_collection_button"
|
android:background="?tabTrayItemBackground">
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toTopOf="parent"
|
|
||||||
mozac:tabsTrayItemBackgroundColor="?tabTrayItemBackground"
|
|
||||||
mozac:tabsTrayItemTextColor="?tabTrayItemText"
|
|
||||||
mozac:tabsTraySelectedItemBackgroundColor="?tabTrayItemSelectedBackground"
|
|
||||||
mozac:tabsTraySelectedItemTextColor="?tabTrayItemText"
|
|
||||||
mozac:tabsTrayItemUrlTextColor="?tabTrayItemUrl"
|
|
||||||
mozac:tabsTraySelectedItemUrlTextColor="?tabTrayItemUrl"/>
|
|
||||||
|
|
||||||
<include
|
<TextView
|
||||||
layout="@layout/save_to_collection_button"
|
android:id="@+id/tab_tray_empty_view"
|
||||||
android:id="@+id/save_to_collection_button"
|
android:layout_width="0dp"
|
||||||
android:layout_width="match_parent"
|
android:layout_height="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:gravity="center"
|
||||||
android:layout_marginStart="16dp"
|
android:text="@string/no_open_tabs_description"
|
||||||
android:layout_marginEnd="16dp"
|
android:textColor="?secondaryText"
|
||||||
app:layout_constraintBottom_toTopOf="@id/bottomBarShadow"
|
android:textSize="16sp"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/tabsTray" />
|
android:visibility="gone"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
<View
|
<mozilla.components.concept.tabstray.TabsTray
|
||||||
android:id="@+id/bottomBarShadow"
|
android:id="@+id/tabsTray"
|
||||||
android:layout_width="0dp"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="1dp"
|
android:layout_height="0dp"
|
||||||
android:background="@color/bottom_bar_shadow"
|
app:layout_constraintBottom_toTopOf="@+id/save_to_collection_button"
|
||||||
app:layout_constraintBottom_toTopOf="@id/tab_tray_controls"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent" />
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
mozac:tabsTrayItemBackgroundColor="?tabTrayItemBackground"
|
||||||
|
mozac:tabsTrayItemTextColor="?tabTrayItemText"
|
||||||
|
mozac:tabsTraySelectedItemBackgroundColor="?tabTrayItemSelectedBackground"
|
||||||
|
mozac:tabsTraySelectedItemTextColor="?tabTrayItemText"
|
||||||
|
mozac:tabsTrayItemUrlTextColor="?tabTrayItemUrl"
|
||||||
|
mozac:tabsTraySelectedItemUrlTextColor="?tabTrayItemUrl"/>
|
||||||
|
|
||||||
<View
|
<include
|
||||||
android:id="@+id/tab_tray_controls"
|
layout="@layout/save_to_collection_button"
|
||||||
android:layout_width="0dp"
|
android:id="@+id/save_to_collection_button"
|
||||||
android:layout_height="@dimen/browser_toolbar_height"
|
android:layout_width="match_parent"
|
||||||
android:background="?tabTrayToolbarBackground"
|
android:layout_height="wrap_content"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
android:layout_marginStart="16dp"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
android:layout_marginEnd="16dp"
|
||||||
app:layout_constraintStart_toStartOf="parent" />
|
app:layout_constraintBottom_toTopOf="@id/bottomBarShadow"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/tabsTray" />
|
||||||
|
|
||||||
<ImageButton
|
<View
|
||||||
android:id="@+id/private_browsing_button"
|
android:id="@+id/bottomBarShadow"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="0dp"
|
android:layout_height="1dp"
|
||||||
android:layout_marginStart="32dp"
|
android:background="@color/bottom_bar_shadow"
|
||||||
android:background="?android:attr/selectableItemBackgroundBorderless"
|
app:layout_constraintBottom_toTopOf="@id/tab_tray_controls"
|
||||||
android:contentDescription="@string/content_description_private_browsing_button"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:srcCompat="@drawable/private_browsing_button"
|
app:layout_constraintStart_toStartOf="parent" />
|
||||||
app:layout_constraintHorizontal_chainStyle="spread_inside"
|
|
||||||
app:layout_constraintTop_toTopOf="@id/tab_tray_controls"
|
|
||||||
app:layout_constraintDimensionRatio="1.0"
|
|
||||||
app:layout_constraintBottom_toBottomOf="@+id/tab_tray_controls"
|
|
||||||
app:layout_constraintEnd_toStartOf="@+id/tab_tray_go_home"
|
|
||||||
app:layout_constraintStart_toStartOf="@id/tab_tray_controls" />
|
|
||||||
|
|
||||||
<ImageButton
|
<View
|
||||||
android:id="@+id/tab_tray_go_home"
|
android:id="@+id/tab_tray_controls"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="0dp"
|
android:layout_height="@dimen/browser_toolbar_height"
|
||||||
android:background="?android:attr/selectableItemBackgroundBorderless"
|
android:background="?tabTrayToolbarBackground"
|
||||||
android:contentDescription="@string/tab_tray_menu_home"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:srcCompat="@drawable/ic_home"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintDimensionRatio="1.0"
|
app:layout_constraintStart_toStartOf="parent" />
|
||||||
app:layout_constraintTop_toTopOf="@id/tab_tray_controls"
|
|
||||||
app:layout_constraintBottom_toBottomOf="@+id/tab_tray_controls"
|
|
||||||
app:layout_constraintEnd_toStartOf="@+id/tab_tray_open_new_tab"
|
|
||||||
app:layout_constraintStart_toEndOf="@+id/private_browsing_button" />
|
|
||||||
|
|
||||||
<ImageButton
|
<ImageButton
|
||||||
android:id="@+id/tab_tray_open_new_tab"
|
android:id="@+id/private_browsing_button"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="0dp"
|
android:layout_height="0dp"
|
||||||
android:layout_marginEnd="32dp"
|
android:layout_marginStart="32dp"
|
||||||
android:background="?android:attr/selectableItemBackgroundBorderless"
|
android:background="?android:attr/selectableItemBackgroundBorderless"
|
||||||
android:contentDescription="@string/tab_tray_menu_open_new_tab"
|
android:contentDescription="@string/content_description_private_browsing_button"
|
||||||
app:srcCompat="@drawable/ic_new"
|
app:srcCompat="@drawable/private_browsing_button"
|
||||||
app:layout_constraintDimensionRatio="1.0"
|
app:layout_constraintHorizontal_chainStyle="spread_inside"
|
||||||
app:layout_constraintTop_toTopOf="@id/tab_tray_controls"
|
app:layout_constraintTop_toTopOf="@id/tab_tray_controls"
|
||||||
app:layout_constraintBottom_toBottomOf="@+id/tab_tray_controls"
|
app:layout_constraintDimensionRatio="1.0"
|
||||||
app:layout_constraintEnd_toEndOf="@+id/tab_tray_controls"
|
app:layout_constraintBottom_toBottomOf="@+id/tab_tray_controls"
|
||||||
app:layout_constraintStart_toEndOf="@+id/tab_tray_go_home" />
|
app:layout_constraintEnd_toStartOf="@+id/tab_tray_go_home"
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
app:layout_constraintStart_toStartOf="@id/tab_tray_controls" />
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/tab_tray_go_home"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
android:background="?android:attr/selectableItemBackgroundBorderless"
|
||||||
|
android:contentDescription="@string/tab_tray_menu_home"
|
||||||
|
app:srcCompat="@drawable/ic_home"
|
||||||
|
app:layout_constraintDimensionRatio="1.0"
|
||||||
|
app:layout_constraintTop_toTopOf="@id/tab_tray_controls"
|
||||||
|
app:layout_constraintBottom_toBottomOf="@+id/tab_tray_controls"
|
||||||
|
app:layout_constraintEnd_toStartOf="@+id/tab_tray_open_new_tab"
|
||||||
|
app:layout_constraintStart_toEndOf="@+id/private_browsing_button" />
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/tab_tray_open_new_tab"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
android:layout_marginEnd="32dp"
|
||||||
|
android:background="?android:attr/selectableItemBackgroundBorderless"
|
||||||
|
android:contentDescription="@string/tab_tray_menu_open_new_tab"
|
||||||
|
app:srcCompat="@drawable/ic_new"
|
||||||
|
app:layout_constraintDimensionRatio="1.0"
|
||||||
|
app:layout_constraintTop_toTopOf="@id/tab_tray_controls"
|
||||||
|
app:layout_constraintBottom_toBottomOf="@+id/tab_tray_controls"
|
||||||
|
app:layout_constraintEnd_toEndOf="@+id/tab_tray_controls"
|
||||||
|
app:layout_constraintStart_toEndOf="@+id/tab_tray_go_home" />
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
Loading…
Reference in New Issue