From 17c300be7e3a1def136e1236a901c8b640471a7d Mon Sep 17 00:00:00 2001 From: tanvirahmod Date: Tue, 5 Jan 2021 17:54:56 +0600 Subject: [PATCH 1/6] Add setting to hide message content in notification --- .../activities/SettingsActivity.kt | 21 +++++++++ .../smsmessenger/extensions/Context.kt | 44 +++++++++++++------ .../smsmessenger/helpers/Config.kt | 4 ++ .../smsmessenger/helpers/Constants.kt | 6 +++ app/src/main/res/layout/activity_settings.xml | 31 +++++++++++++ app/src/main/res/values/strings.xml | 6 +++ 6 files changed, 98 insertions(+), 14 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/SettingsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/SettingsActivity.kt index c8d6949e..b421f16d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/SettingsActivity.kt @@ -13,6 +13,10 @@ import com.simplemobiletools.commons.helpers.* import com.simplemobiletools.commons.models.RadioItem import com.simplemobiletools.smsmessenger.R import com.simplemobiletools.smsmessenger.extensions.config +import com.simplemobiletools.smsmessenger.extensions.getConfigurationText +import com.simplemobiletools.smsmessenger.helpers.CONFIGURE_NAME +import com.simplemobiletools.smsmessenger.helpers.CONFIGURE_NAME_AND_MESSAGE +import com.simplemobiletools.smsmessenger.helpers.CONFIGURE_NO_DETAILS import com.simplemobiletools.smsmessenger.helpers.refreshMessages import kotlinx.android.synthetic.main.activity_settings.* import java.util.* @@ -35,6 +39,7 @@ class SettingsActivity : SimpleActivity() { setupChangeDateTimeFormat() setupFontSize() setupShowCharacterCounter() + setupConfigureNotification() updateTextColors(settings_scrollview) if (blockedNumbersAtPause != -1 && blockedNumbersAtPause != getBlockedNumbers().hashCode()) { @@ -116,4 +121,20 @@ class SettingsActivity : SimpleActivity() { config.showCharacterCounter = settings_show_character_counter.isChecked } } + + private fun setupConfigureNotification() { + settings_configure_notification_type.text = getConfigurationText(config.notificationSetting) + settings_configure_notification.setOnClickListener { + val items = arrayListOf( + RadioItem(CONFIGURE_NAME_AND_MESSAGE, getString(R.string.configure_name_and_message)), + RadioItem(CONFIGURE_NAME, getString(R.string.configure_name)), + RadioItem(CONFIGURE_NO_DETAILS, getString(R.string.configure_no_details)), + ) + + RadioGroupDialog(this@SettingsActivity, items, config.notificationSetting) { + config.notificationSetting = it as Int + settings_configure_notification_type.text = getConfigurationText(config.notificationSetting) + } + } + } } diff --git a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/extensions/Context.kt index b30cf279..fa7d0b3b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/extensions/Context.kt @@ -706,20 +706,30 @@ fun Context.showMessageNotification(address: String, body: String, threadId: Lon } val largeIcon = bitmap ?: SimpleContactsHelper(this).getContactLetterIcon(sender) - val builder = NotificationCompat.Builder(this, NOTIFICATION_CHANNEL) - .setContentTitle(sender) - .setContentText(body) - .setColor(config.primaryColor) - .setSmallIcon(R.drawable.ic_messenger) - .setLargeIcon(largeIcon) - .setStyle(NotificationCompat.BigTextStyle().setSummaryText(summaryText).bigText(body)) - .setContentIntent(pendingIntent) - .setPriority(NotificationCompat.PRIORITY_MAX) - .setDefaults(Notification.DEFAULT_LIGHTS) - .setCategory(Notification.CATEGORY_MESSAGE) - .setAutoCancel(true) - .setSound(soundUri, AudioManager.STREAM_NOTIFICATION) - if (replyAction != null) { + val builder = NotificationCompat.Builder(this, NOTIFICATION_CHANNEL).apply { + when (config.notificationSetting) { + CONFIGURE_NAME_AND_MESSAGE -> { + this.setContentTitle(sender) + this.setLargeIcon(largeIcon) + this.setContentText(body) + } + CONFIGURE_NAME -> { + this.setContentTitle(sender) + this.setLargeIcon(largeIcon) + } + } + this.color = config.primaryColor + this.setSmallIcon(R.drawable.ic_messenger) + this.setStyle(NotificationCompat.BigTextStyle().setSummaryText(summaryText).bigText(body)) + this.setContentIntent(pendingIntent) + this.priority = NotificationCompat.PRIORITY_MAX + this.setDefaults(Notification.DEFAULT_LIGHTS) + this.setCategory(Notification.CATEGORY_MESSAGE) + this.setAutoCancel(true) + this.setSound(soundUri, AudioManager.STREAM_NOTIFICATION) + } + + if (replyAction != null && config.notificationSetting == CONFIGURE_NAME_AND_MESSAGE) { builder.addAction(replyAction) } builder.addAction(R.drawable.ic_check_vector, getString(R.string.mark_as_read), markAsReadPendingIntent) @@ -727,3 +737,9 @@ fun Context.showMessageNotification(address: String, body: String, threadId: Lon notificationManager.notify(threadId.hashCode(), builder.build()) } + +fun Context.getConfigurationText(type: Int) = getString(when (type) { + CONFIGURE_NAME_AND_MESSAGE -> R.string.configure_name_and_message + CONFIGURE_NAME -> R.string.configure_name + else -> R.string.configure_no_details +}) diff --git a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/helpers/Config.kt b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/helpers/Config.kt index 451fe60f..ed65e60c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/helpers/Config.kt @@ -17,4 +17,8 @@ class Config(context: Context) : BaseConfig(context) { var showCharacterCounter: Boolean get() = prefs.getBoolean(SHOW_CHARACTER_COUNTER, false) set(showCharacterCounter) = prefs.edit().putBoolean(SHOW_CHARACTER_COUNTER, showCharacterCounter).apply() + + var notificationSetting: Int + get() = prefs.getInt(CONFIGURATION_NOTIFICATION_SETTING, CONFIGURE_NAME_AND_MESSAGE) + set(size) = prefs.edit().putInt(CONFIGURATION_NOTIFICATION_SETTING, size).apply() } diff --git a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/helpers/Constants.kt index 1705773f..11425c0a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/helpers/Constants.kt @@ -12,6 +12,7 @@ const val THREAD_ATTACHMENT_URIS = "thread_attachment_uris" const val USE_SIM_ID_PREFIX = "use_sim_id_" const val NOTIFICATION_CHANNEL = "simple_sms_messenger" const val SHOW_CHARACTER_COUNTER = "show_character_counter" +const val CONFIGURATION_NOTIFICATION_SETTING = "configuration_notification_setting" private const val PATH = "com.simplemobiletools.smsmessenger.action." const val MARK_AS_READ = PATH + "mark_as_read" @@ -25,6 +26,11 @@ const val THREAD_SENT_MESSAGE_ERROR = 4 const val THREAD_SENT_MESSAGE_SUCCESS = 5 const val THREAD_SENT_MESSAGE_SENDING = 6 +// configure notification setting constants +const val CONFIGURE_NAME_AND_MESSAGE = 1 +const val CONFIGURE_NAME = 2 +const val CONFIGURE_NO_DETAILS = 3 + fun refreshMessages() { EventBus.getDefault().post(Events.RefreshMessages()) } diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml index c71368f9..73b74258 100644 --- a/app/src/main/res/layout/activity_settings.xml +++ b/app/src/main/res/layout/activity_settings.xml @@ -172,5 +172,36 @@ app:switchPadding="@dimen/medium_margin" /> + + + + + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c40c26d6..990ae0d5 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -15,6 +15,12 @@ Sender doesn\'t support replies Draft Sending… + Configure Notification + + + Name and Message + Name + No Details New conversation From b65a78394e78e1607f24d547d4cf0bcb9f49175b Mon Sep 17 00:00:00 2001 From: Tibor Kaputa Date: Wed, 18 Aug 2021 12:45:08 +0200 Subject: [PATCH 2/6] Update SettingsActivity.kt --- .../activities/SettingsActivity.kt | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/SettingsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/SettingsActivity.kt index 9617b5a1..809190d6 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/SettingsActivity.kt @@ -13,10 +13,10 @@ import com.simplemobiletools.commons.helpers.* import com.simplemobiletools.commons.models.RadioItem import com.simplemobiletools.smsmessenger.R import com.simplemobiletools.smsmessenger.extensions.config -import com.simplemobiletools.smsmessenger.extensions.getConfigurationText -import com.simplemobiletools.smsmessenger.helpers.CONFIGURE_NAME -import com.simplemobiletools.smsmessenger.helpers.CONFIGURE_NAME_AND_MESSAGE -import com.simplemobiletools.smsmessenger.helpers.CONFIGURE_NO_DETAILS +import com.simplemobiletools.smsmessenger.extensions.getLockScreenVisibilityText +import com.simplemobiletools.smsmessenger.helpers.LOCK_SCREEN_NOTHING +import com.simplemobiletools.smsmessenger.helpers.LOCK_SCREEN_SENDER +import com.simplemobiletools.smsmessenger.helpers.LOCK_SCREEN_SENDER_MESSAGE import com.simplemobiletools.smsmessenger.helpers.refreshMessages import kotlinx.android.synthetic.main.activity_settings.* import java.util.* @@ -40,7 +40,7 @@ class SettingsActivity : SimpleActivity() { setupChangeDateTimeFormat() setupFontSize() setupShowCharacterCounter() - setupConfigureNotification() + setupLockScreenVisibility() updateTextColors(settings_scrollview) if (blockedNumbersAtPause != -1 && blockedNumbersAtPause != getBlockedNumbers().hashCode()) { @@ -113,7 +113,8 @@ class SettingsActivity : SimpleActivity() { RadioItem(FONT_SIZE_SMALL, getString(R.string.small)), RadioItem(FONT_SIZE_MEDIUM, getString(R.string.medium)), RadioItem(FONT_SIZE_LARGE, getString(R.string.large)), - RadioItem(FONT_SIZE_EXTRA_LARGE, getString(R.string.extra_large))) + RadioItem(FONT_SIZE_EXTRA_LARGE, getString(R.string.extra_large)) + ) RadioGroupDialog(this@SettingsActivity, items, config.fontSize) { config.fontSize = it as Int @@ -130,18 +131,18 @@ class SettingsActivity : SimpleActivity() { } } - private fun setupConfigureNotification() { - settings_configure_notification_type.text = getConfigurationText(config.notificationSetting) - settings_configure_notification.setOnClickListener { + private fun setupLockScreenVisibility() { + settings_lock_screen_visibility.text = getLockScreenVisibilityText(config.lockScreenVisibilitySetting) + settings_lock_screen_visibility_holder.setOnClickListener { val items = arrayListOf( - RadioItem(CONFIGURE_NAME_AND_MESSAGE, getString(R.string.configure_name_and_message)), - RadioItem(CONFIGURE_NAME, getString(R.string.configure_name)), - RadioItem(CONFIGURE_NO_DETAILS, getString(R.string.configure_no_details)), + RadioItem(LOCK_SCREEN_SENDER_MESSAGE, getString(R.string.sender_and_message)), + RadioItem(LOCK_SCREEN_SENDER, getString(R.string.sender_only)), + RadioItem(LOCK_SCREEN_NOTHING, getString(R.string.nothing)), ) - RadioGroupDialog(this@SettingsActivity, items, config.notificationSetting) { - config.notificationSetting = it as Int - settings_configure_notification_type.text = getConfigurationText(config.notificationSetting) + RadioGroupDialog(this@SettingsActivity, items, config.lockScreenVisibilitySetting) { + config.lockScreenVisibilitySetting = it as Int + settings_lock_screen_visibility.text = getLockScreenVisibilityText(config.lockScreenVisibilitySetting) } } } From f68bc5477110a121ce6d51c7c2a7a77f3d6ea55b Mon Sep 17 00:00:00 2001 From: Tibor Kaputa Date: Wed, 18 Aug 2021 12:45:33 +0200 Subject: [PATCH 3/6] Update Context.kt --- .../smsmessenger/extensions/Context.kt | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/extensions/Context.kt index 1b1a7448..f32db870 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/extensions/Context.kt @@ -710,13 +710,13 @@ fun Context.showMessageNotification(address: String, body: String, threadId: Lon val largeIcon = bitmap ?: SimpleContactsHelper(this).getContactLetterIcon(sender) val builder = NotificationCompat.Builder(this, NOTIFICATION_CHANNEL).apply { - when (config.notificationSetting) { - CONFIGURE_NAME_AND_MESSAGE -> { + when (config.lockScreenVisibilitySetting) { + LOCK_SCREEN_SENDER_MESSAGE -> { setContentTitle(sender) setLargeIcon(largeIcon) setContentText(body) } - CONFIGURE_NAME -> { + LOCK_SCREEN_SENDER -> { setContentTitle(sender) setLargeIcon(largeIcon) } @@ -733,7 +733,7 @@ fun Context.showMessageNotification(address: String, body: String, threadId: Lon setSound(soundUri, AudioManager.STREAM_NOTIFICATION) } - if (replyAction != null && config.notificationSetting == CONFIGURE_NAME_AND_MESSAGE) { + if (replyAction != null && config.lockScreenVisibilitySetting == LOCK_SCREEN_SENDER_MESSAGE) { builder.addAction(replyAction) } @@ -743,10 +743,10 @@ fun Context.showMessageNotification(address: String, body: String, threadId: Lon notificationManager.notify(threadId.hashCode(), builder.build()) } -fun Context.getConfigurationText(type: Int) = getString( +fun Context.getLockScreenVisibilityText(type: Int) = getString( when (type) { - CONFIGURE_NAME_AND_MESSAGE -> R.string.sender_and_message - CONFIGURE_NAME -> R.string.sender_only + LOCK_SCREEN_SENDER_MESSAGE -> R.string.sender_and_message + LOCK_SCREEN_SENDER -> R.string.sender_only else -> R.string.nothing } ) From 79c7645ab767d6c7ff7e221b197ee636145c7339 Mon Sep 17 00:00:00 2001 From: Tibor Kaputa Date: Wed, 18 Aug 2021 12:45:51 +0200 Subject: [PATCH 4/6] Update Config.kt --- .../com/simplemobiletools/smsmessenger/helpers/Config.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/helpers/Config.kt b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/helpers/Config.kt index ed65e60c..7b767cd3 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/helpers/Config.kt @@ -18,7 +18,7 @@ class Config(context: Context) : BaseConfig(context) { get() = prefs.getBoolean(SHOW_CHARACTER_COUNTER, false) set(showCharacterCounter) = prefs.edit().putBoolean(SHOW_CHARACTER_COUNTER, showCharacterCounter).apply() - var notificationSetting: Int - get() = prefs.getInt(CONFIGURATION_NOTIFICATION_SETTING, CONFIGURE_NAME_AND_MESSAGE) - set(size) = prefs.edit().putInt(CONFIGURATION_NOTIFICATION_SETTING, size).apply() + var lockScreenVisibilitySetting: Int + get() = prefs.getInt(LOCK_SCREEN_VISIBILITY, LOCK_SCREEN_SENDER_MESSAGE) + set(lockScreenVisibilitySetting) = prefs.edit().putInt(LOCK_SCREEN_VISIBILITY, lockScreenVisibilitySetting).apply() } From ecbf29ec83c1bc7416bad54072a24299c85b1230 Mon Sep 17 00:00:00 2001 From: Tibor Kaputa Date: Wed, 18 Aug 2021 12:46:03 +0200 Subject: [PATCH 5/6] Update Constants.kt --- .../smsmessenger/helpers/Constants.kt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/helpers/Constants.kt index ca72c64a..f73c12e0 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/helpers/Constants.kt @@ -13,7 +13,7 @@ const val SEARCHED_MESSAGE_ID = "searched_message_id" const val USE_SIM_ID_PREFIX = "use_sim_id_" const val NOTIFICATION_CHANNEL = "simple_sms_messenger" const val SHOW_CHARACTER_COUNTER = "show_character_counter" -const val CONFIGURATION_NOTIFICATION_SETTING = "configuration_notification_setting" +const val LOCK_SCREEN_VISIBILITY = "lock_screen_visibility" private const val PATH = "com.simplemobiletools.smsmessenger.action." const val MARK_AS_READ = PATH + "mark_as_read" @@ -27,10 +27,10 @@ const val THREAD_SENT_MESSAGE_ERROR = 4 const val THREAD_SENT_MESSAGE_SUCCESS = 5 const val THREAD_SENT_MESSAGE_SENDING = 6 -// configure notification setting constants -const val CONFIGURE_NAME_AND_MESSAGE = 1 -const val CONFIGURE_NAME = 2 -const val CONFIGURE_NO_DETAILS = 3 +// lock screen visibility constants +const val LOCK_SCREEN_SENDER_MESSAGE = 1 +const val LOCK_SCREEN_SENDER = 2 +const val LOCK_SCREEN_NOTHING = 3 fun refreshMessages() { EventBus.getDefault().post(Events.RefreshMessages()) From 5d782a7f7ad178b6578dc1f42ffc8c87b9d68ca0 Mon Sep 17 00:00:00 2001 From: Tibor Kaputa Date: Wed, 18 Aug 2021 12:46:15 +0200 Subject: [PATCH 6/6] Update activity_settings.xml --- app/src/main/res/layout/activity_settings.xml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml index a54f0241..1900f25b 100644 --- a/app/src/main/res/layout/activity_settings.xml +++ b/app/src/main/res/layout/activity_settings.xml @@ -195,7 +195,7 @@ + android:text="@string/lock_screen_visibility" /> -