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..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,15 +3,17 @@ 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 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 @@ -30,6 +32,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 @@ -63,6 +67,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 @@ -78,6 +83,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 @@ -280,8 +288,12 @@ 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 { + analyticsTrackerWrapper.track(NOTIFICATION_MENU_TAPPED) + showNotificationActionsPopup(it) + } super.onPrepareOptionsMenu(menu) } @@ -291,13 +303,34 @@ 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 + */ + @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).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() { + analyticsTrackerWrapper.track(NOTIFICATIONS_MARK_ALL_READ_TAPPED) + // 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..165f25309025 --- /dev/null +++ b/WordPress/src/main/res/layout/notification_action_menu.xml @@ -0,0 +1,14 @@ + + + + + + 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 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; }