diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/AppPrefs.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/AppPrefs.kt index 2c4d9c1f33b7..23e243ee0eaa 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/AppPrefs.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/AppPrefs.kt @@ -310,6 +310,14 @@ object AppPrefs { get() = getBoolean(DeletablePrefKey.JETPACK_APP_PASSWORDS_ENABLED, true) set(value) = setBoolean(DeletablePrefKey.JETPACK_APP_PASSWORDS_ENABLED, value) + var isWooPosSurveyNotificationCurrentUserShown: Boolean + get() = getBoolean(UndeletablePrefKey.WOO_POS_SURVEY_NOTIFICATION_CURRENT_USER_SHOWN, false) + set(value) = setBoolean(UndeletablePrefKey.WOO_POS_SURVEY_NOTIFICATION_CURRENT_USER_SHOWN, value) + + var isWooPosSurveyNotificationPotentialUserShown: Boolean + get() = getBoolean(UndeletablePrefKey.WOO_POS_SURVEY_NOTIFICATION_POTENTIAL_USER_SHOWN, false) + set(value) = setBoolean(UndeletablePrefKey.WOO_POS_SURVEY_NOTIFICATION_POTENTIAL_USER_SHOWN, value) + fun getProductSortingChoice(currentSiteId: Int) = getString(getProductSortingKey(currentSiteId)).orNullIfEmpty() fun setProductSortingChoice(currentSiteId: Int, value: String) { @@ -1357,14 +1365,6 @@ object AppPrefs { ) } - var isWooPosSurveyNotificationCurrentUserShown: Boolean - get() = getBoolean(UndeletablePrefKey.WOO_POS_SURVEY_NOTIFICATION_CURRENT_USER_SHOWN, false) - set(value) = setBoolean(UndeletablePrefKey.WOO_POS_SURVEY_NOTIFICATION_CURRENT_USER_SHOWN, value) - - var isWooPosSurveyNotificationPotentialUserShown: Boolean - get() = getBoolean(UndeletablePrefKey.WOO_POS_SURVEY_NOTIFICATION_POTENTIAL_USER_SHOWN, false) - set(value) = setBoolean(UndeletablePrefKey.WOO_POS_SURVEY_NOTIFICATION_POTENTIAL_USER_SHOWN, value) - enum class CardReaderOnboardingStatus { CARD_READER_ONBOARDING_COMPLETED, CARD_READER_ONBOARDING_PENDING, diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/AppPrefsWrapper.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/AppPrefsWrapper.kt index ea1a6ad058d0..1ba67f19e606 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/AppPrefsWrapper.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/AppPrefsWrapper.kt @@ -39,6 +39,10 @@ open class AppPrefsWrapper @Inject constructor() { var isSiteWPComSuspended by AppPrefs::isSiteWPComSuspended + var isWooPosSurveyNotificationPotentialUserShown by AppPrefs::isWooPosSurveyNotificationPotentialUserShown + + var isWooPosSurveyNotificationCurrentUserShown by AppPrefs::isWooPosSurveyNotificationCurrentUserShown + open var orderSummaryMigrated by AppPrefs::orderSummaryMigrated open var gatewayMigrated by AppPrefs::gatewayMigrated diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/notifications/local/LocalNotification.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/notifications/local/LocalNotification.kt index f39613bb68e0..631e8590b674 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/notifications/local/LocalNotification.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/notifications/local/LocalNotification.kt @@ -40,4 +40,28 @@ sealed class LocalNotification( delay = 1, delayUnit = TimeUnit.DAYS ) + + data class WooPosSurveyPotentialUserNotification( + override val siteId: Long, + override val delay: Long = 0, + ) : LocalNotification( + siteId = siteId, + title = R.string.local_notification_woo_pos_survey_potential_user_title, + description = R.string.local_notification_woo_pos_survey_potential_user_description, + type = LocalNotificationType.WOO_POS_SURVEY_POTENTIAL_USER_REMINDER, + delay = delay, + delayUnit = TimeUnit.MILLISECONDS + ) + + data class WooPosSurveyCurrentUserNotification( + override val siteId: Long, + override val delay: Long = 0, + ) : LocalNotification( + siteId = siteId, + title = R.string.local_notification_woo_pos_survey_current_user_title, + description = R.string.local_notification_woo_pos_survey_current_user_description, + type = LocalNotificationType.WOO_POS_SURVEY_CURRENT_USER_REMINDER, + delay = delay, + delayUnit = TimeUnit.MILLISECONDS + ) } diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/notifications/local/LocalNotificationType.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/notifications/local/LocalNotificationType.kt index 6d43f782c12e..036ad175e554 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/notifications/local/LocalNotificationType.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/notifications/local/LocalNotificationType.kt @@ -2,7 +2,9 @@ package com.woocommerce.android.notifications.local enum class LocalNotificationType(val value: String) { BLAZE_NO_CAMPAIGN_REMINDER("blaze_no_campaign_reminder"), - BLAZE_ABANDONED_CAMPAIGN_REMINDER("blaze_abandoned_campaign_reminder"); + BLAZE_ABANDONED_CAMPAIGN_REMINDER("blaze_abandoned_campaign_reminder"), + WOO_POS_SURVEY_POTENTIAL_USER_REMINDER("woo_pos_survey_potential_user_reminder"), + WOO_POS_SURVEY_CURRENT_USER_REMINDER("woo_pos_survey_current_user_reminder"); override fun toString() = value companion object { diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/notifications/local/LocalNotificationWorker.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/notifications/local/LocalNotificationWorker.kt index 262642569ddd..2901393c15f5 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/notifications/local/LocalNotificationWorker.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/notifications/local/LocalNotificationWorker.kt @@ -84,6 +84,14 @@ class LocalNotificationWorker @AssistedInject constructor( appsPrefsWrapper.isBlazeAbandonedCampaignReminderShown = true } + LocalNotificationType.WOO_POS_SURVEY_POTENTIAL_USER_REMINDER -> { + appsPrefsWrapper.isWooPosSurveyNotificationPotentialUserShown = true + } + + LocalNotificationType.WOO_POS_SURVEY_CURRENT_USER_REMINDER -> { + appsPrefsWrapper.isWooPosSurveyNotificationCurrentUserShown = true + } + else -> {} } } diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/notifications/local/PreconditionCheckWorker.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/notifications/local/PreconditionCheckWorker.kt index f0b2d86f023c..0d9c21d33052 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/notifications/local/PreconditionCheckWorker.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/notifications/local/PreconditionCheckWorker.kt @@ -38,6 +38,9 @@ class PreconditionCheckWorker @AssistedInject constructor( LocalNotificationType.BLAZE_NO_CAMPAIGN_REMINDER, LocalNotificationType.BLAZE_ABANDONED_CAMPAIGN_REMINDER -> proceedIfValidSiteAndBlazeAvailable(siteId) + LocalNotificationType.WOO_POS_SURVEY_POTENTIAL_USER_REMINDER, + LocalNotificationType.WOO_POS_SURVEY_CURRENT_USER_REMINDER -> proceedIfValidSite(siteId) + null -> cancelWork("Notification type is null. Cancelling work.") } } @@ -63,6 +66,23 @@ class PreconditionCheckWorker @AssistedInject constructor( else -> Result.success() } + private fun proceedIfValidSite(siteId: Long) = when { + siteId == 0L -> { + val message = "Site id is missing. Cancelling local notification work." + crashLogging.sendReport( + exception = Exception(message), + message = "PreconditionCheckWorker: cancelling work" + ) + cancelWork(message) + } + + siteStore.getSiteBySiteId(siteId) == null -> { + cancelWork("The site linked to the notifications doesn't exist in the db. Cancelling work.") + } + + else -> Result.success() + } + private val canDisplayNotifications: Boolean get() = VERSION.SDK_INT < VERSION_CODES.TIRAMISU || WooPermissionUtils.hasNotificationsPermission(appContext) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/main/MainActivityViewModel.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/main/MainActivityViewModel.kt index 242936c1fd02..e52ee91e2c02 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/main/MainActivityViewModel.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/main/MainActivityViewModel.kt @@ -19,6 +19,8 @@ import com.woocommerce.android.notifications.WooNotificationType import com.woocommerce.android.notifications.local.LocalNotificationType import com.woocommerce.android.notifications.local.LocalNotificationType.BLAZE_ABANDONED_CAMPAIGN_REMINDER import com.woocommerce.android.notifications.local.LocalNotificationType.BLAZE_NO_CAMPAIGN_REMINDER +import com.woocommerce.android.notifications.local.LocalNotificationType.WOO_POS_SURVEY_CURRENT_USER_REMINDER +import com.woocommerce.android.notifications.local.LocalNotificationType.WOO_POS_SURVEY_POTENTIAL_USER_REMINDER import com.woocommerce.android.notifications.push.NotificationMessageHandler import com.woocommerce.android.tools.SelectedSite import com.woocommerce.android.tools.SiteConnectionType.Jetpack @@ -286,6 +288,9 @@ class MainActivityViewModel @Inject constructor( when (it) { BLAZE_NO_CAMPAIGN_REMINDER, BLAZE_ABANDONED_CAMPAIGN_REMINDER -> triggerEvent(LaunchBlazeCampaignCreation) + + WOO_POS_SURVEY_POTENTIAL_USER_REMINDER, + WOO_POS_SURVEY_CURRENT_USER_REMINDER -> error("POS Survey notifications are not implemented yet") } } } diff --git a/WooCommerce/src/main/res/values/strings.xml b/WooCommerce/src/main/res/values/strings.xml index 38e79f4821f6..ce2691a66c2e 100644 --- a/WooCommerce/src/main/res/values/strings.xml +++ b/WooCommerce/src/main/res/values/strings.xml @@ -3210,6 +3210,10 @@ Promote your products with Blaze Ads and increase your sales now. Thinking about boosting your sales? Get your products seen by millions with Blaze and boost your sales + Thinking about in-person sales? + Help us build tools you\'d actually use. 2-minute survey to build tools you\'ll love. + How\'s POS working for you? + Share your experience in 2 minutes and help us improve.