调整界面以及修复多个bug

-调整mbti类型界面
-修复断网时,用户资料编辑保存出现闪退
-修复暂停短视频后进入后台并返回,视频会继续播放,暂停图标不会消失
-修复输入框为空时显示为英文,且个人简介布局靠上
-修复其他用户/智能体个人主页群聊列表显示我加入的群聊
-修复系统切换暗黑模式,应用会刷新,但模式不变
This commit is contained in:
2025-11-26 18:44:07 +08:00
parent 3d64cc5929
commit 05615ce5dc
12 changed files with 199 additions and 113 deletions

View File

@@ -54,7 +54,7 @@
android:theme="@style/Theme.App.Starting"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustResize"
android:configChanges="fontScale|orientation|screenSize|keyboardHidden">
android:configChanges="fontScale|orientation|screenSize|keyboardHidden|uiMode">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />

View File

@@ -73,6 +73,10 @@ class MainActivity : ComponentActivity() {
val config = Configuration(newConfig)
config.fontScale = 1.0f
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)
if (AppState.darkMode) {
window.decorView.setBackgroundColor(android.graphics.Color.BLACK)
}
updateWindowBackground(AppState.darkMode)
enableEdgeToEdge()
scope.launch {
@@ -269,8 +271,22 @@ class MainActivity : ComponentActivity() {
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> {
error("NavController not provided")
}

View File

@@ -545,7 +545,13 @@ class AccountServiceImpl : AccountService {
val bannerField: MultipartBody.Part? = banner?.let {
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) {

View File

@@ -2,6 +2,7 @@ package com.aiosman.ravenow
import android.content.Context
import android.content.SharedPreferences
import android.content.res.Configuration
import com.google.android.gms.auth.api.signin.GoogleSignInOptions
/**
@@ -24,11 +25,16 @@ object AppStore {
.requestEmail()
.build()
googleSignInOptions = gso
// apply dark mode
if (sharedPreferences.getBoolean("darkMode", false)) {
AppState.darkMode = true
AppState.appTheme = DarkThemeColors()
// apply dark mode - 如果用户未手动设置,优先跟随系统
val hasUserPreference = sharedPreferences.contains("darkMode")
val resolvedDarkMode = if (hasUserPreference) {
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
val savedBgUrl = sharedPreferences.getString("chatBackgroundUrl", null)

View File

@@ -20,9 +20,8 @@ import androidx.compose.foundation.layout.offset
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.lazy.grid.itemsIndexed
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.ModalBottomSheet
@@ -219,44 +218,78 @@ fun MbtiSelectBottomSheet(
val nestedScrollConnection = remember {
object : NestedScrollConnection {
override fun onPreScroll(available: Offset, source: NestedScrollSource): Offset {
// 不消费任何事件,让 LazyVerticalGrid 先处理
// 不消费任何事件,让 LazyColumn 先处理
return Offset.Zero
}
override fun onPostScroll(consumed: Offset, available: Offset, source: NestedScrollSource): Offset {
// 消费 LazyVerticalGrid 处理后的剩余滚动事件,防止传递到 ModalBottomSheet
// 消费 LazyColumn 处理后的剩余滚动事件,防止传递到 ModalBottomSheet
return available
}
override suspend fun onPreFling(available: Velocity): Velocity {
// 不消费惯性滚动,让 LazyVerticalGrid 先处理
// 不消费惯性滚动,让 LazyColumn 先处理
return Velocity.Zero
}
override suspend fun onPostFling(consumed: Velocity, available: Velocity): Velocity {
// 消费 LazyVerticalGrid 处理后的剩余惯性滚动,防止传递到 ModalBottomSheet
// 消费 LazyColumn 处理后的剩余惯性滚动,防止传递到 ModalBottomSheet
return available
}
}
}
// 网格列表 - 2列
LazyVerticalGrid(
columns = GridCells.Fixed(2),
// MBTI解释文字背景色
val descriptionBackgroundColor = if (isDarkMode) {
Color(0xFF2A2A2A) // 比 secondaryBackground (0xFF1C1C1C) 更亮的灰色
} else {
Color(0xFFFAF9FB)
}
// 使用LazyColumn包裹解释文字和MBTI类型网格使它们一起滚动
LazyColumn(
modifier = Modifier
.fillMaxWidth()
.weight(1f)
.nestedScroll(nestedScrollConnection),
contentPadding = PaddingValues(
start = 8.dp,
top = 8.dp,
top = 0.dp,
end = 8.dp,
bottom = 8.dp
),
horizontalArrangement = Arrangement.spacedBy(10.dp),
verticalArrangement = Arrangement.spacedBy(10.dp)
verticalArrangement = Arrangement.spacedBy(16.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(
mbti = mbti,
isSelected = mbti == currentMbti,
@@ -268,6 +301,13 @@ fun MbtiSelectBottomSheet(
)
}
}
// 如果这一行只有1个item添加一个空的Spacer来保持布局
if (rowItems.size == 1) {
Spacer(modifier = Modifier.weight(1f))
}
}
}
}
}
}
}

View File

@@ -396,7 +396,7 @@ fun AccountEditScreen2(onUpdateBanner: ((Uri, File, Context) -> Unit)? = null,)
ProfileInfoCard(
label = stringResource(R.string.nickname),
value = model.name,
placeholder = "Value",
placeholder = stringResource(R.string.nickname_placeholder),
onValueChange = { onNicknameChange(it) },
isMultiline = false
)
@@ -407,7 +407,7 @@ fun AccountEditScreen2(onUpdateBanner: ((Uri, File, Context) -> Unit)? = null,)
ProfileInfoCard(
label = stringResource(R.string.personal_intro),
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) },
isMultiline = true
)
@@ -502,6 +502,7 @@ fun AccountEditScreen2(onUpdateBanner: ((Uri, File, Context) -> Unit)? = null,)
// 验证通过,执行保存
model.viewModelScope.launch {
model.isUpdating = true
try {
model.updateUserProfile(context)
model.viewModelScope.launch(Dispatchers.Main) {
debouncedNavigation {
@@ -509,6 +510,17 @@ fun AccountEditScreen2(onUpdateBanner: ((Uri, File, Context) -> Unit)? = null,)
}
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
@@ -568,13 +580,19 @@ fun ProfileInfoCard(
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 = label,
fontSize = 17.sp,
fontWeight = FontWeight.Normal,
color = appColors.text,
modifier = Modifier.width(100.dp)
color = appColors.text
)
}
Spacer(modifier = Modifier.width(16.dp))

View File

@@ -319,6 +319,7 @@ object MyProfileViewModel : ViewModel() {
return
}
val normalizedOwnerId = normalizeOwnerSessionId(ownerSessionId)
if (roomsLoading && !pullRefresh) return
viewModelScope.launch {
@@ -340,16 +341,16 @@ object MyProfileViewModel : ViewModel() {
2 -> "private"
else -> null
}
val effectiveRoomType = if (normalizedOwnerId != null) "public" else roomType
// 构建API调用参数
if (ownerSessionId != null) {
// 查看其他用户的房间:显示该用户创建和加入的房间
// 1. 先快速获取该用户创建的房间(不需要 includeUsers减少数据量
if (normalizedOwnerId != null) {
// 查看其他用户的房间:显示该用户创建的公开房间
val createdResponse = apiClient.getRooms(
page = currentPage,
pageSize = roomsPageSize,
roomType = roomType,
ownerSessionId = ownerSessionId,
roomType = effectiveRoomType,
ownerSessionId = normalizedOwnerId,
includeUsers = false
)
@@ -359,68 +360,23 @@ object MyProfileViewModel : ViewModel() {
emptyList()
}
// 先快速显示创建的房间,提升用户体验
if (pullRefresh || currentPage == 1) {
rooms = createdRooms
} else {
rooms = rooms + createdRooms
}
// 处理分页(基于创建的房间)
val total = createdResponse.body()?.total ?: 0L
roomsHasMore = rooms.size < total
if (roomsHasMore && !pullRefresh) {
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 {
// 查看自己的房间:显示创建或加入的房间
val response = apiClient.getRooms(
page = currentPage,
pageSize = roomsPageSize,
roomType = roomType,
roomType = effectiveRoomType,
showCreated = true,
showJoined = if (filterType == 2) null else true // 私有房间不显示加入的
)
@@ -458,8 +414,9 @@ object MyProfileViewModel : ViewModel() {
* @param ownerSessionId 创建者用户IDChatAIID用于过滤特定创建者的房间
*/
fun loadMoreRooms(filterType: Int = 0, ownerSessionId: String? = null) {
val normalizedOwnerId = normalizeOwnerSessionId(ownerSessionId)
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()
roomsCurrentPage = 1
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
}
}

View File

@@ -168,6 +168,14 @@ fun ProfileV3(
initialFirstVisibleItemScrollOffset = model.profileGridFirstVisibleItemOffset
)
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) {
object : NestedScrollConnection {
override fun onPreScroll(available: Offset, source: NestedScrollSource): Offset {
@@ -537,24 +545,24 @@ fun ProfileV3(
showSegments = isSelf // 只有查看自己的主页时才显示分段控制器
)
} else {
// 查看其他用户的主页时,传递该用户的chatAIId以显示其创建的群聊查看自己的主页时传递null
// 查看其他用户的主页时,传递该用户的会话ID以显示其创建的群聊查看自己的主页时传递null
GroupChatPlaceholder(
modifier = Modifier.fillMaxSize(),
listState = groupChatListState,
nestedScrollConnection = nestedScrollConnection,
ownerSessionId = if (!isSelf) profile?.chatAIId else null,
ownerSessionId = externalOwnerSessionId,
showSegments = isSelf // 只有查看自己的主页时才显示分段控制器
)
}
}
2 -> {
if (!isAiAccount) {
// 查看其他用户的主页时,传递该用户的chatAIId以显示其创建的群聊查看自己的主页时传递null
// 查看其他用户的主页时,传递该用户的会话ID以显示其创建的群聊查看自己的主页时传递null
GroupChatPlaceholder(
modifier = Modifier.fillMaxSize(),
listState = groupChatListState,
nestedScrollConnection = nestedScrollConnection,
ownerSessionId = if (!isSelf) profile?.chatAIId else null,
ownerSessionId = externalOwnerSessionId,
showSegments = isSelf // 只有查看自己的主页时才显示分段控制器
)
}

View File

@@ -81,21 +81,27 @@ fun GroupChatEmptyContent(
val context = LocalContext.current
val navController = LocalNavController.current
val viewModel = MyProfileViewModel
val normalizedOwnerSessionId = ownerSessionId?.takeIf { it.isNotBlank() }
val canLoadRooms = showSegments || normalizedOwnerSessionId != null
val networkAvailable = isNetworkAvailable(context)
// 如果查看其他用户的房间固定使用全部类型filterType = 0
val filterType = if (showSegments) selectedSegment else 0
val state = rememberPullRefreshState(
refreshing = viewModel.roomsRefreshing,
refreshing = if (canLoadRooms) viewModel.roomsRefreshing else false,
onRefresh = {
viewModel.refreshRooms(filterType = filterType, ownerSessionId = ownerSessionId)
if (canLoadRooms) {
viewModel.refreshRooms(filterType = filterType, ownerSessionId = normalizedOwnerSessionId)
}
}
)
// 当分段或用户ID改变时重新加载数据
LaunchedEffect(selectedSegment, ownerSessionId, showSegments) {
viewModel.refreshRooms(filterType = filterType, ownerSessionId = ownerSessionId)
LaunchedEffect(selectedSegment, normalizedOwnerSessionId, showSegments) {
if (canLoadRooms) {
viewModel.refreshRooms(filterType = filterType, ownerSessionId = normalizedOwnerSessionId)
}
}
val nestedScrollModifier = if (nestedScrollConnection != null) {
@@ -130,7 +136,14 @@ fun GroupChatEmptyContent(
.fillMaxSize()
.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(
modifier = nestedScrollModifier.fillMaxWidth(),
@@ -208,13 +221,17 @@ fun GroupChatEmptyContent(
if (viewModel.roomsHasMore && !viewModel.roomsLoading) {
item {
LaunchedEffect(Unit) {
viewModel.loadMoreRooms(filterType = filterType, ownerSessionId = ownerSessionId)
viewModel.loadMoreRooms(
filterType = filterType,
ownerSessionId = normalizedOwnerSessionId
)
}
}
}
}
}
if (canLoadRooms) {
PullRefreshIndicator(
refreshing = viewModel.roomsRefreshing,
state = state,
@@ -222,6 +239,7 @@ fun GroupChatEmptyContent(
)
}
}
}
}
@Composable

View File

@@ -331,8 +331,11 @@
<string name="error_nickname_too_long">ニックネームの長さは20文字を超えることはできません</string>
<string name="error_bio_too_long">自己紹介の長さは100文字を超えることはできません</string>
<string name="error_load_profile_failed">ユーザープロフィールの読み込みに失敗しました。もう一度お試しください</string>
<string name="nickname_placeholder">ニックネームを入力</string>
<string name="bio_placeholder">私の世界へようこそ。魔法について何かお見せします</string>
<string name="save">保存</string>
<string name="choose_mbti">MBTIを選択</string>
<string name="mbti_description">MBTIは心理学理論に基づく人格評価ツールです。人々がエネルギーを獲得する方法内向-外向)、情報を収集する方法(感覚-直感)、意思決定を行う方法(思考-感情)、生活様式(判断-知覚の好みを理解することで、人格タイプを16種類に分類します。</string>
<string name="choose_zodiac">星座を選択</string>
<string name="zodiac_aries">牡羊座</string>
<string name="zodiac_taurus">牡牛座</string>

View File

@@ -322,8 +322,12 @@
<string name="error_nickname_too_long">昵称长度不能大于20</string>
<string name="error_bio_too_long">个人简介长度不能大于100</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="choose_mbti">选择 MBTI</string>
<string name="mbti_description">MBTI是基于心理学理论的人格测评工具。了解人们获取能量方式(内向-外向)、收集信息方式(感觉-直觉)、做决策方式(思维-情感)、生活方式(判断-知觉)的偏好,将人格类型分为16种。</string>
<string name="choose_zodiac">选择星座</string>
<string name="zodiac_aries">白羊座</string>
<string name="zodiac_taurus">金牛座</string>

View File

@@ -330,8 +330,12 @@
<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_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="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="zodiac_aries">Aries</string>
<string name="zodiac_taurus">Taurus</string>