mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-09 19:10:42 +00:00
parent
e1cdeffe8c
commit
cfccb997fd
@ -166,6 +166,45 @@ class HomeFragment : Fragment(), CoroutineScope {
|
||||
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() {
|
||||
homeMenu = null
|
||||
job.cancel()
|
||||
@ -469,6 +508,9 @@ class HomeFragment : Fragment(), CoroutineScope {
|
||||
}
|
||||
|
||||
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"
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@
|
||||
package org.mozilla.fenix.home.sessioncontrol
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import android.os.Parcelable
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.ViewModel
|
||||
@ -13,6 +14,7 @@ import androidx.lifecycle.ViewModelProviders
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.Observer
|
||||
import kotlinx.android.parcel.Parcelize
|
||||
import org.mozilla.fenix.mvi.Action
|
||||
import org.mozilla.fenix.mvi.ActionBusFactory
|
||||
import org.mozilla.fenix.mvi.Change
|
||||
@ -32,19 +34,25 @@ class SessionControlComponent(
|
||||
bus.getSafeManagedObservable(SessionControlChange::class.java)
|
||||
) {
|
||||
|
||||
var stateObservable: Observable<SessionControlState>
|
||||
lateinit var viewModel: SessionControlViewModel
|
||||
|
||||
override fun initView() = SessionControlUIView(container, actionEmitter, changesObservable)
|
||||
val view: RecyclerView
|
||||
get() = uiView.view as RecyclerView
|
||||
|
||||
override fun render(): Observable<SessionControlState> =
|
||||
ViewModelProviders.of(owner, SessionControlViewModel.Factory(initialState, changesObservable))
|
||||
.get(SessionControlViewModel::class.java).render(uiView)
|
||||
override fun render(): Observable<SessionControlState> {
|
||||
viewModel = ViewModelProviders.of(owner, SessionControlViewModel.Factory(initialState, changesObservable))
|
||||
.get(SessionControlViewModel::class.java)
|
||||
return viewModel.render(uiView)
|
||||
}
|
||||
|
||||
init {
|
||||
render()
|
||||
stateObservable = render()
|
||||
}
|
||||
}
|
||||
|
||||
@Parcelize
|
||||
data class Tab(
|
||||
val sessionId: String,
|
||||
val url: String,
|
||||
@ -52,15 +60,16 @@ data class Tab(
|
||||
val title: String,
|
||||
val selected: Boolean? = null,
|
||||
val thumbnail: Bitmap? = null
|
||||
)
|
||||
) : Parcelable
|
||||
|
||||
@Parcelize
|
||||
data class TabCollection(
|
||||
val id: Int,
|
||||
val title: String,
|
||||
val tabs: MutableList<Tab>,
|
||||
val iconColor: Int = 0,
|
||||
var expanded: Boolean = false
|
||||
)
|
||||
) : Parcelable
|
||||
|
||||
sealed class Mode {
|
||||
object Normal : Mode()
|
||||
|
Loading…
Reference in New Issue
Block a user