mirror of
https://github.com/SimpleMobileTools/Simple-SMS-Messenger.git
synced 2025-06-05 21:49:22 +02:00
Add setting to hide message content in notification
This commit is contained in:
@@ -13,6 +13,10 @@ import com.simplemobiletools.commons.helpers.*
|
|||||||
import com.simplemobiletools.commons.models.RadioItem
|
import com.simplemobiletools.commons.models.RadioItem
|
||||||
import com.simplemobiletools.smsmessenger.R
|
import com.simplemobiletools.smsmessenger.R
|
||||||
import com.simplemobiletools.smsmessenger.extensions.config
|
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 com.simplemobiletools.smsmessenger.helpers.refreshMessages
|
||||||
import kotlinx.android.synthetic.main.activity_settings.*
|
import kotlinx.android.synthetic.main.activity_settings.*
|
||||||
import java.util.*
|
import java.util.*
|
||||||
@@ -35,6 +39,7 @@ class SettingsActivity : SimpleActivity() {
|
|||||||
setupChangeDateTimeFormat()
|
setupChangeDateTimeFormat()
|
||||||
setupFontSize()
|
setupFontSize()
|
||||||
setupShowCharacterCounter()
|
setupShowCharacterCounter()
|
||||||
|
setupConfigureNotification()
|
||||||
updateTextColors(settings_scrollview)
|
updateTextColors(settings_scrollview)
|
||||||
|
|
||||||
if (blockedNumbersAtPause != -1 && blockedNumbersAtPause != getBlockedNumbers().hashCode()) {
|
if (blockedNumbersAtPause != -1 && blockedNumbersAtPause != getBlockedNumbers().hashCode()) {
|
||||||
@@ -116,4 +121,20 @@ class SettingsActivity : SimpleActivity() {
|
|||||||
config.showCharacterCounter = settings_show_character_counter.isChecked
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -706,20 +706,30 @@ fun Context.showMessageNotification(address: String, body: String, threadId: Lon
|
|||||||
}
|
}
|
||||||
|
|
||||||
val largeIcon = bitmap ?: SimpleContactsHelper(this).getContactLetterIcon(sender)
|
val largeIcon = bitmap ?: SimpleContactsHelper(this).getContactLetterIcon(sender)
|
||||||
val builder = NotificationCompat.Builder(this, NOTIFICATION_CHANNEL)
|
val builder = NotificationCompat.Builder(this, NOTIFICATION_CHANNEL).apply {
|
||||||
.setContentTitle(sender)
|
when (config.notificationSetting) {
|
||||||
.setContentText(body)
|
CONFIGURE_NAME_AND_MESSAGE -> {
|
||||||
.setColor(config.primaryColor)
|
this.setContentTitle(sender)
|
||||||
.setSmallIcon(R.drawable.ic_messenger)
|
this.setLargeIcon(largeIcon)
|
||||||
.setLargeIcon(largeIcon)
|
this.setContentText(body)
|
||||||
.setStyle(NotificationCompat.BigTextStyle().setSummaryText(summaryText).bigText(body))
|
}
|
||||||
.setContentIntent(pendingIntent)
|
CONFIGURE_NAME -> {
|
||||||
.setPriority(NotificationCompat.PRIORITY_MAX)
|
this.setContentTitle(sender)
|
||||||
.setDefaults(Notification.DEFAULT_LIGHTS)
|
this.setLargeIcon(largeIcon)
|
||||||
.setCategory(Notification.CATEGORY_MESSAGE)
|
}
|
||||||
.setAutoCancel(true)
|
}
|
||||||
.setSound(soundUri, AudioManager.STREAM_NOTIFICATION)
|
this.color = config.primaryColor
|
||||||
if (replyAction != null) {
|
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(replyAction)
|
||||||
}
|
}
|
||||||
builder.addAction(R.drawable.ic_check_vector, getString(R.string.mark_as_read), markAsReadPendingIntent)
|
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())
|
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
|
||||||
|
})
|
||||||
|
@@ -17,4 +17,8 @@ class Config(context: Context) : BaseConfig(context) {
|
|||||||
var showCharacterCounter: Boolean
|
var showCharacterCounter: Boolean
|
||||||
get() = prefs.getBoolean(SHOW_CHARACTER_COUNTER, false)
|
get() = prefs.getBoolean(SHOW_CHARACTER_COUNTER, false)
|
||||||
set(showCharacterCounter) = prefs.edit().putBoolean(SHOW_CHARACTER_COUNTER, showCharacterCounter).apply()
|
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()
|
||||||
}
|
}
|
||||||
|
@@ -12,6 +12,7 @@ const val THREAD_ATTACHMENT_URIS = "thread_attachment_uris"
|
|||||||
const val USE_SIM_ID_PREFIX = "use_sim_id_"
|
const val USE_SIM_ID_PREFIX = "use_sim_id_"
|
||||||
const val NOTIFICATION_CHANNEL = "simple_sms_messenger"
|
const val NOTIFICATION_CHANNEL = "simple_sms_messenger"
|
||||||
const val SHOW_CHARACTER_COUNTER = "show_character_counter"
|
const val SHOW_CHARACTER_COUNTER = "show_character_counter"
|
||||||
|
const val CONFIGURATION_NOTIFICATION_SETTING = "configuration_notification_setting"
|
||||||
|
|
||||||
private const val PATH = "com.simplemobiletools.smsmessenger.action."
|
private const val PATH = "com.simplemobiletools.smsmessenger.action."
|
||||||
const val MARK_AS_READ = PATH + "mark_as_read"
|
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_SUCCESS = 5
|
||||||
const val THREAD_SENT_MESSAGE_SENDING = 6
|
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() {
|
fun refreshMessages() {
|
||||||
EventBus.getDefault().post(Events.RefreshMessages())
|
EventBus.getDefault().post(Events.RefreshMessages())
|
||||||
}
|
}
|
||||||
|
@@ -172,5 +172,36 @@
|
|||||||
app:switchPadding="@dimen/medium_margin" />
|
app:switchPadding="@dimen/medium_margin" />
|
||||||
|
|
||||||
</RelativeLayout>
|
</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>
|
</LinearLayout>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
@@ -15,6 +15,12 @@
|
|||||||
<string name="no_reply_support">Sender doesn\'t support replies</string>
|
<string name="no_reply_support">Sender doesn\'t support replies</string>
|
||||||
<string name="draft">Draft</string>
|
<string name="draft">Draft</string>
|
||||||
<string name="sending">Sending…</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 -->
|
<!-- New conversation -->
|
||||||
<string name="new_conversation">New conversation</string>
|
<string name="new_conversation">New conversation</string>
|
||||||
|
Reference in New Issue
Block a user