srctree

Robin Linden parent 02dfbd7d 31730335
Add a mark-as-read button to message notifications

inlinesplit
atox/src/main/kotlin/ActionReceiver.kt added: 36, removed: 5, total 31
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2021 aTox contributors
// SPDX-FileCopyrightText: 2021-2022 aTox contributors
//
// SPDX-License-Identifier: GPL-3.0-only
 
@@ -32,6 +32,11 @@ import ltd.evilcorp.domain.tox.Tox
const val KEY_TEXT_REPLY = "text_reply"
const val KEY_CALL = "accept_or_reject_call"
const val KEY_CONTACT_PK = "contact_pk"
const val KEY_ACTION = "action"
 
enum class Action {
MarkAsRead,
}
 
private const val TAG = "ActionReceiver"
 
@@ -119,5 +124,14 @@ class ActionReceiver : BroadcastReceiver() {
"ignore" -> callManager.removePendingCall(pk)
}
}
 
when (intent.getSerializableExtra(KEY_ACTION) as Action?) {
Action.MarkAsRead -> scope.launch {
val pk = intent.getStringExtra(KEY_CONTACT_PK) ?: return@launch
contactRepository.setHasUnreadMessages(pk, false)
notificationHelper.dismissNotifications(PublicKey(pk))
}
null -> Log.e(TAG, "Missing action in intent $intent")
}
}
}
 
atox/src/main/kotlin/ui/NotificationHelper.kt added: 36, removed: 5, total 31
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2019-2021 aTox contributors
// SPDX-FileCopyrightText: 2019-2022 aTox contributors
//
// SPDX-License-Identifier: GPL-3.0-only
 
@@ -30,7 +30,9 @@ import com.squareup.picasso.Picasso
import com.squareup.picasso.Transformation
import javax.inject.Inject
import javax.inject.Singleton
import ltd.evilcorp.atox.Action
import ltd.evilcorp.atox.ActionReceiver
import ltd.evilcorp.atox.KEY_ACTION
import ltd.evilcorp.atox.KEY_CALL
import ltd.evilcorp.atox.KEY_CONTACT_PK
import ltd.evilcorp.atox.KEY_TEXT_REPLY
@@ -144,6 +146,20 @@ class NotificationHelper @Inject constructor(
.setAllowGeneratedReplies(true)
.build()
)
.addAction(
NotificationCompat.Action.Builder(
null,
context.getString(R.string.mark_as_read),
PendingIntentCompat.getBroadcast(
context,
"${contact.publicKey}_mark_as_read".hashCode(),
Intent(context, ActionReceiver::class.java)
.putExtra(KEY_CONTACT_PK, contact.publicKey)
.putExtra(KEY_ACTION, Action.MarkAsRead),
PendingIntent.FLAG_UPDATE_CURRENT,
)
).setSemanticAction(NotificationCompat.Action.SEMANTIC_ACTION_MARK_AS_READ).build()
)
 
if (outgoing) {
notificationBuilder.setSilent(true)
 
atox/src/main/res/values/strings.xml added: 36, removed: 5, total 31
@@ -184,4 +184,5 @@
<string name="atox_profile_locked">aTox profile locked</string>
<string name="tap_to_unlock_and_start_atox">Tap to unlock your profile and start aTox</string>
<string name="share">Share</string>
<string name="mark_as_read">Mark as read</string>
</resources>
No newline at end of file