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
@@ -113,6 +113,7 @@ class Preferences @Inject constructor(
val signature = rxPrefs.getString("signature", "")
val unicode = rxPrefs.getBoolean("unicode", false)
val mobileOnly = rxPrefs.getBoolean("mobileOnly", false)
val autoDelete = rxPrefs.getInteger("autoDelete", 0)
val longAsMms = rxPrefs.getBoolean("longAsMms", false)
val mmsSize = rxPrefs.getInteger("mmsSize", 300)
val logging = rxPrefs.getBoolean("logging", false)
@@ -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
}
}
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M15.1,19.37l1,1.74c-0.96,0.44 -2.01,0.73 -3.1,0.84v-2.02C13.74,19.84 14.44,19.65 15.1,19.37zM4.07,13H2.05c0.11,1.1 0.4,2.14 0.84,3.1l1.74,-1C4.35,14.44 4.16,13.74 4.07,13zM15.1,4.63l1,-1.74C15.14,2.45 14.1,2.16 13,2.05v2.02C13.74,4.16 14.44,4.35 15.1,4.63zM19.93,11h2.02c-0.11,-1.1 -0.4,-2.14 -0.84,-3.1l-1.74,1C19.65,9.56 19.84,10.26 19.93,11zM8.9,19.37l-1,1.74c0.96,0.44 2.01,0.73 3.1,0.84v-2.02C10.26,19.84 9.56,19.65 8.9,19.37zM11,4.07V2.05c-1.1,0.11 -2.14,0.4 -3.1,0.84l1,1.74C9.56,4.35 10.26,4.16 11,4.07zM18.36,7.17l1.74,-1.01c-0.63,-0.87 -1.4,-1.64 -2.27,-2.27l-1.01,1.74C17.41,6.08 17.92,6.59 18.36,7.17zM4.63,8.9l-1.74,-1C2.45,8.86 2.16,9.9 2.05,11h2.02C4.16,10.26 4.35,9.56 4.63,8.9zM19.93,13c-0.09,0.74 -0.28,1.44 -0.56,2.1l1.74,1c0.44,-0.96 0.73,-2.01 0.84,-3.1H19.93zM16.83,18.36l1.01,1.74c0.87,-0.63 1.64,-1.4 2.27,-2.27l-1.74,-1.01C17.92,17.41 17.41,17.92 16.83,18.36zM7.17,5.64L6.17,3.89C5.29,4.53 4.53,5.29 3.9,6.17l1.74,1.01C6.08,6.59 6.59,6.08 7.17,5.64zM5.64,16.83L3.9,17.83c0.63,0.87 1.4,1.64 2.27,2.27l1.01,-1.74C6.59,17.92 6.08,17.41 5.64,16.83zM13,7h-2v5.41l4.29,4.29l1.41,-1.41L13,11.59V7z"/>
</vector>
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2019 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/>.
-->
<com.moez.QKSMS.common.widget.QkEditText xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/field"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@null"
android:hint="@string/settings_auto_delete_dialog_hint"
android:inputType="number"
android:lines="1"
android:maxLength="3"
android:padding="24dp"
android:singleLine="true"
android:textStyle="bold"
app:textSize="dialog"
tools:hint="Enter something" />
@@ -177,6 +177,14 @@
app:title="@string/settings_mobile_title"
app:widget="@layout/settings_switch_widget" />
<com.moez.QKSMS.common.widget.PreferenceView
android:id="@+id/autoDelete"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:icon="@drawable/ic_baseline_history_toggle_off_24"
app:title="@string/settings_auto_delete"
tools:summary="Never" />
<com.moez.QKSMS.common.widget.PreferenceView
android:id="@+id/longAsMms"
android:layout_width="match_parent"
@@ -258,6 +258,15 @@
<string name="settings_unicode_summary">Remove accents from characters in outgoing SMS messages</string>
<string name="settings_mobile_title">Mobile numbers only</string>
<string name="settings_mobile_summary">When composing a message, only show mobile numbers</string>
<string name="settings_auto_delete">Delete old messages automatically</string>
<string name="settings_auto_delete_dialog_message">Messages will be deleted after the specified number of days</string>
<string name="settings_auto_delete_dialog_hint">Number of days</string>
<string name="settings_auto_delete_never">Never</string>
<plurals name="settings_auto_delete_summary">
<item quantity="zero">Never</item>
<item quantity="one">After 1 day</item>
<item quantity="other">After %d days</item>
</plurals>
<string name="settings_long_as_mms_title">Send long messages as MMS</string>
<string name="settings_long_as_mms_summary">If your longer text messages are failing to send, or sending in the wrong order, you can send them as MMS messages instead. Additional charges may apply</string>
<string name="settings_mms_size_title">Auto-compress MMS attachments</string>