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
internal fun getVerificationCodeFromSms(sms: String, smsCodeLength: Int): String = | |
sms.filter { it.isDigit() } | |
.substring(0 until smsCodeLength) |
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
@Composable | |
fun PhoneNumberLoginScreen() { | |
// UI | |
PhoneNumberConsent { viewModel.onPhoneNumberFetchedFromDevice(it) } | |
} |
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
@Composable | |
fun SmsRetrieverUserConsentBroadcast( | |
smsCodeLength: Int = SMS_CODE_LENGTH, | |
onSmsReceived: (message: String, code: String) -> Unit, | |
) { | |
val context = LocalContext.current | |
var shouldRegisterReceiver by remember { mutableStateOf(false) } | |
LaunchedEffect(Unit) { |
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
/** | |
* Find the closest Activity in a given Context. | |
*/ | |
internal fun Context.findActivity(): Activity { | |
var context = this | |
while (context is ContextWrapper) { | |
if (context is Activity) return context | |
context = context.baseContext | |
} | |
throw IllegalStateException("Permissions should be called in the context of an Activity") |
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
@Composable | |
fun PhoneNumberConsent( | |
onPhoneNumberFetchedFromDevice: (phoneNumber: String) -> Unit, | |
) { | |
val context = LocalContext.current | |
val getPhoneNumberConsent = | |
rememberLauncherForActivityResult(ActivityResultContracts.StartIntentSenderForResult()) { result: ActivityResult? -> | |
if (result?.resultCode == Activity.RESULT_OK && result.data != null) { | |
val credential = result.data!!.getParcelableExtra<Credential>(Credential.EXTRA_KEY) |
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
AutoScrollingLazyRow(list = featuresList) { | |
FeatureTile(feature = it) | |
} |
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
@Composable | |
fun <T : Any> AutoScrollingLazyRow( | |
list: List<T>, | |
modifier: Modifier = Modifier, | |
scrollDx: Float = SCROLL_DX, | |
delayBetweenScrollMs: Long = DELAY_BETWEEN_SCROLL_MS, | |
divider: @Composable () -> Unit = { Spacer(modifier = Modifier.width(Dimens.grid_1)) }, | |
itemContent: @Composable (item: T) -> Unit, | |
) { | |
var itemsListState by remember { mutableStateOf(list) } |
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
@Composable | |
fun FeatureList( | |
list: List<Feature>, | |
modifier: Modifier, | |
) { | |
var itemsListState by remember { mutableStateOf(list) } | |
val lazyListState = rememberLazyListState() | |
LazyRow( | |
state = lazyListState, |
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
@Composable | |
fun FeatureTile(feature: Feature) { | |
Card( | |
shape = MaterialTheme.shapes.small, | |
modifier = Modifier | |
.size(Dimens.grid_6) | |
.aspectRatio(1f) | |
.padding(1.dp), | |
elevation = Dimens.plane_2 | |
) { |
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
private tailrec suspend fun autoScrollFeaturesList() { | |
if (recyclerFeatures.canScrollHorizontally(DIRECTION_RIGHT)) { | |
recyclerFeatures.smoothScrollBy(SCROLL_DX, 0) | |
} else { | |
val firstPosition = | |
(recyclerFeatures.layoutManager as LinearLayoutManager).findFirstVisibleItemPosition() | |
if (firstPosition != RecyclerView.NO_POSITION) { | |
val currentList = featuresAdapter.currentList | |
val secondPart = currentList.subList(0, firstPosition) | |
val firstPart = currentList.subList(firstPosition, currentList.size) |