forked from upstream-mirrors/quik
Move packages to com.moez.QKSMS
This commit is contained in:
@@ -0,0 +1,169 @@
|
||||
/*
|
||||
* 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 android.app.ProgressDialog
|
||||
import android.app.TimePickerDialog
|
||||
import android.arch.lifecycle.ViewModelProvider
|
||||
import android.arch.lifecycle.ViewModelProviders
|
||||
import android.os.Bundle
|
||||
import android.support.design.widget.Snackbar
|
||||
import android.text.format.DateFormat
|
||||
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.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.android.lifecycle.scope
|
||||
import com.uber.autodispose.kotlin.autoDisposable
|
||||
import dagger.android.AndroidInjection
|
||||
import io.reactivex.subjects.PublishSubject
|
||||
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 {
|
||||
|
||||
@Inject lateinit var nightModeDialog: QkDialog
|
||||
@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?) {
|
||||
AndroidInjection.inject(this)
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.settings_activity)
|
||||
setTitle(R.string.title_settings)
|
||||
showBackButton(true)
|
||||
viewModel.bindView(this)
|
||||
|
||||
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 = 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 showNightModeDialog() = nightModeDialog.show(this)
|
||||
|
||||
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)
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.moez.QKSMS.feature.settings
|
||||
|
||||
import android.arch.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,43 @@
|
||||
/*
|
||||
* 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 com.moez.QKSMS.util.Preferences
|
||||
|
||||
data class SettingsState(
|
||||
val syncing: Boolean = false,
|
||||
val theme: Int = 0,
|
||||
val nightModeSummary: String = "",
|
||||
val nightModeId: Int = Preferences.NIGHT_MODE_OFF,
|
||||
val nightStart: String = "",
|
||||
val nightEnd: String = "",
|
||||
val black: Boolean = false,
|
||||
val autoEmojiEnabled: Boolean = true,
|
||||
val notificationsEnabled: Boolean = true,
|
||||
val sendDelaySummary: String = "",
|
||||
val sendDelayId: Int = 0,
|
||||
val deliveryEnabled: Boolean = false,
|
||||
val textSizeSummary: String = "",
|
||||
val textSizeId: Int = Preferences.TEXT_SIZE_NORMAL,
|
||||
val systemFontEnabled: Boolean = false,
|
||||
val splitSmsEnabled: Boolean = false,
|
||||
val stripUnicodeEnabled: Boolean = false,
|
||||
val maxMmsSizeSummary: String = "100KB",
|
||||
val maxMmsSizeId: Int = 100
|
||||
)
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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 com.moez.QKSMS.common.base.QkView
|
||||
import com.moez.QKSMS.common.widget.PreferenceView
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.subjects.Subject
|
||||
|
||||
interface SettingsView : QkView<SettingsState> {
|
||||
|
||||
val preferenceClickIntent: Subject<PreferenceView>
|
||||
val viewQksmsPlusIntent: Subject<Unit>
|
||||
val nightModeSelectedIntent: Observable<Int>
|
||||
val startTimeSelectedIntent: Subject<Pair<Int, Int>>
|
||||
val endTimeSelectedIntent: Subject<Pair<Int, Int>>
|
||||
val textSizeSelectedIntent: Subject<Int>
|
||||
val sendDelayChangedIntent: Observable<Int>
|
||||
val mmsSizeSelectedIntent: Observable<Int>
|
||||
|
||||
fun showQksmsPlusSnackbar()
|
||||
fun showNightModeDialog()
|
||||
fun showStartTimePicker(hour: Int, minute: Int)
|
||||
fun showEndTimePicker(hour: Int, minute: Int)
|
||||
fun showTextSizePicker()
|
||||
fun showDelayDurationDialog()
|
||||
fun showMmsSizePicker()
|
||||
}
|
||||
@@ -0,0 +1,207 @@
|
||||
/*
|
||||
* 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 android.content.Context
|
||||
import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.common.Navigator
|
||||
import com.moez.QKSMS.common.base.QkViewModel
|
||||
import com.moez.QKSMS.common.util.BillingManager
|
||||
import com.moez.QKSMS.common.util.Colors
|
||||
import com.moez.QKSMS.common.util.DateFormatter
|
||||
import com.moez.QKSMS.interactor.SyncMessages
|
||||
import com.moez.QKSMS.util.NightModeManager
|
||||
import com.moez.QKSMS.util.Preferences
|
||||
import com.uber.autodispose.android.lifecycle.scope
|
||||
import com.uber.autodispose.kotlin.autoDisposable
|
||||
import io.reactivex.rxkotlin.plusAssign
|
||||
import io.reactivex.rxkotlin.withLatestFrom
|
||||
import timber.log.Timber
|
||||
import java.util.*
|
||||
import javax.inject.Inject
|
||||
|
||||
class SettingsViewModel @Inject constructor(
|
||||
private val context: Context,
|
||||
private val billingManager: BillingManager,
|
||||
private val colors: Colors,
|
||||
private val dateFormatter: DateFormatter,
|
||||
private val navigator: Navigator,
|
||||
private val nightModeManager: NightModeManager,
|
||||
private val prefs: Preferences,
|
||||
private val syncMessages: SyncMessages
|
||||
) : QkViewModel<SettingsView, SettingsState>(SettingsState()) {
|
||||
|
||||
|
||||
init {
|
||||
newState { copy(theme = colors.theme().theme) }
|
||||
|
||||
val nightModeLabels = context.resources.getStringArray(R.array.night_modes)
|
||||
disposables += prefs.nightMode.asObservable()
|
||||
.subscribe { nightMode ->
|
||||
newState { copy(nightModeSummary = nightModeLabels[nightMode], nightModeId = nightMode) }
|
||||
}
|
||||
|
||||
disposables += prefs.nightStart.asObservable()
|
||||
.map { time -> nightModeManager.parseTime(time) }
|
||||
.map { calendar -> calendar.timeInMillis }
|
||||
.map { millis -> dateFormatter.getTimestamp(millis) }
|
||||
.subscribe { nightStart -> newState { copy(nightStart = nightStart) } }
|
||||
|
||||
disposables += prefs.nightEnd.asObservable()
|
||||
.map { time -> nightModeManager.parseTime(time) }
|
||||
.map { calendar -> calendar.timeInMillis }
|
||||
.map { millis -> dateFormatter.getTimestamp(millis) }
|
||||
.subscribe { nightEnd -> newState { copy(nightEnd = nightEnd) } }
|
||||
|
||||
disposables += prefs.black.asObservable()
|
||||
.subscribe { black -> newState { copy(black = black) } }
|
||||
|
||||
disposables += prefs.notifications().asObservable()
|
||||
.subscribe { enabled -> newState { copy(notificationsEnabled = enabled) } }
|
||||
|
||||
disposables += prefs.autoEmoji.asObservable()
|
||||
.subscribe { enabled -> newState { copy(autoEmojiEnabled = enabled) } }
|
||||
|
||||
val delayedSendingLabels = context.resources.getStringArray(R.array.delayed_sending_labels)
|
||||
disposables += prefs.sendDelay.asObservable()
|
||||
.subscribe { id -> newState { copy(sendDelaySummary = delayedSendingLabels[id], sendDelayId = id) } }
|
||||
|
||||
disposables += prefs.delivery.asObservable()
|
||||
.subscribe { enabled -> newState { copy(deliveryEnabled = enabled) } }
|
||||
|
||||
val textSizeLabels = context.resources.getStringArray(R.array.text_sizes)
|
||||
disposables += prefs.textSize.asObservable()
|
||||
.subscribe { textSize ->
|
||||
newState { copy(textSizeSummary = textSizeLabels[textSize], textSizeId = textSize) }
|
||||
}
|
||||
|
||||
disposables += prefs.systemFont.asObservable()
|
||||
.subscribe { enabled -> newState { copy(systemFontEnabled = enabled) } }
|
||||
|
||||
disposables += prefs.unicode.asObservable()
|
||||
.subscribe { enabled -> newState { copy(stripUnicodeEnabled = enabled) } }
|
||||
|
||||
val mmsSizeLabels = context.resources.getStringArray(R.array.mms_sizes)
|
||||
val mmsSizeIds = context.resources.getIntArray(R.array.mms_sizes_ids)
|
||||
disposables += prefs.mmsSize.asObservable()
|
||||
.subscribe { maxMmsSize ->
|
||||
val index = mmsSizeIds.indexOf(maxMmsSize)
|
||||
newState { copy(maxMmsSizeSummary = mmsSizeLabels[index], maxMmsSizeId = maxMmsSize) }
|
||||
}
|
||||
|
||||
disposables += syncMessages
|
||||
}
|
||||
|
||||
override fun bindView(view: SettingsView) {
|
||||
super.bindView(view)
|
||||
|
||||
view.preferenceClickIntent
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe {
|
||||
Timber.v("Preference click: ${context.resources.getResourceName(it.id)}")
|
||||
|
||||
when (it.id) {
|
||||
R.id.theme -> navigator.showThemePicker()
|
||||
|
||||
R.id.night -> view.showNightModeDialog()
|
||||
|
||||
R.id.nightStart -> {
|
||||
val date = nightModeManager.parseTime(prefs.nightStart.get())
|
||||
view.showStartTimePicker(date.get(Calendar.HOUR_OF_DAY), date.get(Calendar.MINUTE))
|
||||
}
|
||||
|
||||
R.id.nightEnd -> {
|
||||
val date = nightModeManager.parseTime(prefs.nightEnd.get())
|
||||
view.showEndTimePicker(date.get(Calendar.HOUR_OF_DAY), date.get(Calendar.MINUTE))
|
||||
}
|
||||
|
||||
R.id.black -> prefs.black.set(!prefs.black.get())
|
||||
|
||||
R.id.autoEmoji -> prefs.autoEmoji.set(!prefs.autoEmoji.get())
|
||||
|
||||
R.id.notifications -> navigator.showNotificationSettings()
|
||||
|
||||
R.id.blocked -> navigator.showBlockedConversations()
|
||||
|
||||
R.id.delayed -> view.showDelayDurationDialog()
|
||||
|
||||
R.id.delivery -> prefs.delivery.set(!prefs.delivery.get())
|
||||
|
||||
R.id.textSize -> view.showTextSizePicker()
|
||||
|
||||
R.id.systemFont -> prefs.systemFont.set(!prefs.systemFont.get())
|
||||
|
||||
R.id.unicode -> prefs.unicode.set(!prefs.unicode.get())
|
||||
|
||||
R.id.mmsSize -> view.showMmsSizePicker()
|
||||
|
||||
R.id.sync -> {
|
||||
newState { copy(syncing = true) }
|
||||
syncMessages.execute(Unit, {
|
||||
newState { copy(syncing = false) }
|
||||
})
|
||||
}
|
||||
|
||||
R.id.about -> navigator.showAbout()
|
||||
}
|
||||
}
|
||||
|
||||
view.nightModeSelectedIntent
|
||||
.withLatestFrom(billingManager.upgradeStatus, { mode, upgraded ->
|
||||
if (!upgraded && mode == Preferences.NIGHT_MODE_AUTO) {
|
||||
view.showQksmsPlusSnackbar()
|
||||
} else {
|
||||
nightModeManager.updateNightMode(mode)
|
||||
}
|
||||
})
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
|
||||
view.viewQksmsPlusIntent
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { navigator.showQksmsPlusActivity() }
|
||||
|
||||
view.startTimeSelectedIntent
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { nightModeManager.setNightStart(it.first, it.second) }
|
||||
|
||||
view.endTimeSelectedIntent
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { nightModeManager.setNightEnd(it.first, it.second) }
|
||||
|
||||
view.textSizeSelectedIntent
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { prefs.textSize.set(it) }
|
||||
|
||||
view.sendDelayChangedIntent
|
||||
.withLatestFrom(billingManager.upgradeStatus, { duration, upgraded ->
|
||||
if (!upgraded && duration != 0) {
|
||||
view.showQksmsPlusSnackbar()
|
||||
} else {
|
||||
prefs.sendDelay.set(duration)
|
||||
}
|
||||
})
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe()
|
||||
|
||||
view.mmsSizeSelectedIntent
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { prefs.mmsSize.set(it) }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.moez.QKSMS.feature.settings.about
|
||||
|
||||
import android.arch.lifecycle.ViewModelProvider
|
||||
import android.arch.lifecycle.ViewModelProviders
|
||||
import android.os.Bundle
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package com.moez.QKSMS.feature.settings.about
|
||||
|
||||
import android.arch.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,11 @@
|
||||
package com.moez.QKSMS.feature.settings.about
|
||||
|
||||
import com.moez.QKSMS.common.base.QkView
|
||||
import com.moez.QKSMS.common.widget.PreferenceView
|
||||
import io.reactivex.subjects.Subject
|
||||
|
||||
interface AboutView : QkView<Unit> {
|
||||
|
||||
val preferenceClickIntent: Subject<PreferenceView>
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.moez.QKSMS.feature.settings.about
|
||||
|
||||
import com.moez.QKSMS.R
|
||||
import com.moez.QKSMS.common.Navigator
|
||||
import com.moez.QKSMS.common.base.QkViewModel
|
||||
import com.uber.autodispose.android.lifecycle.scope
|
||||
import com.uber.autodispose.kotlin.autoDisposable
|
||||
import javax.inject.Inject
|
||||
|
||||
class AboutViewModel @Inject constructor(
|
||||
private val navigator: Navigator
|
||||
) : QkViewModel<AboutView, Unit>(Unit) {
|
||||
|
||||
override fun bindView(view: AboutView) {
|
||||
super.bindView(view)
|
||||
|
||||
view.preferenceClickIntent
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { preference ->
|
||||
when (preference.id) {
|
||||
R.id.developer -> navigator.showDeveloper()
|
||||
|
||||
R.id.source -> navigator.showSourceCode()
|
||||
|
||||
R.id.changelog -> navigator.showChangelog()
|
||||
|
||||
R.id.contact -> navigator.showSupport()
|
||||
|
||||
R.id.license -> navigator.showLicense()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user