forked from upstream-mirrors/quik
Implement Conductor for Settings and About screens
This commit is contained in:
@@ -38,7 +38,6 @@ import com.moez.QKSMS.feature.notificationprefs.NotificationPrefsActivity
|
||||
import com.moez.QKSMS.feature.plus.PlusActivity
|
||||
import com.moez.QKSMS.feature.scheduled.ScheduledActivity
|
||||
import com.moez.QKSMS.feature.settings.SettingsActivity
|
||||
import com.moez.QKSMS.feature.settings.about.AboutActivity
|
||||
import com.moez.QKSMS.feature.themepicker.ThemePickerActivity
|
||||
import com.moez.QKSMS.manager.AnalyticsManager
|
||||
import com.moez.QKSMS.manager.NotificationManager
|
||||
@@ -139,11 +138,6 @@ class Navigator @Inject constructor(
|
||||
startActivity(intent)
|
||||
}
|
||||
|
||||
fun showAbout() {
|
||||
val intent = Intent(context, AboutActivity::class.java)
|
||||
startActivity(intent)
|
||||
}
|
||||
|
||||
fun showDeveloper() {
|
||||
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/moezbhatti"))
|
||||
startActivity(intent)
|
||||
|
||||
@@ -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