Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
226 changes: 124 additions & 102 deletions app/src/main/java/com/getcode/view/login/PhoneVerify.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.imePadding
Expand All @@ -21,22 +22,18 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.windowInsetsPadding
import androidx.compose.foundation.layout.wrapContentWidth
import androidx.compose.foundation.shape.ZeroCornerSize
import androidx.compose.foundation.text.BasicTextField
import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material.Text
import androidx.compose.material.TextField
import androidx.compose.material.TextFieldDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Alignment.Companion.BottomCenter
import androidx.compose.ui.Alignment.Companion.Center
import androidx.compose.ui.Alignment.Companion.CenterStart
import androidx.compose.ui.Alignment.Companion.CenterVertically
Expand All @@ -52,11 +49,11 @@ import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.input.TextFieldValue
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.constraintlayout.compose.ConstraintLayout
import androidx.hilt.navigation.compose.hiltViewModel
import com.getcode.R
import com.getcode.navigation.core.LocalCodeNavigator
Expand All @@ -66,7 +63,7 @@ import com.getcode.theme.CodeTheme
import com.getcode.theme.White05
import com.getcode.theme.White50
import com.getcode.theme.extraSmall
import com.getcode.util.debugBounds
import com.getcode.util.PhoneUtils
import com.getcode.util.getActivity
import com.getcode.util.rememberedClickable
import com.getcode.view.components.ButtonState
Expand All @@ -75,7 +72,6 @@ import com.google.android.gms.auth.api.identity.GetPhoneNumberHintIntentRequest
import com.google.android.gms.auth.api.identity.Identity
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import timber.log.Timber

