For #1696 - Removes sessions from the bottomsheetfragment
This commit is contained in:
parent
0d183b01f3
commit
6183e82264
|
@ -103,20 +103,6 @@ class HomeFragment : Fragment(), CoroutineScope {
|
||||||
|
|
||||||
setupHomeMenu()
|
setupHomeMenu()
|
||||||
|
|
||||||
val bundles = requireComponents.core.sessionStorage.bundles(limit = temporaryNumberOfSessions)
|
|
||||||
|
|
||||||
bundles.observe(this, Observer { sessionBundles ->
|
|
||||||
val sessions = sessionBundles
|
|
||||||
.filter { it.id != requireComponents.core.sessionStorage.current()?.id }
|
|
||||||
.mapNotNull { sessionBundle ->
|
|
||||||
sessionBundle.id?.let {
|
|
||||||
ArchivedSession(it, sessionBundle, sessionBundle.lastSavedAt, sessionBundle.urls)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
getManagedEmitter<SessionControlChange>().onNext(SessionControlChange.ArchivedSessionsChange(sessions))
|
|
||||||
})
|
|
||||||
|
|
||||||
val searchIcon = requireComponents.search.searchEngineManager.getDefaultSearchEngine(
|
val searchIcon = requireComponents.search.searchEngineManager.getDefaultSearchEngine(
|
||||||
requireContext()
|
requireContext()
|
||||||
).let {
|
).let {
|
||||||
|
@ -177,7 +163,6 @@ class HomeFragment : Fragment(), CoroutineScope {
|
||||||
.subscribe {
|
.subscribe {
|
||||||
when (it) {
|
when (it) {
|
||||||
is SessionControlAction.Tab -> handleTabAction(it.action)
|
is SessionControlAction.Tab -> handleTabAction(it.action)
|
||||||
is SessionControlAction.Session -> handleSessionAction(it.action)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -196,11 +181,7 @@ class HomeFragment : Fragment(), CoroutineScope {
|
||||||
@SuppressWarnings("ComplexMethod")
|
@SuppressWarnings("ComplexMethod")
|
||||||
private fun handleTabAction(action: TabAction) {
|
private fun handleTabAction(action: TabAction) {
|
||||||
Do exhaustive when (action) {
|
Do exhaustive when (action) {
|
||||||
is TabAction.Archive -> {
|
is TabAction.Archive -> {}
|
||||||
launch {
|
|
||||||
requireComponents.core.sessionStorage.archive(requireComponents.core.sessionManager)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
is TabAction.MenuTapped -> {
|
is TabAction.MenuTapped -> {
|
||||||
val isPrivate = (activity as HomeActivity).browsingModeManager.isPrivate
|
val isPrivate = (activity as HomeActivity).browsingModeManager.isPrivate
|
||||||
val titles = requireComponents.core.sessionManager.sessions
|
val titles = requireComponents.core.sessionManager.sessions
|
||||||
|
@ -244,28 +225,6 @@ class HomeFragment : Fragment(), CoroutineScope {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleSessionAction(action: ArchivedSessionAction) {
|
|
||||||
when (action) {
|
|
||||||
is ArchivedSessionAction.Select -> {
|
|
||||||
launch {
|
|
||||||
requireComponents.core.sessionStorage.archive(requireComponents.core.sessionManager)
|
|
||||||
action.session.bundle.restoreSnapshot()?.apply {
|
|
||||||
requireComponents.core.sessionManager.restore(this)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
is ArchivedSessionAction.Delete -> {
|
|
||||||
launch(IO) {
|
|
||||||
requireComponents.core.sessionStorage.remove(action.session.bundle)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
is ArchivedSessionAction.MenuTapped ->
|
|
||||||
openSessionMenu(SessionBottomSheetFragment.SessionType.Archived(action.session))
|
|
||||||
is ArchivedSessionAction.ShareTapped ->
|
|
||||||
ItsNotBrokenSnack(context!!).showSnackbar(issueNumber = "244")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onPause() {
|
override fun onPause() {
|
||||||
super.onPause()
|
super.onPause()
|
||||||
sessionObserver?.let {
|
sessionObserver?.let {
|
||||||
|
@ -339,37 +298,18 @@ class HomeFragment : Fragment(), CoroutineScope {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun openSessionMenu(sessionType: SessionBottomSheetFragment.SessionType) {
|
private fun openSessionMenu(sessionType: SessionBottomSheetFragment.SessionType) {
|
||||||
SessionBottomSheetFragment.create(sessionType).apply {
|
SessionBottomSheetFragment
|
||||||
onArchive = {
|
.create(sessionType)
|
||||||
launch {
|
.apply {
|
||||||
requireComponents.core.sessionStorage.archive(requireComponents.core.sessionManager)
|
onDelete = {
|
||||||
|
val isPrivate = sessionType is SessionBottomSheetFragment.SessionType.Private
|
||||||
|
requireComponents.useCases.tabsUseCases.removeAllTabsOfType.invoke(isPrivate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
onDelete = {
|
.show(requireActivity().supportFragmentManager, SessionBottomSheetFragment.overflowFragmentTag)
|
||||||
when (it) {
|
|
||||||
is SessionBottomSheetFragment.SessionType.Archived -> {
|
|
||||||
launch(IO) {
|
|
||||||
requireComponents.core.sessionStorage.remove(it.archivedSession.bundle)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
is SessionBottomSheetFragment.SessionType.Current -> {
|
|
||||||
requireComponents.useCases.tabsUseCases.removeAllTabsOfType.invoke(false)
|
|
||||||
launch(IO) {
|
|
||||||
requireComponents.core.sessionStorage.current()?.apply {
|
|
||||||
requireComponents.core.sessionStorage.remove(this)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
is SessionBottomSheetFragment.SessionType.Private -> {
|
|
||||||
requireComponents.useCases.tabsUseCases.removeAllTabsOfType.invoke(true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}.show(requireActivity().supportFragmentManager, SessionBottomSheetFragment.overflowFragmentTag)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val toolbarPaddingDp = 12f
|
const val toolbarPaddingDp = 12f
|
||||||
const val temporaryNumberOfSessions = 25
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,14 +21,14 @@ import org.mozilla.fenix.home.sessioncontrol.viewholders.formattedSavedAt
|
||||||
|
|
||||||
class SessionBottomSheetFragment : BottomSheetDialogFragment(), LayoutContainer {
|
class SessionBottomSheetFragment : BottomSheetDialogFragment(), LayoutContainer {
|
||||||
sealed class SessionType {
|
sealed class SessionType {
|
||||||
data class Current(val titles: List<String>) : SessionType()
|
data class Current(override val titles: List<String>) : SessionType()
|
||||||
data class Archived(val archivedSession: ArchivedSession) : SessionType()
|
data class Private(override val titles: List<String>) : SessionType()
|
||||||
data class Private(val titles: List<String>) : SessionType()
|
|
||||||
|
abstract val titles: List<String>
|
||||||
}
|
}
|
||||||
|
|
||||||
private var sessionType: SessionType? = null
|
private var sessionType: SessionType? = null
|
||||||
var onDelete: ((SessionType) -> Unit)? = null
|
var onDelete: ((SessionType) -> Unit)? = null
|
||||||
var onArchive: ((SessionType.Current) -> Unit)? = null
|
|
||||||
|
|
||||||
override val containerView: View?
|
override val containerView: View?
|
||||||
get() = view
|
get() = view
|
||||||
|
@ -44,7 +44,6 @@ class SessionBottomSheetFragment : BottomSheetDialogFragment(), LayoutContainer
|
||||||
view.current_session_card_title.text = getCardTitle()
|
view.current_session_card_title.text = getCardTitle()
|
||||||
view.current_session_card_tab_list.text = getTabTitles()
|
view.current_session_card_tab_list.text = getTabTitles()
|
||||||
view.archive_session_button.apply {
|
view.archive_session_button.apply {
|
||||||
visibility = if (sessionType is SessionType.Current) View.VISIBLE else View.GONE
|
|
||||||
val drawable = ContextCompat.getDrawable(context!!, R.drawable.ic_archive)
|
val drawable = ContextCompat.getDrawable(context!!, R.drawable.ic_archive)
|
||||||
drawable?.setColorFilter(
|
drawable?.setColorFilter(
|
||||||
ContextCompat.getColor(
|
ContextCompat.getColor(
|
||||||
|
@ -54,12 +53,6 @@ class SessionBottomSheetFragment : BottomSheetDialogFragment(), LayoutContainer
|
||||||
)
|
)
|
||||||
setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null)
|
setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null)
|
||||||
setOnClickListener {
|
setOnClickListener {
|
||||||
sessionType?.also {
|
|
||||||
if (it is SessionType.Current) {
|
|
||||||
onArchive?.invoke(it)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
dismiss()
|
dismiss()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -101,7 +94,6 @@ class SessionBottomSheetFragment : BottomSheetDialogFragment(), LayoutContainer
|
||||||
private fun getCardTitle(): String? {
|
private fun getCardTitle(): String? {
|
||||||
return sessionType?.let {
|
return sessionType?.let {
|
||||||
when (it) {
|
when (it) {
|
||||||
is SessionType.Archived -> it.archivedSession.formattedSavedAt
|
|
||||||
is SessionType.Current -> getString(R.string.tabs_header_title)
|
is SessionType.Current -> getString(R.string.tabs_header_title)
|
||||||
is SessionType.Private -> getString(R.string.tabs_header_private_title)
|
is SessionType.Private -> getString(R.string.tabs_header_private_title)
|
||||||
}
|
}
|
||||||
|
@ -109,16 +101,7 @@ class SessionBottomSheetFragment : BottomSheetDialogFragment(), LayoutContainer
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getTabTitles(): String? {
|
private fun getTabTitles(): String? {
|
||||||
return sessionType?.let {
|
return sessionType?.titles?.joinToString(", ") {
|
||||||
when (it) {
|
|
||||||
is SessionType.Current -> it.titles
|
|
||||||
is SessionType.Private -> it.titles
|
|
||||||
is SessionType.Archived ->
|
|
||||||
it.archivedSession.bundle.restoreSnapshot()?.let { snapshot ->
|
|
||||||
snapshot.sessions.map { item -> item.session.title }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}?.joinToString(", ") {
|
|
||||||
if (it.length > maxTitleLength) it.substring(0,
|
if (it.length > maxTitleLength) it.substring(0,
|
||||||
maxTitleLength
|
maxTitleLength
|
||||||
) + "..." else it
|
) + "..." else it
|
||||||
|
|
|
@ -109,6 +109,7 @@
|
||||||
android:text="@string/current_session_save"
|
android:text="@string/current_session_save"
|
||||||
android:textColor="?primaryText"
|
android:textColor="?primaryText"
|
||||||
android:textSize="16sp"
|
android:textSize="16sp"
|
||||||
|
android:visibility="gone"
|
||||||
tools:targetApi="m" />
|
tools:targetApi="m" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
@ -125,5 +126,6 @@
|
||||||
android:text="@string/current_session_share"
|
android:text="@string/current_session_share"
|
||||||
android:textColor="?primaryText"
|
android:textColor="?primaryText"
|
||||||
android:textSize="16sp"
|
android:textSize="16sp"
|
||||||
|
android:visibility="gone"
|
||||||
tools:targetApi="m" />
|
tools:targetApi="m" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
Loading…
Reference in New Issue
Block a user