forked from upstream-mirrors/quik
Convert ThemePicker Activity to Controller
This commit is contained in:
@@ -1,7 +1,10 @@
|
|||||||
package com.moez.QKSMS.common.base
|
package com.moez.QKSMS.common.base
|
||||||
|
|
||||||
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
import androidx.annotation.CallSuper
|
import androidx.annotation.CallSuper
|
||||||
|
import androidx.annotation.LayoutRes
|
||||||
import androidx.annotation.StringRes
|
import androidx.annotation.StringRes
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import com.bluelinelabs.conductor.Controller
|
import com.bluelinelabs.conductor.Controller
|
||||||
@@ -22,6 +25,13 @@ abstract class QkController<ViewContract : QkViewContract<State>, State, Present
|
|||||||
override val containerView: View?
|
override val containerView: View?
|
||||||
get() = view
|
get() = view
|
||||||
|
|
||||||
|
@LayoutRes
|
||||||
|
var layoutRes: Int = 0
|
||||||
|
|
||||||
|
final override fun onCreateView(inflater: LayoutInflater, container: ViewGroup): View {
|
||||||
|
return inflater.inflate(layoutRes, container, false)
|
||||||
|
}
|
||||||
|
|
||||||
@CallSuper
|
@CallSuper
|
||||||
override fun onAttach(view: View) {
|
override fun onAttach(view: View) {
|
||||||
super.onAttach(view)
|
super.onAttach(view)
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import com.moez.QKSMS.common.util.extensions.setBackgroundTint
|
|||||||
import com.moez.QKSMS.common.util.extensions.setVisible
|
import com.moez.QKSMS.common.util.extensions.setVisible
|
||||||
import com.moez.QKSMS.common.widget.PreferenceView
|
import com.moez.QKSMS.common.widget.PreferenceView
|
||||||
import com.moez.QKSMS.feature.settings.about.AboutController
|
import com.moez.QKSMS.feature.settings.about.AboutController
|
||||||
|
import com.moez.QKSMS.feature.themepicker.ThemePickerController
|
||||||
import com.moez.QKSMS.injection.appComponent
|
import com.moez.QKSMS.injection.appComponent
|
||||||
import com.moez.QKSMS.util.Preferences
|
import com.moez.QKSMS.util.Preferences
|
||||||
import com.uber.autodispose.kotlin.autoDisposable
|
import com.uber.autodispose.kotlin.autoDisposable
|
||||||
@@ -60,30 +61,27 @@ class SettingsController : QkController<SettingsView, SettingsState, SettingsPre
|
|||||||
init {
|
init {
|
||||||
appComponent.inject(this)
|
appComponent.inject(this)
|
||||||
retainViewMode = RetainViewMode.RETAIN_DETACH
|
retainViewMode = RetainViewMode.RETAIN_DETACH
|
||||||
|
layoutRes = R.layout.settings_activity
|
||||||
|
|
||||||
colors.themeObservable()
|
colors.themeObservable()
|
||||||
.autoDisposable(scope())
|
.autoDisposable(scope())
|
||||||
.subscribe { activity?.recreate() }
|
.subscribe { activity?.recreate() }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup): View {
|
|
||||||
return inflater.inflate(R.layout.settings_activity, container, false).apply {
|
|
||||||
preferences.postDelayed({ preferences.animateLayoutChanges = true }, 100)
|
|
||||||
|
|
||||||
nightModeDialog.adapter.setData(R.array.night_modes)
|
|
||||||
textSizeDialog.adapter.setData(R.array.text_sizes)
|
|
||||||
sendDelayDialog.adapter.setData(R.array.delayed_sending_labels)
|
|
||||||
mmsSizeDialog.adapter.setData(R.array.mms_sizes, R.array.mms_sizes_ids)
|
|
||||||
|
|
||||||
about.summary = context.getString(R.string.settings_version, BuildConfig.VERSION_NAME)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onAttach(view: View) {
|
override fun onAttach(view: View) {
|
||||||
super.onAttach(view)
|
super.onAttach(view)
|
||||||
presenter.bindIntents(this)
|
presenter.bindIntents(this)
|
||||||
setTitle(R.string.title_settings)
|
setTitle(R.string.title_settings)
|
||||||
showBackButton(true)
|
showBackButton(true)
|
||||||
|
|
||||||
|
preferences.postDelayed({ preferences.animateLayoutChanges = true }, 100)
|
||||||
|
|
||||||
|
nightModeDialog.adapter.setData(R.array.night_modes)
|
||||||
|
textSizeDialog.adapter.setData(R.array.text_sizes)
|
||||||
|
sendDelayDialog.adapter.setData(R.array.delayed_sending_labels)
|
||||||
|
mmsSizeDialog.adapter.setData(R.array.mms_sizes, R.array.mms_sizes_ids)
|
||||||
|
|
||||||
|
about.summary = context.getString(R.string.settings_version, BuildConfig.VERSION_NAME)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun preferenceClicks(): Observable<PreferenceView> = (0 until preferences.childCount)
|
override fun preferenceClicks(): Observable<PreferenceView> = (0 until preferences.childCount)
|
||||||
@@ -168,10 +166,16 @@ class SettingsController : QkController<SettingsView, SettingsState, SettingsPre
|
|||||||
|
|
||||||
override fun showMmsSizePicker() = mmsSizeDialog.show(activity!!)
|
override fun showMmsSizePicker() = mmsSizeDialog.show(activity!!)
|
||||||
|
|
||||||
|
override fun showThemePicker() {
|
||||||
|
router.pushController(RouterTransaction.with(ThemePickerController())
|
||||||
|
.pushChangeHandler(FadeChangeHandler(150))
|
||||||
|
.popChangeHandler(FadeChangeHandler(150)))
|
||||||
|
}
|
||||||
|
|
||||||
override fun showAbout() {
|
override fun showAbout() {
|
||||||
router.pushController(RouterTransaction.with(AboutController())
|
router.pushController(RouterTransaction.with(AboutController())
|
||||||
.pushChangeHandler(FadeChangeHandler())
|
.pushChangeHandler(FadeChangeHandler(150))
|
||||||
.popChangeHandler(FadeChangeHandler()))
|
.popChangeHandler(FadeChangeHandler(150)))
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -97,7 +97,7 @@ class SettingsPresenter @Inject constructor(
|
|||||||
Timber.v("Preference click: ${context.resources.getResourceName(it.id)}")
|
Timber.v("Preference click: ${context.resources.getResourceName(it.id)}")
|
||||||
|
|
||||||
when (it.id) {
|
when (it.id) {
|
||||||
R.id.theme -> navigator.showThemePicker()
|
R.id.theme -> view.showThemePicker()
|
||||||
|
|
||||||
R.id.night -> view.showNightModeDialog()
|
R.id.night -> view.showNightModeDialog()
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ import com.moez.QKSMS.common.widget.PreferenceView
|
|||||||
import io.reactivex.Observable
|
import io.reactivex.Observable
|
||||||
|
|
||||||
interface SettingsView : QkViewContract<SettingsState> {
|
interface SettingsView : QkViewContract<SettingsState> {
|
||||||
|
|
||||||
fun preferenceClicks(): Observable<PreferenceView>
|
fun preferenceClicks(): Observable<PreferenceView>
|
||||||
fun viewQksmsPlusClicks(): Observable<*>
|
fun viewQksmsPlusClicks(): Observable<*>
|
||||||
fun nightModeSelected(): Observable<Int>
|
fun nightModeSelected(): Observable<Int>
|
||||||
@@ -40,5 +39,6 @@ interface SettingsView : QkViewContract<SettingsState> {
|
|||||||
fun showTextSizePicker()
|
fun showTextSizePicker()
|
||||||
fun showDelayDurationDialog()
|
fun showDelayDurationDialog()
|
||||||
fun showMmsSizePicker()
|
fun showMmsSizePicker()
|
||||||
|
fun showThemePicker()
|
||||||
fun showAbout()
|
fun showAbout()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
package com.moez.QKSMS.feature.settings.about
|
package com.moez.QKSMS.feature.settings.about
|
||||||
|
|
||||||
import android.view.LayoutInflater
|
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
|
||||||
import com.jakewharton.rxbinding2.view.clicks
|
import com.jakewharton.rxbinding2.view.clicks
|
||||||
import com.moez.QKSMS.BuildConfig
|
import com.moez.QKSMS.BuildConfig
|
||||||
import com.moez.QKSMS.R
|
import com.moez.QKSMS.R
|
||||||
@@ -11,7 +9,6 @@ import com.moez.QKSMS.common.widget.PreferenceView
|
|||||||
import com.moez.QKSMS.injection.appComponent
|
import com.moez.QKSMS.injection.appComponent
|
||||||
import io.reactivex.Observable
|
import io.reactivex.Observable
|
||||||
import kotlinx.android.synthetic.main.about_activity.*
|
import kotlinx.android.synthetic.main.about_activity.*
|
||||||
import kotlinx.android.synthetic.main.about_activity.view.*
|
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class AboutController : QkController<AboutView, Unit, AboutPresenter>(), AboutView {
|
class AboutController : QkController<AboutView, Unit, AboutPresenter>(), AboutView {
|
||||||
@@ -20,12 +17,7 @@ class AboutController : QkController<AboutView, Unit, AboutPresenter>(), AboutVi
|
|||||||
|
|
||||||
init {
|
init {
|
||||||
appComponent.inject(this)
|
appComponent.inject(this)
|
||||||
}
|
layoutRes = R.layout.about_activity
|
||||||
|
|
||||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup): View {
|
|
||||||
return inflater.inflate(R.layout.about_activity, container, false).apply {
|
|
||||||
version.summary = BuildConfig.VERSION_NAME
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onAttach(view: View) {
|
override fun onAttach(view: View) {
|
||||||
@@ -33,6 +25,8 @@ class AboutController : QkController<AboutView, Unit, AboutPresenter>(), AboutVi
|
|||||||
presenter.bindIntents(this)
|
presenter.bindIntents(this)
|
||||||
setTitle(R.string.about_title)
|
setTitle(R.string.about_title)
|
||||||
showBackButton(true)
|
showBackButton(true)
|
||||||
|
|
||||||
|
version.summary = BuildConfig.VERSION_NAME
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun preferenceClicks(): Observable<PreferenceView> = (0 until preferences.childCount)
|
override fun preferenceClicks(): Observable<PreferenceView> = (0 until preferences.childCount)
|
||||||
|
|||||||
+15
-54
@@ -19,73 +19,34 @@
|
|||||||
package com.moez.QKSMS.feature.themepicker
|
package com.moez.QKSMS.feature.themepicker
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.lifecycle.ViewModelProvider
|
import com.bluelinelabs.conductor.Conductor
|
||||||
import androidx.lifecycle.ViewModelProviders
|
import com.bluelinelabs.conductor.Router
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import com.bluelinelabs.conductor.RouterTransaction
|
||||||
import com.google.android.material.snackbar.Snackbar
|
|
||||||
import com.jakewharton.rxbinding2.view.clicks
|
|
||||||
import com.moez.QKSMS.R
|
import com.moez.QKSMS.R
|
||||||
import com.moez.QKSMS.common.base.QkThemedActivity
|
import com.moez.QKSMS.common.base.QkThemedActivity
|
||||||
import com.moez.QKSMS.common.util.extensions.setBackgroundTint
|
|
||||||
import com.moez.QKSMS.common.util.extensions.setVisible
|
|
||||||
import dagger.android.AndroidInjection
|
import dagger.android.AndroidInjection
|
||||||
import io.reactivex.subjects.PublishSubject
|
import kotlinx.android.synthetic.main.container_activity.*
|
||||||
import io.reactivex.subjects.Subject
|
|
||||||
import kotlinx.android.synthetic.main.theme_picker_activity.*
|
|
||||||
import kotlinx.android.synthetic.main.theme_picker_hsv.*
|
|
||||||
import javax.inject.Inject
|
|
||||||
|
|
||||||
class ThemePickerActivity : QkThemedActivity(), ThemePickerView {
|
class ThemePickerActivity : QkThemedActivity() {
|
||||||
|
|
||||||
@Inject lateinit var themeAdapter: ThemeAdapter
|
private lateinit var router: Router
|
||||||
@Inject lateinit var themePagerAdapter: ThemePagerAdapter
|
|
||||||
@Inject lateinit var viewModelFactory: ViewModelProvider.Factory
|
|
||||||
|
|
||||||
override val themeSelectedIntent by lazy { themeAdapter.colorSelected }
|
|
||||||
override val hsvThemeSelectedIntent by lazy { picker.selectedColor }
|
|
||||||
override val hsvThemeClearedIntent by lazy { clear.clicks() }
|
|
||||||
override val hsvThemeAppliedIntent by lazy { apply.clicks() }
|
|
||||||
override val viewQksmsPlusIntent: Subject<Unit> = PublishSubject.create()
|
|
||||||
|
|
||||||
private val viewModel by lazy { ViewModelProviders.of(this, viewModelFactory)[ThemePickerViewModel::class.java] }
|
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
AndroidInjection.inject(this)
|
AndroidInjection.inject(this)
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.theme_picker_activity)
|
setContentView(R.layout.container_activity)
|
||||||
setTitle(R.string.title_theme)
|
|
||||||
showBackButton(true)
|
|
||||||
viewModel.bindView(this)
|
|
||||||
|
|
||||||
pager.offscreenPageLimit = 1
|
router = Conductor.attachRouter(this, container, savedInstanceState)
|
||||||
pager.adapter = themePagerAdapter
|
if (!router.hasRootController()) {
|
||||||
tabs.pager = pager
|
val threadId = intent.extras?.getLong("threadId") ?: 0L
|
||||||
|
router.setRoot(RouterTransaction.with(ThemePickerController(threadId)))
|
||||||
themeAdapter.data = colors.materialColors
|
|
||||||
|
|
||||||
materialColors.layoutManager = LinearLayoutManager(this)
|
|
||||||
materialColors.adapter = themeAdapter
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun showQksmsPlusSnackbar() {
|
|
||||||
Snackbar.make(contentView, R.string.toast_qksms_plus, Snackbar.LENGTH_LONG).run {
|
|
||||||
setAction(R.string.button_more) { viewQksmsPlusIntent.onNext(Unit) }
|
|
||||||
show()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun render(state: ThemePickerState) {
|
override fun onBackPressed() {
|
||||||
tabs.setThreadId(state.threadId)
|
if (!router.handleBack()) {
|
||||||
|
super.onBackPressed()
|
||||||
hex.setText(Integer.toHexString(state.newColor).takeLast(6))
|
}
|
||||||
|
|
||||||
applyGroup.setVisible(state.applyThemeVisible)
|
|
||||||
apply.setBackgroundTint(state.newColor)
|
|
||||||
apply.setTextColor(state.newTextColor)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setCurrentTheme(color: Int) {
|
|
||||||
picker.setColor(color)
|
|
||||||
themeAdapter.selectedColor = color
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
+107
@@ -0,0 +1,107 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
|
||||||
|
*
|
||||||
|
* This file is part of QKSMS.
|
||||||
|
*
|
||||||
|
* QKSMS is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* QKSMS is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package com.moez.QKSMS.feature.themepicker
|
||||||
|
|
||||||
|
import android.view.View
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
|
import com.google.android.material.snackbar.Snackbar
|
||||||
|
import com.jakewharton.rxbinding2.view.clicks
|
||||||
|
import com.moez.QKSMS.R
|
||||||
|
import com.moez.QKSMS.common.base.QkController
|
||||||
|
import com.moez.QKSMS.common.util.Colors
|
||||||
|
import com.moez.QKSMS.common.util.extensions.setBackgroundTint
|
||||||
|
import com.moez.QKSMS.common.util.extensions.setVisible
|
||||||
|
import com.moez.QKSMS.feature.themepicker.injection.ThemePickerModule
|
||||||
|
import com.moez.QKSMS.injection.appComponent
|
||||||
|
import io.reactivex.Observable
|
||||||
|
import io.reactivex.subjects.PublishSubject
|
||||||
|
import io.reactivex.subjects.Subject
|
||||||
|
import kotlinx.android.synthetic.main.theme_picker_activity.*
|
||||||
|
import kotlinx.android.synthetic.main.theme_picker_hsv.*
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class ThemePickerController(val threadId: Long = 0L) : QkController<ThemePickerView, ThemePickerState, ThemePickerPresenter>(), ThemePickerView {
|
||||||
|
|
||||||
|
@Inject override lateinit var presenter: ThemePickerPresenter
|
||||||
|
|
||||||
|
@Inject lateinit var colors: Colors
|
||||||
|
@Inject lateinit var themeAdapter: ThemeAdapter
|
||||||
|
@Inject lateinit var themePagerAdapter: ThemePagerAdapter
|
||||||
|
|
||||||
|
private val viewQksmsPlusSubject: Subject<Unit> = PublishSubject.create()
|
||||||
|
|
||||||
|
init {
|
||||||
|
appComponent
|
||||||
|
.themePickerBuilder()
|
||||||
|
.themePickerModule(ThemePickerModule(this))
|
||||||
|
.build()
|
||||||
|
.inject(this)
|
||||||
|
|
||||||
|
layoutRes = R.layout.theme_picker_activity
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onAttach(view: View) {
|
||||||
|
super.onAttach(view)
|
||||||
|
presenter.bindIntents(this)
|
||||||
|
setTitle(R.string.title_theme)
|
||||||
|
showBackButton(true)
|
||||||
|
|
||||||
|
pager.offscreenPageLimit = 1
|
||||||
|
pager.adapter = themePagerAdapter
|
||||||
|
tabs.pager = pager
|
||||||
|
|
||||||
|
themeAdapter.data = colors.materialColors
|
||||||
|
|
||||||
|
materialColors.layoutManager = LinearLayoutManager(activity)
|
||||||
|
materialColors.adapter = themeAdapter
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun showQksmsPlusSnackbar() {
|
||||||
|
Snackbar.make(contentView, R.string.toast_qksms_plus, Snackbar.LENGTH_LONG).run {
|
||||||
|
setAction(R.string.button_more) { viewQksmsPlusSubject.onNext(Unit) }
|
||||||
|
show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun themeSelected(): Observable<Int> = themeAdapter.colorSelected
|
||||||
|
|
||||||
|
override fun hsvThemeSelected(): Observable<Int> = picker.selectedColor
|
||||||
|
|
||||||
|
override fun clearHsvThemeClicks(): Observable<*> = clear.clicks()
|
||||||
|
|
||||||
|
override fun applyHsvThemeClicks(): Observable<*> = apply.clicks()
|
||||||
|
|
||||||
|
override fun viewQksmsPlusClicks(): Observable<*> = viewQksmsPlusSubject
|
||||||
|
|
||||||
|
override fun render(state: ThemePickerState) {
|
||||||
|
tabs.setThreadId(state.threadId)
|
||||||
|
|
||||||
|
hex.setText(Integer.toHexString(state.newColor).takeLast(6))
|
||||||
|
|
||||||
|
applyGroup.setVisible(state.applyThemeVisible)
|
||||||
|
apply.setBackgroundTint(state.newColor)
|
||||||
|
apply.setTextColor(state.newTextColor)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setCurrentTheme(color: Int) {
|
||||||
|
picker.setColor(color)
|
||||||
|
themeAdapter.selectedColor = color
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+14
-15
@@ -20,8 +20,7 @@ package com.moez.QKSMS.feature.themepicker
|
|||||||
|
|
||||||
import com.f2prateek.rx.preferences2.Preference
|
import com.f2prateek.rx.preferences2.Preference
|
||||||
import com.moez.QKSMS.common.Navigator
|
import com.moez.QKSMS.common.Navigator
|
||||||
import com.moez.QKSMS.common.androidxcompat.scope
|
import com.moez.QKSMS.common.base.QkPresenter
|
||||||
import com.moez.QKSMS.common.base.QkViewModel
|
|
||||||
import com.moez.QKSMS.common.util.BillingManager
|
import com.moez.QKSMS.common.util.BillingManager
|
||||||
import com.moez.QKSMS.common.util.Colors
|
import com.moez.QKSMS.common.util.Colors
|
||||||
import com.moez.QKSMS.util.Preferences
|
import com.moez.QKSMS.util.Preferences
|
||||||
@@ -31,30 +30,30 @@ import io.reactivex.rxkotlin.withLatestFrom
|
|||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Named
|
import javax.inject.Named
|
||||||
|
|
||||||
class ThemePickerViewModel @Inject constructor(
|
class ThemePickerPresenter @Inject constructor(
|
||||||
@Named("threadId") threadId: Long,
|
@Named("threadId") threadId: Long,
|
||||||
|
prefs: Preferences,
|
||||||
private val billingManager: BillingManager,
|
private val billingManager: BillingManager,
|
||||||
private val colors: Colors,
|
private val colors: Colors,
|
||||||
private val navigator: Navigator,
|
private val navigator: Navigator
|
||||||
private val prefs: Preferences
|
) : QkPresenter<ThemePickerView, ThemePickerState>(ThemePickerState(threadId = threadId)) {
|
||||||
) : QkViewModel<ThemePickerView, ThemePickerState>(ThemePickerState(threadId = threadId)) {
|
|
||||||
|
|
||||||
private val theme: Preference<Int> = prefs.theme(threadId)
|
private val theme: Preference<Int> = prefs.theme(threadId)
|
||||||
|
|
||||||
override fun bindView(view: ThemePickerView) {
|
override fun bindIntents(view: ThemePickerView) {
|
||||||
super.bindView(view)
|
super.bindIntents(view)
|
||||||
|
|
||||||
theme.asObservable()
|
theme.asObservable()
|
||||||
.autoDisposable(view.scope())
|
.autoDisposable(view.scope())
|
||||||
.subscribe { color -> view.setCurrentTheme(color) }
|
.subscribe { color -> view.setCurrentTheme(color) }
|
||||||
|
|
||||||
// Update the theme when a material theme is clicked
|
// Update the theme when a material theme is clicked
|
||||||
view.themeSelectedIntent
|
view.themeSelected()
|
||||||
.autoDisposable(view.scope())
|
.autoDisposable(view.scope())
|
||||||
.subscribe { color -> theme.set(color) }
|
.subscribe { color -> theme.set(color) }
|
||||||
|
|
||||||
// Update the color of the apply button
|
// Update the color of the apply button
|
||||||
view.hsvThemeSelectedIntent
|
view.hsvThemeSelected()
|
||||||
.doOnNext { color -> newState { copy(newColor = color) } }
|
.doOnNext { color -> newState { copy(newColor = color) } }
|
||||||
.map { color -> colors.textPrimaryOnThemeForColor(color) }
|
.map { color -> colors.textPrimaryOnThemeForColor(color) }
|
||||||
.doOnNext { color -> newState { copy(newTextColor = color) } }
|
.doOnNext { color -> newState { copy(newTextColor = color) } }
|
||||||
@@ -62,13 +61,13 @@ class ThemePickerViewModel @Inject constructor(
|
|||||||
.subscribe()
|
.subscribe()
|
||||||
|
|
||||||
// Toggle the visibility of the apply group
|
// Toggle the visibility of the apply group
|
||||||
Observables.combineLatest(theme.asObservable(), view.hsvThemeSelectedIntent) { old, new -> old != new }
|
Observables.combineLatest(theme.asObservable(), view.hsvThemeSelected()) { old, new -> old != new }
|
||||||
.autoDisposable(view.scope())
|
.autoDisposable(view.scope())
|
||||||
.subscribe { themeChanged -> newState { copy(applyThemeVisible = themeChanged) } }
|
.subscribe { themeChanged -> newState { copy(applyThemeVisible = themeChanged) } }
|
||||||
|
|
||||||
// Update the theme, when apply is clicked
|
// Update the theme, when apply is clicked
|
||||||
view.hsvThemeAppliedIntent
|
view.applyHsvThemeClicks()
|
||||||
.withLatestFrom(view.hsvThemeSelectedIntent) { _, color -> color }
|
.withLatestFrom(view.hsvThemeSelected()) { _, color -> color }
|
||||||
.withLatestFrom(billingManager.upgradeStatus) { color, upgraded ->
|
.withLatestFrom(billingManager.upgradeStatus) { color, upgraded ->
|
||||||
if (!upgraded) {
|
if (!upgraded) {
|
||||||
view.showQksmsPlusSnackbar()
|
view.showQksmsPlusSnackbar()
|
||||||
@@ -80,12 +79,12 @@ class ThemePickerViewModel @Inject constructor(
|
|||||||
.subscribe()
|
.subscribe()
|
||||||
|
|
||||||
// Show QKSMS+ activity
|
// Show QKSMS+ activity
|
||||||
view.viewQksmsPlusIntent
|
view.viewQksmsPlusClicks()
|
||||||
.autoDisposable(view.scope())
|
.autoDisposable(view.scope())
|
||||||
.subscribe { navigator.showQksmsPlusActivity("settings_theme") }
|
.subscribe { navigator.showQksmsPlusActivity("settings_theme") }
|
||||||
|
|
||||||
// Reset the theme
|
// Reset the theme
|
||||||
view.hsvThemeClearedIntent
|
view.clearHsvThemeClicks()
|
||||||
.withLatestFrom(theme.asObservable()) { _, color -> color }
|
.withLatestFrom(theme.asObservable()) { _, color -> color }
|
||||||
.autoDisposable(view.scope())
|
.autoDisposable(view.scope())
|
||||||
.subscribe { color -> view.setCurrentTheme(color) }
|
.subscribe { color -> view.setCurrentTheme(color) }
|
||||||
@@ -18,17 +18,16 @@
|
|||||||
*/
|
*/
|
||||||
package com.moez.QKSMS.feature.themepicker
|
package com.moez.QKSMS.feature.themepicker
|
||||||
|
|
||||||
import com.moez.QKSMS.common.base.QkView
|
import com.moez.QKSMS.common.base.QkViewContract
|
||||||
import io.reactivex.Observable
|
import io.reactivex.Observable
|
||||||
import io.reactivex.subjects.Subject
|
|
||||||
|
|
||||||
interface ThemePickerView : QkView<ThemePickerState> {
|
interface ThemePickerView : QkViewContract<ThemePickerState> {
|
||||||
|
|
||||||
val themeSelectedIntent: Observable<Int>
|
fun themeSelected(): Observable<Int>
|
||||||
val hsvThemeSelectedIntent: Observable<Int>
|
fun hsvThemeSelected(): Observable<Int>
|
||||||
val hsvThemeClearedIntent: Observable<*>
|
fun clearHsvThemeClicks(): Observable<*>
|
||||||
val hsvThemeAppliedIntent: Observable<*>
|
fun applyHsvThemeClicks(): Observable<*>
|
||||||
val viewQksmsPlusIntent: Subject<Unit>
|
fun viewQksmsPlusClicks(): Observable<*>
|
||||||
|
|
||||||
fun setCurrentTheme(color: Int)
|
fun setCurrentTheme(color: Int)
|
||||||
fun showQksmsPlusSnackbar()
|
fun showQksmsPlusSnackbar()
|
||||||
|
|||||||
+37
@@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
|
||||||
|
*
|
||||||
|
* This file is part of QKSMS.
|
||||||
|
*
|
||||||
|
* QKSMS is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* QKSMS is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package com.moez.QKSMS.feature.themepicker.injection
|
||||||
|
|
||||||
|
import com.moez.QKSMS.feature.themepicker.ThemePickerController
|
||||||
|
import com.moez.QKSMS.injection.scope.ControllerScope
|
||||||
|
import dagger.Subcomponent
|
||||||
|
|
||||||
|
@ControllerScope
|
||||||
|
@Subcomponent(modules = [ThemePickerModule::class])
|
||||||
|
interface ThemePickerComponent {
|
||||||
|
|
||||||
|
fun inject(controller: ThemePickerController)
|
||||||
|
|
||||||
|
@Subcomponent.Builder
|
||||||
|
interface Builder {
|
||||||
|
fun themePickerModule(module: ThemePickerModule): Builder
|
||||||
|
fun build(): ThemePickerComponent
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+6
-11
@@ -16,25 +16,20 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
|
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package com.moez.QKSMS.feature.themepicker
|
package com.moez.QKSMS.feature.themepicker.injection
|
||||||
|
|
||||||
import androidx.lifecycle.ViewModel
|
import com.moez.QKSMS.feature.themepicker.ThemePickerController
|
||||||
import com.moez.QKSMS.injection.ViewModelKey
|
import com.moez.QKSMS.injection.scope.ControllerScope
|
||||||
import dagger.Module
|
import dagger.Module
|
||||||
import dagger.Provides
|
import dagger.Provides
|
||||||
import dagger.multibindings.IntoMap
|
|
||||||
import javax.inject.Named
|
import javax.inject.Named
|
||||||
|
|
||||||
@Module
|
@Module
|
||||||
class ThemePickerActivityModule {
|
class ThemePickerModule(private val controller: ThemePickerController) {
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
|
@ControllerScope
|
||||||
@Named("threadId")
|
@Named("threadId")
|
||||||
fun provideThreadId(activity: ThemePickerActivity): Long = activity.intent.extras?.getLong("threadId") ?: 0L
|
fun provideThreadId(): Long = controller.threadId
|
||||||
|
|
||||||
@Provides
|
|
||||||
@IntoMap
|
|
||||||
@ViewModelKey(ThemePickerViewModel::class)
|
|
||||||
fun provideThemePickerViewModel(viewModel: ThemePickerViewModel): ViewModel = viewModel
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -29,7 +29,11 @@ import com.moez.QKSMS.common.widget.QkTextView
|
|||||||
import com.moez.QKSMS.feature.compose.DetailedChipView
|
import com.moez.QKSMS.feature.compose.DetailedChipView
|
||||||
import com.moez.QKSMS.feature.settings.SettingsController
|
import com.moez.QKSMS.feature.settings.SettingsController
|
||||||
import com.moez.QKSMS.feature.settings.about.AboutController
|
import com.moez.QKSMS.feature.settings.about.AboutController
|
||||||
|
import com.moez.QKSMS.feature.themepicker.injection.ThemePickerComponent
|
||||||
import com.moez.QKSMS.feature.widget.WidgetAdapter
|
import com.moez.QKSMS.feature.widget.WidgetAdapter
|
||||||
|
import com.moez.QKSMS.injection.android.ActivityBuilderModule
|
||||||
|
import com.moez.QKSMS.injection.android.BroadcastReceiverBuilderModule
|
||||||
|
import com.moez.QKSMS.injection.android.ServiceBuilderModule
|
||||||
import com.moez.QKSMS.util.ContactImageLoader
|
import com.moez.QKSMS.util.ContactImageLoader
|
||||||
import dagger.Component
|
import dagger.Component
|
||||||
import dagger.android.support.AndroidSupportInjectionModule
|
import dagger.android.support.AndroidSupportInjectionModule
|
||||||
@@ -44,6 +48,8 @@ import javax.inject.Singleton
|
|||||||
ServiceBuilderModule::class])
|
ServiceBuilderModule::class])
|
||||||
interface AppComponent {
|
interface AppComponent {
|
||||||
|
|
||||||
|
fun themePickerBuilder(): ThemePickerComponent.Builder
|
||||||
|
|
||||||
fun inject(application: QKApplication)
|
fun inject(application: QKApplication)
|
||||||
|
|
||||||
fun inject(controller: AboutController)
|
fun inject(controller: AboutController)
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import androidx.lifecycle.ViewModelProvider
|
|||||||
import com.f2prateek.rx.preferences2.RxSharedPreferences
|
import com.f2prateek.rx.preferences2.RxSharedPreferences
|
||||||
import com.moez.QKSMS.common.ViewModelFactory
|
import com.moez.QKSMS.common.ViewModelFactory
|
||||||
import com.moez.QKSMS.common.util.NotificationManagerImpl
|
import com.moez.QKSMS.common.util.NotificationManagerImpl
|
||||||
|
import com.moez.QKSMS.feature.themepicker.injection.ThemePickerComponent
|
||||||
import com.moez.QKSMS.manager.AlarmManager
|
import com.moez.QKSMS.manager.AlarmManager
|
||||||
import com.moez.QKSMS.manager.AlarmManagerImpl
|
import com.moez.QKSMS.manager.AlarmManagerImpl
|
||||||
import com.moez.QKSMS.manager.AnalyticsManager
|
import com.moez.QKSMS.manager.AnalyticsManager
|
||||||
@@ -67,7 +68,7 @@ import dagger.Module
|
|||||||
import dagger.Provides
|
import dagger.Provides
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
|
||||||
@Module
|
@Module(subcomponents = [ThemePickerComponent::class])
|
||||||
class AppModule(private var application: Application) {
|
class AppModule(private var application: Application) {
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
|
|||||||
+3
-3
@@ -16,7 +16,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
|
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package com.moez.QKSMS.injection
|
package com.moez.QKSMS.injection.android
|
||||||
|
|
||||||
import com.moez.QKSMS.feature.blocked.BlockedActivity
|
import com.moez.QKSMS.feature.blocked.BlockedActivity
|
||||||
import com.moez.QKSMS.feature.blocked.BlockedActivityModule
|
import com.moez.QKSMS.feature.blocked.BlockedActivityModule
|
||||||
@@ -38,7 +38,7 @@ import com.moez.QKSMS.feature.scheduled.ScheduledActivity
|
|||||||
import com.moez.QKSMS.feature.scheduled.ScheduledActivityModule
|
import com.moez.QKSMS.feature.scheduled.ScheduledActivityModule
|
||||||
import com.moez.QKSMS.feature.settings.SettingsActivity
|
import com.moez.QKSMS.feature.settings.SettingsActivity
|
||||||
import com.moez.QKSMS.feature.themepicker.ThemePickerActivity
|
import com.moez.QKSMS.feature.themepicker.ThemePickerActivity
|
||||||
import com.moez.QKSMS.feature.themepicker.ThemePickerActivityModule
|
import com.moez.QKSMS.injection.scope.ActivityScope
|
||||||
import dagger.Module
|
import dagger.Module
|
||||||
import dagger.android.ContributesAndroidInjector
|
import dagger.android.ContributesAndroidInjector
|
||||||
|
|
||||||
@@ -86,7 +86,7 @@ abstract class ActivityBuilderModule {
|
|||||||
abstract fun bindBlockedActivity(): BlockedActivity
|
abstract fun bindBlockedActivity(): BlockedActivity
|
||||||
|
|
||||||
@ActivityScope
|
@ActivityScope
|
||||||
@ContributesAndroidInjector(modules = [ThemePickerActivityModule::class])
|
@ContributesAndroidInjector(modules = [])
|
||||||
abstract fun bindThemePickerActivity(): ThemePickerActivity
|
abstract fun bindThemePickerActivity(): ThemePickerActivity
|
||||||
|
|
||||||
}
|
}
|
||||||
+2
-1
@@ -16,9 +16,10 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
|
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package com.moez.QKSMS.injection
|
package com.moez.QKSMS.injection.android
|
||||||
|
|
||||||
import com.moez.QKSMS.feature.widget.WidgetProvider
|
import com.moez.QKSMS.feature.widget.WidgetProvider
|
||||||
|
import com.moez.QKSMS.injection.scope.ActivityScope
|
||||||
import com.moez.QKSMS.receiver.BootReceiver
|
import com.moez.QKSMS.receiver.BootReceiver
|
||||||
import com.moez.QKSMS.receiver.DefaultSmsChangedReceiver
|
import com.moez.QKSMS.receiver.DefaultSmsChangedReceiver
|
||||||
import com.moez.QKSMS.receiver.MarkReadReceiver
|
import com.moez.QKSMS.receiver.MarkReadReceiver
|
||||||
+2
-1
@@ -16,8 +16,9 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
|
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package com.moez.QKSMS.injection
|
package com.moez.QKSMS.injection.android
|
||||||
|
|
||||||
|
import com.moez.QKSMS.injection.scope.ActivityScope
|
||||||
import com.moez.QKSMS.service.HeadlessSmsSendService
|
import com.moez.QKSMS.service.HeadlessSmsSendService
|
||||||
import dagger.Module
|
import dagger.Module
|
||||||
import dagger.android.ContributesAndroidInjector
|
import dagger.android.ContributesAndroidInjector
|
||||||
+1
-1
@@ -16,7 +16,7 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
|
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package com.moez.QKSMS.injection
|
package com.moez.QKSMS.injection.scope
|
||||||
|
|
||||||
import javax.inject.Scope
|
import javax.inject.Scope
|
||||||
|
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
|
||||||
|
*
|
||||||
|
* This file is part of QKSMS.
|
||||||
|
*
|
||||||
|
* QKSMS is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* QKSMS is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package com.moez.QKSMS.injection.scope
|
||||||
|
|
||||||
|
import javax.inject.Scope
|
||||||
|
|
||||||
|
@Scope
|
||||||
|
annotation class ControllerScope
|
||||||
Reference in New Issue
Block a user