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()
|
||||||
|
}
|
|
@ -14,16 +14,20 @@ import android.view.ViewGroup
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.navigation.Navigation
|
import androidx.navigation.Navigation
|
||||||
|
import kotlinx.android.synthetic.main.fragment_history.view.*
|
||||||
import org.mozilla.fenix.R
|
import org.mozilla.fenix.R
|
||||||
|
import org.mozilla.fenix.mvi.ActionBusFactory
|
||||||
|
|
||||||
class HistoryFragment : Fragment() {
|
class HistoryFragment : Fragment() {
|
||||||
|
|
||||||
override fun onCreateView(
|
override fun onCreateView(
|
||||||
inflater: LayoutInflater,
|
inflater: LayoutInflater,
|
||||||
container: ViewGroup?,
|
container: ViewGroup?,
|
||||||
savedInstanceState: Bundle?
|
savedInstanceState: Bundle?
|
||||||
): View? {
|
): View? {
|
||||||
return inflater.inflate(R.layout.fragment_history, container, false)
|
val view = inflater.inflate(R.layout.fragment_history, container, false)
|
||||||
|
HistoryComponent(view.history_layout, ActionBusFactory.get(this), initialState = HistoryState(emptyList()))
|
||||||
|
|
||||||
|
return view
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
|
|
@ -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" />
|
|
@ -4,9 +4,9 @@
|
||||||
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
|
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:id="@+id/history_layout"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
tools:context="org.mozilla.fenix.library.history.HistoryFragment">
|
tools:context="org.mozilla.fenix.library.history.HistoryFragment">
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
|
@ -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