From 12d99ca830097eaa9d8beb8d92043148e612dfff Mon Sep 17 00:00:00 2001 From: Antonis Lilis Date: Thu, 25 Apr 2024 17:50:15 +0300 Subject: [PATCH 1/4] Hides notification title for milestones --- .../main/java/org/wordpress/android/models/Note.kt | 14 ++++++++++++++ .../notifications/NotificationsDetailActivity.java | 4 ++++ 2 files changed, 18 insertions(+) diff --git a/WordPress/src/main/java/org/wordpress/android/models/Note.kt b/WordPress/src/main/java/org/wordpress/android/models/Note.kt index 7dfe4cdb1543..df2b9c53a9b3 100644 --- a/WordPress/src/main/java/org/wordpress/android/models/Note.kt +++ b/WordPress/src/main/java/org/wordpress/android/models/Note.kt @@ -76,6 +76,7 @@ class Note { val title: String by lazy { queryJSON("title", "") } val iconURL: String by lazy { queryJSON("icon", "") } val enabledCommentActions: EnumSet by lazy { getEnabledActions(commentActions) } + val hasBadge: Boolean by lazy { containsBadgeMediaType() } private val enabledPostActions: EnumSet by lazy { getEnabledActions(postActions) } private val timestampString: String by lazy { queryJSON("timestamp", "") } private val commentText: String by lazy { queryJSON("body[last].text", "") } @@ -181,6 +182,19 @@ class Note { "" } + private fun containsBadgeMediaType(): Boolean { + val bodyArray = mNoteJSON?.optJSONArray("body") + if (bodyArray != null && bodyArray.length() > 0) { + for (i in 0 until bodyArray.length()) { + val mediaType = JSONUtils.queryJSON(bodyArray, "body[$i].media[0].type", "") + if ("badge" == mediaType) { + return true + } + } + } + return false + } + /** * Computed properties */ diff --git a/WordPress/src/main/java/org/wordpress/android/ui/notifications/NotificationsDetailActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/notifications/NotificationsDetailActivity.java index 79ba8a858972..715bb3204d84 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/notifications/NotificationsDetailActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/notifications/NotificationsDetailActivity.java @@ -366,6 +366,10 @@ private void setActionBarTitleForNote(Note note) { title = getString(R.string.reader_title_post_detail); } + if (note.isViewMilestoneType() || note.getHasBadge()) { + title = ""; + } + getSupportActionBar().setTitle(title); // important for accessibility - talkback setTitle(getString(R.string.notif_detail_screen_title, title)); From 49035a2b0dd40051969129c54a29d62dad53466b Mon Sep 17 00:00:00 2001 From: Antonis Lilis Date: Fri, 26 Apr 2024 14:27:45 +0300 Subject: [PATCH 2/4] Detect achievement notification based on raw type --- .../java/org/wordpress/android/models/Note.kt | 14 --------- .../android/models/NoteExtensions.kt | 29 +++++++++++++++++++ .../NotificationsDetailActivity.java | 3 +- 3 files changed, 31 insertions(+), 15 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/models/Note.kt b/WordPress/src/main/java/org/wordpress/android/models/Note.kt index df2b9c53a9b3..7dfe4cdb1543 100644 --- a/WordPress/src/main/java/org/wordpress/android/models/Note.kt +++ b/WordPress/src/main/java/org/wordpress/android/models/Note.kt @@ -76,7 +76,6 @@ class Note { val title: String by lazy { queryJSON("title", "") } val iconURL: String by lazy { queryJSON("icon", "") } val enabledCommentActions: EnumSet by lazy { getEnabledActions(commentActions) } - val hasBadge: Boolean by lazy { containsBadgeMediaType() } private val enabledPostActions: EnumSet by lazy { getEnabledActions(postActions) } private val timestampString: String by lazy { queryJSON("timestamp", "") } private val commentText: String by lazy { queryJSON("body[last].text", "") } @@ -182,19 +181,6 @@ class Note { "" } - private fun containsBadgeMediaType(): Boolean { - val bodyArray = mNoteJSON?.optJSONArray("body") - if (bodyArray != null && bodyArray.length() > 0) { - for (i in 0 until bodyArray.length()) { - val mediaType = JSONUtils.queryJSON(bodyArray, "body[$i].media[0].type", "") - if ("badge" == mediaType) { - return true - } - } - } - return false - } - /** * Computed properties */ diff --git a/WordPress/src/main/java/org/wordpress/android/models/NoteExtensions.kt b/WordPress/src/main/java/org/wordpress/android/models/NoteExtensions.kt index 28b0d9b949ac..bf77e146bc40 100644 --- a/WordPress/src/main/java/org/wordpress/android/models/NoteExtensions.kt +++ b/WordPress/src/main/java/org/wordpress/android/models/NoteExtensions.kt @@ -1,9 +1,12 @@ +@file:JvmName("NoteExtensions") package org.wordpress.android.models val Note.type get() = NoteType.from(rawType) +fun Note.isAchievement() = AchievementType.isAchievementType(rawType) + sealed class Notification { data class PostLike(val url: String, val title: String): Notification() data object NewPost: Notification() @@ -34,3 +37,29 @@ enum class NoteType(val rawType: String) { fun from(rawType: String) = map[rawType] ?: Unknown } } + +enum class AchievementType(val rawType: String) { + UserGoalMet("user_goal_met"), + AutomatticianAchievement("automattician_achievement"), + AchieveBurritoFriday("achieve_burrito_friday"), + AchieveDailyStreak("achieve_daily_streak"), + FollowedMilestoneAchievement("followed_milestone_achievement"), + LikeMilestoneAchievement("like_milestone_achievement"), + OnFireAchievement("on_fire_achievement"), + PostMilestoneAchievement("post_milestone_achievement"), + AchieveUserAnniversary("achieve_user_anniversary"), + BestFollowedDayFeat("best_followed_day_feat"), + BestLikedDayFeat("best_liked_day_feat"), + NewTrafficSurge("new_traffic_surge"), + PrivacyChange("privacy_change"), + FreeTrialStart("free_trial_start"), + FreeTrialNearEndNote("free_trial_near_end_note"), + FreeTrialEnd("free_trial_end"), + ViewMilestone(Note.NOTE_VIEW_MILESTONE), + AscProfileRegenerationStarted("asc_profile_regeneration_started"), + AscProfileRegenerationFinished("asc_profile_regeneration_finished"); + + companion object { + fun isAchievementType(rawType: String) = entries.any { it.rawType == rawType } + } +} diff --git a/WordPress/src/main/java/org/wordpress/android/ui/notifications/NotificationsDetailActivity.java b/WordPress/src/main/java/org/wordpress/android/ui/notifications/NotificationsDetailActivity.java index 715bb3204d84..81becea1cdd2 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/notifications/NotificationsDetailActivity.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/notifications/NotificationsDetailActivity.java @@ -33,6 +33,7 @@ import org.wordpress.android.fluxc.store.SiteStore; import org.wordpress.android.fluxc.tools.FormattableRangeType; import org.wordpress.android.models.Note; +import org.wordpress.android.models.NoteExtensions; import org.wordpress.android.push.GCMMessageHandler; import org.wordpress.android.ui.ActivityLauncher; import org.wordpress.android.ui.CollapseFullScreenDialogFragment; @@ -366,7 +367,7 @@ private void setActionBarTitleForNote(Note note) { title = getString(R.string.reader_title_post_detail); } - if (note.isViewMilestoneType() || note.getHasBadge()) { + if (NoteExtensions.isAchievement(note)) { title = ""; } From d1e527ab3ac180bea3cf90ec3a66e5630266bba0 Mon Sep 17 00:00:00 2001 From: Antonis Lilis Date: Fri, 26 Apr 2024 17:51:47 +0300 Subject: [PATCH 3/4] Adds test for the isAchievement method --- .../android/models/NoteExtensionsTest.kt | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 WordPress/src/test/java/org/wordpress/android/models/NoteExtensionsTest.kt diff --git a/WordPress/src/test/java/org/wordpress/android/models/NoteExtensionsTest.kt b/WordPress/src/test/java/org/wordpress/android/models/NoteExtensionsTest.kt new file mode 100644 index 000000000000..3a50bb42583c --- /dev/null +++ b/WordPress/src/test/java/org/wordpress/android/models/NoteExtensionsTest.kt @@ -0,0 +1,28 @@ +package org.wordpress.android.models + +import kotlinx.coroutines.ExperimentalCoroutinesApi +import org.junit.Test +import org.mockito.kotlin.mock +import org.mockito.kotlin.whenever +import org.wordpress.android.BaseUnitTest +import kotlin.test.assertFalse +import kotlin.test.assertTrue + +@ExperimentalCoroutinesApi +class NoteExtensionsTest : BaseUnitTest() { + @Test + fun `A comment_like note is not an achievement note`(){ + val note = mock() + whenever(note.rawType).thenReturn("comment_like") + val result = note.isAchievement() + assertFalse(result) + } + + @Test + fun `A user_goal_met note is an achievement note`(){ + val note = mock() + whenever(note.rawType).thenReturn("user_goal_met") + val result = note.isAchievement() + assertTrue(result) + } +} From 9b612b39b0c4df34b1a22a54f31f8f86aab7d1e4 Mon Sep 17 00:00:00 2001 From: Antonis Lilis Date: Wed, 8 May 2024 09:46:01 +0300 Subject: [PATCH 4/4] Adds unit test for achivement type --- .../android/models/AchievementTypeTest.kt | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 WordPress/src/test/java/org/wordpress/android/models/AchievementTypeTest.kt diff --git a/WordPress/src/test/java/org/wordpress/android/models/AchievementTypeTest.kt b/WordPress/src/test/java/org/wordpress/android/models/AchievementTypeTest.kt new file mode 100644 index 000000000000..a0f38dd0067e --- /dev/null +++ b/WordPress/src/test/java/org/wordpress/android/models/AchievementTypeTest.kt @@ -0,0 +1,22 @@ +package org.wordpress.android.models + +import kotlinx.coroutines.ExperimentalCoroutinesApi +import org.junit.Test +import org.wordpress.android.BaseUnitTest +import kotlin.test.assertFalse +import kotlin.test.assertTrue + +@ExperimentalCoroutinesApi +class AchievementTypeTest : BaseUnitTest() { + @Test + fun `isAchievementType returns true for valid achievement types`() { + for (type in AchievementType.entries) { + assertTrue(AchievementType.isAchievementType(type.rawType)) + } + } + + @Test + fun `isAchievementType returns false for invalid achievement type`() { + assertFalse(AchievementType.isAchievementType("invalid_type")) + } +}