parent
f1050eaff5
commit
0e44921e08
|
@ -51,6 +51,7 @@ import org.mozilla.fenix.mvi.ActionBusFactory
|
|||
import org.mozilla.fenix.mvi.getAutoDisposeObservable
|
||||
import org.mozilla.fenix.mvi.getManagedEmitter
|
||||
import org.mozilla.fenix.settings.SupportUtils
|
||||
import org.mozilla.fenix.utils.ItsNotBrokenSnack
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
|
@ -200,20 +201,6 @@ class HomeFragment : Fragment(), CoroutineScope {
|
|||
CreateCollectionFragment.createCollectionTag
|
||||
)
|
||||
}
|
||||
is TabAction.MenuTapped -> {
|
||||
val isPrivate = (activity as HomeActivity).browsingModeManager.isPrivate
|
||||
val titles = requireComponents.core.sessionManager.sessions
|
||||
.filter { session -> session.private == isPrivate }
|
||||
.map { session -> session.title }
|
||||
|
||||
val sessionType = if (isPrivate) {
|
||||
SessionBottomSheetFragment.SessionType.Private(titles)
|
||||
} else {
|
||||
SessionBottomSheetFragment.SessionType.Current(titles)
|
||||
}
|
||||
|
||||
openSessionMenu(sessionType)
|
||||
}
|
||||
is TabAction.Select -> {
|
||||
val session = requireComponents.core.sessionManager.findSessionById(action.sessionId)
|
||||
requireComponents.core.sessionManager.select(session!!)
|
||||
|
@ -240,6 +227,9 @@ class HomeFragment : Fragment(), CoroutineScope {
|
|||
val directions = HomeFragmentDirections.actionHomeFragmentToSearchFragment(null)
|
||||
Navigation.findNavController(view!!).navigate(directions)
|
||||
}
|
||||
is TabAction.ShareTabs -> {
|
||||
ItsNotBrokenSnack(context!!).showSnackbar(issueNumber = "1843")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -61,8 +61,8 @@ data class SessionControlState(
|
|||
|
||||
sealed class TabAction : Action {
|
||||
data class SaveTabGroup(val selectedTabSessionId: String?) : TabAction()
|
||||
object MenuTapped : TabAction()
|
||||
object Add : TabAction()
|
||||
object ShareTabs : TabAction()
|
||||
data class CloseAll(val private: Boolean) : TabAction()
|
||||
data class Select(val sessionId: String) : TabAction()
|
||||
data class Close(val sessionId: String) : TabAction()
|
||||
|
|
|
@ -4,10 +4,14 @@
|
|||
|
||||
package org.mozilla.fenix.home.sessioncontrol.viewholders
|
||||
|
||||
import android.content.Context
|
||||
import android.view.View
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import io.reactivex.Observer
|
||||
import kotlinx.android.synthetic.main.tab_header.view.*
|
||||
import mozilla.components.browser.menu.BrowserMenu
|
||||
import mozilla.components.browser.menu.BrowserMenuBuilder
|
||||
import mozilla.components.browser.menu.item.SimpleBrowserMenuItem
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.ext.increaseTapArea
|
||||
import org.mozilla.fenix.home.sessioncontrol.SessionControlAction
|
||||
|
@ -19,24 +23,74 @@ class TabHeaderViewHolder(
|
|||
private val actionEmitter: Observer<SessionControlAction>
|
||||
) : RecyclerView.ViewHolder(view) {
|
||||
private var isPrivate = false
|
||||
private var tabsMenu: TabHeaderMenu
|
||||
|
||||
init {
|
||||
tabsMenu = TabHeaderMenu(view.context) {
|
||||
when (it) {
|
||||
is TabHeaderMenu.Item.Share -> actionEmitter.onNext(TabAction.ShareTabs)
|
||||
is TabHeaderMenu.Item.CloseAll -> actionEmitter.onNext(TabAction.CloseAll(isPrivate))
|
||||
is TabHeaderMenu.Item.SaveToCollection -> actionEmitter.onNext(
|
||||
TabAction.SaveTabGroup(
|
||||
null
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
view.apply {
|
||||
add_tab_button.increaseTapArea(addTabButtonIncreaseDps)
|
||||
val headerTextResourceId =
|
||||
if (isPrivate) R.string.tabs_header_private_title else R.string.tab_header_label
|
||||
header_text.text = context.getString(headerTextResourceId)
|
||||
|
||||
add_tab_button.increaseTapArea(addTabButtonIncreaseDps)
|
||||
add_tab_button.setOnClickListener {
|
||||
actionEmitter.onNext(TabAction.Add)
|
||||
}
|
||||
|
||||
val headerTextResourceId = if (isPrivate) R.string.tabs_header_private_title else R.string.tab_header_label
|
||||
header_text.text = context.getString(headerTextResourceId)
|
||||
tabs_overflow_button.increaseTapArea(overflowButtonIncreaseDps)
|
||||
tabs_overflow_button.setOnClickListener {
|
||||
actionEmitter.onNext(TabAction.MenuTapped)
|
||||
tabs_overflow_button.run {
|
||||
increaseTapArea(overflowButtonIncreaseDps)
|
||||
setOnClickListener {
|
||||
tabsMenu.menuBuilder
|
||||
.build(view.context)
|
||||
.show(anchor = it, orientation = BrowserMenu.Orientation.DOWN)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class TabHeaderMenu(
|
||||
private val context: Context,
|
||||
private val onItemTapped: (Item) -> Unit = {}
|
||||
) {
|
||||
sealed class Item {
|
||||
object CloseAll : Item()
|
||||
object Share : Item()
|
||||
object SaveToCollection : Item()
|
||||
}
|
||||
|
||||
val menuBuilder by lazy { BrowserMenuBuilder(menuItems) }
|
||||
|
||||
private val menuItems by lazy {
|
||||
listOf(
|
||||
SimpleBrowserMenuItem(
|
||||
context.getString(R.string.tabs_menu_close_all_tabs)
|
||||
) {
|
||||
onItemTapped.invoke(Item.CloseAll)
|
||||
},
|
||||
SimpleBrowserMenuItem(
|
||||
context.getString(R.string.tabs_menu_share_tabs)
|
||||
) {
|
||||
onItemTapped.invoke(Item.Share)
|
||||
},
|
||||
SimpleBrowserMenuItem(
|
||||
context.getString(R.string.tabs_menu_save_to_collection)
|
||||
) {
|
||||
onItemTapped.invoke(Item.SaveToCollection)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val LAYOUT_ID = R.layout.tab_header
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
android:layout_width="@dimen/glyph_button_width"
|
||||
android:layout_height="@dimen/glyph_button_height"
|
||||
android:background="?android:attr/selectableItemBackgroundBorderless"
|
||||
android:contentDescription="@string/tab_menu"
|
||||
android:contentDescription="@string/open_tabs_menu"
|
||||
android:src="@drawable/ic_menu"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
|
|
|
@ -235,6 +235,14 @@
|
|||
<string name="add_tab">Add tab</string>
|
||||
<!-- Content description (not visible, for screen readers etc.): Close tab button. Closes the current session when pressed -->
|
||||
<string name="close_tab">Close tab</string>
|
||||
<!-- Content description (not visible, for screen readers etc.): Opens the open tabs menu when pressed -->
|
||||
<string name="open_tabs_menu">Open tabs menu</string>
|
||||
<!-- Open tabs menu item to close all tabs -->
|
||||
<string name="tabs_menu_close_all_tabs">Close all tabs</string>
|
||||
<!-- Open tabs menu item to share all tabs -->
|
||||
<string name="tabs_menu_share_tabs">Share tabs</string>
|
||||
<!-- Open tabs menu item to save tabs to collection -->
|
||||
<string name="tabs_menu_save_to_collection">Save to collection</string>
|
||||
<!-- Content description (not visible, for screen readers etc.): Opens the tab menu when pressed -->
|
||||
<string name="tab_menu">Tab menu</string>
|
||||
<!-- Tab menu item to share the tab -->
|
||||
|
|
Loading…
Reference in New Issue