Compare commits
3 Commits
revert-48-
...
zhong
| Author | SHA1 | Date | |
|---|---|---|---|
| 85141fde1b | |||
| 234c07142c | |||
| 89227edccf |
@@ -81,7 +81,9 @@ data class CreateGroupChatRequestBody(
|
||||
|
||||
data class JoinGroupChatRequestBody(
|
||||
@SerializedName("trtcId")
|
||||
val trtcId: String,
|
||||
val trtcId: String? = null,
|
||||
@SerializedName("roomId")
|
||||
val roomId: Int? = null,
|
||||
)
|
||||
|
||||
data class LoginUserRequestBody(
|
||||
@@ -271,6 +273,132 @@ data class RemoveAccountRequestBody(
|
||||
val password: String,
|
||||
)
|
||||
|
||||
// API 错误响应(用于加入房间等接口的错误处理)
|
||||
data class ApiErrorResponse(
|
||||
@SerializedName("err")
|
||||
val error: String,
|
||||
@SerializedName("success")
|
||||
val success: Boolean
|
||||
)
|
||||
|
||||
// 群聊中的用户信息
|
||||
data class GroupChatUser(
|
||||
@SerializedName("ID")
|
||||
val id: Int,
|
||||
@SerializedName("CreatedAt")
|
||||
val createdAt: String,
|
||||
@SerializedName("UpdatedAt")
|
||||
val updatedAt: String,
|
||||
@SerializedName("DeletedAt")
|
||||
val deletedAt: String?,
|
||||
@SerializedName("userSessionId")
|
||||
val userSessionId: String,
|
||||
@SerializedName("sessions")
|
||||
val sessions: Any?, // 根据实际需要可以定义具体类型
|
||||
@SerializedName("prompts")
|
||||
val prompts: Any?, // 根据实际需要可以定义具体类型
|
||||
@SerializedName("isAgent")
|
||||
val isAgent: Boolean
|
||||
)
|
||||
|
||||
// 智能体角色信息
|
||||
data class GroupChatPrompt(
|
||||
@SerializedName("ID")
|
||||
val id: Int,
|
||||
@SerializedName("CreatedAt")
|
||||
val createdAt: String,
|
||||
@SerializedName("UpdatedAt")
|
||||
val updatedAt: String,
|
||||
@SerializedName("DeletedAt")
|
||||
val deletedAt: String?,
|
||||
@SerializedName("Title")
|
||||
val title: String,
|
||||
@SerializedName("Desc")
|
||||
val desc: String,
|
||||
@SerializedName("Value")
|
||||
val value: String,
|
||||
@SerializedName("Enable")
|
||||
val enable: Boolean,
|
||||
@SerializedName("UserSessions")
|
||||
val userSessions: Any?, // 根据实际需要可以定义具体类型
|
||||
@SerializedName("Avatar")
|
||||
val avatar: String,
|
||||
@SerializedName("AuthorId")
|
||||
val authorId: Int?,
|
||||
@SerializedName("Author")
|
||||
val author: Any?, // 根据实际需要可以定义具体类型
|
||||
@SerializedName("TokenCount")
|
||||
val tokenCount: Int,
|
||||
@SerializedName("OpenId")
|
||||
val openId: String,
|
||||
@SerializedName("Public")
|
||||
val public: Boolean,
|
||||
@SerializedName("BreakMode")
|
||||
val breakMode: Boolean,
|
||||
@SerializedName("DocNamespace")
|
||||
val docNamespace: String,
|
||||
@SerializedName("UseRag")
|
||||
val useRag: Boolean,
|
||||
@SerializedName("RagThreshold")
|
||||
val ragThreshold: Double,
|
||||
@SerializedName("WorkflowId")
|
||||
val workflowId: Int?,
|
||||
@SerializedName("Workflow")
|
||||
val workflow: Any?, // 根据实际需要可以定义具体类型
|
||||
@SerializedName("WorkflowInputs")
|
||||
val workflowInputs: Any?, // 根据实际需要可以定义具体类型
|
||||
@SerializedName("Source")
|
||||
val source: String,
|
||||
@SerializedName("categories")
|
||||
val categories: Any? // 根据实际需要可以定义具体类型
|
||||
)
|
||||
|
||||
// 群聊详细信息响应
|
||||
data class GroupChatResponse(
|
||||
@SerializedName("ID")
|
||||
val id: Int,
|
||||
@SerializedName("CreatedAt")
|
||||
val createdAt: String,
|
||||
@SerializedName("UpdatedAt")
|
||||
val updatedAt: String,
|
||||
@SerializedName("DeletedAt")
|
||||
val deletedAt: String?,
|
||||
@SerializedName("name")
|
||||
val name: String,
|
||||
@SerializedName("description")
|
||||
val description: String,
|
||||
@SerializedName("creatorId")
|
||||
val creatorId: Int,
|
||||
@SerializedName("creator")
|
||||
val creator: Any?, // 根据实际需要可以定义具体类型
|
||||
@SerializedName("trtcRoomId")
|
||||
val trtcRoomId: String,
|
||||
@SerializedName("trtcType")
|
||||
val trtcType: String,
|
||||
@SerializedName("cover")
|
||||
val cover: String,
|
||||
@SerializedName("avatar")
|
||||
val avatar: String,
|
||||
@SerializedName("recommendBanner")
|
||||
val recommendBanner: String,
|
||||
@SerializedName("isRecommended")
|
||||
val isRecommended: Boolean,
|
||||
@SerializedName("allowInHot")
|
||||
val allowInHot: Boolean,
|
||||
@SerializedName("users")
|
||||
val users: List<GroupChatUser>,
|
||||
@SerializedName("prompts")
|
||||
val prompts: List<GroupChatPrompt>,
|
||||
@SerializedName("source")
|
||||
val source: String
|
||||
)
|
||||
class CategoryTemplateTranslation(
|
||||
@SerializedName("name")
|
||||
val name: String,
|
||||
@SerializedName("description")
|
||||
val description: String,
|
||||
)
|
||||
|
||||
data class CategoryTemplate(
|
||||
@SerializedName("id")
|
||||
val id: Int,
|
||||
@@ -295,19 +423,19 @@ data class CategoryTemplate(
|
||||
@SerializedName("createdAt")
|
||||
val createdAt: String,
|
||||
@SerializedName("updatedAt")
|
||||
val updatedAt: String
|
||||
)
|
||||
|
||||
data class CategoryListResponse(
|
||||
@SerializedName("page")
|
||||
val page: Int,
|
||||
@SerializedName("pageSize")
|
||||
val pageSize: Int,
|
||||
@SerializedName("total")
|
||||
val total: Int,
|
||||
@SerializedName("list")
|
||||
val list: List<CategoryTemplate>
|
||||
)
|
||||
val updatedAt: String,
|
||||
@SerializedName("translations")
|
||||
val translations: Map<String, CategoryTemplateTranslation>?
|
||||
) {
|
||||
/**
|
||||
* 获取本地化名称,优先使用当前语言的翻译,如果没有则使用默认名称
|
||||
*/
|
||||
fun getLocalizedName(): String {
|
||||
// 这里可以根据需要添加国际化逻辑
|
||||
// 目前直接返回默认名称
|
||||
return name
|
||||
}
|
||||
}
|
||||
|
||||
interface RaveNowAPI {
|
||||
@GET("membership/config")
|
||||
@@ -588,9 +716,26 @@ interface RaveNowAPI {
|
||||
suspend fun getAgent(
|
||||
@Query("page") page: Int = 1,
|
||||
@Query("pageSize") pageSize: Int = 20,
|
||||
@Query("withWorkflow") withWorkflow: Int = 1,
|
||||
@Query("order") order: String? = null,
|
||||
@Query("orderKey") orderKey: String? = null,
|
||||
@Query("createdAt") createdAt: String? = null,
|
||||
@Query("updatedAt") updatedAt: String? = null,
|
||||
@Query("createdStart") createdStart: String? = null,
|
||||
@Query("createdEnd") createdEnd: String? = null,
|
||||
@Query("updatedStart") updatedStart: String? = null,
|
||||
@Query("updatedEnd") updatedEnd: String? = null,
|
||||
@Query("title") title: String? = null,
|
||||
@Query("authorId") authorId: Int? = null,
|
||||
@Query("authorOpenId") authorOpenId: String? = null,
|
||||
@Query("showPrivate") showPrivate: String? = null,
|
||||
@Query("explore") explore: String? = null,
|
||||
@Query("desc") desc: String? = null,
|
||||
@Query("withWorkflow") withWorkflow: String? = null,
|
||||
@Query("hasAvatar") hasAvatar: String? = null,
|
||||
@Query("random") random: String? = null,
|
||||
@Query("categoryName") categoryName: String? = null,
|
||||
@Query("categoryIds") categoryIds: List<Int>? = null,
|
||||
@Query("uncategorized") uncategorized: String? = null,
|
||||
): Response<DataContainer<ListContainer<Agent>>>
|
||||
|
||||
@GET("outside/my/prompts")
|
||||
@@ -619,7 +764,10 @@ interface RaveNowAPI {
|
||||
suspend fun agentMoment(@Body body: AgentMomentRequestBody): Response<DataContainer<String>>
|
||||
|
||||
@GET("outside/rooms/open")
|
||||
suspend fun createGroupChatAi(@Query("trtcGroupId") trtcGroupId: String): Response<DataContainer<Unit>>
|
||||
suspend fun createGroupChatAi(
|
||||
@Query("trtcGroupId") trtcGroupId: String? = null,
|
||||
@Query("roomId") roomId: Int? = null
|
||||
): Response<DataContainer<GroupChatResponse>>
|
||||
|
||||
@POST("outside/rooms/create-single-chat")
|
||||
suspend fun createSingleChat(@Body body: SingleChatRequestBody): Response<DataContainer<Unit>>
|
||||
@@ -634,6 +782,7 @@ interface RaveNowAPI {
|
||||
suspend fun getRooms(@Query("page") page: Int = 1,
|
||||
@Query("pageSize") pageSize: Int = 20,
|
||||
@Query("isRecommended") isRecommended: Int = 1,
|
||||
@Query("random") random: Int? = null,
|
||||
): Response<ListContainer<Room>>
|
||||
|
||||
@GET("outside/rooms/detail")
|
||||
@@ -655,7 +804,7 @@ interface RaveNowAPI {
|
||||
@Query("withParent") withParent: Boolean? = null,
|
||||
@Query("withCount") withCount: Boolean? = null,
|
||||
@Query("hideEmpty") hideEmpty: Boolean? = null
|
||||
): Response<DataContainer<CategoryListResponse>>
|
||||
): Response<ListContainer<CategoryTemplate>>
|
||||
|
||||
@GET("outside/categories/tree")
|
||||
suspend fun getCategoryTree(
|
||||
@@ -668,14 +817,6 @@ interface RaveNowAPI {
|
||||
@Path("id") id: Int
|
||||
): Response<DataContainer<CategoryTemplate>>
|
||||
|
||||
@GET("outside/prompts")
|
||||
suspend fun getPromptsByCategory(
|
||||
@Query("categoryIds") categoryIds: List<Int>? = null,
|
||||
@Query("categoryName") categoryName: String? = null,
|
||||
@Query("uncategorized") uncategorized: String? = null,
|
||||
@Query("page") page: Int? = null,
|
||||
@Query("pageSize") pageSize: Int? = null
|
||||
): Response<ListContainer<Agent>>
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ 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.fillMaxHeight
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
@@ -28,19 +29,15 @@ import androidx.compose.foundation.pager.rememberPagerState
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.Icon
|
||||
import androidx.compose.material.Text
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.material3.TopAppBarDefaults
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.DisposableEffect
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.derivedStateOf
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.runtime.snapshotFlow
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
@@ -52,6 +49,10 @@ 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.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.window.Dialog
|
||||
import androidx.compose.ui.window.DialogProperties
|
||||
import androidx.compose.material.CircularProgressIndicator
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import androidx.navigation.NavHostController
|
||||
import com.aiosman.ravenow.AppStore
|
||||
@@ -78,9 +79,7 @@ import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.LazyListState
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||
import androidx.compose.foundation.lazy.grid.GridCells
|
||||
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
|
||||
import androidx.compose.foundation.lazy.grid.items as gridItems
|
||||
import androidx.compose.ui.zIndex
|
||||
|
||||
// 检测是否接近列表底部的扩展函数
|
||||
fun LazyListState.isScrolledToEnd(buffer: Int = 3): Boolean {
|
||||
@@ -91,7 +90,7 @@ fun LazyListState.isScrolledToEnd(buffer: Int = 3): Boolean {
|
||||
return lastVisibleItemIndex >= (totalItemsCount - buffer)
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalFoundationApi::class, ExperimentalMaterial3Api::class)
|
||||
@OptIn(ExperimentalFoundationApi::class)
|
||||
@Composable
|
||||
fun Agent() {
|
||||
val AppColors = LocalAppTheme.current
|
||||
@@ -111,6 +110,19 @@ fun Agent() {
|
||||
viewModel.ensureDataLoaded()
|
||||
}
|
||||
|
||||
// 列表滚动状态(用于吸顶与加载更多)
|
||||
val listState = rememberLazyListState()
|
||||
|
||||
// 监听滚动到底部,加载更多网格数据
|
||||
LaunchedEffect(listState) {
|
||||
snapshotFlow { listState.isScrolledToEnd() }
|
||||
.collect { atEnd ->
|
||||
if (atEnd && !viewModel.isLoading) {
|
||||
viewModel.loadMoreGridAgentData()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 防抖状态
|
||||
var lastClickTime by remember { mutableStateOf(0L) }
|
||||
|
||||
@@ -122,38 +134,35 @@ fun Agent() {
|
||||
}
|
||||
}
|
||||
|
||||
val agentItems = viewModel.agentItems
|
||||
var selectedTabIndex by remember { mutableStateOf(0) }
|
||||
|
||||
// 无限滚动状态
|
||||
val listState = rememberLazyListState()
|
||||
|
||||
// 创建一个可观察的滚动到底部状态
|
||||
val isScrolledToEnd by remember {
|
||||
derivedStateOf {
|
||||
listState.isScrolledToEnd()
|
||||
}
|
||||
}
|
||||
|
||||
// 检测滚动到底部并加载更多数据
|
||||
LaunchedEffect(isScrolledToEnd) {
|
||||
if (isScrolledToEnd && !viewModel.isLoadingMore && agentItems.isNotEmpty() && viewModel.hasMoreData) {
|
||||
viewModel.loadMoreAgents()
|
||||
}
|
||||
}
|
||||
|
||||
Scaffold(
|
||||
topBar = {
|
||||
TopAppBar(
|
||||
title = {
|
||||
androidx.compose.material3.Text(
|
||||
Box(
|
||||
modifier = Modifier.fillMaxSize()
|
||||
) {
|
||||
// 固定顶部搜索条
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.background(AppColors.background)
|
||||
.zIndex(999.0f)
|
||||
.height(44.dp + statusBarPaddingValues.calculateTopPadding())
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.fillMaxHeight().padding(top = 32.dp, start = 16.dp, end = 16.dp),
|
||||
horizontalArrangement = Arrangement.Start,
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Text(
|
||||
text = "Rave AI",
|
||||
fontSize = 20.sp,
|
||||
fontWeight = FontWeight.W900,
|
||||
color = AppColors.text
|
||||
color = AppColors.text,
|
||||
modifier = Modifier
|
||||
.align(Alignment.CenterVertically)
|
||||
)
|
||||
},
|
||||
actions = {
|
||||
|
||||
Spacer(modifier = Modifier.weight(1f))
|
||||
|
||||
Image(
|
||||
painter = painterResource(id = R.drawable.rider_pro_nav_search),
|
||||
contentDescription = "search",
|
||||
@@ -164,28 +173,22 @@ fun Agent() {
|
||||
},
|
||||
colorFilter = ColorFilter.tint(AppColors.text)
|
||||
)
|
||||
},
|
||||
colors = TopAppBarDefaults.topAppBarColors(
|
||||
containerColor = AppColors.background
|
||||
)
|
||||
)
|
||||
},
|
||||
containerColor = AppColors.background,
|
||||
contentWindowInsets = WindowInsets(0, 0, 0, 0)
|
||||
) { paddingValues ->
|
||||
}
|
||||
}
|
||||
|
||||
LazyColumn(
|
||||
state = listState,
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(paddingValues)
|
||||
.padding(
|
||||
top = 44.dp + statusBarPaddingValues.calculateTopPadding() + 15.dp,
|
||||
bottom = navigationBarPaddings,
|
||||
start = 16.dp,
|
||||
end = 16.dp
|
||||
)
|
||||
) {
|
||||
|
||||
// 类别标签页 - 吸顶
|
||||
// 动态标签页
|
||||
stickyHeader(key = "category_tabs") {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
@@ -193,101 +196,33 @@ fun Agent() {
|
||||
.background(AppColors.background)
|
||||
.padding(top = 4.dp, bottom = 8.dp)
|
||||
) {
|
||||
val selectedTabIndex = viewModel.selectedCategoryIndex
|
||||
if (viewModel.categories.isNotEmpty()) {
|
||||
LazyRow(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.wrapContentHeight()
|
||||
.padding(bottom = 8.dp),
|
||||
.padding(bottom = 16.dp),
|
||||
horizontalArrangement = Arrangement.Start,
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
viewModel.categories.forEachIndexed { index, category ->
|
||||
item {
|
||||
CustomTabItem(
|
||||
text = stringResource(R.string.agent_recommend),
|
||||
isSelected = selectedTabIndex == 0,
|
||||
onClick = {
|
||||
selectedTabIndex = 0
|
||||
viewModel.loadAllAgents()
|
||||
}
|
||||
text = category.getLocalizedName(),
|
||||
isSelected = selectedTabIndex == index,
|
||||
onClick = { viewModel.selectCategory(index) }
|
||||
)
|
||||
}
|
||||
|
||||
item {
|
||||
TabSpacer()
|
||||
}
|
||||
|
||||
// 动态添加分类标签
|
||||
viewModel.categories.take(4).forEachIndexed { index, category ->
|
||||
item {
|
||||
CustomTabItem(
|
||||
text = category.name,
|
||||
isSelected = selectedTabIndex == index + 1,
|
||||
onClick = {
|
||||
selectedTabIndex = index + 1
|
||||
viewModel.loadAgentsByCategory(category.id)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
item {
|
||||
TabSpacer()
|
||||
if (index < viewModel.categories.size - 1) {
|
||||
item { TabSpacer() }
|
||||
}
|
||||
}
|
||||
|
||||
item {
|
||||
CustomTabItem(
|
||||
text = "scenes",
|
||||
isSelected = selectedTabIndex == 1,
|
||||
onClick = {
|
||||
selectedTabIndex = 1
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
item {
|
||||
TabSpacer()
|
||||
}
|
||||
|
||||
item {
|
||||
CustomTabItem(
|
||||
text = "voices",
|
||||
isSelected = selectedTabIndex == 6,
|
||||
onClick = {
|
||||
selectedTabIndex = 6
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
item {
|
||||
TabSpacer()
|
||||
}
|
||||
|
||||
item {
|
||||
CustomTabItem(
|
||||
text = "anime",
|
||||
isSelected = selectedTabIndex == 7,
|
||||
onClick = {
|
||||
selectedTabIndex = 7
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
item {
|
||||
TabSpacer()
|
||||
}
|
||||
|
||||
item {
|
||||
CustomTabItem(
|
||||
text = "assist",
|
||||
isSelected = selectedTabIndex == 8,
|
||||
onClick = {
|
||||
selectedTabIndex = 8
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 推荐内容区域
|
||||
item {
|
||||
Column(
|
||||
@@ -295,23 +230,59 @@ fun Agent() {
|
||||
.fillMaxWidth()
|
||||
.padding(vertical = 8.dp)
|
||||
) {
|
||||
when {
|
||||
selectedTabIndex == 0 -> {
|
||||
AgentViewPagerSection(agentItems = viewModel.agentItems.take(15), viewModel)
|
||||
AgentViewPagerSection(agentItems = viewModel.topAgentItems, viewModel)
|
||||
}
|
||||
selectedTabIndex in 1..viewModel.categories.size -> {
|
||||
AgentViewPagerSection(agentItems = viewModel.agentItems.take(15), viewModel)
|
||||
}
|
||||
else -> {
|
||||
val shuffledAgents = viewModel.agentItems.shuffled().take(15)
|
||||
AgentViewPagerSection(agentItems = shuffledAgents, viewModel)
|
||||
|
||||
// 热门聊天室
|
||||
stickyHeader(key = "hot_rooms_header") {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.background(AppColors.background)
|
||||
.padding(top = 8.dp, bottom = 12.dp),
|
||||
horizontalArrangement = Arrangement.Start,
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Image(
|
||||
painter = painterResource(R.mipmap.rider_pro_hot_room),
|
||||
contentDescription = "chat room",
|
||||
modifier = Modifier.size(28.dp)
|
||||
)
|
||||
Spacer(modifier = Modifier.width(4.dp))
|
||||
androidx.compose.material3.Text(
|
||||
text = stringResource(R.string.hot_rooms),
|
||||
fontSize = 16.sp,
|
||||
fontWeight = androidx.compose.ui.text.font.FontWeight.W900,
|
||||
color = AppColors.text
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// 热门聊天室网格
|
||||
items(viewModel.chatRooms.chunked(2)) { rowRooms ->
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(bottom = 12.dp),
|
||||
horizontalArrangement = Arrangement.spacedBy(12.dp)
|
||||
) {
|
||||
rowRooms.forEach { chatRoom ->
|
||||
ChatRoomCard(
|
||||
chatRoom = chatRoom,
|
||||
navController = LocalNavController.current,
|
||||
modifier = Modifier.weight(1f)
|
||||
)
|
||||
}
|
||||
if (rowRooms.size == 1) {
|
||||
Spacer(modifier = Modifier.weight(1f))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
item { Spacer(modifier = Modifier.height(20.dp)) }
|
||||
|
||||
// "发现更多" 标题 - 吸顶
|
||||
// 发现区域
|
||||
stickyHeader(key = "discover_more") {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
@@ -322,9 +293,9 @@ fun Agent() {
|
||||
verticalAlignment = Alignment.Bottom
|
||||
) {
|
||||
Image(
|
||||
painter = painterResource(R.mipmap.rider_pro_agent2),
|
||||
painter = painterResource(R.mipmap.bars_x_buttons_home_n_copy_2),
|
||||
contentDescription = "agent",
|
||||
modifier = Modifier.size(28.dp),
|
||||
modifier = Modifier.size(28.dp)
|
||||
)
|
||||
Spacer(modifier = Modifier.width(4.dp))
|
||||
androidx.compose.material3.Text(
|
||||
@@ -335,38 +306,42 @@ fun Agent() {
|
||||
)
|
||||
}
|
||||
}
|
||||
item { Spacer(modifier = Modifier.height(20.dp)) }
|
||||
|
||||
// Agent网格 - 使用行式布局
|
||||
items(
|
||||
items = agentItems.chunked(2),
|
||||
key = { row -> row.firstOrNull()?.openId ?: "" }
|
||||
) { rowItems ->
|
||||
// Agent 两列网格行
|
||||
items(viewModel.gridAgentItems.chunked(2)) { rowItems ->
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(vertical = 16.dp),
|
||||
.padding(
|
||||
top = 20.dp,
|
||||
bottom = 20.dp
|
||||
),
|
||||
horizontalArrangement = Arrangement.spacedBy(16.dp)
|
||||
) {
|
||||
rowItems.forEach { agentItem ->
|
||||
Box(
|
||||
modifier = Modifier.weight(1f)
|
||||
) {
|
||||
Box(modifier = Modifier.weight(1f)) {
|
||||
AgentCardSquare(
|
||||
agentItem = agentItem,
|
||||
agentItem = rowItems[0],
|
||||
viewModel = viewModel,
|
||||
navController = LocalNavController.current
|
||||
)
|
||||
}
|
||||
if (rowItems.size > 1) {
|
||||
Box(modifier = Modifier.weight(1f)) {
|
||||
AgentCardSquare(
|
||||
agentItem = rowItems[1],
|
||||
viewModel = viewModel,
|
||||
navController = LocalNavController.current
|
||||
)
|
||||
}
|
||||
// 如果这一行只有一个item,添加一个空的占位符
|
||||
if (rowItems.size == 1) {
|
||||
} else {
|
||||
Spacer(modifier = Modifier.weight(1f))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 加载更多指示器
|
||||
if (viewModel.isLoadingMore) {
|
||||
if (viewModel.isLoading) {
|
||||
item {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
@@ -381,7 +356,7 @@ fun Agent() {
|
||||
)
|
||||
Spacer(modifier = Modifier.width(12.dp))
|
||||
androidx.compose.material3.Text(
|
||||
text = "加载中...",
|
||||
text = stringResource(R.string.agent_chat_loading),
|
||||
color = AppColors.secondaryText,
|
||||
fontSize = 14.sp
|
||||
)
|
||||
@@ -391,11 +366,67 @@ fun Agent() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun AgentGridLayout(
|
||||
agentItems: List<AgentItem>,
|
||||
viewModel: AgentViewModel,
|
||||
navController: NavHostController
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
) {
|
||||
// 将agentItems按两列分组
|
||||
agentItems.chunked(2).forEachIndexed { rowIndex, rowItems ->
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(
|
||||
top = if (rowIndex == 0) 30.dp else 20.dp, // 第一行添加更多顶部间距
|
||||
bottom = 20.dp
|
||||
),
|
||||
horizontalArrangement = Arrangement.spacedBy(16.dp)
|
||||
) {
|
||||
// 第一列
|
||||
Box(
|
||||
modifier = Modifier.weight(1f)
|
||||
) {
|
||||
AgentCardSquare(
|
||||
agentItem = rowItems[0],
|
||||
viewModel = viewModel,
|
||||
navController = navController
|
||||
)
|
||||
}
|
||||
|
||||
// 第二列(如果存在)
|
||||
if (rowItems.size > 1) {
|
||||
Box(
|
||||
modifier = Modifier.weight(1f)
|
||||
) {
|
||||
AgentCardSquare(
|
||||
agentItem = rowItems[1],
|
||||
viewModel = viewModel,
|
||||
navController = navController
|
||||
)
|
||||
}
|
||||
} else {
|
||||
// 如果只有一列,添加空白占位
|
||||
Spacer(modifier = Modifier.weight(1f))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("SuspiciousIndentation")
|
||||
@Composable
|
||||
fun AgentCardSquare(agentItem: AgentItem, viewModel: AgentViewModel, navController: NavHostController) {
|
||||
fun AgentCardSquare(
|
||||
agentItem: AgentItem,
|
||||
viewModel: AgentViewModel,
|
||||
navController: NavHostController
|
||||
) {
|
||||
val AppColors = LocalAppTheme.current
|
||||
val cardHeight = 200.dp
|
||||
val cardHeight = 180.dp
|
||||
val avatarSize = cardHeight / 3 // 头像大小为方块高度的三分之一
|
||||
|
||||
// 防抖状态
|
||||
@@ -404,9 +435,8 @@ fun AgentCardSquare(agentItem: AgentItem, viewModel: AgentViewModel, navControll
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(top = avatarSize / 2)
|
||||
.height(cardHeight)
|
||||
.background(AppColors.nonActive, RoundedCornerShape(12.dp)) // 修改背景颜色
|
||||
.background(AppColors.secondaryBackground, RoundedCornerShape(12.dp))
|
||||
.clickable {
|
||||
if (DebounceUtils.simpleDebounceClick(lastClickTime, 500L) {
|
||||
viewModel.goToProfile(agentItem.openId, navController)
|
||||
@@ -416,12 +446,11 @@ fun AgentCardSquare(agentItem: AgentItem, viewModel: AgentViewModel, navControll
|
||||
},
|
||||
contentAlignment = Alignment.TopCenter
|
||||
) {
|
||||
// 头像,位于方块上方居中,部分悬于方块外部
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.offset(y = -avatarSize / 2)
|
||||
.offset(y = 4.dp)
|
||||
.size(avatarSize)
|
||||
.background(Color.White, RoundedCornerShape(avatarSize / 2))
|
||||
.background(AppColors.background, RoundedCornerShape(avatarSize / 2))
|
||||
.clip(RoundedCornerShape(avatarSize / 2)),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
@@ -429,9 +458,7 @@ fun AgentCardSquare(agentItem: AgentItem, viewModel: AgentViewModel, navControll
|
||||
painter = painterResource(R.mipmap.group_copy),
|
||||
contentDescription = "默认头像",
|
||||
modifier = Modifier.size(avatarSize),
|
||||
contentScale = androidx.compose.ui.layout.ContentScale.Crop
|
||||
)
|
||||
|
||||
if (agentItem.avatar.isNotEmpty()) {
|
||||
CustomAsyncImage(
|
||||
imageUrl = agentItem.avatar,
|
||||
@@ -448,7 +475,7 @@ fun AgentCardSquare(agentItem: AgentItem, viewModel: AgentViewModel, navControll
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(top = avatarSize / 2 + 8.dp, start = 8.dp, end = 8.dp, bottom = 8.dp),
|
||||
.padding(top = 4.dp + avatarSize + 8.dp, start = 8.dp, end = 8.dp, bottom = 48.dp), // 为底部聊天按钮留出空间
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
androidx.compose.material3.Text(
|
||||
@@ -462,30 +489,31 @@ fun AgentCardSquare(agentItem: AgentItem, viewModel: AgentViewModel, navControll
|
||||
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.height(85.dp)
|
||||
.fillMaxWidth()
|
||||
) {
|
||||
androidx.compose.material3.Text(
|
||||
text = agentItem.desc,
|
||||
fontSize = 12.sp,
|
||||
color = AppColors.secondaryText,
|
||||
maxLines = 5,
|
||||
maxLines = 2,
|
||||
overflow = androidx.compose.ui.text.style.TextOverflow.Ellipsis,
|
||||
modifier = Modifier.weight(1f, fill = false)
|
||||
)
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
|
||||
// 聊天按钮,位于底部居中
|
||||
// 聊天按钮,固定在底部居中,距离底部有一定边距
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.align(Alignment.BottomCenter)
|
||||
.padding(bottom = 12.dp) // 距离底部的边距
|
||||
.width(60.dp)
|
||||
.height(32.dp)
|
||||
.background(
|
||||
color = Color(0X147c7480),
|
||||
shape = RoundedCornerShape(8.dp)
|
||||
color = AppColors.text,
|
||||
shape = RoundedCornerShape(
|
||||
topStart = 10.dp,
|
||||
topEnd = 10.dp,
|
||||
bottomStart = 0.dp,
|
||||
bottomEnd = 10.dp
|
||||
)
|
||||
)
|
||||
.clickable {
|
||||
if (DebounceUtils.simpleDebounceClick(lastClickTime, 500L) {
|
||||
@@ -507,14 +535,14 @@ fun AgentCardSquare(agentItem: AgentItem, viewModel: AgentViewModel, navControll
|
||||
) {
|
||||
androidx.compose.material3.Text(
|
||||
text = stringResource(R.string.chat),
|
||||
fontSize = 12.sp,
|
||||
color = AppColors.text,
|
||||
fontSize = 15.sp,
|
||||
color = AppColors.background,
|
||||
fontWeight = androidx.compose.ui.text.font.FontWeight.W500
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalFoundationApi::class)
|
||||
@Composable
|
||||
fun AgentViewPagerSection(agentItems: List<AgentItem>, viewModel: AgentViewModel) {
|
||||
@@ -531,7 +559,7 @@ fun AgentViewPagerSection(agentItems: List<AgentItem>,viewModel: AgentViewModel)
|
||||
// Agent内容
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.height(310.dp)
|
||||
.height(300.dp)
|
||||
) {
|
||||
HorizontalPager(
|
||||
state = pagerState,
|
||||
@@ -553,7 +581,7 @@ fun AgentViewPagerSection(agentItems: List<AgentItem>,viewModel: AgentViewModel)
|
||||
agentItems = agentItems.drop(page * itemsPerPage).take(itemsPerPage),
|
||||
page = page,
|
||||
modifier = Modifier
|
||||
.height(310.dp)
|
||||
.height(300.dp)
|
||||
.graphicsLayer {
|
||||
scaleX = scale
|
||||
scaleY = scale
|
||||
@@ -590,7 +618,13 @@ fun AgentViewPagerSection(agentItems: List<AgentItem>,viewModel: AgentViewModel)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun AgentPage(viewModel: AgentViewModel,agentItems: List<AgentItem>, page: Int, modifier: Modifier = Modifier,navController: NavHostController) {
|
||||
fun AgentPage(
|
||||
viewModel: AgentViewModel,
|
||||
agentItems: List<AgentItem>,
|
||||
page: Int,
|
||||
modifier: Modifier = Modifier,
|
||||
navController: NavHostController
|
||||
) {
|
||||
Column(
|
||||
modifier = modifier
|
||||
.fillMaxSize()
|
||||
@@ -598,7 +632,11 @@ fun AgentPage(viewModel: AgentViewModel,agentItems: List<AgentItem>, page: Int,
|
||||
) {
|
||||
// 显示3个agent
|
||||
agentItems.forEachIndexed { index, agentItem ->
|
||||
AgentCard2(agentItem = agentItem, viewModel = viewModel, navController = LocalNavController.current)
|
||||
AgentCard2(
|
||||
agentItem = agentItem,
|
||||
viewModel = viewModel,
|
||||
navController = LocalNavController.current
|
||||
)
|
||||
if (index < agentItems.size - 1) {
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
}
|
||||
@@ -624,7 +662,7 @@ fun AgentCard2(viewModel: AgentViewModel,agentItem: AgentItem,navController: Nav
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.size(48.dp)
|
||||
.background(Color(0x00F5F5F5), RoundedCornerShape(24.dp))
|
||||
.background(AppColors.secondaryBackground, RoundedCornerShape(24.dp))
|
||||
.clickable {
|
||||
if (DebounceUtils.simpleDebounceClick(lastClickTime, 500L) {
|
||||
viewModel.goToProfile(agentItem.openId, navController)
|
||||
@@ -634,12 +672,6 @@ fun AgentCard2(viewModel: AgentViewModel,agentItem: AgentItem,navController: Nav
|
||||
},
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Image(
|
||||
painter = painterResource(R.mipmap.group_copy),
|
||||
contentDescription = "默认头像",
|
||||
modifier = Modifier.size(48.dp),
|
||||
)
|
||||
|
||||
if (agentItem.avatar.isNotEmpty()) {
|
||||
CustomAsyncImage(
|
||||
imageUrl = agentItem.avatar,
|
||||
@@ -649,6 +681,13 @@ fun AgentCard2(viewModel: AgentViewModel,agentItem: AgentItem,navController: Nav
|
||||
.clip(RoundedCornerShape(24.dp)),
|
||||
contentScale = androidx.compose.ui.layout.ContentScale.Crop
|
||||
)
|
||||
} else {
|
||||
Image(
|
||||
painter = painterResource(R.mipmap.rider_pro_agent),
|
||||
contentDescription = "默认头像",
|
||||
modifier = Modifier.size(24.dp),
|
||||
colorFilter = ColorFilter.tint(AppColors.secondaryText)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -687,7 +726,7 @@ fun AgentCard2(viewModel: AgentViewModel,agentItem: AgentItem,navController: Nav
|
||||
modifier = Modifier
|
||||
.size(width = 60.dp, height = 32.dp)
|
||||
.background(
|
||||
color = Color(0X147c7480),
|
||||
color = AppColors.inputBackground,
|
||||
shape = RoundedCornerShape(8.dp)
|
||||
)
|
||||
.clickable {
|
||||
@@ -717,3 +756,180 @@ fun AgentCard2(viewModel: AgentViewModel,agentItem: AgentItem,navController: Nav
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun ChatRoomsSection(
|
||||
chatRooms: List<ChatRoom>,
|
||||
navController: NavHostController
|
||||
) {
|
||||
val AppColors = LocalAppTheme.current
|
||||
|
||||
Column(
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
) {
|
||||
// 标题
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(bottom = 16.dp),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Image(
|
||||
painter = painterResource(R.mipmap.rider_pro_hot_room),
|
||||
contentDescription = "chat room",
|
||||
modifier = Modifier.size(28.dp)
|
||||
)
|
||||
Spacer(modifier = Modifier.width(4.dp))
|
||||
androidx.compose.material3.Text(
|
||||
text = stringResource(R.string.hot_rooms),
|
||||
fontSize = 16.sp,
|
||||
fontWeight = androidx.compose.ui.text.font.FontWeight.W900,
|
||||
color = AppColors.text
|
||||
)
|
||||
}
|
||||
|
||||
Column(
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
) {
|
||||
chatRooms.chunked(2).forEach { rowRooms ->
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(bottom = 12.dp),
|
||||
horizontalArrangement = Arrangement.spacedBy(12.dp)
|
||||
) {
|
||||
rowRooms.forEach { chatRoom ->
|
||||
ChatRoomCard(
|
||||
chatRoom = chatRoom,
|
||||
navController = navController,
|
||||
modifier = Modifier.weight(1f)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun ChatRoomCard(
|
||||
chatRoom: ChatRoom,
|
||||
navController: NavHostController,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val AppColors = LocalAppTheme.current
|
||||
val cardSize = 160.dp
|
||||
val viewModel: AgentViewModel = viewModel()
|
||||
val context = LocalContext.current
|
||||
|
||||
// 防抖状态
|
||||
var lastClickTime by remember { mutableStateOf(0L) }
|
||||
|
||||
// Loading 对话框
|
||||
if (viewModel.isJoiningRoom) {
|
||||
Dialog(
|
||||
onDismissRequest = { /* 阻止用户关闭对话框 */ },
|
||||
properties = DialogProperties(
|
||||
dismissOnBackPress = false,
|
||||
dismissOnClickOutside = false
|
||||
)
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.size(120.dp)
|
||||
.background(
|
||||
color = AppColors.background,
|
||||
shape = RoundedCornerShape(12.dp)
|
||||
),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Column(
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.Center
|
||||
) {
|
||||
CircularProgressIndicator(
|
||||
modifier = Modifier.size(32.dp),
|
||||
color = AppColors.main
|
||||
)
|
||||
Spacer(modifier = Modifier.height(12.dp))
|
||||
androidx.compose.material3.Text(
|
||||
text = "加入中...",
|
||||
fontSize = 14.sp,
|
||||
color = AppColors.text
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 正方形卡片,文字重叠在底部
|
||||
Box(
|
||||
modifier = modifier
|
||||
.size(cardSize)
|
||||
.background(AppColors.secondaryBackground, RoundedCornerShape(12.dp))
|
||||
.clickable(enabled = !viewModel.isJoiningRoom) {
|
||||
if (!viewModel.isJoiningRoom && DebounceUtils.simpleDebounceClick(lastClickTime, 500L) {
|
||||
// 加入群聊房间
|
||||
viewModel.joinRoom(
|
||||
id = chatRoom.id,
|
||||
name = chatRoom.name,
|
||||
avatar = chatRoom.avatar,
|
||||
context = context,
|
||||
navController = navController,
|
||||
onSuccess = {
|
||||
// 成功加入房间
|
||||
},
|
||||
onError = { errorMsg ->
|
||||
// 处理错误,可以显示Toast或其他提示
|
||||
}
|
||||
)
|
||||
}) {
|
||||
lastClickTime = System.currentTimeMillis()
|
||||
}
|
||||
}
|
||||
) {
|
||||
// 优先显示banner,如果没有banner则显示头像
|
||||
val imageUrl = if (chatRoom.banner.isNotEmpty()) chatRoom.banner else chatRoom.avatar
|
||||
|
||||
if (imageUrl.isNotEmpty()) {
|
||||
CustomAsyncImage(
|
||||
imageUrl = imageUrl,
|
||||
contentDescription = if (chatRoom.banner.isNotEmpty()) "房间banner" else "房间头像",
|
||||
modifier = Modifier
|
||||
.size(cardSize)
|
||||
.clip(RoundedCornerShape(12.dp)),
|
||||
contentScale = androidx.compose.ui.layout.ContentScale.Crop
|
||||
)
|
||||
} else {
|
||||
// 默认房间图标
|
||||
Image(
|
||||
painter = painterResource(R.mipmap.rider_pro_agent),
|
||||
contentDescription = "默认房间图标",
|
||||
modifier = Modifier.size(cardSize * 0.4f),
|
||||
colorFilter = ColorFilter.tint(AppColors.secondaryText)
|
||||
)
|
||||
}
|
||||
|
||||
// 房间名称,重叠在底部
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.align(Alignment.BottomCenter)
|
||||
.fillMaxWidth()
|
||||
.background(
|
||||
color = Color.Black.copy(alpha = 0.6f),
|
||||
shape = RoundedCornerShape(bottomStart = 12.dp, bottomEnd = 12.dp)
|
||||
)
|
||||
.padding(horizontal = 8.dp, vertical = 6.dp)
|
||||
) {
|
||||
androidx.compose.material3.Text(
|
||||
text = chatRoom.name,
|
||||
fontSize = 12.sp,
|
||||
color = Color.White,
|
||||
maxLines = 1,
|
||||
overflow = androidx.compose.ui.text.style.TextOverflow.Ellipsis,
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
textAlign = androidx.compose.ui.text.style.TextAlign.Center
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,185 +1,351 @@
|
||||
package com.aiosman.ravenow.ui.index.tabs.ai
|
||||
|
||||
import android.util.Log
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import androidx.navigation.NavHostController
|
||||
import com.aiosman.ravenow.data.Agent
|
||||
import com.aiosman.ravenow.data.ListContainer
|
||||
import com.aiosman.ravenow.AppState
|
||||
import com.aiosman.ravenow.AppStore
|
||||
import com.aiosman.ravenow.ConstVars
|
||||
import com.aiosman.ravenow.data.Room
|
||||
import com.aiosman.ravenow.data.api.ApiClient
|
||||
import com.aiosman.ravenow.data.api.CategoryTemplate
|
||||
import com.aiosman.ravenow.data.api.CreateGroupChatRequestBody
|
||||
import com.aiosman.ravenow.data.api.RaveNowAPI
|
||||
import com.aiosman.ravenow.data.api.SingleChatRequestBody
|
||||
import com.aiosman.ravenow.data.api.JoinGroupChatRequestBody
|
||||
import com.aiosman.ravenow.ui.index.tabs.ai.tabs.mine.MineAgentViewModel.createGroup2ChatAi
|
||||
import com.aiosman.ravenow.ui.NavigationRoute
|
||||
import com.aiosman.ravenow.ui.index.tabs.message.MessageListViewModel.userService
|
||||
import com.aiosman.ravenow.ui.index.tabs.message.tab.GroupChatListViewModel.createGroupChat
|
||||
import com.aiosman.ravenow.ui.index.tabs.moment.tabs.expolre.AgentItem
|
||||
import com.aiosman.ravenow.ui.navigateToGroupChat
|
||||
import com.aiosman.ravenow.data.api.ApiErrorResponse
|
||||
import com.google.gson.Gson
|
||||
import android.content.Context
|
||||
import android.widget.Toast
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
data class ChatRoom(
|
||||
val id: Int,
|
||||
val name: String,
|
||||
val avatar: String = "",
|
||||
val banner: String = "",
|
||||
val memberCount: Int = 0
|
||||
)
|
||||
|
||||
object AgentViewModel : ViewModel() {
|
||||
|
||||
private val apiClient: RaveNowAPI = ApiClient.api
|
||||
|
||||
var agentItems by mutableStateOf<List<AgentItem>>(emptyList())
|
||||
// 顶部Agent列表数据(用于ViewPager)
|
||||
var topAgentItems by mutableStateOf<List<AgentItem>>(emptyList())
|
||||
private set
|
||||
|
||||
var categories by mutableStateOf<List<CategoryItem>>(emptyList())
|
||||
// 底部网格布局Agent数据
|
||||
var gridAgentItems by mutableStateOf<List<AgentItem>>(emptyList())
|
||||
private set
|
||||
|
||||
var chatRooms by mutableStateOf<List<ChatRoom>>(emptyList())
|
||||
private set
|
||||
|
||||
var rooms by mutableStateOf<List<Room>>(emptyList())
|
||||
private set
|
||||
|
||||
var categories by mutableStateOf<List<CategoryTemplate>>(emptyList())
|
||||
private set
|
||||
|
||||
var selectedCategoryIndex by mutableStateOf(0)
|
||||
private set
|
||||
|
||||
var errorMessage by mutableStateOf<String?>(null)
|
||||
private set
|
||||
|
||||
|
||||
var isRefreshing by mutableStateOf(false)
|
||||
private set
|
||||
|
||||
var isLoading by mutableStateOf(false)
|
||||
private set
|
||||
|
||||
// 分页相关状态
|
||||
var isLoadingMore by mutableStateOf(false)
|
||||
var isJoiningRoom by mutableStateOf(false)
|
||||
private set
|
||||
|
||||
var currentPage by mutableStateOf(1)
|
||||
private set
|
||||
private var topCurrentPage = 1
|
||||
private var topHasMoreData = true
|
||||
|
||||
var hasMoreData by mutableStateOf(true)
|
||||
private set
|
||||
|
||||
private val pageSize = 20
|
||||
private var currentCategoryId: Int? = null
|
||||
private var gridCurrentPage = 1
|
||||
private var gridHasMoreData = true
|
||||
|
||||
init {
|
||||
loadAgentData()
|
||||
loadTopAgentData()
|
||||
loadGridAgentData()
|
||||
loadChatRooms()
|
||||
loadCategories()
|
||||
}
|
||||
|
||||
private fun loadAgentData(categoryId: Int? = null, page: Int = 1, isLoadMore: Boolean = false) {
|
||||
/**
|
||||
* 加载顶部Agent列表数据(用于ViewPager)
|
||||
*/
|
||||
private fun loadTopAgentData(categoryIndex: Int = 0) {
|
||||
viewModelScope.launch {
|
||||
if (isLoadMore) {
|
||||
isLoadingMore = true
|
||||
} else {
|
||||
isLoading = true
|
||||
// 重置分页状态
|
||||
currentPage = 1
|
||||
hasMoreData = true
|
||||
currentCategoryId = categoryId
|
||||
}
|
||||
|
||||
errorMessage = null
|
||||
topCurrentPage = 1
|
||||
topHasMoreData = true
|
||||
try {
|
||||
val response = if (categoryId != null) {
|
||||
// 根据分类ID获取智能体
|
||||
val selectedCategory =
|
||||
if (categoryIndex < categories.size) categories[categoryIndex] else null
|
||||
|
||||
val response = if (categoryIndex == 0 || selectedCategory == null) {
|
||||
// 推荐分类或无效分类,加载所有 Agent
|
||||
apiClient.getAgent(
|
||||
page = page,
|
||||
pageSize = pageSize,
|
||||
withWorkflow = 1,
|
||||
categoryIds = listOf(categoryId)
|
||||
page = topCurrentPage,
|
||||
pageSize = 15,
|
||||
withWorkflow = "1",
|
||||
random = "1"
|
||||
)
|
||||
} else {
|
||||
// 获取所有智能体
|
||||
apiClient.getAgent(page = page, pageSize = pageSize, withWorkflow = 1)
|
||||
// 特定分类,使用 categoryName 参数
|
||||
apiClient.getAgent(
|
||||
page = topCurrentPage,
|
||||
pageSize = 15,
|
||||
withWorkflow = "1",
|
||||
categoryName = selectedCategory.name,
|
||||
random = "1"
|
||||
)
|
||||
}
|
||||
|
||||
if (response.isSuccessful) {
|
||||
val responseData = response.body()?.data
|
||||
val agents = responseData?.list ?: emptyList<Agent>()
|
||||
val newAgentItems = agents.map { agent ->
|
||||
val agents = response.body()?.data?.list ?: emptyList()
|
||||
topAgentItems = agents.map { agent ->
|
||||
AgentItem.fromAgent(agent)
|
||||
}
|
||||
|
||||
if (isLoadMore) {
|
||||
// 加载更多:追加到现有列表
|
||||
agentItems = agentItems + newAgentItems
|
||||
currentPage = page
|
||||
topHasMoreData = agents.size >= 15
|
||||
} else {
|
||||
// 首次加载或刷新:替换整个列表
|
||||
agentItems = newAgentItems
|
||||
currentPage = 1
|
||||
}
|
||||
|
||||
// 检查是否还有更多数据
|
||||
hasMoreData = agents.size >= pageSize
|
||||
|
||||
} else {
|
||||
errorMessage = "获取Agent数据失败: ${response.code()}"
|
||||
errorMessage = "获取顶部Agent数据失败: ${response.code()}"
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
errorMessage = "网络请求失败: ${e.message}"
|
||||
} finally {
|
||||
if (isLoadMore) {
|
||||
isLoadingMore = false
|
||||
} else {
|
||||
isLoading = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载底部网格布局Agent数据
|
||||
*/
|
||||
private fun loadGridAgentData(categoryIndex: Int = 0) {
|
||||
viewModelScope.launch {
|
||||
isLoading = true
|
||||
errorMessage = null
|
||||
gridCurrentPage = 1
|
||||
gridHasMoreData = true
|
||||
try {
|
||||
val selectedCategory =
|
||||
if (categoryIndex < categories.size) categories[categoryIndex] else null
|
||||
|
||||
val response = if (categoryIndex == 0 || selectedCategory == null) {
|
||||
// 推荐分类或无效分类,加载所有 Agent
|
||||
apiClient.getAgent(
|
||||
page = gridCurrentPage,
|
||||
pageSize = 20,
|
||||
withWorkflow = "1",
|
||||
random = "true"
|
||||
)
|
||||
} else {
|
||||
// 特定分类,使用 categoryName 参数
|
||||
apiClient.getAgent(
|
||||
page = gridCurrentPage,
|
||||
pageSize = 20,
|
||||
withWorkflow = "1",
|
||||
categoryName = selectedCategory.name,
|
||||
random = "true"
|
||||
)
|
||||
}
|
||||
|
||||
if (response.isSuccessful) {
|
||||
val agents = response.body()?.data?.list ?: emptyList()
|
||||
gridAgentItems = agents.map { agent ->
|
||||
AgentItem.fromAgent(agent)
|
||||
}
|
||||
gridHasMoreData = agents.size >= 20
|
||||
} else {
|
||||
errorMessage = "获取网格Agent数据失败: ${response.code()}"
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
errorMessage = "网络请求失败: ${e.message}"
|
||||
} finally {
|
||||
isLoading = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun loadChatRooms() {
|
||||
viewModelScope.launch {
|
||||
try {
|
||||
val response = apiClient.getRooms(
|
||||
page = 1,
|
||||
pageSize = 21,
|
||||
isRecommended = 1,
|
||||
random = 1
|
||||
) // 请求21个,确保是3的倍数
|
||||
if (response.isSuccessful) {
|
||||
val allRooms = response.body()?.list ?: emptyList()
|
||||
// 确保房间数量是3的倍数,如果不足则截取,如果超出则取前几个
|
||||
val targetCount = (allRooms.size / 3) * 3 // 向下取整到最近的3的倍数
|
||||
rooms = allRooms.take(targetCount)
|
||||
|
||||
// 转换为ChatRoom格式用于兼容现有UI
|
||||
chatRooms = rooms.map { room ->
|
||||
ChatRoom(
|
||||
id = room.id,
|
||||
name = room.name,
|
||||
avatar = room.avatar,
|
||||
banner = ConstVars.BASE_SERVER + "/api/v1/outside/" + room.recommendBanner + "?token=${AppStore.token}",
|
||||
memberCount = room.userCount
|
||||
)
|
||||
}
|
||||
} else {
|
||||
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
// 如果网络请求失败,使用默认数据
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun loadCategories() {
|
||||
viewModelScope.launch {
|
||||
try {
|
||||
val response = apiClient.getCategories(
|
||||
pageSize = 20,
|
||||
withChildren = false,
|
||||
withParent = false,
|
||||
withCount = true,
|
||||
hideEmpty = true
|
||||
val categoriesResponse = apiClient.getCategories(
|
||||
page = 1,
|
||||
pageSize = 100,
|
||||
)
|
||||
println("分类数据请求完成,响应成功: ${response.isSuccessful}")
|
||||
if (response.isSuccessful) {
|
||||
val categoryList = response.body()?.data?.list ?: emptyList()
|
||||
println("获取到 ${categoryList.size} 个分类")
|
||||
categories = categoryList.map { category ->
|
||||
CategoryItem.fromCategoryTemplate(category)
|
||||
if (categoriesResponse.isSuccessful && categoriesResponse.body() != null) {
|
||||
// 添加一个默认的"推荐"分类在第一位
|
||||
val recommendCategory = createRecommendCategory()
|
||||
val categoriesList = categoriesResponse.body()?.list ?: emptyList()
|
||||
categories = listOf(recommendCategory) + categoriesList
|
||||
|
||||
// 分类加载完成后,重新加载当前选中分类的 Agent 数据
|
||||
if (topAgentItems.isEmpty()) {
|
||||
loadTopAgentData(selectedCategoryIndex)
|
||||
}
|
||||
if (gridAgentItems.isEmpty()) {
|
||||
loadGridAgentData(selectedCategoryIndex)
|
||||
}
|
||||
println("成功处理并映射了 ${categories.size} 个分类")
|
||||
} else {
|
||||
errorMessage = "获取分类数据失败: ${response.code()}"
|
||||
println("获取分类数据失败: ${response.code()}")
|
||||
// 如果请求失败,使用默认分类
|
||||
categories = listOf(createRecommendCategory())
|
||||
errorMessage = "获取分类失败: ${categoriesResponse.code()}"
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
errorMessage = "获取分类数据失败: ${e.message}"
|
||||
println("获取分类数据异常: ${e.message}")
|
||||
e.printStackTrace()
|
||||
// 如果网络请求失败,使用默认分类
|
||||
categories = listOf(createRecommendCategory())
|
||||
errorMessage = "网络请求失败: ${e.message}"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun loadAgentsByCategory(categoryId: Int) {
|
||||
loadAgentData(categoryId)
|
||||
}
|
||||
|
||||
fun loadAllAgents() {
|
||||
loadAgentData()
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载更多Agent数据
|
||||
* 创建推荐分类
|
||||
*/
|
||||
fun loadMoreAgents() {
|
||||
// 检查是否正在加载或没有更多数据
|
||||
if (isLoadingMore || !hasMoreData) {
|
||||
return
|
||||
}
|
||||
|
||||
val nextPage = currentPage + 1
|
||||
loadAgentData(
|
||||
categoryId = currentCategoryId,
|
||||
page = nextPage,
|
||||
isLoadMore = true
|
||||
private fun createRecommendCategory(): CategoryTemplate {
|
||||
return CategoryTemplate(
|
||||
id = 0,
|
||||
name = "推荐",
|
||||
description = "推荐内容",
|
||||
avatar = "",
|
||||
parentId = null,
|
||||
parent = null,
|
||||
children = null,
|
||||
sort = 0,
|
||||
isActive = true,
|
||||
promptCount = 0,
|
||||
createdAt = "",
|
||||
updatedAt = "",
|
||||
translations = null
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 加载更多网格Agent数据
|
||||
*/
|
||||
fun loadMoreGridAgentData() {
|
||||
if (!gridHasMoreData || isLoading) return
|
||||
|
||||
viewModelScope.launch {
|
||||
isLoading = true
|
||||
try {
|
||||
val nextPage = gridCurrentPage + 1
|
||||
val selectedCategory =
|
||||
if (selectedCategoryIndex < categories.size) categories[selectedCategoryIndex] else null
|
||||
|
||||
val response = if (selectedCategoryIndex == 0 || selectedCategory == null) {
|
||||
apiClient.getAgent(
|
||||
page = nextPage,
|
||||
pageSize = 20,
|
||||
withWorkflow = "1",
|
||||
random = "true"
|
||||
)
|
||||
} else {
|
||||
apiClient.getAgent(
|
||||
page = nextPage,
|
||||
pageSize = 20,
|
||||
withWorkflow = "1",
|
||||
categoryName = selectedCategory.name,
|
||||
random = "true"
|
||||
)
|
||||
}
|
||||
|
||||
if (response.isSuccessful) {
|
||||
val agents = response.body()?.data?.list ?: emptyList()
|
||||
val newAgentItems = agents.map { agent ->
|
||||
AgentItem.fromAgent(agent)
|
||||
}
|
||||
gridAgentItems = gridAgentItems + newAgentItems
|
||||
gridCurrentPage = nextPage
|
||||
gridHasMoreData = agents.size >= 20
|
||||
} else {
|
||||
errorMessage = "加载更多网格Agent数据失败: ${response.code()}"
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
errorMessage = "网络请求失败: ${e.message}"
|
||||
} finally {
|
||||
isLoading = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 选择分类并加载对应的 Agent 数据
|
||||
*/
|
||||
fun selectCategory(categoryIndex: Int) {
|
||||
if (categoryIndex != selectedCategoryIndex && categoryIndex >= 0 && categoryIndex < categories.size) {
|
||||
selectedCategoryIndex = categoryIndex
|
||||
// 同时加载顶部和网格的数据
|
||||
loadTopAgentData(categoryIndex)
|
||||
loadGridAgentData(categoryIndex)
|
||||
}
|
||||
}
|
||||
|
||||
fun createSingleChat(
|
||||
openId: String,
|
||||
) {
|
||||
viewModelScope.launch {
|
||||
val response = ApiClient.api.createSingleChat(SingleChatRequestBody(agentOpenId = openId))
|
||||
val response =
|
||||
ApiClient.api.createSingleChat(SingleChatRequestBody(agentOpenId = openId))
|
||||
Log.d("debug", response.toString())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun goToChatAi(
|
||||
openId: String,
|
||||
navController: NavHostController
|
||||
@@ -213,15 +379,98 @@ object AgentViewModel: ViewModel() {
|
||||
* 刷新推荐Agent数据
|
||||
*/
|
||||
fun refreshAgentData() {
|
||||
loadAgentData()
|
||||
loadTopAgentData()
|
||||
loadGridAgentData()
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查数据是否为空,如果为空则重新加载
|
||||
*/
|
||||
fun ensureDataLoaded() {
|
||||
if (agentItems.isEmpty() && !isLoading) {
|
||||
loadAgentData()
|
||||
if (topAgentItems.isEmpty() && !isLoading) {
|
||||
loadTopAgentData()
|
||||
}
|
||||
if (gridAgentItems.isEmpty() && !isLoading) {
|
||||
loadGridAgentData()
|
||||
}
|
||||
// 同时确保分类数据已加载
|
||||
if (categories.isEmpty() && !isLoading) {
|
||||
loadCategories()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 加入房间
|
||||
*/
|
||||
fun joinRoom(
|
||||
id: Int,
|
||||
name: String,
|
||||
avatar: String,
|
||||
context: Context,
|
||||
navController: NavHostController,
|
||||
onSuccess: () -> Unit,
|
||||
onError: (String) -> Unit
|
||||
) {
|
||||
// 防止重复点击
|
||||
if (isJoiningRoom) return
|
||||
|
||||
viewModelScope.launch {
|
||||
try {
|
||||
isJoiningRoom = true
|
||||
val response = apiClient.joinRoom(JoinGroupChatRequestBody(roomId = id))
|
||||
if (response.isSuccessful) {
|
||||
// 打开房间
|
||||
val openRoomResponse = apiClient.createGroupChatAi(
|
||||
roomId = id
|
||||
)
|
||||
|
||||
if (openRoomResponse.isSuccessful){
|
||||
val respData = openRoomResponse.body()
|
||||
respData?.let {
|
||||
viewModelScope.launch {
|
||||
try {
|
||||
// 群聊直接使用群ID进行导航
|
||||
navController.navigateToGroupChat(
|
||||
id = respData.data.trtcRoomId,
|
||||
name = name,
|
||||
avatar = avatar
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
onError("加入房间失败")
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
onSuccess()
|
||||
|
||||
} else {
|
||||
// 处理错误响应
|
||||
try {
|
||||
val errorBody = response.errorBody()?.string()
|
||||
if (errorBody != null) {
|
||||
val gson = Gson()
|
||||
val errorResponse = gson.fromJson(errorBody, ApiErrorResponse::class.java)
|
||||
|
||||
// 在主线程显示 Toast
|
||||
Toast.makeText(context, errorResponse.error, Toast.LENGTH_LONG).show()
|
||||
onError(errorResponse.error)
|
||||
} else {
|
||||
Toast.makeText(context, "加入房间失败", Toast.LENGTH_SHORT).show()
|
||||
onError("加入房间失败")
|
||||
}
|
||||
} catch (parseException: Exception) {
|
||||
// 如果解析错误响应失败,显示默认错误信息
|
||||
Toast.makeText(context, "加入房间失败", Toast.LENGTH_SHORT).show()
|
||||
onError("加入房间失败")
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Toast.makeText(context, "网络请求失败:${e.message}", Toast.LENGTH_SHORT).show()
|
||||
onError("网络请求失败:${e.message}")
|
||||
} finally {
|
||||
isJoiningRoom = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -229,33 +478,18 @@ object AgentViewModel: ViewModel() {
|
||||
* 重置ViewModel状态,用于登出或切换账号时清理数据
|
||||
*/
|
||||
fun ResetModel() {
|
||||
agentItems = emptyList()
|
||||
topAgentItems = emptyList()
|
||||
gridAgentItems = emptyList()
|
||||
categories = emptyList()
|
||||
selectedCategoryIndex = 0
|
||||
errorMessage = null
|
||||
isRefreshing = false
|
||||
isLoading = false
|
||||
isLoadingMore = false
|
||||
currentPage = 1
|
||||
hasMoreData = true
|
||||
currentCategoryId = null
|
||||
isJoiningRoom = false
|
||||
topCurrentPage = 1
|
||||
topHasMoreData = true
|
||||
gridCurrentPage = 1
|
||||
gridHasMoreData = true
|
||||
}
|
||||
|
||||
}
|
||||
data class CategoryItem(
|
||||
val id: Int,
|
||||
val name: String,
|
||||
val description: String,
|
||||
val avatar: String,
|
||||
val promptCount: Int?
|
||||
) {
|
||||
companion object {
|
||||
fun fromCategoryTemplate(template: CategoryTemplate): CategoryItem {
|
||||
return CategoryItem(
|
||||
id = template.id,
|
||||
name = template.name,
|
||||
description = template.description,
|
||||
avatar = "${ApiClient.BASE_API_URL}${template.avatar}",
|
||||
promptCount = template.promptCount
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.aiosman.ravenow.ui.index.tabs.message.tab
|
||||
|
||||
import android.content.Context
|
||||
import android.icu.util.Calendar
|
||||
import android.util.Log
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.setValue
|
||||
@@ -167,10 +168,12 @@ object GroupChatListViewModel : ViewModel() {
|
||||
}
|
||||
|
||||
fun createGroupChat(
|
||||
trtcGroupId: String,
|
||||
trtcGroupId: String? = null,
|
||||
roomId: Int? = null
|
||||
) {
|
||||
viewModelScope.launch {
|
||||
val response = ApiClient.api.createGroupChatAi(trtcGroupId = trtcGroupId)
|
||||
val response = ApiClient.api.createGroupChatAi(trtcGroupId = trtcGroupId,roomId = roomId)
|
||||
Log.d("debug",response.toString())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -369,6 +369,7 @@ fun Explore() {
|
||||
trtcId = roomItem.trtcId.toString(),
|
||||
name = roomItem.title,
|
||||
avatar = roomItem.avatar,
|
||||
context = context,
|
||||
navController = navController,
|
||||
onSuccess = {
|
||||
Toast.makeText(context, enterSuccessText, Toast.LENGTH_SHORT).show()
|
||||
@@ -636,6 +637,7 @@ fun Explore() {
|
||||
trtcId = bannerItem.trtcId.toString(),
|
||||
name = bannerItem.title,
|
||||
avatar = bannerItem.avatar,
|
||||
context = context,
|
||||
navController = navController,
|
||||
onSuccess = {
|
||||
Toast.makeText(context, enterSuccessText, Toast.LENGTH_SHORT).show()
|
||||
|
||||
@@ -17,6 +17,10 @@ import com.aiosman.ravenow.ui.index.tabs.message.MessageListViewModel.userServic
|
||||
import com.aiosman.ravenow.ui.index.tabs.message.tab.GroupChatListViewModel
|
||||
import com.aiosman.ravenow.ui.index.tabs.message.tab.GroupChatListViewModel.createGroupChat
|
||||
import com.aiosman.ravenow.ui.navigateToGroupChat
|
||||
import com.aiosman.ravenow.data.api.ApiErrorResponse
|
||||
import com.google.gson.Gson
|
||||
import android.content.Context
|
||||
import android.widget.Toast
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class ExploreViewModel : ViewModel() {
|
||||
@@ -70,7 +74,7 @@ class ExploreViewModel : ViewModel() {
|
||||
isRefreshing = true
|
||||
errorMessage = null
|
||||
try {
|
||||
val response = apiClient.getAgent(page = 1, pageSize = 20, withWorkflow = 1)
|
||||
val response = apiClient.getAgent(page = 1, pageSize = 20, withWorkflow = "1")
|
||||
if (response.isSuccessful) {
|
||||
val agents = response.body()?.data?.list ?: emptyList()
|
||||
agentItems = agents.map { agent ->
|
||||
@@ -114,7 +118,7 @@ class ExploreViewModel : ViewModel() {
|
||||
isLoading = true
|
||||
errorMessage = null
|
||||
try {
|
||||
val response = apiClient.getAgent(page = 1, pageSize = 20, withWorkflow = 1)
|
||||
val response = apiClient.getAgent(page = 1, pageSize = 20, withWorkflow = "1")
|
||||
if (response.isSuccessful) {
|
||||
val agents = response.body()?.data?.list ?: emptyList()
|
||||
agentItems = agents.map { agent ->
|
||||
@@ -130,14 +134,17 @@ class ExploreViewModel : ViewModel() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun createSingleChat(
|
||||
openId: String,
|
||||
) {
|
||||
viewModelScope.launch {
|
||||
val response = ApiClient.api.createSingleChat(SingleChatRequestBody(agentOpenId = openId))
|
||||
val response =
|
||||
ApiClient.api.createSingleChat(SingleChatRequestBody(agentOpenId = openId))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun goToChatAi(
|
||||
openId: String,
|
||||
navController: NavHostController
|
||||
@@ -152,6 +159,7 @@ class ExploreViewModel : ViewModel() {
|
||||
trtcId: String,
|
||||
name: String,
|
||||
avatar: String,
|
||||
context: Context,
|
||||
navController: NavHostController,
|
||||
onSuccess: () -> Unit,
|
||||
onError: (String) -> Unit
|
||||
@@ -164,9 +172,11 @@ class ExploreViewModel : ViewModel() {
|
||||
try {
|
||||
createGroupChat(trtcGroupId = trtcId)
|
||||
// 群聊直接使用群ID进行导航
|
||||
navController.navigateToGroupChat( id = trtcId,
|
||||
navController.navigateToGroupChat(
|
||||
id = trtcId,
|
||||
name = name,
|
||||
avatar = avatar)
|
||||
avatar = avatar
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
onError("加入房间失败")
|
||||
e.printStackTrace()
|
||||
@@ -175,9 +185,28 @@ class ExploreViewModel : ViewModel() {
|
||||
onSuccess()
|
||||
|
||||
} else {
|
||||
// 处理错误响应
|
||||
try {
|
||||
val errorBody = response.errorBody()?.string()
|
||||
if (errorBody != null) {
|
||||
val gson = Gson()
|
||||
val errorResponse = gson.fromJson(errorBody, ApiErrorResponse::class.java)
|
||||
|
||||
// 在主线程显示 Toast
|
||||
Toast.makeText(context, errorResponse.error, Toast.LENGTH_LONG).show()
|
||||
onError(errorResponse.error)
|
||||
} else {
|
||||
Toast.makeText(context, "加入房间失败", Toast.LENGTH_SHORT).show()
|
||||
onError("加入房间失败")
|
||||
}
|
||||
} catch (parseException: Exception) {
|
||||
// 如果解析错误响应失败,显示默认错误信息
|
||||
Toast.makeText(context, "加入房间失败", Toast.LENGTH_SHORT).show()
|
||||
onError("加入房间失败")
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Toast.makeText(context, "网络请求失败:${e.message}", Toast.LENGTH_SHORT).show()
|
||||
onError("网络请求失败:${e.message}")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,6 +157,7 @@
|
||||
<string name="agent_chat_file">[ファイル]</string>
|
||||
<string name="agent_chat_message">[メッセージ]</string>
|
||||
<string name="agent_chat_load_failed">読み込みに失敗しました</string>
|
||||
<string name="agent_chat_loading">読み込み中</string>
|
||||
<string name="agent_chat_load_more_failed">さらに読み込むのに失敗しました</string>
|
||||
<string name="agent_chat_user_info_failed">ユーザー情報の取得に失敗しました: %s</string>
|
||||
<string name="group_chat_empty">グループチャットがありません</string>
|
||||
|
||||
@@ -161,14 +161,15 @@
|
||||
<string name="agent_chat_file">[文件]</string>
|
||||
<string name="agent_chat_message">[消息]</string>
|
||||
<string name="agent_chat_load_failed">加载失败</string>
|
||||
<string name="agent_chat_loading">加载中</string>
|
||||
<string name="agent_chat_load_more_failed">加载更多失败</string>
|
||||
<string name="agent_chat_user_info_failed">获取用户信息失败: %s</string>
|
||||
<string name="group_chat_empty">没有群聊,宇宙好安静</string>
|
||||
<string name="group_chat_empty_title">没有群聊消息的宇宙太安静了</string>
|
||||
<string name="group_chat_empty_subtitle">在首页探索感兴趣的主题房间</string>
|
||||
<string name="group_chat_empty_join">去首页探索感兴趣的高能对话</string>
|
||||
<string name="friend_chat_empty_title">和朋友,还没有对话哦~</string>
|
||||
<string name="friend_chat_empty_subtitle">点击好友头像,即刻发起聊天</string>
|
||||
<string name="friend_chat_empty_title">你和朋友,还没说第一句话呢</string>
|
||||
<string name="friend_chat_empty_subtitle">一段崭新的友谊 等待被唤醒</string>
|
||||
<string name="friend_chat_me_prefix">我: </string>
|
||||
<string name="friend_chat_load_failed">加载失败</string>
|
||||
<string name="create_group_chat">创建群聊</string>
|
||||
|
||||
@@ -147,6 +147,7 @@
|
||||
<string name="chat_friend">Friends</string>
|
||||
<string name="chat_all">All</string>
|
||||
<string name="agent_chat_list_title">Agent Chat</string>
|
||||
<string name="agent_chat_loading">Loading</string>
|
||||
<string name="agent_chat_empty_title">No Agent Chat</string>
|
||||
<string name="agent_chat_empty_subtitle">Start chatting with agents</string>
|
||||
<string name="agent_chat_me_prefix">Me: </string>
|
||||
|
||||
Reference in New Issue
Block a user