Skip to content

Instantly share code, notes, and snippets.

View rahulsainani's full-sized avatar

Rahul Sainani rahulsainani

View GitHub Profile
resConfigs "an", "ar", "ast", "az", "ban", "be", "bg", "bn", "br", "bs", "ca", "cak", "ceb", "ckb", "co", "cs", "cy", "da", "de", "dsb",
"el", "en_CA", "en_GB", "eo", "es", "es_AR", "es_CL", "es_ES", "es_MX", "et", "eu", "fa", "ff", "fi", "fr", "fur", "fy", "ga", "gd", "gl", "gn", "gu",
"hi", "hr", "hsb", "hu", "hy", "ia", "in", "is", "it", "iw", "ja", "ka", "kab", "kk", "kmr", "kn", "ko", "lij", "lo", "lt", "ml", "mr",
"my", "nb", "ne", "nl", "nn", "oc", "pa", "pl", "pt", "pt_BR", "pt_PT", "rm", "ro", "ru", "sat", "sc", "si", "sk", "skr", "sl", "sq", "sr", "su", "sv", "szl",
"ta", "te", "tg", "th", "tl", "tok", "tr", "trs", "tt", "tzm", "ug", "uk", "ur", "uz", "vec", "vi", "yo", "zh_CN", "zh_TW"
@rahulsainani
rahulsainani / TextFieldInScrollableParent.kt
Created November 11, 2021 14:56
A workaround to make TextField scroll inside a scrolling parent so it doesn't go behind the ime. https://issuetracker.google.com/issues/192043120
@Composable
private fun ScrollingTextField(
text: String,
onValueChange: (String) -> Unit,
scrollState: ScrollState,
) {
val interactionSource = remember { MutableInteractionSource() }
val interactionSourceState = interactionSource.collectIsFocusedAsState()
val coroutineScope = rememberCoroutineScope()
@Composable
private fun PhotosRow(
images: List<BeautifulCreature>,
numPhotosVisible: Float,
modifier: Modifier = Modifier,
) {
BoxWithConstraints(modifier = modifier) {
// Arbitrarily chosen 20 as number of "units" to divide the available width
val numGrids = 20
// Using available space to calculate the space between items and itemWidth
@rahulsainani
rahulsainani / LazyGrid.kt
Last active October 30, 2021 18:24
LazyGrid implementation in Compose Foundation
@ExperimentalFoundationApi
@Composable
fun LazyVerticalGrid(
cells: GridCells,
modifier: Modifier = Modifier,
state: LazyListState = rememberLazyListState(),
contentPadding: PaddingValues = PaddingValues(0.dp),
content: LazyGridScope.() -> Unit
) {
val scope = LazyGridScopeImpl()
@Composable
private fun Thumbnails(
thumbnails: List<String>,
modifier: Modifier = Modifier,
) {
BoxWithConstraints(modifier) {
val boxWithConstraintsScope = this
val padding = Theme.dimens.grid_2
val thumbnailSize = Theme.dimens.grid_6
#!/bin/sh
VERSION=0.1.0
SUBJECT=sms-retriever-hash-generator
USAGE="Usage: sms_retriever_hash_v9.sh --package package_name --keystore keystore_file"
# --- Options processing -------------------------------------------
if [ $# == 0 ] ; then
echo $USAGE
exit 1;
class PhoneNumberFormatter @Inject constructor(
private val phoneNumberUtil: PhoneNumberUtil
) {
fun formatToCountryCodeAndNationalNumber(phoneNumberWithCountryCode: String): Pair<Int, Long>? =
try {
// Can pass a default country code as the second param if there is one or an empty string if not
val number = phoneNumberUtil.parse(phoneNumberWithCountryCode, "")
Pair(number.countryCode, number.nationalNumber)
} catch (e: NumberParseException) {
adb emu sms send "+351910000001" "Your verification code is 12345. Always be riding!"
@Composable
fun VerificationCodeScreen() {
// UI
SmsRetrieverUserConsent { _, code -> viewModel.onSmsReceived(code) }
}
@Composable
fun SmsRetriever(
smsCodeLength: Int = SMS_CODE_LENGTH,
onSmsReceived: (message: String, code: String) -> Unit,
) {
val context = LocalContext.current
var shouldRegisterReceiver by remember { mutableStateOf(false) }
LaunchedEffect(Unit) {