From 05fd85f025d3e599cf78c0d8aed65e5ba3d05a57 Mon Sep 17 00:00:00 2001 From: mtgriego Date: Tue, 2 Apr 2024 17:42:29 -0700 Subject: [PATCH] add links functionality for checkout page (#2006) --- .../ui/activities/ProjectPageActivity.kt | 28 +++++++++++++++++++ .../compose/projectpage/CheckoutScreen.kt | 23 +++++++++++---- ...ProjectPledgeButtonAndFragmentContainer.kt | 11 ++++++-- 3 files changed, 55 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/kickstarter/ui/activities/ProjectPageActivity.kt b/app/src/main/java/com/kickstarter/ui/activities/ProjectPageActivity.kt index eea3b2a172..7635d0f1c5 100644 --- a/app/src/main/java/com/kickstarter/ui/activities/ProjectPageActivity.kt +++ b/app/src/main/java/com/kickstarter/ui/activities/ProjectPageActivity.kt @@ -9,6 +9,7 @@ import android.app.Activity import android.content.Intent import android.content.res.Configuration import android.graphics.Rect +import android.net.Uri import android.os.Bundle import android.util.Pair import android.view.MotionEvent @@ -45,12 +46,14 @@ import com.kickstarter.databinding.ActivityProjectPageBinding import com.kickstarter.libs.ActivityRequestCodes import com.kickstarter.libs.BaseFragment import com.kickstarter.libs.Either +import com.kickstarter.libs.Environment import com.kickstarter.libs.KSString import com.kickstarter.libs.MessagePreviousScreenType import com.kickstarter.libs.ProjectPagerTabs import com.kickstarter.libs.featureflag.FlagKey import com.kickstarter.libs.rx.transformers.Transformers import com.kickstarter.libs.utils.ApplicationUtils +import com.kickstarter.libs.utils.UrlUtils import com.kickstarter.libs.utils.ViewUtils import com.kickstarter.libs.utils.extensions.addToDisposable import com.kickstarter.libs.utils.extensions.getEnvironment @@ -60,6 +63,7 @@ import com.kickstarter.libs.utils.extensions.toVisibility import com.kickstarter.models.Project import com.kickstarter.models.Reward import com.kickstarter.models.StoredCard +import com.kickstarter.models.chrome.ChromeTabsHelperActivity import com.kickstarter.ui.IntentKey import com.kickstarter.ui.activities.compose.projectpage.ProjectPledgeButtonAndFragmentContainer import com.kickstarter.ui.adapters.ProjectPagerAdapter @@ -77,6 +81,7 @@ import com.kickstarter.ui.extensions.selectPledgeFragment import com.kickstarter.ui.extensions.setUpConnectivityStatusCheck import com.kickstarter.ui.extensions.showErrorToast import com.kickstarter.ui.extensions.showSnackbar +import com.kickstarter.ui.extensions.startDisclaimerChromeTab import com.kickstarter.ui.extensions.startRootCommentsActivity import com.kickstarter.ui.extensions.startUpdatesActivity import com.kickstarter.ui.extensions.startVideoActivity @@ -690,6 +695,16 @@ class ProjectPageActivity : }, onAddPaymentMethodClicked = { latePledgeCheckoutViewModel.onAddNewCardClicked(project = projectData.project(), totalAmount = totalAmount) + }, + onDisclaimerItemClicked = { disclaimerItem -> + getEnvironment()?.let { environment -> + showDisclaimerScreen(disclaimerItem, environment) + } ?: run { + showToastError() + } + }, + onAccountabilityLinkClicked = { + showAccountabilityPage() } ) @@ -719,6 +734,19 @@ class ProjectPageActivity : } } + private fun showDisclaimerScreen(disclaimerItem: DisclaimerItems, environment: Environment) { + startDisclaimerChromeTab(disclaimerItem, environment) + } + + private fun showAccountabilityPage() { + getEnvironment()?.webEndpoint()?.let { endpoint -> + val trustUrl = UrlUtils.appendPath(endpoint, "trust") + ChromeTabsHelperActivity.openCustomTab(this, UrlUtils.baseCustomTabsIntent(this), Uri.parse(trustUrl), null) + } ?: run { + showToastError() + } + } + /** * Give a List of configurations will iterate over it and apply * the configuration required. diff --git a/app/src/main/java/com/kickstarter/ui/activities/compose/projectpage/CheckoutScreen.kt b/app/src/main/java/com/kickstarter/ui/activities/compose/projectpage/CheckoutScreen.kt index e21d251adf..4b9ed72558 100644 --- a/app/src/main/java/com/kickstarter/ui/activities/compose/projectpage/CheckoutScreen.kt +++ b/app/src/main/java/com/kickstarter/ui/activities/compose/projectpage/CheckoutScreen.kt @@ -113,7 +113,9 @@ fun CheckoutScreenPreview() { pledgeReason = PledgeReason.PLEDGE, rewardsHaveShippables = true, onPledgeCtaClicked = { }, - newPaymentMethodClicked = { } + newPaymentMethodClicked = { }, + onDisclaimerItemClicked = {}, + onAccountabilityLinkClicked = {} ) } } @@ -135,7 +137,9 @@ fun CheckoutScreen( rewardsHaveShippables: Boolean, isLoading: Boolean = false, onPledgeCtaClicked: (selectedCard: StoredCard?) -> Unit, - newPaymentMethodClicked: () -> Unit + newPaymentMethodClicked: () -> Unit, + onDisclaimerItemClicked: (disclaimerItem: DisclaimerItems) -> Unit, + onAccountabilityLinkClicked: () -> Unit ) { var (selectedOption, onOptionSelected) = remember { mutableStateOf( @@ -208,9 +212,15 @@ fun CheckoutScreen( Spacer(modifier = Modifier.height(dimensions.paddingMediumSmall)) TermsOfUseClickableText( - onPrivacyPolicyClicked = {}, - onCookiePolicyClicked = {}, - onTermsOfUseClicked = {} + onPrivacyPolicyClicked = { + onDisclaimerItemClicked.invoke(DisclaimerItems.PRIVACY) + }, + onCookiePolicyClicked = { + onDisclaimerItemClicked.invoke(DisclaimerItems.COOKIES) + }, + onTermsOfUseClicked = { + onDisclaimerItemClicked.invoke(DisclaimerItems.TERMS) + } ) } } @@ -420,6 +430,9 @@ fun CheckoutScreen( TextWithClickableAccountabilityLink( padding = dimensions.paddingXSmall, html = stringResource(id = R.string.Its_a_way_to_bring_creative_projects_to_life_Learn_more_about_accountability), + onClickCallback = { + onAccountabilityLinkClicked.invoke() + } ) } } diff --git a/app/src/main/java/com/kickstarter/ui/activities/compose/projectpage/ProjectPledgeButtonAndFragmentContainer.kt b/app/src/main/java/com/kickstarter/ui/activities/compose/projectpage/ProjectPledgeButtonAndFragmentContainer.kt index 4a343766b1..0e78af1869 100644 --- a/app/src/main/java/com/kickstarter/ui/activities/compose/projectpage/ProjectPledgeButtonAndFragmentContainer.kt +++ b/app/src/main/java/com/kickstarter/ui/activities/compose/projectpage/ProjectPledgeButtonAndFragmentContainer.kt @@ -41,6 +41,7 @@ import com.kickstarter.models.Project import com.kickstarter.models.Reward import com.kickstarter.models.ShippingRule import com.kickstarter.models.StoredCard +import com.kickstarter.ui.activities.DisclaimerItems import com.kickstarter.ui.compose.designsystem.KSAlertDialog import com.kickstarter.ui.compose.designsystem.KSPrimaryGreenButton import com.kickstarter.ui.compose.designsystem.KSTheme @@ -111,7 +112,9 @@ private fun ProjectPledgeButtonAndContainerPreview() { storedCards = listOf(), userEmail = "test@test.test", onPledgeCtaClicked = {}, - onAddPaymentMethodClicked = {} + onAddPaymentMethodClicked = {}, + onDisclaimerItemClicked = {}, + onAccountabilityLinkClicked = {} ) } } @@ -154,7 +157,9 @@ fun ProjectPledgeButtonAndFragmentContainer( storedCards: List, userEmail: String, onPledgeCtaClicked: (selectedCard: StoredCard?) -> Unit, - onAddPaymentMethodClicked: () -> Unit + onAddPaymentMethodClicked: () -> Unit, + onDisclaimerItemClicked: (disclaimerItem: DisclaimerItems) -> Unit, + onAccountabilityLinkClicked: () -> Unit ) { Column { Surface( @@ -335,6 +340,8 @@ fun ProjectPledgeButtonAndFragmentContainer( onPledgeCtaClicked = onPledgeCtaClicked, newPaymentMethodClicked = onAddPaymentMethodClicked, isLoading = isLoading, + onDisclaimerItemClicked = onDisclaimerItemClicked, + onAccountabilityLinkClicked = onAccountabilityLinkClicked ) } }