diff --git a/domain/src/main/java/com/moez/QKSMS/util/Preferences.kt b/domain/src/main/java/com/moez/QKSMS/util/Preferences.kt index 92794caf..919fab27 100644 --- a/domain/src/main/java/com/moez/QKSMS/util/Preferences.kt +++ b/domain/src/main/java/com/moez/QKSMS/util/Preferences.kt @@ -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) diff --git a/presentation/src/main/java/com/moez/QKSMS/common/widget/FieldDialog.kt b/presentation/src/main/java/com/moez/QKSMS/common/widget/TextInputDialog.kt similarity index 82% rename from presentation/src/main/java/com/moez/QKSMS/common/widget/FieldDialog.kt rename to presentation/src/main/java/com/moez/QKSMS/common/widget/TextInputDialog.kt index 3efb1262..0c9ee56d 100644 --- a/presentation/src/main/java/com/moez/QKSMS/common/widget/FieldDialog.kt +++ b/presentation/src/main/java/com/moez/QKSMS/common/widget/TextInputDialog.kt @@ -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 } diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/conversationinfo/ConversationInfoController.kt b/presentation/src/main/java/com/moez/QKSMS/feature/conversationinfo/ConversationInfoController.kt index 293e9b75..07682cf9 100644 --- a/presentation/src/main/java/com/moez/QKSMS/feature/conversationinfo/ConversationInfoController.kt +++ b/presentation/src/main/java/com/moez/QKSMS/feature/conversationinfo/ConversationInfoController.kt @@ -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 = PublishSubject.create() diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/settings/SettingsController.kt b/presentation/src/main/java/com/moez/QKSMS/feature/settings/SettingsController.kt index f2d652a7..eace81b3 100644 --- a/presentation/src/main/java/com/moez/QKSMS/feature/settings/SettingsController.kt +++ b/presentation/src/main/java/com/moez/QKSMS/feature/settings/SettingsController.kt @@ -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 = PublishSubject.create() private val startTimeSelectedSubject: Subject> = PublishSubject.create() private val endTimeSelectedSubject: Subject> = PublishSubject.create() private val signatureSubject: Subject = PublishSubject.create() + private val autoDeleteSubject: Subject = PublishSubject.create() private val progressAnimator by lazy { ObjectAnimator.ofInt(binding.syncingProgress, "progress", 0, 0) } @@ -132,7 +137,9 @@ class SettingsController : QkController = sendDelayDialog.adapter.menuItemClicks - override fun signatureSet(): Observable = signatureSubject + override fun signatureChanged(): Observable = signatureSubject + + override fun autoDeleteChanged(): Observable = autoDeleteSubject override fun mmsSizeSelected(): Observable = mmsSizeDialog.adapter.menuItemClicks @@ -167,6 +174,13 @@ class SettingsController : QkController().isChecked = state.stripUnicodeEnabled binding.mobileOnly.widget().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().isChecked = state.longAsMms binding.mmsSize.summary = state.maxMmsSizeSummary @@ -198,13 +212,13 @@ class SettingsController : QkController + 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 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) diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/settings/SettingsState.kt b/presentation/src/main/java/com/moez/QKSMS/feature/settings/SettingsState.kt index f18ccd80..35cf2252 100644 --- a/presentation/src/main/java/com/moez/QKSMS/feature/settings/SettingsState.kt +++ b/presentation/src/main/java/com/moez/QKSMS/feature/settings/SettingsState.kt @@ -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, diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/settings/SettingsView.kt b/presentation/src/main/java/com/moez/QKSMS/feature/settings/SettingsView.kt index 80431508..f0350609 100644 --- a/presentation/src/main/java/com/moez/QKSMS/feature/settings/SettingsView.kt +++ b/presentation/src/main/java/com/moez/QKSMS/feature/settings/SettingsView.kt @@ -31,7 +31,8 @@ interface SettingsView : QkViewContract { fun nightEndSelected(): Observable> fun textSizeSelected(): Observable fun sendDelaySelected(): Observable - fun signatureSet(): Observable + fun signatureChanged(): Observable + fun autoDeleteChanged(): Observable fun mmsSizeSelected(): Observable fun showQksmsPlusSnackbar() @@ -41,6 +42,7 @@ interface SettingsView : QkViewContract { fun showTextSizePicker() fun showDelayDurationDialog() fun showSignatureDialog(signature: String) + fun showAutoDeleteDialog(days: Int) fun showMmsSizePicker() fun showSwipeActions() fun showThemePicker() diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/settings/autodelete/AutoDeleteDialog.kt b/presentation/src/main/java/com/moez/QKSMS/feature/settings/autodelete/AutoDeleteDialog.kt new file mode 100644 index 00000000..260b0f4f --- /dev/null +++ b/presentation/src/main/java/com/moez/QKSMS/feature/settings/autodelete/AutoDeleteDialog.kt @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2017 Moez Bhatti + * + * 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 . + */ +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 + } + +} diff --git a/presentation/src/main/res/drawable/ic_baseline_history_toggle_off_24.xml b/presentation/src/main/res/drawable/ic_baseline_history_toggle_off_24.xml new file mode 100644 index 00000000..ece916dc --- /dev/null +++ b/presentation/src/main/res/drawable/ic_baseline_history_toggle_off_24.xml @@ -0,0 +1,10 @@ + + + diff --git a/presentation/src/main/res/layout/settings_auto_delete_dialog.xml b/presentation/src/main/res/layout/settings_auto_delete_dialog.xml new file mode 100644 index 00000000..92830e5c --- /dev/null +++ b/presentation/src/main/res/layout/settings_auto_delete_dialog.xml @@ -0,0 +1,35 @@ + + + diff --git a/presentation/src/main/res/layout/settings_controller.xml b/presentation/src/main/res/layout/settings_controller.xml index 0ae7a8cf..4fe6e9b3 100644 --- a/presentation/src/main/res/layout/settings_controller.xml +++ b/presentation/src/main/res/layout/settings_controller.xml @@ -177,6 +177,14 @@ app:title="@string/settings_mobile_title" app:widget="@layout/settings_switch_widget" /> + + Remove accents from characters in outgoing SMS messages Mobile numbers only When composing a message, only show mobile numbers + Delete old messages automatically + Messages will be deleted after the specified number of days + Number of days + Never + + Never + After 1 day + After %d days + Send long messages as MMS 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 Auto-compress MMS attachments