Skip to content

Commit

Permalink
s/severity/tag
Browse files Browse the repository at this point in the history
Signed-off-by: mueller-ma <[email protected]>
  • Loading branch information
mueller-ma committed Jul 9, 2024
1 parent 0359833 commit bd203c4
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class FcmMessageListenerService : FirebaseMessagingService() {
// in that case. If that also isn't present, don't show time at all.
createdTimestamp = data["timestamp"]?.toLongOrNull() ?: 0,
icon = data["icon"].toOH2IconResource(),
severity = data["tag"],
tag = data["tag"],
actions = actions,
onClickAction = data["on-click"].toCloudNotificationAction(),
mediaAttachmentUrl = data["media-attachment-url"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class NotificationHelper(private val context: Context) {
private val notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager

suspend fun showNotification(message: CloudNotification) {
createChannelForSeverity(message.severity)
createChannelForTag(message.tag)
val n = makeNotification(message, message.idHash, createDeleteIntent(message.idHash))
notificationManager.notify(message.idHash, n)
updateGroupNotification()
Expand Down Expand Up @@ -93,16 +93,16 @@ class NotificationHelper(private val context: Context) {
)
}

private fun createChannelForSeverity(severity: String?) {
private fun createChannelForTag(tag: String?) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
return
}
NotificationUpdateObserver.createNotificationChannels(context)
if (!severity.isNullOrEmpty()) {
if (!tag.isNullOrEmpty()) {
with(
NotificationChannel(
getChannelId(severity),
context.getString(R.string.notification_channel_severity_value, severity),
getChannelId(tag),
context.getString(R.string.notification_channel_severity_value, tag),
NotificationManager.IMPORTANCE_DEFAULT
)
) {
Expand All @@ -111,7 +111,7 @@ class NotificationHelper(private val context: Context) {
enableLights(true)
lightColor = ContextCompat.getColor(context, R.color.openhab_orange)
group = NotificationUpdateObserver.CHANNEL_GROUP_MESSAGES
description = context.getString(R.string.notification_channel_severity_value_description, severity)
description = context.getString(R.string.notification_channel_severity_value_description, tag)
notificationManager.createNotificationChannel(this)
}
}
Expand All @@ -134,7 +134,7 @@ class NotificationHelper(private val context: Context) {
} else {
NotificationHandlingReceiver.createActionPendingIntent(context, notificationId, message.onClickAction)
}
val channelId = getChannelId(message.severity)
val channelId = getChannelId(message.tag)

val publicText = context.resources.getQuantityString(R.plurals.summary_notification_text, 1, 1)
val publicVersion = makeNotificationBuilder(channelId, message.createdTimestamp)
Expand All @@ -149,7 +149,7 @@ class NotificationHelper(private val context: Context) {
.setSound(context.getPrefs().getNotificationTone())
.setContentTitle(message.title)
.setContentText(message.message)
.setSubText(message.severity)
.setSubText(message.tag)
.setContentIntent(contentIntent)
.setDeleteIntent(deleteIntent)
.setVisibility(NotificationCompat.VISIBILITY_PRIVATE)
Expand Down Expand Up @@ -259,10 +259,10 @@ class NotificationHelper(private val context: Context) {
companion object {
private val TAG = NotificationHelper::class.java.simpleName

private fun getChannelId(severity: String?) = if (severity.isNullOrEmpty()) {
private fun getChannelId(tag: String?) = if (tag.isNullOrEmpty()) {
NotificationUpdateObserver.CHANNEL_ID_MESSAGE_DEFAULT
} else {
"severity-$severity"
"severity-$tag"
}

internal const val SUMMARY_NOTIFICATION_ID = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ data class CloudNotification internal constructor(
val message: String,
val createdTimestamp: Long,
val icon: IconResource?,
val severity: String?,
val tag: String?,
val actions: List<CloudNotificationAction>?,
val onClickAction: CloudNotificationAction?,
val mediaAttachmentUrl: String?
Expand Down Expand Up @@ -99,7 +99,7 @@ fun JSONObject.toCloudNotification(): CloudNotification {
message = payload?.getString("message") ?: getString("message"),
createdTimestamp = created,
icon = payload?.optStringOrNull("icon").toOH2IconResource() ?: optStringOrNull("icon").toOH2IconResource(),
severity = payload?.optStringOrNull("severity") ?: optStringOrNull("severity"),
tag = payload?.optStringOrNull("tag") ?: optStringOrNull("severity"),
actions = payload?.optJSONArray("actions")?.map { it.toCloudNotificationAction() }?.filterNotNull(),
onClickAction = payload?.optStringOrNull("on-click").toCloudNotificationAction(),
mediaAttachmentUrl = payload?.optStringOrNull("media-attachment-url")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class CloudNotificationAdapter(context: Context, private val loadMoreListener: (
private val createdView: TextView = itemView.findViewById(R.id.notificationCreated)
private val iconView: WidgetImageView = itemView.findViewById(R.id.notificationIcon)
private val imageView: WidgetImageView = itemView.findViewById(R.id.notificationImage)
private val severityView: TextView = itemView.findViewById(R.id.notificationSeverity)
private val tagView: TextView = itemView.findViewById(R.id.notificationTag)

fun bind(notification: CloudNotification) {
createdView.text = DateUtils.getRelativeDateTimeString(
Expand Down Expand Up @@ -143,8 +143,8 @@ class CloudNotificationAdapter(context: Context, private val loadMoreListener: (
}
}
}
severityView.text = notification.severity
severityView.isGone = notification.severity.isNullOrEmpty()
tagView.text = notification.tag
tagView.isGone = notification.tag.isNullOrEmpty()
}
}

Expand Down
2 changes: 1 addition & 1 deletion mobile/src/main/res/layout/notificationlist_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
tools:text="6 hours ago" />

<TextView
android:id="@+id/notificationSeverity"
android:id="@+id/notificationTag"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
Expand Down

0 comments on commit bd203c4

Please sign in to comment.