From 0c319dabd4815199655f03c49ea94ff44d57cb0e Mon Sep 17 00:00:00 2001 From: Jarvis Lin Date: Mon, 5 Feb 2024 23:10:44 +0800 Subject: [PATCH 1/5] Add a popup for the notification actions --- .../NotificationsListFragment.kt | 43 +++++++++++---- .../res/layout/notification_action_menu.xml | 13 +++++ .../main/res/layout/notification_actions.xml | 55 +++++++++++++++++++ .../main/res/menu/notifications_list_menu.xml | 10 ++-- WordPress/src/main/res/values/dimens.xml | 2 + WordPress/src/main/res/values/strings.xml | 2 + 6 files changed, 109 insertions(+), 16 deletions(-) create mode 100644 WordPress/src/main/res/layout/notification_action_menu.xml create mode 100644 WordPress/src/main/res/layout/notification_actions.xml diff --git a/WordPress/src/main/java/org/wordpress/android/ui/notifications/NotificationsListFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/notifications/NotificationsListFragment.kt index 459dd85958d1..9dd21915bf9a 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/notifications/NotificationsListFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/notifications/NotificationsListFragment.kt @@ -8,10 +8,11 @@ import android.content.Intent import android.os.Build import android.os.Bundle import android.text.TextUtils +import android.view.LayoutInflater import android.view.Menu import android.view.MenuInflater -import android.view.MenuItem import android.view.View +import android.widget.PopupWindow import androidx.annotation.StringRes import androidx.appcompat.app.AppCompatActivity import androidx.core.text.HtmlCompat @@ -280,8 +281,11 @@ class NotificationsListFragment : Fragment(R.layout.notifications_list_fragment) @Suppress("OVERRIDE_DEPRECATION") override fun onPrepareOptionsMenu(menu: Menu) { - val notificationSettings = menu.findItem(R.id.notifications_settings) - notificationSettings.isVisible = accountStore.hasAccessToken() + val notificationActions = menu.findItem(R.id.notifications_actions) + notificationActions.isVisible = accountStore.hasAccessToken() + notificationActions.actionView?.setOnClickListener { + showNotificationActionsPopup(it) + } super.onPrepareOptionsMenu(menu) } @@ -291,13 +295,32 @@ class NotificationsListFragment : Fragment(R.layout.notifications_list_fragment) super.onCreateOptionsMenu(menu, inflater) } - @Suppress("OVERRIDE_DEPRECATION") - override fun onOptionsItemSelected(item: MenuItem): Boolean { - if (item.itemId == R.id.notifications_settings) { - ActivityLauncher.viewNotificationsSettings(activity) - return true - } - return super.onOptionsItemSelected(item) + /** + * For displaying the popup of notifications settings + */ + private fun showNotificationActionsPopup(anchorView: View) { + val popupWindow = PopupWindow(requireContext(), null, R.style.WordPress) + popupWindow.isOutsideTouchable = true + popupWindow.elevation = resources.getDimension(R.dimen.popup_over_toolbar_elevation) + popupWindow.contentView = LayoutInflater.from(requireContext()) + .inflate(R.layout.notification_actions, null, false).apply { + findViewById(R.id.text_mark_all_as_read).setOnClickListener { + markAllAsRead() + popupWindow.dismiss() + } + findViewById(R.id.text_settings).setOnClickListener { + ActivityLauncher.viewNotificationsSettings(activity) + popupWindow.dismiss() + } + } + popupWindow.showAsDropDown(anchorView) + } + + /** + * For marking the status of every notification as read + */ + private fun markAllAsRead() { + // TODO("not yet implemented") } companion object { diff --git a/WordPress/src/main/res/layout/notification_action_menu.xml b/WordPress/src/main/res/layout/notification_action_menu.xml new file mode 100644 index 000000000000..c7ec5529e2e7 --- /dev/null +++ b/WordPress/src/main/res/layout/notification_action_menu.xml @@ -0,0 +1,13 @@ + + + + + + diff --git a/WordPress/src/main/res/layout/notification_actions.xml b/WordPress/src/main/res/layout/notification_actions.xml new file mode 100644 index 000000000000..d9beae2543ea --- /dev/null +++ b/WordPress/src/main/res/layout/notification_actions.xml @@ -0,0 +1,55 @@ + + + + + + + + + + + + + diff --git a/WordPress/src/main/res/menu/notifications_list_menu.xml b/WordPress/src/main/res/menu/notifications_list_menu.xml index d721396ead78..7f226358f32c 100644 --- a/WordPress/src/main/res/menu/notifications_list_menu.xml +++ b/WordPress/src/main/res/menu/notifications_list_menu.xml @@ -1,11 +1,9 @@ - + xmlns:app="http://schemas.android.com/apk/res-auto"> - diff --git a/WordPress/src/main/res/values/dimens.xml b/WordPress/src/main/res/values/dimens.xml index 15e6f1d173d0..882740466ae0 100644 --- a/WordPress/src/main/res/values/dimens.xml +++ b/WordPress/src/main/res/values/dimens.xml @@ -283,8 +283,10 @@ 12dp 18dp 12dp + 28dp 16dp 4dp + 4dp 3dp 5dp diff --git a/WordPress/src/main/res/values/strings.xml b/WordPress/src/main/res/values/strings.xml index 02b414050257..9a3194f4743a 100644 --- a/WordPress/src/main/res/values/strings.xml +++ b/WordPress/src/main/res/values/strings.xml @@ -1578,6 +1578,8 @@ To see notifications on notifications tab for this site, turn Notifications for this site on. Turning Notifications for this site off will disable notifications display on notifications tab for this site. You can fine-tune which kind of notification you see after turning Notifications for this site on. + Mark all as read + On Off From 778919c0a0d6a7f89c63ccc8a1d427b64f305345 Mon Sep 17 00:00:00 2001 From: Jarvis Lin Date: Tue, 6 Feb 2024 11:57:38 +0800 Subject: [PATCH 2/5] Add events --- .../android/ui/notifications/NotificationsListFragment.kt | 8 ++++++++ .../org/wordpress/android/analytics/AnalyticsTracker.java | 4 +++- .../android/analytics/AnalyticsTrackerNosara.java | 4 ++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/notifications/NotificationsListFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/notifications/NotificationsListFragment.kt index 9dd21915bf9a..a5327a15d5e3 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/notifications/NotificationsListFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/notifications/NotificationsListFragment.kt @@ -31,6 +31,8 @@ import org.greenrobot.eventbus.EventBus import org.wordpress.android.R import org.wordpress.android.analytics.AnalyticsTracker import org.wordpress.android.analytics.AnalyticsTracker.NOTIFICATIONS_SELECTED_FILTER +import org.wordpress.android.analytics.AnalyticsTracker.Stat.NOTIFICATIONS_MARK_ALL_READ_TAPPED +import org.wordpress.android.analytics.AnalyticsTracker.Stat.NOTIFICATION_MENU_TAPPED import org.wordpress.android.analytics.AnalyticsTracker.Stat.NOTIFICATION_TAPPED_SEGMENTED_CONTROL import org.wordpress.android.databinding.NotificationsListFragmentBinding import org.wordpress.android.fluxc.store.AccountStore @@ -64,6 +66,7 @@ import org.wordpress.android.util.PermissionUtils import org.wordpress.android.util.WPPermissionUtils import org.wordpress.android.util.WPPermissionUtils.NOTIFICATIONS_PERMISSION_REQUEST_CODE import org.wordpress.android.util.WPUrlUtils +import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper import org.wordpress.android.util.extensions.setLiftOnScrollTargetViewIdAndRequestLayout import org.wordpress.android.viewmodel.observeEvent import javax.inject.Inject @@ -79,6 +82,9 @@ class NotificationsListFragment : Fragment(R.layout.notifications_list_fragment) @Inject lateinit var uiHelpers: UiHelpers + @Inject + lateinit var analyticsTrackerWrapper: AnalyticsTrackerWrapper + private val viewModel: NotificationsListViewModel by viewModels() private var shouldRefreshNotifications = false @@ -284,6 +290,7 @@ class NotificationsListFragment : Fragment(R.layout.notifications_list_fragment) val notificationActions = menu.findItem(R.id.notifications_actions) notificationActions.isVisible = accountStore.hasAccessToken() notificationActions.actionView?.setOnClickListener { + analyticsTrackerWrapper.track(NOTIFICATION_MENU_TAPPED) showNotificationActionsPopup(it) } super.onPrepareOptionsMenu(menu) @@ -320,6 +327,7 @@ class NotificationsListFragment : Fragment(R.layout.notifications_list_fragment) * For marking the status of every notification as read */ private fun markAllAsRead() { + analyticsTrackerWrapper.track(NOTIFICATIONS_MARK_ALL_READ_TAPPED) // TODO("not yet implemented") } diff --git a/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTracker.java b/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTracker.java index 9c93b7293a73..6282934df911 100644 --- a/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTracker.java +++ b/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTracker.java @@ -1104,7 +1104,9 @@ public enum Stat { SITE_MONITORING_SCREEN_SHOWN, OPENED_SITE_MONITORING, SITE_MONITORING_TAB_SHOWN, - SITE_MONITORING_TAB_LOADING_ERROR + SITE_MONITORING_TAB_LOADING_ERROR, + NOTIFICATION_MENU_TAPPED, + NOTIFICATIONS_MARK_ALL_READ_TAPPED } private static final List TRACKERS = new ArrayList<>(); diff --git a/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTrackerNosara.java b/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTrackerNosara.java index 5e5fa351b389..6c9485c07ae9 100644 --- a/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTrackerNosara.java +++ b/libs/analytics/src/main/java/org/wordpress/android/analytics/AnalyticsTrackerNosara.java @@ -2703,6 +2703,10 @@ public static String getEventNameForStat(AnalyticsTracker.Stat stat) { return "site_monitoring_tab_shown"; case SITE_MONITORING_TAB_LOADING_ERROR: return "site_monitoring_tab_loading_error"; + case NOTIFICATION_MENU_TAPPED: + return "notification_menu_tapped"; + case NOTIFICATIONS_MARK_ALL_READ_TAPPED: + return "notifications_mark_all_read_tapped"; } return null; } From f1d7c56b04173f1878b535b25f85ae917407c00c Mon Sep 17 00:00:00 2001 From: Jarvis Lin Date: Tue, 6 Feb 2024 12:26:29 +0800 Subject: [PATCH 3/5] Fix a lint issue --- .../android/ui/notifications/NotificationsListFragment.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/notifications/NotificationsListFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/notifications/NotificationsListFragment.kt index a5327a15d5e3..1da921116d46 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/notifications/NotificationsListFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/notifications/NotificationsListFragment.kt @@ -305,12 +305,13 @@ class NotificationsListFragment : Fragment(R.layout.notifications_list_fragment) /** * For displaying the popup of notifications settings */ + @SuppressLint("InflateParams") private fun showNotificationActionsPopup(anchorView: View) { val popupWindow = PopupWindow(requireContext(), null, R.style.WordPress) popupWindow.isOutsideTouchable = true popupWindow.elevation = resources.getDimension(R.dimen.popup_over_toolbar_elevation) popupWindow.contentView = LayoutInflater.from(requireContext()) - .inflate(R.layout.notification_actions, null, false).apply { + .inflate(R.layout.notification_actions, null).apply { findViewById(R.id.text_mark_all_as_read).setOnClickListener { markAllAsRead() popupWindow.dismiss() From aac65539575323ff6d9f4caf1166f92e389d2a3b Mon Sep 17 00:00:00 2001 From: Jarvis Lin Date: Tue, 6 Feb 2024 12:32:53 +0800 Subject: [PATCH 4/5] Fix a lint issue --- .../android/ui/notifications/NotificationsListFragment.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/notifications/NotificationsListFragment.kt b/WordPress/src/main/java/org/wordpress/android/ui/notifications/NotificationsListFragment.kt index 1da921116d46..8956530b7307 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/notifications/NotificationsListFragment.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/notifications/NotificationsListFragment.kt @@ -3,6 +3,7 @@ package org.wordpress.android.ui.notifications import android.Manifest +import android.annotation.SuppressLint import android.app.Activity import android.content.Intent import android.os.Build From 79034090d3cc5dfcdce427cfeaf928e621b2eb1e Mon Sep 17 00:00:00 2001 From: Jarvis Lin Date: Tue, 6 Feb 2024 14:49:25 +0800 Subject: [PATCH 5/5] Fix a lint issue --- WordPress/src/main/res/layout/notification_action_menu.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/WordPress/src/main/res/layout/notification_action_menu.xml b/WordPress/src/main/res/layout/notification_action_menu.xml index c7ec5529e2e7..165f25309025 100644 --- a/WordPress/src/main/res/layout/notification_action_menu.xml +++ b/WordPress/src/main/res/layout/notification_action_menu.xml @@ -7,6 +7,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="?attr/selectableItemBackground" + android:contentDescription="@string/more" android:padding="@dimen/notifications_item_action_padding" android:src="@drawable/more_vertical" />