forked from upstream-mirrors/quik
Implement Conductor for Settings and About screens
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
package com.moez.QKSMS.common.base
|
||||
|
||||
import com.bluelinelabs.conductor.autodispose.ControllerEvent
|
||||
import com.uber.autodispose.LifecycleScopeProvider
|
||||
|
||||
interface QkConductorView<in State> {
|
||||
|
||||
fun render(state: State)
|
||||
|
||||
fun scope(): LifecycleScopeProvider<ControllerEvent>
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.moez.QKSMS.common.base
|
||||
|
||||
import android.view.View
|
||||
import androidx.annotation.CallSuper
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.bluelinelabs.conductor.Controller
|
||||
import com.bluelinelabs.conductor.autodispose.ControllerEvent
|
||||
import com.bluelinelabs.conductor.autodispose.ControllerScopeProvider
|
||||
import com.uber.autodispose.LifecycleScopeProvider
|
||||
import kotlinx.android.synthetic.main.toolbar.view.*
|
||||
|
||||
abstract class QkController : Controller() {
|
||||
|
||||
private val appCompatActivity: AppCompatActivity?
|
||||
get() = activity as? AppCompatActivity
|
||||
|
||||
@CallSuper
|
||||
override fun onAttach(view: View) {
|
||||
super.onAttach(view)
|
||||
appCompatActivity?.setSupportActionBar(view.toolbar)
|
||||
setTitle(activity?.title)
|
||||
}
|
||||
|
||||
fun setTitle(@StringRes titleId: Int) {
|
||||
setTitle(activity?.getString(titleId))
|
||||
}
|
||||
|
||||
fun setTitle(title: CharSequence?) {
|
||||
activity?.title = title
|
||||
view?.toolbarTitle?.text = title
|
||||
}
|
||||
|
||||
fun showBackButton(show: Boolean) {
|
||||
appCompatActivity?.supportActionBar?.setDisplayHomeAsUpEnabled(show)
|
||||
}
|
||||
|
||||
fun scope(): LifecycleScopeProvider<ControllerEvent> {
|
||||
return ControllerScopeProvider.from(this)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.moez.QKSMS.common.base
|
||||
|
||||
import androidx.annotation.CallSuper
|
||||
import com.uber.autodispose.kotlin.autoDisposable
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.subjects.BehaviorSubject
|
||||
|
||||
abstract class QkPresenter<View : QkConductorView<State>, State>(initialState: State) {
|
||||
|
||||
protected val state: BehaviorSubject<State> = BehaviorSubject.createDefault(initialState)
|
||||
|
||||
open fun onCreate(view: View) {
|
||||
}
|
||||
|
||||
@CallSuper
|
||||
open fun onAttach(view: View) {
|
||||
state
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe(view::render)
|
||||
}
|
||||
|
||||
protected fun newState(reducer: State.() -> State) {
|
||||
state.value?.let { state.onNext(reducer(it)) }
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user