forked from upstream-mirrors/quik
#1026 - Add option to hide message contents
This commit is contained in:
@@ -37,6 +37,10 @@ class Preferences @Inject constructor(private val rxPrefs: RxSharedPreferences)
|
|||||||
const val TEXT_SIZE_NORMAL = 1
|
const val TEXT_SIZE_NORMAL = 1
|
||||||
const val TEXT_SIZE_LARGE = 2
|
const val TEXT_SIZE_LARGE = 2
|
||||||
const val TEXT_SIZE_LARGER = 3
|
const val TEXT_SIZE_LARGER = 3
|
||||||
|
|
||||||
|
const val NOTIFICATION_PREVIEWS_ALL = 0
|
||||||
|
const val NOTIFICATION_PREVIEWS_NAME = 1
|
||||||
|
const val NOTIFICATION_PREVIEWS_NONE = 2
|
||||||
}
|
}
|
||||||
|
|
||||||
val defaultSms = rxPrefs.getBoolean("defaultSms", false)
|
val defaultSms = rxPrefs.getBoolean("defaultSms", false)
|
||||||
@@ -73,6 +77,15 @@ class Preferences @Inject constructor(private val rxPrefs: RxSharedPreferences)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun notificationPreviews(threadId: Long = 0): Preference<Int> {
|
||||||
|
val default = rxPrefs.getInteger("notification_previews", 0)
|
||||||
|
|
||||||
|
return when (threadId) {
|
||||||
|
0L -> default
|
||||||
|
else -> rxPrefs.getInteger("notification_previews_$threadId", default.get())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun vibration(threadId: Long = 0): Preference<Boolean> {
|
fun vibration(threadId: Long = 0): Preference<Boolean> {
|
||||||
val default = rxPrefs.getBoolean("vibration", true)
|
val default = rxPrefs.getBoolean("vibration", true)
|
||||||
|
|
||||||
|
|||||||
@@ -97,23 +97,6 @@ class NotificationManagerImpl @Inject constructor(
|
|||||||
|
|
||||||
val conversation = messageRepo.getConversation(threadId) ?: return
|
val conversation = messageRepo.getConversation(threadId) ?: return
|
||||||
|
|
||||||
val style = NotificationCompat.MessagingStyle("Me")
|
|
||||||
messages.forEach { message ->
|
|
||||||
val name = if (message.isMe()) null else conversation.getTitle()
|
|
||||||
style.addMessage(message.getSummary(), message.date, name)
|
|
||||||
}
|
|
||||||
|
|
||||||
val avatar = conversation.recipients.takeIf { it.size == 1 }
|
|
||||||
?.first()?.address
|
|
||||||
?.let { address ->
|
|
||||||
GlideApp.with(context)
|
|
||||||
.asBitmap()
|
|
||||||
.circleCrop()
|
|
||||||
.load(PhoneNumberUtils.stripSeparators(address))
|
|
||||||
.submit(64.dpToPx(context), 64.dpToPx(context))
|
|
||||||
}
|
|
||||||
?.let { futureGet -> tryOrNull { futureGet.get() } }
|
|
||||||
|
|
||||||
val contentIntent = Intent(context, ComposeActivity::class.java).putExtra("threadId", threadId)
|
val contentIntent = Intent(context, ComposeActivity::class.java).putExtra("threadId", threadId)
|
||||||
val taskStackBuilder = TaskStackBuilder.create(context)
|
val taskStackBuilder = TaskStackBuilder.create(context)
|
||||||
taskStackBuilder.addParentStack(ComposeActivity::class.java)
|
taskStackBuilder.addParentStack(ComposeActivity::class.java)
|
||||||
@@ -131,18 +114,54 @@ class NotificationManagerImpl @Inject constructor(
|
|||||||
.setCategory(NotificationCompat.CATEGORY_MESSAGE)
|
.setCategory(NotificationCompat.CATEGORY_MESSAGE)
|
||||||
.setColor(colors.themeForConversation(threadId).blockingFirst())
|
.setColor(colors.themeForConversation(threadId).blockingFirst())
|
||||||
.setPriority(NotificationManagerCompat.IMPORTANCE_MAX)
|
.setPriority(NotificationManagerCompat.IMPORTANCE_MAX)
|
||||||
.setLargeIcon(avatar)
|
|
||||||
.setSmallIcon(R.drawable.ic_notification)
|
.setSmallIcon(R.drawable.ic_notification)
|
||||||
.setNumber(messages.size)
|
.setNumber(messages.size)
|
||||||
.setAutoCancel(true)
|
.setAutoCancel(true)
|
||||||
.setContentIntent(contentPI)
|
.setContentIntent(contentPI)
|
||||||
.setDeleteIntent(seenPI)
|
.setDeleteIntent(seenPI)
|
||||||
.addAction(readAction)
|
.addAction(readAction)
|
||||||
.setStyle(style)
|
|
||||||
.setSound(Uri.parse(prefs.ringtone(threadId).get()))
|
.setSound(Uri.parse(prefs.ringtone(threadId).get()))
|
||||||
.setLights(Color.WHITE, 500, 2000)
|
.setLights(Color.WHITE, 500, 2000)
|
||||||
.setVibrate(if (prefs.vibration(threadId).get()) VIBRATE_PATTERN else longArrayOf(0))
|
.setVibrate(if (prefs.vibration(threadId).get()) VIBRATE_PATTERN else longArrayOf(0))
|
||||||
|
|
||||||
|
val messagingStyle = NotificationCompat.MessagingStyle("Me")
|
||||||
|
messages.forEach { message ->
|
||||||
|
val name = if (message.isMe()) null else conversation.getTitle()
|
||||||
|
messagingStyle.addMessage(message.getSummary(), message.date, name)
|
||||||
|
}
|
||||||
|
|
||||||
|
val avatar = conversation.recipients.takeIf { it.size == 1 }
|
||||||
|
?.first()?.address
|
||||||
|
?.let { address ->
|
||||||
|
GlideApp.with(context)
|
||||||
|
.asBitmap()
|
||||||
|
.circleCrop()
|
||||||
|
.load(PhoneNumberUtils.stripSeparators(address))
|
||||||
|
.submit(64.dpToPx(context), 64.dpToPx(context))
|
||||||
|
}
|
||||||
|
?.let { futureGet -> tryOrNull { futureGet.get() } }
|
||||||
|
|
||||||
|
when (prefs.notificationPreviews(threadId).get()) {
|
||||||
|
Preferences.NOTIFICATION_PREVIEWS_ALL -> {
|
||||||
|
notification
|
||||||
|
.setLargeIcon(avatar)
|
||||||
|
.setStyle(messagingStyle)
|
||||||
|
}
|
||||||
|
|
||||||
|
Preferences.NOTIFICATION_PREVIEWS_NAME -> {
|
||||||
|
notification
|
||||||
|
.setLargeIcon(avatar)
|
||||||
|
.setContentTitle(conversation.getTitle())
|
||||||
|
.setContentText(context.resources.getQuantityString(R.plurals.notification_new_messages, messages.size, messages.size))
|
||||||
|
}
|
||||||
|
|
||||||
|
Preferences.NOTIFICATION_PREVIEWS_NONE -> {
|
||||||
|
notification
|
||||||
|
.setContentTitle(context.getString(R.string.app_name))
|
||||||
|
.setContentText(context.resources.getQuantityString(R.plurals.notification_new_messages, messages.size, messages.size))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Add all of the people from this conversation to the notification, so that the system can
|
// Add all of the people from this conversation to the notification, so that the system can
|
||||||
// appropriately bypass DND mode
|
// appropriately bypass DND mode
|
||||||
conversation.recipients
|
conversation.recipients
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ class SettingsActivity : QkThemedActivity<SettingsViewModel>(), SettingsView {
|
|||||||
|
|
||||||
@Inject lateinit var nightModeAdapter: MenuItemAdapter
|
@Inject lateinit var nightModeAdapter: MenuItemAdapter
|
||||||
@Inject lateinit var textSizeAdapter: MenuItemAdapter
|
@Inject lateinit var textSizeAdapter: MenuItemAdapter
|
||||||
|
@Inject lateinit var notificationPreviewModeAdapter: MenuItemAdapter
|
||||||
@Inject lateinit var mmsSizeAdapter: MenuItemAdapter
|
@Inject lateinit var mmsSizeAdapter: MenuItemAdapter
|
||||||
|
|
||||||
override val viewModelClass = SettingsViewModel::class
|
override val viewModelClass = SettingsViewModel::class
|
||||||
@@ -58,6 +59,7 @@ class SettingsActivity : QkThemedActivity<SettingsViewModel>(), SettingsView {
|
|||||||
override val startTimeSelectedIntent: Subject<Pair<Int, Int>> = PublishSubject.create()
|
override val startTimeSelectedIntent: Subject<Pair<Int, Int>> = PublishSubject.create()
|
||||||
override val endTimeSelectedIntent: Subject<Pair<Int, Int>> = PublishSubject.create()
|
override val endTimeSelectedIntent: Subject<Pair<Int, Int>> = PublishSubject.create()
|
||||||
override val textSizeSelectedIntent by lazy { textSizeAdapter.menuItemClicks }
|
override val textSizeSelectedIntent by lazy { textSizeAdapter.menuItemClicks }
|
||||||
|
override val notificationPreviewModeSelectedIntent by lazy { notificationPreviewModeAdapter.menuItemClicks }
|
||||||
override val mmsSizeSelectedIntent: Subject<Int> by lazy { mmsSizeAdapter.menuItemClicks }
|
override val mmsSizeSelectedIntent: Subject<Int> by lazy { mmsSizeAdapter.menuItemClicks }
|
||||||
|
|
||||||
// TODO remove this
|
// TODO remove this
|
||||||
@@ -86,6 +88,7 @@ class SettingsActivity : QkThemedActivity<SettingsViewModel>(), SettingsView {
|
|||||||
|
|
||||||
nightModeAdapter.setData(R.array.night_modes)
|
nightModeAdapter.setData(R.array.night_modes)
|
||||||
textSizeAdapter.setData(R.array.text_sizes)
|
textSizeAdapter.setData(R.array.text_sizes)
|
||||||
|
notificationPreviewModeAdapter.setData(R.array.notification_preview_options)
|
||||||
mmsSizeAdapter.setData(R.array.mms_sizes, R.array.mms_sizes_ids)
|
mmsSizeAdapter.setData(R.array.mms_sizes, R.array.mms_sizes_ids)
|
||||||
|
|
||||||
version.text = getString(R.string.settings_version, BuildConfig.VERSION_NAME)
|
version.text = getString(R.string.settings_version, BuildConfig.VERSION_NAME)
|
||||||
@@ -124,6 +127,7 @@ class SettingsActivity : QkThemedActivity<SettingsViewModel>(), SettingsView {
|
|||||||
black.setVisible(state.nightModeId != Preferences.NIGHT_MODE_OFF)
|
black.setVisible(state.nightModeId != Preferences.NIGHT_MODE_OFF)
|
||||||
black.checkbox.isChecked = state.black
|
black.checkbox.isChecked = state.black
|
||||||
|
|
||||||
|
notificationPreviews.summary = state.notificationPreviewSummary
|
||||||
autoEmoji.checkbox.isChecked = state.autoEmojiEnabled
|
autoEmoji.checkbox.isChecked = state.autoEmojiEnabled
|
||||||
delivery.checkbox.isChecked = state.deliveryEnabled
|
delivery.checkbox.isChecked = state.deliveryEnabled
|
||||||
qkreply.checkbox.isChecked = state.qkReplyEnabled
|
qkreply.checkbox.isChecked = state.qkReplyEnabled
|
||||||
@@ -191,6 +195,22 @@ class SettingsActivity : QkThemedActivity<SettingsViewModel>(), SettingsView {
|
|||||||
textSizeDialog = null
|
textSizeDialog = null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun showNotificationPreviewModeDialog() {
|
||||||
|
val recyclerView = RecyclerView(this)
|
||||||
|
recyclerView.layoutManager = LinearLayoutManager(this)
|
||||||
|
recyclerView.adapter = notificationPreviewModeAdapter
|
||||||
|
recyclerView.setPadding(0, 8.dpToPx(this), 0, 8.dpToPx(this))
|
||||||
|
|
||||||
|
val dialog = AlertDialog.Builder(this)
|
||||||
|
.setView(recyclerView)
|
||||||
|
.create()
|
||||||
|
.apply { show() }
|
||||||
|
|
||||||
|
notificationPreviewModeAdapter.menuItemClicks
|
||||||
|
.autoDisposable(scope())
|
||||||
|
.subscribe { dialog.dismiss() }
|
||||||
|
}
|
||||||
|
|
||||||
override fun showMmsSizePicker() {
|
override fun showMmsSizePicker() {
|
||||||
val recyclerView = RecyclerView(this)
|
val recyclerView = RecyclerView(this)
|
||||||
recyclerView.layoutManager = LinearLayoutManager(this)
|
recyclerView.layoutManager = LinearLayoutManager(this)
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ data class SettingsState(
|
|||||||
val black: Boolean = false,
|
val black: Boolean = false,
|
||||||
val autoEmojiEnabled: Boolean = true,
|
val autoEmojiEnabled: Boolean = true,
|
||||||
val notificationsEnabled: Boolean = true,
|
val notificationsEnabled: Boolean = true,
|
||||||
|
val notificationPreviewSummary: String = "",
|
||||||
val deliveryEnabled: Boolean = false,
|
val deliveryEnabled: Boolean = false,
|
||||||
val qkReplyEnabled: Boolean = Build.VERSION.SDK_INT < Build.VERSION_CODES.N,
|
val qkReplyEnabled: Boolean = Build.VERSION.SDK_INT < Build.VERSION_CODES.N,
|
||||||
val qkReplyTapDismiss: Boolean = true,
|
val qkReplyTapDismiss: Boolean = true,
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ interface SettingsView : QkView<SettingsState> {
|
|||||||
val startTimeSelectedIntent: Subject<Pair<Int, Int>>
|
val startTimeSelectedIntent: Subject<Pair<Int, Int>>
|
||||||
val endTimeSelectedIntent: Subject<Pair<Int, Int>>
|
val endTimeSelectedIntent: Subject<Pair<Int, Int>>
|
||||||
val textSizeSelectedIntent: Subject<Int>
|
val textSizeSelectedIntent: Subject<Int>
|
||||||
|
val notificationPreviewModeSelectedIntent: Subject<Int>
|
||||||
val mmsSizeSelectedIntent: Observable<Int>
|
val mmsSizeSelectedIntent: Observable<Int>
|
||||||
|
|
||||||
fun showNightModeDialog()
|
fun showNightModeDialog()
|
||||||
@@ -39,6 +40,7 @@ interface SettingsView : QkView<SettingsState> {
|
|||||||
fun showStartTimePicker(hour: Int, minute: Int)
|
fun showStartTimePicker(hour: Int, minute: Int)
|
||||||
fun showEndTimePicker(hour: Int, minute: Int)
|
fun showEndTimePicker(hour: Int, minute: Int)
|
||||||
fun showTextSizePicker()
|
fun showTextSizePicker()
|
||||||
|
fun showNotificationPreviewModeDialog()
|
||||||
fun dismissTextSizePicker()
|
fun dismissTextSizePicker()
|
||||||
fun showMmsSizePicker()
|
fun showMmsSizePicker()
|
||||||
fun dismissMmsSizePicker()
|
fun dismissMmsSizePicker()
|
||||||
|
|||||||
@@ -81,6 +81,10 @@ class SettingsViewModel : QkViewModel<SettingsView, SettingsState>(SettingsState
|
|||||||
disposables += prefs.notifications().asObservable()
|
disposables += prefs.notifications().asObservable()
|
||||||
.subscribe { enabled -> newState { it.copy(notificationsEnabled = enabled) } }
|
.subscribe { enabled -> newState { it.copy(notificationsEnabled = enabled) } }
|
||||||
|
|
||||||
|
val notificationPreviewLabels = context.resources.getStringArray(R.array.notification_preview_options)
|
||||||
|
disposables += prefs.notificationPreviews().asObservable()
|
||||||
|
.subscribe { nightMode -> newState { it.copy(notificationPreviewSummary = notificationPreviewLabels[nightMode]) } }
|
||||||
|
|
||||||
disposables += prefs.delivery.asObservable()
|
disposables += prefs.delivery.asObservable()
|
||||||
.subscribe { enabled -> newState { it.copy(deliveryEnabled = enabled) } }
|
.subscribe { enabled -> newState { it.copy(deliveryEnabled = enabled) } }
|
||||||
|
|
||||||
@@ -142,6 +146,8 @@ class SettingsViewModel : QkViewModel<SettingsView, SettingsState>(SettingsState
|
|||||||
|
|
||||||
R.id.notifications -> navigator.showNotificationSettings()
|
R.id.notifications -> navigator.showNotificationSettings()
|
||||||
|
|
||||||
|
R.id.notificationPreviews -> view.showNotificationPreviewModeDialog()
|
||||||
|
|
||||||
R.id.blocked -> navigator.showBlockedConversations()
|
R.id.blocked -> navigator.showBlockedConversations()
|
||||||
|
|
||||||
R.id.delivery -> prefs.delivery.set(!prefs.delivery.get())
|
R.id.delivery -> prefs.delivery.set(!prefs.delivery.get())
|
||||||
@@ -200,6 +206,10 @@ class SettingsViewModel : QkViewModel<SettingsView, SettingsState>(SettingsState
|
|||||||
.autoDisposable(view.scope())
|
.autoDisposable(view.scope())
|
||||||
.subscribe { prefs.textSize.set(it) }
|
.subscribe { prefs.textSize.set(it) }
|
||||||
|
|
||||||
|
view.notificationPreviewModeSelectedIntent
|
||||||
|
.autoDisposable(view.scope())
|
||||||
|
.subscribe { prefs.notificationPreviews().set(it) }
|
||||||
|
|
||||||
view.mmsSizeSelectedIntent
|
view.mmsSizeSelectedIntent
|
||||||
.doOnNext { view.dismissMmsSizePicker() }
|
.doOnNext { view.dismissMmsSizePicker() }
|
||||||
.autoDisposable(view.scope())
|
.autoDisposable(view.scope())
|
||||||
|
|||||||
@@ -144,6 +144,13 @@
|
|||||||
app:icon="@drawable/ic_notifications_black_24dp"
|
app:icon="@drawable/ic_notifications_black_24dp"
|
||||||
app:title="@string/settings_notifications_title" />
|
app:title="@string/settings_notifications_title" />
|
||||||
|
|
||||||
|
<common.widget.PreferenceView
|
||||||
|
android:id="@+id/notificationPreviews"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
app:title="@string/settings_notification_previews_title"
|
||||||
|
tools:summary="Show name and message" />
|
||||||
|
|
||||||
<common.widget.PreferenceView
|
<common.widget.PreferenceView
|
||||||
android:id="@+id/autoEmoji"
|
android:id="@+id/autoEmoji"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|||||||
@@ -101,6 +101,7 @@
|
|||||||
<string name="settings_night_end_title">End time</string>
|
<string name="settings_night_end_title">End time</string>
|
||||||
<string name="settings_auto_emoji_title">Automatic emoji</string>
|
<string name="settings_auto_emoji_title">Automatic emoji</string>
|
||||||
<string name="settings_notifications_title">Notifications</string>
|
<string name="settings_notifications_title">Notifications</string>
|
||||||
|
<string name="settings_notification_previews_title">Notification previews</string>
|
||||||
<string name="settings_vibration_title">Vibration</string>
|
<string name="settings_vibration_title">Vibration</string>
|
||||||
<string name="settings_ringtone_title">Sound</string>
|
<string name="settings_ringtone_title">Sound</string>
|
||||||
<string name="settings_blocking_title">Blocking</string>
|
<string name="settings_blocking_title">Blocking</string>
|
||||||
@@ -184,6 +185,10 @@
|
|||||||
<string name="toast_archived">Archived conversation</string>
|
<string name="toast_archived">Archived conversation</string>
|
||||||
<string name="toast_qksms_plus">You must unlock QKSMS+ to use this</string>
|
<string name="toast_qksms_plus">You must unlock QKSMS+ to use this</string>
|
||||||
|
|
||||||
|
<plurals name="notification_new_messages">
|
||||||
|
<item quantity="one">New message</item>
|
||||||
|
<item quantity="other">%s new messages</item>
|
||||||
|
</plurals>
|
||||||
<string name="notification_message_failed_title">Message not sent</string>
|
<string name="notification_message_failed_title">Message not sent</string>
|
||||||
<string name="notification_message_failed_text">The message to %s failed to send</string>
|
<string name="notification_message_failed_text">The message to %s failed to send</string>
|
||||||
|
|
||||||
@@ -193,6 +198,12 @@
|
|||||||
<item>Automatic</item>
|
<item>Automatic</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="notification_preview_options">
|
||||||
|
<item>Show name and message</item>
|
||||||
|
<item>Show name</item>
|
||||||
|
<item>Hide contents</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
<string-array name="text_sizes">
|
<string-array name="text_sizes">
|
||||||
<item>Small</item>
|
<item>Small</item>
|
||||||
<item>Normal</item>
|
<item>Normal</item>
|
||||||
|
|||||||
Reference in New Issue
Block a user