From 91052fc1eeb88498cbfebf73710bf231939c7c1d Mon Sep 17 00:00:00 2001 From: jorgemucientesfayos Date: Mon, 23 Sep 2024 10:09:20 +0200 Subject: [PATCH] Extract logic to url helper --- .../com/woocommerce/android/ui/blaze/BlazeUrlsHelper.kt | 5 +++++ .../blaze/detail/BlazeCampaignDetailWebViewViewModel.kt | 9 +++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/blaze/BlazeUrlsHelper.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/blaze/BlazeUrlsHelper.kt index cc7c40b2450..03719e0607a 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/blaze/BlazeUrlsHelper.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/blaze/BlazeUrlsHelper.kt @@ -20,6 +20,11 @@ class BlazeUrlsHelper @Inject constructor( private fun getSiteUrl() = selectedSite.get().url.replace(Regex(HTTP_PATTERN), "") + fun extractProductIdFromPromoteAgainUrl(url: String): Long? = + url.substringAfter("post-") + .substringBefore("_campaign") + .toLongOrNull() + enum class BlazeFlowSource(val trackingName: String) { MORE_MENU_ITEM("menu"), PRODUCT_DETAIL_PROMOTE_BUTTON("product_detail_promote_button"), diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/blaze/detail/BlazeCampaignDetailWebViewViewModel.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/blaze/detail/BlazeCampaignDetailWebViewViewModel.kt index 277a812cd8b..e96cf07b6a1 100644 --- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/blaze/detail/BlazeCampaignDetailWebViewViewModel.kt +++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/blaze/detail/BlazeCampaignDetailWebViewViewModel.kt @@ -35,18 +35,15 @@ class BlazeCampaignDetailWebViewViewModel @Inject constructor( url.contains(BlazeUrlsHelper.PROMOTE_AGAIN_URL_PATH) -> { viewState = viewState.copy( - blazeAction = PromoteProductAgain(productId = extractProductIdFromUrl(url)) + blazeAction = PromoteProductAgain( + productId = blazeUrlsHelper.extractProductIdFromPromoteAgainUrl(url) + ) ) onDismiss() } } } - private fun extractProductIdFromUrl(url: String): Long? = - url.substringAfter("post-") - .substringBefore("_campaign") - .toLongOrNull() - fun onDismiss() { when (viewState.blazeAction) { None -> triggerEvent(Exit)