Skip to content

Commit

Permalink
adapt tablet
Browse files Browse the repository at this point in the history
  • Loading branch information
aderan committed Sep 4, 2023
1 parent c9d694f commit 3d725c1
Show file tree
Hide file tree
Showing 12 changed files with 147 additions and 100 deletions.
70 changes: 58 additions & 12 deletions app/src/main/java/io/agora/flat/ui/activity/LoginActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ import io.agora.flat.ui.activity.base.BaseComposeActivity
import io.agora.flat.ui.activity.login.LoginUiAction
import io.agora.flat.ui.activity.login.LoginUiState
import io.agora.flat.ui.activity.login.LoginViewModel
import io.agora.flat.ui.activity.password.PasswordResetDialog
import io.agora.flat.ui.activity.phone.PhoneBindDialog
import io.agora.flat.ui.activity.register.RegisterDialog
import io.agora.flat.ui.compose.AgreementDialog
import io.agora.flat.ui.compose.ClickableItem
import io.agora.flat.ui.compose.FlatClickableText
Expand Down Expand Up @@ -101,7 +103,12 @@ class LoginActivity : BaseComposeActivity() {
setContent {
val loginState by loginHandler.observeLoginState().collectAsState()
val uiState by viewModel.state.collectAsState()

val isPhoneMode = isPhoneMode()

var showPhoneBind by remember { mutableStateOf(false) }
var showRegister by remember { mutableStateOf(false) }
var showForgotPwd by remember { mutableStateOf(false) }

val actioner: (LoginUiAction) -> Unit = { action ->
when (action) {
Expand Down Expand Up @@ -134,11 +141,19 @@ class LoginActivity : BaseComposeActivity() {
}

is LoginUiAction.SignUpClick -> {
Navigator.launchRegisterActivity(this)
if (isPhoneMode) {
Navigator.launchRegisterActivity(this)
} else {
showRegister = true
}
}

LoginUiAction.ForgotPwdClick -> {
Navigator.launchForgotPwdActivity(this)
if (isPhoneMode) {
Navigator.launchForgotPwdActivity(this)
} else {
showForgotPwd = true
}
}

is LoginUiAction.PasswordLoginClick -> {
Expand Down Expand Up @@ -174,6 +189,22 @@ class LoginActivity : BaseComposeActivity() {
}
}

LaunchedEffect(uiState) {
if (uiState.success) {
if (viewModel.needBindPhone()) {
if (isPhoneMode()) {
Navigator.launchPhoneBindActivity(this@LoginActivity)
} else {
showPhoneBind = true
}
} else {
showToast(R.string.login_success_and_jump)
delay(2000)
Navigator.launchHomeActivity(this@LoginActivity)
}
}
}

ShowUiMessageEffect(uiMessage = uiState.message, onMessageShown = {
viewModel.clearUiMessage(it)
})
Expand All @@ -185,14 +216,6 @@ class LoginActivity : BaseComposeActivity() {
}
}

LaunchedEffect(uiState) {
if (uiState.success) {
showToast(R.string.login_success_and_jump)
delay(2000)
Navigator.launchHomeActivity(this@LoginActivity)
}
}

// Disable press back to exit login page
BackHandler {}

Expand All @@ -204,7 +227,29 @@ class LoginActivity : BaseComposeActivity() {
Navigator.launchHomeActivity(this)
},
onDismissRequest = {
// should not cancel dialog
showPhoneBind = false
}
)
}

if (showRegister) {
RegisterDialog(
onRegisterSuccess = {
Navigator.launchHomeActivity(this)
},
onClose = {
showRegister = false
}
)
}

if (showForgotPwd) {
PasswordResetDialog(
onResetSuccess = {
showForgotPwd = false
},
onClose = {
showForgotPwd = false
}
)
}
Expand Down Expand Up @@ -310,6 +355,7 @@ private fun LoginArea(state: LoginUiState, modifier: Modifier, actioner: (LoginU
actioner(it)
})
}

