更新代码

This commit is contained in:
2024-09-22 15:35:42 +08:00
parent fc7d9336cd
commit 573b85f35d
16 changed files with 133 additions and 91 deletions

View File

@@ -6,6 +6,8 @@ import android.app.NotificationManager
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.icu.util.Calendar
import android.icu.util.TimeZone
import android.net.Uri
import android.os.Build
import android.os.Bundle
@@ -28,6 +30,7 @@ import com.aiosman.riderpro.data.AccountService
import com.aiosman.riderpro.data.AccountServiceImpl
import com.aiosman.riderpro.ui.Navigation
import com.aiosman.riderpro.ui.NavigationRoute
import com.aiosman.riderpro.ui.navigateToPost
import com.aiosman.riderpro.ui.post.NewPostViewModel
import com.aiosman.riderpro.utils.Utils
import com.google.android.libraries.places.api.Places
@@ -59,8 +62,14 @@ class MainActivity : ComponentActivity() {
val accountService: AccountService = AccountServiceImpl()
try {
val resp = accountService.getMyAccount()
accountService.updateUserLanguage(
Utils.getCurrentLanguage()
val calendar: Calendar = Calendar.getInstance()
val tz: TimeZone = calendar.timeZone
val offsetInMillis: Int = tz.rawOffset
accountService.updateUserExtra(
Utils.getCurrentLanguage(),
// 时区偏移量单位是秒
offsetInMillis / 1000,
tz.displayName
)
// 设置当前登录用户 ID
AppState.UserId = resp.id
@@ -122,19 +131,20 @@ class MainActivity : ComponentActivity() {
navController.navigate(NavigationRoute.Followers.route)
return@Navigation
}
if (action == "followCount") {
navController.navigate(NavigationRoute.Followers.route)
return@Navigation
}
if (commentId == null) {
commentId = "0"
}
if (postId != null) {
Log.d("MainActivity", "Navigation to Post$postId")
navController.navigate(
NavigationRoute.Post.route
.replace(
"{id}",
postId
)
.replace("{highlightCommentId}", commentId)
navController.navigateToPost(
id = postId.toInt(),
highlightCommentId = commentId.toInt(),
initImagePagerIndex = 0
)
}
// 处理分享过来的图片

View File

@@ -352,9 +352,9 @@ interface AccountService {
suspend fun resetPassword(email: String)
/**
* 更新用户语言
* 更新用户额外信息
*/
suspend fun updateUserLanguage(language: String)
suspend fun updateUserExtra(language: String, timeOffset: Int, timezone: String)
}
class AccountServiceImpl : AccountService {
@@ -486,8 +486,8 @@ class AccountServiceImpl : AccountService {
}
}
override suspend fun updateUserLanguage(language: String) {
ApiClient.api.updateUserLang(UpdateUserLangRequestBody(language))
override suspend fun updateUserExtra(language: String, timeOffset: Int, timezone: String) {
ApiClient.api.updateUserExtra(UpdateUserLangRequestBody(language, timeOffset, timezone))
}
}

View File

@@ -101,6 +101,10 @@ data class ResetPasswordRequestBody(
data class UpdateUserLangRequestBody(
@SerializedName("language")
val lang: String,
@SerializedName("timeOffset")
val timeOffset: Int,
@SerializedName("timezone")
val timezone: String,
)
interface RiderProAPI {
@@ -291,8 +295,8 @@ interface RiderProAPI {
@Path("id") id: Int
): Response<DataContainer<Comment>>
@PATCH("account/my/lang")
suspend fun updateUserLang(
@PATCH("account/my/extra")
suspend fun updateUserExtra(
@Body body: UpdateUserLangRequestBody
): Response<Unit>

View File

@@ -61,7 +61,7 @@ sealed class NavigationRoute(
data object LocationDetail : NavigationRoute("LocationDetail/{x}/{y}")
data object OfficialPhoto : NavigationRoute("OfficialPhoto")
data object OfficialPhotographer : NavigationRoute("OfficialPhotographer")
data object Post : NavigationRoute("Post/{id}/{highlightCommentId}")
data object Post : NavigationRoute("Post/{id}/{highlightCommentId}/{initImagePagerIndex}")
data object ModificationList : NavigationRoute("ModificationList")
data object MyMessage : NavigationRoute("MyMessage")
data object Comments : NavigationRoute("Comments")
@@ -137,19 +137,23 @@ fun NavigationController(
route = NavigationRoute.Post.route,
arguments = listOf(
navArgument("id") { type = NavType.StringType },
navArgument("highlightCommentId") { type = NavType.IntType }
navArgument("highlightCommentId") { type = NavType.IntType },
navArgument("initImagePagerIndex") { type = NavType.IntType }
),
) { backStackEntry ->
CompositionLocalProvider(
LocalAnimatedContentScope provides this,
) {
val id = backStackEntry.arguments?.getString("id")
val highlightCommentId = backStackEntry.arguments?.getInt("highlightCommentId")?.let {
if (it == 0) null else it
}
val highlightCommentId =
backStackEntry.arguments?.getInt("highlightCommentId")?.let {
if (it == 0) null else it
}
val initIndex = backStackEntry.arguments?.getInt("initImagePagerIndex")
PostScreen(
id!!,
highlightCommentId
highlightCommentId,
initImagePagerIndex = initIndex
)
}
}
@@ -364,4 +368,17 @@ fun Navigation(
}
}
}
}
fun NavHostController.navigateToPost(
id: Int,
highlightCommentId: Int? = 0,
initImagePagerIndex: Int? = null
) {
navigate(
route = NavigationRoute.Post.route
.replace("{id}", id.toString())
.replace("{highlightCommentId}", highlightCommentId.toString())
.replace("{initImagePagerIndex}", initImagePagerIndex.toString())
)
}

View File

@@ -31,6 +31,7 @@ import com.aiosman.riderpro.ui.composables.CustomAsyncImage
import com.aiosman.riderpro.ui.composables.StatusBarSpacer
import com.aiosman.riderpro.ui.favourite.FavouriteListViewModel.refreshPager
import com.aiosman.riderpro.ui.modifiers.noRippleClickable
import com.aiosman.riderpro.ui.navigateToPost
@OptIn(ExperimentalMaterialApi::class)
@Composable
@@ -79,11 +80,10 @@ fun FavouriteListPage() {
.padding(2.dp)
.noRippleClickable {
navController.navigate(
NavigationRoute.Post.route.replace(
"{id}",
momentItem.id.toString()
).replace("{highlightCommentId}", "0")
navController.navigateToPost(
id = momentItem.id,
highlightCommentId = 0,
initImagePagerIndex = 0
)
}
) {

View File

@@ -7,12 +7,9 @@ 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.WindowInsets
import androidx.compose.foundation.layout.asPaddingValues
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.navigationBars
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
@@ -28,10 +25,6 @@ import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
@@ -51,14 +44,13 @@ import com.aiosman.riderpro.R
import com.aiosman.riderpro.entity.CommentEntity
import com.aiosman.riderpro.exp.timeAgo
import com.aiosman.riderpro.ui.NavigationRoute
import com.aiosman.riderpro.ui.composables.BottomNavigationPlaceholder
import com.aiosman.riderpro.ui.composables.CustomAsyncImage
import com.aiosman.riderpro.ui.composables.StatusBarSpacer
import com.aiosman.riderpro.ui.favourite.FavouriteNoticeViewModel
import com.aiosman.riderpro.ui.follower.FollowerNoticeViewModel
import com.aiosman.riderpro.ui.like.LikeNoticeViewModel
import com.aiosman.riderpro.ui.modifiers.noRippleClickable
import com.aiosman.riderpro.ui.post.PostViewModel
import com.aiosman.riderpro.ui.navigateToPost
import com.google.accompanist.systemuicontroller.rememberSystemUiController
import kotlinx.coroutines.launch
@@ -179,14 +171,10 @@ fun NotificationsScreen() {
comment.parentCommentId?.let {
highlightCommentId = it
}
navController.navigate(
NavigationRoute.Post.route.replace(
"{id}",
comment.postId.toString()
).replace(
"{highlightCommentId}",
highlightCommentId.toString()
)
navController.navigateToPost(
id = comment.post!!.id,
highlightCommentId = highlightCommentId,
initImagePagerIndex = 0
)
}
}

View File

@@ -61,7 +61,6 @@ 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 androidx.paging.LoadState
import androidx.paging.compose.collectAsLazyPagingItems
import com.aiosman.riderpro.LocalNavController
import com.aiosman.riderpro.R
@@ -76,8 +75,8 @@ import com.aiosman.riderpro.ui.composables.AnimatedLikeIcon
import com.aiosman.riderpro.ui.composables.CustomAsyncImage
import com.aiosman.riderpro.ui.composables.RelPostCard
import com.aiosman.riderpro.ui.modifiers.noRippleClickable
import com.aiosman.riderpro.ui.navigateToPost
import com.aiosman.riderpro.ui.post.NewPostViewModel
import com.aiosman.riderpro.ui.post.PostViewModel
import kotlinx.coroutines.launch
/**
@@ -178,10 +177,10 @@ fun MomentCard(
modifier = Modifier
.fillMaxWidth()
.noRippleClickable {
navController.navigate(
route = NavigationRoute.Post.route
.replace("{id}", momentEntity.id.toString())
.replace("{highlightCommentId}", "0")
navController.navigateToPost(
momentEntity.id,
highlightCommentId = 0,
initImagePagerIndex = imageIndex
)
}
) {
@@ -203,8 +202,11 @@ fun MomentCard(
onFavoriteClick = onFavoriteClick,
imageIndex = imageIndex,
onCommentClick = {
// PostViewModel.preTransit(momentEntity)
navController.navigate("Post/${momentEntity.id}")
navController.navigateToPost(
momentEntity.id,
highlightCommentId = 0,
initImagePagerIndex = imageIndex
)
}
)
}

View File

@@ -33,7 +33,7 @@ object MomentViewModel : ViewModel() {
var refreshing by mutableStateOf(false)
var isFirstLoad = true
fun refreshPager(pullRefresh: Boolean = false) {
if (!isFirstLoad) {
if (!isFirstLoad && !pullRefresh) {
return
}
isFirstLoad = false

View File

@@ -40,9 +40,9 @@ object MyProfileViewModel : ViewModel() {
var refreshing by mutableStateOf(false)
var firstLoad = true
fun loadProfile(pullRefresh: Boolean = false) {
if (!firstLoad && !pullRefresh) {
return
}
// if (!firstLoad && !pullRefresh) {
// return
// }
viewModelScope.launch {
if (pullRefresh){
refreshing = true

View File

@@ -78,6 +78,8 @@ import com.aiosman.riderpro.ui.NavigationRoute
import com.aiosman.riderpro.ui.composables.CustomAsyncImage
import com.aiosman.riderpro.ui.composables.MenuItem
import com.aiosman.riderpro.ui.modifiers.noRippleClickable
import com.aiosman.riderpro.ui.navigateToPost
import com.aiosman.riderpro.ui.post.NewPostViewModel
import com.aiosman.riderpro.ui.post.PostViewModel
import kotlinx.coroutines.launch
@@ -673,9 +675,9 @@ fun ProfileEmptyMomentCard(
.fillMaxSize()
.background(Color(0xFFF5F5F5))
.noRippleClickable {
NewPostViewModel.asNewPost()
navController.navigate(NavigationRoute.NewPost.route)
}
) {
Icon(
Icons.Default.Add,
@@ -808,12 +810,10 @@ fun MomentCardPicture(imageUrl: String, momentEntity: MomentEntity) {
.aspectRatio(3f / 2f)
.padding(top = 16.dp)
.noRippleClickable {
// PostViewModel.preTransit(momentEntity)
navController.navigate(
NavigationRoute.Post.route.replace(
"{id}",
momentEntity.id.toString()
).replace("{highlightCommentId}", "0")
navController.navigateToPost(
id = momentEntity.id,
highlightCommentId = 0,
initImagePagerIndex = 0
)
},
contentDescription = "",

View File

@@ -6,17 +6,14 @@ 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.WindowInsets
import androidx.compose.foundation.layout.asPaddingValues
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.navigationBars
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.systemBars
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.shape.RoundedCornerShape
@@ -50,8 +47,7 @@ import com.aiosman.riderpro.ui.NavigationRoute
import com.aiosman.riderpro.ui.composables.CustomAsyncImage
import com.aiosman.riderpro.ui.composables.StatusBarSpacer
import com.aiosman.riderpro.ui.modifiers.noRippleClickable
import com.aiosman.riderpro.ui.post.PostViewModel
import com.google.accompanist.systemuicontroller.rememberSystemUiController
import com.aiosman.riderpro.ui.navigateToPost
@OptIn(ExperimentalFoundationApi::class, ExperimentalMaterialApi::class)
@@ -156,12 +152,10 @@ fun DiscoverView() {
.padding(2.dp)
.noRippleClickable {
// PostViewModel.preTransit(momentItem)
navController.navigate(
NavigationRoute.Post.route.replace(
"{id}",
momentItem.id.toString()
).replace("{highlightCommentId}", "0")
navController.navigateToPost(
id = momentItem.id,
highlightCommentId = 0,
initImagePagerIndex = 0
)
}
) {

View File

@@ -46,6 +46,7 @@ import com.aiosman.riderpro.ui.composables.CustomAsyncImage
import com.aiosman.riderpro.ui.composables.StatusBarMaskLayout
import com.aiosman.riderpro.ui.index.tabs.profile.MyProfileViewModel
import com.aiosman.riderpro.ui.modifiers.noRippleClickable
import com.aiosman.riderpro.ui.navigateToPost
import java.util.Date
@Preview
@@ -154,11 +155,10 @@ fun ActionPostNoticeItem(
modifier = Modifier
.weight(1f)
.noRippleClickable {
navController.navigate(
NavigationRoute.Post.route.replace(
"{id}",
postId.toString()
).replace("{highlightCommentId}", "0")
navController.navigateToPost(
id = postId,
highlightCommentId = 0,
initImagePagerIndex = 0
)
}
) {
@@ -192,11 +192,10 @@ fun LikeCommentNoticeItem(
Box(
modifier = Modifier.padding(vertical = 16.dp).noRippleClickable {
item.comment?.postId.let {
navController.navigate(
NavigationRoute.Post.route.replace(
"{id}",
it.toString()
).replace("{highlightCommentId}", "0")
navController.navigateToPost(
id = it ?: 0,
highlightCommentId = item.comment?.id ?: 0,
initImagePagerIndex = 0
)
}

View File

@@ -1,5 +1,7 @@
package com.aiosman.riderpro.ui.login
import android.icu.util.Calendar
import android.icu.util.TimeZone
import android.widget.Toast
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
@@ -156,8 +158,13 @@ fun EmailSignupScreen() {
try {
val resp = accountService.getMyAccount()
AppState.UserId = resp.id
accountService.updateUserLanguage(
Utils.getCurrentLanguage()
val calendar: Calendar = Calendar.getInstance()
val tz: TimeZone = calendar.timeZone
val offsetInMillis: Int = tz.rawOffset
accountService.updateUserExtra(
Utils.getCurrentLanguage(),
offsetInMillis / 1000,
tz.displayName
)
Messaging.RegistDevice(scope, context)
} catch (e: ServiceException) {

View File

@@ -1,6 +1,8 @@
package com.aiosman.riderpro.ui.login
import android.content.ContentValues.TAG
import android.icu.util.Calendar
import android.icu.util.TimeZone
import android.util.Log
import android.widget.Toast
import androidx.compose.foundation.Image
@@ -85,8 +87,13 @@ fun SignupScreen() {
// 获取token 信息
try {
val resp = accountService.getMyAccount()
accountService.updateUserLanguage(
Utils.getCurrentLanguage()
val calendar: Calendar = Calendar.getInstance()
val tz: TimeZone = calendar.timeZone
val offsetInMillis: Int = tz.rawOffset
accountService.updateUserExtra(
Utils.getCurrentLanguage(),
offsetInMillis / 1000,
tz.displayName
)
AppState.UserId = resp.id
Messaging.RegistDevice(coroutineScope, context)

View File

@@ -1,5 +1,7 @@
package com.aiosman.riderpro.ui.login
import android.icu.util.Calendar
import android.icu.util.TimeZone
import android.widget.Toast
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
@@ -44,6 +46,7 @@ import com.aiosman.riderpro.ui.composables.StatusBarSpacer
import com.aiosman.riderpro.ui.composables.TextInputField
import com.aiosman.riderpro.ui.modifiers.noRippleClickable
import com.aiosman.riderpro.utils.GoogleLogin
import com.aiosman.riderpro.utils.Utils
import kotlinx.coroutines.launch
@@ -81,6 +84,14 @@ fun UserAuthScreen() {
saveData()
}
accountService.getMyAccount()
val calendar: Calendar = Calendar.getInstance()
val tz: TimeZone = calendar.timeZone
val offsetInMillis: Int = tz.rawOffset
accountService.updateUserExtra(
Utils.getCurrentLanguage(),
offsetInMillis / 1000,
tz.displayName
)
Messaging.RegistDevice(scope, context)
navController.navigate(NavigationRoute.Index.route) {
popUpTo(NavigationRoute.Login.route) { inclusive = true }

View File

@@ -100,7 +100,8 @@ import kotlinx.coroutines.launch
@Composable
fun PostScreen(
id: String,
highlightCommentId: Int?
highlightCommentId: Int?,
initImagePagerIndex: Int?
) {
val viewModel = viewModel<PostViewModel>(
key = "PostViewModel_$id",
@@ -331,7 +332,8 @@ fun PostScreen(
.aspectRatio(383f / 527f)
) {
PostImageView(
viewModel.moment?.images ?: emptyList()
viewModel.moment?.images ?: emptyList(),
initialPage = initImagePagerIndex
)
}
@@ -440,7 +442,7 @@ fun CommentContent(
}
},
)
)
}
}
@@ -719,8 +721,9 @@ fun Header(
@Composable
fun PostImageView(
images: List<MomentImageEntity>,
initialPage: Int? = 0
) {
val pagerState = rememberPagerState(pageCount = { images.size })
val pagerState = rememberPagerState(pageCount = { images.size }, initialPage = initialPage ?: 0)
val navController = LocalNavController.current
val sharedTransitionScope = LocalSharedTransitionScope.current
val animatedVisibilityScope = LocalAnimatedContentScope.current