From 1e992434c4304d5f7b7ec29f0d34f7aff128028a Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Fri, 30 Oct 2020 10:57:05 +0100 Subject: [PATCH] Added setting to automatically mark as read a chat room when dismissing the notification --- CHANGELOG.md | 9 +++++++-- .../viewmodels/ChatSettingsViewModel.kt | 8 ++++++++ .../java/org/linphone/core/CorePreferences.kt | 6 ++++++ .../notifications/NotificationsManager.kt | 17 +++++++++++++---- .../res/layout/settings_chat_fragment.xml | 19 +++++++++++++------ app/src/main/res/values/strings.xml | 2 ++ 6 files changed, 49 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e57fee818..df973b46a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,21 +17,26 @@ This version is a full rewrite of the app in kotlin, using modern Android compon ### Added - Using linphone SDK 5.0 API to better handle audio route (see linphone-sdk changelog) -- More settings are available - Display video in recordings if available - "Swipe left to delete" action available on calls history, contacts & chat rooms list - Improved preview when sharing video files through the chat - Android 11 people & conversation compliant +- New animations between fragments and for unread chat messages / missed calls counters (can be disabled) +- Option to mark messages as read when dismissing the notification +- More settings are available ### Changed - Dropped Android 5 compatibility, Android 6 or higher (API 23) is now required to install the app - Call history view groups call from the same SIP URI (like linphone-iphone) - Improved how Android native contacts are used -- Removed "back-to-call" button from dialer & chat views, use notification or overlay (see call settings) - Switched to material design for text input fields & switches - Launcher shortcuts can be to either contacts or chat rooms +### Removed + +- Removed "back-to-call" button from dialer & chat views, use notification or overlay (see call settings) + ### [4.4.0] - 2021-03-29 ### Added diff --git a/app/src/main/java/org/linphone/activities/main/settings/viewmodels/ChatSettingsViewModel.kt b/app/src/main/java/org/linphone/activities/main/settings/viewmodels/ChatSettingsViewModel.kt index 7b77c50ae..a2bc186bf 100644 --- a/app/src/main/java/org/linphone/activities/main/settings/viewmodels/ChatSettingsViewModel.kt +++ b/app/src/main/java/org/linphone/activities/main/settings/viewmodels/ChatSettingsViewModel.kt @@ -26,6 +26,13 @@ import org.linphone.activities.main.settings.SettingListenerStub import org.linphone.utils.Event class ChatSettingsViewModel : GenericSettingsViewModel() { + val markAsReadNotifDismissalListener = object : SettingListenerStub() { + override fun onBoolValueChanged(newValue: Boolean) { + prefs.markAsReadUponChatMessageNotificationDismissal = newValue + } + } + val markAsReadNotifDismissal = MutableLiveData() + val fileSharingUrlListener = object : SettingListenerStub() { override fun onTextValueChanged(newValue: String) { core.logCollectionUploadServerUrl = newValue @@ -112,6 +119,7 @@ class ChatSettingsViewModel : GenericSettingsViewModel() { val goToAndroidNotificationSettingsEvent = MutableLiveData>() init { + markAsReadNotifDismissal.value = prefs.markAsReadUponChatMessageNotificationDismissal downloadedMediaPublic.value = prefs.makePublicMediaFilesDownloaded hideNotificationContent.value = prefs.hideChatMessageContentInNotification initAutoDownloadList() diff --git a/app/src/main/java/org/linphone/core/CorePreferences.kt b/app/src/main/java/org/linphone/core/CorePreferences.kt index fbe6e574e..f6f92ff26 100644 --- a/app/src/main/java/org/linphone/core/CorePreferences.kt +++ b/app/src/main/java/org/linphone/core/CorePreferences.kt @@ -100,6 +100,12 @@ class CorePreferences constructor(private val context: Context) { /* Chat */ + var markAsReadUponChatMessageNotificationDismissal: Boolean + get() = config.getBool("app", "mark_as_read_notif_dismissal", false) + set(value) { + config.setBool("app", "mark_as_read_notif_dismissal", value) + } + var makePublicMediaFilesDownloaded: Boolean // Keep old name for backward compatibility get() = config.getBool("app", "make_downloaded_images_public_in_gallery", true) diff --git a/app/src/main/java/org/linphone/notifications/NotificationsManager.kt b/app/src/main/java/org/linphone/notifications/NotificationsManager.kt index d0b5e611c..0045ada2a 100644 --- a/app/src/main/java/org/linphone/notifications/NotificationsManager.kt +++ b/app/src/main/java/org/linphone/notifications/NotificationsManager.kt @@ -662,7 +662,7 @@ class NotificationsManager(private val context: Context) { } style.isGroupConversation = notifiable.isGroup - return NotificationCompat.Builder(context, context.getString(R.string.notification_channel_chat_id)) + val notificationBuilder = NotificationCompat.Builder(context, context.getString(R.string.notification_channel_chat_id)) .setSmallIcon(R.drawable.topbar_chat_notification) .setAutoCancel(true) .setContentIntent(pendingIntent) @@ -678,7 +678,12 @@ class NotificationsManager(private val context: Context) { .addAction(getReplyMessageAction(notifiable)) .addAction(getMarkMessageAsReadAction(notifiable)) .setShortcutId(shortcutId) - .build() + if (corePreferences.markAsReadUponChatMessageNotificationDismissal) { + Log.i("[Notifications Manager] Chat room will be marked as read when notification will be dismissed") + notificationBuilder + .setDeleteIntent(getMarkMessageAsReadPendingIntent(notifiable)) + } + return notificationBuilder.build() } /* Notifications actions */ @@ -743,18 +748,22 @@ class NotificationsManager(private val context: Context) { .build() } - private fun getMarkMessageAsReadAction(notifiable: Notifiable): NotificationCompat.Action { + private fun getMarkMessageAsReadPendingIntent(notifiable: Notifiable): PendingIntent { val markAsReadIntent = Intent(context, NotificationBroadcastReceiver::class.java) markAsReadIntent.action = INTENT_MARK_AS_READ_ACTION markAsReadIntent.putExtra(INTENT_NOTIF_ID, notifiable.notificationId) markAsReadIntent.putExtra(INTENT_LOCAL_IDENTITY, notifiable.localIdentity) - val markAsReadPendingIntent = PendingIntent.getBroadcast( + return PendingIntent.getBroadcast( context, notifiable.notificationId, markAsReadIntent, PendingIntent.FLAG_UPDATE_CURRENT ) + } + + private fun getMarkMessageAsReadAction(notifiable: Notifiable): NotificationCompat.Action { + val markAsReadPendingIntent = getMarkMessageAsReadPendingIntent(notifiable) return NotificationCompat.Action.Builder( R.drawable.chat_send_over, context.getString(R.string.received_chat_notification_mark_as_read_label), diff --git a/app/src/main/res/layout/settings_chat_fragment.xml b/app/src/main/res/layout/settings_chat_fragment.xml index 82b9750d3..ed59d1d7a 100644 --- a/app/src/main/res/layout/settings_chat_fragment.xml +++ b/app/src/main/res/layout/settings_chat_fragment.xml @@ -66,12 +66,11 @@ android:orientation="vertical"> + layout="@layout/settings_widget_switch" + linphone:title="@{@string/chat_settings_mark_as_read_notif_dismissal_title}" + linphone:subtitle="@{@string/chat_settings_mark_as_read_notif_dismissal_summary}" + linphone:listener="@{viewModel.markAsReadNotifDismissalListener}" + linphone:checked="@={viewModel.markAsReadNotifDismissal}"/> + + Android notification settings + Mark as read upon notification dismissal + Sharing server URL Do not edit unless you know what you are doing! Auto download incoming files policy