Add preference for auto-delete

This commit is contained in:
Moez Bhatti
2020-12-20 23:51:01 -05:00
parent df181caf9e
commit 0cfca58350
13 changed files with 157 additions and 15 deletions
@@ -22,11 +22,11 @@ import android.app.Activity
import android.content.DialogInterface
import androidx.appcompat.app.AlertDialog
import com.moez.QKSMS.R
import com.moez.QKSMS.databinding.FieldDialogBinding
import com.moez.QKSMS.databinding.TextInputDialogBinding
class FieldDialog(context: Activity, hint: String, listener: (String) -> Unit) : AlertDialog(context) {
class TextInputDialog(context: Activity, hint: String, listener: (String) -> Unit) : AlertDialog(context) {
private val binding = FieldDialogBinding.inflate(context.layoutInflater)
private val binding = TextInputDialogBinding.inflate(context.layoutInflater)
init {
binding.field.hint = hint
@@ -39,7 +39,7 @@ class FieldDialog(context: Activity, hint: String, listener: (String) -> Unit) :
}
}
fun setText(text: String): FieldDialog {
fun setText(text: String): TextInputDialog {
binding.field.setText(text)
return this
}
@@ -27,7 +27,7 @@ import com.moez.QKSMS.common.Navigator
import com.moez.QKSMS.common.QkChangeHandler
import com.moez.QKSMS.common.base.QkController
import com.moez.QKSMS.common.util.extensions.scrapViews
import com.moez.QKSMS.common.widget.FieldDialog
import com.moez.QKSMS.common.widget.TextInputDialog
import com.moez.QKSMS.databinding.ConversationInfoControllerBinding
import com.moez.QKSMS.feature.blocking.BlockingDialog
import com.moez.QKSMS.feature.conversationinfo.injection.ConversationInfoModule
@@ -50,8 +50,8 @@ class ConversationInfoController(
@Inject lateinit var navigator: Navigator
@Inject lateinit var adapter: ConversationInfoAdapter
private val nameDialog: FieldDialog by lazy {
FieldDialog(activity!!, activity!!.getString(R.string.info_name), nameChangeSubject::onNext)
private val nameDialog: TextInputDialog by lazy {
TextInputDialog(activity!!, activity!!.getString(R.string.info_name), nameChangeSubject::onNext)
}
private val nameChangeSubject: Subject<String> = PublishSubject.create()
@@ -39,11 +39,12 @@ 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.FieldDialog
import com.moez.QKSMS.common.widget.TextInputDialog
import com.moez.QKSMS.common.widget.PreferenceView
import com.moez.QKSMS.common.widget.QkSwitch
import com.moez.QKSMS.databinding.SettingsControllerBinding
import com.moez.QKSMS.feature.settings.about.AboutController
import com.moez.QKSMS.feature.settings.autodelete.AutoDeleteDialog
import com.moez.QKSMS.feature.settings.swipe.SwipeActionsController
import com.moez.QKSMS.feature.themepicker.ThemePickerController
import com.moez.QKSMS.injection.appComponent
@@ -69,14 +70,18 @@ class SettingsController : QkController<SettingsView, SettingsState, SettingsPre
@Inject override lateinit var presenter: SettingsPresenter
private val signatureDialog: FieldDialog by lazy {
FieldDialog(activity!!, context.getString(R.string.settings_signature_title), signatureSubject::onNext)
private val signatureDialog: TextInputDialog by lazy {
TextInputDialog(activity!!, context.getString(R.string.settings_signature_title), signatureSubject::onNext)
}
private val autoDeleteDialog: AutoDeleteDialog by lazy {
AutoDeleteDialog(activity!!, autoDeleteSubject::onNext)
}
private val viewQksmsPlusSubject: Subject<Unit> = PublishSubject.create()
private val startTimeSelectedSubject: Subject<Pair<Int, Int>> = PublishSubject.create()
private val endTimeSelectedSubject: Subject<Pair<Int, Int>> = PublishSubject.create()
private val signatureSubject: Subject<String> = PublishSubject.create()
private val autoDeleteSubject: Subject<Int> = PublishSubject.create()
private val progressAnimator by lazy { ObjectAnimator.ofInt(binding.syncingProgress, "progress", 0, 0) }
@@ -132,7 +137,9 @@ class SettingsController : QkController<SettingsView, SettingsState, SettingsPre
override fun sendDelaySelected(): Observable<Int> = sendDelayDialog.adapter.menuItemClicks
override fun signatureSet(): Observable<String> = signatureSubject
override fun signatureChanged(): Observable<String> = signatureSubject
override fun autoDeleteChanged(): Observable<Int> = autoDeleteSubject
override fun mmsSizeSelected(): Observable<Int> = mmsSizeDialog.adapter.menuItemClicks
@@ -167,6 +174,13 @@ class SettingsController : QkController<SettingsView, SettingsState, SettingsPre
binding.unicode.widget<QkSwitch>().isChecked = state.stripUnicodeEnabled
binding.mobileOnly.widget<QkSwitch>().isChecked = state.mobileOnly
binding.autoDelete.summary = when (state.autoDelete) {
0 -> context.getString(R.string.settings_auto_delete_never)
else -> context.resources.getQuantityString(
R.plurals.settings_auto_delete_summary, state.autoDelete, state.autoDelete)
}
binding.longAsMms.widget<QkSwitch>().isChecked = state.longAsMms
binding.mmsSize.summary = state.maxMmsSizeSummary
@@ -198,13 +212,13 @@ class SettingsController : QkController<SettingsView, SettingsState, SettingsPre
override fun showNightModeDialog() = nightModeDialog.show(activity!!)
override fun showStartTimePicker(hour: Int, minute: Int) {
TimePickerDialog(activity, TimePickerDialog.OnTimeSetListener { _, newHour, newMinute ->
TimePickerDialog(activity, { _, newHour, newMinute ->
startTimeSelectedSubject.onNext(Pair(newHour, newMinute))
}, hour, minute, DateFormat.is24HourFormat(activity)).show()
}
override fun showEndTimePicker(hour: Int, minute: Int) {
TimePickerDialog(activity, TimePickerDialog.OnTimeSetListener { _, newHour, newMinute ->
TimePickerDialog(activity, { _, newHour, newMinute ->
endTimeSelectedSubject.onNext(Pair(newHour, newMinute))
}, hour, minute, DateFormat.is24HourFormat(activity)).show()
}
@@ -215,6 +229,8 @@ class SettingsController : QkController<SettingsView, SettingsState, SettingsPre
override fun showSignatureDialog(signature: String) = signatureDialog.setText(signature).show()
override fun showAutoDeleteDialog(days: Int) = autoDeleteDialog.setExpiry(days).show()
override fun showMmsSizePicker() = mmsSizeDialog.show(activity!!)
override fun showSwipeActions() {
@@ -114,6 +114,9 @@ class SettingsPresenter @Inject constructor(
disposables += prefs.mobileOnly.asObservable()
.subscribe { enabled -> newState { copy(mobileOnly = enabled) } }
disposables += prefs.autoDelete.asObservable()
.subscribe { autoDelete -> newState { copy(autoDelete = autoDelete) } }
disposables += prefs.longAsMms.asObservable()
.subscribe { enabled -> newState { copy(longAsMms = enabled) } }
@@ -183,6 +186,8 @@ class SettingsPresenter @Inject constructor(
R.id.mobileOnly -> prefs.mobileOnly.set(!prefs.mobileOnly.get())
R.id.autoDelete -> view.showAutoDeleteDialog(prefs.autoDelete.get())
R.id.longAsMms -> prefs.longAsMms.set(!prefs.longAsMms.get())
R.id.mmsSize -> view.showMmsSizePicker()
@@ -242,11 +247,16 @@ class SettingsPresenter @Inject constructor(
.autoDisposable(view.scope())
.subscribe()
view.signatureSet()
view.signatureChanged()
.doOnNext(prefs.signature::set)
.autoDisposable(view.scope())
.subscribe()
view.autoDeleteChanged()
.doOnNext(prefs.autoDelete::set)
.autoDisposable(view.scope())
.subscribe()
view.mmsSizeSelected()
.autoDisposable(view.scope())
.subscribe(prefs.mmsSize::set)
@@ -41,6 +41,7 @@ data class SettingsState(
val splitSmsEnabled: Boolean = false,
val stripUnicodeEnabled: Boolean = false,
val mobileOnly: Boolean = false,
val autoDelete: Int = 0,
val longAsMms: Boolean = false,
val maxMmsSizeSummary: String = "100KB",
val maxMmsSizeId: Int = 100,
@@ -31,7 +31,8 @@ interface SettingsView : QkViewContract<SettingsState> {
fun nightEndSelected(): Observable<Pair<Int, Int>>
fun textSizeSelected(): Observable<Int>
fun sendDelaySelected(): Observable<Int>
fun signatureSet(): Observable<String>
fun signatureChanged(): Observable<String>
fun autoDeleteChanged(): Observable<Int>
fun mmsSizeSelected(): Observable<Int>
fun showQksmsPlusSnackbar()
@@ -41,6 +42,7 @@ interface SettingsView : QkViewContract<SettingsState> {
fun showTextSizePicker()
fun showDelayDurationDialog()
fun showSignatureDialog(signature: String)
fun showAutoDeleteDialog(days: Int)
fun showMmsSizePicker()
fun showSwipeActions()
fun showThemePicker()
@@ -0,0 +1,50 @@
/*
* 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.autodelete
import android.app.Activity
import android.content.DialogInterface
import androidx.appcompat.app.AlertDialog
import com.moez.QKSMS.R
import com.moez.QKSMS.databinding.SettingsAutoDeleteDialogBinding
class AutoDeleteDialog(context: Activity, listener: (Int) -> Unit) : AlertDialog(context) {
private val binding = SettingsAutoDeleteDialogBinding.inflate(context.layoutInflater)
init {
setView(binding.root)
setTitle(R.string.settings_auto_delete)
setMessage(context.getString(R.string.settings_auto_delete_dialog_message))
setButton(DialogInterface.BUTTON_NEUTRAL, context.getString(R.string.button_cancel)) { _, _ -> }
setButton(DialogInterface.BUTTON_NEGATIVE, context.getString(R.string.settings_auto_delete_never)) { _, _ -> listener(0) }
setButton(DialogInterface.BUTTON_POSITIVE, context.getString(R.string.button_save)) { _, _ ->
listener(binding.field.text.toString().toIntOrNull() ?: 0)
}
}
fun setExpiry(days: Int): AutoDeleteDialog {
when (days) {
0 -> binding.field.text = null
else -> binding.field.setText(days.toString())
}
return this
}
}