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.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
|
2019-02-15 00:23:41 +01:00
|
|
|
import mozilla.components.support.base.feature.BackHandler
|
2019-02-09 01:00:33 +01:00
|
|
|
import org.mozilla.fenix.R
|
|
|
|
import org.mozilla.fenix.mvi.UIView
|
|
|
|
|
|
|
|
class HistoryUIView(
|
|
|
|
container: ViewGroup,
|
|
|
|
actionEmitter: Observer<HistoryAction>,
|
|
|
|
changesObservable: Observable<HistoryChange>
|
|
|
|
) :
|
2019-02-15 00:23:41 +01:00
|
|
|
UIView<HistoryState, HistoryAction, HistoryChange>(container, actionEmitter, changesObservable),
|
|
|
|
BackHandler {
|
|
|
|
|
|
|
|
var mode: HistoryState.Mode = HistoryState.Mode.Normal
|
|
|
|
private set
|
2019-02-09 01:00:33 +01:00
|
|
|
|
|
|
|
override val view: RecyclerView = LayoutInflater.from(container.context)
|
|
|
|
.inflate(R.layout.component_history, container, true)
|
|
|
|
.findViewById(R.id.history_list)
|
|
|
|
|
|
|
|
init {
|
|
|
|
view.apply {
|
2019-02-09 02:06:47 +01:00
|
|
|
adapter = HistoryAdapter(actionEmitter)
|
2019-02-09 01:00:33 +01:00
|
|
|
layoutManager = LinearLayoutManager(container.context)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun updateView() = Consumer<HistoryState> {
|
2019-02-15 00:23:41 +01:00
|
|
|
mode = it.mode
|
2019-02-13 23:36:59 +01:00
|
|
|
(view.adapter as HistoryAdapter).updateData(it.items, it.mode)
|
2019-02-09 01:21:55 +01:00
|
|
|
}
|
2019-02-12 01:19:18 +01:00
|
|
|
|
2019-02-15 00:23:41 +01:00
|
|
|
override fun onBackPressed(): Boolean {
|
|
|
|
if (mode is HistoryState.Mode.Editing) {
|
2019-02-15 22:13:57 +01:00
|
|
|
actionEmitter.onNext(HistoryAction.BackPressed)
|
2019-02-15 00:23:41 +01:00
|
|
|
return true
|
2019-02-12 01:19:18 +01:00
|
|
|
}
|
|
|
|
|
2019-02-15 00:23:41 +01:00
|
|
|
return false
|
2019-02-09 01:00:33 +01:00
|
|
|
}
|
|
|
|
}
|