mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 21:03:54 +01:00
notification: classify email messages and add mail check prompt (#5865)
This commit adds logic to classify notifications as "email" type when the notification text contains "sent you an email". It also updates the email notification prompt to support localization, ensuring a better user experience across different regions. ### Problem: 1. Previously, email-related notifications from the backend were missing a URL. As a result, when users clicked on these notifications, there was no link to open, and the notifications were categorized as UNKNOWN. This led to a poor user experience since there was no feedback provided when the user clicked on an email notification. 2. Additionally, the existing code used hardcoded English text for the email notification prompt, which did not provide a localized experience for users in different regions. ### Solution: 1. Added logic to categorize email-related notifications as `EMAIL` when the notification text contains "sent you an email". 2. Replaced the hardcoded "Check your email inbox" string with a localized string and added translations for multiple languages, including zh, zh-rhk, zh-rcn, zh-rtw, and ja. ### Changes: - **NotificationClient**: - Modified `WikimediaNotification.toCommonsNotification()` to check if the notification text contains "sent you an email". If it does, the notification is classified as `EMAIL_MESSAGE` instead of the default `UNKNOWN`. - **NotificationActivity**: - In the `NotificatinAdapter` click handler, added a check for `EMAIL_MESSAGE` type. When an email-type notification is clicked, a localized "Check your mail box" prompt is shown using `Snackbar`, instead of attempting to open a URL (which is typically missing for such notifications). - Modified to fetch the string using `getString(R.string.check_your_mail_box)` to support localization. - **NotificationType**: - Added a new `EMAIL` type to categorize email-related notifications. - **Localization**: - Added localized translations for "Check your mail box" in zh, zh-rhk, zh-rcn, zh-rtw, and ja. Co-authored-by: Qiutong Zeng <Qiutong.zeng@anu.edu.au>
This commit is contained in:
parent
817e07b921
commit
c77e5abba7
9 changed files with 32 additions and 10 deletions
|
|
@ -19,6 +19,7 @@ import fr.free.nrw.commons.databinding.ActivityNotificationBinding;
|
|||
import fr.free.nrw.commons.auth.SessionManager;
|
||||
import fr.free.nrw.commons.auth.csrf.InvalidLoginTokenException;
|
||||
import fr.free.nrw.commons.notification.models.Notification;
|
||||
import fr.free.nrw.commons.notification.models.NotificationType;
|
||||
import fr.free.nrw.commons.theme.BaseActivity;
|
||||
import fr.free.nrw.commons.utils.NetworkUtils;
|
||||
import fr.free.nrw.commons.utils.ViewUtil;
|
||||
|
|
@ -148,7 +149,11 @@ public class NotificationActivity extends BaseActivity {
|
|||
}
|
||||
adapter = new NotificatinAdapter(item -> {
|
||||
Timber.d("Notification clicked %s", item.getLink());
|
||||
handleUrl(item.getLink());
|
||||
if (item.getNotificationType() == NotificationType.EMAIL){
|
||||
ViewUtil.showLongSnackbar(binding.container,getString(R.string.check_your_email_inbox));
|
||||
} else {
|
||||
handleUrl(item.getLink());
|
||||
}
|
||||
removeNotification(item);
|
||||
return Unit.INSTANCE;
|
||||
});
|
||||
|
|
|
|||
|
|
@ -51,13 +51,23 @@ class NotificationClient
|
|||
}
|
||||
}
|
||||
|
||||
private fun WikimediaNotification.toCommonsNotification() =
|
||||
Notification(
|
||||
notificationType = NotificationType.UNKNOWN,
|
||||
notificationText = contents?.compactHeader ?: "",
|
||||
date = DateUtil.getMonthOnlyDateString(timestamp),
|
||||
link = contents?.links?.primary?.url ?: "",
|
||||
iconUrl = "",
|
||||
notificationId = id().toString(),
|
||||
)
|
||||
private fun WikimediaNotification.toCommonsNotification() :
|
||||
Notification {
|
||||
val notificationText = contents?.compactHeader ?: ""
|
||||
val notificationType =
|
||||
if (notificationText.contains("Sent you an email", ignoreCase = true)) {
|
||||
NotificationType.EMAIL
|
||||
} else {
|
||||
NotificationType.UNKNOWN
|
||||
}
|
||||
|
||||
return Notification(
|
||||
notificationType = notificationType,
|
||||
notificationText = notificationText,
|
||||
date = DateUtil.getMonthOnlyDateString(timestamp),
|
||||
link = contents?.links?.primary?.url ?: "",
|
||||
iconUrl = "",
|
||||
notificationId = id().toString(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ public enum NotificationType {
|
|||
THANK_YOU_EDIT("thank-you-edit"),
|
||||
EDIT_USER_TALK("edit-user-talk"),
|
||||
MENTION("mention"),
|
||||
EMAIL("email"),
|
||||
WELCOME("welcome"),
|
||||
UNKNOWN("unknown");
|
||||
private String type;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue