删除账户UI调整
This commit is contained in:
@@ -30,6 +30,7 @@ import com.aiosman.ravenow.LocalSharedTransitionScope
|
||||
import com.aiosman.ravenow.ui.about.AboutScreen
|
||||
import com.aiosman.ravenow.ui.account.AccountEditScreen2
|
||||
import com.aiosman.ravenow.ui.account.AccountSetting
|
||||
import com.aiosman.ravenow.ui.account.RemoveAccountScreen
|
||||
import com.aiosman.ravenow.ui.account.ResetPasswordScreen
|
||||
import com.aiosman.ravenow.ui.agent.AddAgentScreen
|
||||
import com.aiosman.ravenow.ui.group.CreateGroupChatScreen
|
||||
@@ -104,6 +105,7 @@ sealed class NavigationRoute(
|
||||
data object AddAgent : NavigationRoute("AddAgent")
|
||||
data object CreateGroupChat : NavigationRoute("CreateGroupChat")
|
||||
data object GroupInfo : NavigationRoute("GroupInfo/{id}")
|
||||
data object RemoveAccountScreen: NavigationRoute("RemoveAccount")
|
||||
}
|
||||
|
||||
|
||||
@@ -320,6 +322,9 @@ fun NavigationController(
|
||||
composable(route = NavigationRoute.ChangePasswordScreen.route) {
|
||||
ChangePasswordScreen()
|
||||
}
|
||||
composable(route = NavigationRoute.RemoveAccountScreen.route) {
|
||||
RemoveAccountScreen()
|
||||
}
|
||||
composable(route = NavigationRoute.FavouritesScreen.route) {
|
||||
FavouriteNoticeScreen()
|
||||
}
|
||||
|
||||
@@ -52,56 +52,8 @@ import kotlinx.coroutines.launch
|
||||
fun AccountSetting() {
|
||||
val appColors = LocalAppTheme.current
|
||||
val navController = LocalNavController.current
|
||||
var removeAccountModal by remember { mutableStateOf(false) }
|
||||
val scope = rememberCoroutineScope()
|
||||
val context = LocalContext.current
|
||||
fun removeAccount(password: String) {
|
||||
scope.launch {
|
||||
removeAccountModal = false
|
||||
try {
|
||||
val accountService = AccountServiceImpl()
|
||||
accountService.removeAccount(password)
|
||||
Messaging.unregisterDevice(context)
|
||||
AppStore.apply {
|
||||
token = null
|
||||
rememberMe = false
|
||||
saveData()
|
||||
}
|
||||
// 删除推送渠道
|
||||
AppState.ReloadAppState(context)
|
||||
navController.navigate(NavigationRoute.Login.route) {
|
||||
popUpTo(NavigationRoute.Login.route) {
|
||||
inclusive = true
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
// show toast
|
||||
Toast.makeText(context, e.message, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
if (removeAccountModal) {
|
||||
ModalBottomSheet(
|
||||
onDismissRequest = {
|
||||
removeAccountModal = false
|
||||
},
|
||||
containerColor = appColors.background,
|
||||
sheetState = rememberModalBottomSheetState(
|
||||
skipPartiallyExpanded = true
|
||||
),
|
||||
dragHandle = {},
|
||||
shape = RoundedCornerShape(topStart = 16.dp, topEnd = 16.dp),
|
||||
windowInsets = WindowInsets(0),
|
||||
modifier = Modifier.height(600.dp) // 设置固定高度
|
||||
) {
|
||||
RemoveAccountModal(
|
||||
onRemove = {
|
||||
removeAccount(it)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
@@ -133,7 +85,7 @@ fun AccountSetting() {
|
||||
)
|
||||
}
|
||||
|
||||
// divider
|
||||
// 分割线
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
@@ -149,7 +101,7 @@ fun AccountSetting() {
|
||||
iconRes = R.drawable.rider_pro_moment_delete,
|
||||
label = stringResource(R.string.remove_account),
|
||||
modifier = Modifier.noRippleClickable {
|
||||
removeAccountModal = true
|
||||
navController.navigate(NavigationRoute.RemoveAccountScreen.route)
|
||||
}
|
||||
)
|
||||
}
|
||||
@@ -162,82 +114,4 @@ fun AccountSetting() {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun RemoveAccountModal(
|
||||
onRemove: (String) -> Unit
|
||||
) {
|
||||
val appColors = LocalAppTheme.current
|
||||
var inputPassword by remember { mutableStateOf("") }
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(horizontal = 24.dp, vertical = 16.dp)
|
||||
.background(appColors.background),
|
||||
) {
|
||||
StatusBarSpacer()
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(vertical = 8.dp),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Text(
|
||||
stringResource(R.string.remove_account),
|
||||
fontWeight = FontWeight.Bold,
|
||||
fontSize = 20.sp,
|
||||
color = appColors.text
|
||||
)
|
||||
}
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.padding(bottom = 32.dp, top = 16.dp)
|
||||
.fillMaxWidth(),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Text(
|
||||
stringResource(R.string.remove_account_desc),
|
||||
fontSize = 16.sp,
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
textAlign = TextAlign.Center,
|
||||
color = appColors.text
|
||||
)
|
||||
}
|
||||
Text(
|
||||
stringResource(R.string.remove_account_password_hint),
|
||||
fontSize = 16.sp,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(top = 16.dp, bottom = 4.dp),
|
||||
color = appColors.text
|
||||
)
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.background(
|
||||
appColors.inputBackground,
|
||||
shape = RoundedCornerShape(24.dp)
|
||||
)
|
||||
.padding(vertical = 16.dp, horizontal = 16.dp)
|
||||
){
|
||||
|
||||
BasicTextField(
|
||||
value = inputPassword,
|
||||
onValueChange = { inputPassword = it },
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
textStyle = TextStyle(color = appColors.text),
|
||||
cursorBrush = SolidColor(appColors.text)
|
||||
)
|
||||
}
|
||||
Spacer(modifier = Modifier.weight(1f))
|
||||
ActionButton(
|
||||
text = stringResource(R.string.remove_account),
|
||||
fullWidth = true,
|
||||
enabled = inputPassword.isNotEmpty(),
|
||||
click = {
|
||||
onRemove(inputPassword)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
package com.aiosman.ravenow.ui.account
|
||||
|
||||
import android.widget.Toast
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.text.BasicTextField
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.ui.graphics.SolidColor
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.aiosman.ravenow.LocalAppTheme
|
||||
import com.aiosman.ravenow.LocalNavController
|
||||
import com.aiosman.ravenow.AppState
|
||||
import com.aiosman.ravenow.AppStore
|
||||
import com.aiosman.ravenow.Messaging
|
||||
import com.aiosman.ravenow.R
|
||||
import com.aiosman.ravenow.data.AccountServiceImpl
|
||||
import com.aiosman.ravenow.ui.NavigationRoute
|
||||
import com.aiosman.ravenow.ui.comment.NoticeScreenHeader
|
||||
import com.aiosman.ravenow.ui.composables.ActionButton
|
||||
import com.aiosman.ravenow.ui.composables.StatusBarSpacer
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
@Composable
|
||||
fun RemoveAccountScreen() {
|
||||
val appColors = LocalAppTheme.current
|
||||
val navController = LocalNavController.current
|
||||
var inputPassword by remember { mutableStateOf("") }
|
||||
val scope = rememberCoroutineScope()
|
||||
val context = LocalContext.current
|
||||
|
||||
fun removeAccount(password: String) {
|
||||
scope.launch {
|
||||
try {
|
||||
val accountService = AccountServiceImpl()
|
||||
accountService.removeAccount(password)
|
||||
Messaging.unregisterDevice(context)
|
||||
AppStore.apply {
|
||||
token = null
|
||||
rememberMe = false
|
||||
saveData()
|
||||
}
|
||||
// 删除推送渠道
|
||||
AppState.ReloadAppState(context)
|
||||
navController.navigate(NavigationRoute.Login.route) {
|
||||
popUpTo(NavigationRoute.Login.route) {
|
||||
inclusive = true
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
// show toast
|
||||
Toast.makeText(context, e.message, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.background(appColors.background),
|
||||
) {
|
||||
StatusBarSpacer()
|
||||
Box(
|
||||
modifier = Modifier.padding(horizontal = 24.dp, vertical = 16.dp)
|
||||
) {
|
||||
NoticeScreenHeader(
|
||||
title = stringResource(R.string.remove_account),
|
||||
moreIcon = false
|
||||
)
|
||||
}
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(horizontal = 24.dp, vertical = 16.dp)
|
||||
.background(appColors.background),
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.padding(bottom = 32.dp, top = 16.dp)
|
||||
.fillMaxWidth(),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Text(
|
||||
stringResource(R.string.remove_account_desc),
|
||||
fontSize = 16.sp,
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
textAlign = TextAlign.Center,
|
||||
color = appColors.text
|
||||
)
|
||||
}
|
||||
Text(
|
||||
stringResource(R.string.remove_account_password_hint),
|
||||
fontSize = 16.sp,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(top = 16.dp, bottom = 4.dp),
|
||||
color = appColors.text
|
||||
)
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.background(
|
||||
appColors.inputBackground,
|
||||
shape = RoundedCornerShape(24.dp)
|
||||
)
|
||||
.padding(vertical = 16.dp, horizontal = 16.dp)
|
||||
){
|
||||
|
||||
BasicTextField(
|
||||
value = inputPassword,
|
||||
onValueChange = { inputPassword = it },
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
textStyle = TextStyle(color = appColors.text),
|
||||
cursorBrush = SolidColor(appColors.text)
|
||||
)
|
||||
}
|
||||
Spacer(modifier = Modifier.weight(1f))
|
||||
ActionButton(
|
||||
text = stringResource(R.string.remove_account),
|
||||
fullWidth = true,
|
||||
enabled = inputPassword.isNotEmpty(),
|
||||
click = {
|
||||
removeAccount(inputPassword)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user