2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-09 19:10:42 +00:00

For #1909: Tabs disappear intermittently (#2426)

This commit is contained in:
Colin Lee 2019-05-10 17:20:45 -05:00 committed by Jeff Boek
parent e1cdeffe8c
commit cfccb997fd
2 changed files with 58 additions and 7 deletions

View File

@ -166,6 +166,45 @@ class HomeFragment : Fragment(), CoroutineScope {
homeDividerShadow.bringToFront() homeDividerShadow.bringToFront()
} }
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
val state = sessionControlComponent.stateObservable.blockingFirst()
outState.putParcelableArrayList(
KEY_TABS,
ArrayList(state.tabs)
)
outState.putParcelableArrayList(
KEY_COLLECTIONS,
ArrayList(state.collections)
)
val modeInt = if (state.mode is Mode.Private) 0 else 1
outState.putInt(KEY_MODE, modeInt)
}
override fun onViewStateRestored(savedInstanceState: Bundle?) {
super.onViewStateRestored(savedInstanceState)
if (savedInstanceState != null) {
getManagedEmitter<SessionControlChange>().onNext(
SessionControlChange.TabsChange(
(savedInstanceState.getParcelableArrayList<Tab>(
KEY_TABS
) ?: arrayListOf()).toList()
)
)
getManagedEmitter<SessionControlChange>().onNext(
SessionControlChange.CollectionsChange(
(savedInstanceState.getParcelableArrayList<TabCollection>(
KEY_COLLECTIONS
) ?: arrayListOf()).toList()
)
)
val mode = if (savedInstanceState.getInt(KEY_MODE) == 0) Mode.Private else Mode.Normal
getManagedEmitter<SessionControlChange>().onNext(
SessionControlChange.ModeChange(mode)
)
}
}
override fun onDestroyView() { override fun onDestroyView() {
homeMenu = null homeMenu = null
job.cancel() job.cancel()
@ -469,6 +508,9 @@ class HomeFragment : Fragment(), CoroutineScope {
} }
companion object { companion object {
const val toolbarPaddingDp = 12f private const val toolbarPaddingDp = 12f
private const val KEY_TABS = "tabs"
private const val KEY_COLLECTIONS = "collections"
private const val KEY_MODE = "mode"
} }
} }

View File

@ -5,6 +5,7 @@
package org.mozilla.fenix.home.sessioncontrol package org.mozilla.fenix.home.sessioncontrol
import android.graphics.Bitmap import android.graphics.Bitmap
import android.os.Parcelable
import android.view.ViewGroup import android.view.ViewGroup
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
@ -13,6 +14,7 @@ import androidx.lifecycle.ViewModelProviders
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import io.reactivex.Observable import io.reactivex.Observable
import io.reactivex.Observer import io.reactivex.Observer
import kotlinx.android.parcel.Parcelize
import org.mozilla.fenix.mvi.Action import org.mozilla.fenix.mvi.Action
import org.mozilla.fenix.mvi.ActionBusFactory import org.mozilla.fenix.mvi.ActionBusFactory
import org.mozilla.fenix.mvi.Change import org.mozilla.fenix.mvi.Change
@ -32,19 +34,25 @@ class SessionControlComponent(
bus.getSafeManagedObservable(SessionControlChange::class.java) bus.getSafeManagedObservable(SessionControlChange::class.java)
) { ) {
var stateObservable: Observable<SessionControlState>
lateinit var viewModel: SessionControlViewModel
override fun initView() = SessionControlUIView(container, actionEmitter, changesObservable) override fun initView() = SessionControlUIView(container, actionEmitter, changesObservable)
val view: RecyclerView val view: RecyclerView
get() = uiView.view as RecyclerView get() = uiView.view as RecyclerView
override fun render(): Observable<SessionControlState> = override fun render(): Observable<SessionControlState> {
ViewModelProviders.of(owner, SessionControlViewModel.Factory(initialState, changesObservable)) viewModel = ViewModelProviders.of(owner, SessionControlViewModel.Factory(initialState, changesObservable))
.get(SessionControlViewModel::class.java).render(uiView) .get(SessionControlViewModel::class.java)
return viewModel.render(uiView)
}
init { init {
render() stateObservable = render()
} }
} }
@Parcelize
data class Tab( data class Tab(
val sessionId: String, val sessionId: String,
val url: String, val url: String,
@ -52,15 +60,16 @@ data class Tab(
val title: String, val title: String,
val selected: Boolean? = null, val selected: Boolean? = null,
val thumbnail: Bitmap? = null val thumbnail: Bitmap? = null
) ) : Parcelable
@Parcelize
data class TabCollection( data class TabCollection(
val id: Int, val id: Int,
val title: String, val title: String,
val tabs: MutableList<Tab>, val tabs: MutableList<Tab>,
val iconColor: Int = 0, val iconColor: Int = 0,
var expanded: Boolean = false var expanded: Boolean = false
) ) : Parcelable
sealed class Mode { sealed class Mode {
object Normal : Mode() object Normal : Mode()