|
|
|
@ -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<SessionControlChange>().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
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|