2019-02-09 01:00:33 +01:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
package org.mozilla.fenix.library.history
|
|
|
|
|
|
|
|
import android.view.ViewGroup
|
2019-02-09 01:21:55 +01:00
|
|
|
import org.mozilla.fenix.mvi.Action
|
|
|
|
import org.mozilla.fenix.mvi.ActionBusFactory
|
|
|
|
import org.mozilla.fenix.mvi.Change
|
|
|
|
import org.mozilla.fenix.mvi.UIComponent
|
|
|
|
import org.mozilla.fenix.mvi.ViewState
|
|
|
|
|
|
|
|
data class HistoryItem(val url: String)
|
2019-02-09 01:00:33 +01:00
|
|
|
|
|
|
|
class HistoryComponent(
|
|
|
|
private val container: ViewGroup,
|
|
|
|
bus: ActionBusFactory,
|
|
|
|
override var initialState: HistoryState = HistoryState(emptyList())
|
|
|
|
) :
|
|
|
|
UIComponent<HistoryState, HistoryAction, HistoryChange>(
|
|
|
|
bus.getManagedEmitter(HistoryAction::class.java),
|
|
|
|
bus.getSafeManagedObservable(HistoryChange::class.java)
|
|
|
|
) {
|
|
|
|
|
|
|
|
override val reducer: (HistoryState, HistoryChange) -> HistoryState = { state, change ->
|
|
|
|
when (change) {
|
2019-02-09 01:21:55 +01:00
|
|
|
is HistoryChange.Change -> state.copy(items = change.list)
|
2019-02-09 01:00:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun initView() = HistoryUIView(container, actionEmitter, changesObservable)
|
|
|
|
|
|
|
|
init {
|
|
|
|
render(reducer)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-09 01:21:55 +01:00
|
|
|
data class HistoryState(val items: List<HistoryItem>) : ViewState
|
2019-02-09 01:00:33 +01:00
|
|
|
|
|
|
|
sealed class HistoryAction : Action {
|
|
|
|
object Select : HistoryAction()
|
|
|
|
}
|
|
|
|
|
|
|
|
sealed class HistoryChange : Change {
|
2019-02-09 01:21:55 +01:00
|
|
|
data class Change(val list: List<HistoryItem>) : HistoryChange()
|
2019-02-09 01:00:33 +01:00
|
|
|
}
|