For #355 - Creates the history component
parent
0b147d8956
commit
22ab6ac934
@ -0,0 +1,41 @@
|
||||
/* 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
|
||||
import org.mozilla.fenix.home.sessions.SessionsUIView
|
||||
import org.mozilla.fenix.mvi.*
|
||||
|
||||
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) {
|
||||
is HistoryChange.Changed -> state // copy state with changes here
|
||||
}
|
||||
}
|
||||
|
||||
override fun initView() = HistoryUIView(container, actionEmitter, changesObservable)
|
||||
|
||||
init {
|
||||
render(reducer)
|
||||
}
|
||||
}
|
||||
|
||||
data class HistoryState(val items: List<String>) : ViewState
|
||||
|
||||
sealed class HistoryAction : Action {
|
||||
object Select : HistoryAction()
|
||||
}
|
||||
|
||||
sealed class HistoryChange : Change {
|
||||
object Changed : HistoryChange()
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
|
||||
/* 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.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.Observer
|
||||
import io.reactivex.functions.Consumer
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.mvi.UIView
|
||||
|
||||
class HistoryUIView(
|
||||
container: ViewGroup,
|
||||
actionEmitter: Observer<HistoryAction>,
|
||||
changesObservable: Observable<HistoryChange>
|
||||
) :
|
||||
UIView<HistoryState, HistoryAction, HistoryChange>(container, actionEmitter, changesObservable) {
|
||||
|
||||
override val view: RecyclerView = LayoutInflater.from(container.context)
|
||||
.inflate(R.layout.component_history, container, true)
|
||||
.findViewById(R.id.history_list)
|
||||
|
||||
init {
|
||||
view.apply {
|
||||
layoutManager = LinearLayoutManager(container.context)
|
||||
}
|
||||
}
|
||||
|
||||
override fun updateView() = Consumer<HistoryState> {
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/history_list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/url"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="TextView" />
|
||||
</LinearLayout>
|
Loading…
Reference in New Issue