From 68769a21e25d792828dc949bdf1533462160c03a Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 5 Apr 2023 10:12:36 +0200 Subject: [PATCH] Cleanup up string for push and notification (before integrating to Localazy) --- libraries/push/impl/build.gradle.kts | 1 - .../libraries/push/impl/GoogleFcmHelper.kt | 2 +- .../libraries/push/impl/UnifiedPushHelper.kt | 10 +++--- .../NotificationBroadcastReceiver.kt | 4 +-- .../impl/notifications/NotificationUtils.kt | 31 +++++++++---------- .../SummaryGroupMessageCreator.kt | 28 ++++++++++++----- .../impl/src/main/res/values/temporary.xml | 28 +++++++++-------- 7 files changed, 59 insertions(+), 45 deletions(-) diff --git a/libraries/push/impl/build.gradle.kts b/libraries/push/impl/build.gradle.kts index abee3728f2..0968ac4344 100644 --- a/libraries/push/impl/build.gradle.kts +++ b/libraries/push/impl/build.gradle.kts @@ -38,7 +38,6 @@ dependencies { implementation(libs.serialization.json) implementation(projects.libraries.architecture) - implementation(projects.libraries.uiStrings) implementation(projects.libraries.core) implementation(projects.libraries.di) implementation(projects.libraries.androidutils) diff --git a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/GoogleFcmHelper.kt b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/GoogleFcmHelper.kt index b8dc1ad384..0ead18c75e 100755 --- a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/GoogleFcmHelper.kt +++ b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/GoogleFcmHelper.kt @@ -71,7 +71,7 @@ class GoogleFcmHelper @Inject constructor( Timber.e(e, "## ensureFcmTokenIsRetrieved() : failed") } } else { - Toast.makeText(context, R.string.no_valid_google_play_services_apk, Toast.LENGTH_SHORT).show() + Toast.makeText(context, R.string.push_no_valid_google_play_services_apk_android, Toast.LENGTH_SHORT).show() Timber.e("No valid Google Play Services found. Cannot use FCM.") } } diff --git a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/UnifiedPushHelper.kt b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/UnifiedPushHelper.kt index f77b5b2833..adabca5b18 100644 --- a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/UnifiedPushHelper.kt +++ b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/UnifiedPushHelper.kt @@ -44,9 +44,9 @@ class UnifiedPushHelper @Inject constructor( ) { val internalDistributorName = stringProvider.getString( if (fcmHelper.isFirebaseAvailable()) { - StringR.string.unifiedpush_distributor_fcm_fallback + R.string.push_distributor_firebase } else { - StringR.string.unifiedpush_distributor_background_sync + R.string.push_distributor_background_sync } ) @@ -60,7 +60,7 @@ class UnifiedPushHelper @Inject constructor( } MaterialAlertDialogBuilder(context) - .setTitle(stringProvider.getString(StringR.string.unifiedpush_getdistributors_dialog_title)) + .setTitle(stringProvider.getString(R.string.push_choose_distributor_dialog_title)) .setItems(distributorsName.toTypedArray()) { _, which -> val distributor = distributors[which] onDistributorSelected(distributor) @@ -133,8 +133,8 @@ class UnifiedPushHelper @Inject constructor( fun getCurrentDistributorName(): String { return when { - isEmbeddedDistributor() -> stringProvider.getString(R.string.unifiedpush_distributor_fcm_fallback) - isBackgroundSync() -> stringProvider.getString(R.string.unifiedpush_distributor_background_sync) + isEmbeddedDistributor() -> stringProvider.getString(R.string.push_distributor_firebase) + isBackgroundSync() -> stringProvider.getString(R.string.push_distributor_background_sync) else -> context.getApplicationLabel(UnifiedPush.getDistributor(context)) } } diff --git a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/NotificationBroadcastReceiver.kt b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/NotificationBroadcastReceiver.kt index 2c29765d55..078de3a8a8 100644 --- a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/NotificationBroadcastReceiver.kt +++ b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/NotificationBroadcastReceiver.kt @@ -164,7 +164,7 @@ class NotificationBroadcastReceiver : BroadcastReceiver() { noisy = false, timestamp = clock.epochMillis(), senderName = session.roomService().getRoomMember(session.myUserId, room.roomId)?.displayName - ?: context?.getString(StringR.string.notification_sender_me), + ?: context?.getString(R.string.notification_sender_me), senderId = session.myUserId, body = message, imageUriString = null, @@ -216,7 +216,7 @@ class NotificationBroadcastReceiver : BroadcastReceiver() { false, clock.epochMillis(), session.myUser?.displayname - ?: context?.getString(StringR.string.notification_sender_me), + ?: context?.getString(R.string.notification_sender_me), session.myUserId, message, roomId, diff --git a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/NotificationUtils.kt b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/NotificationUtils.kt index 2802b5489c..28a98f496f 100755 --- a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/NotificationUtils.kt +++ b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/NotificationUtils.kt @@ -55,7 +55,6 @@ import io.element.android.services.toolbox.api.strings.StringProvider import io.element.android.services.toolbox.api.systemclock.SystemClock import timber.log.Timber import javax.inject.Inject -import io.element.android.libraries.ui.strings.R as StringR // TODO EAx Split into factories @SingleIn(AppScope::class) @@ -154,11 +153,11 @@ class NotificationUtils @Inject constructor( */ notificationManager.createNotificationChannel(NotificationChannel( NOISY_NOTIFICATION_CHANNEL_ID, - stringProvider.getString(R.string.notification_noisy_notifications).ifEmpty { "Noisy notifications" }, + stringProvider.getString(R.string.notification_channel_noisy).ifEmpty { "Noisy notifications" }, NotificationManager.IMPORTANCE_DEFAULT ) .apply { - description = stringProvider.getString(R.string.notification_noisy_notifications) + description = stringProvider.getString(R.string.notification_channel_noisy) enableVibration(true) enableLights(true) lightColor = accentColor @@ -169,11 +168,11 @@ class NotificationUtils @Inject constructor( */ notificationManager.createNotificationChannel(NotificationChannel( SILENT_NOTIFICATION_CHANNEL_ID, - stringProvider.getString(R.string.notification_silent_notifications).ifEmpty { "Silent notifications" }, + stringProvider.getString(R.string.notification_channel_silent).ifEmpty { "Silent notifications" }, NotificationManager.IMPORTANCE_LOW ) .apply { - description = stringProvider.getString(R.string.notification_silent_notifications) + description = stringProvider.getString(R.string.notification_channel_silent) setSound(null, null) enableLights(true) lightColor = accentColor @@ -181,22 +180,22 @@ class NotificationUtils @Inject constructor( notificationManager.createNotificationChannel(NotificationChannel( LISTENING_FOR_EVENTS_NOTIFICATION_CHANNEL_ID, - stringProvider.getString(R.string.notification_listening_for_events).ifEmpty { "Listening for events" }, + stringProvider.getString(R.string.notification_channel_listening_for_events).ifEmpty { "Listening for events" }, NotificationManager.IMPORTANCE_MIN ) .apply { - description = stringProvider.getString(R.string.notification_listening_for_events) + description = stringProvider.getString(R.string.notification_channel_listening_for_events) setSound(null, null) setShowBadge(false) }) notificationManager.createNotificationChannel(NotificationChannel( CALL_NOTIFICATION_CHANNEL_ID, - stringProvider.getString(R.string.call).ifEmpty { "Call" }, + stringProvider.getString(R.string.notification_channel_call).ifEmpty { "Call" }, NotificationManager.IMPORTANCE_HIGH ) .apply { - description = stringProvider.getString(R.string.call) + description = stringProvider.getString(R.string.notification_channel_call) setSound(null, null) enableLights(true) lightColor = accentColor @@ -255,7 +254,7 @@ class NotificationUtils @Inject constructor( // Number of new notifications for API <24 (M and below) devices. .setSubText( stringProvider.getQuantityString( - R.plurals.room_new_messages_notification, + R.plurals.notification_new_messages_for_room, messageStyle.messages.size, messageStyle.messages.size ) @@ -301,7 +300,7 @@ class NotificationUtils @Inject constructor( NotificationCompat.Action.Builder( R.drawable.ic_material_done_all_white, - stringProvider.getString(R.string.action_mark_room_read), markRoomReadPendingIntent + stringProvider.getString(R.string.notification_room_action_mark_as_read), markRoomReadPendingIntent ) .setSemanticAction(NotificationCompat.Action.SEMANTIC_ACTION_MARK_AS_READ) .setShowsUserInterface(false) @@ -312,11 +311,11 @@ class NotificationUtils @Inject constructor( if (!roomInfo.hasSmartReplyError) { buildQuickReplyIntent(roomInfo.sessionId, roomInfo.roomId, threadId, senderDisplayNameForReplyCompat)?.let { replyPendingIntent -> val remoteInput = RemoteInput.Builder(NotificationBroadcastReceiver.KEY_TEXT_REPLY) - .setLabel(stringProvider.getString(StringR.string.action_quick_reply)) + .setLabel(stringProvider.getString(R.string.notification_room_action_quick_reply)) .build() NotificationCompat.Action.Builder( R.drawable.vector_notification_quick_reply, - stringProvider.getString(StringR.string.action_quick_reply), replyPendingIntent + stringProvider.getString(R.string.notification_room_action_quick_reply), replyPendingIntent ) .addRemoteInput(remoteInput) .setSemanticAction(NotificationCompat.Action.SEMANTIC_ACTION_REPLY) @@ -383,7 +382,7 @@ class NotificationUtils @Inject constructor( addAction( R.drawable.vector_notification_reject_invitation, - stringProvider.getString(R.string.action_reject), + stringProvider.getString(R.string.notification_invitation_action_reject), rejectIntentPendingIntent ) @@ -401,7 +400,7 @@ class NotificationUtils @Inject constructor( ) addAction( R.drawable.vector_notification_accept_invitation, - stringProvider.getString(R.string.action_join), + stringProvider.getString(R.string.notification_invitation_action_join), joinIntentPendingIntent ) @@ -667,7 +666,7 @@ class NotificationUtils @Inject constructor( 888, NotificationCompat.Builder(context, NOISY_NOTIFICATION_CHANNEL_ID) .setContentTitle(buildMeta.applicationName) - .setContentText(stringProvider.getString(R.string.settings_troubleshoot_test_push_notification_content)) + .setContentText(stringProvider.getString(R.string.notification_test_push_notification_content)) .setSmallIcon(R.drawable.ic_notification) .setLargeIcon(getBitmap(context, R.drawable.element_logo_green)) .setColor(ContextCompat.getColor(context, R.color.notification_accent_color)) diff --git a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/SummaryGroupMessageCreator.kt b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/SummaryGroupMessageCreator.kt index 07471fd9f8..ed0053e58c 100644 --- a/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/SummaryGroupMessageCreator.kt +++ b/libraries/push/impl/src/main/kotlin/io/element/android/libraries/push/impl/notifications/SummaryGroupMessageCreator.kt @@ -105,18 +105,23 @@ class SummaryGroupMessageCreator @Inject constructor( val messageNotificationCount = messageEventsCount + simpleEventsCount val privacyTitle = if (invitationEventsCount > 0) { - val invitationsStr = stringProvider.getQuantityString(R.plurals.notification_invitations, invitationEventsCount, invitationEventsCount) + val invitationsStr = stringProvider.getQuantityString( + R.plurals.notification_invitations, + invitationEventsCount, + invitationEventsCount + ) if (messageNotificationCount > 0) { // Invitation and message val messageStr = stringProvider.getQuantityString( - R.plurals.room_new_messages_notification, + R.plurals.notification_new_messages_for_room, messageNotificationCount, messageNotificationCount ) if (roomCount > 1) { // In several rooms val roomStr = stringProvider.getQuantityString( R.plurals.notification_unread_notified_messages_in_room_rooms, - roomCount, roomCount + roomCount, + roomCount ) stringProvider.getString( R.string.notification_unread_notified_messages_in_room_and_invitation, @@ -139,13 +144,22 @@ class SummaryGroupMessageCreator @Inject constructor( } else { // No invitation, only messages val messageStr = stringProvider.getQuantityString( - R.plurals.room_new_messages_notification, - messageNotificationCount, messageNotificationCount + R.plurals.notification_new_messages_for_room, + messageNotificationCount, + messageNotificationCount ) if (roomCount > 1) { // In several rooms - val roomStr = stringProvider.getQuantityString(R.plurals.notification_unread_notified_messages_in_room_rooms, roomCount, roomCount) - stringProvider.getString(R.string.notification_unread_notified_messages_in_room, messageStr, roomStr) + val roomStr = stringProvider.getQuantityString( + R.plurals.notification_unread_notified_messages_in_room_rooms, + roomCount, + roomCount + ) + stringProvider.getString( + R.string.notification_unread_notified_messages_in_room, + messageStr, + roomStr + ) } else { // In one room messageStr diff --git a/libraries/push/impl/src/main/res/values/temporary.xml b/libraries/push/impl/src/main/res/values/temporary.xml index b560669f57..e0833bd2dc 100644 --- a/libraries/push/impl/src/main/res/values/temporary.xml +++ b/libraries/push/impl/src/main/res/values/temporary.xml @@ -15,27 +15,29 @@ --> - No valid Google Play Services APK found. Notifications may not work properly. - Choose how to receive notifications - Google Services - Background synchronization + No valid Google Play Services found. Notifications may not work properly. + Choose how to receive notifications + Google Services + Background synchronization - Listening for events - Noisy notifications - Silent notifications - Call + Listening for events + Noisy notifications + Silent notifications + Call + Me New Messages - Mark as read - Join - Reject - You are viewing the notification! Click me! + Mark as read + Quick reply + Join + Reject + You are viewing the notification! Click me! %1$s: %2$s %1$s: %2$s %3$s ** Failed to send - please open room %1$s in %2$s and %3$s" %1$s and %2$s" %1$s in %2$s" - + %d new message %d new messages