Minor code improvement
This commit is contained in:
parent
9e9eebc5ff
commit
1d675a1be9
3 changed files with 14 additions and 15 deletions
|
|
@ -97,7 +97,7 @@ class ConversationDetailsActivity : SimpleActivity() {
|
|||
customNotificationsButton.setOnClickListener {
|
||||
Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS).apply {
|
||||
putExtra(Settings.EXTRA_APP_PACKAGE, packageName)
|
||||
putExtra(Settings.EXTRA_CHANNEL_ID, threadId.hashCode().toString())
|
||||
putExtra(Settings.EXTRA_CHANNEL_ID, threadId.toString())
|
||||
startActivity(this)
|
||||
}
|
||||
}
|
||||
|
|
@ -113,7 +113,7 @@ class ConversationDetailsActivity : SimpleActivity() {
|
|||
.setLegacyStreamType(AudioManager.STREAM_NOTIFICATION)
|
||||
.build()
|
||||
|
||||
NotificationChannel(threadId.hashCode().toString(), name, NotificationManager.IMPORTANCE_HIGH).apply {
|
||||
NotificationChannel(threadId.toString(), name, NotificationManager.IMPORTANCE_HIGH).apply {
|
||||
setBypassDnd(false)
|
||||
enableLights(true)
|
||||
setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION), audioAttributes)
|
||||
|
|
@ -124,7 +124,7 @@ class ConversationDetailsActivity : SimpleActivity() {
|
|||
|
||||
@RequiresApi(Build.VERSION_CODES.O)
|
||||
private fun removeNotificationChannel() {
|
||||
notificationManager.deleteNotificationChannel(threadId.hashCode().toString())
|
||||
notificationManager.deleteNotificationChannel(threadId.toString())
|
||||
}
|
||||
|
||||
private fun setupTextViews() {
|
||||
|
|
|
|||
|
|
@ -694,7 +694,7 @@ fun Context.deleteConversation(threadId: Long) {
|
|||
|
||||
if (config.customNotifications.contains(threadId.toString()) && isOreoPlus()) {
|
||||
config.removeCustomNotificationsByThreadId(threadId)
|
||||
notificationManager.deleteNotificationChannel(threadId.hashCode().toString())
|
||||
notificationManager.deleteNotificationChannel(threadId.toString())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -45,14 +45,13 @@ class NotificationHelper(private val context: Context) {
|
|||
sender: String?,
|
||||
alertOnlyOnce: Boolean = false
|
||||
) {
|
||||
val notificationId = threadId.hashCode()
|
||||
|
||||
val hasCustomNotifications = context.config.customNotifications.contains(threadId.toString())
|
||||
val notificationChannel = if (hasCustomNotifications) notificationId.toString() else NOTIFICATION_CHANNEL
|
||||
val notificationChannelId = if (hasCustomNotifications) threadId.toString() else NOTIFICATION_CHANNEL
|
||||
if (!hasCustomNotifications) {
|
||||
maybeCreateChannel(notificationChannel, context.getString(R.string.channel_received_sms))
|
||||
maybeCreateChannel(notificationChannelId, context.getString(R.string.channel_received_sms))
|
||||
}
|
||||
|
||||
val notificationId = threadId.hashCode()
|
||||
val contentIntent = Intent(context, ThreadActivity::class.java).apply {
|
||||
putExtra(THREAD_ID, threadId)
|
||||
}
|
||||
|
|
@ -103,7 +102,7 @@ class NotificationHelper(private val context: Context) {
|
|||
} else {
|
||||
null
|
||||
}
|
||||
val builder = NotificationCompat.Builder(context, notificationChannel).apply {
|
||||
val builder = NotificationCompat.Builder(context, notificationChannelId).apply {
|
||||
when (context.config.lockScreenVisibilitySetting) {
|
||||
LOCK_SCREEN_SENDER_MESSAGE -> {
|
||||
setLargeIcon(largeIcon)
|
||||
|
|
@ -134,13 +133,13 @@ class NotificationHelper(private val context: Context) {
|
|||
}
|
||||
|
||||
builder.addAction(org.fossify.commons.R.drawable.ic_check_vector, context.getString(R.string.mark_as_read), markAsReadPendingIntent)
|
||||
.setChannelId(notificationChannel)
|
||||
.setChannelId(notificationChannelId)
|
||||
if (isNoReplySms) {
|
||||
builder.addAction(
|
||||
org.fossify.commons.R.drawable.ic_delete_vector,
|
||||
context.getString(org.fossify.commons.R.string.delete),
|
||||
deleteSmsPendingIntent
|
||||
).setChannelId(notificationChannel)
|
||||
).setChannelId(notificationChannelId)
|
||||
}
|
||||
notificationManager.notify(notificationId, builder.build())
|
||||
}
|
||||
|
|
@ -148,9 +147,9 @@ class NotificationHelper(private val context: Context) {
|
|||
@SuppressLint("NewApi")
|
||||
fun showSendingFailedNotification(recipientName: String, threadId: Long) {
|
||||
val hasCustomNotifications = context.config.customNotifications.contains(threadId.toString())
|
||||
val notificationChannel = if (hasCustomNotifications) threadId.hashCode().toString() else NOTIFICATION_CHANNEL
|
||||
val notificationChannelId = if (hasCustomNotifications) threadId.toString() else NOTIFICATION_CHANNEL
|
||||
if (!hasCustomNotifications) {
|
||||
maybeCreateChannel(notificationChannel, context.getString(R.string.message_not_sent_short))
|
||||
maybeCreateChannel(notificationChannelId, context.getString(R.string.message_not_sent_short))
|
||||
}
|
||||
|
||||
val notificationId = generateRandomId().hashCode()
|
||||
|
|
@ -161,7 +160,7 @@ class NotificationHelper(private val context: Context) {
|
|||
|
||||
val summaryText = String.format(context.getString(R.string.message_sending_error), recipientName)
|
||||
val largeIcon = SimpleContactsHelper(context).getContactLetterIcon(recipientName)
|
||||
val builder = NotificationCompat.Builder(context, notificationChannel)
|
||||
val builder = NotificationCompat.Builder(context, notificationChannelId)
|
||||
.setContentTitle(context.getString(R.string.message_not_sent_short))
|
||||
.setContentText(summaryText)
|
||||
.setColor(context.getProperPrimaryColor())
|
||||
|
|
@ -173,7 +172,7 @@ class NotificationHelper(private val context: Context) {
|
|||
.setDefaults(Notification.DEFAULT_LIGHTS)
|
||||
.setCategory(Notification.CATEGORY_MESSAGE)
|
||||
.setAutoCancel(true)
|
||||
.setChannelId(notificationChannel)
|
||||
.setChannelId(notificationChannelId)
|
||||
|
||||
notificationManager.notify(notificationId, builder.build())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue