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 / 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.
private fun ScrollingTextField(
text: String,
onValueChange: (String) -> Unit,
scrollState: ScrollState,
) {
val interactionSource = remember { MutableInteractionSource() }
val interactionSourceState = interactionSource.collectIsFocusedAsState()
val coroutineScope = rememberCoroutineScope()
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 / LazyGrid.kt
Last active October 30, 2021 18:24
LazyGrid implementation in Compose Foundation
fun LazyVerticalGrid(
cells: GridCells,
modifier: Modifier = Modifier,
state: LazyListState = rememberLazyListState(),
contentPadding: PaddingValues = PaddingValues(0.dp),
content: LazyGridScope.() -> Unit
) {
val scope = LazyGridScopeImpl()
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
USAGE="Usage: --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!"
fun VerificationCodeScreen() {
// UI
SmsRetrieverUserConsent { _, code -> viewModel.onSmsReceived(code) }
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) {