mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-16 19:18:52 +01:00
#1026 - Add option to hide message contents
This commit is contained in:
@@ -97,23 +97,6 @@ class NotificationManagerImpl @Inject constructor(
|
||||
|
||||
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 taskStackBuilder = TaskStackBuilder.create(context)
|
||||
taskStackBuilder.addParentStack(ComposeActivity::class.java)
|
||||
@@ -131,18 +114,54 @@ class NotificationManagerImpl @Inject constructor(
|
||||
.setCategory(NotificationCompat.CATEGORY_MESSAGE)
|
||||
.setColor(colors.themeForConversation(threadId).blockingFirst())
|
||||
.setPriority(NotificationManagerCompat.IMPORTANCE_MAX)
|
||||
.setLargeIcon(avatar)
|
||||
.setSmallIcon(R.drawable.ic_notification)
|
||||
.setNumber(messages.size)
|
||||
.setAutoCancel(true)
|
||||
.setContentIntent(contentPI)
|
||||
.setDeleteIntent(seenPI)
|
||||
.addAction(readAction)
|
||||
.setStyle(style)
|
||||
.setSound(Uri.parse(prefs.ringtone(threadId).get()))
|
||||
.setLights(Color.WHITE, 500, 2000)
|
||||
.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
|
||||
// appropriately bypass DND mode
|
||||
conversation.recipients
|
||||
|
||||
@@ -49,6 +49,7 @@ class SettingsActivity : QkThemedActivity<SettingsViewModel>(), SettingsView {
|
||||
|
||||
@Inject lateinit var nightModeAdapter: MenuItemAdapter
|
||||
@Inject lateinit var textSizeAdapter: MenuItemAdapter
|
||||
@Inject lateinit var notificationPreviewModeAdapter: MenuItemAdapter
|
||||
@Inject lateinit var mmsSizeAdapter: MenuItemAdapter
|
||||
|
||||
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 endTimeSelectedIntent: Subject<Pair<Int, Int>> = PublishSubject.create()
|
||||
override val textSizeSelectedIntent by lazy { textSizeAdapter.menuItemClicks }
|
||||
override val notificationPreviewModeSelectedIntent by lazy { notificationPreviewModeAdapter.menuItemClicks }
|
||||
override val mmsSizeSelectedIntent: Subject<Int> by lazy { mmsSizeAdapter.menuItemClicks }
|
||||
|
||||
// TODO remove this
|
||||
@@ -86,6 +88,7 @@ class SettingsActivity : QkThemedActivity<SettingsViewModel>(), SettingsView {
|
||||
|
||||
nightModeAdapter.setData(R.array.night_modes)
|
||||
textSizeAdapter.setData(R.array.text_sizes)
|
||||
notificationPreviewModeAdapter.setData(R.array.notification_preview_options)
|
||||
mmsSizeAdapter.setData(R.array.mms_sizes, R.array.mms_sizes_ids)
|
||||
|
||||
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.checkbox.isChecked = state.black
|
||||
|
||||
notificationPreviews.summary = state.notificationPreviewSummary
|
||||
autoEmoji.checkbox.isChecked = state.autoEmojiEnabled
|
||||
delivery.checkbox.isChecked = state.deliveryEnabled
|
||||
qkreply.checkbox.isChecked = state.qkReplyEnabled
|
||||
@@ -191,6 +195,22 @@ class SettingsActivity : QkThemedActivity<SettingsViewModel>(), SettingsView {
|
||||
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() {
|
||||
val recyclerView = RecyclerView(this)
|
||||
recyclerView.layoutManager = LinearLayoutManager(this)
|
||||
|
||||
@@ -33,6 +33,7 @@ data class SettingsState(
|
||||
val black: Boolean = false,
|
||||
val autoEmojiEnabled: Boolean = true,
|
||||
val notificationsEnabled: Boolean = true,
|
||||
val notificationPreviewSummary: String = "",
|
||||
val deliveryEnabled: Boolean = false,
|
||||
val qkReplyEnabled: Boolean = Build.VERSION.SDK_INT < Build.VERSION_CODES.N,
|
||||
val qkReplyTapDismiss: Boolean = true,
|
||||
|
||||
@@ -31,6 +31,7 @@ interface SettingsView : QkView<SettingsState> {
|
||||
val startTimeSelectedIntent: Subject<Pair<Int, Int>>
|
||||
val endTimeSelectedIntent: Subject<Pair<Int, Int>>
|
||||
val textSizeSelectedIntent: Subject<Int>
|
||||
val notificationPreviewModeSelectedIntent: Subject<Int>
|
||||
val mmsSizeSelectedIntent: Observable<Int>
|
||||
|
||||
fun showNightModeDialog()
|
||||
@@ -39,6 +40,7 @@ interface SettingsView : QkView<SettingsState> {
|
||||
fun showStartTimePicker(hour: Int, minute: Int)
|
||||
fun showEndTimePicker(hour: Int, minute: Int)
|
||||
fun showTextSizePicker()
|
||||
fun showNotificationPreviewModeDialog()
|
||||
fun dismissTextSizePicker()
|
||||
fun showMmsSizePicker()
|
||||
fun dismissMmsSizePicker()
|
||||
|
||||
@@ -81,6 +81,10 @@ class SettingsViewModel : QkViewModel<SettingsView, SettingsState>(SettingsState
|
||||
disposables += prefs.notifications().asObservable()
|
||||
.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()
|
||||
.subscribe { enabled -> newState { it.copy(deliveryEnabled = enabled) } }
|
||||
|
||||
@@ -142,6 +146,8 @@ class SettingsViewModel : QkViewModel<SettingsView, SettingsState>(SettingsState
|
||||
|
||||
R.id.notifications -> navigator.showNotificationSettings()
|
||||
|
||||
R.id.notificationPreviews -> view.showNotificationPreviewModeDialog()
|
||||
|
||||
R.id.blocked -> navigator.showBlockedConversations()
|
||||
|
||||
R.id.delivery -> prefs.delivery.set(!prefs.delivery.get())
|
||||
@@ -200,6 +206,10 @@ class SettingsViewModel : QkViewModel<SettingsView, SettingsState>(SettingsState
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { prefs.textSize.set(it) }
|
||||
|
||||
view.notificationPreviewModeSelectedIntent
|
||||
.autoDisposable(view.scope())
|
||||
.subscribe { prefs.notificationPreviews().set(it) }
|
||||
|
||||
view.mmsSizeSelectedIntent
|
||||
.doOnNext { view.dismissMmsSizePicker() }
|
||||
.autoDisposable(view.scope())
|
||||
|
||||
Reference in New Issue
Block a user