Add setting to hide message content in notification

This commit is contained in:
tanvirahmod
2021-01-05 17:54:56 +06:00
parent 7cb605ce58
commit 17c300be7e
6 changed files with 98 additions and 14 deletions

View File

@@ -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)
}
}
}
}

View File

@@ -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
})

View File

@@ -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()
}

View File

@@ -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())
}

View File

@@ -172,5 +172,36 @@
app:switchPadding="@dimen/medium_margin" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/settings_configure_notification_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/medium_margin"
android:background="?attr/selectableItemBackground"
android:paddingLeft="@dimen/normal_margin"
android:paddingTop="@dimen/activity_margin"
android:paddingRight="@dimen/normal_margin"
android:paddingBottom="@dimen/activity_margin">
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/settings_configure_notification"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:paddingStart="@dimen/medium_margin"
android:text="@string/configure_notification" />
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/settings_configure_notification_type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_marginEnd="@dimen/medium_margin"
android:background="@null"
android:clickable="false" />
</RelativeLayout>
</LinearLayout>
</ScrollView>

View File

@@ -15,6 +15,12 @@
<string name="no_reply_support">Sender doesn\'t support replies</string>
<string name="draft">Draft</string>
<string name="sending">Sending…</string>
<string name="configure_notification">Configure Notification</string>
<!-- Configuration Settings -->
<string name="configure_name_and_message">Name and Message</string>
<string name="configure_name">Name</string>
<string name="configure_no_details">No Details</string>
<!-- New conversation -->
<string name="new_conversation">New conversation</string>