Skip to content

Commit

Permalink
Extract logic to url helper
Browse files Browse the repository at this point in the history
  • Loading branch information
JorgeMucientes committed Sep 23, 2024
1 parent 5a7d36c commit 91052fc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 91052fc

Please sign in to comment.