forked from upstream-mirrors/quik
Implement Conductor for Settings and About screens
This commit is contained in:
+3
-1
@@ -1,9 +1,11 @@
|
|||||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||||
|
|
||||||
buildscript {
|
buildscript {
|
||||||
ext.androidx_version = '1.0.0-alpha3'
|
ext.androidx_version = '1.0.0-beta01'
|
||||||
ext.androidx_testrunner_version = '1.1.0-alpha3'
|
ext.androidx_testrunner_version = '1.1.0-alpha3'
|
||||||
ext.autodispose_version = '0.5.1'
|
ext.autodispose_version = '0.5.1'
|
||||||
|
ext.conductor_version = '2.1.5-20180620.204119-27'
|
||||||
|
ext.conductor_autodispose_version = '2.1.5-20180620.204134-27'
|
||||||
ext.constraintlayout_version = '1.1.0'
|
ext.constraintlayout_version = '1.1.0'
|
||||||
ext.dagger_version = "2.16"
|
ext.dagger_version = "2.16"
|
||||||
ext.espresso_version = '3.1.0-alpha3'
|
ext.espresso_version = '3.1.0-alpha3'
|
||||||
|
|||||||
@@ -111,6 +111,10 @@ dependencies {
|
|||||||
implementation "com.google.android.material:material:$androidx_version"
|
implementation "com.google.android.material:material:$androidx_version"
|
||||||
implementation "androidx.emoji:emoji-appcompat:$androidx_version"
|
implementation "androidx.emoji:emoji-appcompat:$androidx_version"
|
||||||
|
|
||||||
|
// conductor
|
||||||
|
implementation "com.bluelinelabs:conductor:$conductor_version"
|
||||||
|
implementation "com.bluelinelabs:conductor-autodispose:$conductor_autodispose_version"
|
||||||
|
|
||||||
// glide
|
// glide
|
||||||
implementation "com.github.bumptech.glide:glide:$glide_version"
|
implementation "com.github.bumptech.glide:glide:$glide_version"
|
||||||
kapt "com.github.bumptech.glide:compiler:$glide_compiler_version"
|
kapt "com.github.bumptech.glide:compiler:$glide_compiler_version"
|
||||||
|
|||||||
@@ -92,7 +92,7 @@
|
|||||||
android:excludeFromRecents="true"
|
android:excludeFromRecents="true"
|
||||||
android:taskAffinity=""
|
android:taskAffinity=""
|
||||||
android:theme="@style/AppThemeLightDialog" />
|
android:theme="@style/AppThemeLightDialog" />
|
||||||
<activity android:name=".feature.settings.about.AboutActivity" />
|
<activity android:name=".feature.settings.about.AboutController" />
|
||||||
<activity android:name=".feature.scheduled.ScheduledActivity" />
|
<activity android:name=".feature.scheduled.ScheduledActivity" />
|
||||||
|
|
||||||
<receiver android:name=".receiver.BootReceiver">
|
<receiver android:name=".receiver.BootReceiver">
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ import com.moez.QKSMS.feature.notificationprefs.NotificationPrefsActivity
|
|||||||
import com.moez.QKSMS.feature.plus.PlusActivity
|
import com.moez.QKSMS.feature.plus.PlusActivity
|
||||||
import com.moez.QKSMS.feature.scheduled.ScheduledActivity
|
import com.moez.QKSMS.feature.scheduled.ScheduledActivity
|
||||||
import com.moez.QKSMS.feature.settings.SettingsActivity
|
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.feature.themepicker.ThemePickerActivity
|
||||||
import com.moez.QKSMS.manager.AnalyticsManager
|
import com.moez.QKSMS.manager.AnalyticsManager
|
||||||
import com.moez.QKSMS.manager.NotificationManager
|
import com.moez.QKSMS.manager.NotificationManager
|
||||||
@@ -139,11 +138,6 @@ class Navigator @Inject constructor(
|
|||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun showAbout() {
|
|
||||||
val intent = Intent(context, AboutActivity::class.java)
|
|
||||||
startActivity(intent)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun showDeveloper() {
|
fun showDeveloper() {
|
||||||
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/moezbhatti"))
|
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/moezbhatti"))
|
||||||
startActivity(intent)
|
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)) }
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -18,152 +18,34 @@
|
|||||||
*/
|
*/
|
||||||
package com.moez.QKSMS.feature.settings
|
package com.moez.QKSMS.feature.settings
|
||||||
|
|
||||||
import android.app.ProgressDialog
|
|
||||||
import android.app.TimePickerDialog
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.text.format.DateFormat
|
import com.bluelinelabs.conductor.Conductor
|
||||||
import androidx.lifecycle.ViewModelProvider
|
import com.bluelinelabs.conductor.Router
|
||||||
import androidx.lifecycle.ViewModelProviders
|
import com.bluelinelabs.conductor.RouterTransaction
|
||||||
import com.google.android.material.snackbar.Snackbar
|
|
||||||
import com.jakewharton.rxbinding2.view.clicks
|
|
||||||
import com.moez.QKSMS.BuildConfig
|
|
||||||
import com.moez.QKSMS.R
|
import com.moez.QKSMS.R
|
||||||
import com.moez.QKSMS.common.QkDialog
|
|
||||||
import com.moez.QKSMS.common.androidxcompat.scope
|
|
||||||
import com.moez.QKSMS.common.base.QkThemedActivity
|
import com.moez.QKSMS.common.base.QkThemedActivity
|
||||||
import com.moez.QKSMS.common.util.extensions.animateLayoutChanges
|
|
||||||
import com.moez.QKSMS.common.util.extensions.setBackgroundTint
|
|
||||||
import com.moez.QKSMS.common.util.extensions.setVisible
|
|
||||||
import com.moez.QKSMS.common.widget.PreferenceView
|
|
||||||
import com.moez.QKSMS.util.Preferences
|
|
||||||
import com.uber.autodispose.kotlin.autoDisposable
|
|
||||||
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.settings_activity.*
|
|
||||||
import kotlinx.android.synthetic.main.settings_switch_widget.view.*
|
|
||||||
import kotlinx.android.synthetic.main.settings_theme_widget.*
|
|
||||||
import javax.inject.Inject
|
|
||||||
|
|
||||||
class SettingsActivity : QkThemedActivity(), SettingsView {
|
class SettingsActivity : QkThemedActivity() {
|
||||||
|
|
||||||
@Inject lateinit var nightModeDialog: QkDialog
|
private lateinit var router: Router
|
||||||
@Inject lateinit var textSizeDialog: QkDialog
|
|
||||||
@Inject lateinit var sendDelayDialog: QkDialog
|
|
||||||
@Inject lateinit var mmsSizeDialog: QkDialog
|
|
||||||
@Inject lateinit var viewModelFactory: ViewModelProvider.Factory
|
|
||||||
|
|
||||||
override val preferenceClickIntent: Subject<PreferenceView> = PublishSubject.create()
|
|
||||||
override val viewQksmsPlusIntent: Subject<Unit> = PublishSubject.create()
|
|
||||||
override val nightModeSelectedIntent by lazy { nightModeDialog.adapter.menuItemClicks }
|
|
||||||
override val startTimeSelectedIntent: Subject<Pair<Int, Int>> = PublishSubject.create()
|
|
||||||
override val endTimeSelectedIntent: Subject<Pair<Int, Int>> = PublishSubject.create()
|
|
||||||
override val textSizeSelectedIntent by lazy { textSizeDialog.adapter.menuItemClicks }
|
|
||||||
override val sendDelayChangedIntent by lazy { sendDelayDialog.adapter.menuItemClicks }
|
|
||||||
override val mmsSizeSelectedIntent: Subject<Int> by lazy { mmsSizeDialog.adapter.menuItemClicks }
|
|
||||||
|
|
||||||
private val viewModel by lazy { ViewModelProviders.of(this, viewModelFactory)[SettingsViewModel::class.java] }
|
|
||||||
|
|
||||||
// TODO remove this
|
|
||||||
private val progressDialog by lazy {
|
|
||||||
ProgressDialog(this).apply {
|
|
||||||
isIndeterminate = true
|
|
||||||
setCancelable(false)
|
|
||||||
setCanceledOnTouchOutside(false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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.settings_activity)
|
setContentView(R.layout.container_activity)
|
||||||
setTitle(R.string.title_settings)
|
|
||||||
showBackButton(true)
|
|
||||||
viewModel.bindView(this)
|
|
||||||
|
|
||||||
preferences.postDelayed({ preferences.animateLayoutChanges = true }, 100)
|
router = Conductor.attachRouter(this, container, savedInstanceState)
|
||||||
|
if (!router.hasRootController()) {
|
||||||
nightModeDialog.adapter.setData(R.array.night_modes)
|
router.setRoot(RouterTransaction.with(SettingsController()))
|
||||||
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 = getString(R.string.settings_version, BuildConfig.VERSION_NAME)
|
|
||||||
|
|
||||||
// Listen to clicks for all of the preferences
|
|
||||||
(0 until preferences.childCount)
|
|
||||||
.map { index -> preferences.getChildAt(index) }
|
|
||||||
.filter { view -> view is PreferenceView }
|
|
||||||
.forEach { preference ->
|
|
||||||
preference.clicks().subscribe {
|
|
||||||
preferenceClickIntent.onNext(preference as PreferenceView)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
theme
|
|
||||||
.skip(1)
|
|
||||||
.autoDisposable(scope())
|
|
||||||
.subscribe { recreate() }
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun render(state: SettingsState) {
|
|
||||||
if (progressDialog.isShowing && !state.syncing) progressDialog.dismiss()
|
|
||||||
else if (!progressDialog.isShowing && state.syncing) progressDialog.show()
|
|
||||||
|
|
||||||
themePreview.setBackgroundTint(state.theme)
|
|
||||||
night.summary = state.nightModeSummary
|
|
||||||
nightModeDialog.adapter.selectedItem = state.nightModeId
|
|
||||||
nightStart.setVisible(state.nightModeId == Preferences.NIGHT_MODE_AUTO)
|
|
||||||
nightStart.summary = state.nightStart
|
|
||||||
nightEnd.setVisible(state.nightModeId == Preferences.NIGHT_MODE_AUTO)
|
|
||||||
nightEnd.summary = state.nightEnd
|
|
||||||
|
|
||||||
black.setVisible(state.nightModeId != Preferences.NIGHT_MODE_OFF)
|
|
||||||
black.checkbox.isChecked = state.black
|
|
||||||
|
|
||||||
autoEmoji.checkbox.isChecked = state.autoEmojiEnabled
|
|
||||||
|
|
||||||
delayed.summary = state.sendDelaySummary
|
|
||||||
sendDelayDialog.adapter.selectedItem = state.sendDelayId
|
|
||||||
|
|
||||||
delivery.checkbox.isChecked = state.deliveryEnabled
|
|
||||||
|
|
||||||
textSize.summary = state.textSizeSummary
|
|
||||||
textSizeDialog.adapter.selectedItem = state.textSizeId
|
|
||||||
systemFont.checkbox.isChecked = state.systemFontEnabled
|
|
||||||
|
|
||||||
unicode.checkbox.isChecked = state.stripUnicodeEnabled
|
|
||||||
|
|
||||||
mmsSize.summary = state.maxMmsSizeSummary
|
|
||||||
mmsSizeDialog.adapter.selectedItem = state.maxMmsSizeId
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun showQksmsPlusSnackbar() {
|
|
||||||
Snackbar.make(contentView, R.string.toast_qksms_plus, Snackbar.LENGTH_LONG).run {
|
|
||||||
setAction(R.string.button_more) { viewQksmsPlusIntent.onNext(Unit) }
|
|
||||||
show()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO change this to a PopupWindow
|
override fun onBackPressed() {
|
||||||
override fun showNightModeDialog() = nightModeDialog.show(this)
|
if (!router.handleBack()) {
|
||||||
|
super.onBackPressed()
|
||||||
override fun showStartTimePicker(hour: Int, minute: Int) {
|
}
|
||||||
TimePickerDialog(this, TimePickerDialog.OnTimeSetListener { _, newHour, newMinute ->
|
|
||||||
startTimeSelectedIntent.onNext(Pair(newHour, newMinute))
|
|
||||||
}, hour, minute, DateFormat.is24HourFormat(this)).show()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun showEndTimePicker(hour: Int, minute: Int) {
|
|
||||||
TimePickerDialog(this, TimePickerDialog.OnTimeSetListener { _, newHour, newMinute ->
|
|
||||||
endTimeSelectedIntent.onNext(Pair(newHour, newMinute))
|
|
||||||
}, hour, minute, DateFormat.is24HourFormat(this)).show()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun showTextSizePicker() = textSizeDialog.show(this)
|
|
||||||
|
|
||||||
override fun showDelayDurationDialog() = sendDelayDialog.show(this)
|
|
||||||
|
|
||||||
override fun showMmsSizePicker() = mmsSizeDialog.show(this)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.settings
|
|
||||||
|
|
||||||
import androidx.lifecycle.ViewModel
|
|
||||||
import com.moez.QKSMS.injection.ViewModelKey
|
|
||||||
import dagger.Module
|
|
||||||
import dagger.Provides
|
|
||||||
import dagger.multibindings.IntoMap
|
|
||||||
|
|
||||||
@Module
|
|
||||||
class SettingsActivityModule {
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
@IntoMap
|
|
||||||
@ViewModelKey(SettingsViewModel::class)
|
|
||||||
fun provideSettingsViewModel(viewModel: SettingsViewModel): ViewModel = viewModel
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,173 @@
|
|||||||
|
package com.moez.QKSMS.feature.settings
|
||||||
|
|
||||||
|
import android.app.ProgressDialog
|
||||||
|
import android.app.TimePickerDialog
|
||||||
|
import android.content.Context
|
||||||
|
import android.text.format.DateFormat
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import com.bluelinelabs.conductor.RouterTransaction
|
||||||
|
import com.bluelinelabs.conductor.changehandler.FadeChangeHandler
|
||||||
|
import com.google.android.material.snackbar.Snackbar
|
||||||
|
import com.jakewharton.rxbinding2.view.clicks
|
||||||
|
import com.moez.QKSMS.BuildConfig
|
||||||
|
import com.moez.QKSMS.R
|
||||||
|
import com.moez.QKSMS.common.QkDialog
|
||||||
|
import com.moez.QKSMS.common.base.QkController
|
||||||
|
import com.moez.QKSMS.common.util.Colors
|
||||||
|
import com.moez.QKSMS.common.util.extensions.animateLayoutChanges
|
||||||
|
import com.moez.QKSMS.common.util.extensions.setBackgroundTint
|
||||||
|
import com.moez.QKSMS.common.util.extensions.setVisible
|
||||||
|
import com.moez.QKSMS.common.widget.PreferenceView
|
||||||
|
import com.moez.QKSMS.feature.settings.about.AboutController
|
||||||
|
import com.moez.QKSMS.injection.appComponent
|
||||||
|
import com.moez.QKSMS.util.Preferences
|
||||||
|
import com.uber.autodispose.kotlin.autoDisposable
|
||||||
|
import io.reactivex.Observable
|
||||||
|
import io.reactivex.subjects.PublishSubject
|
||||||
|
import io.reactivex.subjects.Subject
|
||||||
|
import kotlinx.android.synthetic.main.settings_activity.view.*
|
||||||
|
import kotlinx.android.synthetic.main.settings_switch_widget.view.*
|
||||||
|
import kotlinx.android.synthetic.main.settings_theme_widget.view.*
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class SettingsController : QkController(), SettingsView {
|
||||||
|
|
||||||
|
@Inject lateinit var context: Context
|
||||||
|
@Inject lateinit var colors: Colors
|
||||||
|
@Inject lateinit var nightModeDialog: QkDialog
|
||||||
|
@Inject lateinit var textSizeDialog: QkDialog
|
||||||
|
@Inject lateinit var sendDelayDialog: QkDialog
|
||||||
|
@Inject lateinit var mmsSizeDialog: QkDialog
|
||||||
|
|
||||||
|
@Inject lateinit var presenter: SettingsPresenter
|
||||||
|
|
||||||
|
override val preferenceClickIntent: Subject<PreferenceView> = PublishSubject.create()
|
||||||
|
override val viewQksmsPlusIntent: Subject<Unit> = PublishSubject.create()
|
||||||
|
override val nightModeSelectedIntent by lazy { nightModeDialog.adapter.menuItemClicks }
|
||||||
|
override val startTimeSelectedIntent: Subject<Pair<Int, Int>> = PublishSubject.create()
|
||||||
|
override val endTimeSelectedIntent: Subject<Pair<Int, Int>> = PublishSubject.create()
|
||||||
|
override val textSizeSelectedIntent by lazy { textSizeDialog.adapter.menuItemClicks }
|
||||||
|
override val sendDelayChangedIntent by lazy { sendDelayDialog.adapter.menuItemClicks }
|
||||||
|
override val mmsSizeSelectedIntent: Subject<Int> by lazy { mmsSizeDialog.adapter.menuItemClicks }
|
||||||
|
|
||||||
|
// TODO remove this
|
||||||
|
private val progressDialog by lazy {
|
||||||
|
ProgressDialog(activity).apply {
|
||||||
|
isIndeterminate = true
|
||||||
|
setCancelable(false)
|
||||||
|
setCanceledOnTouchOutside(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
init {
|
||||||
|
appComponent.inject(this)
|
||||||
|
presenter.onCreate(this)
|
||||||
|
retainViewMode = RetainViewMode.RETAIN_DETACH
|
||||||
|
|
||||||
|
colors.themeObservable()
|
||||||
|
.autoDisposable(scope())
|
||||||
|
.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)
|
||||||
|
|
||||||
|
// Listen to clicks for all of the preferences
|
||||||
|
(0 until preferences.childCount)
|
||||||
|
.map { index -> preferences.getChildAt(index) }
|
||||||
|
.mapNotNull { view -> view as? PreferenceView }
|
||||||
|
.map { preference -> preference.clicks().map { preference } }
|
||||||
|
.let { preferences -> Observable.merge(preferences) }
|
||||||
|
.subscribe(preferenceClickIntent::onNext)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onAttach(view: View) {
|
||||||
|
super.onAttach(view)
|
||||||
|
presenter.onAttach(this)
|
||||||
|
setTitle(R.string.title_settings)
|
||||||
|
showBackButton(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun render(state: SettingsState) {
|
||||||
|
if (progressDialog.isShowing && !state.syncing) progressDialog.dismiss()
|
||||||
|
else if (!progressDialog.isShowing && state.syncing) progressDialog.show()
|
||||||
|
|
||||||
|
view?.run {
|
||||||
|
themePreview.setBackgroundTint(state.theme)
|
||||||
|
night.summary = state.nightModeSummary
|
||||||
|
nightModeDialog.adapter.selectedItem = state.nightModeId
|
||||||
|
nightStart.setVisible(state.nightModeId == Preferences.NIGHT_MODE_AUTO)
|
||||||
|
nightStart.summary = state.nightStart
|
||||||
|
nightEnd.setVisible(state.nightModeId == Preferences.NIGHT_MODE_AUTO)
|
||||||
|
nightEnd.summary = state.nightEnd
|
||||||
|
|
||||||
|
black.setVisible(state.nightModeId != Preferences.NIGHT_MODE_OFF)
|
||||||
|
black.checkbox.isChecked = state.black
|
||||||
|
|
||||||
|
autoEmoji.checkbox.isChecked = state.autoEmojiEnabled
|
||||||
|
|
||||||
|
delayed.summary = state.sendDelaySummary
|
||||||
|
sendDelayDialog.adapter.selectedItem = state.sendDelayId
|
||||||
|
|
||||||
|
delivery.checkbox.isChecked = state.deliveryEnabled
|
||||||
|
|
||||||
|
textSize.summary = state.textSizeSummary
|
||||||
|
textSizeDialog.adapter.selectedItem = state.textSizeId
|
||||||
|
systemFont.checkbox.isChecked = state.systemFontEnabled
|
||||||
|
|
||||||
|
unicode.checkbox.isChecked = state.stripUnicodeEnabled
|
||||||
|
|
||||||
|
mmsSize.summary = state.maxMmsSizeSummary
|
||||||
|
mmsSizeDialog.adapter.selectedItem = state.maxMmsSizeId
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun showQksmsPlusSnackbar() {
|
||||||
|
view?.run {
|
||||||
|
Snackbar.make(contentView, R.string.toast_qksms_plus, Snackbar.LENGTH_LONG).run {
|
||||||
|
setAction(R.string.button_more) { viewQksmsPlusIntent.onNext(Unit) }
|
||||||
|
show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO change this to a PopupWindow
|
||||||
|
override fun showNightModeDialog() = nightModeDialog.show(activity!!)
|
||||||
|
|
||||||
|
override fun showStartTimePicker(hour: Int, minute: Int) {
|
||||||
|
TimePickerDialog(activity, TimePickerDialog.OnTimeSetListener { _, newHour, newMinute ->
|
||||||
|
startTimeSelectedIntent.onNext(Pair(newHour, newMinute))
|
||||||
|
}, hour, minute, DateFormat.is24HourFormat(activity)).show()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun showEndTimePicker(hour: Int, minute: Int) {
|
||||||
|
TimePickerDialog(activity, TimePickerDialog.OnTimeSetListener { _, newHour, newMinute ->
|
||||||
|
endTimeSelectedIntent.onNext(Pair(newHour, newMinute))
|
||||||
|
}, hour, minute, DateFormat.is24HourFormat(activity)).show()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun showTextSizePicker() = textSizeDialog.show(activity!!)
|
||||||
|
|
||||||
|
override fun showDelayDurationDialog() = sendDelayDialog.show(activity!!)
|
||||||
|
|
||||||
|
override fun showMmsSizePicker() = mmsSizeDialog.show(activity!!)
|
||||||
|
|
||||||
|
override fun showAbout() {
|
||||||
|
router.pushController(RouterTransaction.with(AboutController())
|
||||||
|
.pushChangeHandler(FadeChangeHandler())
|
||||||
|
.popChangeHandler(FadeChangeHandler()))
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+31
-45
@@ -1,28 +1,9 @@
|
|||||||
/*
|
|
||||||
* 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.settings
|
package com.moez.QKSMS.feature.settings
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import com.moez.QKSMS.R
|
import com.moez.QKSMS.R
|
||||||
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.common.util.DateFormatter
|
import com.moez.QKSMS.common.util.DateFormatter
|
||||||
@@ -30,13 +11,12 @@ import com.moez.QKSMS.interactor.SyncMessages
|
|||||||
import com.moez.QKSMS.util.NightModeManager
|
import com.moez.QKSMS.util.NightModeManager
|
||||||
import com.moez.QKSMS.util.Preferences
|
import com.moez.QKSMS.util.Preferences
|
||||||
import com.uber.autodispose.kotlin.autoDisposable
|
import com.uber.autodispose.kotlin.autoDisposable
|
||||||
import io.reactivex.rxkotlin.plusAssign
|
|
||||||
import io.reactivex.rxkotlin.withLatestFrom
|
import io.reactivex.rxkotlin.withLatestFrom
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class SettingsViewModel @Inject constructor(
|
class SettingsPresenter @Inject constructor(
|
||||||
private val context: Context,
|
private val context: Context,
|
||||||
private val billingManager: BillingManager,
|
private val billingManager: BillingManager,
|
||||||
private val colors: Colors,
|
private val colors: Colors,
|
||||||
@@ -45,72 +25,77 @@ class SettingsViewModel @Inject constructor(
|
|||||||
private val nightModeManager: NightModeManager,
|
private val nightModeManager: NightModeManager,
|
||||||
private val prefs: Preferences,
|
private val prefs: Preferences,
|
||||||
private val syncMessages: SyncMessages
|
private val syncMessages: SyncMessages
|
||||||
) : QkViewModel<SettingsView, SettingsState>(SettingsState()) {
|
) : QkPresenter<SettingsView, SettingsState>(SettingsState(theme = colors.theme().theme)) {
|
||||||
|
|
||||||
|
override fun onCreate(view: SettingsView) {
|
||||||
init {
|
super.onCreate(view)
|
||||||
newState { copy(theme = colors.theme().theme) }
|
|
||||||
|
|
||||||
val nightModeLabels = context.resources.getStringArray(R.array.night_modes)
|
val nightModeLabels = context.resources.getStringArray(R.array.night_modes)
|
||||||
disposables += prefs.nightMode.asObservable()
|
prefs.nightMode.asObservable()
|
||||||
|
.autoDisposable(view.scope())
|
||||||
.subscribe { nightMode ->
|
.subscribe { nightMode ->
|
||||||
newState { copy(nightModeSummary = nightModeLabels[nightMode], nightModeId = nightMode) }
|
newState { copy(nightModeSummary = nightModeLabels[nightMode], nightModeId = nightMode) }
|
||||||
}
|
}
|
||||||
|
|
||||||
disposables += prefs.nightStart.asObservable()
|
prefs.nightStart.asObservable()
|
||||||
.map { time -> nightModeManager.parseTime(time) }
|
.map { time -> nightModeManager.parseTime(time) }
|
||||||
.map { calendar -> calendar.timeInMillis }
|
.map { calendar -> calendar.timeInMillis }
|
||||||
.map { millis -> dateFormatter.getTimestamp(millis) }
|
.map { millis -> dateFormatter.getTimestamp(millis) }
|
||||||
|
.autoDisposable(view.scope())
|
||||||
.subscribe { nightStart -> newState { copy(nightStart = nightStart) } }
|
.subscribe { nightStart -> newState { copy(nightStart = nightStart) } }
|
||||||
|
|
||||||
disposables += prefs.nightEnd.asObservable()
|
prefs.nightEnd.asObservable()
|
||||||
.map { time -> nightModeManager.parseTime(time) }
|
.map { time -> nightModeManager.parseTime(time) }
|
||||||
.map { calendar -> calendar.timeInMillis }
|
.map { calendar -> calendar.timeInMillis }
|
||||||
.map { millis -> dateFormatter.getTimestamp(millis) }
|
.map { millis -> dateFormatter.getTimestamp(millis) }
|
||||||
|
.autoDisposable(view.scope())
|
||||||
.subscribe { nightEnd -> newState { copy(nightEnd = nightEnd) } }
|
.subscribe { nightEnd -> newState { copy(nightEnd = nightEnd) } }
|
||||||
|
|
||||||
disposables += prefs.black.asObservable()
|
prefs.black.asObservable()
|
||||||
|
.autoDisposable(view.scope())
|
||||||
.subscribe { black -> newState { copy(black = black) } }
|
.subscribe { black -> newState { copy(black = black) } }
|
||||||
|
|
||||||
disposables += prefs.notifications().asObservable()
|
prefs.notifications().asObservable()
|
||||||
|
.autoDisposable(view.scope())
|
||||||
.subscribe { enabled -> newState { copy(notificationsEnabled = enabled) } }
|
.subscribe { enabled -> newState { copy(notificationsEnabled = enabled) } }
|
||||||
|
|
||||||
disposables += prefs.autoEmoji.asObservable()
|
prefs.autoEmoji.asObservable()
|
||||||
|
.autoDisposable(view.scope())
|
||||||
.subscribe { enabled -> newState { copy(autoEmojiEnabled = enabled) } }
|
.subscribe { enabled -> newState { copy(autoEmojiEnabled = enabled) } }
|
||||||
|
|
||||||
val delayedSendingLabels = context.resources.getStringArray(R.array.delayed_sending_labels)
|
val delayedSendingLabels = context.resources.getStringArray(R.array.delayed_sending_labels)
|
||||||
disposables += prefs.sendDelay.asObservable()
|
prefs.sendDelay.asObservable()
|
||||||
|
.autoDisposable(view.scope())
|
||||||
.subscribe { id -> newState { copy(sendDelaySummary = delayedSendingLabels[id], sendDelayId = id) } }
|
.subscribe { id -> newState { copy(sendDelaySummary = delayedSendingLabels[id], sendDelayId = id) } }
|
||||||
|
|
||||||
disposables += prefs.delivery.asObservable()
|
prefs.delivery.asObservable()
|
||||||
|
.autoDisposable(view.scope())
|
||||||
.subscribe { enabled -> newState { copy(deliveryEnabled = enabled) } }
|
.subscribe { enabled -> newState { copy(deliveryEnabled = enabled) } }
|
||||||
|
|
||||||
val textSizeLabels = context.resources.getStringArray(R.array.text_sizes)
|
val textSizeLabels = context.resources.getStringArray(R.array.text_sizes)
|
||||||
disposables += prefs.textSize.asObservable()
|
prefs.textSize.asObservable()
|
||||||
|
.autoDisposable(view.scope())
|
||||||
.subscribe { textSize ->
|
.subscribe { textSize ->
|
||||||
newState { copy(textSizeSummary = textSizeLabels[textSize], textSizeId = textSize) }
|
newState { copy(textSizeSummary = textSizeLabels[textSize], textSizeId = textSize) }
|
||||||
}
|
}
|
||||||
|
|
||||||
disposables += prefs.systemFont.asObservable()
|
prefs.systemFont.asObservable()
|
||||||
|
.autoDisposable(view.scope())
|
||||||
.subscribe { enabled -> newState { copy(systemFontEnabled = enabled) } }
|
.subscribe { enabled -> newState { copy(systemFontEnabled = enabled) } }
|
||||||
|
|
||||||
disposables += prefs.unicode.asObservable()
|
prefs.unicode.asObservable()
|
||||||
|
.autoDisposable(view.scope())
|
||||||
.subscribe { enabled -> newState { copy(stripUnicodeEnabled = enabled) } }
|
.subscribe { enabled -> newState { copy(stripUnicodeEnabled = enabled) } }
|
||||||
|
|
||||||
val mmsSizeLabels = context.resources.getStringArray(R.array.mms_sizes)
|
val mmsSizeLabels = context.resources.getStringArray(R.array.mms_sizes)
|
||||||
val mmsSizeIds = context.resources.getIntArray(R.array.mms_sizes_ids)
|
val mmsSizeIds = context.resources.getIntArray(R.array.mms_sizes_ids)
|
||||||
disposables += prefs.mmsSize.asObservable()
|
prefs.mmsSize.asObservable()
|
||||||
|
.autoDisposable(view.scope())
|
||||||
.subscribe { maxMmsSize ->
|
.subscribe { maxMmsSize ->
|
||||||
val index = mmsSizeIds.indexOf(maxMmsSize)
|
val index = mmsSizeIds.indexOf(maxMmsSize)
|
||||||
newState { copy(maxMmsSizeSummary = mmsSizeLabels[index], maxMmsSizeId = maxMmsSize) }
|
newState { copy(maxMmsSizeSummary = mmsSizeLabels[index], maxMmsSizeId = maxMmsSize) }
|
||||||
}
|
}
|
||||||
|
|
||||||
disposables += syncMessages
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun bindView(view: SettingsView) {
|
|
||||||
super.bindView(view)
|
|
||||||
|
|
||||||
view.preferenceClickIntent
|
view.preferenceClickIntent
|
||||||
.autoDisposable(view.scope())
|
.autoDisposable(view.scope())
|
||||||
.subscribe {
|
.subscribe {
|
||||||
@@ -156,7 +141,7 @@ class SettingsViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
R.id.about -> navigator.showAbout()
|
R.id.about -> view.showAbout()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -202,4 +187,5 @@ class SettingsViewModel @Inject constructor(
|
|||||||
.autoDisposable(view.scope())
|
.autoDisposable(view.scope())
|
||||||
.subscribe { prefs.mmsSize.set(it) }
|
.subscribe { prefs.mmsSize.set(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -18,12 +18,12 @@
|
|||||||
*/
|
*/
|
||||||
package com.moez.QKSMS.feature.settings
|
package com.moez.QKSMS.feature.settings
|
||||||
|
|
||||||
import com.moez.QKSMS.common.base.QkView
|
import com.moez.QKSMS.common.base.QkConductorView
|
||||||
import com.moez.QKSMS.common.widget.PreferenceView
|
import com.moez.QKSMS.common.widget.PreferenceView
|
||||||
import io.reactivex.Observable
|
import io.reactivex.Observable
|
||||||
import io.reactivex.subjects.Subject
|
import io.reactivex.subjects.Subject
|
||||||
|
|
||||||
interface SettingsView : QkView<SettingsState> {
|
interface SettingsView : QkConductorView<SettingsState> {
|
||||||
|
|
||||||
val preferenceClickIntent: Subject<PreferenceView>
|
val preferenceClickIntent: Subject<PreferenceView>
|
||||||
val viewQksmsPlusIntent: Subject<Unit>
|
val viewQksmsPlusIntent: Subject<Unit>
|
||||||
@@ -41,4 +41,5 @@ interface SettingsView : QkView<SettingsState> {
|
|||||||
fun showTextSizePicker()
|
fun showTextSizePicker()
|
||||||
fun showDelayDurationDialog()
|
fun showDelayDurationDialog()
|
||||||
fun showMmsSizePicker()
|
fun showMmsSizePicker()
|
||||||
|
fun showAbout()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,67 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.settings.about
|
|
||||||
|
|
||||||
import android.os.Bundle
|
|
||||||
import androidx.lifecycle.ViewModelProvider
|
|
||||||
import androidx.lifecycle.ViewModelProviders
|
|
||||||
import com.jakewharton.rxbinding2.view.clicks
|
|
||||||
import com.moez.QKSMS.BuildConfig
|
|
||||||
import com.moez.QKSMS.R
|
|
||||||
import com.moez.QKSMS.common.base.QkThemedActivity
|
|
||||||
import com.moez.QKSMS.common.widget.PreferenceView
|
|
||||||
import dagger.android.AndroidInjection
|
|
||||||
import io.reactivex.subjects.PublishSubject
|
|
||||||
import io.reactivex.subjects.Subject
|
|
||||||
import kotlinx.android.synthetic.main.about_activity.*
|
|
||||||
import javax.inject.Inject
|
|
||||||
|
|
||||||
class AboutActivity : QkThemedActivity(), AboutView {
|
|
||||||
|
|
||||||
@Inject lateinit var viewModelFactory: ViewModelProvider.Factory
|
|
||||||
|
|
||||||
override val preferenceClickIntent: Subject<PreferenceView> = PublishSubject.create()
|
|
||||||
|
|
||||||
private val viewModel by lazy { ViewModelProviders.of(this, viewModelFactory)[AboutViewModel::class.java] }
|
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
|
||||||
AndroidInjection.inject(this)
|
|
||||||
super.onCreate(savedInstanceState)
|
|
||||||
setContentView(R.layout.about_activity)
|
|
||||||
setTitle(R.string.about_title)
|
|
||||||
showBackButton(true)
|
|
||||||
viewModel.bindView(this)
|
|
||||||
|
|
||||||
version.summary = BuildConfig.VERSION_NAME
|
|
||||||
|
|
||||||
// Listen to clicks for all of the preferences
|
|
||||||
(0 until preferences.childCount)
|
|
||||||
.map { index -> preferences.getChildAt(index) }
|
|
||||||
.mapNotNull { view -> view as? PreferenceView }
|
|
||||||
.forEach { preference ->
|
|
||||||
preference.clicks().map { preference }.subscribe(preferenceClickIntent)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun render(state: Unit) {
|
|
||||||
// No special rendering required
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
-35
@@ -1,35 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.settings.about
|
|
||||||
|
|
||||||
import androidx.lifecycle.ViewModel
|
|
||||||
import com.moez.QKSMS.injection.ViewModelKey
|
|
||||||
import dagger.Module
|
|
||||||
import dagger.Provides
|
|
||||||
import dagger.multibindings.IntoMap
|
|
||||||
|
|
||||||
@Module
|
|
||||||
class AboutActivityModule {
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
@IntoMap
|
|
||||||
@ViewModelKey(AboutViewModel::class)
|
|
||||||
fun provideAboutViewModel(viewModel: AboutViewModel): ViewModel = viewModel
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
package com.moez.QKSMS.feature.settings.about
|
||||||
|
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import com.jakewharton.rxbinding2.view.clicks
|
||||||
|
import com.moez.QKSMS.BuildConfig
|
||||||
|
import com.moez.QKSMS.R
|
||||||
|
import com.moez.QKSMS.common.base.QkController
|
||||||
|
import com.moez.QKSMS.common.widget.PreferenceView
|
||||||
|
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.about_activity.view.*
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class AboutController : QkController(), AboutView {
|
||||||
|
|
||||||
|
@Inject lateinit var presenter: AboutPresenter
|
||||||
|
|
||||||
|
override val preferenceClickIntent: Subject<PreferenceView> = PublishSubject.create()
|
||||||
|
|
||||||
|
init {
|
||||||
|
appComponent.inject(this)
|
||||||
|
presenter.onCreate(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup): View {
|
||||||
|
return inflater.inflate(R.layout.about_activity, container, false).apply {
|
||||||
|
version.summary = BuildConfig.VERSION_NAME
|
||||||
|
|
||||||
|
// Listen to clicks for all of the preferences
|
||||||
|
(0 until preferences.childCount)
|
||||||
|
.map { index -> preferences.getChildAt(index) }
|
||||||
|
.mapNotNull { view -> view as? PreferenceView }
|
||||||
|
.map { preference -> preference.clicks().map { preference } }
|
||||||
|
.let { preferences -> Observable.merge(preferences) }
|
||||||
|
.subscribe(preferenceClickIntent::onNext)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onAttach(view: View) {
|
||||||
|
super.onAttach(view)
|
||||||
|
presenter.onAttach(this)
|
||||||
|
setTitle(R.string.about_title)
|
||||||
|
showBackButton(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun render(state: Unit) {
|
||||||
|
// No special rendering required
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
+5
-6
@@ -20,17 +20,16 @@ package com.moez.QKSMS.feature.settings.about
|
|||||||
|
|
||||||
import com.moez.QKSMS.R
|
import com.moez.QKSMS.R
|
||||||
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.uber.autodispose.kotlin.autoDisposable
|
import com.uber.autodispose.kotlin.autoDisposable
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class AboutViewModel @Inject constructor(
|
class AboutPresenter @Inject constructor(
|
||||||
private val navigator: Navigator
|
private val navigator: Navigator
|
||||||
) : QkViewModel<AboutView, Unit>(Unit) {
|
) : QkPresenter<AboutView, Unit>(Unit) {
|
||||||
|
|
||||||
override fun bindView(view: AboutView) {
|
override fun onCreate(view: AboutView) {
|
||||||
super.bindView(view)
|
super.onCreate(view)
|
||||||
|
|
||||||
view.preferenceClickIntent
|
view.preferenceClickIntent
|
||||||
.autoDisposable(view.scope())
|
.autoDisposable(view.scope())
|
||||||
@@ -18,11 +18,11 @@
|
|||||||
*/
|
*/
|
||||||
package com.moez.QKSMS.feature.settings.about
|
package com.moez.QKSMS.feature.settings.about
|
||||||
|
|
||||||
import com.moez.QKSMS.common.base.QkView
|
import com.moez.QKSMS.common.base.QkConductorView
|
||||||
import com.moez.QKSMS.common.widget.PreferenceView
|
import com.moez.QKSMS.common.widget.PreferenceView
|
||||||
import io.reactivex.subjects.Subject
|
import io.reactivex.subjects.Subject
|
||||||
|
|
||||||
interface AboutView : QkView<Unit> {
|
interface AboutView : QkConductorView<Unit> {
|
||||||
|
|
||||||
val preferenceClickIntent: Subject<PreferenceView>
|
val preferenceClickIntent: Subject<PreferenceView>
|
||||||
|
|
||||||
|
|||||||
@@ -37,9 +37,6 @@ import com.moez.QKSMS.feature.qkreply.QkReplyActivityModule
|
|||||||
import com.moez.QKSMS.feature.scheduled.ScheduledActivity
|
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.settings.SettingsActivityModule
|
|
||||||
import com.moez.QKSMS.feature.settings.about.AboutActivity
|
|
||||||
import com.moez.QKSMS.feature.settings.about.AboutActivityModule
|
|
||||||
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.feature.themepicker.ThemePickerActivityModule
|
||||||
import dagger.Module
|
import dagger.Module
|
||||||
@@ -56,10 +53,6 @@ abstract class ActivityBuilderModule {
|
|||||||
@ContributesAndroidInjector(modules = [PlusActivityModule::class])
|
@ContributesAndroidInjector(modules = [PlusActivityModule::class])
|
||||||
abstract fun bindPlusActivity(): PlusActivity
|
abstract fun bindPlusActivity(): PlusActivity
|
||||||
|
|
||||||
@ActivityScope
|
|
||||||
@ContributesAndroidInjector(modules = [AboutActivityModule::class])
|
|
||||||
abstract fun bindAboutActivity(): AboutActivity
|
|
||||||
|
|
||||||
@ActivityScope
|
@ActivityScope
|
||||||
@ContributesAndroidInjector(modules = [ComposeActivityModule::class])
|
@ContributesAndroidInjector(modules = [ComposeActivityModule::class])
|
||||||
abstract fun bindComposeActivity(): ComposeActivity
|
abstract fun bindComposeActivity(): ComposeActivity
|
||||||
@@ -85,7 +78,7 @@ abstract class ActivityBuilderModule {
|
|||||||
abstract fun bindScheduledActivity(): ScheduledActivity
|
abstract fun bindScheduledActivity(): ScheduledActivity
|
||||||
|
|
||||||
@ActivityScope
|
@ActivityScope
|
||||||
@ContributesAndroidInjector(modules = [SettingsActivityModule::class])
|
@ContributesAndroidInjector(modules = [])
|
||||||
abstract fun bindSettingsActivity(): SettingsActivity
|
abstract fun bindSettingsActivity(): SettingsActivity
|
||||||
|
|
||||||
@ActivityScope
|
@ActivityScope
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ import com.moez.QKSMS.common.widget.QkEditText
|
|||||||
import com.moez.QKSMS.common.widget.QkSwitch
|
import com.moez.QKSMS.common.widget.QkSwitch
|
||||||
import com.moez.QKSMS.common.widget.QkTextView
|
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.about.AboutController
|
||||||
import com.moez.QKSMS.feature.widget.WidgetAdapter
|
import com.moez.QKSMS.feature.widget.WidgetAdapter
|
||||||
import com.moez.QKSMS.util.ContactImageLoader
|
import com.moez.QKSMS.util.ContactImageLoader
|
||||||
import dagger.Component
|
import dagger.Component
|
||||||
@@ -44,6 +46,9 @@ interface AppComponent {
|
|||||||
|
|
||||||
fun inject(application: QKApplication)
|
fun inject(application: QKApplication)
|
||||||
|
|
||||||
|
fun inject(controller: AboutController)
|
||||||
|
fun inject(controller: SettingsController)
|
||||||
|
|
||||||
fun inject(dialog: QkDialog)
|
fun inject(dialog: QkDialog)
|
||||||
|
|
||||||
fun inject(fetcher: ContactImageLoader.ContactImageFetcher)
|
fun inject(fetcher: ContactImageLoader.ContactImageFetcher)
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<com.bluelinelabs.conductor.ChangeHandlerFrameLayout
|
||||||
|
android:id="@+id/container"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent" />
|
||||||
|
|
||||||
|
</FrameLayout>
|
||||||
Reference in New Issue
Block a user