LoginAgreement(
modifier = Modifier.padding(horizontal = 24.dp),
checked = agreementChecked,
Expand Down Expand Up @@ -490,7 +536,7 @@ private fun LoginButtonsArea(
Spacer(Modifier.width(24.dp))
}
}
Spacer(Modifier.height(64.dp))
Spacer(Modifier.height(80.dp))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.widthIn
import androidx.compose.material.Surface
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
Expand All @@ -20,12 +22,14 @@ import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Dialog
import androidx.hilt.navigation.compose.hiltViewModel
import dagger.hilt.android.AndroidEntryPoint
import io.agora.flat.R
import io.agora.flat.common.Navigator
import io.agora.flat.data.model.PhoneOrEmailInfo
import io.agora.flat.ui.activity.base.BaseComposeActivity
import io.agora.flat.ui.activity.register.RegisterScreen
import io.agora.flat.ui.compose.BackTopAppBar
import io.agora.flat.ui.compose.CloseTopAppBar
import io.agora.flat.ui.compose.FlatPage
Expand All @@ -34,6 +38,8 @@ import io.agora.flat.ui.compose.FlatTextCaption
import io.agora.flat.ui.compose.PasswordInput
import io.agora.flat.ui.compose.PhoneOrEmailInput
import io.agora.flat.ui.compose.SendCodeInput
import io.agora.flat.ui.theme.FlatTheme
import io.agora.flat.ui.theme.Shapes
import io.agora.flat.ui.util.ShowUiMessageEffect
import io.agora.flat.util.isValidPassword
import io.agora.flat.util.isValidVerifyCode
Expand All @@ -57,6 +63,28 @@ class PasswordResetActivity : BaseComposeActivity() {
}
}

@Composable
fun PasswordResetDialog(
onClose: () -> Unit,
onResetSuccess: () -> Unit = {},
) {
FlatTheme {
Dialog(onDismissRequest = onClose) {
Surface(
Modifier
.widthIn(max = 400.dp)
.height(500.dp),
shape = Shapes.large,
) {
PasswordResetScreen(
onClose = onClose,
onResetSuccess = onResetSuccess,
)
}
}
}
}

@Composable
fun PasswordResetScreen(
onClose: () -> Unit,
Expand Down Expand Up @@ -229,7 +257,7 @@ internal fun PhoneBindScreenPreview() {
code = "123456",
password = "123456",
),
step = Step.Confirm,
step = Step.FetchCode,
),
onPhoneOrEmailChange = {},
onSendCode = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,10 @@ fun PhoneBindScreen(

PhoneBindScreen(
state = state,
onBindClose = onBindClose,
onBindClose = {
viewModel.setMerging(false)
onBindClose()
},
onSendCode = { ccode, phone ->
lastCCode = ccode
lastPhone = phone
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.widthIn
import androidx.compose.material.Surface
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
Expand All @@ -20,6 +22,7 @@ import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Dialog
import androidx.hilt.navigation.compose.hiltViewModel
import dagger.hilt.android.AndroidEntryPoint
import io.agora.flat.R
Expand All @@ -35,6 +38,8 @@ import io.agora.flat.ui.compose.FlatPrimaryTextButton
import io.agora.flat.ui.compose.PasswordInput
import io.agora.flat.ui.compose.PhoneOrEmailInput
import io.agora.flat.ui.compose.SendCodeInput
import io.agora.flat.ui.theme.FlatTheme
import io.agora.flat.ui.theme.Shapes
import io.agora.flat.util.isValidEmail
import io.agora.flat.util.isValidPhone
import io.agora.flat.util.showToast
Expand All @@ -57,6 +62,30 @@ class RegisterActivity : BaseComposeActivity() {
}
}


@Composable
fun RegisterDialog(
onRegisterSuccess: () -> Unit,
onClose: () -> Unit,
) {
FlatTheme {
Dialog(onDismissRequest = onClose) {
Surface(
Modifier
.widthIn(max = 400.dp)
.height(500.dp),
shape = Shapes.large,
) {
RegisterScreen(
onClose = onClose,
onRegisterSuccess = onRegisterSuccess,
)
}
}
}
}


@Composable
fun RegisterScreen(
onClose: () -> Unit,
Expand Down
5 changes: 4 additions & 1 deletion app/src/main/java/io/agora/flat/ui/compose/FlatTextFiled.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import androidx.compose.ui.graphics.SolidColor
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.input.VisualTransformation
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
Expand Down Expand Up @@ -99,6 +100,7 @@ fun FlatBasicTextField(
textStyle: TextStyle? = null,
keyboardOptions: KeyboardOptions = KeyboardOptions.Default,
keyboardActions: KeyboardActions = KeyboardActions.Default,
visualTransformation: VisualTransformation = VisualTransformation.None,
placeholderValue: String?,
) {
val darkMode = isDarkTheme()
Expand All @@ -116,6 +118,7 @@ fun FlatBasicTextField(
singleLine = true,
keyboardOptions = keyboardOptions,
keyboardActions = keyboardActions,
visualTransformation = visualTransformation,
decorationBox = { innerTextField ->
Box(
Modifier.fillMaxWidth(),
Expand All @@ -131,7 +134,7 @@ fun FlatBasicTextField(
Icon(
painterResource(id = R.drawable.ic_text_filed_clear),
"",
tint = FlatTheme.colors.textPrimary
tint = FlatTheme.colors.textSecondary
)
}
}
Expand Down
Loading

0 comments on commit 3d725c1

Please sign in to comment.