diff --git a/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt b/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt index 15dd7ad03..6d6ff1c7e 100644 --- a/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt @@ -103,20 +103,6 @@ class HomeFragment : Fragment(), CoroutineScope { 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().onNext(SessionControlChange.ArchivedSessionsChange(sessions)) - }) - val searchIcon = requireComponents.search.searchEngineManager.getDefaultSearchEngine( requireContext() ).let { @@ -177,7 +163,6 @@ class HomeFragment : Fragment(), CoroutineScope { .subscribe { when (it) { is SessionControlAction.Tab -> handleTabAction(it.action) - is SessionControlAction.Session -> handleSessionAction(it.action) } } } @@ -196,11 +181,7 @@ class HomeFragment : Fragment(), CoroutineScope { @SuppressWarnings("ComplexMethod") private fun handleTabAction(action: TabAction) { Do exhaustive when (action) { - is TabAction.Archive -> { - launch { - requireComponents.core.sessionStorage.archive(requireComponents.core.sessionManager) - } - } + is TabAction.Archive -> {} is TabAction.MenuTapped -> { val isPrivate = (activity as HomeActivity).browsingModeManager.isPrivate 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() { super.onPause() sessionObserver?.let { @@ -339,37 +298,18 @@ class HomeFragment : Fragment(), CoroutineScope { } private fun openSessionMenu(sessionType: SessionBottomSheetFragment.SessionType) { - SessionBottomSheetFragment.create(sessionType).apply { - onArchive = { - launch { - requireComponents.core.sessionStorage.archive(requireComponents.core.sessionManager) - } - } - onDelete = { - 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) - } + SessionBottomSheetFragment + .create(sessionType) + .apply { + onDelete = { + val isPrivate = sessionType is SessionBottomSheetFragment.SessionType.Private + requireComponents.useCases.tabsUseCases.removeAllTabsOfType.invoke(isPrivate) } } - }.show(requireActivity().supportFragmentManager, SessionBottomSheetFragment.overflowFragmentTag) + .show(requireActivity().supportFragmentManager, SessionBottomSheetFragment.overflowFragmentTag) } companion object { const val toolbarPaddingDp = 12f - const val temporaryNumberOfSessions = 25 } } diff --git a/app/src/main/java/org/mozilla/fenix/home/SessionBottomSheetFragment.kt b/app/src/main/java/org/mozilla/fenix/home/SessionBottomSheetFragment.kt index 947f162b5..c52ff31c8 100644 --- a/app/src/main/java/org/mozilla/fenix/home/SessionBottomSheetFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/home/SessionBottomSheetFragment.kt @@ -21,14 +21,14 @@ import org.mozilla.fenix.home.sessioncontrol.viewholders.formattedSavedAt class SessionBottomSheetFragment : BottomSheetDialogFragment(), LayoutContainer { sealed class SessionType { - data class Current(val titles: List) : SessionType() - data class Archived(val archivedSession: ArchivedSession) : SessionType() - data class Private(val titles: List) : SessionType() + data class Current(override val titles: List) : SessionType() + data class Private(override val titles: List) : SessionType() + + abstract val titles: List } private var sessionType: SessionType? = null var onDelete: ((SessionType) -> Unit)? = null - var onArchive: ((SessionType.Current) -> Unit)? = null override val containerView: View? get() = view @@ -44,7 +44,6 @@ class SessionBottomSheetFragment : BottomSheetDialogFragment(), LayoutContainer view.current_session_card_title.text = getCardTitle() view.current_session_card_tab_list.text = getTabTitles() 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) drawable?.setColorFilter( ContextCompat.getColor( @@ -54,12 +53,6 @@ class SessionBottomSheetFragment : BottomSheetDialogFragment(), LayoutContainer ) setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null) setOnClickListener { - sessionType?.also { - if (it is SessionType.Current) { - onArchive?.invoke(it) - } - } - dismiss() } } @@ -101,7 +94,6 @@ class SessionBottomSheetFragment : BottomSheetDialogFragment(), LayoutContainer private fun getCardTitle(): String? { return sessionType?.let { when (it) { - is SessionType.Archived -> it.archivedSession.formattedSavedAt is SessionType.Current -> getString(R.string.tabs_header_title) is SessionType.Private -> getString(R.string.tabs_header_private_title) } @@ -109,16 +101,7 @@ class SessionBottomSheetFragment : BottomSheetDialogFragment(), LayoutContainer } private fun getTabTitles(): String? { - return sessionType?.let { - 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(", ") { + return sessionType?.titles?.joinToString(", ") { if (it.length > maxTitleLength) it.substring(0, maxTitleLength ) + "..." else it diff --git a/app/src/main/res/layout/session_bottom_sheet.xml b/app/src/main/res/layout/session_bottom_sheet.xml index 1c8303d4c..a25ef3a6c 100644 --- a/app/src/main/res/layout/session_bottom_sheet.xml +++ b/app/src/main/res/layout/session_bottom_sheet.xml @@ -109,6 +109,7 @@ android:text="@string/current_session_save" android:textColor="?primaryText" android:textSize="16sp" + android:visibility="gone" tools:targetApi="m" /> \ No newline at end of file