1
0
Fork 0

For #1696 - Removes sessions from the bottomsheetfragment

master
Jeff Boek 2019-04-17 16:40:48 -07:00
parent 0d183b01f3
commit 6183e82264
3 changed files with 15 additions and 90 deletions

View File

@ -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)
SessionBottomSheetFragment
.create(sessionType)
.apply {
onDelete = {
val isPrivate = sessionType is SessionBottomSheetFragment.SessionType.Private
requireComponents.useCases.tabsUseCases.removeAllTabsOfType.invoke(isPrivate)
}
}
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)
}
}
}
}.show(requireActivity().supportFragmentManager, SessionBottomSheetFragment.overflowFragmentTag)
.show(requireActivity().supportFragmentManager, SessionBottomSheetFragment.overflowFragmentTag)
}
companion object {
const val toolbarPaddingDp = 12f
const val temporaryNumberOfSessions = 25
}
}

View File

@ -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<String>) : SessionType()
data class Archived(val archivedSession: ArchivedSession) : SessionType()
data class Private(val titles: List<String>) : SessionType()
data class Current(override val titles: List<String>) : SessionType()
data class Private(override val titles: List<String>) : SessionType()
abstract val titles: List<String>
}
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

View File

@ -109,6 +109,7 @@
android:text="@string/current_session_save"
android:textColor="?primaryText"
android:textSize="16sp"
android:visibility="gone"
tools:targetApi="m" />
<TextView
@ -125,5 +126,6 @@
android:text="@string/current_session_share"
android:textColor="?primaryText"
android:textSize="16sp"
android:visibility="gone"
tools:targetApi="m" />
</LinearLayout>