#505 - Signature support

This commit is contained in:
moezbhatti
2019-07-26 23:34:00 -04:00
parent 4681b03895
commit 3915b9322b
12 changed files with 146 additions and 33 deletions
@@ -218,10 +218,16 @@ class MessageRepositoryImpl @Inject constructor(
attachments: List<Attachment>,
delay: Int
) {
val signedBody = when {
prefs.signature.get().isEmpty() -> body
body.isNotEmpty() -> body + '\n' + prefs.signature.get()
else -> prefs.signature.get()
}
if (addresses.size == 1 && attachments.isEmpty()) { // SMS
if (delay > 0) { // With delay
val sendTime = System.currentTimeMillis() + delay
val message = insertSentSms(subId, threadId, addresses.first(), body, sendTime)
val message = insertSentSms(subId, threadId, addresses.first(), signedBody, sendTime)
val intent = getIntentForDelayedSms(message.id)
@@ -232,14 +238,14 @@ class MessageRepositoryImpl @Inject constructor(
alarmManager.setExact(AlarmManager.RTC_WAKEUP, sendTime, intent)
}
} else { // No delay
val message = insertSentSms(subId, threadId, addresses.first(), body, System.currentTimeMillis())
val message = insertSentSms(subId, threadId, addresses.first(), signedBody, System.currentTimeMillis())
sendSms(message)
}
} else { // MMS
val parts = arrayListOf<MMSPart>()
if (body.isNotBlank()) {
parts += MMSPart("text", ContentType.TEXT_PLAIN, body.toByteArray())
if (signedBody.isNotBlank()) {
parts += MMSPart("text", ContentType.TEXT_PLAIN, signedBody.toByteArray())
}
// Add the GIFs as attachments
@@ -83,6 +83,7 @@ class Preferences @Inject constructor(private val rxPrefs: RxSharedPreferences)
val swipeLeft = rxPrefs.getInteger("swipeLeft", SWIPE_ACTION_ARCHIVE)
val autoEmoji = rxPrefs.getBoolean("autoEmoji", true)
val delivery = rxPrefs.getBoolean("delivery", false)
val signature = rxPrefs.getString("signature", "")
val unicode = rxPrefs.getBoolean("unicode", false)
val mobileOnly = rxPrefs.getBoolean("mobileOnly", false)
val mmsSize = rxPrefs.getInteger("mmsSize", 300)
@@ -0,0 +1,48 @@
/*
* 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.common.widget
import android.app.Activity
import android.content.DialogInterface
import android.view.LayoutInflater
import androidx.appcompat.app.AlertDialog
import com.moez.QKSMS.R
import kotlinx.android.synthetic.main.field_dialog.view.*
class FieldDialog(context: Activity, hint: String, listener: (String) -> Unit) : AlertDialog(context) {
private val layout = LayoutInflater.from(context).inflate(R.layout.field_dialog, null)
init {
layout.field.hint = hint
setView(layout)
setButton(DialogInterface.BUTTON_NEUTRAL, context.getString(R.string.button_cancel)) { _, _ -> }
setButton(DialogInterface.BUTTON_NEGATIVE, context.getString(R.string.button_delete)) { _, _ -> listener("") }
setButton(DialogInterface.BUTTON_POSITIVE, context.getString(R.string.button_save)) { _, _ ->
listener(layout.field.text.toString())
}
}
fun setText(text: String): FieldDialog {
layout.field.setText(text)
return this
}
}
@@ -18,7 +18,6 @@
*/
package com.moez.QKSMS.feature.conversationinfo
import android.text.InputFilter
import android.view.View
import androidx.appcompat.app.AlertDialog
import com.bluelinelabs.conductor.RouterTransaction
@@ -28,11 +27,9 @@ 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.animateLayoutChanges
import com.moez.QKSMS.common.util.extensions.dpToPx
import com.moez.QKSMS.common.util.extensions.resolveThemeColor
import com.moez.QKSMS.common.util.extensions.scrapViews
import com.moez.QKSMS.common.util.extensions.setVisible
import com.moez.QKSMS.common.widget.QkEditText
import com.moez.QKSMS.common.widget.FieldDialog
import com.moez.QKSMS.feature.conversationinfo.injection.ConversationInfoModule
import com.moez.QKSMS.feature.themepicker.ThemePickerController
import com.moez.QKSMS.injection.appComponent
@@ -43,7 +40,9 @@ import io.reactivex.subjects.Subject
import kotlinx.android.synthetic.main.conversation_info_controller.*
import javax.inject.Inject
class ConversationInfoController(val threadId: Long = 0) : QkController<ConversationInfoView, ConversationInfoState, ConversationInfoPresenter>(), ConversationInfoView {
class ConversationInfoController(
val threadId: Long = 0
) : QkController<ConversationInfoView, ConversationInfoState, ConversationInfoPresenter>(), ConversationInfoView {
@Inject override lateinit var presenter: ConversationInfoPresenter
@Inject lateinit var navigator: Navigator
@@ -51,6 +50,10 @@ class ConversationInfoController(val threadId: Long = 0) : QkController<Conversa
@Inject lateinit var mediaAdapter: ConversationMediaAdapter
@Inject lateinit var itemDecoration: GridSpacingItemDecoration
private val nameDialog: FieldDialog by lazy {
FieldDialog(activity!!, activity!!.getString(R.string.info_name), nameChangeSubject::onNext)
}
private val nameChangeSubject: Subject<String> = PublishSubject.create()
private val confirmDeleteSubject: Subject<Unit> = PublishSubject.create()
@@ -130,26 +133,7 @@ class ConversationInfoController(val threadId: Long = 0) : QkController<Conversa
mediaAdapter.updateData(state.media)
}
override fun showNameDialog(name: String) {
val editText = QkEditText(activity!!).apply {
val padding = 8.dpToPx(activity!!)
setPadding(padding * 3, padding, padding * 3, padding)
setSingleLine(true)
setHint(R.string.info_name_hint)
setText(name)
setHintTextColor(context.resolveThemeColor(android.R.attr.textColorTertiary))
setTextColor(context.resolveThemeColor(android.R.attr.textColorPrimary))
filters = arrayOf(InputFilter.LengthFilter(30))
background = null
}
AlertDialog.Builder(activity!!)
.setTitle(R.string.info_name)
.setView(editText)
.setPositiveButton(R.string.button_save) { _, _ -> nameChangeSubject.onNext(editText.text.toString()) }
.setNegativeButton(R.string.button_cancel, null)
.show()
}
override fun showNameDialog(name: String) = nameDialog.setText(name).show()
override fun showThemePicker(threadId: Long) {
router.pushController(RouterTransaction.with(ThemePickerController(threadId))
@@ -37,6 +37,7 @@ 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.PreferenceView
import com.moez.QKSMS.feature.settings.about.AboutController
import com.moez.QKSMS.feature.settings.swipe.SwipeActionsController
@@ -65,9 +66,14 @@ 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 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 progressAnimator by lazy { ObjectAnimator.ofInt(syncingProgress, "progress", 0, 0) }
@@ -119,6 +125,8 @@ class SettingsController : QkController<SettingsView, SettingsState, SettingsPre
override fun sendDelaySelected(): Observable<Int> = sendDelayDialog.adapter.menuItemClicks
override fun signatureSet(): Observable<String> = signatureSubject
override fun mmsSizeSelected(): Observable<Int> = mmsSizeDialog.adapter.menuItemClicks
override fun render(state: SettingsState) {
@@ -140,6 +148,8 @@ class SettingsController : QkController<SettingsView, SettingsState, SettingsPre
delivery.checkbox.isChecked = state.deliveryEnabled
signature.summary = state.signature
textSize.summary = state.textSizeSummary
textSizeDialog.adapter.selectedItem = state.textSizeId
systemFont.checkbox.isChecked = state.systemFontEnabled
@@ -190,6 +200,8 @@ class SettingsController : QkController<SettingsView, SettingsState, SettingsPre
override fun showDelayDurationDialog() = sendDelayDialog.show(activity!!)
override fun showSignatureDialog(signature: String) = signatureDialog.setText(signature).show()
override fun showMmsSizePicker() = mmsSizeDialog.show(activity!!)
override fun showSwipeActions() {
@@ -87,6 +87,9 @@ class SettingsPresenter @Inject constructor(
disposables += prefs.delivery.asObservable()
.subscribe { enabled -> newState { copy(deliveryEnabled = enabled) } }
disposables += prefs.signature.asObservable()
.subscribe { signature -> newState { copy(signature = signature) } }
val textSizeLabels = context.resources.getStringArray(R.array.text_sizes)
disposables += prefs.textSize.asObservable()
.subscribe { textSize ->
@@ -153,6 +156,8 @@ class SettingsPresenter @Inject constructor(
R.id.delivery -> prefs.delivery.set(!prefs.delivery.get())
R.id.signature -> view.showSignatureDialog(prefs.signature.get())
R.id.textSize -> view.showTextSizePicker()
R.id.systemFont -> prefs.systemFont.set(!prefs.systemFont.get())
@@ -205,7 +210,7 @@ class SettingsPresenter @Inject constructor(
view.textSizeSelected()
.autoDisposable(view.scope())
.subscribe { prefs.textSize.set(it) }
.subscribe(prefs.textSize::set)
view.sendDelaySelected()
.withLatestFrom(billingManager.upgradeStatus) { duration, upgraded ->
@@ -218,9 +223,14 @@ class SettingsPresenter @Inject constructor(
.autoDisposable(view.scope())
.subscribe()
view.signatureSet()
.doOnNext(prefs.signature::set)
.autoDisposable(view.scope())
.subscribe()
view.mmsSizeSelected()
.autoDisposable(view.scope())
.subscribe { prefs.mmsSize.set(it) }
.subscribe(prefs.mmsSize::set)
}
}
@@ -33,6 +33,7 @@ data class SettingsState(
val sendDelaySummary: String = "",
val sendDelayId: Int = 0,
val deliveryEnabled: Boolean = false,
val signature: String = "",
val textSizeSummary: String = "",
val textSizeId: Int = Preferences.TEXT_SIZE_NORMAL,
val systemFontEnabled: Boolean = false,
@@ -31,6 +31,7 @@ interface SettingsView : QkViewContract<SettingsState> {
fun nightEndSelected(): Observable<Pair<Int, Int>>
fun textSizeSelected(): Observable<Int>
fun sendDelaySelected(): Observable<Int>
fun signatureSet(): Observable<String>
fun mmsSizeSelected(): Observable<Int>
fun showQksmsPlusSnackbar()
@@ -39,6 +40,7 @@ interface SettingsView : QkViewContract<SettingsState> {
fun showEndTimePicker(hour: Int, minute: Int)
fun showTextSizePicker()
fun showDelayDurationDialog()
fun showSignatureDialog(signature: String)
fun showMmsSizePicker()
fun showSwipeActions()
fun showThemePicker()
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M4,9h16v2L4,11zM4,13h10v2L4,15z"/>
</vector>
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ 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/>.
-->
<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:lines="1"
android:maxLength="30"
android:padding="24dp"
android:singleLine="true"
android:textStyle="bold"
app:textSize="dialog"
tools:hint="Enter something" />
@@ -144,6 +144,13 @@
app:title="@string/settings_delivery_title"
app:widget="@layout/settings_switch_widget" />
<com.moez.QKSMS.common.widget.PreferenceView
android:id="@+id/signature"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:icon="@drawable/ic_short_text_black_24dp"
app:title="@string/settings_signature_title" />
<com.moez.QKSMS.common.widget.PreferenceView
android:id="@+id/unicode"
android:layout_width="match_parent"
@@ -207,4 +214,4 @@
</LinearLayout>
</ScrollView>
</ScrollView>
+1 -1
View File
@@ -138,7 +138,6 @@
<string name="info_title">Details</string>
<string name="info_name">Conversation title</string>
<string name="info_name_hint">Enter title</string>
<string name="info_notifications">Notifications</string>
<string name="info_theme">Theme</string>
<string name="info_archive">Archive</string>
@@ -241,6 +240,7 @@
</string-array>
<string name="settings_delivery_title">Delivery confirmations</string>
<string name="settings_delivery_summary">Confirm that messages were sent successfully</string>
<string name="settings_signature_title">Signature</string>
<string name="settings_unicode_title">Strip accents</string>
<string name="settings_unicode_summary">Remove accents from characters in outgoing SMS messages</string>
<string name="settings_mobile_title">Mobile numbers only</string>