1
0
Fork 0
fenix/architecture/src/main/java/org/mozilla/fenix/mvi/UIView.kt

55 lines
1.3 KiB
Kotlin
Raw Normal View History

2019-01-28 17:46:39 +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/. */
2019-01-28 17:46:39 +01:00
package org.mozilla.fenix.mvi
import android.view.View
import android.view.ViewGroup
import androidx.annotation.IdRes
2019-01-31 07:49:41 +01:00
import io.reactivex.Observable
import io.reactivex.Observer
2019-01-28 17:46:39 +01:00
import io.reactivex.functions.Consumer
import kotlinx.android.extensions.LayoutContainer
2019-01-31 07:49:41 +01:00
abstract class UIView<S : ViewState, A : Action, C : Change>(
2019-01-30 17:36:14 +01:00
private val container: ViewGroup,
2019-01-31 07:49:41 +01:00
protected val actionEmitter: Observer<A>,
protected val changesObservable: Observable<C>
2019-01-28 17:46:39 +01:00
) : LayoutContainer {
abstract val view: View
2019-01-28 17:46:39 +01:00
/**
* Get the XML id for the UIView
*/
@get:IdRes
val containerId: Int
get() = container.id
/**
* Provides container to empower Kotlin Android Extensions
*/
override val containerView: View?
get() = container
/**
* Show the UIView
*/
open fun show() {
view.visibility = View.VISIBLE
}
2019-01-28 17:46:39 +01:00
/**
* Hide the UIView
*/
open fun hide() {
view.visibility = View.GONE
}
2019-01-28 17:46:39 +01:00
/**
* Update the view from the ViewState
*/
abstract fun updateView(): Consumer<S>
}