Skip to content

Commit 96d9998

Browse files
committed
feat(user-profile): 优化好友位置计算并调整用户资料逻辑
- 更改 `onClickUserIcon` 参数类型为 `FriendData` - 新增好友位置动态计算支持,增强好友位置逻辑 - 修改 `UserProfileScreen` 和相关组件参数传递方式,提高一致性 - 修复冗余代码,提升代码可读性和维护性
1 parent b37135f commit 96d9998

File tree

6 files changed

+19
-16
lines changed

6 files changed

+19
-16
lines changed

composeApp/src/commonMain/kotlin/presentation/compoments/LocationDialog.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ class LocationDialog(
6565
val onClickUserIcon = { user: IUser ->
6666
if (currentNavigator.size <= 1) {
6767
currentNavigator push UserProfileScreen(
68-
UserProfileVo(user),
69-
sharedSuffixKey
68+
userProfileVO = UserProfileVo(user),
69+
sharedSuffixKey = sharedSuffixKey
7070
)
7171
}
7272
}

composeApp/src/commonMain/kotlin/presentation/compoments/UserStateIcon.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ fun UserIconsRow(
5454
modifier: Modifier = Modifier,
5555
friends: List<State<FriendData>>,
5656
contentPadding: PaddingValues = PaddingValues(0.dp),
57-
onClickUserIcon: (IUser) -> Unit,
57+
onClickUserIcon: (FriendData) -> Unit,
5858
) {
5959
if (friends.isEmpty()) return
6060
LazyRow(

composeApp/src/commonMain/kotlin/presentation/screens/home/pager/FriendLocationPager.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import androidx.compose.ui.graphics.vector.rememberVectorPainter
1414
import androidx.compose.ui.unit.dp
1515
import cafe.adriel.voyager.koin.koinScreenModel
1616
import io.github.vrcmteam.vrcm.core.shared.SharedFlowCentre
17-
import io.github.vrcmteam.vrcm.network.api.attributes.IUser
1817
import io.github.vrcmteam.vrcm.network.api.attributes.LocationType
18+
import io.github.vrcmteam.vrcm.network.api.friends.date.FriendData
1919
import io.github.vrcmteam.vrcm.presentation.compoments.LocalSharedSuffixKey
2020
import io.github.vrcmteam.vrcm.presentation.compoments.LocationCard
2121
import io.github.vrcmteam.vrcm.presentation.compoments.RefreshBox
@@ -119,11 +119,12 @@ fun Pager.FriendLocationPager(
119119
}
120120
}
121121
val topPadding = getInsetPadding(WindowInsets::getTop) + 80.dp
122-
val onClickUserIcon = { user: IUser ->
122+
val onClickUserIcon = { user: FriendData ->
123123
if (navigator.size <= 1) {
124124
navigator push UserProfileScreen(
125-
UserProfileVo(user),
126-
sharedSuffixKey
125+
userProfileVO = UserProfileVo(user),
126+
location = user.location,
127+
sharedSuffixKey = sharedSuffixKey
127128
)
128129
}
129130
}
@@ -201,7 +202,7 @@ fun Pager.FriendLocationPager(
201202
private fun LazyListScope.SimpleCLocationCard(
202203
friendLocation: FriendLocation?,
203204
locationType: LocationType,
204-
onClickUserIcon: (IUser) -> Unit,
205+
onClickUserIcon: (FriendData) -> Unit,
205206
text: @Composable () -> String,
206207
) {
207208
friendLocation?.friendList.let {

composeApp/src/commonMain/kotlin/presentation/screens/user/UserProfileScreen.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import org.koin.core.parameter.parametersOf
4343

4444
data class UserProfileScreen(
4545
private val userProfileVO: UserProfileVo,
46+
private val location: String = userProfileVO.location,
4647
private val sharedSuffixKey: String = "",
4748
) : Screen {
4849
@OptIn(ExperimentalMaterial3Api::class)
@@ -55,6 +56,9 @@ data class UserProfileScreen(
5556
LaunchedEffect(userProfileVO.id) {
5657
userProfileScreenModel.initUserState(userProfileVO)
5758
}
59+
LaunchedEffect(location){
60+
userProfileScreenModel.computeFriendLocation(location)
61+
}
5862
LaunchedEffect(Unit) {
5963
SharedFlowCentre.logout.collect {
6064
currentNavigator replaceAll AuthAnimeScreen(false)
@@ -334,8 +338,8 @@ private fun ProfileContent(
334338
friends = friends,
335339
onClickUserIcon = { user ->
336340
navigator replace UserProfileScreen(
337-
UserProfileVo(user),
338-
sharedSuffixKey
341+
userProfileVO = UserProfileVo(user),
342+
sharedSuffixKey = sharedSuffixKey
339343
)
340344
}
341345
)

composeApp/src/commonMain/kotlin/presentation/screens/user/UserProfileScreenModel.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ class UserProfileScreenModel(
4848
fun initUserState(userProfileVO: UserProfileVo) {
4949
if (userProfileVO.id != _userState.value.id){
5050
_userState.value = userProfileVO
51-
computeFriendLocation(userProfileVO)
5251
}
5352
}
5453

@@ -63,7 +62,7 @@ class UserProfileScreenModel(
6362
runCatching { UserProfileVo(response.body<UserData>()) }
6463
.onSuccess {
6564
_userState.value = it
66-
computeFriendLocation(it)
65+
computeFriendLocation(it.location)
6766
}
6867
.onFailure { handleError(it) }
6968
_userJson.value = response.bodyAsText().pretty()
@@ -118,8 +117,7 @@ class UserProfileScreenModel(
118117
SharedFlowCentre.toastText.emit(ToastText.Error(it.message.toString()))
119118
}
120119

121-
private fun computeFriendLocation(user: UserProfileVo) {
122-
val location = user.location
120+
fun computeFriendLocation(location: String) {
123121
val type = LocationType.fromValue(location)
124122
if (location.isEmpty() || type != LocationType.Instance || _friendLocation.value != null) {
125123
return

composeApp/src/commonMain/kotlin/presentation/screens/user/data/UserProfileVo.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ data class UserProfileVo(
2525
override val currentAvatarTags: List<String> = listOf(),
2626
override val userIcon: String = "",
2727
override val profilePicOverride: String = "",
28-
override val lastLogin: String? = "",
28+
override val lastLogin: String = "",
2929
override val lastPlatform: String = "",
3030
override val developerType: String = "",
3131
override val pronouns: String = "",
@@ -50,7 +50,7 @@ data class UserProfileVo(
5050
currentAvatarTags = user.currentAvatarTags,
5151
userIcon = user.userIcon,
5252
profilePicOverride = user.profilePicOverride,
53-
lastLogin = user.lastLogin,
53+
lastLogin = user.lastLogin.orEmpty(),
5454
lastPlatform = user.lastPlatform,
5555
developerType = user.developerType,
5656
pronouns = user.pronouns.orEmpty(),

0 commit comments

Comments
 (0)