调整界面以及修复多个bug
-调整mbti类型界面 -修复断网时,用户资料编辑保存出现闪退 -修复暂停短视频后进入后台并返回,视频会继续播放,暂停图标不会消失 -修复输入框为空时显示为英文,且个人简介布局靠上 -修复其他用户/智能体个人主页群聊列表显示我加入的群聊 -修复系统切换暗黑模式,应用会刷新,但模式不变
This commit is contained in:
@@ -54,7 +54,7 @@
|
|||||||
android:theme="@style/Theme.App.Starting"
|
android:theme="@style/Theme.App.Starting"
|
||||||
android:screenOrientation="portrait"
|
android:screenOrientation="portrait"
|
||||||
android:windowSoftInputMode="adjustResize"
|
android:windowSoftInputMode="adjustResize"
|
||||||
android:configChanges="fontScale|orientation|screenSize|keyboardHidden">
|
android:configChanges="fontScale|orientation|screenSize|keyboardHidden|uiMode">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
|
|||||||
@@ -73,6 +73,10 @@ class MainActivity : ComponentActivity() {
|
|||||||
val config = Configuration(newConfig)
|
val config = Configuration(newConfig)
|
||||||
config.fontScale = 1.0f
|
config.fontScale = 1.0f
|
||||||
super.onConfigurationChanged(config)
|
super.onConfigurationChanged(config)
|
||||||
|
val isNightMode = (newConfig.uiMode and Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES
|
||||||
|
if (AppState.darkMode != isNightMode) {
|
||||||
|
syncDarkModeWithSystem(isNightMode)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 请求通知权限
|
// 请求通知权限
|
||||||
@@ -129,9 +133,7 @@ class MainActivity : ComponentActivity() {
|
|||||||
|
|
||||||
JPushInterface.init(this)
|
JPushInterface.init(this)
|
||||||
|
|
||||||
if (AppState.darkMode) {
|
updateWindowBackground(AppState.darkMode)
|
||||||
window.decorView.setBackgroundColor(android.graphics.Color.BLACK)
|
|
||||||
}
|
|
||||||
enableEdgeToEdge()
|
enableEdgeToEdge()
|
||||||
|
|
||||||
scope.launch {
|
scope.launch {
|
||||||
@@ -269,8 +271,22 @@ class MainActivity : ComponentActivity() {
|
|||||||
notificationManager.createNotificationChannel(channel)
|
notificationManager.createNotificationChannel(channel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun syncDarkModeWithSystem(isNightMode: Boolean) {
|
||||||
|
AppState.darkMode = isNightMode
|
||||||
|
AppState.appTheme = if (isNightMode) DarkThemeColors() else LightThemeColors()
|
||||||
|
AppStore.saveDarkMode(isNightMode)
|
||||||
|
updateWindowBackground(isNightMode)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun updateWindowBackground(isDarkMode: Boolean) {
|
||||||
|
window.decorView.setBackgroundColor(
|
||||||
|
if (isDarkMode) android.graphics.Color.BLACK else android.graphics.Color.WHITE
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
val LocalNavController = compositionLocalOf<NavHostController> {
|
val LocalNavController = compositionLocalOf<NavHostController> {
|
||||||
error("NavController not provided")
|
error("NavController not provided")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -545,7 +545,13 @@ class AccountServiceImpl : AccountService {
|
|||||||
val bannerField: MultipartBody.Part? = banner?.let {
|
val bannerField: MultipartBody.Part? = banner?.let {
|
||||||
createMultipartBody(it.file, it.filename, "banner")
|
createMultipartBody(it.file, it.filename, "banner")
|
||||||
}
|
}
|
||||||
ApiClient.api.updateProfile(avatarField, bannerField, nicknameField, bioField)
|
val resp = ApiClient.api.updateProfile(avatarField, bannerField, nicknameField, bioField)
|
||||||
|
if (!resp.isSuccessful) {
|
||||||
|
parseErrorResponse(resp.errorBody())?.let {
|
||||||
|
throw it.toServiceException()
|
||||||
|
}
|
||||||
|
throw ServiceException("Failed to update profile")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun registerUserWithPassword(loginName: String, password: String) {
|
override suspend fun registerUserWithPassword(loginName: String, password: String) {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.aiosman.ravenow
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
|
import android.content.res.Configuration
|
||||||
import com.google.android.gms.auth.api.signin.GoogleSignInOptions
|
import com.google.android.gms.auth.api.signin.GoogleSignInOptions
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -24,11 +25,16 @@ object AppStore {
|
|||||||
.requestEmail()
|
.requestEmail()
|
||||||
.build()
|
.build()
|
||||||
googleSignInOptions = gso
|
googleSignInOptions = gso
|
||||||
// apply dark mode
|
// apply dark mode - 如果用户未手动设置,优先跟随系统
|
||||||
if (sharedPreferences.getBoolean("darkMode", false)) {
|
val hasUserPreference = sharedPreferences.contains("darkMode")
|
||||||
AppState.darkMode = true
|
val resolvedDarkMode = if (hasUserPreference) {
|
||||||
AppState.appTheme = DarkThemeColors()
|
sharedPreferences.getBoolean("darkMode", false)
|
||||||
|
} else {
|
||||||
|
val currentNightMode = context.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
|
||||||
|
currentNightMode == Configuration.UI_MODE_NIGHT_YES
|
||||||
}
|
}
|
||||||
|
AppState.darkMode = resolvedDarkMode
|
||||||
|
AppState.appTheme = if (resolvedDarkMode) DarkThemeColors() else LightThemeColors()
|
||||||
|
|
||||||
// load chat background
|
// load chat background
|
||||||
val savedBgUrl = sharedPreferences.getString("chatBackgroundUrl", null)
|
val savedBgUrl = sharedPreferences.getString("chatBackgroundUrl", null)
|
||||||
|
|||||||
@@ -20,9 +20,8 @@ import androidx.compose.foundation.layout.offset
|
|||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.layout.size
|
import androidx.compose.foundation.layout.size
|
||||||
import androidx.compose.foundation.layout.systemBars
|
import androidx.compose.foundation.layout.systemBars
|
||||||
import androidx.compose.foundation.lazy.grid.GridCells
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
|
import androidx.compose.foundation.lazy.itemsIndexed
|
||||||
import androidx.compose.foundation.lazy.grid.itemsIndexed
|
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
import androidx.compose.material3.ModalBottomSheet
|
import androidx.compose.material3.ModalBottomSheet
|
||||||
@@ -219,44 +218,78 @@ fun MbtiSelectBottomSheet(
|
|||||||
val nestedScrollConnection = remember {
|
val nestedScrollConnection = remember {
|
||||||
object : NestedScrollConnection {
|
object : NestedScrollConnection {
|
||||||
override fun onPreScroll(available: Offset, source: NestedScrollSource): Offset {
|
override fun onPreScroll(available: Offset, source: NestedScrollSource): Offset {
|
||||||
// 不消费任何事件,让 LazyVerticalGrid 先处理
|
// 不消费任何事件,让 LazyColumn 先处理
|
||||||
return Offset.Zero
|
return Offset.Zero
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPostScroll(consumed: Offset, available: Offset, source: NestedScrollSource): Offset {
|
override fun onPostScroll(consumed: Offset, available: Offset, source: NestedScrollSource): Offset {
|
||||||
// 消费 LazyVerticalGrid 处理后的剩余滚动事件,防止传递到 ModalBottomSheet
|
// 消费 LazyColumn 处理后的剩余滚动事件,防止传递到 ModalBottomSheet
|
||||||
return available
|
return available
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun onPreFling(available: Velocity): Velocity {
|
override suspend fun onPreFling(available: Velocity): Velocity {
|
||||||
// 不消费惯性滚动,让 LazyVerticalGrid 先处理
|
// 不消费惯性滚动,让 LazyColumn 先处理
|
||||||
return Velocity.Zero
|
return Velocity.Zero
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun onPostFling(consumed: Velocity, available: Velocity): Velocity {
|
override suspend fun onPostFling(consumed: Velocity, available: Velocity): Velocity {
|
||||||
// 消费 LazyVerticalGrid 处理后的剩余惯性滚动,防止传递到 ModalBottomSheet
|
// 消费 LazyColumn 处理后的剩余惯性滚动,防止传递到 ModalBottomSheet
|
||||||
return available
|
return available
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 网格列表 - 2列
|
// MBTI解释文字背景色
|
||||||
LazyVerticalGrid(
|
val descriptionBackgroundColor = if (isDarkMode) {
|
||||||
columns = GridCells.Fixed(2),
|
Color(0xFF2A2A2A) // 比 secondaryBackground (0xFF1C1C1C) 更亮的灰色
|
||||||
|
} else {
|
||||||
|
Color(0xFFFAF9FB)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 使用LazyColumn包裹解释文字和MBTI类型网格,使它们一起滚动
|
||||||
|
LazyColumn(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.weight(1f)
|
.weight(1f)
|
||||||
.nestedScroll(nestedScrollConnection),
|
.nestedScroll(nestedScrollConnection),
|
||||||
contentPadding = PaddingValues(
|
contentPadding = PaddingValues(
|
||||||
start = 8.dp,
|
start = 8.dp,
|
||||||
top = 8.dp,
|
top = 0.dp,
|
||||||
end = 8.dp,
|
end = 8.dp,
|
||||||
bottom = 8.dp
|
bottom = 8.dp
|
||||||
),
|
),
|
||||||
horizontalArrangement = Arrangement.spacedBy(10.dp),
|
verticalArrangement = Arrangement.spacedBy(16.dp)
|
||||||
verticalArrangement = Arrangement.spacedBy(10.dp)
|
) {
|
||||||
|
// MBTI解释文字 - 作为第一个item
|
||||||
|
item {
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.clip(RoundedCornerShape(16.dp))
|
||||||
|
.background(descriptionBackgroundColor)
|
||||||
|
.padding(horizontal = 16.dp, vertical = 12.dp)
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
text = stringResource(R.string.mbti_description),
|
||||||
|
color = appColors.text,
|
||||||
|
fontSize = 14.sp,
|
||||||
|
lineHeight = 20.sp
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MBTI类型网格 - 手动创建2列网格布局
|
||||||
|
itemsIndexed(MBTI_TYPES.chunked(2)) { rowIndex, rowItems ->
|
||||||
|
Row(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(bottom = if (rowIndex < MBTI_TYPES.chunked(2).size - 1) 10.dp else 0.dp),
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(10.dp)
|
||||||
|
) {
|
||||||
|
rowItems.forEachIndexed { colIndex, mbti ->
|
||||||
|
Box(
|
||||||
|
modifier = Modifier.weight(1f)
|
||||||
) {
|
) {
|
||||||
itemsIndexed(MBTI_TYPES) { index, mbti ->
|
|
||||||
MbtiItem(
|
MbtiItem(
|
||||||
mbti = mbti,
|
mbti = mbti,
|
||||||
isSelected = mbti == currentMbti,
|
isSelected = mbti == currentMbti,
|
||||||
@@ -268,6 +301,13 @@ fun MbtiSelectBottomSheet(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// 如果这一行只有1个item,添加一个空的Spacer来保持布局
|
||||||
|
if (rowItems.size == 1) {
|
||||||
|
Spacer(modifier = Modifier.weight(1f))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -396,7 +396,7 @@ fun AccountEditScreen2(onUpdateBanner: ((Uri, File, Context) -> Unit)? = null,)
|
|||||||
ProfileInfoCard(
|
ProfileInfoCard(
|
||||||
label = stringResource(R.string.nickname),
|
label = stringResource(R.string.nickname),
|
||||||
value = model.name,
|
value = model.name,
|
||||||
placeholder = "Value",
|
placeholder = stringResource(R.string.nickname_placeholder),
|
||||||
onValueChange = { onNicknameChange(it) },
|
onValueChange = { onNicknameChange(it) },
|
||||||
isMultiline = false
|
isMultiline = false
|
||||||
)
|
)
|
||||||
@@ -407,7 +407,7 @@ fun AccountEditScreen2(onUpdateBanner: ((Uri, File, Context) -> Unit)? = null,)
|
|||||||
ProfileInfoCard(
|
ProfileInfoCard(
|
||||||
label = stringResource(R.string.personal_intro),
|
label = stringResource(R.string.personal_intro),
|
||||||
value = model.bio,
|
value = model.bio,
|
||||||
placeholder = "Welcome to my fantiac word i will show you something about magic",
|
placeholder = stringResource(R.string.bio_placeholder),
|
||||||
onValueChange = { onBioChange(it) },
|
onValueChange = { onBioChange(it) },
|
||||||
isMultiline = true
|
isMultiline = true
|
||||||
)
|
)
|
||||||
@@ -502,6 +502,7 @@ fun AccountEditScreen2(onUpdateBanner: ((Uri, File, Context) -> Unit)? = null,)
|
|||||||
// 验证通过,执行保存
|
// 验证通过,执行保存
|
||||||
model.viewModelScope.launch {
|
model.viewModelScope.launch {
|
||||||
model.isUpdating = true
|
model.isUpdating = true
|
||||||
|
try {
|
||||||
model.updateUserProfile(context)
|
model.updateUserProfile(context)
|
||||||
model.viewModelScope.launch(Dispatchers.Main) {
|
model.viewModelScope.launch(Dispatchers.Main) {
|
||||||
debouncedNavigation {
|
debouncedNavigation {
|
||||||
@@ -509,6 +510,17 @@ fun AccountEditScreen2(onUpdateBanner: ((Uri, File, Context) -> Unit)? = null,)
|
|||||||
}
|
}
|
||||||
model.isUpdating = false
|
model.isUpdating = false
|
||||||
}
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
// 捕获所有异常,包括网络异常
|
||||||
|
model.viewModelScope.launch(Dispatchers.Main) {
|
||||||
|
Toast.makeText(
|
||||||
|
context,
|
||||||
|
context.getString(R.string.network_error_check_network),
|
||||||
|
Toast.LENGTH_SHORT
|
||||||
|
).show()
|
||||||
|
model.isUpdating = false
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
contentAlignment = Alignment.Center
|
contentAlignment = Alignment.Center
|
||||||
@@ -568,13 +580,19 @@ fun ProfileInfoCard(
|
|||||||
verticalAlignment = if (isMultiline) Alignment.Top else Alignment.CenterVertically
|
verticalAlignment = if (isMultiline) Alignment.Top else Alignment.CenterVertically
|
||||||
) {
|
) {
|
||||||
// 标签
|
// 标签
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.width(100.dp)
|
||||||
|
.height(if (isMultiline) 44.dp else 56.dp),
|
||||||
|
contentAlignment = Alignment.CenterStart
|
||||||
|
) {
|
||||||
Text(
|
Text(
|
||||||
text = label,
|
text = label,
|
||||||
fontSize = 17.sp,
|
fontSize = 17.sp,
|
||||||
fontWeight = FontWeight.Normal,
|
fontWeight = FontWeight.Normal,
|
||||||
color = appColors.text,
|
color = appColors.text
|
||||||
modifier = Modifier.width(100.dp)
|
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
|
||||||
Spacer(modifier = Modifier.width(16.dp))
|
Spacer(modifier = Modifier.width(16.dp))
|
||||||
|
|
||||||
|
|||||||
@@ -319,6 +319,7 @@ object MyProfileViewModel : ViewModel() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val normalizedOwnerId = normalizeOwnerSessionId(ownerSessionId)
|
||||||
if (roomsLoading && !pullRefresh) return
|
if (roomsLoading && !pullRefresh) return
|
||||||
|
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
@@ -340,16 +341,16 @@ object MyProfileViewModel : ViewModel() {
|
|||||||
2 -> "private"
|
2 -> "private"
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
|
val effectiveRoomType = if (normalizedOwnerId != null) "public" else roomType
|
||||||
|
|
||||||
// 构建API调用参数
|
// 构建API调用参数
|
||||||
if (ownerSessionId != null) {
|
if (normalizedOwnerId != null) {
|
||||||
// 查看其他用户的房间:显示该用户创建和加入的房间
|
// 查看其他用户的房间:仅显示该用户创建的公开房间
|
||||||
// 1. 先快速获取该用户创建的房间(不需要 includeUsers,减少数据量)
|
|
||||||
val createdResponse = apiClient.getRooms(
|
val createdResponse = apiClient.getRooms(
|
||||||
page = currentPage,
|
page = currentPage,
|
||||||
pageSize = roomsPageSize,
|
pageSize = roomsPageSize,
|
||||||
roomType = roomType,
|
roomType = effectiveRoomType,
|
||||||
ownerSessionId = ownerSessionId,
|
ownerSessionId = normalizedOwnerId,
|
||||||
includeUsers = false
|
includeUsers = false
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -359,68 +360,23 @@ object MyProfileViewModel : ViewModel() {
|
|||||||
emptyList()
|
emptyList()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 先快速显示创建的房间,提升用户体验
|
|
||||||
if (pullRefresh || currentPage == 1) {
|
if (pullRefresh || currentPage == 1) {
|
||||||
rooms = createdRooms
|
rooms = createdRooms
|
||||||
} else {
|
} else {
|
||||||
rooms = rooms + createdRooms
|
rooms = rooms + createdRooms
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理分页(基于创建的房间)
|
|
||||||
val total = createdResponse.body()?.total ?: 0L
|
val total = createdResponse.body()?.total ?: 0L
|
||||||
roomsHasMore = rooms.size < total
|
roomsHasMore = rooms.size < total
|
||||||
if (roomsHasMore && !pullRefresh) {
|
if (roomsHasMore && !pullRefresh) {
|
||||||
roomsCurrentPage++
|
roomsCurrentPage++
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. 后台异步获取该用户加入的房间(仅在非私有房间时获取,且只在第一页时获取以提升性能)
|
|
||||||
if (filterType != 2 && currentPage == 1) {
|
|
||||||
launch {
|
|
||||||
try {
|
|
||||||
// 获取公开房间,但限制数量以减少数据量
|
|
||||||
val joinedResponse = apiClient.getRooms(
|
|
||||||
page = 1,
|
|
||||||
pageSize = roomsPageSize,
|
|
||||||
roomType = if (filterType == 1) "public" else null,
|
|
||||||
includeUsers = true // 需要成员信息来判断
|
|
||||||
)
|
|
||||||
|
|
||||||
if (joinedResponse.isSuccessful) {
|
|
||||||
val joinedRooms = joinedResponse.body()?.list?.mapNotNull { room ->
|
|
||||||
try {
|
|
||||||
val entity = room.toRoomtEntity()
|
|
||||||
// 检查房间的创建者是否是该用户
|
|
||||||
val isCreatedByUser = entity.creator.profile.chatAIId == ownerSessionId
|
|
||||||
// 检查房间的成员是否包含该用户
|
|
||||||
val isMember = entity.users.any { it.profile.chatAIId == ownerSessionId }
|
|
||||||
|
|
||||||
// 如果用户是成员但不是创建者,则认为是加入的房间
|
|
||||||
if (isMember && !isCreatedByUser) {
|
|
||||||
entity
|
|
||||||
} else {
|
|
||||||
null
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
|
||||||
Log.e("MyProfileViewModel", "处理房间失败: ${e.message}")
|
|
||||||
null
|
|
||||||
}
|
|
||||||
} ?: emptyList()
|
|
||||||
|
|
||||||
// 合并并去重(基于房间ID),然后更新列表
|
|
||||||
val allRooms = (rooms + joinedRooms).distinctBy { it.id }
|
|
||||||
rooms = allRooms
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
|
||||||
Log.e("MyProfileViewModel", "获取加入的房间失败: ${e.message}")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// 查看自己的房间:显示创建或加入的房间
|
// 查看自己的房间:显示创建或加入的房间
|
||||||
val response = apiClient.getRooms(
|
val response = apiClient.getRooms(
|
||||||
page = currentPage,
|
page = currentPage,
|
||||||
pageSize = roomsPageSize,
|
pageSize = roomsPageSize,
|
||||||
roomType = roomType,
|
roomType = effectiveRoomType,
|
||||||
showCreated = true,
|
showCreated = true,
|
||||||
showJoined = if (filterType == 2) null else true // 私有房间不显示加入的
|
showJoined = if (filterType == 2) null else true // 私有房间不显示加入的
|
||||||
)
|
)
|
||||||
@@ -458,8 +414,9 @@ object MyProfileViewModel : ViewModel() {
|
|||||||
* @param ownerSessionId 创建者用户ID(ChatAIID),用于过滤特定创建者的房间
|
* @param ownerSessionId 创建者用户ID(ChatAIID),用于过滤特定创建者的房间
|
||||||
*/
|
*/
|
||||||
fun loadMoreRooms(filterType: Int = 0, ownerSessionId: String? = null) {
|
fun loadMoreRooms(filterType: Int = 0, ownerSessionId: String? = null) {
|
||||||
|
val normalizedOwnerId = normalizeOwnerSessionId(ownerSessionId)
|
||||||
if (roomsLoading || !roomsHasMore) return
|
if (roomsLoading || !roomsHasMore) return
|
||||||
loadRooms(filterType = filterType, pullRefresh = false, ownerSessionId = ownerSessionId)
|
loadRooms(filterType = filterType, pullRefresh = false, ownerSessionId = normalizedOwnerId)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -471,6 +428,12 @@ object MyProfileViewModel : ViewModel() {
|
|||||||
rooms = emptyList()
|
rooms = emptyList()
|
||||||
roomsCurrentPage = 1
|
roomsCurrentPage = 1
|
||||||
roomsHasMore = true
|
roomsHasMore = true
|
||||||
loadRooms(filterType = filterType, pullRefresh = true, ownerSessionId = ownerSessionId)
|
val normalizedOwnerId = normalizeOwnerSessionId(ownerSessionId)
|
||||||
|
loadRooms(filterType = filterType, pullRefresh = true, ownerSessionId = normalizedOwnerId)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun normalizeOwnerSessionId(ownerSessionId: String?): String? {
|
||||||
|
val trimmed = ownerSessionId?.trim()
|
||||||
|
return if (trimmed.isNullOrEmpty()) null else trimmed
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -168,6 +168,14 @@ fun ProfileV3(
|
|||||||
initialFirstVisibleItemScrollOffset = model.profileGridFirstVisibleItemOffset
|
initialFirstVisibleItemScrollOffset = model.profileGridFirstVisibleItemOffset
|
||||||
)
|
)
|
||||||
val scrollState = rememberScrollState(model.profileScrollOffset)
|
val scrollState = rememberScrollState(model.profileScrollOffset)
|
||||||
|
val externalOwnerSessionId = remember(isSelf, profile?.chatAIId, profile?.trtcUserId) {
|
||||||
|
if (isSelf) {
|
||||||
|
null
|
||||||
|
} else {
|
||||||
|
profile?.chatAIId?.takeIf { it.isNotBlank() }
|
||||||
|
?: profile?.trtcUserId?.takeIf { it.isNotBlank() }
|
||||||
|
}
|
||||||
|
}
|
||||||
val nestedScrollConnection = remember(scrollState, pagerState, gridState, listState, groupChatListState, isAiAccount) {
|
val nestedScrollConnection = remember(scrollState, pagerState, gridState, listState, groupChatListState, isAiAccount) {
|
||||||
object : NestedScrollConnection {
|
object : NestedScrollConnection {
|
||||||
override fun onPreScroll(available: Offset, source: NestedScrollSource): Offset {
|
override fun onPreScroll(available: Offset, source: NestedScrollSource): Offset {
|
||||||
@@ -537,24 +545,24 @@ fun ProfileV3(
|
|||||||
showSegments = isSelf // 只有查看自己的主页时才显示分段控制器
|
showSegments = isSelf // 只有查看自己的主页时才显示分段控制器
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
// 查看其他用户的主页时,传递该用户的chatAIId以显示其创建的群聊;查看自己的主页时传递null
|
// 查看其他用户的主页时,传递该用户的会话ID以显示其创建的群聊;查看自己的主页时传递null
|
||||||
GroupChatPlaceholder(
|
GroupChatPlaceholder(
|
||||||
modifier = Modifier.fillMaxSize(),
|
modifier = Modifier.fillMaxSize(),
|
||||||
listState = groupChatListState,
|
listState = groupChatListState,
|
||||||
nestedScrollConnection = nestedScrollConnection,
|
nestedScrollConnection = nestedScrollConnection,
|
||||||
ownerSessionId = if (!isSelf) profile?.chatAIId else null,
|
ownerSessionId = externalOwnerSessionId,
|
||||||
showSegments = isSelf // 只有查看自己的主页时才显示分段控制器
|
showSegments = isSelf // 只有查看自己的主页时才显示分段控制器
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
2 -> {
|
2 -> {
|
||||||
if (!isAiAccount) {
|
if (!isAiAccount) {
|
||||||
// 查看其他用户的主页时,传递该用户的chatAIId以显示其创建的群聊;查看自己的主页时传递null
|
// 查看其他用户的主页时,传递该用户的会话ID以显示其创建的群聊;查看自己的主页时传递null
|
||||||
GroupChatPlaceholder(
|
GroupChatPlaceholder(
|
||||||
modifier = Modifier.fillMaxSize(),
|
modifier = Modifier.fillMaxSize(),
|
||||||
listState = groupChatListState,
|
listState = groupChatListState,
|
||||||
nestedScrollConnection = nestedScrollConnection,
|
nestedScrollConnection = nestedScrollConnection,
|
||||||
ownerSessionId = if (!isSelf) profile?.chatAIId else null,
|
ownerSessionId = externalOwnerSessionId,
|
||||||
showSegments = isSelf // 只有查看自己的主页时才显示分段控制器
|
showSegments = isSelf // 只有查看自己的主页时才显示分段控制器
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,21 +81,27 @@ fun GroupChatEmptyContent(
|
|||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
val navController = LocalNavController.current
|
val navController = LocalNavController.current
|
||||||
val viewModel = MyProfileViewModel
|
val viewModel = MyProfileViewModel
|
||||||
|
val normalizedOwnerSessionId = ownerSessionId?.takeIf { it.isNotBlank() }
|
||||||
|
val canLoadRooms = showSegments || normalizedOwnerSessionId != null
|
||||||
val networkAvailable = isNetworkAvailable(context)
|
val networkAvailable = isNetworkAvailable(context)
|
||||||
|
|
||||||
// 如果查看其他用户的房间,固定使用全部类型(filterType = 0)
|
// 如果查看其他用户的房间,固定使用全部类型(filterType = 0)
|
||||||
val filterType = if (showSegments) selectedSegment else 0
|
val filterType = if (showSegments) selectedSegment else 0
|
||||||
|
|
||||||
val state = rememberPullRefreshState(
|
val state = rememberPullRefreshState(
|
||||||
refreshing = viewModel.roomsRefreshing,
|
refreshing = if (canLoadRooms) viewModel.roomsRefreshing else false,
|
||||||
onRefresh = {
|
onRefresh = {
|
||||||
viewModel.refreshRooms(filterType = filterType, ownerSessionId = ownerSessionId)
|
if (canLoadRooms) {
|
||||||
|
viewModel.refreshRooms(filterType = filterType, ownerSessionId = normalizedOwnerSessionId)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
// 当分段或用户ID改变时,重新加载数据
|
// 当分段或用户ID改变时,重新加载数据
|
||||||
LaunchedEffect(selectedSegment, ownerSessionId, showSegments) {
|
LaunchedEffect(selectedSegment, normalizedOwnerSessionId, showSegments) {
|
||||||
viewModel.refreshRooms(filterType = filterType, ownerSessionId = ownerSessionId)
|
if (canLoadRooms) {
|
||||||
|
viewModel.refreshRooms(filterType = filterType, ownerSessionId = normalizedOwnerSessionId)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val nestedScrollModifier = if (nestedScrollConnection != null) {
|
val nestedScrollModifier = if (nestedScrollConnection != null) {
|
||||||
@@ -130,7 +136,14 @@ fun GroupChatEmptyContent(
|
|||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
.pullRefresh(state)
|
.pullRefresh(state)
|
||||||
) {
|
) {
|
||||||
if (viewModel.rooms.isEmpty() && !viewModel.roomsLoading) {
|
if (!canLoadRooms) {
|
||||||
|
Box(
|
||||||
|
modifier = Modifier.fillMaxSize(),
|
||||||
|
contentAlignment = Alignment.Center
|
||||||
|
) {
|
||||||
|
CircularProgressIndicator()
|
||||||
|
}
|
||||||
|
} else if (viewModel.rooms.isEmpty() && !viewModel.roomsLoading) {
|
||||||
// 空状态内容(居中)
|
// 空状态内容(居中)
|
||||||
Column(
|
Column(
|
||||||
modifier = nestedScrollModifier.fillMaxWidth(),
|
modifier = nestedScrollModifier.fillMaxWidth(),
|
||||||
@@ -208,13 +221,17 @@ fun GroupChatEmptyContent(
|
|||||||
if (viewModel.roomsHasMore && !viewModel.roomsLoading) {
|
if (viewModel.roomsHasMore && !viewModel.roomsLoading) {
|
||||||
item {
|
item {
|
||||||
LaunchedEffect(Unit) {
|
LaunchedEffect(Unit) {
|
||||||
viewModel.loadMoreRooms(filterType = filterType, ownerSessionId = ownerSessionId)
|
viewModel.loadMoreRooms(
|
||||||
|
filterType = filterType,
|
||||||
|
ownerSessionId = normalizedOwnerSessionId
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (canLoadRooms) {
|
||||||
PullRefreshIndicator(
|
PullRefreshIndicator(
|
||||||
refreshing = viewModel.roomsRefreshing,
|
refreshing = viewModel.roomsRefreshing,
|
||||||
state = state,
|
state = state,
|
||||||
@@ -223,6 +240,7 @@ fun GroupChatEmptyContent(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun RoomCard(
|
fun RoomCard(
|
||||||
|
|||||||
@@ -331,8 +331,11 @@
|
|||||||
<string name="error_nickname_too_long">ニックネームの長さは20文字を超えることはできません</string>
|
<string name="error_nickname_too_long">ニックネームの長さは20文字を超えることはできません</string>
|
||||||
<string name="error_bio_too_long">自己紹介の長さは100文字を超えることはできません</string>
|
<string name="error_bio_too_long">自己紹介の長さは100文字を超えることはできません</string>
|
||||||
<string name="error_load_profile_failed">ユーザープロフィールの読み込みに失敗しました。もう一度お試しください</string>
|
<string name="error_load_profile_failed">ユーザープロフィールの読み込みに失敗しました。もう一度お試しください</string>
|
||||||
|
<string name="nickname_placeholder">ニックネームを入力</string>
|
||||||
|
<string name="bio_placeholder">私の世界へようこそ。魔法について何かお見せします</string>
|
||||||
<string name="save">保存</string>
|
<string name="save">保存</string>
|
||||||
<string name="choose_mbti">MBTIを選択</string>
|
<string name="choose_mbti">MBTIを選択</string>
|
||||||
|
<string name="mbti_description">MBTIは心理学理論に基づく人格評価ツールです。人々がエネルギーを獲得する方法(内向-外向)、情報を収集する方法(感覚-直感)、意思決定を行う方法(思考-感情)、生活様式(判断-知覚)の好みを理解することで、人格タイプを16種類に分類します。</string>
|
||||||
<string name="choose_zodiac">星座を選択</string>
|
<string name="choose_zodiac">星座を選択</string>
|
||||||
<string name="zodiac_aries">牡羊座</string>
|
<string name="zodiac_aries">牡羊座</string>
|
||||||
<string name="zodiac_taurus">牡牛座</string>
|
<string name="zodiac_taurus">牡牛座</string>
|
||||||
|
|||||||
@@ -322,8 +322,12 @@
|
|||||||
<string name="error_nickname_too_long">昵称长度不能大于20</string>
|
<string name="error_nickname_too_long">昵称长度不能大于20</string>
|
||||||
<string name="error_bio_too_long">个人简介长度不能大于100</string>
|
<string name="error_bio_too_long">个人简介长度不能大于100</string>
|
||||||
<string name="error_load_profile_failed">加载用户资料失败,请重试</string>
|
<string name="error_load_profile_failed">加载用户资料失败,请重试</string>
|
||||||
|
<string name="network_error_check_network">网络错误,请检查网络</string>
|
||||||
|
<string name="nickname_placeholder">请输入昵称</string>
|
||||||
|
<string name="bio_placeholder">欢迎来到我的世界,我会向你展示一些关于魔法的内容</string>
|
||||||
<string name="save">保存</string>
|
<string name="save">保存</string>
|
||||||
<string name="choose_mbti">选择 MBTI</string>
|
<string name="choose_mbti">选择 MBTI</string>
|
||||||
|
<string name="mbti_description">MBTI是基于心理学理论的人格测评工具。了解人们获取能量方式(内向-外向)、收集信息方式(感觉-直觉)、做决策方式(思维-情感)、生活方式(判断-知觉)的偏好,将人格类型分为16种。</string>
|
||||||
<string name="choose_zodiac">选择星座</string>
|
<string name="choose_zodiac">选择星座</string>
|
||||||
<string name="zodiac_aries">白羊座</string>
|
<string name="zodiac_aries">白羊座</string>
|
||||||
<string name="zodiac_taurus">金牛座</string>
|
<string name="zodiac_taurus">金牛座</string>
|
||||||
|
|||||||
@@ -330,8 +330,12 @@
|
|||||||
<string name="error_nickname_too_long">Nickname length cannot be greater than 20</string>
|
<string name="error_nickname_too_long">Nickname length cannot be greater than 20</string>
|
||||||
<string name="error_bio_too_long">Bio length cannot be greater than 100</string>
|
<string name="error_bio_too_long">Bio length cannot be greater than 100</string>
|
||||||
<string name="error_load_profile_failed">Failed to load user profile, please try again</string>
|
<string name="error_load_profile_failed">Failed to load user profile, please try again</string>
|
||||||
|
<string name="network_error_check_network">Network error, please check your network</string>
|
||||||
|
<string name="nickname_placeholder">Value</string>
|
||||||
|
<string name="bio_placeholder">Welcome to my fantiac word i will show you something about magic</string>
|
||||||
<string name="save">Save</string>
|
<string name="save">Save</string>
|
||||||
<string name="choose_mbti">Choose MBTI</string>
|
<string name="choose_mbti">Choose MBTI</string>
|
||||||
|
<string name="mbti_description">MBTI is a personality assessment tool based on psychological theory. By understanding people\'s preferences in how they acquire energy (introversion-extraversion), collect information (sensing-intuition), make decisions (thinking-feeling), and live their lives (judging-perceiving), personality types are divided into 16 kinds.</string>
|
||||||
<string name="choose_zodiac">Choose Zodiac</string>
|
<string name="choose_zodiac">Choose Zodiac</string>
|
||||||
<string name="zodiac_aries">Aries</string>
|
<string name="zodiac_aries">Aries</string>
|
||||||
<string name="zodiac_taurus">Taurus</string>
|
<string name="zodiac_taurus">Taurus</string>
|
||||||
|
|||||||
Reference in New Issue
Block a user