@Preview
@Composable
Expand All @@ -88,7 +84,6 @@ internal fun PhoneVerify(
val dataState by viewModel.uiFlow.collectAsState()
val focusRequester = remember { FocusRequester() }
val context = LocalContext.current
val composeScope = rememberCoroutineScope()
val focusManager = LocalFocusManager.current

Column(
Expand All @@ -105,101 +100,21 @@ internal fun PhoneVerify(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(CodeTheme.dimens.inset),
) {
Row(
PhoneEntry(
modifier = Modifier
.height(CodeTheme.dimens.grid.x12)
.border(
width = CodeTheme.dimens.border,
color = BrandLight,
shape = CodeTheme.shapes.extraSmall
)
.background(White05)
) {
Row(
modifier = Modifier
.height(CodeTheme.dimens.grid.x12)
.clip(
CodeTheme.shapes.extraSmall
.copy(bottomEnd = ZeroCornerSize, topEnd = ZeroCornerSize)
)
.rememberedClickable {
composeScope.launch {
focusManager.clearFocus(true)
delay(500)
openCountrySelector()
}
},
) {
dataState.countryLocale.resId?.let { resId ->
Image(
modifier = Modifier
.align(CenterVertically)
.padding(start = CodeTheme.dimens.grid.x3)
.size(CodeTheme.dimens.staticGrid.x5)
.clip(CodeTheme.shapes.large),
painter = painterResource(resId),
contentDescription = "",
)
}
Box(
modifier = Modifier
.height(CodeTheme.dimens.grid.x12)
.align(CenterVertically)
.padding(horizontal = CodeTheme.dimens.grid.x3,),
contentAlignment = Center
) {
Text(
style = CodeTheme.typography.subtitle1,
text = "+${dataState.countryLocale.phoneCode}"
)
}
}
Spacer(
modifier = Modifier
.background(BrandLight)
.width(1.dp)
.height(CodeTheme.dimens.grid.x12)
)
BasicTextField(
modifier = Modifier
.wrapContentWidth()
.weight(1f)
.focusRequester(focusRequester),
value = dataState.phoneNumberFormattedTextFieldValue,
textStyle = CodeTheme.typography.subtitle1.copy(color = CodeTheme.colors.onBackground),
keyboardOptions = KeyboardOptions.Default.copy(keyboardType = KeyboardType.Phone),
cursorBrush = SolidColor(Color.White),
singleLine = true,
keyboardActions = KeyboardActions(
onDone = {
viewModel.onSubmit(navigator, context.getActivity())
}
),
onValueChange = {
if (!dataState.isLoading) {
viewModel.setPhoneInput(it.text, it.selection)
}
},
enabled = !dataState.isLoading && !dataState.isSuccess,
) { textField ->
Box(
modifier = Modifier
.fillMaxSize()
.padding(start = CodeTheme.dimens.staticGrid.x2),
contentAlignment = CenterStart
) {
if (dataState.phoneNumberFormattedTextFieldValue.text.isEmpty()) {
Text(
text = stringResource(id = R.string.title_phoneNumber),
color = White50,
fontSize = 20.sp
)
}
textField()
}
}

}
.height(CodeTheme.dimens.grid.x12),
focusManager = focusManager,
focusRequester = focusRequester,
locale = dataState.countryLocale,
isLoading = dataState.isLoading,
isSuccess = dataState.isSuccess,
value = dataState.phoneNumberFormattedTextFieldValue,
onValueChanged = {
viewModel.setPhoneInput(it.text, it.selection)
},
openCountrySelector = openCountrySelector,
onSubmit = { viewModel.onSubmit(navigator, context.getActivity()) }
)

Text(
modifier = Modifier.padding(horizontal = CodeTheme.dimens.grid.x2),
Expand Down Expand Up @@ -262,4 +177,111 @@ internal fun PhoneVerify(
}
}
}
}

@Composable
private fun PhoneEntry(
modifier: Modifier = Modifier,
focusManager: FocusManager,
focusRequester: FocusRequester,
locale: PhoneUtils.CountryLocale,
isLoading: Boolean,
isSuccess: Boolean,
value: TextFieldValue,
onValueChanged: (TextFieldValue) -> Unit,
openCountrySelector: () -> Unit,
onSubmit: () -> Unit,
) {
val composeScope = rememberCoroutineScope()
Row(
modifier = modifier
.border(
width = CodeTheme.dimens.border,
color = BrandLight,
shape = CodeTheme.shapes.extraSmall
)
.background(White05)
) {
Row(
modifier = Modifier
.height(CodeTheme.dimens.grid.x12)
.clip(
CodeTheme.shapes.extraSmall
.copy(bottomEnd = ZeroCornerSize, topEnd = ZeroCornerSize)
)
.rememberedClickable {
composeScope.launch {
focusManager.clearFocus(true)
delay(500)
openCountrySelector()
}
},
) {
locale.resId?.let { resId ->
Image(
modifier = Modifier
.align(CenterVertically)
.padding(start = CodeTheme.dimens.grid.x3)
.size(CodeTheme.dimens.staticGrid.x5)
.clip(CodeTheme.shapes.large),
painter = painterResource(resId),
contentDescription = "",
)
}
Box(
modifier = Modifier
.fillMaxHeight()
.padding(vertical = CodeTheme.dimens.border)
.padding(horizontal = CodeTheme.dimens.grid.x3,),
contentAlignment = Center
) {
Text(
style = CodeTheme.typography.subtitle1,
text = "+${locale.phoneCode}"
)
}
}
Spacer(
modifier = Modifier
.background(BrandLight)
.width(1.dp)
.fillMaxHeight()
)
BasicTextField(
modifier = Modifier
.fillMaxHeight()
.padding(top = CodeTheme.dimens.border)
.weight(1f)
.focusRequester(focusRequester),
value = value,
textStyle = CodeTheme.typography.subtitle1.copy(color = CodeTheme.colors.onBackground),
keyboardOptions = KeyboardOptions.Default.copy(keyboardType = KeyboardType.Phone),
cursorBrush = SolidColor(Color.White),
singleLine = true,
keyboardActions = KeyboardActions(onDone = { onSubmit() }),
onValueChange = {
if (!isLoading) {
onValueChanged(it)
}
},
enabled = !isLoading && !isSuccess,
) { textField ->
Box(
modifier = Modifier
.fillMaxSize()
.padding(start = CodeTheme.dimens.staticGrid.x2),
contentAlignment = CenterStart
) {
if (value.text.isEmpty()) {
Text(
text = stringResource(id = R.string.title_phoneNumber),
color = White50,
fontSize = 20.sp
)
}
textField()
}
}

}
}