fix #9 修正多次点击的白屏,添加修改用户资料防抖
This commit is contained in:
@@ -21,6 +21,7 @@ object AccountEditViewModel : ViewModel() {
|
||||
val accountService: AccountService = AccountServiceImpl()
|
||||
var profile by mutableStateOf<AccountProfileEntity?>(null)
|
||||
var croppedBitmap by mutableStateOf<Bitmap?>(null)
|
||||
var isUpdating by mutableStateOf(false)
|
||||
suspend fun reloadProfile() {
|
||||
accountService.getMyAccountProfile().let {
|
||||
profile = it
|
||||
@@ -30,7 +31,6 @@ object AccountEditViewModel : ViewModel() {
|
||||
}
|
||||
|
||||
suspend fun updateUserProfile(context: Context) {
|
||||
|
||||
val newAvatar = croppedBitmap?.let {
|
||||
val file = File(context.cacheDir, "avatar.jpg")
|
||||
it.compress(Bitmap.CompressFormat.JPEG, 100, file.outputStream())
|
||||
@@ -47,6 +47,5 @@ object AccountEditViewModel : ViewModel() {
|
||||
reloadProfile()
|
||||
// 刷新个人资料页面的用户资料
|
||||
MyProfileViewModel.loadUserProfile()
|
||||
|
||||
}
|
||||
}
|
||||
@@ -194,7 +194,7 @@ fun ResetPasswordScreen() {
|
||||
text = stringResource(R.string.back_upper),
|
||||
contentPadding = PaddingValues(0.dp),
|
||||
) {
|
||||
navController.popBackStack()
|
||||
navController.navigateUp()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -140,7 +140,7 @@ fun ChangePasswordScreen() {
|
||||
try {
|
||||
viewModel.changePassword(currentPassword, newPassword)
|
||||
|
||||
navController.popBackStack()
|
||||
navController.navigateUp()
|
||||
} catch (e: ServiceException) {
|
||||
when (e.errorType) {
|
||||
ErrorCode.IncorrectOldPassword ->
|
||||
|
||||
@@ -39,6 +39,7 @@ import com.aiosman.riderpro.ui.composables.CustomAsyncImage
|
||||
import com.aiosman.riderpro.ui.composables.StatusBarSpacer
|
||||
import com.aiosman.riderpro.ui.composables.form.FormTextInput
|
||||
import com.aiosman.riderpro.ui.modifiers.noRippleClickable
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
/**
|
||||
@@ -60,6 +61,7 @@ fun AccountEditScreen2() {
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
val appColors = LocalAppTheme.current
|
||||
|
||||
fun onBioChange(value: String) {
|
||||
@@ -75,7 +77,7 @@ fun AccountEditScreen2() {
|
||||
}
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
if (model.profile == null){
|
||||
if (model.profile == null) {
|
||||
model.reloadProfile()
|
||||
}
|
||||
|
||||
@@ -99,14 +101,22 @@ fun AccountEditScreen2() {
|
||||
modifier = Modifier
|
||||
.size(24.dp)
|
||||
.noRippleClickable {
|
||||
model.viewModelScope.launch {
|
||||
model.updateUserProfile(context)
|
||||
navController.popBackStack()
|
||||
|
||||
if (validate() && !model.isUpdating) {
|
||||
model.viewModelScope.launch {
|
||||
model.isUpdating = true
|
||||
model.updateUserProfile(context)
|
||||
model.viewModelScope.launch(Dispatchers.Main) {
|
||||
navController.navigateUp()
|
||||
model.isUpdating = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
imageVector = Icons.Default.Check,
|
||||
contentDescription = "保存",
|
||||
tint = if (validate()) Color.Black else Color.Gray
|
||||
tint = if (validate() && !model.isUpdating) Color.Black else Color.Gray
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -176,7 +176,7 @@ fun ChatScreen(userId: String) {
|
||||
modifier = Modifier
|
||||
.size(28.dp)
|
||||
.noRippleClickable {
|
||||
navController.popBackStack()
|
||||
navController.navigateUp()
|
||||
},
|
||||
contentDescription = null,
|
||||
colorFilter = ColorFilter.tint(
|
||||
|
||||
@@ -81,7 +81,7 @@ fun NoticeScreenHeader(
|
||||
indication = null,
|
||||
interactionSource = remember { MutableInteractionSource() }
|
||||
) {
|
||||
nav.popBackStack()
|
||||
nav.navigateUp()
|
||||
},
|
||||
colorFilter = ColorFilter.tint(AppColors.text)
|
||||
)
|
||||
|
||||
@@ -115,6 +115,7 @@ fun ImageCropScreen() {
|
||||
AccountEditViewModel.viewModelScope.launch {
|
||||
AccountEditViewModel.updateUserProfile(context)
|
||||
navController.popBackStack()
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ fun ImageViewer() {
|
||||
.zoomable(
|
||||
zoomState = zoomState,
|
||||
onTap = {
|
||||
navController.popBackStack()
|
||||
navController.navigateUp()
|
||||
}
|
||||
)
|
||||
,
|
||||
|
||||
@@ -131,7 +131,7 @@ fun SearchScreen() {
|
||||
stringResource(R.string.cancel),
|
||||
fontSize = 16.sp,
|
||||
modifier = Modifier.noRippleClickable {
|
||||
navController.popBackStack()
|
||||
navController.navigateUp()
|
||||
},
|
||||
color = AppColors.text
|
||||
)
|
||||
|
||||
@@ -229,7 +229,7 @@ fun SignupScreen() {
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
modifier = Modifier.noRippleClickable {
|
||||
navController.popBackStack()
|
||||
navController.navigateUp()
|
||||
}
|
||||
) {
|
||||
Image(
|
||||
|
||||
@@ -3,8 +3,13 @@ package com.aiosman.riderpro.ui.modifiers
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.composed
|
||||
import com.aiosman.riderpro.LocalNavController
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
inline fun Modifier.noRippleClickable(crossinline onClick: () -> Unit): Modifier = composed {
|
||||
this.clickable(indication = null,
|
||||
@@ -12,3 +17,24 @@ inline fun Modifier.noRippleClickable(crossinline onClick: () -> Unit): Modifier
|
||||
onClick()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline fun Modifier.noRippleClickable(
|
||||
debounceTime: Long = 300L,
|
||||
crossinline onClick: () -> Unit
|
||||
): Modifier = composed {
|
||||
var job: Job? = null
|
||||
val scope = rememberCoroutineScope()
|
||||
this.clickable(
|
||||
indication = null,
|
||||
interactionSource = remember { MutableInteractionSource() }
|
||||
) {
|
||||
job?.cancel()
|
||||
job = scope.launch {
|
||||
delay(debounceTime)
|
||||
onClick()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -331,7 +331,7 @@ fun PostScreen(
|
||||
},
|
||||
onDeleteClick = {
|
||||
viewModel.deleteMoment {
|
||||
navController.popBackStack()
|
||||
navController.navigateUp()
|
||||
}
|
||||
}
|
||||
)
|
||||
@@ -682,7 +682,7 @@ fun Header(
|
||||
contentDescription = "Back",
|
||||
modifier = Modifier
|
||||
.noRippleClickable {
|
||||
navController.popBackStack()
|
||||
navController.navigateUp()
|
||||
}
|
||||
.size(32.dp),
|
||||
colorFilter = ColorFilter.tint(AppColors.text)
|
||||
|
||||
Reference in New Issue
Block a user