-
Notifications
You must be signed in to change notification settings - Fork 661
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Identity] - support consent page for Butter 2.0 (#7412)
- Loading branch information
1 parent
23fff4c
commit 971e015
Showing
20 changed files
with
884 additions
and
483 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
...com/stripe/android/identity/networking/models/VerificationPageStaticConsentLineContent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.stripe.android.identity.networking.models | ||
|
||
import android.os.Parcelable | ||
import kotlinx.parcelize.Parcelize | ||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
@Parcelize | ||
internal data class VerificationPageStaticConsentLineContent( | ||
@SerialName("icon") | ||
val icon: VerificationPageIconType, | ||
@SerialName("content") | ||
val content: String | ||
) : Parcelable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
identity/src/main/java/com/stripe/android/identity/ui/BottomsheetHTML.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package com.stripe.android.identity.ui | ||
|
||
import android.content.Intent | ||
import android.net.Uri | ||
import android.util.Log | ||
import android.webkit.URLUtil | ||
import androidx.compose.material.ExperimentalMaterialApi | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.platform.LocalContext | ||
import androidx.compose.ui.text.SpanStyle | ||
import androidx.compose.ui.text.TextStyle | ||
import androidx.compose.ui.text.style.TextDecoration | ||
import androidx.lifecycle.viewmodel.compose.viewModel | ||
import com.stripe.android.identity.networking.STRIPE_BOTTOM_SHEET | ||
import com.stripe.android.identity.networking.models.VerificationPageStaticContentBottomSheetContent | ||
import com.stripe.android.identity.viewmodel.BottomSheetViewModel | ||
import com.stripe.android.uicore.text.HtmlWithCustomOnClick | ||
|
||
/** | ||
* Draw Html with the ability to open a web link or bottomsheet | ||
*/ | ||
@Composable | ||
@ExperimentalMaterialApi | ||
internal fun BottomSheetHTML( | ||
html: String, | ||
modifier: Modifier = Modifier, | ||
bottomSheets: Map<String, VerificationPageStaticContentBottomSheetContent>?, | ||
color: Color = Color.Unspecified, | ||
style: TextStyle, | ||
urlSpanStyle: SpanStyle = SpanStyle(textDecoration = TextDecoration.Underline) | ||
) { | ||
val context = LocalContext.current | ||
val bottomSheetViewModel = viewModel<BottomSheetViewModel>() | ||
HtmlWithCustomOnClick( | ||
html = html, | ||
modifier = modifier, | ||
color = color, | ||
style = style, | ||
urlSpanStyle = urlSpanStyle | ||
) { annotatedStringRanges -> | ||
annotatedStringRanges.firstOrNull()?.item?.let { urlString -> | ||
when { | ||
(URLUtil.isNetworkUrl(urlString)) -> { | ||
val openURL = Intent(Intent.ACTION_VIEW) | ||
openURL.data = Uri.parse(urlString) | ||
context.startActivity(openURL) | ||
} | ||
|
||
urlString.startsWith(STRIPE_BOTTOM_SHEET) -> { | ||
val bottomSheetId = urlString.substringAfterLast('/') | ||
bottomSheets?.get(bottomSheetId)?.let { bottomSheetContent -> | ||
bottomSheetViewModel.showBottomSheet(bottomSheetContent) | ||
} ?: run { | ||
Log.e( | ||
BottomSheetHTMLTAG, | ||
"Fail to present buttomsheet with id $bottomSheetId" | ||
) | ||
} | ||
} | ||
|
||
else -> { | ||
Log.e(BottomSheetHTMLTAG, "unknown url string: $urlString") | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
internal const val BottomSheetHTMLTAG = "BottomSheetHTML" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
identity/src/main/java/com/stripe/android/identity/ui/ConsentLines.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.stripe.android.identity.ui | ||
|
||
import androidx.compose.foundation.Image | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.material.ExperimentalMaterialApi | ||
import androidx.compose.material.LocalTextStyle | ||
import androidx.compose.material.MaterialTheme | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.platform.testTag | ||
import androidx.compose.ui.res.dimensionResource | ||
import androidx.compose.ui.res.painterResource | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.text.SpanStyle | ||
import androidx.compose.ui.text.style.TextDecoration | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.unit.sp | ||
import com.stripe.android.identity.R | ||
import com.stripe.android.identity.networking.models.VerificationPageStaticConsentLineContent | ||
import com.stripe.android.identity.networking.models.VerificationPageStaticContentBottomSheetContent | ||
import com.stripe.android.identity.networking.models.getContentDescriptionId | ||
import com.stripe.android.identity.networking.models.getResourceId | ||
|
||
@OptIn(ExperimentalMaterialApi::class) | ||
@Composable | ||
internal fun ConsentLines( | ||
lines: List<VerificationPageStaticConsentLineContent>, | ||
bottomSheets: Map<String, VerificationPageStaticContentBottomSheetContent>? | ||
) { | ||
for (line in lines) { | ||
Row( | ||
modifier = Modifier | ||
.testTag(CONSENT_LINE_TAG) | ||
.padding(top = dimensionResource(id = R.dimen.stripe_item_vertical_margin)) | ||
) { | ||
Image( | ||
painter = painterResource(id = line.icon.getResourceId()), | ||
modifier = Modifier | ||
.size(28.dp) | ||
.padding(end = 8.dp), | ||
contentDescription = stringResource(id = line.icon.getContentDescriptionId()) | ||
) | ||
BottomSheetHTML( | ||
html = line.content, | ||
color = MaterialTheme.colors.onSurface.copy( | ||
alpha = 0.6f | ||
), | ||
style = LocalTextStyle.current.merge(fontSize = 16.sp), | ||
bottomSheets = bottomSheets, | ||
urlSpanStyle = SpanStyle( | ||
textDecoration = TextDecoration.Underline, | ||
color = MaterialTheme.colors.secondary | ||
) | ||
) | ||
} | ||
} | ||
} | ||
|
||
internal const val CONSENT_LINE_TAG = "consentLineTag" |
Oops, something went wrong.