diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt index a36186397575..e03d7c500d50 100644 --- a/RELEASE-NOTES.txt +++ b/RELEASE-NOTES.txt @@ -3,6 +3,7 @@ *** For entries which are touching the Android Wear app's, start entry with `[WEAR]` too. 23.7 ----- +- [Internal][Woo POS] Survey for potential and current users of the POS delivered via local push notification. [https://github.com/woocommerce/woocommerce-android/pull/14751] - [Internal] Handle BLUETOOTH_PEER_REMOVED_PAIRING_INFORMATION disconnect reason from Stripe SDK [https://github.com/woocommerce/woocommerce-android/pull/14886] 23.6 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 036ad175e554..d04ce44d0bef 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 @@ -3,8 +3,8 @@ 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"), - WOO_POS_SURVEY_POTENTIAL_USER_REMINDER("woo_pos_survey_potential_user_reminder"), - WOO_POS_SURVEY_CURRENT_USER_REMINDER("woo_pos_survey_current_user_reminder"); + WOO_POS_SURVEY_POTENTIAL_USER_REMINDER("woo_pos_survey_potential_user_survey"), + WOO_POS_SURVEY_CURRENT_USER_REMINDER("woo_pos_survey_current_user_survey"); override fun toString() = value companion object { diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/feedback/FeedbackSurveyFragment.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/feedback/FeedbackSurveyFragment.kt index 86d10987f2f8..f60bc2b6e413 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/feedback/FeedbackSurveyFragment.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/feedback/FeedbackSurveyFragment.kt @@ -7,6 +7,7 @@ import android.webkit.WebResourceRequest import android.webkit.WebSettings import android.webkit.WebView import android.webkit.WebViewClient +import androidx.activity.OnBackPressedCallback import androidx.appcompat.app.AppCompatActivity import androidx.navigation.fragment.findNavController import androidx.navigation.fragment.navArgs @@ -56,6 +57,7 @@ class FeedbackSurveyFragment : BaseFragment(R.layout.fragment_feedback_survey) { private var progressDialog: CustomProgressDialog? = null private var surveyCompleted: Boolean = false private val surveyWebViewClient = SurveyWebViewClient() + private var backPressedCallback: OnBackPressedCallback? = null private val arguments: FeedbackSurveyFragmentArgs by navArgs() private val feedbackContext by lazy { when (arguments.surveyType) { @@ -77,6 +79,7 @@ class FeedbackSurveyFragment : BaseFragment(R.layout.fragment_feedback_survey) { _binding = FragmentFeedbackSurveyBinding.bind(view) setupToolbar(binding.toolbar) + setupBackPressHandling() configureWebView() savedInstanceState?.let { @@ -95,6 +98,21 @@ class FeedbackSurveyFragment : BaseFragment(R.layout.fragment_feedback_survey) { activity?.invalidateOptionsMenu() } + private fun setupBackPressHandling() { + backPressedCallback = object : OnBackPressedCallback(true) { + override fun handleOnBackPressed() { + if (binding.webView.canGoBack()) { + binding.webView.goBack() + } else { + isEnabled = false + requireActivity().onBackPressedDispatcher.onBackPressed() + } + } + }.also { + requireActivity().onBackPressedDispatcher.addCallback(viewLifecycleOwner, it) + } + } + private fun getSurveyUrlFromArguments(): String = arguments.customUrl ?: arguments.surveyType.url private fun addCrowdSignalTagsTo(url: String): String { @@ -112,6 +130,8 @@ class FeedbackSurveyFragment : BaseFragment(R.layout.fragment_feedback_survey) { override fun onDestroyView() { super.onDestroyView() + backPressedCallback?.remove() + backPressedCallback = null _binding = null } diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/common/util/WooPosSurveysNotificationScheduler.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/common/util/WooPosSurveysNotificationScheduler.kt index 7af26a725222..5f95536e976b 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/common/util/WooPosSurveysNotificationScheduler.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/woopos/common/util/WooPosSurveysNotificationScheduler.kt @@ -5,7 +5,6 @@ import com.woocommerce.android.notifications.local.LocalNotification import com.woocommerce.android.notifications.local.LocalNotificationScheduler import com.woocommerce.android.tools.SelectedSite import com.woocommerce.android.ui.woopos.util.datastore.WooPosPreferencesRepository -import com.woocommerce.android.util.FeatureFlag import kotlinx.coroutines.flow.first import org.wordpress.android.fluxc.store.WooCommerceStore import java.util.concurrent.TimeUnit @@ -26,7 +25,7 @@ class WooPosSurveysNotificationScheduler @Inject constructor( suspend fun schedulePotentialUserSurveyNotification() { if (!appPrefs.isWooPosSurveyNotificationPotentialUserShown && !wooPosPreferencesRepository.wasOpenedOnce.first() && - areNotificationsAllowed() + isAllowedCountry() ) { localNotificationScheduler.scheduleNotification( LocalNotification.WooPosSurveyPotentialUserNotification( @@ -39,7 +38,7 @@ class WooPosSurveysNotificationScheduler @Inject constructor( suspend fun scheduleCurrentUserSurveyNotification() { if (!appPrefs.isWooPosSurveyNotificationCurrentUserShown && wooPosPreferencesRepository.wasOpenedOnce.first() && - areNotificationsAllowed() + isAllowedCountry() ) { localNotificationScheduler.scheduleNotification( LocalNotification.WooPosSurveyCurrentUserNotification( @@ -50,9 +49,6 @@ class WooPosSurveysNotificationScheduler @Inject constructor( } } - private suspend fun areNotificationsAllowed(): Boolean = - isAllowedCountry() && FeatureFlag.WOO_POS_SURVEYS.isEnabled() - private suspend fun isAllowedCountry(): Boolean { val countryCode = wooCommerceStore.getSiteSettingsAsync(selectedSite.get())?.countryCode return countryCode?.lowercase() in ALLOWED_COUNTRIES diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/util/FeatureFlag.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/util/FeatureFlag.kt index 37834a23a614..e5389124c454 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/util/FeatureFlag.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/util/FeatureFlag.kt @@ -10,7 +10,6 @@ enum class FeatureFlag { WC_SHIPPING_BANNER, BETTER_CUSTOMER_SEARCH_M2, ORDER_CREATION_AUTO_TAX_RATE, - WOO_POS_SURVEYS, WOO_POS_LOCAL_CATALOG_M1, BOOKINGS_MVP; @@ -21,7 +20,6 @@ enum class FeatureFlag { } WC_SHIPPING_BANNER, - WOO_POS_SURVEYS, BETTER_CUSTOMER_SEARCH_M2, ORDER_CREATION_AUTO_TAX_RATE, WOO_POS_LOCAL_CATALOG_M1,