Skip to content

Commit

Permalink
add links functionality for checkout page (#2006)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtgriego authored Apr 3, 2024
1 parent 695f73f commit 05fd85f
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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()
}
)

Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ fun CheckoutScreenPreview() {
pledgeReason = PledgeReason.PLEDGE,
rewardsHaveShippables = true,
onPledgeCtaClicked = { },
newPaymentMethodClicked = { }
newPaymentMethodClicked = { },
onDisclaimerItemClicked = {},
onAccountabilityLinkClicked = {}
)
}
}
Expand All @@ -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(
Expand Down Expand Up @@ -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)
}
)
}
}
Expand Down Expand Up @@ -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()
}
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -111,7 +112,9 @@ private fun ProjectPledgeButtonAndContainerPreview() {
storedCards = listOf(),
userEmail = "[email protected]",
onPledgeCtaClicked = {},
onAddPaymentMethodClicked = {}
onAddPaymentMethodClicked = {},
onDisclaimerItemClicked = {},
onAccountabilityLinkClicked = {}
)
}
}
Expand Down Expand Up @@ -154,7 +157,9 @@ fun ProjectPledgeButtonAndFragmentContainer(
storedCards: List<StoredCard>,
userEmail: String,
onPledgeCtaClicked: (selectedCard: StoredCard?) -> Unit,
onAddPaymentMethodClicked: () -> Unit
onAddPaymentMethodClicked: () -> Unit,
onDisclaimerItemClicked: (disclaimerItem: DisclaimerItems) -> Unit,
onAccountabilityLinkClicked: () -> Unit
) {
Column {
Surface(
Expand Down Expand Up @@ -335,6 +340,8 @@ fun ProjectPledgeButtonAndFragmentContainer(
onPledgeCtaClicked = onPledgeCtaClicked,
newPaymentMethodClicked = onAddPaymentMethodClicked,
isLoading = isLoading,
onDisclaimerItemClicked = onDisclaimerItemClicked,
onAccountabilityLinkClicked = onAccountabilityLinkClicked
)
}
}
Expand Down

0 comments on commit 05fd85f

Please sign in to comment.