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.getAutoDisposeObservable
|
||||||
import org.mozilla.fenix.mvi.getManagedEmitter
|
import org.mozilla.fenix.mvi.getManagedEmitter
|
||||||
import org.mozilla.fenix.settings.SupportUtils
|
import org.mozilla.fenix.settings.SupportUtils
|
||||||
|
import org.mozilla.fenix.utils.ItsNotBrokenSnack
|
||||||
import kotlin.coroutines.CoroutineContext
|
import kotlin.coroutines.CoroutineContext
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
|
@ -200,20 +201,6 @@ class HomeFragment : Fragment(), CoroutineScope {
|
||||||
CreateCollectionFragment.createCollectionTag
|
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 -> {
|
is TabAction.Select -> {
|
||||||
val session = requireComponents.core.sessionManager.findSessionById(action.sessionId)
|
val session = requireComponents.core.sessionManager.findSessionById(action.sessionId)
|
||||||
requireComponents.core.sessionManager.select(session!!)
|
requireComponents.core.sessionManager.select(session!!)
|
||||||
|
@ -240,6 +227,9 @@ class HomeFragment : Fragment(), CoroutineScope {
|
||||||
val directions = HomeFragmentDirections.actionHomeFragmentToSearchFragment(null)
|
val directions = HomeFragmentDirections.actionHomeFragmentToSearchFragment(null)
|
||||||
Navigation.findNavController(view!!).navigate(directions)
|
Navigation.findNavController(view!!).navigate(directions)
|
||||||
}
|
}
|
||||||
|
is TabAction.ShareTabs -> {
|
||||||
|
ItsNotBrokenSnack(context!!).showSnackbar(issueNumber = "1843")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -61,8 +61,8 @@ data class SessionControlState(
|
||||||
|
|
||||||
sealed class TabAction : Action {
|
sealed class TabAction : Action {
|
||||||
data class SaveTabGroup(val selectedTabSessionId: String?) : TabAction()
|
data class SaveTabGroup(val selectedTabSessionId: String?) : TabAction()
|
||||||
object MenuTapped : TabAction()
|
|
||||||
object Add : TabAction()
|
object Add : TabAction()
|
||||||
|
object ShareTabs : TabAction()
|
||||||
data class CloseAll(val private: Boolean) : TabAction()
|
data class CloseAll(val private: Boolean) : TabAction()
|
||||||
data class Select(val sessionId: String) : TabAction()
|
data class Select(val sessionId: String) : TabAction()
|
||||||
data class Close(val sessionId: String) : TabAction()
|
data class Close(val sessionId: String) : TabAction()
|
||||||
|
|
|
@ -4,10 +4,14 @@
|
||||||
|
|
||||||
package org.mozilla.fenix.home.sessioncontrol.viewholders
|
package org.mozilla.fenix.home.sessioncontrol.viewholders
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import io.reactivex.Observer
|
import io.reactivex.Observer
|
||||||
import kotlinx.android.synthetic.main.tab_header.view.*
|
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.R
|
||||||
import org.mozilla.fenix.ext.increaseTapArea
|
import org.mozilla.fenix.ext.increaseTapArea
|
||||||
import org.mozilla.fenix.home.sessioncontrol.SessionControlAction
|
import org.mozilla.fenix.home.sessioncontrol.SessionControlAction
|
||||||
|
@ -19,24 +23,74 @@ class TabHeaderViewHolder(
|
||||||
private val actionEmitter: Observer<SessionControlAction>
|
private val actionEmitter: Observer<SessionControlAction>
|
||||||
) : RecyclerView.ViewHolder(view) {
|
) : RecyclerView.ViewHolder(view) {
|
||||||
private var isPrivate = false
|
private var isPrivate = false
|
||||||
|
private var tabsMenu: TabHeaderMenu
|
||||||
|
|
||||||
init {
|
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 {
|
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 {
|
add_tab_button.setOnClickListener {
|
||||||
actionEmitter.onNext(TabAction.Add)
|
actionEmitter.onNext(TabAction.Add)
|
||||||
}
|
}
|
||||||
|
|
||||||
val headerTextResourceId = if (isPrivate) R.string.tabs_header_private_title else R.string.tab_header_label
|
tabs_overflow_button.run {
|
||||||
header_text.text = context.getString(headerTextResourceId)
|
increaseTapArea(overflowButtonIncreaseDps)
|
||||||
tabs_overflow_button.increaseTapArea(overflowButtonIncreaseDps)
|
setOnClickListener {
|
||||||
tabs_overflow_button.setOnClickListener {
|
tabsMenu.menuBuilder
|
||||||
actionEmitter.onNext(TabAction.MenuTapped)
|
.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 {
|
companion object {
|
||||||
const val LAYOUT_ID = R.layout.tab_header
|
const val LAYOUT_ID = R.layout.tab_header
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@
|
||||||
android:layout_width="@dimen/glyph_button_width"
|
android:layout_width="@dimen/glyph_button_width"
|
||||||
android:layout_height="@dimen/glyph_button_height"
|
android:layout_height="@dimen/glyph_button_height"
|
||||||
android:background="?android:attr/selectableItemBackgroundBorderless"
|
android:background="?android:attr/selectableItemBackgroundBorderless"
|
||||||
android:contentDescription="@string/tab_menu"
|
android:contentDescription="@string/open_tabs_menu"
|
||||||
android:src="@drawable/ic_menu"
|
android:src="@drawable/ic_menu"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
|
|
@ -235,6 +235,14 @@
|
||||||
<string name="add_tab">Add tab</string>
|
<string name="add_tab">Add tab</string>
|
||||||
<!-- Content description (not visible, for screen readers etc.): Close tab button. Closes the current session when pressed -->
|
<!-- Content description (not visible, for screen readers etc.): Close tab button. Closes the current session when pressed -->
|
||||||
<string name="close_tab">Close tab</string>
|
<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 -->
|
<!-- Content description (not visible, for screen readers etc.): Opens the tab menu when pressed -->
|
||||||
<string name="tab_menu">Tab menu</string>
|
<string name="tab_menu">Tab menu</string>
|
||||||
<!-- Tab menu item to share the tab -->
|
<!-- Tab menu item to share the tab -->
|
||||||
|
|
Loading…
Reference in New Issue