Use better names for API.
This commit is contained in:
parent
7ee00a65d8
commit
6fe85dc579
5 changed files with 23 additions and 23 deletions
|
|
@ -19,8 +19,8 @@ import io.element.android.libraries.di.annotations.ApplicationContext
|
|||
import timber.log.Timber
|
||||
|
||||
interface NotificationDisplayer {
|
||||
fun showNotificationMessage(tag: String?, id: Int, notification: Notification): Boolean
|
||||
fun cancelNotificationMessage(tag: String?, id: Int)
|
||||
fun showNotification(tag: String?, id: Int, notification: Notification): Boolean
|
||||
fun cancelNotification(tag: String?, id: Int)
|
||||
fun displayDiagnosticNotification(notification: Notification): Boolean
|
||||
fun dismissDiagnosticNotification()
|
||||
}
|
||||
|
|
@ -30,7 +30,7 @@ class DefaultNotificationDisplayer(
|
|||
@ApplicationContext private val context: Context,
|
||||
private val notificationManager: NotificationManagerCompat
|
||||
) : NotificationDisplayer {
|
||||
override fun showNotificationMessage(tag: String?, id: Int, notification: Notification): Boolean {
|
||||
override fun showNotification(tag: String?, id: Int, notification: Notification): Boolean {
|
||||
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) {
|
||||
Timber.w("Not allowed to notify.")
|
||||
return false
|
||||
|
|
@ -40,12 +40,12 @@ class DefaultNotificationDisplayer(
|
|||
return true
|
||||
}
|
||||
|
||||
override fun cancelNotificationMessage(tag: String?, id: Int) {
|
||||
override fun cancelNotification(tag: String?, id: Int) {
|
||||
notificationManager.cancel(tag, id)
|
||||
}
|
||||
|
||||
override fun displayDiagnosticNotification(notification: Notification): Boolean {
|
||||
return showNotificationMessage(
|
||||
return showNotification(
|
||||
tag = "DIAGNOSTIC",
|
||||
id = NOTIFICATION_ID_DIAGNOSTIC,
|
||||
notification = notification
|
||||
|
|
@ -53,7 +53,7 @@ class DefaultNotificationDisplayer(
|
|||
}
|
||||
|
||||
override fun dismissDiagnosticNotification() {
|
||||
cancelNotificationMessage(
|
||||
cancelNotification(
|
||||
tag = "DIAGNOSTIC",
|
||||
id = NOTIFICATION_ID_DIAGNOSTIC
|
||||
)
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ class NotificationRenderer(
|
|||
// Remove summary first to avoid briefly displaying it after dismissing the last notification
|
||||
if (summaryNotification == SummaryNotification.Removed) {
|
||||
Timber.tag(loggerTag.value).d("Removing summary notification")
|
||||
notificationDisplayer.cancelNotificationMessage(
|
||||
notificationDisplayer.cancelNotification(
|
||||
tag = null,
|
||||
id = NotificationIdProvider.getSummaryNotificationId(currentUser.userId)
|
||||
)
|
||||
|
|
@ -85,7 +85,7 @@ class NotificationRenderer(
|
|||
roomId = notificationData.roomId,
|
||||
threadId = notificationData.threadId
|
||||
)
|
||||
notificationDisplayer.showNotificationMessage(
|
||||
notificationDisplayer.showNotification(
|
||||
tag = tag,
|
||||
id = NotificationIdProvider.getRoomMessagesNotificationId(currentUser.userId),
|
||||
notification = notificationData.notification
|
||||
|
|
@ -95,7 +95,7 @@ class NotificationRenderer(
|
|||
invitationNotifications.forEach { notificationData ->
|
||||
if (useCompleteNotificationFormat) {
|
||||
Timber.tag(loggerTag.value).d("Updating invitation notification ${notificationData.tag}")
|
||||
notificationDisplayer.showNotificationMessage(
|
||||
notificationDisplayer.showNotification(
|
||||
tag = notificationData.tag,
|
||||
id = NotificationIdProvider.getRoomInvitationNotificationId(currentUser.userId),
|
||||
notification = notificationData.notification
|
||||
|
|
@ -106,7 +106,7 @@ class NotificationRenderer(
|
|||
simpleNotifications.forEach { notificationData ->
|
||||
if (useCompleteNotificationFormat) {
|
||||
Timber.tag(loggerTag.value).d("Updating simple notification ${notificationData.tag}")
|
||||
notificationDisplayer.showNotificationMessage(
|
||||
notificationDisplayer.showNotification(
|
||||
tag = notificationData.tag,
|
||||
id = NotificationIdProvider.getRoomEventNotificationId(currentUser.userId),
|
||||
notification = notificationData.notification
|
||||
|
|
@ -117,7 +117,7 @@ class NotificationRenderer(
|
|||
// Show only the first fallback notification
|
||||
if (fallbackNotifications.isNotEmpty()) {
|
||||
Timber.tag(loggerTag.value).d("Showing fallback notification")
|
||||
notificationDisplayer.showNotificationMessage(
|
||||
notificationDisplayer.showNotification(
|
||||
tag = "FALLBACK",
|
||||
id = NotificationIdProvider.getFallbackNotificationId(currentUser.userId),
|
||||
notification = fallbackNotifications.first().notification
|
||||
|
|
@ -127,7 +127,7 @@ class NotificationRenderer(
|
|||
// Update summary last to avoid briefly displaying it before other notifications
|
||||
if (summaryNotification is SummaryNotification.Update) {
|
||||
Timber.tag(loggerTag.value).d("Updating summary notification")
|
||||
notificationDisplayer.showNotificationMessage(
|
||||
notificationDisplayer.showNotification(
|
||||
tag = null,
|
||||
id = NotificationIdProvider.getSummaryNotificationId(currentUser.userId),
|
||||
notification = summaryNotification.notification
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ class DefaultOnRedactedEventReceived(
|
|||
oldMessage.person
|
||||
)
|
||||
messagingStyle.messages[messageToRedactIndex] = newMessage
|
||||
notificationDisplayer.showNotificationMessage(
|
||||
notificationDisplayer.showNotification(
|
||||
statusBarNotification.tag,
|
||||
statusBarNotification.id,
|
||||
NotificationCompat.Builder(context, notification)
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ class NotificationRendererTest {
|
|||
|
||||
renderEventsAsNotifications(listOf(aNotifiableMessageEvent()))
|
||||
|
||||
notificationDisplayer.showNotificationMessageResult.assertions().isCalledExactly(2).withSequence(
|
||||
notificationDisplayer.showNotificationResult.assertions().isCalledExactly(2).withSequence(
|
||||
listOf(value(A_ROOM_ID.value), value(notificationIdProvider.getRoomMessagesNotificationId(A_SESSION_ID)), value(A_NOTIFICATION)),
|
||||
listOf(value(null), value(notificationIdProvider.getSummaryNotificationId(A_SESSION_ID)), value(A_SUMMARY_NOTIFICATION.notification))
|
||||
)
|
||||
|
|
@ -90,7 +90,7 @@ class NotificationRendererTest {
|
|||
|
||||
renderEventsAsNotifications(listOf(aSimpleNotifiableEvent(eventId = AN_EVENT_ID)))
|
||||
|
||||
notificationDisplayer.showNotificationMessageResult.assertions().isCalledExactly(2).withSequence(
|
||||
notificationDisplayer.showNotificationResult.assertions().isCalledExactly(2).withSequence(
|
||||
listOf(value(AN_EVENT_ID.value), value(notificationIdProvider.getRoomEventNotificationId(A_SESSION_ID)), value(A_NOTIFICATION)),
|
||||
listOf(value(null), value(notificationIdProvider.getSummaryNotificationId(A_SESSION_ID)), value(A_SUMMARY_NOTIFICATION.notification))
|
||||
)
|
||||
|
|
@ -102,7 +102,7 @@ class NotificationRendererTest {
|
|||
|
||||
renderEventsAsNotifications(listOf(anInviteNotifiableEvent()))
|
||||
|
||||
notificationDisplayer.showNotificationMessageResult.assertions().isCalledExactly(2).withSequence(
|
||||
notificationDisplayer.showNotificationResult.assertions().isCalledExactly(2).withSequence(
|
||||
listOf(value(A_ROOM_ID.value), value(notificationIdProvider.getRoomInvitationNotificationId(A_SESSION_ID)), value(A_NOTIFICATION)),
|
||||
listOf(value(null), value(notificationIdProvider.getSummaryNotificationId(A_SESSION_ID)), value(A_SUMMARY_NOTIFICATION.notification))
|
||||
)
|
||||
|
|
|
|||
|
|
@ -19,17 +19,17 @@ import io.element.android.tests.testutils.lambda.lambdaRecorder
|
|||
import io.element.android.tests.testutils.lambda.value
|
||||
|
||||
class FakeNotificationDisplayer(
|
||||
var showNotificationMessageResult: LambdaThreeParamsRecorder<String?, Int, Notification, Boolean> = lambdaRecorder { _, _, _ -> true },
|
||||
var cancelNotificationMessageResult: LambdaTwoParamsRecorder<String?, Int, Unit> = lambdaRecorder { _, _ -> },
|
||||
var showNotificationResult: LambdaThreeParamsRecorder<String?, Int, Notification, Boolean> = lambdaRecorder { _, _, _ -> true },
|
||||
var cancelNotificationResult: LambdaTwoParamsRecorder<String?, Int, Unit> = lambdaRecorder { _, _ -> },
|
||||
var displayDiagnosticNotificationResult: LambdaOneParamRecorder<Notification, Boolean> = lambdaRecorder { _ -> true },
|
||||
var dismissDiagnosticNotificationResult: LambdaNoParamRecorder<Unit> = lambdaRecorder { -> },
|
||||
) : NotificationDisplayer {
|
||||
override fun showNotificationMessage(tag: String?, id: Int, notification: Notification): Boolean {
|
||||
return showNotificationMessageResult(tag, id, notification)
|
||||
override fun showNotification(tag: String?, id: Int, notification: Notification): Boolean {
|
||||
return showNotificationResult(tag, id, notification)
|
||||
}
|
||||
|
||||
override fun cancelNotificationMessage(tag: String?, id: Int) {
|
||||
return cancelNotificationMessageResult(tag, id)
|
||||
override fun cancelNotification(tag: String?, id: Int) {
|
||||
return cancelNotificationResult(tag, id)
|
||||
}
|
||||
|
||||
override fun displayDiagnosticNotification(notification: Notification): Boolean {
|
||||
|
|
@ -41,7 +41,7 @@ class FakeNotificationDisplayer(
|
|||
}
|
||||
|
||||
fun verifySummaryCancelled(times: Int = 1) {
|
||||
cancelNotificationMessageResult.assertions().isCalledExactly(times).withSequence(
|
||||
cancelNotificationResult.assertions().isCalledExactly(times).withSequence(
|
||||
listOf(value(null), value(NotificationIdProvider.getSummaryNotificationId(A_SESSION_ID)))
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue