更新代码

This commit is contained in:
2024-11-03 09:17:46 +08:00
parent d49e037f51
commit 3cef90c887
29 changed files with 261 additions and 113 deletions

View File

@@ -423,12 +423,16 @@ class AccountServiceImpl : AccountService {
override suspend fun loginUserWithGoogle(googleId: String): UserAuth {
val resp = ApiClient.api.login(LoginUserRequestBody(googleId = googleId))
val body = resp.body() ?: throw ServiceException("Failed to login")
return UserAuth(0, body.token)
}
override suspend fun regiterUserWithGoogleAccount(idToken: String) {
val resp = ApiClient.api.registerWithGoogle(GoogleRegisterRequestBody(idToken))
if (resp.code() != 200) {
if (!resp.isSuccessful) {
parseErrorResponse(resp.errorBody())?.let {
throw it.toServiceException()
}
throw ServiceException("Failed to register")
}
}
@@ -472,7 +476,13 @@ class AccountServiceImpl : AccountService {
}
override suspend fun changeAccountPassword(oldPassword: String, newPassword: String) {
ApiClient.api.changePassword(ChangePasswordRequestBody(oldPassword, newPassword))
val resp = ApiClient.api.changePassword(ChangePasswordRequestBody(oldPassword, newPassword))
if (!resp.isSuccessful) {
parseErrorResponse(resp.errorBody())?.let {
throw it.toServiceException()
}
throw ServiceException("Failed to change password")
}
}
override suspend fun getMyLikeNotice(page: Int, pageSize: Int): ListContainer<AccountLike> {

View File

@@ -1,5 +1,7 @@
package com.aiosman.riderpro.data
import com.aiosman.riderpro.data.api.ErrorCode
import com.aiosman.riderpro.data.api.toErrorCode
import com.google.gson.Gson
import com.google.gson.annotations.SerializedName
import okhttp3.ResponseBody
@@ -13,6 +15,7 @@ class ServiceException(
val data: Any? = null,
val error: String? = null,
val name: String? = null,
val errorType: ErrorCode = ErrorCode.UNKNOWN
) : Exception(
message
)
@@ -30,7 +33,8 @@ data class ApiErrorResponse(
message = error ?: name ?: "",
code = code,
error = error,
name = name
name = name,
errorType = (code ?: 0).toErrorCode()
)
}
}

View File

@@ -0,0 +1,42 @@
package com.aiosman.riderpro.data.api
import android.content.Context
import android.widget.Toast
import com.aiosman.riderpro.R
//
enum class ErrorCode(val code: Int) {
USER_EXIST(40001),
USER_NOT_EXIST(40002),
InvalidateCaptcha(40004),
IncorrectOldPassword(40005),
// 未知错误
UNKNOWN(99999)
}
fun ErrorCode.toErrorMessage(context: Context): String {
return context.getErrorMessageCode(code)
}
fun ErrorCode.showToast(context: Context) {
Toast.makeText(context, toErrorMessage(context), Toast.LENGTH_SHORT).show()
}
// code to ErrorCode
fun Int.toErrorCode(): ErrorCode {
return when (this) {
40001 -> ErrorCode.USER_EXIST
40002 -> ErrorCode.USER_NOT_EXIST
40004 -> ErrorCode.InvalidateCaptcha
40005 -> ErrorCode.IncorrectOldPassword
else -> ErrorCode.UNKNOWN
}
}
fun Context.getErrorMessageCode(code: Int?): String {
return when (code) {
40001 -> getString(R.string.error_10001_user_exist)
ErrorCode.IncorrectOldPassword.code -> getString(R.string.error_incorrect_old_password)
else -> getString(R.string.error_unknown)
}
}

View File

@@ -26,7 +26,7 @@ import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.aiosman.riderpro.ConstVars
import com.aiosman.riderpro.ErrorCode
import com.aiosman.riderpro.data.api.ErrorCode
import com.aiosman.riderpro.LocalAppTheme
import com.aiosman.riderpro.LocalNavController
import com.aiosman.riderpro.R

View File

@@ -32,6 +32,7 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.compose.ui.viewinterop.AndroidView
import com.aiosman.riderpro.ConstVars
import com.aiosman.riderpro.LocalAppTheme
import com.aiosman.riderpro.R
import com.aiosman.riderpro.data.DictService
import com.aiosman.riderpro.data.DictServiceImpl
@@ -51,6 +52,7 @@ fun PolicyCheckbox(
var scope = rememberCoroutineScope()
val dictService: DictService = DictServiceImpl()
var policyUrl by remember { mutableStateOf("") }
val appColor = LocalAppTheme.current
fun openPolicyModel() {
scope.launch {
try {
@@ -91,13 +93,13 @@ fun PolicyCheckbox(
val template = stringResource(R.string.private_policy_template)
append(template)
append(" ")
withStyle(style = SpanStyle(color = if (error) Color.Red else Color.Black)) {
withStyle(style = SpanStyle(color = if (error) appColor.error else appColor.text)) {
append(keyword)
}
addStyle(
style = SpanStyle(
color = Color.Red,
color = appColor.main,
textDecoration = TextDecoration.Underline
),
start = template.length + 1,
@@ -113,7 +115,7 @@ fun PolicyCheckbox(
},
style = TextStyle(
fontSize = 12.sp,
color = if (error) Color.Red else Color.Black
color = if (error) appColor.error else appColor.text
)
)
}

View File

@@ -1,10 +1,12 @@
package com.aiosman.riderpro.ui.follower
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
@@ -19,6 +21,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
@@ -62,6 +65,38 @@ fun FollowerNoticeScreen() {
model.reload()
model.updateNotice()
}
if (followers.itemCount == 0) {
Box(
modifier = Modifier
.fillMaxSize(),
contentAlignment = Alignment.Center
) {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier.fillMaxWidth()
) {
Image(
painter = painterResource(id = R.mipmap.rider_pro_followers_empty),
contentDescription = null,
modifier = Modifier.size(140.dp)
)
Spacer(modifier = Modifier.size(32.dp))
androidx.compose.material.Text(
text = "No followers yet",
color = AppColors.text,
fontSize = 16.sp,
fontWeight = FontWeight.W600
)
Spacer(modifier = Modifier.size(16.dp))
androidx.compose.material.Text(
text = "Share your life and get more followers.",
color = AppColors.text,
fontSize = 16.sp,
fontWeight = FontWeight.W400
)
}
}
}else{
LazyColumn(
modifier = Modifier.weight(1f)
.background(color = AppColors.background)
@@ -82,6 +117,9 @@ fun FollowerNoticeScreen() {
}
}
}
}
}
@@ -125,44 +163,6 @@ fun FollowItem(
) {
Text(nickname, fontWeight = FontWeight.Bold, fontSize = 16.sp, color = AppColors.text)
}
// if (userId != AppState.UserId) {
// FollowButton(
// isFollowing = isFollowing,
// onFollowClick = onFollow,
// fontSize = 14.sp,
// imageModifier = Modifier
// .width(100.dp)
// .height(24.dp)
// )
// }
// Box(
// modifier = Modifier.noRippleClickable {
// onFollow()
// }
// ) {
// Image(
// painter = painterResource(id = R.drawable.follow_bg),
// contentDescription = "Follow",
// modifier = Modifier
// .width(79.dp)
// .height(24.dp)
// )
// Text(
// text = if (isFollowing) {
// stringResource(R.string.following_upper)
// } else {
// stringResource(R.string.follow_upper)
// },
// fontSize = 14.sp,
// color = Color(0xFFFFFFFF),
// modifier = Modifier.align(
// Alignment.Center
// )
// )
// }
}
}
}

View File

@@ -1,10 +1,14 @@
package com.aiosman.riderpro.ui.follower
import androidx.compose.foundation.Image
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.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.pullrefresh.PullRefreshIndicator
@@ -15,8 +19,11 @@ import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.paging.compose.collectAsLazyPagingItems
import com.aiosman.riderpro.LocalAppTheme
import com.aiosman.riderpro.R
@@ -51,6 +58,38 @@ fun FollowingListScreen(userId: Int) {
) {
NoticeScreenHeader(stringResource(R.string.following_upper), moreIcon = false)
}
if(users.itemCount == 0) {
Box(
modifier = Modifier
.fillMaxSize(),
contentAlignment = Alignment.Center
) {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier.fillMaxWidth()
) {
Image(
painter = painterResource(id = R.mipmap.rider_pro_following_empty),
contentDescription = null,
modifier = Modifier.size(140.dp)
)
Spacer(modifier = Modifier.size(32.dp))
androidx.compose.material.Text(
text = "You haven't followed anyone yet",
color = AppColors.text,
fontSize = 16.sp,
fontWeight = FontWeight.W600
)
Spacer(modifier = Modifier.size(16.dp))
androidx.compose.material.Text(
text = "Click start your social journey.",
color = AppColors.text,
fontSize = 16.sp,
fontWeight = FontWeight.W400
)
}
}
}else{
Box(
modifier = Modifier
.fillMaxWidth()
@@ -86,4 +125,6 @@ fun FollowingListScreen(userId: Int) {
)
}
}
}
}

View File

@@ -1,10 +1,12 @@
package com.aiosman.riderpro.ui.like
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
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
@@ -23,6 +25,7 @@ import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
@@ -81,6 +84,30 @@ fun LikeNoticeScreen() {
}
// Spacer(modifier = Modifier.height(28.dp))
if (likes.itemCount == 0) {
Box(
modifier = Modifier.fillMaxSize(),
contentAlignment = Alignment.Center
) {
Column(
modifier = Modifier.fillMaxWidth(),
horizontalAlignment = Alignment.CenterHorizontally
) {
Image(
painter = painterResource(id = R.mipmap.rider_pro_like_empty),
contentDescription = "No Notice",
modifier = Modifier.size(140.dp)
)
Spacer(modifier = Modifier.height(32.dp))
Text(
text = "Your like notification box is feeling lonely",
color = AppColors.text,
fontSize = 16.sp,
fontWeight = FontWeight.W500,
)
}
}
}else{
LazyColumn(
modifier = Modifier.weight(1f),
state = listState,
@@ -109,6 +136,8 @@ fun LikeNoticeScreen() {
}
}
}
}
}
}

View File

@@ -24,13 +24,13 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.aiosman.riderpro.AppState
import com.aiosman.riderpro.AppStore
import com.aiosman.riderpro.ErrorCode
import com.aiosman.riderpro.data.api.ErrorCode
import com.aiosman.riderpro.LocalNavController
import com.aiosman.riderpro.R
import com.aiosman.riderpro.data.AccountService
import com.aiosman.riderpro.data.ServiceException
import com.aiosman.riderpro.data.AccountServiceImpl
import com.aiosman.riderpro.getErrorMessageCode
import com.aiosman.riderpro.data.api.getErrorMessageCode
import com.aiosman.riderpro.ui.NavigationRoute
import com.aiosman.riderpro.ui.comment.NoticeScreenHeader
import com.aiosman.riderpro.ui.composables.ActionButton

View File

@@ -50,11 +50,14 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.aiosman.riderpro.AppState
import com.aiosman.riderpro.AppStore
import com.aiosman.riderpro.data.api.ErrorCode
import com.aiosman.riderpro.LocalAppTheme
import com.aiosman.riderpro.LocalNavController
import com.aiosman.riderpro.R
import com.aiosman.riderpro.data.AccountServiceImpl
import com.aiosman.riderpro.data.ServiceException
import com.aiosman.riderpro.data.api.getErrorMessageCode
import com.aiosman.riderpro.data.api.showToast
import com.aiosman.riderpro.ui.NavigationRoute
import com.aiosman.riderpro.ui.composables.ActionButton
import com.aiosman.riderpro.ui.modifiers.noRippleClickable
@@ -83,6 +86,20 @@ fun LoginPage() {
coroutineScope.launch {
try {
accountService.regiterUserWithGoogleAccount(it)
}catch (e : ServiceException) {
when (e.errorType) {
ErrorCode.USER_EXIST ->
Toast.makeText(
context,
context.getErrorMessageCode(e.errorType.code),
Toast.LENGTH_SHORT
).show()
else -> {
e.errorType.showToast(context)
}
}
Log.e(TAG, "Failed to register with google", e)
return@launch
} catch (e: Exception) {
Log.e(TAG, "Failed to register with google", e)
return@launch

View File

@@ -32,6 +32,7 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.aiosman.riderpro.AppState
import com.aiosman.riderpro.AppStore
import com.aiosman.riderpro.LocalAppTheme
import com.aiosman.riderpro.LocalNavController
import com.aiosman.riderpro.Messaging
import com.aiosman.riderpro.R
@@ -53,7 +54,7 @@ fun SignupScreen() {
val context = LocalContext.current
val coroutineScope = rememberCoroutineScope()
val accountService: AccountService = AccountServiceImpl()
val appColor = LocalAppTheme.current
fun googleLogin() {
coroutineScope.launch {
try {
@@ -114,7 +115,7 @@ fun SignupScreen() {
Scaffold(
modifier = Modifier
.fillMaxSize()
.background(Color(0xFFECECEC))
.background(appColor.background)
) {
it
Box(

View File

@@ -31,7 +31,7 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.aiosman.riderpro.AppState
import com.aiosman.riderpro.AppStore
import com.aiosman.riderpro.ErrorCode
import com.aiosman.riderpro.data.api.ErrorCode
import com.aiosman.riderpro.LocalAppTheme
import com.aiosman.riderpro.LocalNavController
import com.aiosman.riderpro.R

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

View File

@@ -93,4 +93,5 @@
<string name="clear">清除</string>
<string name="incorrect_captcha_please_try_again">验证码错误,请重试</string>
<string name="search_user_item_follower_count">%d 粉丝</string>
<string name="error_incorrect_old_password">旧密码不正确</string>
</resources>

View File

@@ -92,4 +92,5 @@
<string name="clear">Clear</string>
<string name="incorrect_captcha_please_try_again">incorrect captcha,please try again</string>
<string name="search_user_item_follower_count">%d followers</string>
<string name="error_incorrect_old_password">Incorrect old password</string>
</resources>