-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CU-862k43hfa - Add circuit and decouple viewmodel from view
- Loading branch information
1 parent
edabd57
commit 9911935
Showing
30 changed files
with
227 additions
and
148 deletions.
There are no files selected for viewing
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
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
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
30 changes: 30 additions & 0 deletions
30
...-login/src/main/java/io/newm/feature/login/screen/createaccount/CreateAccountPresenter.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package io.newm.feature.login.screen.createaccount | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.remember | ||
import com.slack.circuit.retained.rememberRetained | ||
import com.slack.circuit.runtime.Navigator | ||
import com.slack.circuit.runtime.presenter.Presenter | ||
import io.newm.feature.login.screen.TextFieldState | ||
import io.newm.feature.login.screen.createaccount.signupform.SignupFormUiEvent | ||
import io.newm.feature.login.screen.password.ConfirmPasswordState | ||
import io.newm.feature.login.screen.password.PasswordState | ||
|
||
class CreateAccountPresenter : Presenter<CreateAccountUiState> { | ||
@Composable | ||
override fun present(): CreateAccountUiState { | ||
val userEmail = rememberRetained { TextFieldState() } | ||
val password = rememberRetained { PasswordState() } | ||
val passwordConfirmation = rememberRetained { ConfirmPasswordState(password) } | ||
|
||
return CreateAccountUiState.SignupForm( | ||
emailState = userEmail, | ||
passwordState = password, | ||
passwordConfirmationState = passwordConfirmation, | ||
) { event -> | ||
when (event) { | ||
SignupFormUiEvent.Next -> TODO() | ||
} | ||
} | ||
} | ||
} |
100 changes: 4 additions & 96 deletions
100
...ure-login/src/main/java/io/newm/feature/login/screen/createaccount/CreateAccountScreen.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,99 +1,7 @@ | ||
package io.newm.feature.login.screen.createaccount | ||
|
||
import androidx.compose.foundation.layout.* | ||
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.ui.Modifier | ||
import androidx.compose.ui.focus.FocusRequester | ||
import androidx.compose.ui.focus.focusRequester | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.unit.dp | ||
import io.newm.feature.login.screen.email.Email | ||
import io.newm.feature.login.screen.email.EmailState | ||
import io.newm.feature.login.screen.password.Password | ||
import io.newm.feature.login.screen.password.PasswordState | ||
import io.newm.core.resources.R | ||
import io.newm.core.ui.buttons.SecondaryButton | ||
import io.newm.feature.login.screen.PreLoginArtistBackgroundContentTemplate | ||
import com.slack.circuit.runtime.Screen | ||
import kotlinx.parcelize.Parcelize | ||
|
||
@Composable | ||
fun CreateAccountScreen( | ||
onUserLoggedIn: () -> Unit, | ||
onNext: () -> Unit, | ||
viewModel: CreateAccountViewModel | ||
) { | ||
val userState by viewModel.state.collectAsState() | ||
|
||
CreateAccountScreen( | ||
onUserLoggedIn = onUserLoggedIn, | ||
onNext = onNext, | ||
userState = userState, | ||
setUserEmail = viewModel::setUserEmail, | ||
setUserPassword = viewModel::setUserPassword, | ||
setUserPasswordConfirmation = viewModel::setUserPasswordConfirmation, | ||
requestCode = viewModel::requestCode, | ||
) | ||
} | ||
|
||
@Composable | ||
internal fun CreateAccountScreen( | ||
onUserLoggedIn: () -> Unit, | ||
onNext: () -> Unit, | ||
userState: CreateAccountViewModel.SignupUserState, | ||
setUserEmail: (String) -> Unit, | ||
setUserPassword: (String) -> Unit, | ||
setUserPasswordConfirmation: (String) -> Unit, | ||
requestCode: () -> Unit, | ||
) { | ||
PreLoginArtistBackgroundContentTemplate { | ||
|
||
LaunchedEffect( | ||
key1 = userState.verificationRequested, | ||
key2 = userState.verificationRequested | ||
) { | ||
if (userState.verificationRequested) { | ||
onNext() | ||
} | ||
if (userState.isUserRegistered) { | ||
onUserLoggedIn() | ||
} | ||
} | ||
|
||
val focusRequester = remember { FocusRequester() } | ||
|
||
val emailState = remember { EmailState() } | ||
Email(emailState = emailState, onImeAction = { focusRequester.requestFocus() }) | ||
|
||
val passwordState1 = remember { PasswordState() } | ||
Password( | ||
label = stringResource(id = R.string.password), | ||
passwordState = passwordState1, | ||
onImeAction = {}, | ||
modifier = Modifier.focusRequester(focusRequester), | ||
) | ||
|
||
val passwordState2 = remember { PasswordState() } | ||
Password( | ||
label = stringResource(id = R.string.password), | ||
passwordState = passwordState2, | ||
onImeAction = {}, | ||
modifier = Modifier.focusRequester(focusRequester), | ||
) | ||
|
||
Spacer(modifier = Modifier.height(16.dp)) | ||
|
||
SecondaryButton(text = "Next") { | ||
if (passwordState1.isValid && passwordState2.isValid | ||
&& passwordState1.text == passwordState2.text || true | ||
) { | ||
setUserEmail("[email protected]") | ||
setUserPassword("Password18") | ||
setUserPasswordConfirmation("Password18") | ||
requestCode() | ||
} | ||
} | ||
} | ||
} | ||
@Parcelize | ||
object CreateAccountScreen : Screen |
18 changes: 18 additions & 0 deletions
18
...feature-login/src/main/java/io/newm/feature/login/screen/createaccount/CreateAccountUi.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package io.newm.feature.login.screen.createaccount | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import com.slack.circuit.runtime.ui.Ui | ||
import io.newm.feature.login.screen.createaccount.CreateAccountUiState.SignupForm | ||
import io.newm.feature.login.screen.createaccount.signupform.SignUpFormUi | ||
|
||
class CreateAccountUi : Ui<CreateAccountUiState> { | ||
@Composable | ||
override fun Content(state: CreateAccountUiState, modifier: Modifier) { | ||
when (state) { | ||
is SignupForm -> { | ||
SignUpFormUi(state = state) | ||
} | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...re-login/src/main/java/io/newm/feature/login/screen/createaccount/CreateAccountUiState.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package io.newm.feature.login.screen.createaccount | ||
|
||
import com.slack.circuit.runtime.CircuitUiState | ||
import io.newm.feature.login.screen.TextFieldState | ||
import io.newm.feature.login.screen.createaccount.signupform.SignupFormUiEvent | ||
|
||
sealed interface CreateAccountUiState : CircuitUiState { | ||
data class SignupForm( | ||
val passwordConfirmationState: TextFieldState, | ||
val passwordState: TextFieldState, | ||
val emailState: TextFieldState, | ||
val eventSink: (SignupFormUiEvent) -> Unit, | ||
) : CreateAccountUiState | ||
} |
51 changes: 51 additions & 0 deletions
51
...login/src/main/java/io/newm/feature/login/screen/createaccount/signupform/SignUpFormUi.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package io.newm.feature.login.screen.createaccount.signupform | ||
|
||
import androidx.compose.foundation.layout.* | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.focus.FocusRequester | ||
import androidx.compose.ui.focus.focusRequester | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.unit.dp | ||
import io.newm.feature.login.screen.email.Email | ||
import io.newm.feature.login.screen.password.Password | ||
import io.newm.core.resources.R | ||
import io.newm.core.ui.buttons.SecondaryButton | ||
import io.newm.feature.login.screen.PreLoginArtistBackgroundContentTemplate | ||
import io.newm.feature.login.screen.createaccount.CreateAccountUiState.SignupForm | ||
|
||
@Composable | ||
fun SignUpFormUi( | ||
state: SignupForm, | ||
) { | ||
val onEvent = state.eventSink | ||
val focusRequester = remember { FocusRequester() } | ||
|
||
PreLoginArtistBackgroundContentTemplate { | ||
Email( | ||
emailState = state.emailState, | ||
onImeAction = { focusRequester.requestFocus() } | ||
) | ||
|
||
Password( | ||
label = stringResource(id = R.string.password), | ||
passwordState = state.passwordState, | ||
onImeAction = {}, | ||
modifier = Modifier.focusRequester(focusRequester), | ||
) | ||
|
||
Password( | ||
label = stringResource(id = R.string.password), | ||
passwordState = state.passwordConfirmationState, | ||
onImeAction = {}, | ||
modifier = Modifier.focusRequester(focusRequester), | ||
) | ||
|
||
Spacer(modifier = Modifier.height(16.dp)) | ||
|
||
SecondaryButton(text = "Next") { | ||
onEvent(SignupFormUiEvent.Next) | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
.../src/main/java/io/newm/feature/login/screen/createaccount/signupform/SignupFormUiEvent.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package io.newm.feature.login.screen.createaccount.signupform | ||
|
||
import com.slack.circuit.runtime.CircuitUiEvent | ||
|
||
sealed interface SignupFormUiEvent : CircuitUiEvent { | ||
object Next : SignupFormUiEvent | ||
} |
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
3 changes: 0 additions & 3 deletions
3
...wm.feature.login.screen_CreateAccountScreenTest_default[AccessibilityLight].png
This file was deleted.
Oops, something went wrong.
3 changes: 0 additions & 3 deletions
3
...es/io.newm.feature.login.screen_CreateAccountScreenTest_default[NormalDark].png
This file was deleted.
Oops, something went wrong.
3 changes: 0 additions & 3 deletions
3
...s/io.newm.feature.login.screen_CreateAccountScreenTest_default[NormalLight].png
This file was deleted.
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
...e.login.screen_CreateAccountUiTest_default sign up form[AccessibilityLight].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...m.feature.login.screen_CreateAccountUiTest_default sign up form[NormalDark].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.