package com.suno.android.ui.screens.onboarding.username_handle import androidx.compose.foundation.background import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.material3.Scaffold import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.input.ImeAction import androidx.compose.ui.text.input.KeyboardType import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.suno.android.common_ui.components.buttons.OnboardingBottomButton import com.suno.android.common_ui.components.displays.top_bars.OnboardingTopBar import com.suno.android.common_ui.components.text_fields.LargeInputTextField import com.suno.android.common_ui.theme.ExtendedTheme import com.suno.android.common_ui.theme.SunoTheme import com.suno.android.common_res.R as CommonResR @Composable fun OnboardingUsernameHandleScreen( vm: OnboardingUsernameHandleScreenVM = hiltViewModel(), onReadyForNextScreen: () -> Unit, stepCountDisplay: String, ) { LaunchedEffect(Unit) { vm.effects.collect { effect -> when (effect) { OnboardingUsernameHandleScreenEffect.OnSkipClicked -> { onReadyForNextScreen.invoke() } OnboardingUsernameHandleScreenEffect.OnUsernameHandleSuccessfullySaved -> { onReadyForNextScreen.invoke() } OnboardingUsernameHandleScreenEffect.UserHandleWasTaken -> { // todo: impl? no-op? } } } } val viewState = vm.state.collectAsStateWithLifecycle().value Scaffold( topBar = { OnboardingTopBar( title = stringResource(CommonResR.string.pick_a_username), stepCountDisplay = stepCountDisplay, actionClick = { vm.sendEvent( OnboardingUsernameHandleScreenEvent.OnSkipClicked, ) }, ) }, ) { innerPadding -> Column( modifier = Modifier .padding(innerPadding) .fillMaxSize() .background(ExtendedTheme.colors.backgroundPrimary), verticalArrangement = Arrangement.Center, horizontalAlignment = Alignment.CenterHorizontally, ) { Box( modifier = Modifier.weight(1f), contentAlignment = Alignment.Center, ) { LargeInputTextField( modifier = Modifier.fillMaxWidth(), keyboardOptions = KeyboardOptions.Default.copy( showKeyboardOnFocus = true, keyboardType = KeyboardType.Text, imeAction = ImeAction.Done, ), placeHolderText = "@mattrobertson", inputText = viewState.userHandle, onValueChange = { textInput -> vm.sendEvent( OnboardingUsernameHandleScreenEvent.OnHandleInput( handle = textInput, ), ) }, ) } Text( text = stringResource(CommonResR.string.this_is_your_user_handle), style = ExtendedTheme.typography.smallBody, color = ExtendedTheme.colors.textPrimary.copy(alpha = 0.5f), ) OnboardingBottomButton( modifier = Modifier.padding(horizontal = 8.dp, vertical = 16.dp), buttonText = stringResource(CommonResR.string.love_it), onClick = { vm.sendEvent( OnboardingUsernameHandleScreenEvent.OnSaveClicked( handle = viewState.userHandle, ), ) }, ) } } } @Preview(showSystemUi = true) @Composable private fun OnboardingUsernameHandleScreen_Preview() { SunoTheme { OnboardingUsernameHandleScreen( onReadyForNextScreen = {}, stepCountDisplay = "2/4", ) } }