Compare commits
3 Commits
feat/pr-20
...
zhong
| Author | SHA1 | Date | |
|---|---|---|---|
| 85141fde1b | |||
| 234c07142c | |||
| 89227edccf |
4
.idea/deploymentTargetSelector.xml
generated
@@ -4,10 +4,10 @@
|
|||||||
<selectionStates>
|
<selectionStates>
|
||||||
<SelectionState runConfigName="app">
|
<SelectionState runConfigName="app">
|
||||||
<option name="selectionMode" value="DROPDOWN" />
|
<option name="selectionMode" value="DROPDOWN" />
|
||||||
<DropdownSelection timestamp="2025-11-05T12:24:27.034893100Z">
|
<DropdownSelection timestamp="2025-09-17T06:25:35.585100400Z">
|
||||||
<Target type="DEFAULT_BOOT">
|
<Target type="DEFAULT_BOOT">
|
||||||
<handle>
|
<handle>
|
||||||
<DeviceId pluginId="PhysicalDevice" identifier="serial=c328a150" />
|
<DeviceId pluginId="Default" identifier="serial=192.168.0.216:5555;connection=698a7727" />
|
||||||
</handle>
|
</handle>
|
||||||
</Target>
|
</Target>
|
||||||
</DropdownSelection>
|
</DropdownSelection>
|
||||||
|
|||||||
32
.idea/gradle.xml
generated
@@ -1,20 +1,20 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="GradleMigrationSettings" migrationVersion="1" />
|
<component name="GradleMigrationSettings" migrationVersion="1" />
|
||||||
<component name="GradleSettings">
|
<component name="GradleSettings">
|
||||||
<option name="linkedExternalProjectsSettings">
|
<option name="linkedExternalProjectsSettings">
|
||||||
<GradleProjectSettings>
|
<GradleProjectSettings>
|
||||||
<option name="testRunner" value="CHOOSE_PER_TEST" />
|
<option name="testRunner" value="CHOOSE_PER_TEST" />
|
||||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||||
<option name="gradleJvm" value="#GRADLE_LOCAL_JAVA_HOME" />
|
<option name="gradleJvm" value="#GRADLE_LOCAL_JAVA_HOME" />
|
||||||
<option name="modules">
|
<option name="modules">
|
||||||
<set>
|
<set>
|
||||||
<option value="$PROJECT_DIR$" />
|
<option value="$PROJECT_DIR$" />
|
||||||
<option value="$PROJECT_DIR$/app" />
|
<option value="$PROJECT_DIR$/app" />
|
||||||
</set>
|
</set>
|
||||||
</option>
|
|
||||||
<option name="resolveExternalAnnotations" value="false" />
|
|
||||||
</GradleProjectSettings>
|
|
||||||
</option>
|
</option>
|
||||||
</component>
|
<option name="resolveExternalAnnotations" value="false" />
|
||||||
|
</GradleProjectSettings>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
</project>
|
</project>
|
||||||
@@ -125,7 +125,7 @@ dependencies {
|
|||||||
// 添加 lifecycle-runtime-ktx 依赖
|
// 添加 lifecycle-runtime-ktx 依赖
|
||||||
implementation(libs.androidx.lifecycle.runtime.ktx.v262)
|
implementation(libs.androidx.lifecycle.runtime.ktx.v262)
|
||||||
implementation (libs.eventbus)
|
implementation (libs.eventbus)
|
||||||
implementation(libs.lottie)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,6 @@
|
|||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:theme="@style/Theme.RaveNow"
|
android:theme="@style/Theme.RaveNow"
|
||||||
android:usesCleartextTraffic="true"
|
android:usesCleartextTraffic="true"
|
||||||
android:networkSecurityConfig="@xml/network_security_config"
|
|
||||||
tools:targetApi="31">
|
tools:targetApi="31">
|
||||||
<meta-data
|
<meta-data
|
||||||
android:name="com.google.android.geo.API_KEY"
|
android:name="com.google.android.geo.API_KEY"
|
||||||
|
|||||||
@@ -46,7 +46,6 @@ object AppState {
|
|||||||
var enableGoogleLogin: Boolean = false
|
var enableGoogleLogin: Boolean = false
|
||||||
var enableChat = false
|
var enableChat = false
|
||||||
var agentCreatedSuccess by mutableStateOf(false)
|
var agentCreatedSuccess by mutableStateOf(false)
|
||||||
var chatBackgroundUrl by mutableStateOf<String?>(null)
|
|
||||||
suspend fun initWithAccount(scope: CoroutineScope, context: Context) {
|
suspend fun initWithAccount(scope: CoroutineScope, context: Context) {
|
||||||
// 如果是游客模式,使用简化的初始化流程
|
// 如果是游客模式,使用简化的初始化流程
|
||||||
if (AppStore.isGuest) {
|
if (AppStore.isGuest) {
|
||||||
|
|||||||
@@ -5,8 +5,7 @@ object ConstVars {
|
|||||||
// Debug: http://192.168.0.201:8088
|
// Debug: http://192.168.0.201:8088
|
||||||
// Release: https://rider-pro.aiosman.com/beta_api
|
// Release: https://rider-pro.aiosman.com/beta_api
|
||||||
val BASE_SERVER = if (BuildConfig.DEBUG) {
|
val BASE_SERVER = if (BuildConfig.DEBUG) {
|
||||||
// "http://47.109.137.67:6363" // Debug环境
|
"http://47.109.137.67:6363" // Debug环境
|
||||||
"https://rider-pro.aiosman.com/beta_api" // Release环境
|
|
||||||
} else {
|
} else {
|
||||||
"https://rider-pro.aiosman.com/beta_api" // Release环境
|
"https://rider-pro.aiosman.com/beta_api" // Release环境
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,16 +2,8 @@ package com.aiosman.ravenow.data
|
|||||||
|
|
||||||
import com.aiosman.ravenow.AppStore
|
import com.aiosman.ravenow.AppStore
|
||||||
import com.aiosman.ravenow.data.api.ApiClient
|
import com.aiosman.ravenow.data.api.ApiClient
|
||||||
import com.aiosman.ravenow.data.api.AgentRule
|
|
||||||
import com.aiosman.ravenow.data.api.AgentRuleListResponse
|
|
||||||
import com.aiosman.ravenow.data.api.AgentRuleQuota
|
|
||||||
import com.aiosman.ravenow.data.api.AgentRuleAgent
|
|
||||||
import com.aiosman.ravenow.data.api.CreateAgentRuleRequestBody
|
|
||||||
import com.aiosman.ravenow.data.api.InsufficientBalanceError
|
|
||||||
import com.aiosman.ravenow.data.api.UpdateAgentRuleRequestBody
|
|
||||||
import com.aiosman.ravenow.entity.AgentEntity
|
import com.aiosman.ravenow.entity.AgentEntity
|
||||||
import com.aiosman.ravenow.entity.ProfileEntity
|
import com.aiosman.ravenow.entity.ProfileEntity
|
||||||
import com.google.gson.Gson
|
|
||||||
import com.google.gson.annotations.SerializedName
|
import com.google.gson.annotations.SerializedName
|
||||||
|
|
||||||
data class Agent(
|
data class Agent(
|
||||||
@@ -91,16 +83,9 @@ data class Profile(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* 智能体服务
|
|
||||||
*/
|
|
||||||
interface AgentService {
|
interface AgentService {
|
||||||
/**
|
/**
|
||||||
* 获取智能体列表
|
* 获取智能体列表
|
||||||
* @param pageNumber 页码
|
|
||||||
* @param pageSize 每页数量,默认 20
|
|
||||||
* @param authorId 作者ID,可选参数,用于筛选特定作者的智能体
|
|
||||||
* @return 智能体列表容器,包含分页信息和智能体列表,失败时返回 null
|
|
||||||
*/
|
*/
|
||||||
suspend fun getAgent(
|
suspend fun getAgent(
|
||||||
pageNumber: Int,
|
pageNumber: Int,
|
||||||
@@ -111,206 +96,3 @@ interface AgentService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ========== Agent 规则 - 领域实体 ==========
|
|
||||||
|
|
||||||
data class AgentRuleAgentInfo(
|
|
||||||
val id: Int,
|
|
||||||
val title: String,
|
|
||||||
val avatar: String,
|
|
||||||
)
|
|
||||||
|
|
||||||
data class AgentRuleEntity(
|
|
||||||
val id: Int,
|
|
||||||
val rule: String,
|
|
||||||
val creator: String,
|
|
||||||
val creatorType: String,
|
|
||||||
val scope: String,
|
|
||||||
val agent: AgentRuleAgentInfo,
|
|
||||||
val createdAt: String,
|
|
||||||
val updatedAt: String,
|
|
||||||
)
|
|
||||||
|
|
||||||
data class AgentRuleListResult(
|
|
||||||
val page: Int,
|
|
||||||
val pageSize: Int,
|
|
||||||
val total: Int,
|
|
||||||
val list: List<AgentRuleEntity>,
|
|
||||||
)
|
|
||||||
|
|
||||||
data class AgentRuleQuotaEntity(
|
|
||||||
val agentId: Int,
|
|
||||||
val agentTitle: String,
|
|
||||||
val baseMaxCount: Int,
|
|
||||||
val purchasedCount: Int,
|
|
||||||
val totalMaxCount: Int,
|
|
||||||
val currentCount: Int,
|
|
||||||
val remainingCount: Int,
|
|
||||||
val usagePercent: Double,
|
|
||||||
)
|
|
||||||
|
|
||||||
// ========== Agent 规则 - Service 接口 ==========
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Agent 规则服务
|
|
||||||
*/
|
|
||||||
interface AgentRuleService {
|
|
||||||
/**
|
|
||||||
* 根据 OpenId 创建 Agent 规则
|
|
||||||
* @param openId Agent 的 OpenId
|
|
||||||
* @param rule 规则内容,不能为空
|
|
||||||
* @throws ServiceException 创建失败时抛出异常(包括余额不足等情况)
|
|
||||||
*/
|
|
||||||
suspend fun createAgentRuleByOpenId(openId: String, rule: String)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 修改 Agent 规则
|
|
||||||
* @param id 规则ID
|
|
||||||
* @param rule 新的规则内容,不能为空
|
|
||||||
* @param openId Agent 的 OpenId,可选参数
|
|
||||||
* @throws ServiceException 修改失败时抛出异常(包括余额不足等情况)
|
|
||||||
*/
|
|
||||||
suspend fun updateAgentRule(id: Int, rule: String, openId: String? = null)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除 Agent 规则
|
|
||||||
* @param id 规则ID
|
|
||||||
* @throws ServiceException 删除失败时抛出异常
|
|
||||||
*/
|
|
||||||
suspend fun deleteAgentRule(id: Int)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询 Agent 规则列表
|
|
||||||
* @param openId Agent 的 OpenId
|
|
||||||
* @param keyword 关键词搜索,可选参数
|
|
||||||
* @param page 页码,默认 1
|
|
||||||
* @param pageSize 每页数量,默认 10
|
|
||||||
* @return 规则列表响应,包含分页信息和规则列表
|
|
||||||
* @throws ServiceException 查询失败时抛出异常
|
|
||||||
*/
|
|
||||||
suspend fun getAgentRuleList(
|
|
||||||
openId: String,
|
|
||||||
keyword: String? = null,
|
|
||||||
page: Int = 1,
|
|
||||||
pageSize: Int = 10
|
|
||||||
): AgentRuleListResult
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询 Agent 规则配额使用情况
|
|
||||||
* @param openId Agent 的 OpenId
|
|
||||||
* @return 规则配额信息,包含基础配额、已购买配额、当前使用量等
|
|
||||||
* @throws ServiceException 查询失败时抛出异常
|
|
||||||
*/
|
|
||||||
suspend fun getAgentRuleQuota(openId: String): AgentRuleQuotaEntity
|
|
||||||
}
|
|
||||||
|
|
||||||
class AgentRuleServiceImpl : AgentRuleService {
|
|
||||||
private val gson = Gson()
|
|
||||||
|
|
||||||
override suspend fun createAgentRuleByOpenId(openId: String, rule: String) {
|
|
||||||
val body = CreateAgentRuleRequestBody(
|
|
||||||
rule = rule,
|
|
||||||
promptId = null,
|
|
||||||
openId = openId
|
|
||||||
)
|
|
||||||
val resp = ApiClient.api.createAgentRule(body)
|
|
||||||
if (!resp.isSuccessful) {
|
|
||||||
val errorText = resp.errorBody()?.string()
|
|
||||||
try {
|
|
||||||
val err = gson.fromJson(errorText, InsufficientBalanceError::class.java)
|
|
||||||
if (err != null && err.code == 35600) {
|
|
||||||
throw ServiceException(err.message)
|
|
||||||
}
|
|
||||||
} catch (_: Exception) {
|
|
||||||
// ignore parse error
|
|
||||||
}
|
|
||||||
throw ServiceException("创建 Agent 规则失败: HTTP ${resp.code()}")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun updateAgentRule(id: Int, rule: String, openId: String?) {
|
|
||||||
val body = UpdateAgentRuleRequestBody(
|
|
||||||
id = id,
|
|
||||||
rule = rule,
|
|
||||||
promptId = null,
|
|
||||||
openId = openId
|
|
||||||
)
|
|
||||||
val resp = ApiClient.api.updateAgentRule(body)
|
|
||||||
if (!resp.isSuccessful) {
|
|
||||||
val errorText = resp.errorBody()?.string()
|
|
||||||
try {
|
|
||||||
val err = gson.fromJson(errorText, InsufficientBalanceError::class.java)
|
|
||||||
if (err != null && err.code == 35600) {
|
|
||||||
throw ServiceException(err.message)
|
|
||||||
}
|
|
||||||
} catch (_: Exception) {
|
|
||||||
// ignore parse error
|
|
||||||
}
|
|
||||||
throw ServiceException("更新 Agent 规则失败: HTTP ${resp.code()}")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun deleteAgentRule(id: Int) {
|
|
||||||
val resp = ApiClient.api.deleteAgentRule(id)
|
|
||||||
if (!resp.isSuccessful) {
|
|
||||||
throw ServiceException("删除 Agent 规则失败: HTTP ${resp.code()}")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun getAgentRuleList(
|
|
||||||
openId: String,
|
|
||||||
keyword: String?,
|
|
||||||
page: Int,
|
|
||||||
pageSize: Int
|
|
||||||
): AgentRuleListResult {
|
|
||||||
val resp = ApiClient.api.getAgentRuleList(
|
|
||||||
promptId = openId,
|
|
||||||
rule = keyword,
|
|
||||||
page = page,
|
|
||||||
pageSize = pageSize
|
|
||||||
)
|
|
||||||
val data = resp.body()?.data ?: throw ServiceException("获取 Agent 规则列表失败")
|
|
||||||
return data.toEntity()
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun getAgentRuleQuota(openId: String): AgentRuleQuotaEntity {
|
|
||||||
val resp = ApiClient.api.getAgentRuleQuota(openId)
|
|
||||||
val data = resp.body()?.data ?: throw ServiceException("获取 Agent 规则配额失败")
|
|
||||||
return data.toEntity()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun AgentRuleListResponse.toEntity(): AgentRuleListResult = AgentRuleListResult(
|
|
||||||
page = page,
|
|
||||||
pageSize = pageSize,
|
|
||||||
total = total,
|
|
||||||
list = list.map { it.toEntity() }
|
|
||||||
)
|
|
||||||
|
|
||||||
private fun AgentRule.toEntity(): AgentRuleEntity = AgentRuleEntity(
|
|
||||||
id = id,
|
|
||||||
rule = rule,
|
|
||||||
creator = creator,
|
|
||||||
creatorType = creatorType,
|
|
||||||
scope = scope,
|
|
||||||
agent = prompt.toEntity(),
|
|
||||||
createdAt = createdAt,
|
|
||||||
updatedAt = updatedAt,
|
|
||||||
)
|
|
||||||
|
|
||||||
private fun AgentRuleAgent.toEntity(): AgentRuleAgentInfo = AgentRuleAgentInfo(
|
|
||||||
id = id,
|
|
||||||
title = title,
|
|
||||||
avatar = avatar,
|
|
||||||
)
|
|
||||||
|
|
||||||
private fun AgentRuleQuota.toEntity(): AgentRuleQuotaEntity = AgentRuleQuotaEntity(
|
|
||||||
agentId = promptId,
|
|
||||||
agentTitle = promptTitle,
|
|
||||||
baseMaxCount = baseMaxCount,
|
|
||||||
purchasedCount = purchasedCount,
|
|
||||||
totalMaxCount = totalMaxCount,
|
|
||||||
currentCount = currentCount,
|
|
||||||
remainingCount = remainingCount,
|
|
||||||
usagePercent = usagePercent,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import com.google.gson.annotations.SerializedName
|
|||||||
data class ListContainer<T>(
|
data class ListContainer<T>(
|
||||||
// 总数
|
// 总数
|
||||||
@SerializedName("total")
|
@SerializedName("total")
|
||||||
val total: Long,
|
val total: Int,
|
||||||
// 当前页
|
// 当前页
|
||||||
@SerializedName("page")
|
@SerializedName("page")
|
||||||
val page: Int,
|
val page: Int,
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import com.aiosman.ravenow.R
|
|||||||
import com.aiosman.ravenow.data.api.ApiClient
|
import com.aiosman.ravenow.data.api.ApiClient
|
||||||
import com.aiosman.ravenow.entity.MomentEntity
|
import com.aiosman.ravenow.entity.MomentEntity
|
||||||
import com.aiosman.ravenow.entity.MomentImageEntity
|
import com.aiosman.ravenow.entity.MomentImageEntity
|
||||||
import com.aiosman.ravenow.entity.MomentVideoEntity
|
|
||||||
import com.google.gson.annotations.SerializedName
|
import com.google.gson.annotations.SerializedName
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
@@ -13,12 +12,8 @@ data class Moment(
|
|||||||
val id: Long,
|
val id: Long,
|
||||||
@SerializedName("textContent")
|
@SerializedName("textContent")
|
||||||
val textContent: String,
|
val textContent: String,
|
||||||
@SerializedName("url")
|
|
||||||
val url: String? = null,
|
|
||||||
@SerializedName("images")
|
@SerializedName("images")
|
||||||
val images: List<Image>? = null,
|
val images: List<Image>,
|
||||||
@SerializedName("videos")
|
|
||||||
val videos: List<Video>? = null,
|
|
||||||
@SerializedName("user")
|
@SerializedName("user")
|
||||||
val user: User,
|
val user: User,
|
||||||
@SerializedName("likeCount")
|
@SerializedName("likeCount")
|
||||||
@@ -29,7 +24,7 @@ data class Moment(
|
|||||||
val favoriteCount: Long,
|
val favoriteCount: Long,
|
||||||
@SerializedName("isFavorite")
|
@SerializedName("isFavorite")
|
||||||
val isFavorite: Boolean,
|
val isFavorite: Boolean,
|
||||||
@SerializedName("isCommented")
|
@SerializedName("shareCount")
|
||||||
val isCommented: Boolean,
|
val isCommented: Boolean,
|
||||||
@SerializedName("commentCount")
|
@SerializedName("commentCount")
|
||||||
val commentCount: Long,
|
val commentCount: Long,
|
||||||
@@ -37,29 +32,6 @@ data class Moment(
|
|||||||
val time: String,
|
val time: String,
|
||||||
@SerializedName("isFollowed")
|
@SerializedName("isFollowed")
|
||||||
val isFollowed: Boolean,
|
val isFollowed: Boolean,
|
||||||
// 新闻相关字段
|
|
||||||
@SerializedName("isNews")
|
|
||||||
val isNews: Boolean = false,
|
|
||||||
@SerializedName("newsTitle")
|
|
||||||
val newsTitle: String? = null,
|
|
||||||
@SerializedName("newsUrl")
|
|
||||||
val newsUrl: String? = null,
|
|
||||||
@SerializedName("newsSource")
|
|
||||||
val newsSource: String? = null,
|
|
||||||
@SerializedName("newsCategory")
|
|
||||||
val newsCategory: String? = null,
|
|
||||||
@SerializedName("newsLanguage")
|
|
||||||
val newsLanguage: String? = null,
|
|
||||||
@SerializedName("newsContent")
|
|
||||||
val newsContent: String? = null,
|
|
||||||
@SerializedName("hasFullText")
|
|
||||||
val hasFullText: Boolean = false,
|
|
||||||
@SerializedName("summary")
|
|
||||||
val summary: String? = null,
|
|
||||||
@SerializedName("publishedAt")
|
|
||||||
val publishedAt: String? = null,
|
|
||||||
@SerializedName("imageCached")
|
|
||||||
val imageCached: Boolean = false
|
|
||||||
) {
|
) {
|
||||||
fun toMomentItem(): MomentEntity {
|
fun toMomentItem(): MomentEntity {
|
||||||
return MomentEntity(
|
return MomentEntity(
|
||||||
@@ -75,7 +47,7 @@ data class Moment(
|
|||||||
commentCount = commentCount.toInt(),
|
commentCount = commentCount.toInt(),
|
||||||
shareCount = 0,
|
shareCount = 0,
|
||||||
favoriteCount = favoriteCount.toInt(),
|
favoriteCount = favoriteCount.toInt(),
|
||||||
images = images?.map {
|
images = images.map {
|
||||||
MomentImageEntity(
|
MomentImageEntity(
|
||||||
url = "${ApiClient.BASE_SERVER}${it.url}",
|
url = "${ApiClient.BASE_SERVER}${it.url}",
|
||||||
thumbnail = "${ApiClient.BASE_SERVER}${it.thumbnail}",
|
thumbnail = "${ApiClient.BASE_SERVER}${it.thumbnail}",
|
||||||
@@ -84,40 +56,10 @@ data class Moment(
|
|||||||
width = it.width,
|
width = it.width,
|
||||||
height = it.height
|
height = it.height
|
||||||
)
|
)
|
||||||
} ?: emptyList(),
|
},
|
||||||
authorId = user.id.toInt(),
|
authorId = user.id.toInt(),
|
||||||
liked = isLiked,
|
liked = isLiked,
|
||||||
isFavorite = isFavorite,
|
isFavorite = isFavorite,
|
||||||
url = url,
|
|
||||||
videos = videos?.map {
|
|
||||||
MomentVideoEntity(
|
|
||||||
id = it.id,
|
|
||||||
url = "${ApiClient.BASE_SERVER}${it.url}",
|
|
||||||
originalUrl = it.originalUrl,
|
|
||||||
directUrl = it.directUrl,
|
|
||||||
thumbnailUrl = it.thumbnailUrl?.let { thumb -> "${ApiClient.BASE_SERVER}$thumb" },
|
|
||||||
thumbnailDirectUrl = it.thumbnailDirectUrl,
|
|
||||||
duration = it.duration,
|
|
||||||
width = it.width,
|
|
||||||
height = it.height,
|
|
||||||
size = it.size,
|
|
||||||
format = it.format,
|
|
||||||
bitrate = it.bitrate,
|
|
||||||
frameRate = it.frameRate
|
|
||||||
)
|
|
||||||
},
|
|
||||||
// 新闻相关字段
|
|
||||||
isNews = isNews,
|
|
||||||
newsTitle = newsTitle ?: "",
|
|
||||||
newsUrl = newsUrl ?: "",
|
|
||||||
newsSource = newsSource ?: "",
|
|
||||||
newsCategory = newsCategory ?: "",
|
|
||||||
newsLanguage = newsLanguage ?: "",
|
|
||||||
newsContent = newsContent ?: "",
|
|
||||||
hasFullText = hasFullText,
|
|
||||||
summary = summary,
|
|
||||||
publishedAt = publishedAt,
|
|
||||||
imageCached = imageCached
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -127,26 +69,8 @@ data class Image(
|
|||||||
val id: Long,
|
val id: Long,
|
||||||
@SerializedName("url")
|
@SerializedName("url")
|
||||||
val url: String,
|
val url: String,
|
||||||
@SerializedName("original_url")
|
|
||||||
val originalUrl: String? = null,
|
|
||||||
@SerializedName("directUrl")
|
|
||||||
val directUrl: String? = null,
|
|
||||||
@SerializedName("thumbnail")
|
@SerializedName("thumbnail")
|
||||||
val thumbnail: String,
|
val thumbnail: String,
|
||||||
@SerializedName("thumbnailDirectUrl")
|
|
||||||
val thumbnailDirectUrl: String? = null,
|
|
||||||
@SerializedName("small")
|
|
||||||
val small: String? = null,
|
|
||||||
@SerializedName("smallDirectUrl")
|
|
||||||
val smallDirectUrl: String? = null,
|
|
||||||
@SerializedName("medium")
|
|
||||||
val medium: String? = null,
|
|
||||||
@SerializedName("mediumDirectUrl")
|
|
||||||
val mediumDirectUrl: String? = null,
|
|
||||||
@SerializedName("large")
|
|
||||||
val large: String? = null,
|
|
||||||
@SerializedName("largeDirectUrl")
|
|
||||||
val largeDirectUrl: String? = null,
|
|
||||||
@SerializedName("blurHash")
|
@SerializedName("blurHash")
|
||||||
val blurHash: String?,
|
val blurHash: String?,
|
||||||
@SerializedName("width")
|
@SerializedName("width")
|
||||||
@@ -155,68 +79,13 @@ data class Image(
|
|||||||
val height: Int?
|
val height: Int?
|
||||||
)
|
)
|
||||||
|
|
||||||
data class Video(
|
|
||||||
@SerializedName("id")
|
|
||||||
val id: Long,
|
|
||||||
@SerializedName("url")
|
|
||||||
val url: String,
|
|
||||||
@SerializedName("original_url")
|
|
||||||
val originalUrl: String? = null,
|
|
||||||
@SerializedName("directUrl")
|
|
||||||
val directUrl: String? = null,
|
|
||||||
@SerializedName("thumbnailUrl")
|
|
||||||
val thumbnailUrl: String? = null,
|
|
||||||
@SerializedName("thumbnailDirectUrl")
|
|
||||||
val thumbnailDirectUrl: String? = null,
|
|
||||||
@SerializedName("duration")
|
|
||||||
val duration: Int? = null,
|
|
||||||
@SerializedName("width")
|
|
||||||
val width: Int? = null,
|
|
||||||
@SerializedName("height")
|
|
||||||
val height: Int? = null,
|
|
||||||
@SerializedName("size")
|
|
||||||
val size: Long? = null,
|
|
||||||
@SerializedName("format")
|
|
||||||
val format: String? = null,
|
|
||||||
@SerializedName("bitrate")
|
|
||||||
val bitrate: Int? = null,
|
|
||||||
@SerializedName("frameRate")
|
|
||||||
val frameRate: String? = null
|
|
||||||
)
|
|
||||||
|
|
||||||
data class User(
|
data class User(
|
||||||
@SerializedName("id")
|
@SerializedName("id")
|
||||||
val id: Long,
|
val id: Long,
|
||||||
@SerializedName("nickName")
|
@SerializedName("nickName")
|
||||||
val nickName: String,
|
val nickName: String,
|
||||||
@SerializedName("avatar")
|
@SerializedName("avatar")
|
||||||
val avatar: String,
|
val avatar: String
|
||||||
@SerializedName("avatarMedium")
|
|
||||||
val avatarMedium: String? = null,
|
|
||||||
@SerializedName("avatarLarge")
|
|
||||||
val avatarLarge: String? = null,
|
|
||||||
@SerializedName("originAvatar")
|
|
||||||
val originAvatar: String? = null,
|
|
||||||
@SerializedName("avatarDirectUrl")
|
|
||||||
val avatarDirectUrl: String? = null,
|
|
||||||
@SerializedName("avatarMediumDirectUrl")
|
|
||||||
val avatarMediumDirectUrl: String? = null,
|
|
||||||
@SerializedName("avatarLargeDirectUrl")
|
|
||||||
val avatarLargeDirectUrl: String? = null,
|
|
||||||
@SerializedName("aiAccount")
|
|
||||||
val aiAccount: Boolean = false,
|
|
||||||
@SerializedName("aiRoleAvatar")
|
|
||||||
val aiRoleAvatar: String? = null,
|
|
||||||
@SerializedName("aiRoleAvatarMedium")
|
|
||||||
val aiRoleAvatarMedium: String? = null,
|
|
||||||
@SerializedName("aiRoleAvatarLarge")
|
|
||||||
val aiRoleAvatarLarge: String? = null,
|
|
||||||
@SerializedName("aiRoleAvatarDirectUrl")
|
|
||||||
val aiRoleAvatarDirectUrl: String? = null,
|
|
||||||
@SerializedName("aiRoleAvatarMediumDirectUrl")
|
|
||||||
val aiRoleAvatarMediumDirectUrl: String? = null,
|
|
||||||
@SerializedName("aiRoleAvatarLargeDirectUrl")
|
|
||||||
val aiRoleAvatarLargeDirectUrl: String? = null
|
|
||||||
)
|
)
|
||||||
|
|
||||||
data class UploadImage(
|
data class UploadImage(
|
||||||
|
|||||||
@@ -1,16 +1,11 @@
|
|||||||
package com.aiosman.ravenow.data
|
package com.aiosman.ravenow.data
|
||||||
|
|
||||||
|
import com.aiosman.ravenow.AppStore
|
||||||
import com.aiosman.ravenow.data.api.ApiClient
|
import com.aiosman.ravenow.data.api.ApiClient
|
||||||
import com.aiosman.ravenow.data.api.CreateRoomRuleRequestBody
|
import com.aiosman.ravenow.entity.AgentEntity
|
||||||
import com.aiosman.ravenow.data.api.UpdateRoomRuleRequestBody
|
|
||||||
import com.aiosman.ravenow.data.api.RoomRuleQuota
|
|
||||||
import com.aiosman.ravenow.data.api.RoomRule
|
|
||||||
import com.aiosman.ravenow.data.api.RoomRuleCreator
|
|
||||||
import com.aiosman.ravenow.entity.CreatorEntity
|
import com.aiosman.ravenow.entity.CreatorEntity
|
||||||
|
import com.aiosman.ravenow.entity.ProfileEntity
|
||||||
import com.aiosman.ravenow.entity.RoomEntity
|
import com.aiosman.ravenow.entity.RoomEntity
|
||||||
import com.aiosman.ravenow.entity.RoomRuleEntity
|
|
||||||
import com.aiosman.ravenow.entity.RoomRuleCreatorEntity
|
|
||||||
import com.aiosman.ravenow.entity.RoomRuleQuotaEntity
|
|
||||||
import com.aiosman.ravenow.entity.UsersEntity
|
import com.aiosman.ravenow.entity.UsersEntity
|
||||||
import com.google.gson.annotations.SerializedName
|
import com.google.gson.annotations.SerializedName
|
||||||
|
|
||||||
@@ -111,190 +106,6 @@ data class Users(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 房间规则相关服务
|
|
||||||
*/
|
|
||||||
interface RoomService {
|
|
||||||
/**
|
|
||||||
* 创建房间规则
|
|
||||||
* @param rule 规则内容,不能为空
|
|
||||||
* @param roomId 房间ID,与 trtcId 二选一
|
|
||||||
* @param trtcId TRTC房间ID,与 roomId 二选一
|
|
||||||
* @throws ServiceException 创建失败时抛出异常
|
|
||||||
*/
|
|
||||||
suspend fun createRoomRule(
|
|
||||||
rule: String,
|
|
||||||
roomId: Int? = null,
|
|
||||||
trtcId: String? = null
|
|
||||||
)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 修改房间规则
|
|
||||||
* @param id 规则ID
|
|
||||||
* @param rule 新的规则内容,不能为空
|
|
||||||
* @throws ServiceException 修改失败时抛出异常
|
|
||||||
*/
|
|
||||||
suspend fun updateRoomRule(
|
|
||||||
id: Int,
|
|
||||||
rule: String
|
|
||||||
)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除房间规则
|
|
||||||
* @param id 规则ID
|
|
||||||
* @throws ServiceException 删除失败时抛出异常
|
|
||||||
*/
|
|
||||||
suspend fun deleteRoomRule(id: Int)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询房间规则列表
|
|
||||||
* @param roomId 房间ID,与 trtcId 二选一
|
|
||||||
* @param trtcId TRTC房间ID,与 roomId 二选一
|
|
||||||
* @param page 页码,默认 1
|
|
||||||
* @param pageSize 每页数量,默认 10
|
|
||||||
* @return 规则列表响应,包含分页信息和规则列表
|
|
||||||
* @throws ServiceException 查询失败时抛出异常
|
|
||||||
*/
|
|
||||||
suspend fun getRoomRuleList(
|
|
||||||
roomId: Int? = null,
|
|
||||||
trtcId: String? = null,
|
|
||||||
page: Int = 1,
|
|
||||||
pageSize: Int = 10
|
|
||||||
): ListContainer<RoomRuleEntity>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询规则配额使用情况
|
|
||||||
* @param roomId 房间ID,与 trtcId 二选一
|
|
||||||
* @param trtcId TRTC房间ID,与 roomId 二选一
|
|
||||||
* @return 规则配额信息
|
|
||||||
* @throws ServiceException 查询失败时抛出异常
|
|
||||||
*/
|
|
||||||
suspend fun getRoomRuleQuota(
|
|
||||||
roomId: Int? = null,
|
|
||||||
trtcId: String? = null
|
|
||||||
): RoomRuleQuotaEntity
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 房间规则服务实现类
|
|
||||||
*/
|
|
||||||
class RoomServiceImpl : RoomService {
|
|
||||||
override suspend fun createRoomRule(
|
|
||||||
rule: String,
|
|
||||||
roomId: Int?,
|
|
||||||
trtcId: String?
|
|
||||||
) {
|
|
||||||
val resp = ApiClient.api.createRoomRule(
|
|
||||||
CreateRoomRuleRequestBody(
|
|
||||||
rule = rule,
|
|
||||||
roomId = roomId,
|
|
||||||
trtcId = trtcId
|
|
||||||
)
|
|
||||||
)
|
|
||||||
if (!resp.isSuccessful) {
|
|
||||||
throw ServiceException("创建房间规则失败")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun updateRoomRule(
|
|
||||||
id: Int,
|
|
||||||
rule: String
|
|
||||||
) {
|
|
||||||
val resp = ApiClient.api.updateRoomRule(
|
|
||||||
UpdateRoomRuleRequestBody(
|
|
||||||
id = id,
|
|
||||||
rule = rule
|
|
||||||
)
|
|
||||||
)
|
|
||||||
if (!resp.isSuccessful) {
|
|
||||||
throw ServiceException("修改房间规则失败")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun deleteRoomRule(id: Int) {
|
|
||||||
val resp = ApiClient.api.deleteRoomRule(id)
|
|
||||||
if (!resp.isSuccessful) {
|
|
||||||
throw ServiceException("删除房间规则失败")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun getRoomRuleList(
|
|
||||||
roomId: Int?,
|
|
||||||
trtcId: String?,
|
|
||||||
page: Int,
|
|
||||||
pageSize: Int
|
|
||||||
): ListContainer<RoomRuleEntity> {
|
|
||||||
val resp = ApiClient.api.getRoomRuleList(
|
|
||||||
roomId = roomId,
|
|
||||||
trtcId = trtcId,
|
|
||||||
page = page,
|
|
||||||
pageSize = pageSize
|
|
||||||
)
|
|
||||||
val body = resp.body() ?: throw ServiceException("获取房间规则列表失败")
|
|
||||||
|
|
||||||
return ListContainer(
|
|
||||||
list = body.list.map { it.toRoomRuleEntity() },
|
|
||||||
page = body.page,
|
|
||||||
total = body.total,
|
|
||||||
pageSize = body.pageSize
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun getRoomRuleQuota(
|
|
||||||
roomId: Int?,
|
|
||||||
trtcId: String?
|
|
||||||
): RoomRuleQuotaEntity {
|
|
||||||
val resp = ApiClient.api.getRoomRuleQuota(
|
|
||||||
roomId = roomId,
|
|
||||||
trtcId = trtcId
|
|
||||||
)
|
|
||||||
val body = resp.body() ?: throw ServiceException("获取规则配额信息失败")
|
|
||||||
val data = body.data ?: throw ServiceException("规则配额数据为空")
|
|
||||||
|
|
||||||
return data.toRoomRuleQuotaEntity()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* RoomRule 扩展函数,转换为 RoomRuleEntity
|
|
||||||
*/
|
|
||||||
fun RoomRule.toRoomRuleEntity(): RoomRuleEntity {
|
|
||||||
return RoomRuleEntity(
|
|
||||||
id = id,
|
|
||||||
rule = rule,
|
|
||||||
creator = creator?.toRoomRuleCreatorEntity(),
|
|
||||||
creatorType = creatorType,
|
|
||||||
roomId = roomId,
|
|
||||||
createdAt = createdAt,
|
|
||||||
updatedAt = updatedAt
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* RoomRuleCreator 扩展函数,转换为 RoomRuleCreatorEntity
|
|
||||||
*/
|
|
||||||
fun RoomRuleCreator.toRoomRuleCreatorEntity(): RoomRuleCreatorEntity {
|
|
||||||
return RoomRuleCreatorEntity(
|
|
||||||
id = id,
|
|
||||||
nickname = nickname,
|
|
||||||
avatar = avatar
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* RoomRuleQuota 扩展函数,转换为 RoomRuleQuotaEntity
|
|
||||||
*/
|
|
||||||
fun RoomRuleQuota.toRoomRuleQuotaEntity(): RoomRuleQuotaEntity {
|
|
||||||
return RoomRuleQuotaEntity(
|
|
||||||
baseMaxCount = baseMaxCount,
|
|
||||||
purchasedCount = purchasedCount,
|
|
||||||
totalMaxCount = totalMaxCount,
|
|
||||||
currentCount = currentCount,
|
|
||||||
remainingCount = remainingCount,
|
|
||||||
usagePercent = usagePercent
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -97,8 +97,7 @@ class UserServiceImpl : UserService {
|
|||||||
pageSize = pageSize,
|
pageSize = pageSize,
|
||||||
search = nickname,
|
search = nickname,
|
||||||
followerId = followerId,
|
followerId = followerId,
|
||||||
followingId = followingId,
|
followingId = followingId
|
||||||
includeAI = true
|
|
||||||
)
|
)
|
||||||
val body = resp.body() ?: throw ServiceException("Failed to get account")
|
val body = resp.body() ?: throw ServiceException("Failed to get account")
|
||||||
return ListContainer<AccountProfileEntity>(
|
return ListContainer<AccountProfileEntity>(
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ data class SendChatAiRequestBody(
|
|||||||
@SerializedName("skipTrtc")
|
@SerializedName("skipTrtc")
|
||||||
val skipTrtc: Boolean? = true,
|
val skipTrtc: Boolean? = true,
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
data class CreateGroupChatRequestBody(
|
data class CreateGroupChatRequestBody(
|
||||||
@@ -77,7 +77,7 @@ data class CreateGroupChatRequestBody(
|
|||||||
val userIds: List<String>,
|
val userIds: List<String>,
|
||||||
@SerializedName("promptIds")
|
@SerializedName("promptIds")
|
||||||
val promptIds: List<String>,
|
val promptIds: List<String>,
|
||||||
)
|
)
|
||||||
|
|
||||||
data class JoinGroupChatRequestBody(
|
data class JoinGroupChatRequestBody(
|
||||||
@SerializedName("trtcId")
|
@SerializedName("trtcId")
|
||||||
@@ -392,13 +392,11 @@ data class GroupChatResponse(
|
|||||||
@SerializedName("source")
|
@SerializedName("source")
|
||||||
val source: String
|
val source: String
|
||||||
)
|
)
|
||||||
|
class CategoryTemplateTranslation(
|
||||||
|
|
||||||
data class CategoryTranslation(
|
|
||||||
@SerializedName("name")
|
@SerializedName("name")
|
||||||
val name: String?,
|
val name: String,
|
||||||
@SerializedName("description")
|
@SerializedName("description")
|
||||||
val description: String?
|
val description: String,
|
||||||
)
|
)
|
||||||
|
|
||||||
data class CategoryTemplate(
|
data class CategoryTemplate(
|
||||||
@@ -427,340 +425,18 @@ data class CategoryTemplate(
|
|||||||
@SerializedName("updatedAt")
|
@SerializedName("updatedAt")
|
||||||
val updatedAt: String,
|
val updatedAt: String,
|
||||||
@SerializedName("translations")
|
@SerializedName("translations")
|
||||||
val translations: Map<String, CategoryTranslation>?
|
val translations: Map<String, CategoryTemplateTranslation>?
|
||||||
) {
|
) {
|
||||||
/**
|
/**
|
||||||
* 根据语言代码获取翻译后的名称,如果没有翻译则返回默认名称
|
* 获取本地化名称,优先使用当前语言的翻译,如果没有则使用默认名称
|
||||||
*/
|
*/
|
||||||
fun getLocalizedName(lang: String): String {
|
fun getLocalizedName(): String {
|
||||||
// 尝试获取完整的语言标记(如 "zh-CN")
|
// 这里可以根据需要添加国际化逻辑
|
||||||
val translation = translations?.get(lang)
|
// 目前直接返回默认名称
|
||||||
if (translation?.name != null && translation.name.isNotEmpty()) {
|
|
||||||
return translation.name
|
|
||||||
}
|
|
||||||
|
|
||||||
// 如果没有找到,尝试语言代码的前缀(如 "zh")
|
|
||||||
val langPrefix = lang.split("-", "_").firstOrNull()
|
|
||||||
if (langPrefix != null) {
|
|
||||||
translations?.entries?.forEach { (key, value) ->
|
|
||||||
if (key.startsWith(langPrefix) && value.name != null && value.name.isNotEmpty()) {
|
|
||||||
return value.name
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 如果没有翻译,返回默认名称
|
|
||||||
return name
|
return name
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据语言代码获取翻译后的描述,如果没有翻译则返回默认描述
|
|
||||||
*/
|
|
||||||
fun getLocalizedDescription(lang: String): String {
|
|
||||||
// 尝试获取完整的语言标记(如 "zh-CN")
|
|
||||||
val translation = translations?.get(lang)
|
|
||||||
if (translation?.description != null && translation.description.isNotEmpty()) {
|
|
||||||
return translation.description
|
|
||||||
}
|
|
||||||
|
|
||||||
// 如果没有找到,尝试语言代码的前缀(如 "zh")
|
|
||||||
val langPrefix = lang.split("-", "_").firstOrNull()
|
|
||||||
if (langPrefix != null) {
|
|
||||||
translations?.entries?.forEach { (key, value) ->
|
|
||||||
if (key.startsWith(langPrefix) && value.description != null && value.description.isNotEmpty()) {
|
|
||||||
return value.description
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 如果没有翻译,返回默认描述
|
|
||||||
return description
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
data class CategoryListResponse(
|
|
||||||
@SerializedName("page")
|
|
||||||
val page: Int,
|
|
||||||
@SerializedName("pageSize")
|
|
||||||
val pageSize: Int,
|
|
||||||
@SerializedName("total")
|
|
||||||
val total: Int,
|
|
||||||
@SerializedName("list")
|
|
||||||
val list: List<CategoryTemplate>
|
|
||||||
)
|
|
||||||
|
|
||||||
// ========== Agent Rule 相关数据类 ==========
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建规则请求体
|
|
||||||
* @param rule 规则内容,不能为空
|
|
||||||
* @param promptId 智能体ID,与 openId 二选一,promptId 优先
|
|
||||||
* @param openId 智能体的 OpenID(UUID格式),与 promptId 二选一
|
|
||||||
*/
|
|
||||||
data class CreateAgentRuleRequestBody(
|
|
||||||
@SerializedName("rule")
|
|
||||||
val rule: String,
|
|
||||||
@SerializedName("promptId")
|
|
||||||
val promptId: Int? = null,
|
|
||||||
@SerializedName("openId")
|
|
||||||
val openId: String? = null
|
|
||||||
)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 修改规则请求体
|
|
||||||
* @param id 规则ID,必填
|
|
||||||
* @param rule 新的规则内容,不能为空
|
|
||||||
* @param promptId 要更改关联的智能体ID(可选)
|
|
||||||
* @param openId 要更改关联的智能体 OpenID(可选)
|
|
||||||
*/
|
|
||||||
data class UpdateAgentRuleRequestBody(
|
|
||||||
@SerializedName("id")
|
|
||||||
val id: Int,
|
|
||||||
@SerializedName("rule")
|
|
||||||
val rule: String,
|
|
||||||
@SerializedName("promptId")
|
|
||||||
val promptId: Int? = null,
|
|
||||||
@SerializedName("openId")
|
|
||||||
val openId: String? = null
|
|
||||||
)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 规则关联的智能体信息
|
|
||||||
* @param id 智能体ID
|
|
||||||
* @param title 智能体标题
|
|
||||||
* @param avatar 智能体头像URL
|
|
||||||
*/
|
|
||||||
data class AgentRuleAgent(
|
|
||||||
@SerializedName("id")
|
|
||||||
val id: Int,
|
|
||||||
@SerializedName("title")
|
|
||||||
val title: String,
|
|
||||||
@SerializedName("avatar")
|
|
||||||
val avatar: String
|
|
||||||
)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 规则详情
|
|
||||||
* @param id 规则ID
|
|
||||||
* @param rule 规则内容
|
|
||||||
* @param creator 创建者名称
|
|
||||||
* @param creatorType 创建者类型(如 "user")
|
|
||||||
* @param scope 作用域(如 "personal")
|
|
||||||
* @param prompt 关联的智能体信息
|
|
||||||
* @param createdAt 创建时间(ISO 8601 格式)
|
|
||||||
* @param updatedAt 更新时间(ISO 8601 格式)
|
|
||||||
*/
|
|
||||||
data class AgentRule(
|
|
||||||
@SerializedName("id")
|
|
||||||
val id: Int,
|
|
||||||
@SerializedName("rule")
|
|
||||||
val rule: String,
|
|
||||||
@SerializedName("creator")
|
|
||||||
val creator: String,
|
|
||||||
@SerializedName("creator_type")
|
|
||||||
val creatorType: String,
|
|
||||||
@SerializedName("scope")
|
|
||||||
val scope: String,
|
|
||||||
@SerializedName("prompt")
|
|
||||||
val prompt: AgentRuleAgent,
|
|
||||||
@SerializedName("created_at")
|
|
||||||
val createdAt: String,
|
|
||||||
@SerializedName("updated_at")
|
|
||||||
val updatedAt: String
|
|
||||||
)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 规则列表响应
|
|
||||||
* @param page 当前页码
|
|
||||||
* @param pageSize 每页数量
|
|
||||||
* @param total 总记录数
|
|
||||||
* @param list 规则列表
|
|
||||||
*/
|
|
||||||
data class AgentRuleListResponse(
|
|
||||||
@SerializedName("page")
|
|
||||||
val page: Int,
|
|
||||||
@SerializedName("pageSize")
|
|
||||||
val pageSize: Int,
|
|
||||||
@SerializedName("total")
|
|
||||||
val total: Int,
|
|
||||||
@SerializedName("list")
|
|
||||||
val list: List<AgentRule>
|
|
||||||
)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 规则配额信息
|
|
||||||
* @param promptId 智能体ID
|
|
||||||
* @param promptTitle 智能体标题
|
|
||||||
* @param baseMaxCount 基础条数限制(免费配额)
|
|
||||||
* @param purchasedCount 用户购买的额外条数
|
|
||||||
* @param totalMaxCount 总可用条数(基础+购买)
|
|
||||||
* @param currentCount 当前已创建的规则条数
|
|
||||||
* @param remainingCount 剩余可用条数
|
|
||||||
* @param usagePercent 使用百分比(0-100)
|
|
||||||
*/
|
|
||||||
data class AgentRuleQuota(
|
|
||||||
@SerializedName("promptId")
|
|
||||||
val promptId: Int,
|
|
||||||
@SerializedName("promptTitle")
|
|
||||||
val promptTitle: String,
|
|
||||||
@SerializedName("baseMaxCount")
|
|
||||||
val baseMaxCount: Int,
|
|
||||||
@SerializedName("purchasedCount")
|
|
||||||
val purchasedCount: Int,
|
|
||||||
@SerializedName("totalMaxCount")
|
|
||||||
val totalMaxCount: Int,
|
|
||||||
@SerializedName("currentCount")
|
|
||||||
val currentCount: Int,
|
|
||||||
@SerializedName("remainingCount")
|
|
||||||
val remainingCount: Int,
|
|
||||||
@SerializedName("usagePercent")
|
|
||||||
val usagePercent: Double
|
|
||||||
)
|
|
||||||
|
|
||||||
// ========== Room Rule 相关数据类 ==========
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建房间规则请求体
|
|
||||||
* @param rule 规则内容,不能为空
|
|
||||||
* @param roomId 房间ID,与 trtcId 二选一
|
|
||||||
* @param trtcId TRTC房间ID(字符串格式),与 roomId 二选一
|
|
||||||
*/
|
|
||||||
data class CreateRoomRuleRequestBody(
|
|
||||||
@SerializedName("rule")
|
|
||||||
val rule: String,
|
|
||||||
@SerializedName("roomId")
|
|
||||||
val roomId: Int? = null,
|
|
||||||
@SerializedName("trtcId")
|
|
||||||
val trtcId: String? = null
|
|
||||||
)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 修改房间规则请求体
|
|
||||||
* @param id 规则ID,必填
|
|
||||||
* @param rule 新的规则内容,不能为空
|
|
||||||
*/
|
|
||||||
data class UpdateRoomRuleRequestBody(
|
|
||||||
@SerializedName("id")
|
|
||||||
val id: Int,
|
|
||||||
@SerializedName("rule")
|
|
||||||
val rule: String
|
|
||||||
)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 房间规则创建者信息
|
|
||||||
* @param id 创建者ID
|
|
||||||
* @param nickname 创建者昵称
|
|
||||||
* @param avatar 创建者头像文件名
|
|
||||||
*/
|
|
||||||
data class RoomRuleCreator(
|
|
||||||
@SerializedName("id")
|
|
||||||
val id: Int,
|
|
||||||
@SerializedName("nickname")
|
|
||||||
val nickname: String,
|
|
||||||
@SerializedName("avatar")
|
|
||||||
val avatar: String
|
|
||||||
)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 房间规则详情
|
|
||||||
* @param id 规则ID
|
|
||||||
* @param rule 规则内容
|
|
||||||
* @param creator 创建者信息(可能为 null)
|
|
||||||
* @param creatorType 创建者类型(如 "user")
|
|
||||||
* @param roomId 所属房间ID
|
|
||||||
* @param createdAt 创建时间(ISO 8601 格式)
|
|
||||||
* @param updatedAt 更新时间(ISO 8601 格式)
|
|
||||||
*/
|
|
||||||
data class RoomRule(
|
|
||||||
@SerializedName("id")
|
|
||||||
val id: Int,
|
|
||||||
@SerializedName("rule")
|
|
||||||
val rule: String,
|
|
||||||
@SerializedName("creator")
|
|
||||||
val creator: RoomRuleCreator?,
|
|
||||||
@SerializedName("creatorType")
|
|
||||||
val creatorType: String,
|
|
||||||
@SerializedName("roomId")
|
|
||||||
val roomId: Int,
|
|
||||||
@SerializedName("createdAt")
|
|
||||||
val createdAt: String,
|
|
||||||
@SerializedName("updatedAt")
|
|
||||||
val updatedAt: String
|
|
||||||
)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 房间规则列表响应
|
|
||||||
* @param page 当前页码
|
|
||||||
* @param pageSize 每页数量
|
|
||||||
* @param total 总记录数
|
|
||||||
* @param list 规则列表
|
|
||||||
*/
|
|
||||||
data class RoomRuleListResponse(
|
|
||||||
@SerializedName("page")
|
|
||||||
val page: Int,
|
|
||||||
@SerializedName("pageSize")
|
|
||||||
val pageSize: Int,
|
|
||||||
@SerializedName("total")
|
|
||||||
val total: Long,
|
|
||||||
@SerializedName("list")
|
|
||||||
val list: List<RoomRule>
|
|
||||||
)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 房间规则配额信息
|
|
||||||
* @param baseMaxCount 基础条数限制(系统配置的免费配额)
|
|
||||||
* @param purchasedCount 用户购买的额外条数(通过自动扩容机制)
|
|
||||||
* @param totalMaxCount 总可用条数(baseMaxCount + purchasedCount)
|
|
||||||
* @param currentCount 当前已创建的规则条数(该用户在该房间)
|
|
||||||
* @param remainingCount 剩余可用条数(totalMaxCount - currentCount)
|
|
||||||
* @param usagePercent 使用百分比(0-100)
|
|
||||||
*/
|
|
||||||
data class RoomRuleQuota(
|
|
||||||
@SerializedName("baseMaxCount")
|
|
||||||
val baseMaxCount: Int,
|
|
||||||
@SerializedName("purchasedCount")
|
|
||||||
val purchasedCount: Int,
|
|
||||||
@SerializedName("totalMaxCount")
|
|
||||||
val totalMaxCount: Int,
|
|
||||||
@SerializedName("currentCount")
|
|
||||||
val currentCount: Int,
|
|
||||||
@SerializedName("remainingCount")
|
|
||||||
val remainingCount: Int,
|
|
||||||
@SerializedName("usagePercent")
|
|
||||||
val usagePercent: Double
|
|
||||||
)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 积分不足错误响应
|
|
||||||
*
|
|
||||||
* 当创建房间规则时积分不足,服务器会返回此特殊错误格式。
|
|
||||||
* 包含当前余额和所需金额信息,便于客户端提示用户。
|
|
||||||
*
|
|
||||||
* @param success 是否成功,固定为 false
|
|
||||||
* @param code 错误码,固定为 35600(积分不足)
|
|
||||||
* @param message 错误消息,包含所需积分和当前余额的详细说明
|
|
||||||
* @param err 错误类型,固定为 "InsufficientBalance"
|
|
||||||
* @param currentBalance 当前积分余额
|
|
||||||
* @param requiredAmount 所需积分数量
|
|
||||||
* @param traceId 追踪ID(可选)
|
|
||||||
*/
|
|
||||||
data class InsufficientBalanceError(
|
|
||||||
@SerializedName("success")
|
|
||||||
val success: Boolean,
|
|
||||||
@SerializedName("code")
|
|
||||||
val code: Int,
|
|
||||||
@SerializedName("message")
|
|
||||||
val message: String,
|
|
||||||
@SerializedName("err")
|
|
||||||
val err: String,
|
|
||||||
@SerializedName("currentBalance")
|
|
||||||
val currentBalance: Int,
|
|
||||||
@SerializedName("requiredAmount")
|
|
||||||
val requiredAmount: Int,
|
|
||||||
@SerializedName("traceId")
|
|
||||||
val traceId: String?
|
|
||||||
)
|
|
||||||
|
|
||||||
interface RaveNowAPI {
|
interface RaveNowAPI {
|
||||||
@GET("membership/config")
|
@GET("membership/config")
|
||||||
@retrofit2.http.Headers("X-Requires-Auth: true")
|
@retrofit2.http.Headers("X-Requires-Auth: true")
|
||||||
@@ -799,8 +475,6 @@ interface RaveNowAPI {
|
|||||||
@Query("trend") trend: String? = null,
|
@Query("trend") trend: String? = null,
|
||||||
@Query("favouriteUserId") favouriteUserId: Int? = null,
|
@Query("favouriteUserId") favouriteUserId: Int? = null,
|
||||||
@Query("explore") explore: String? = null,
|
@Query("explore") explore: String? = null,
|
||||||
@Query("newsFilter") newsFilter: String? = null,
|
|
||||||
@Query("videoFilter") videoFilter: String? = null,
|
|
||||||
): Response<ListContainer<Moment>>
|
): Response<ListContainer<Moment>>
|
||||||
|
|
||||||
@Multipart
|
@Multipart
|
||||||
@@ -955,7 +629,7 @@ interface RaveNowAPI {
|
|||||||
@Query("nickname") search: String? = null,
|
@Query("nickname") search: String? = null,
|
||||||
@Query("followerId") followerId: Int? = null,
|
@Query("followerId") followerId: Int? = null,
|
||||||
@Query("followingId") followingId: Int? = null,
|
@Query("followingId") followingId: Int? = null,
|
||||||
@Query("includeAI") includeAI: Boolean? = true,
|
@Query("includeAI") includeAI: Boolean? = false,
|
||||||
@Query("chatSessionIdNotNull") chatSessionIdNotNull: Boolean? = true,
|
@Query("chatSessionIdNotNull") chatSessionIdNotNull: Boolean? = true,
|
||||||
): Response<ListContainer<AccountProfile>>
|
): Response<ListContainer<AccountProfile>>
|
||||||
|
|
||||||
@@ -1042,10 +716,26 @@ interface RaveNowAPI {
|
|||||||
suspend fun getAgent(
|
suspend fun getAgent(
|
||||||
@Query("page") page: Int = 1,
|
@Query("page") page: Int = 1,
|
||||||
@Query("pageSize") pageSize: Int = 20,
|
@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("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("categoryIds") categoryIds: List<Int>? = null,
|
||||||
@Query("random") random: Int? = null,
|
@Query("uncategorized") uncategorized: String? = null,
|
||||||
): Response<DataContainer<ListContainer<Agent>>>
|
): Response<DataContainer<ListContainer<Agent>>>
|
||||||
|
|
||||||
@GET("outside/my/prompts")
|
@GET("outside/my/prompts")
|
||||||
@@ -1113,9 +803,8 @@ interface RaveNowAPI {
|
|||||||
@Query("withChildren") withChildren: Boolean? = null,
|
@Query("withChildren") withChildren: Boolean? = null,
|
||||||
@Query("withParent") withParent: Boolean? = null,
|
@Query("withParent") withParent: Boolean? = null,
|
||||||
@Query("withCount") withCount: Boolean? = null,
|
@Query("withCount") withCount: Boolean? = null,
|
||||||
@Query("hideEmpty") hideEmpty: Boolean? = null,
|
@Query("hideEmpty") hideEmpty: Boolean? = null
|
||||||
@Query("lang") lang: String? = null
|
): Response<ListContainer<CategoryTemplate>>
|
||||||
): Response<CategoryListResponse>
|
|
||||||
|
|
||||||
@GET("outside/categories/tree")
|
@GET("outside/categories/tree")
|
||||||
suspend fun getCategoryTree(
|
suspend fun getCategoryTree(
|
||||||
@@ -1128,470 +817,6 @@ interface RaveNowAPI {
|
|||||||
@Path("id") id: Int
|
@Path("id") id: Int
|
||||||
): Response<DataContainer<CategoryTemplate>>
|
): 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>>
|
|
||||||
|
|
||||||
// ========== Agent Rule API ==========
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建智能体规则
|
|
||||||
*
|
|
||||||
* 功能说明:
|
|
||||||
* - 为指定的智能体创建一条新规则
|
|
||||||
* - 规则必须关联到存在的智能体(通过 promptId 或 openId 指定)
|
|
||||||
* - 创建前会自动检查配额限制,如果超出会尝试自动扩容
|
|
||||||
* - 只有创建者可以修改和删除该规则
|
|
||||||
*
|
|
||||||
* @param body 创建规则请求体
|
|
||||||
* - rule: 规则内容,不能为空
|
|
||||||
* - promptId: 智能体ID(与 openId 二选一,promptId 优先)
|
|
||||||
* - openId: 智能体的 OpenID(UUID格式,与 promptId 二选一)
|
|
||||||
*
|
|
||||||
* @return 成功时返回空 Unit,失败时返回错误信息
|
|
||||||
*
|
|
||||||
* 示例:
|
|
||||||
* ```kotlin
|
|
||||||
* val request = CreatePromptRuleRequestBody(
|
|
||||||
* rule = "禁止讨论政治话题",
|
|
||||||
* promptId = 123
|
|
||||||
* )
|
|
||||||
* val response = api.createPromptRule(request)
|
|
||||||
* ```
|
|
||||||
*/
|
|
||||||
@POST("outside/prompt/rule")
|
|
||||||
suspend fun createAgentRule(
|
|
||||||
@Body body: CreateAgentRuleRequestBody
|
|
||||||
): Response<Unit>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 修改智能体规则
|
|
||||||
*
|
|
||||||
* 功能说明:
|
|
||||||
* - 修改已存在的规则内容或关联的智能体
|
|
||||||
* - 只有规则的创建者可以修改
|
|
||||||
* - 可以同时修改规则内容和关联的智能体
|
|
||||||
* - 修改关联智能体时会重新验证配额限制
|
|
||||||
*
|
|
||||||
* @param body 修改规则请求体
|
|
||||||
* - id: 规则ID,必填
|
|
||||||
* - rule: 新的规则内容,不能为空
|
|
||||||
* - promptId: 要更改关联的智能体ID(可选)
|
|
||||||
* - openId: 要更改关联的智能体 OpenID(可选)
|
|
||||||
*
|
|
||||||
* @return 成功时返回空 Unit,失败时返回错误信息
|
|
||||||
*
|
|
||||||
* 权限要求:
|
|
||||||
* - 必须是规则的创建者(creator_type 为 "user" 且 create_id 匹配)
|
|
||||||
*
|
|
||||||
* 示例:
|
|
||||||
* ```kotlin
|
|
||||||
* val request = UpdatePromptRuleRequestBody(
|
|
||||||
* id = 456,
|
|
||||||
* rule = "禁止讨论政治和敏感话题"
|
|
||||||
* )
|
|
||||||
* val response = api.updatePromptRule(request)
|
|
||||||
* ```
|
|
||||||
*/
|
|
||||||
@retrofit2.http.PUT("outside/prompt/rule")
|
|
||||||
suspend fun updateAgentRule(
|
|
||||||
@Body body: UpdateAgentRuleRequestBody
|
|
||||||
): Response<Unit>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除智能体规则
|
|
||||||
*
|
|
||||||
* 功能说明:
|
|
||||||
* - 删除指定的规则
|
|
||||||
* - 只有规则的创建者可以删除
|
|
||||||
* - 删除操作不可恢复,请谨慎操作
|
|
||||||
*
|
|
||||||
* @param id 规则ID
|
|
||||||
*
|
|
||||||
* @return 成功时返回空 Unit,失败时返回错误信息
|
|
||||||
*
|
|
||||||
* 权限要求:
|
|
||||||
* - 必须是规则的创建者(creator_type 为 "user" 且 create_id 匹配)
|
|
||||||
*
|
|
||||||
* 示例:
|
|
||||||
* ```kotlin
|
|
||||||
* val response = api.deletePromptRule(456)
|
|
||||||
* ```
|
|
||||||
*/
|
|
||||||
@DELETE("outside/prompt/rule/{id}")
|
|
||||||
suspend fun deleteAgentRule(
|
|
||||||
@Path("id") id: Int
|
|
||||||
): Response<Unit>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询智能体规则列表
|
|
||||||
*
|
|
||||||
* 功能说明:
|
|
||||||
* - 查询指定智能体下当前用户创建的规则列表
|
|
||||||
* - 支持分页和关键词模糊搜索
|
|
||||||
* - 只返回当前用户创建的规则,不会返回其他用户的规则
|
|
||||||
*
|
|
||||||
* @param promptId 智能体ID,支持数字ID或UUID格式的 openId
|
|
||||||
* @param rule 规则内容关键词(模糊搜索),可选
|
|
||||||
* @param page 页码,默认 1
|
|
||||||
* @param pageSize 每页数量,默认 10
|
|
||||||
*
|
|
||||||
* @return 返回分页的规则列表,包含规则详情和关联的智能体信息
|
|
||||||
*
|
|
||||||
* 响应数据说明:
|
|
||||||
* - page: 当前页码
|
|
||||||
* - pageSize: 每页数量
|
|
||||||
* - total: 总记录数
|
|
||||||
* - list: 规则列表
|
|
||||||
* - id: 规则ID
|
|
||||||
* - rule: 规则内容
|
|
||||||
* - creator: 创建者名称
|
|
||||||
* - creator_type: 创建者类型
|
|
||||||
* - scope: 作用域
|
|
||||||
* - prompt: 关联的智能体信息(id, title, avatar)
|
|
||||||
* - created_at: 创建时间
|
|
||||||
* - updated_at: 更新时间
|
|
||||||
*
|
|
||||||
* 示例:
|
|
||||||
* ```kotlin
|
|
||||||
* // 使用数字ID查询
|
|
||||||
* val response1 = api.getPromptRuleList("123", page = 1, pageSize = 10)
|
|
||||||
*
|
|
||||||
* // 使用 OpenID 查询
|
|
||||||
* val response2 = api.getPromptRuleList(
|
|
||||||
* "550e8400-e29b-41d4-a716-446655440000",
|
|
||||||
* page = 1,
|
|
||||||
* pageSize = 10
|
|
||||||
* )
|
|
||||||
*
|
|
||||||
* // 带关键词搜索
|
|
||||||
* val response3 = api.getPromptRuleList(
|
|
||||||
* "123",
|
|
||||||
* rule = "政治",
|
|
||||||
* page = 1,
|
|
||||||
* pageSize = 10
|
|
||||||
* )
|
|
||||||
* ```
|
|
||||||
*/
|
|
||||||
@GET("outside/prompt/{promptId}/rule/list")
|
|
||||||
suspend fun getAgentRuleList(
|
|
||||||
@Path("promptId") promptId: String,
|
|
||||||
@Query("rule") rule: String? = null,
|
|
||||||
@Query("page") page: Int = 1,
|
|
||||||
@Query("pageSize") pageSize: Int = 10
|
|
||||||
): Response<DataContainer<AgentRuleListResponse>>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询智能体规则配额信息
|
|
||||||
*
|
|
||||||
* 功能说明:
|
|
||||||
* - 查询指定智能体的规则条数使用情况
|
|
||||||
* - 包括基础配额、已购买配额、已使用数量等完整信息
|
|
||||||
* - 用于判断是否还能创建新规则
|
|
||||||
*
|
|
||||||
* @param promptId 智能体ID,支持数字ID或UUID格式的 openId
|
|
||||||
*
|
|
||||||
* @return 返回配额详细信息
|
|
||||||
*
|
|
||||||
* 响应数据说明:
|
|
||||||
* - promptId: 智能体ID
|
|
||||||
* - promptTitle: 智能体标题
|
|
||||||
* - baseMaxCount: 基础条数限制(免费配额,由智能体等级决定)
|
|
||||||
* - purchasedCount: 用户购买的额外条数
|
|
||||||
* - totalMaxCount: 总可用条数(baseMaxCount + purchasedCount)
|
|
||||||
* - currentCount: 当前已创建的规则条数(只统计当前用户创建的)
|
|
||||||
* - remainingCount: 剩余可用条数(totalMaxCount - currentCount)
|
|
||||||
* - usagePercent: 使用百分比,0-100(currentCount / totalMaxCount * 100)
|
|
||||||
*
|
|
||||||
* 使用场景:
|
|
||||||
* 1. 创建规则前检查是否有足够配额
|
|
||||||
* 2. 展示规则使用情况统计
|
|
||||||
* 3. 提示用户购买额外配额
|
|
||||||
*
|
|
||||||
* 示例:
|
|
||||||
* ```kotlin
|
|
||||||
* // 使用数字ID查询
|
|
||||||
* val response1 = api.getPromptRuleQuota("123")
|
|
||||||
*
|
|
||||||
* // 使用 OpenID 查询
|
|
||||||
* val response2 = api.getPromptRuleQuota("550e8400-e29b-41d4-a716-446655440000")
|
|
||||||
*
|
|
||||||
* // 处理响应
|
|
||||||
* response1.body()?.data?.let { quota ->
|
|
||||||
* if (quota.remainingCount > 0) {
|
|
||||||
* // 可以创建新规则
|
|
||||||
* println("还可以创建 ${quota.remainingCount} 条规则")
|
|
||||||
* } else {
|
|
||||||
* // 配额已用完
|
|
||||||
* println("规则配额已用完,已使用 ${quota.currentCount}/${quota.totalMaxCount}")
|
|
||||||
* }
|
|
||||||
* }
|
|
||||||
* ```
|
|
||||||
*/
|
|
||||||
@GET("outside/prompt/{promptId}/rule/count")
|
|
||||||
suspend fun getAgentRuleQuota(
|
|
||||||
@Path("promptId") promptId: String
|
|
||||||
): Response<DataContainer<AgentRuleQuota>>
|
|
||||||
|
|
||||||
// ========== Room Rule API ==========
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 创建房间规则
|
|
||||||
*
|
|
||||||
* 功能说明:
|
|
||||||
* - 为指定的房间创建一条新规则
|
|
||||||
* - 规则会被添加到AI对话上下文中,用于约束房间内的行为和交互方式
|
|
||||||
* - 必须是房间成员或房间创建者才能创建规则
|
|
||||||
* - 每个用户在每个房间有基础条数限制,达到限制后会自动扣费扩容
|
|
||||||
* - 如果积分不足,会返回特殊的错误响应(错误码 35600)
|
|
||||||
*
|
|
||||||
* @param body 创建规则请求体
|
|
||||||
* - rule: 规则内容,不能为空
|
|
||||||
* - roomId: 房间ID(与 trtcId 二选一)
|
|
||||||
* - trtcId: TRTC房间ID(与 roomId 二选一)
|
|
||||||
*
|
|
||||||
* @return 成功时返回空 Unit,失败时返回错误信息
|
|
||||||
*
|
|
||||||
* 错误响应说明:
|
|
||||||
* - 400 (40001): 缺少房间标识(必须提供 roomId 或 trtcId)
|
|
||||||
* - 400 (40002): 规则内容为空
|
|
||||||
* - 400 (40003): 规则内容超出字数限制
|
|
||||||
* - 400 (35600): 积分不足(自动扩容失败),返回 InsufficientBalanceError 格式
|
|
||||||
* - 401 (40101): 未登录
|
|
||||||
* - 403 (40301): 无权限为该房间创建规则
|
|
||||||
* - 400 (40005): 房间不存在
|
|
||||||
*
|
|
||||||
* 示例:
|
|
||||||
* ```kotlin
|
|
||||||
* // 使用 roomId 创建规则
|
|
||||||
* val request1 = CreateRoomRuleRequestBody(
|
|
||||||
* rule = "禁止在房间内讨论政治话题",
|
|
||||||
* roomId = 123
|
|
||||||
* )
|
|
||||||
* val response1 = api.createRoomRule(request1)
|
|
||||||
*
|
|
||||||
* // 使用 trtcId 创建规则
|
|
||||||
* val request2 = CreateRoomRuleRequestBody(
|
|
||||||
* rule = "请使用文明用语",
|
|
||||||
* trtcId = "room_trtc_123"
|
|
||||||
* )
|
|
||||||
* val response2 = api.createRoomRule(request2)
|
|
||||||
*
|
|
||||||
* // 处理积分不足错误
|
|
||||||
* if (!response1.isSuccessful && response1.code() == 400) {
|
|
||||||
* val errorBody = response1.errorBody()?.string()
|
|
||||||
* // 解析为 InsufficientBalanceError 获取余额信息
|
|
||||||
* }
|
|
||||||
* ```
|
|
||||||
*/
|
|
||||||
@POST("outside/room/rule")
|
|
||||||
suspend fun createRoomRule(
|
|
||||||
@Body body: CreateRoomRuleRequestBody
|
|
||||||
): Response<Unit>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 修改房间规则
|
|
||||||
*
|
|
||||||
* 功能说明:
|
|
||||||
* - 修改指定的房间规则内容
|
|
||||||
* - 只能修改自己创建的规则(creator_type 为 "user")
|
|
||||||
* - 修改不会增加规则条数,因此不会触发扣费
|
|
||||||
*
|
|
||||||
* @param body 修改规则请求体
|
|
||||||
* - id: 规则ID,必填
|
|
||||||
* - rule: 新的规则内容,不能为空
|
|
||||||
*
|
|
||||||
* @return 成功时返回空 Unit,失败时返回错误信息
|
|
||||||
*
|
|
||||||
* 权限要求:
|
|
||||||
* - 必须是规则的创建者
|
|
||||||
* - 规则必须是用户类型(creator_type = "user")
|
|
||||||
*
|
|
||||||
* 错误响应说明:
|
|
||||||
* - 400 (40002): 规则内容为空
|
|
||||||
* - 400 (40003): 规则内容超出字数限制
|
|
||||||
* - 401 (40101): 未登录
|
|
||||||
* - 403 (40301): 无权限修改该规则
|
|
||||||
* - 404 (40401): 规则不存在
|
|
||||||
*
|
|
||||||
* 示例:
|
|
||||||
* ```kotlin
|
|
||||||
* val request = UpdateRoomRuleRequestBody(
|
|
||||||
* id = 456,
|
|
||||||
* rule = "请保持友善交流"
|
|
||||||
* )
|
|
||||||
* val response = api.updateRoomRule(request)
|
|
||||||
* ```
|
|
||||||
*/
|
|
||||||
@retrofit2.http.PUT("outside/room/rule")
|
|
||||||
suspend fun updateRoomRule(
|
|
||||||
@Body body: UpdateRoomRuleRequestBody
|
|
||||||
): Response<Unit>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除房间规则
|
|
||||||
*
|
|
||||||
* 功能说明:
|
|
||||||
* - 删除指定的房间规则
|
|
||||||
* - 只能删除自己创建的规则(creator_type 为 "user")
|
|
||||||
* - 删除操作不可恢复,请谨慎操作
|
|
||||||
* - 删除规则不会退还已扣除的积分
|
|
||||||
*
|
|
||||||
* @param id 规则ID
|
|
||||||
*
|
|
||||||
* @return 成功时返回空 Unit,失败时返回错误信息
|
|
||||||
*
|
|
||||||
* 权限要求:
|
|
||||||
* - 必须是规则的创建者
|
|
||||||
* - 规则必须是用户类型(creator_type = "user")
|
|
||||||
*
|
|
||||||
* 错误响应说明:
|
|
||||||
* - 400 (40006): 无效的规则ID
|
|
||||||
* - 401 (40101): 未登录
|
|
||||||
* - 403 (40301): 无权限删除该规则
|
|
||||||
*
|
|
||||||
* 示例:
|
|
||||||
* ```kotlin
|
|
||||||
* val response = api.deleteRoomRule(456)
|
|
||||||
* ```
|
|
||||||
*/
|
|
||||||
@DELETE("outside/room/rule/{id}")
|
|
||||||
suspend fun deleteRoomRule(
|
|
||||||
@Path("id") id: Int
|
|
||||||
): Response<Unit>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询房间规则列表
|
|
||||||
*
|
|
||||||
* 功能说明:
|
|
||||||
* - 查询指定房间的规则列表,支持分页
|
|
||||||
* - 返回该房间所有用户创建的规则,包含创建者信息
|
|
||||||
* - 必须是房间成员或房间创建者才能查询
|
|
||||||
*
|
|
||||||
* @param roomId 房间ID,与 trtcId 二选一
|
|
||||||
* @param trtcId TRTC房间ID,与 roomId 二选一
|
|
||||||
* @param page 页码,默认 1
|
|
||||||
* @param pageSize 每页数量,默认 10
|
|
||||||
*
|
|
||||||
* @return 返回分页的规则列表,包含规则详情和创建者信息
|
|
||||||
*
|
|
||||||
* 响应数据说明:
|
|
||||||
* - page: 当前页码
|
|
||||||
* - pageSize: 每页数量
|
|
||||||
* - total: 总记录数
|
|
||||||
* - list: 规则列表
|
|
||||||
* - id: 规则ID
|
|
||||||
* - rule: 规则内容
|
|
||||||
* - creator: 创建者信息(id, nickname, avatar)
|
|
||||||
* - creatorType: 创建者类型("user" 等)
|
|
||||||
* - roomId: 所属房间ID
|
|
||||||
* - createdAt: 创建时间(ISO 8601格式)
|
|
||||||
* - updatedAt: 更新时间(ISO 8601格式)
|
|
||||||
*
|
|
||||||
* 错误响应说明:
|
|
||||||
* - 400 (40001): 缺少房间标识(必须提供 roomId 或 trtcId)
|
|
||||||
* - 401 (40101): 未登录
|
|
||||||
* - 403 (40301): 无权限查看该房间的规则
|
|
||||||
*
|
|
||||||
* 示例:
|
|
||||||
* ```kotlin
|
|
||||||
* // 使用 roomId 查询
|
|
||||||
* val response1 = api.getRoomRuleList(
|
|
||||||
* roomId = 123,
|
|
||||||
* page = 1,
|
|
||||||
* pageSize = 10
|
|
||||||
* )
|
|
||||||
*
|
|
||||||
* // 使用 trtcId 查询
|
|
||||||
* val response2 = api.getRoomRuleList(
|
|
||||||
* trtcId = "room_trtc_123",
|
|
||||||
* page = 1,
|
|
||||||
* pageSize = 10
|
|
||||||
* )
|
|
||||||
*
|
|
||||||
* // 处理响应
|
|
||||||
* response1.body()?.let { result ->
|
|
||||||
* println("共 ${result.total} 条规则,当前第 ${result.page} 页")
|
|
||||||
* result.list.forEach { rule ->
|
|
||||||
* println("规则: ${rule.rule}, 创建者: ${rule.creator?.nickname}")
|
|
||||||
* }
|
|
||||||
* }
|
|
||||||
* ```
|
|
||||||
*/
|
|
||||||
@GET("outside/room/rule")
|
|
||||||
suspend fun getRoomRuleList(
|
|
||||||
@Query("roomId") roomId: Int? = null,
|
|
||||||
@Query("trtcId") trtcId: String? = null,
|
|
||||||
@Query("page") page: Int = 1,
|
|
||||||
@Query("pageSize") pageSize: Int = 10
|
|
||||||
): Response<RoomRuleListResponse>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询规则额度使用情况
|
|
||||||
*
|
|
||||||
* 功能说明:
|
|
||||||
* - 查询当前用户在指定房间的规则额度使用情况
|
|
||||||
* - 包括基础条数、已购买条数、当前使用数等完整信息
|
|
||||||
* - 用于判断用户是否还能创建新规则
|
|
||||||
* - 必须是房间成员或房间创建者才能查询
|
|
||||||
*
|
|
||||||
* @param roomId 房间ID,与 trtcId 二选一
|
|
||||||
* @param trtcId TRTC房间ID,与 roomId 二选一
|
|
||||||
*
|
|
||||||
* @return 返回配额详细信息
|
|
||||||
*
|
|
||||||
* 响应数据说明:
|
|
||||||
* - baseMaxCount: 基础条数限制(系统配置的免费配额)
|
|
||||||
* - purchasedCount: 用户购买的额外条数(通过自动扩容机制)
|
|
||||||
* - totalMaxCount: 总可用条数(baseMaxCount + purchasedCount)
|
|
||||||
* - currentCount: 当前已创建的规则条数(该用户在该房间)
|
|
||||||
* - remainingCount: 剩余可用条数(totalMaxCount - currentCount)
|
|
||||||
* - usagePercent: 使用百分比,0-100(currentCount / totalMaxCount * 100)
|
|
||||||
*
|
|
||||||
* 使用场景:
|
|
||||||
* 1. 创建规则前检查是否有足够配额
|
|
||||||
* 2. 展示规则使用情况统计
|
|
||||||
* 3. 提示用户即将达到配额上限
|
|
||||||
*
|
|
||||||
* 错误响应说明:
|
|
||||||
* - 400 (40001): 缺少房间标识(必须提供 roomId 或 trtcId)
|
|
||||||
* - 401 (40101): 未登录
|
|
||||||
* - 403 (40301): 无权限查看该房间的规则条数信息
|
|
||||||
*
|
|
||||||
* 示例:
|
|
||||||
* ```kotlin
|
|
||||||
* // 使用 roomId 查询
|
|
||||||
* val response1 = api.getRoomRuleQuota(roomId = 123)
|
|
||||||
*
|
|
||||||
* // 使用 trtcId 查询
|
|
||||||
* val response2 = api.getRoomRuleQuota(trtcId = "room_trtc_123")
|
|
||||||
*
|
|
||||||
* // 处理响应
|
|
||||||
* response1.body()?.data?.let { quota ->
|
|
||||||
* if (quota.remainingCount > 0) {
|
|
||||||
* // 可以创建新规则
|
|
||||||
* println("还可以创建 ${quota.remainingCount} 条规则")
|
|
||||||
* println("使用率: ${quota.usagePercent}%")
|
|
||||||
* } else {
|
|
||||||
* // 配额已用完,需要扩容
|
|
||||||
* println("规则配额已用完,已使用 ${quota.currentCount}/${quota.totalMaxCount}")
|
|
||||||
* println("创建新规则将自动扣除积分进行扩容")
|
|
||||||
* }
|
|
||||||
* }
|
|
||||||
* ```
|
|
||||||
*/
|
|
||||||
@GET("outside/room/rule/length-info")
|
|
||||||
suspend fun getRoomRuleQuota(
|
|
||||||
@Query("roomId") roomId: Int? = null,
|
|
||||||
@Query("trtcId") trtcId: String? = null
|
|
||||||
): Response<DataContainer<RoomRuleQuota>>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,13 +7,18 @@ import com.aiosman.ravenow.data.Agent
|
|||||||
import com.aiosman.ravenow.data.ListContainer
|
import com.aiosman.ravenow.data.ListContainer
|
||||||
import com.aiosman.ravenow.data.AgentService
|
import com.aiosman.ravenow.data.AgentService
|
||||||
import com.aiosman.ravenow.data.DataContainer
|
import com.aiosman.ravenow.data.DataContainer
|
||||||
|
import com.aiosman.ravenow.data.MomentService
|
||||||
import com.aiosman.ravenow.data.ServiceException
|
import com.aiosman.ravenow.data.ServiceException
|
||||||
import com.aiosman.ravenow.data.UploadImage
|
import com.aiosman.ravenow.data.UploadImage
|
||||||
|
import com.aiosman.ravenow.data.UserService
|
||||||
import com.aiosman.ravenow.data.api.ApiClient
|
import com.aiosman.ravenow.data.api.ApiClient
|
||||||
|
import okhttp3.MediaType
|
||||||
import okhttp3.MediaType.Companion.toMediaTypeOrNull
|
import okhttp3.MediaType.Companion.toMediaTypeOrNull
|
||||||
import okhttp3.MultipartBody
|
import okhttp3.MultipartBody
|
||||||
|
import okhttp3.RequestBody
|
||||||
import okhttp3.RequestBody.Companion.asRequestBody
|
import okhttp3.RequestBody.Companion.asRequestBody
|
||||||
import okhttp3.RequestBody.Companion.toRequestBody
|
import okhttp3.RequestBody.Companion.toRequestBody
|
||||||
|
import retrofit2.http.Part
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
|
||||||
@@ -155,7 +160,7 @@ class AgentBackend {
|
|||||||
return if (authorId != null) {
|
return if (authorId != null) {
|
||||||
// getAgent 返回 DataContainer<ListContainer<Agent>>
|
// getAgent 返回 DataContainer<ListContainer<Agent>>
|
||||||
val dataContainer =
|
val dataContainer =
|
||||||
body as DataContainer<ListContainer<Agent>>
|
body as com.aiosman.ravenow.data.DataContainer<com.aiosman.ravenow.data.ListContainer<com.aiosman.ravenow.data.Agent>>
|
||||||
val listContainer = dataContainer.data
|
val listContainer = dataContainer.data
|
||||||
ListContainer(
|
ListContainer(
|
||||||
total = listContainer.total,
|
total = listContainer.total,
|
||||||
@@ -166,7 +171,7 @@ class AgentBackend {
|
|||||||
} else {
|
} else {
|
||||||
// getMyAgent 返回 ListContainer<Agent>
|
// getMyAgent 返回 ListContainer<Agent>
|
||||||
val listContainer =
|
val listContainer =
|
||||||
body as ListContainer<Agent>
|
body as com.aiosman.ravenow.data.ListContainer<com.aiosman.ravenow.data.Agent>
|
||||||
ListContainer(
|
ListContainer(
|
||||||
total = listContainer.total,
|
total = listContainer.total,
|
||||||
page = pageNumber,
|
page = pageNumber,
|
||||||
@@ -246,7 +251,7 @@ class AgentLoader : DataLoader<AgentEntity, AgentLoaderExtraArgs>() {
|
|||||||
} else {
|
} else {
|
||||||
// getMyAgent 返回 ListContainer<Agent>
|
// getMyAgent 返回 ListContainer<Agent>
|
||||||
val listContainer =
|
val listContainer =
|
||||||
body as ListContainer<Agent>
|
body as com.aiosman.ravenow.data.ListContainer<com.aiosman.ravenow.data.Agent>
|
||||||
ListContainer(
|
ListContainer(
|
||||||
list = listContainer.list.map { it.toAgentEntity() },
|
list = listContainer.list.map { it.toAgentEntity() },
|
||||||
total = listContainer.total,
|
total = listContainer.total,
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import com.aiosman.ravenow.data.ListContainer
|
|||||||
abstract class DataLoader<T,ET> {
|
abstract class DataLoader<T,ET> {
|
||||||
var list: MutableList<T> = mutableListOf()
|
var list: MutableList<T> = mutableListOf()
|
||||||
var page by mutableStateOf(1)
|
var page by mutableStateOf(1)
|
||||||
var total by mutableStateOf(0L)
|
var total by mutableStateOf(0)
|
||||||
var pageSize by mutableStateOf(10)
|
var pageSize by mutableStateOf(10)
|
||||||
var hasNext by mutableStateOf(true)
|
var hasNext by mutableStateOf(true)
|
||||||
var isLoading by mutableStateOf(false)
|
var isLoading by mutableStateOf(false)
|
||||||
|
|||||||
@@ -260,38 +260,6 @@ data class MomentImageEntity(
|
|||||||
var height: Int? = null
|
var height: Int? = null
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
|
||||||
* 动态视频
|
|
||||||
*/
|
|
||||||
data class MomentVideoEntity(
|
|
||||||
// 视频ID
|
|
||||||
val id: Long,
|
|
||||||
// 视频URL
|
|
||||||
val url: String,
|
|
||||||
// 原始文件名
|
|
||||||
val originalUrl: String? = null,
|
|
||||||
// 直接访问URL
|
|
||||||
val directUrl: String? = null,
|
|
||||||
// 视频缩略图URL
|
|
||||||
val thumbnailUrl: String? = null,
|
|
||||||
// 视频缩略图直接访问URL
|
|
||||||
val thumbnailDirectUrl: String? = null,
|
|
||||||
// 视频时长(秒)
|
|
||||||
val duration: Int? = null,
|
|
||||||
// 宽度
|
|
||||||
val width: Int? = null,
|
|
||||||
// 高度
|
|
||||||
val height: Int? = null,
|
|
||||||
// 文件大小(字节)
|
|
||||||
val size: Long? = null,
|
|
||||||
// 视频格式
|
|
||||||
val format: String? = null,
|
|
||||||
// 视频比特率(kbps)
|
|
||||||
val bitrate: Int? = null,
|
|
||||||
// 帧率
|
|
||||||
val frameRate: String? = null
|
|
||||||
)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 动态
|
* 动态
|
||||||
*/
|
*/
|
||||||
@@ -331,34 +299,12 @@ data class MomentEntity(
|
|||||||
// 关联动态
|
// 关联动态
|
||||||
var relMoment: MomentEntity? = null,
|
var relMoment: MomentEntity? = null,
|
||||||
// 是否收藏
|
// 是否收藏
|
||||||
var isFavorite: Boolean = false,
|
var isFavorite: Boolean = false
|
||||||
// 外部链接
|
|
||||||
val url: String? = null,
|
|
||||||
// 动态视频列表
|
|
||||||
val videos: List<MomentVideoEntity>? = null,
|
|
||||||
// 新闻相关字段
|
|
||||||
val isNews: Boolean = false,
|
|
||||||
val newsTitle: String = "",
|
|
||||||
val newsUrl: String = "",
|
|
||||||
val newsSource: String = "",
|
|
||||||
val newsCategory: String = "",
|
|
||||||
val newsLanguage: String = "",
|
|
||||||
val newsContent: String = "",
|
|
||||||
// 是否已获取完整正文
|
|
||||||
val hasFullText: Boolean = false,
|
|
||||||
// 新闻摘要
|
|
||||||
val summary: String? = null,
|
|
||||||
// 新闻发布时间
|
|
||||||
val publishedAt: String? = null,
|
|
||||||
// 是否已缓存图片
|
|
||||||
val imageCached: Boolean = false
|
|
||||||
)
|
)
|
||||||
class MomentLoaderExtraArgs(
|
class MomentLoaderExtraArgs(
|
||||||
val explore: Boolean? = false,
|
val explore: Boolean? = false,
|
||||||
val timelineId: Int? = null,
|
val timelineId: Int? = null,
|
||||||
val authorId : Int? = null,
|
val authorId : Int? = null
|
||||||
val newsOnly: Boolean? = null,
|
|
||||||
val videoOnly: Boolean? = null
|
|
||||||
)
|
)
|
||||||
class MomentLoader : DataLoader<MomentEntity,MomentLoaderExtraArgs>() {
|
class MomentLoader : DataLoader<MomentEntity,MomentLoaderExtraArgs>() {
|
||||||
override suspend fun fetchData(
|
override suspend fun fetchData(
|
||||||
@@ -371,9 +317,7 @@ class MomentLoader : DataLoader<MomentEntity,MomentLoaderExtraArgs>() {
|
|||||||
pageSize = pageSize,
|
pageSize = pageSize,
|
||||||
explore = if (extra.explore == true) "true" else "",
|
explore = if (extra.explore == true) "true" else "",
|
||||||
timelineId = extra.timelineId,
|
timelineId = extra.timelineId,
|
||||||
authorId = extra.authorId,
|
authorId = extra.authorId
|
||||||
newsFilter = if (extra.newsOnly == true) "news_only" else "",
|
|
||||||
videoFilter = if (extra.videoOnly == true) "video_only" else ""
|
|
||||||
)
|
)
|
||||||
val data = result.body()?.let {
|
val data = result.body()?.let {
|
||||||
ListContainer(
|
ListContainer(
|
||||||
@@ -411,18 +355,6 @@ class MomentLoader : DataLoader<MomentEntity,MomentLoaderExtraArgs>() {
|
|||||||
onListChanged?.invoke(this.list)
|
onListChanged?.invoke(this.list)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateCommentCount(id: Int, delta: Int) {
|
|
||||||
this.list = this.list.map { momentItem ->
|
|
||||||
if (momentItem.id == id) {
|
|
||||||
val newCount = (momentItem.commentCount + delta).coerceAtLeast(0)
|
|
||||||
momentItem.copy(commentCount = newCount)
|
|
||||||
} else {
|
|
||||||
momentItem
|
|
||||||
}
|
|
||||||
}.toMutableList()
|
|
||||||
onListChanged?.invoke(this.list)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun removeMoment(id: Int) {
|
fun removeMoment(id: Int) {
|
||||||
this.list = this.list.filter { it.id != id }.toMutableList()
|
this.list = this.list.filter { it.id != id }.toMutableList()
|
||||||
onListChanged?.invoke(this.list)
|
onListChanged?.invoke(this.list)
|
||||||
|
|||||||
@@ -3,6 +3,10 @@ package com.aiosman.ravenow.entity
|
|||||||
import com.aiosman.ravenow.data.ListContainer
|
import com.aiosman.ravenow.data.ListContainer
|
||||||
import com.aiosman.ravenow.data.ServiceException
|
import com.aiosman.ravenow.data.ServiceException
|
||||||
import com.aiosman.ravenow.data.api.ApiClient
|
import com.aiosman.ravenow.data.api.ApiClient
|
||||||
|
import okhttp3.MediaType.Companion.toMediaTypeOrNull
|
||||||
|
import okhttp3.MultipartBody
|
||||||
|
import okhttp3.RequestBody.Companion.asRequestBody
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 群聊房间
|
* 群聊房间
|
||||||
@@ -52,40 +56,6 @@ data class ProfileEntity(
|
|||||||
val aiAccount: Boolean,
|
val aiAccount: Boolean,
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
|
||||||
* 房间规则创建者信息
|
|
||||||
*/
|
|
||||||
data class RoomRuleCreatorEntity(
|
|
||||||
val id: Int,
|
|
||||||
val nickname: String,
|
|
||||||
val avatar: String
|
|
||||||
)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 房间规则详情
|
|
||||||
*/
|
|
||||||
data class RoomRuleEntity(
|
|
||||||
val id: Int,
|
|
||||||
val rule: String,
|
|
||||||
val creator: RoomRuleCreatorEntity?,
|
|
||||||
val creatorType: String,
|
|
||||||
val roomId: Int,
|
|
||||||
val createdAt: String,
|
|
||||||
val updatedAt: String
|
|
||||||
)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 房间规则配额信息
|
|
||||||
*/
|
|
||||||
data class RoomRuleQuotaEntity(
|
|
||||||
val baseMaxCount: Int,
|
|
||||||
val purchasedCount: Int,
|
|
||||||
val totalMaxCount: Int,
|
|
||||||
val currentCount: Int,
|
|
||||||
val remainingCount: Int,
|
|
||||||
val usagePercent: Double
|
|
||||||
)
|
|
||||||
|
|
||||||
class RoomLoader : DataLoader<AgentEntity,AgentLoaderExtraArgs>() {
|
class RoomLoader : DataLoader<AgentEntity,AgentLoaderExtraArgs>() {
|
||||||
override suspend fun fetchData(
|
override suspend fun fetchData(
|
||||||
page: Int,
|
page: Int,
|
||||||
|
|||||||
@@ -30,12 +30,6 @@ object AppStore {
|
|||||||
AppState.appTheme = DarkThemeColors()
|
AppState.appTheme = DarkThemeColors()
|
||||||
}
|
}
|
||||||
|
|
||||||
// load chat background
|
|
||||||
val savedBgUrl = sharedPreferences.getString("chatBackgroundUrl", null)
|
|
||||||
if (savedBgUrl != null) {
|
|
||||||
AppState.chatBackgroundUrl = savedBgUrl
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun saveData() {
|
suspend fun saveData() {
|
||||||
@@ -60,40 +54,5 @@ object AppStore {
|
|||||||
}.apply()
|
}.apply()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun saveChatBackgroundUrl(url: String?) {
|
|
||||||
sharedPreferences.edit().apply {
|
|
||||||
if (url != null) {
|
|
||||||
putString("chatBackgroundUrl", url)
|
|
||||||
} else {
|
|
||||||
remove("chatBackgroundUrl")
|
|
||||||
}
|
|
||||||
}.apply()
|
|
||||||
AppState.chatBackgroundUrl = url
|
|
||||||
}
|
|
||||||
|
|
||||||
// ===================== 用户本地扩展信息 =====================
|
|
||||||
// 后端暂未提供 MBTI 与星座字段,使用本地持久化按用户维度进行存储
|
|
||||||
private fun mbtiKey(userId: Int) = "mbti_user_$userId"
|
|
||||||
private fun zodiacKey(userId: Int) = "zodiac_user_$userId"
|
|
||||||
|
|
||||||
fun getUserMbti(userId: Int): String? {
|
|
||||||
return sharedPreferences.getString(mbtiKey(userId), null)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun setUserMbti(userId: Int, mbti: String?) {
|
|
||||||
sharedPreferences.edit().apply {
|
|
||||||
if (mbti.isNullOrEmpty()) remove(mbtiKey(userId)) else putString(mbtiKey(userId), mbti)
|
|
||||||
}.apply()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getUserZodiac(userId: Int): String? {
|
|
||||||
return sharedPreferences.getString(zodiacKey(userId), null)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun setUserZodiac(userId: Int, zodiac: String?) {
|
|
||||||
sharedPreferences.edit().apply {
|
|
||||||
if (zodiac.isNullOrEmpty()) remove(zodiacKey(userId)) else putString(zodiacKey(userId), zodiac)
|
|
||||||
}.apply()
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -35,15 +35,12 @@ import com.aiosman.ravenow.LocalSharedTransitionScope
|
|||||||
import com.aiosman.ravenow.ui.about.AboutScreen
|
import com.aiosman.ravenow.ui.about.AboutScreen
|
||||||
import com.aiosman.ravenow.ui.account.AccountEditScreen2
|
import com.aiosman.ravenow.ui.account.AccountEditScreen2
|
||||||
import com.aiosman.ravenow.ui.account.AccountSetting
|
import com.aiosman.ravenow.ui.account.AccountSetting
|
||||||
import com.aiosman.ravenow.ui.account.MbtiSelectScreen
|
|
||||||
import com.aiosman.ravenow.ui.account.RemoveAccountScreen
|
import com.aiosman.ravenow.ui.account.RemoveAccountScreen
|
||||||
import com.aiosman.ravenow.ui.account.ResetPasswordScreen
|
import com.aiosman.ravenow.ui.account.ResetPasswordScreen
|
||||||
import com.aiosman.ravenow.ui.account.ZodiacSelectScreen
|
|
||||||
import com.aiosman.ravenow.ui.agent.AddAgentScreen
|
import com.aiosman.ravenow.ui.agent.AddAgentScreen
|
||||||
import com.aiosman.ravenow.ui.agent.AgentImageCropScreen
|
import com.aiosman.ravenow.ui.agent.AgentImageCropScreen
|
||||||
import com.aiosman.ravenow.ui.group.CreateGroupChatScreen
|
import com.aiosman.ravenow.ui.group.CreateGroupChatScreen
|
||||||
import com.aiosman.ravenow.ui.chat.ChatAiScreen
|
import com.aiosman.ravenow.ui.chat.ChatAiScreen
|
||||||
import com.aiosman.ravenow.ui.chat.ChatSettingScreen
|
|
||||||
import com.aiosman.ravenow.ui.chat.ChatScreen
|
import com.aiosman.ravenow.ui.chat.ChatScreen
|
||||||
import com.aiosman.ravenow.ui.chat.GroupChatScreen
|
import com.aiosman.ravenow.ui.chat.GroupChatScreen
|
||||||
import com.aiosman.ravenow.ui.comment.CommentsScreen
|
import com.aiosman.ravenow.ui.comment.CommentsScreen
|
||||||
@@ -109,7 +106,6 @@ sealed class NavigationRoute(
|
|||||||
data object FavouriteList : NavigationRoute("FavouriteList")
|
data object FavouriteList : NavigationRoute("FavouriteList")
|
||||||
data object Chat : NavigationRoute("Chat/{id}")
|
data object Chat : NavigationRoute("Chat/{id}")
|
||||||
data object ChatAi : NavigationRoute("ChatAi/{id}")
|
data object ChatAi : NavigationRoute("ChatAi/{id}")
|
||||||
data object ChatSetting : NavigationRoute("ChatSetting")
|
|
||||||
data object ChatGroup : NavigationRoute("ChatGroup/{id}/{name}/{avatar}")
|
data object ChatGroup : NavigationRoute("ChatGroup/{id}/{name}/{avatar}")
|
||||||
data object CommentNoticeScreen : NavigationRoute("CommentNoticeScreen")
|
data object CommentNoticeScreen : NavigationRoute("CommentNoticeScreen")
|
||||||
data object ImageCrop : NavigationRoute("ImageCrop")
|
data object ImageCrop : NavigationRoute("ImageCrop")
|
||||||
@@ -122,8 +118,6 @@ sealed class NavigationRoute(
|
|||||||
data object VipSelPage : NavigationRoute("VipSelPage")
|
data object VipSelPage : NavigationRoute("VipSelPage")
|
||||||
data object RemoveAccountScreen: NavigationRoute("RemoveAccount")
|
data object RemoveAccountScreen: NavigationRoute("RemoveAccount")
|
||||||
data object NotificationScreen : NavigationRoute("NotificationScreen")
|
data object NotificationScreen : NavigationRoute("NotificationScreen")
|
||||||
data object MbtiSelect : NavigationRoute("MbtiSelect")
|
|
||||||
data object ZodiacSelect : NavigationRoute("ZodiacSelect")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -425,12 +419,6 @@ fun NavigationController(
|
|||||||
composable(route = NavigationRoute.RemoveAccountScreen.route) {
|
composable(route = NavigationRoute.RemoveAccountScreen.route) {
|
||||||
RemoveAccountScreen()
|
RemoveAccountScreen()
|
||||||
}
|
}
|
||||||
composable(route = NavigationRoute.MbtiSelect.route) {
|
|
||||||
MbtiSelectScreen()
|
|
||||||
}
|
|
||||||
composable(route = NavigationRoute.ZodiacSelect.route) {
|
|
||||||
ZodiacSelectScreen()
|
|
||||||
}
|
|
||||||
composable(route = NavigationRoute.VipSelPage.route) {
|
composable(route = NavigationRoute.VipSelPage.route) {
|
||||||
VipSelPage()
|
VipSelPage()
|
||||||
}
|
}
|
||||||
@@ -503,14 +491,6 @@ fun NavigationController(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
composable(route = NavigationRoute.ChatSetting.route) {
|
|
||||||
CompositionLocalProvider(
|
|
||||||
LocalAnimatedContentScope provides this,
|
|
||||||
) {
|
|
||||||
ChatSettingScreen()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
composable(
|
composable(
|
||||||
route = NavigationRoute.ChatGroup.route,
|
route = NavigationRoute.ChatGroup.route,
|
||||||
arguments = listOf(navArgument("id") { type = NavType.StringType },
|
arguments = listOf(navArgument("id") { type = NavType.StringType },
|
||||||
|
|||||||
@@ -21,16 +21,11 @@ object AccountEditViewModel : ViewModel() {
|
|||||||
var name by mutableStateOf("")
|
var name by mutableStateOf("")
|
||||||
var bio by mutableStateOf("")
|
var bio by mutableStateOf("")
|
||||||
var imageUrl by mutableStateOf<Uri?>(null)
|
var imageUrl by mutableStateOf<Uri?>(null)
|
||||||
var bannerImageUrl by mutableStateOf<Uri?>(null)
|
|
||||||
var bannerFile by mutableStateOf<File?>(null)
|
|
||||||
val accountService: AccountService = AccountServiceImpl()
|
val accountService: AccountService = AccountServiceImpl()
|
||||||
var profile by mutableStateOf<AccountProfileEntity?>(null)
|
var profile by mutableStateOf<AccountProfileEntity?>(null)
|
||||||
var croppedBitmap by mutableStateOf<Bitmap?>(null)
|
var croppedBitmap by mutableStateOf<Bitmap?>(null)
|
||||||
var isUpdating by mutableStateOf(false)
|
var isUpdating by mutableStateOf(false)
|
||||||
var isLoading by mutableStateOf(false)
|
var isLoading by mutableStateOf(false)
|
||||||
// 本地扩展字段
|
|
||||||
var mbti by mutableStateOf<String?>(null)
|
|
||||||
var zodiac by mutableStateOf<String?>(null)
|
|
||||||
suspend fun reloadProfile(updateTrtcProfile:Boolean = false) {
|
suspend fun reloadProfile(updateTrtcProfile:Boolean = false) {
|
||||||
Log.d("AccountEditViewModel", "reloadProfile: 开始加载用户资料")
|
Log.d("AccountEditViewModel", "reloadProfile: 开始加载用户资料")
|
||||||
isLoading = true
|
isLoading = true
|
||||||
@@ -43,12 +38,6 @@ object AccountEditViewModel : ViewModel() {
|
|||||||
bio = it.bio
|
bio = it.bio
|
||||||
// 清除之前裁剪的图片
|
// 清除之前裁剪的图片
|
||||||
croppedBitmap = null
|
croppedBitmap = null
|
||||||
// 读取本地扩展字段
|
|
||||||
try {
|
|
||||||
val uid = it.id // 使用 profile 的 id,确保非空
|
|
||||||
mbti = com.aiosman.ravenow.AppStore.getUserMbti(uid)
|
|
||||||
zodiac = com.aiosman.ravenow.AppStore.getUserZodiac(uid)
|
|
||||||
} catch (_: Exception) { }
|
|
||||||
if (updateTrtcProfile) {
|
if (updateTrtcProfile) {
|
||||||
TrtcHelper.updateTrtcProfile(
|
TrtcHelper.updateTrtcProfile(
|
||||||
it.nickName,
|
it.nickName,
|
||||||
@@ -84,30 +73,6 @@ object AccountEditViewModel : ViewModel() {
|
|||||||
it.compress(Bitmap.CompressFormat.JPEG, 100, file.outputStream())
|
it.compress(Bitmap.CompressFormat.JPEG, 100, file.outputStream())
|
||||||
UploadImage(file, "avatar.jpg", "", "jpg")
|
UploadImage(file, "avatar.jpg", "", "jpg")
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理背景图更新
|
|
||||||
val newBanner = bannerImageUrl?.let { uri ->
|
|
||||||
bannerFile?.let { file ->
|
|
||||||
val cursor = context.contentResolver.query(uri, null, null, null, null)
|
|
||||||
var uploadBanner: UploadImage? = null
|
|
||||||
cursor?.use { cur ->
|
|
||||||
val columnIndex = cur.getColumnIndex("_display_name")
|
|
||||||
if (cur.moveToFirst() && columnIndex != -1) {
|
|
||||||
val displayName = cur.getString(columnIndex)
|
|
||||||
val extension = displayName.substringAfterLast(".")
|
|
||||||
Log.d("AccountEditViewModel", "Banner file name: $displayName, extension: $extension")
|
|
||||||
uploadBanner = UploadImage(file, displayName, uri.toString(), extension)
|
|
||||||
} else {
|
|
||||||
// 如果无法获取文件名,使用默认值
|
|
||||||
val displayName = "banner.jpg"
|
|
||||||
val extension = "jpg"
|
|
||||||
uploadBanner = UploadImage(file, displayName, uri.toString(), extension)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
uploadBanner
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 去除换行符,确保昵称和个人简介不包含换行
|
// 去除换行符,确保昵称和个人简介不包含换行
|
||||||
val cleanName = name.trim().replace("\n", "").replace("\r", "")
|
val cleanName = name.trim().replace("\n", "").replace("\r", "")
|
||||||
val cleanBio = bio.trim().replace("\n", "").replace("\r", "")
|
val cleanBio = bio.trim().replace("\n", "").replace("\r", "")
|
||||||
@@ -115,20 +80,10 @@ object AccountEditViewModel : ViewModel() {
|
|||||||
val newName = if (cleanName == profile?.nickName) null else cleanName
|
val newName = if (cleanName == profile?.nickName) null else cleanName
|
||||||
accountService.updateProfile(
|
accountService.updateProfile(
|
||||||
avatar = newAvatar,
|
avatar = newAvatar,
|
||||||
banner = newBanner,
|
banner = null,
|
||||||
nickName = newName,
|
nickName = newName,
|
||||||
bio = cleanBio
|
bio = cleanBio
|
||||||
)
|
)
|
||||||
// 保存本地扩展字段
|
|
||||||
try {
|
|
||||||
profile?.id?.let { uid ->
|
|
||||||
com.aiosman.ravenow.AppStore.setUserMbti(uid, mbti)
|
|
||||||
com.aiosman.ravenow.AppStore.setUserZodiac(uid, zodiac)
|
|
||||||
}
|
|
||||||
} catch (_: Exception) { }
|
|
||||||
// 清除背景图状态
|
|
||||||
bannerImageUrl = null
|
|
||||||
bannerFile = null
|
|
||||||
// 刷新用户资料
|
// 刷新用户资料
|
||||||
reloadProfile()
|
reloadProfile()
|
||||||
// 刷新个人资料页面的用户资料
|
// 刷新个人资料页面的用户资料
|
||||||
@@ -145,8 +100,6 @@ object AccountEditViewModel : ViewModel() {
|
|||||||
name = ""
|
name = ""
|
||||||
bio = ""
|
bio = ""
|
||||||
imageUrl = null
|
imageUrl = null
|
||||||
bannerImageUrl = null
|
|
||||||
bannerFile = null
|
|
||||||
croppedBitmap = null
|
croppedBitmap = null
|
||||||
isUpdating = false
|
isUpdating = false
|
||||||
isLoading = false
|
isLoading = false
|
||||||
|
|||||||
@@ -1,177 +1,117 @@
|
|||||||
package com.aiosman.ravenow.ui.account
|
package com.aiosman.ravenow.ui.account
|
||||||
|
|
||||||
import androidx.compose.foundation.Image
|
import android.widget.Toast
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Spacer
|
||||||
|
import androidx.compose.foundation.layout.WindowInsets
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.height
|
import androidx.compose.foundation.layout.height
|
||||||
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.shape.CircleShape
|
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
|
import androidx.compose.foundation.text.BasicTextField
|
||||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
|
import androidx.compose.material3.ModalBottomSheet
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.material3.rememberModalBottomSheetState
|
||||||
|
import androidx.compose.ui.graphics.SolidColor
|
||||||
|
import androidx.compose.ui.text.TextStyle
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
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.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.ColorFilter
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.res.painterResource
|
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
|
import androidx.compose.ui.text.style.TextAlign
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
|
import com.aiosman.ravenow.AppState
|
||||||
|
import com.aiosman.ravenow.AppStore
|
||||||
import com.aiosman.ravenow.LocalAppTheme
|
import com.aiosman.ravenow.LocalAppTheme
|
||||||
import com.aiosman.ravenow.LocalNavController
|
import com.aiosman.ravenow.LocalNavController
|
||||||
|
import com.aiosman.ravenow.Messaging
|
||||||
import com.aiosman.ravenow.R
|
import com.aiosman.ravenow.R
|
||||||
|
import com.aiosman.ravenow.data.AccountServiceImpl
|
||||||
import com.aiosman.ravenow.ui.NavigationRoute
|
import com.aiosman.ravenow.ui.NavigationRoute
|
||||||
|
import com.aiosman.ravenow.ui.comment.NoticeScreenHeader
|
||||||
|
import com.aiosman.ravenow.ui.composables.ActionButton
|
||||||
import com.aiosman.ravenow.ui.composables.StatusBarSpacer
|
import com.aiosman.ravenow.ui.composables.StatusBarSpacer
|
||||||
|
import com.aiosman.ravenow.ui.index.NavItem
|
||||||
import com.aiosman.ravenow.ui.modifiers.noRippleClickable
|
import com.aiosman.ravenow.ui.modifiers.noRippleClickable
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
private object AccountSettingConstants {
|
|
||||||
const val BACK_BUTTON_SIZE = 36
|
|
||||||
const val BACK_BUTTON_ICON_SIZE = 24
|
|
||||||
const val BACK_BUTTON_START_PADDING = 19
|
|
||||||
const val OPTION_ITEM_HEIGHT = 56
|
|
||||||
const val OPTION_ITEM_ICON_SIZE = 24
|
|
||||||
const val OPTION_ITEM_HORIZONTAL_PADDING = 16
|
|
||||||
const val OPTION_ITEM_ICON_TEXT_SPACING = 12
|
|
||||||
const val OPTION_ITEM_TEXT_SIZE = 17
|
|
||||||
const val HEADER_VERTICAL_PADDING = 16
|
|
||||||
const val TITLE_OFFSET_X = 19
|
|
||||||
const val CARD_CORNER_RADIUS = 16
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
private fun CircularBackButton(
|
|
||||||
onClick: () -> Unit,
|
|
||||||
modifier: Modifier = Modifier
|
|
||||||
) {
|
|
||||||
val appColors = LocalAppTheme.current
|
|
||||||
Box(
|
|
||||||
modifier = modifier
|
|
||||||
.size(AccountSettingConstants.BACK_BUTTON_SIZE.dp)
|
|
||||||
.background(
|
|
||||||
color = appColors.secondaryBackground,
|
|
||||||
shape = CircleShape
|
|
||||||
)
|
|
||||||
.noRippleClickable { onClick() },
|
|
||||||
contentAlignment = Alignment.Center
|
|
||||||
) {
|
|
||||||
Image(
|
|
||||||
painter = painterResource(id = R.drawable.rider_pro_back_icon),
|
|
||||||
contentDescription = "返回",
|
|
||||||
modifier = Modifier.size(AccountSettingConstants.BACK_BUTTON_ICON_SIZE.dp),
|
|
||||||
colorFilter = ColorFilter.tint(appColors.text)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
private fun SecurityOptionItem(
|
|
||||||
iconRes: Int,
|
|
||||||
label: String,
|
|
||||||
onClick: () -> Unit,
|
|
||||||
applyColorFilter: Boolean = true
|
|
||||||
) {
|
|
||||||
val appColors = LocalAppTheme.current
|
|
||||||
Row(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.height(AccountSettingConstants.OPTION_ITEM_HEIGHT.dp)
|
|
||||||
.padding(horizontal = AccountSettingConstants.OPTION_ITEM_HORIZONTAL_PADDING.dp)
|
|
||||||
.noRippleClickable { onClick() },
|
|
||||||
verticalAlignment = Alignment.CenterVertically
|
|
||||||
) {
|
|
||||||
Image(
|
|
||||||
painter = painterResource(id = iconRes),
|
|
||||||
contentDescription = null,
|
|
||||||
modifier = Modifier.size(AccountSettingConstants.OPTION_ITEM_ICON_SIZE.dp),
|
|
||||||
colorFilter = if (applyColorFilter) ColorFilter.tint(appColors.text) else null
|
|
||||||
)
|
|
||||||
Text(
|
|
||||||
text = label,
|
|
||||||
modifier = Modifier
|
|
||||||
.padding(start = AccountSettingConstants.OPTION_ITEM_ICON_TEXT_SPACING.dp)
|
|
||||||
.weight(1f),
|
|
||||||
color = appColors.text,
|
|
||||||
fontSize = AccountSettingConstants.OPTION_ITEM_TEXT_SIZE.sp,
|
|
||||||
fontWeight = FontWeight.Medium
|
|
||||||
)
|
|
||||||
Image(
|
|
||||||
painter = painterResource(id = R.drawable.rave_now_nav_right),
|
|
||||||
contentDescription = null,
|
|
||||||
modifier = Modifier.size(AccountSettingConstants.OPTION_ITEM_ICON_SIZE.dp),
|
|
||||||
colorFilter = ColorFilter.tint(appColors.secondaryText)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun AccountSetting() {
|
fun AccountSetting() {
|
||||||
val appColors = LocalAppTheme.current
|
val appColors = LocalAppTheme.current
|
||||||
val navController = LocalNavController.current
|
val navController = LocalNavController.current
|
||||||
|
val scope = rememberCoroutineScope()
|
||||||
|
val context = LocalContext.current
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
.background(appColors.background),
|
.background(appColors.background),
|
||||||
) {
|
) {
|
||||||
StatusBarSpacer()
|
StatusBarSpacer()
|
||||||
|
|
||||||
// 顶部标题栏
|
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier
|
modifier = Modifier.padding(horizontal = 24.dp, vertical = 16.dp)
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(vertical = AccountSettingConstants.HEADER_VERTICAL_PADDING.dp)
|
|
||||||
) {
|
) {
|
||||||
CircularBackButton(
|
NoticeScreenHeader(
|
||||||
onClick = { navController.navigateUp() },
|
title = stringResource(R.string.account_and_security),
|
||||||
modifier = Modifier.padding(start = AccountSettingConstants.BACK_BUTTON_START_PADDING.dp)
|
moreIcon = false
|
||||||
)
|
|
||||||
Text(
|
|
||||||
text = stringResource(R.string.account_and_security),
|
|
||||||
fontWeight = FontWeight.W800,
|
|
||||||
fontSize = AccountSettingConstants.OPTION_ITEM_TEXT_SIZE.sp,
|
|
||||||
color = appColors.text,
|
|
||||||
modifier = Modifier
|
|
||||||
.align(Alignment.Center)
|
|
||||||
.offset(x = AccountSettingConstants.TITLE_OFFSET_X.dp)
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 安全选项卡片
|
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier
|
modifier = Modifier.padding(start = 24.dp)
|
||||||
.fillMaxWidth()
|
|
||||||
.background(
|
|
||||||
color = appColors.background,
|
|
||||||
shape = RoundedCornerShape(AccountSettingConstants.CARD_CORNER_RADIUS.dp)
|
|
||||||
)
|
|
||||||
) {
|
) {
|
||||||
SecurityOptionItem(
|
Box(
|
||||||
iconRes = R.mipmap.icons_padlock,
|
modifier = Modifier
|
||||||
label = stringResource(R.string.change_password),
|
.fillMaxWidth()
|
||||||
onClick = { navController.navigate(NavigationRoute.ChangePasswordScreen.route) }
|
.padding(vertical = 8.dp)
|
||||||
)
|
) {
|
||||||
|
NavItem(
|
||||||
|
iconRes = R.mipmap.rider_pro_change_password,
|
||||||
|
label = stringResource(R.string.change_password),
|
||||||
|
modifier = Modifier.noRippleClickable {
|
||||||
|
navController.navigate(NavigationRoute.ChangePasswordScreen.route)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
SecurityOptionItem(
|
// 分割线
|
||||||
iconRes = R.mipmap.icons_block,
|
Box(
|
||||||
label = stringResource(R.string.blocked_users),
|
modifier = Modifier
|
||||||
onClick = {
|
.fillMaxWidth()
|
||||||
// TODO: 导航到屏蔽用户页面
|
.height(1.dp)
|
||||||
}
|
.background(appColors.divider)
|
||||||
)
|
)
|
||||||
|
Box(
|
||||||
SecurityOptionItem(
|
modifier = Modifier
|
||||||
iconRes = R.mipmap.icons_remove,
|
.fillMaxWidth()
|
||||||
label = stringResource(R.string.remove_account),
|
.padding(vertical = 8.dp)
|
||||||
onClick = { navController.navigate(NavigationRoute.RemoveAccountScreen.route) },
|
) {
|
||||||
applyColorFilter = false
|
NavItem(
|
||||||
|
iconRes = R.drawable.rider_pro_moment_delete,
|
||||||
|
label = stringResource(R.string.remove_account),
|
||||||
|
modifier = Modifier.noRippleClickable {
|
||||||
|
navController.navigate(NavigationRoute.RemoveAccountScreen.route)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.height(1.dp)
|
||||||
|
.background(appColors.divider)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,141 +0,0 @@
|
|||||||
package com.aiosman.ravenow.ui.account
|
|
||||||
|
|
||||||
import androidx.compose.foundation.background
|
|
||||||
import androidx.compose.foundation.clickable
|
|
||||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
|
||||||
import androidx.compose.foundation.layout.Box
|
|
||||||
import androidx.compose.foundation.layout.Column
|
|
||||||
import androidx.compose.foundation.layout.Row
|
|
||||||
import androidx.compose.foundation.layout.Spacer
|
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
|
||||||
import androidx.compose.foundation.layout.height
|
|
||||||
import androidx.compose.foundation.layout.padding
|
|
||||||
import androidx.compose.foundation.layout.size
|
|
||||||
import androidx.compose.foundation.layout.width
|
|
||||||
import androidx.compose.foundation.lazy.LazyColumn
|
|
||||||
import androidx.compose.foundation.lazy.items
|
|
||||||
import androidx.compose.foundation.shape.CircleShape
|
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
||||||
import androidx.compose.material3.Icon
|
|
||||||
import androidx.compose.material3.Text
|
|
||||||
import androidx.compose.runtime.Composable
|
|
||||||
import androidx.compose.runtime.remember
|
|
||||||
import androidx.compose.ui.Alignment
|
|
||||||
import androidx.compose.ui.Modifier
|
|
||||||
import androidx.compose.ui.draw.clip
|
|
||||||
import androidx.compose.ui.graphics.Color
|
|
||||||
import androidx.compose.ui.graphics.ColorFilter
|
|
||||||
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.material.icons.Icons
|
|
||||||
import androidx.compose.material.icons.filled.Check
|
|
||||||
import com.aiosman.ravenow.AppState
|
|
||||||
import com.aiosman.ravenow.LocalAppTheme
|
|
||||||
import com.aiosman.ravenow.LocalNavController
|
|
||||||
import com.aiosman.ravenow.R
|
|
||||||
import com.aiosman.ravenow.ui.comment.NoticeScreenHeader
|
|
||||||
|
|
||||||
// MBTI类型列表
|
|
||||||
val MBTI_TYPES = listOf(
|
|
||||||
"INTJ", "INTP", "ENTJ", "ENTP",
|
|
||||||
"INFJ", "INFP", "ENFJ", "ENFP",
|
|
||||||
"ISTJ", "ISFJ", "ESTJ", "ESFJ",
|
|
||||||
"ISTP", "ISFP", "ESTP", "ESFP"
|
|
||||||
)
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun MbtiSelectScreen() {
|
|
||||||
val navController = LocalNavController.current
|
|
||||||
val appColors = LocalAppTheme.current
|
|
||||||
val model = AccountEditViewModel
|
|
||||||
val currentMbti = model.mbti
|
|
||||||
|
|
||||||
Column(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxSize()
|
|
||||||
.background(appColors.profileBackground)
|
|
||||||
) {
|
|
||||||
// 头部
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(vertical = 16.dp)
|
|
||||||
) {
|
|
||||||
NoticeScreenHeader(
|
|
||||||
title = stringResource(R.string.choose_mbti),
|
|
||||||
moreIcon = false
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 列表
|
|
||||||
LazyColumn(
|
|
||||||
modifier = Modifier.fillMaxSize(),
|
|
||||||
contentPadding = androidx.compose.foundation.layout.PaddingValues(horizontal = 16.dp, vertical = 8.dp)
|
|
||||||
) {
|
|
||||||
items(MBTI_TYPES) { mbti ->
|
|
||||||
MBTIItem(
|
|
||||||
mbti = mbti,
|
|
||||||
isSelected = mbti == currentMbti,
|
|
||||||
onClick = {
|
|
||||||
model.mbti = mbti
|
|
||||||
// 立即保存到本地存储,确保选择后立即生效
|
|
||||||
AppState.UserId?.let { uid ->
|
|
||||||
com.aiosman.ravenow.AppStore.setUserMbti(uid, mbti)
|
|
||||||
}
|
|
||||||
navController.navigateUp()
|
|
||||||
}
|
|
||||||
)
|
|
||||||
Spacer(modifier = Modifier.height(8.dp))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun MBTIItem(
|
|
||||||
mbti: String,
|
|
||||||
isSelected: Boolean,
|
|
||||||
onClick: () -> Unit
|
|
||||||
) {
|
|
||||||
val appColors = LocalAppTheme.current
|
|
||||||
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.clip(RoundedCornerShape(16.dp))
|
|
||||||
.background(if (isSelected) appColors.main.copy(alpha = 0.1f) else Color.White)
|
|
||||||
.clickable(
|
|
||||||
indication = null,
|
|
||||||
interactionSource = remember { MutableInteractionSource() }
|
|
||||||
) {
|
|
||||||
onClick()
|
|
||||||
}
|
|
||||||
.padding(16.dp)
|
|
||||||
) {
|
|
||||||
Row(
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
|
||||||
verticalAlignment = Alignment.CenterVertically
|
|
||||||
) {
|
|
||||||
Text(
|
|
||||||
text = mbti,
|
|
||||||
fontSize = 17.sp,
|
|
||||||
fontWeight = FontWeight.Normal,
|
|
||||||
color = if (isSelected) appColors.main else appColors.text,
|
|
||||||
modifier = Modifier.weight(1f)
|
|
||||||
)
|
|
||||||
|
|
||||||
if (isSelected) {
|
|
||||||
Icon(
|
|
||||||
imageVector = Icons.Default.Check,
|
|
||||||
contentDescription = "Selected",
|
|
||||||
modifier = Modifier.size(20.dp),
|
|
||||||
tint = appColors.main
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,172 +0,0 @@
|
|||||||
package com.aiosman.ravenow.ui.account
|
|
||||||
|
|
||||||
import androidx.compose.foundation.background
|
|
||||||
import androidx.compose.foundation.clickable
|
|
||||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
|
||||||
import androidx.compose.foundation.layout.Box
|
|
||||||
import androidx.compose.foundation.layout.Column
|
|
||||||
import androidx.compose.foundation.layout.Row
|
|
||||||
import androidx.compose.foundation.layout.Spacer
|
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
|
||||||
import androidx.compose.foundation.layout.height
|
|
||||||
import androidx.compose.foundation.layout.padding
|
|
||||||
import androidx.compose.foundation.layout.size
|
|
||||||
import androidx.compose.foundation.lazy.LazyColumn
|
|
||||||
import androidx.compose.foundation.lazy.items
|
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
||||||
import androidx.compose.material3.Icon
|
|
||||||
import androidx.compose.material3.Text
|
|
||||||
import androidx.compose.runtime.Composable
|
|
||||||
import androidx.compose.runtime.remember
|
|
||||||
import androidx.compose.ui.Alignment
|
|
||||||
import androidx.compose.ui.Modifier
|
|
||||||
import androidx.compose.ui.draw.clip
|
|
||||||
import androidx.compose.ui.graphics.Color
|
|
||||||
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.material.icons.Icons
|
|
||||||
import androidx.compose.material.icons.filled.Check
|
|
||||||
import com.aiosman.ravenow.AppState
|
|
||||||
import com.aiosman.ravenow.LocalAppTheme
|
|
||||||
import com.aiosman.ravenow.LocalNavController
|
|
||||||
import com.aiosman.ravenow.R
|
|
||||||
import com.aiosman.ravenow.ui.comment.NoticeScreenHeader
|
|
||||||
|
|
||||||
// 星座资源ID列表
|
|
||||||
val ZODIAC_SIGN_RES_IDS = listOf(
|
|
||||||
R.string.zodiac_aries,
|
|
||||||
R.string.zodiac_taurus,
|
|
||||||
R.string.zodiac_gemini,
|
|
||||||
R.string.zodiac_cancer,
|
|
||||||
R.string.zodiac_leo,
|
|
||||||
R.string.zodiac_virgo,
|
|
||||||
R.string.zodiac_libra,
|
|
||||||
R.string.zodiac_scorpio,
|
|
||||||
R.string.zodiac_sagittarius,
|
|
||||||
R.string.zodiac_capricorn,
|
|
||||||
R.string.zodiac_aquarius,
|
|
||||||
R.string.zodiac_pisces
|
|
||||||
)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据存储的星座字符串(可能是任何语言)找到对应的资源ID
|
|
||||||
* 如果找不到,返回null
|
|
||||||
*/
|
|
||||||
@Composable
|
|
||||||
fun findZodiacResId(storedZodiac: String?): Int? {
|
|
||||||
if (storedZodiac.isNullOrEmpty()) return null
|
|
||||||
|
|
||||||
// 尝试在所有语言的资源中查找匹配
|
|
||||||
ZODIAC_SIGN_RES_IDS.forEachIndexed { index, resId ->
|
|
||||||
val zodiacText = stringResource(resId)
|
|
||||||
if (zodiacText == storedZodiac) {
|
|
||||||
return resId
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 如果找不到精确匹配,尝试通过资源ID索引查找(兼容旧数据)
|
|
||||||
// 这里可以根据需要添加更多兼容逻辑
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun ZodiacSelectScreen() {
|
|
||||||
val navController = LocalNavController.current
|
|
||||||
val appColors = LocalAppTheme.current
|
|
||||||
val model = AccountEditViewModel
|
|
||||||
val currentZodiacResId = findZodiacResId(model.zodiac)
|
|
||||||
|
|
||||||
Column(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxSize()
|
|
||||||
.background(appColors.profileBackground)
|
|
||||||
) {
|
|
||||||
// 头部
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(vertical = 16.dp)
|
|
||||||
) {
|
|
||||||
NoticeScreenHeader(
|
|
||||||
title = stringResource(R.string.choose_zodiac),
|
|
||||||
moreIcon = false
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 列表
|
|
||||||
LazyColumn(
|
|
||||||
modifier = Modifier.fillMaxSize(),
|
|
||||||
contentPadding = androidx.compose.foundation.layout.PaddingValues(horizontal = 16.dp, vertical = 8.dp)
|
|
||||||
) {
|
|
||||||
items(ZODIAC_SIGN_RES_IDS.size) { index ->
|
|
||||||
val zodiacResId = ZODIAC_SIGN_RES_IDS[index]
|
|
||||||
val zodiacText = stringResource(zodiacResId)
|
|
||||||
ZodiacItem(
|
|
||||||
zodiac = zodiacText,
|
|
||||||
zodiacResId = zodiacResId,
|
|
||||||
isSelected = zodiacResId == currentZodiacResId,
|
|
||||||
onClick = {
|
|
||||||
// 保存当前语言的星座文本
|
|
||||||
model.zodiac = zodiacText
|
|
||||||
// 立即保存到本地存储,确保选择后立即生效
|
|
||||||
AppState.UserId?.let { uid ->
|
|
||||||
com.aiosman.ravenow.AppStore.setUserZodiac(uid, zodiacText)
|
|
||||||
}
|
|
||||||
navController.navigateUp()
|
|
||||||
}
|
|
||||||
)
|
|
||||||
Spacer(modifier = Modifier.height(8.dp))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun ZodiacItem(
|
|
||||||
zodiac: String,
|
|
||||||
zodiacResId: Int,
|
|
||||||
isSelected: Boolean,
|
|
||||||
onClick: () -> Unit
|
|
||||||
) {
|
|
||||||
val appColors = LocalAppTheme.current
|
|
||||||
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.clip(RoundedCornerShape(16.dp))
|
|
||||||
.background(if (isSelected) appColors.main.copy(alpha = 0.1f) else Color.White)
|
|
||||||
.clickable(
|
|
||||||
indication = null,
|
|
||||||
interactionSource = remember { MutableInteractionSource() }
|
|
||||||
) {
|
|
||||||
onClick()
|
|
||||||
}
|
|
||||||
.padding(16.dp)
|
|
||||||
) {
|
|
||||||
Row(
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
|
||||||
verticalAlignment = Alignment.CenterVertically
|
|
||||||
) {
|
|
||||||
Text(
|
|
||||||
text = zodiac,
|
|
||||||
fontSize = 17.sp,
|
|
||||||
fontWeight = FontWeight.Normal,
|
|
||||||
color = if (isSelected) appColors.main else appColors.text,
|
|
||||||
modifier = Modifier.weight(1f)
|
|
||||||
)
|
|
||||||
|
|
||||||
if (isSelected) {
|
|
||||||
Icon(
|
|
||||||
imageVector = Icons.Default.Check,
|
|
||||||
contentDescription = "Selected",
|
|
||||||
modifier = Modifier.size(20.dp),
|
|
||||||
tint = appColors.main
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -4,26 +4,19 @@ import android.content.Context
|
|||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.border
|
|
||||||
import androidx.compose.foundation.clickable
|
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.Row
|
|
||||||
import androidx.compose.foundation.layout.Spacer
|
import androidx.compose.foundation.layout.Spacer
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.height
|
import androidx.compose.foundation.layout.height
|
||||||
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.width
|
|
||||||
import androidx.compose.foundation.shape.CircleShape
|
import androidx.compose.foundation.shape.CircleShape
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.filled.Add
|
import androidx.compose.material.icons.filled.Add
|
||||||
import androidx.compose.material.icons.filled.ArrowForward
|
|
||||||
import androidx.compose.material.icons.filled.Check
|
import androidx.compose.material.icons.filled.Check
|
||||||
import androidx.compose.material.icons.filled.Edit as EditIcon
|
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
@@ -35,14 +28,10 @@ import androidx.compose.ui.Alignment
|
|||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.clip
|
import androidx.compose.ui.draw.clip
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.graphics.ColorFilter
|
|
||||||
import androidx.compose.ui.layout.ContentScale
|
import androidx.compose.ui.layout.ContentScale
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.res.painterResource
|
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.sp
|
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import com.aiosman.ravenow.AppState
|
import com.aiosman.ravenow.AppState
|
||||||
import com.aiosman.ravenow.AppStore
|
import com.aiosman.ravenow.AppStore
|
||||||
@@ -50,29 +39,28 @@ import com.aiosman.ravenow.LocalAppTheme
|
|||||||
import com.aiosman.ravenow.LocalNavController
|
import com.aiosman.ravenow.LocalNavController
|
||||||
import com.aiosman.ravenow.R
|
import com.aiosman.ravenow.R
|
||||||
import com.aiosman.ravenow.ui.NavigationRoute
|
import com.aiosman.ravenow.ui.NavigationRoute
|
||||||
|
import com.aiosman.ravenow.ui.comment.NoticeScreenHeader
|
||||||
import com.aiosman.ravenow.ui.composables.CustomAsyncImage
|
import com.aiosman.ravenow.ui.composables.CustomAsyncImage
|
||||||
import com.aiosman.ravenow.ui.composables.StatusBarMaskLayout
|
import com.aiosman.ravenow.ui.composables.StatusBarMaskLayout
|
||||||
|
import com.aiosman.ravenow.ui.composables.StatusBarSpacer
|
||||||
|
import com.aiosman.ravenow.ui.composables.form.FormTextInput
|
||||||
import com.aiosman.ravenow.ui.composables.debouncedClickable
|
import com.aiosman.ravenow.ui.composables.debouncedClickable
|
||||||
import com.aiosman.ravenow.ui.composables.rememberDebouncedNavigation
|
import com.aiosman.ravenow.ui.composables.rememberDebouncedNavigation
|
||||||
import com.google.accompanist.systemuicontroller.rememberSystemUiController
|
|
||||||
import com.aiosman.ravenow.ui.modifiers.noRippleClickable
|
import com.aiosman.ravenow.ui.modifiers.noRippleClickable
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import androidx.compose.foundation.Image
|
import androidx.compose.foundation.Image
|
||||||
import androidx.compose.foundation.layout.WindowInsets
|
import androidx.compose.foundation.layout.width
|
||||||
import androidx.compose.foundation.layout.asPaddingValues
|
|
||||||
import androidx.compose.foundation.layout.offset
|
|
||||||
import androidx.compose.foundation.layout.systemBars
|
|
||||||
import androidx.compose.foundation.text.BasicTextField
|
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.rememberCoroutineScope
|
import androidx.compose.runtime.rememberCoroutineScope
|
||||||
import androidx.compose.ui.draw.shadow
|
import androidx.compose.ui.draw.shadow
|
||||||
import androidx.compose.ui.graphics.Brush
|
import androidx.compose.ui.graphics.Brush
|
||||||
import androidx.compose.ui.graphics.SolidColor
|
import androidx.compose.ui.res.painterResource
|
||||||
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
|
import androidx.compose.ui.unit.sp
|
||||||
import com.aiosman.ravenow.ConstVars
|
import com.aiosman.ravenow.ConstVars
|
||||||
import com.aiosman.ravenow.ui.composables.pickupAndCompressLauncher
|
import com.aiosman.ravenow.ui.composables.pickupAndCompressLauncher
|
||||||
import android.widget.Toast
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -98,10 +86,6 @@ fun AccountEditScreen2(onUpdateBanner: ((Uri, File, Context) -> Unit)? = null,)
|
|||||||
quality = 100
|
quality = 100
|
||||||
) { uri, file ->
|
) { uri, file ->
|
||||||
// 处理选中的图片
|
// 处理选中的图片
|
||||||
// 保存到 ViewModel 中,等待保存时一起上传
|
|
||||||
model.bannerImageUrl = uri
|
|
||||||
model.bannerFile = file
|
|
||||||
// 如果提供了回调,也调用它(用于个人主页直接更新)
|
|
||||||
onUpdateBanner?.invoke(uri, file, context)
|
onUpdateBanner?.invoke(uri, file, context)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,21 +93,10 @@ fun AccountEditScreen2(onUpdateBanner: ((Uri, File, Context) -> Unit)? = null,)
|
|||||||
// 去除换行符,确保昵称不包含换行
|
// 去除换行符,确保昵称不包含换行
|
||||||
val cleanValue = value.replace("\n", "").replace("\r", "")
|
val cleanValue = value.replace("\n", "").replace("\r", "")
|
||||||
model.name = cleanValue
|
model.name = cleanValue
|
||||||
// 实时验证,但不显示错误(只在保存时显示)
|
|
||||||
usernameError = when {
|
usernameError = when {
|
||||||
cleanValue.trim().isEmpty() -> context.getString(R.string.error_nickname_empty)
|
cleanValue.trim().isEmpty() -> "昵称不能为空"
|
||||||
cleanValue.length < 3 -> context.getString(R.string.error_nickname_too_short)
|
cleanValue.length < 3 -> "昵称长度不能小于3"
|
||||||
cleanValue.length > 20 -> context.getString(R.string.error_nickname_too_long)
|
cleanValue.length > 20 -> "昵称长度不能大于20"
|
||||||
else -> null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun validateNickname(): String? {
|
|
||||||
val cleanValue = model.name.replace("\n", "").replace("\r", "")
|
|
||||||
return when {
|
|
||||||
cleanValue.trim().isEmpty() -> context.getString(R.string.error_nickname_empty)
|
|
||||||
cleanValue.length < 3 -> context.getString(R.string.error_nickname_too_short)
|
|
||||||
cleanValue.length > 20 -> context.getString(R.string.error_nickname_too_long)
|
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -134,17 +107,8 @@ fun AccountEditScreen2(onUpdateBanner: ((Uri, File, Context) -> Unit)? = null,)
|
|||||||
// 去除换行符,确保个人简介不包含换行
|
// 去除换行符,确保个人简介不包含换行
|
||||||
val cleanValue = value.replace("\n", "").replace("\r", "")
|
val cleanValue = value.replace("\n", "").replace("\r", "")
|
||||||
model.bio = cleanValue
|
model.bio = cleanValue
|
||||||
// 实时验证,但不显示错误(只在保存时显示)
|
|
||||||
bioError = when {
|
bioError = when {
|
||||||
cleanValue.length > 100 -> context.getString(R.string.error_bio_too_long)
|
cleanValue.length > 100 -> "个人简介长度不能大于100"
|
||||||
else -> null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun validateBio(): String? {
|
|
||||||
val cleanValue = model.bio.replace("\n", "").replace("\r", "")
|
|
||||||
return when {
|
|
||||||
cleanValue.length > 100 -> context.getString(R.string.error_bio_too_long)
|
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -170,28 +134,192 @@ fun AccountEditScreen2(onUpdateBanner: ((Uri, File, Context) -> Unit)? = null,)
|
|||||||
// 确保显示的是当前登录用户的信息,而不是之前用户的缓存数据
|
// 确保显示的是当前登录用户的信息,而不是之前用户的缓存数据
|
||||||
model.reloadProfile()
|
model.reloadProfile()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 设置状态栏为透明,根据暗色模式决定图标颜色
|
|
||||||
val systemUiController = rememberSystemUiController()
|
|
||||||
LaunchedEffect(Unit) {
|
|
||||||
systemUiController.setStatusBarColor(Color.Transparent, darkIcons = !AppState.darkMode)
|
|
||||||
}
|
|
||||||
|
|
||||||
StatusBarMaskLayout(
|
StatusBarMaskLayout(
|
||||||
modifier = Modifier.background(appColors.background),
|
modifier = Modifier.background(color = appColors.background).padding(horizontal = 16.dp),
|
||||||
darkIcons = !AppState.darkMode, // 根据暗色模式决定图标颜色
|
darkIcons = !AppState.darkMode,
|
||||||
maskBoxBackgroundColor = Color.Transparent
|
maskBoxBackgroundColor = appColors.background
|
||||||
) {
|
) {
|
||||||
Box(
|
Column(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
.background(appColors.background)
|
.background(color = appColors.background),
|
||||||
|
horizontalAlignment = Alignment.CenterHorizontally
|
||||||
) {
|
) {
|
||||||
|
//StatusBarSpacer()
|
||||||
|
Box(
|
||||||
|
modifier = Modifier.padding(horizontal = 0.dp, vertical = 16.dp)
|
||||||
|
) {
|
||||||
|
NoticeScreenHeader(
|
||||||
|
title = stringResource(R.string.edit_profile),
|
||||||
|
moreIcon = false
|
||||||
|
) {
|
||||||
|
|
||||||
|
Icon(
|
||||||
|
modifier = Modifier
|
||||||
|
.size(24.dp)
|
||||||
|
.debouncedClickable(
|
||||||
|
enabled = validate() && !model.isUpdating,
|
||||||
|
debounceTime = 1000L
|
||||||
|
) {
|
||||||
|
if (validate() && !model.isUpdating) {
|
||||||
|
model.viewModelScope.launch {
|
||||||
|
model.isUpdating = true
|
||||||
|
model.updateUserProfile(context)
|
||||||
|
model.viewModelScope.launch(Dispatchers.Main) {
|
||||||
|
debouncedNavigation {
|
||||||
|
navController.navigateUp()
|
||||||
|
}
|
||||||
|
model.isUpdating = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
imageVector = Icons.Default.Check,
|
||||||
|
contentDescription = "保存",
|
||||||
|
tint = if (validate() && !model.isUpdating) appColors.text else appColors.nonActiveText
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 添加横幅图片区域
|
||||||
|
val banner = model.profile?.banner
|
||||||
|
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.height(300.dp)
|
||||||
|
.clip(RoundedCornerShape(12.dp))
|
||||||
|
) {
|
||||||
|
if (banner != null) {
|
||||||
|
CustomAsyncImage(
|
||||||
|
context = LocalContext.current,
|
||||||
|
imageUrl = banner,
|
||||||
|
modifier = Modifier.fillMaxSize(),
|
||||||
|
contentDescription = "Banner",
|
||||||
|
contentScale = ContentScale.Crop
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.background(Color.Gray.copy(alpha = 0.1f))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.width(120.dp)
|
||||||
|
.height(42.dp)
|
||||||
|
.align(Alignment.BottomEnd)
|
||||||
|
.padding(end = 12.dp, bottom = 12.dp)
|
||||||
|
.background(
|
||||||
|
color = Color.Black.copy(alpha = 0.4f),
|
||||||
|
shape = RoundedCornerShape(9.dp)
|
||||||
|
)
|
||||||
|
.noRippleClickable {
|
||||||
|
Intent(Intent.ACTION_PICK).apply {
|
||||||
|
type = "image/*"
|
||||||
|
pickBannerImageLauncher.launch(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
){
|
||||||
|
Text(
|
||||||
|
text = "change",
|
||||||
|
fontSize = 14.sp,
|
||||||
|
fontWeight = FontWeight.W600,
|
||||||
|
color = Color.White,
|
||||||
|
modifier = Modifier.align(Alignment.Center)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Spacer(modifier = Modifier.height(20.dp))
|
||||||
|
|
||||||
|
// 显示内容或加载状态
|
||||||
|
Log.d("AccountEditScreen2", "UI状态 - profile: ${model.profile?.nickName}, isLoading: ${model.isLoading}")
|
||||||
when {
|
when {
|
||||||
|
model.profile != null -> {
|
||||||
|
Log.d("AccountEditScreen2", "显示用户资料内容")
|
||||||
|
// 有数据时显示内容
|
||||||
|
val it = model.profile!!
|
||||||
|
Box(
|
||||||
|
modifier = Modifier.size(88.dp),
|
||||||
|
contentAlignment = Alignment.Center
|
||||||
|
) {
|
||||||
|
CustomAsyncImage(
|
||||||
|
context,
|
||||||
|
model.croppedBitmap ?: it.avatar,
|
||||||
|
modifier = Modifier
|
||||||
|
.size(88.dp)
|
||||||
|
.clip(
|
||||||
|
RoundedCornerShape(88.dp)
|
||||||
|
),
|
||||||
|
contentDescription = "",
|
||||||
|
contentScale = ContentScale.Crop
|
||||||
|
)
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.size(32.dp)
|
||||||
|
.clip(CircleShape)
|
||||||
|
.background(
|
||||||
|
brush = Brush.linearGradient(
|
||||||
|
colors = listOf(
|
||||||
|
Color(0xFF7c45ed),
|
||||||
|
Color(0x997c68ef),
|
||||||
|
Color(0xFF7bd8f8)
|
||||||
|
)
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.align(Alignment.BottomEnd)
|
||||||
|
.debouncedClickable(
|
||||||
|
debounceTime = 800L
|
||||||
|
) {
|
||||||
|
debouncedNavigation {
|
||||||
|
navController.navigate(NavigationRoute.ImageCrop.route)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
contentAlignment = Alignment.Center
|
||||||
|
) {
|
||||||
|
Icon(
|
||||||
|
Icons.Default.Add,
|
||||||
|
contentDescription = "Add",
|
||||||
|
tint = Color.White,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Spacer(modifier = Modifier.height(18.dp))
|
||||||
|
Column(
|
||||||
|
modifier = Modifier
|
||||||
|
.weight(1f)
|
||||||
|
.padding(horizontal = 16.dp)
|
||||||
|
) {
|
||||||
|
FormTextInput(
|
||||||
|
value = model.name,
|
||||||
|
label = stringResource(R.string.nickname),
|
||||||
|
hint = "Input nickname",
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
error = usernameError
|
||||||
|
) { value ->
|
||||||
|
onNicknameChange(value)
|
||||||
|
}
|
||||||
|
FormTextInput(
|
||||||
|
value = model.bio,
|
||||||
|
label = stringResource(R.string.bio),
|
||||||
|
hint = "Input bio",
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
error = bioError
|
||||||
|
) { value ->
|
||||||
|
onBioChange(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
model.isLoading -> {
|
model.isLoading -> {
|
||||||
|
Log.d("AccountEditScreen2", "显示加载指示器")
|
||||||
// 加载中状态
|
// 加载中状态
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier.fillMaxSize(),
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.padding(16.dp),
|
||||||
contentAlignment = Alignment.Center
|
contentAlignment = Alignment.Center
|
||||||
) {
|
) {
|
||||||
androidx.compose.material3.CircularProgressIndicator(
|
androidx.compose.material3.CircularProgressIndicator(
|
||||||
@@ -199,468 +327,24 @@ fun AccountEditScreen2(onUpdateBanner: ((Uri, File, Context) -> Unit)? = null,)
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
model.profile != null -> {
|
|
||||||
Column(
|
|
||||||
modifier = Modifier.fillMaxSize()
|
|
||||||
) {
|
|
||||||
// 顶部背景区域(圆角在底部,覆盖状态栏)
|
|
||||||
// 优先显示新选择的背景图,如果没有则显示原有的背景图
|
|
||||||
val banner = model.bannerImageUrl?.toString() ?: model.profile?.banner
|
|
||||||
val statusBarPadding = WindowInsets.systemBars.asPaddingValues().calculateTopPadding()
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.offset(y = -statusBarPadding)
|
|
||||||
) {
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.width(402.dp)
|
|
||||||
.height(206.dp)
|
|
||||||
.align(Alignment.TopCenter)
|
|
||||||
.clip(RoundedCornerShape(bottomStart = 32.dp, bottomEnd = 32.dp))
|
|
||||||
) {
|
|
||||||
if (banner != null) {
|
|
||||||
CustomAsyncImage(
|
|
||||||
context = context,
|
|
||||||
imageUrl = banner,
|
|
||||||
modifier = Modifier.fillMaxSize(),
|
|
||||||
contentDescription = "Banner",
|
|
||||||
contentScale = ContentScale.Crop
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxSize()
|
|
||||||
.background(Color.Gray.copy(alpha = 0.2f))
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 更换封面按钮(位于壁纸右下方)
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.align(Alignment.BottomEnd)
|
|
||||||
.padding(end = 16.dp, bottom = 20.dp)
|
|
||||||
.clip(RoundedCornerShape(12.dp))
|
|
||||||
.background(Color(0x5C7D7C80)) // RGB(125, 120, 128, 0.36)
|
|
||||||
.padding(horizontal = 8.dp, vertical = 4.dp)
|
|
||||||
.noRippleClickable {
|
|
||||||
Intent(Intent.ACTION_PICK).apply {
|
|
||||||
type = "image/*"
|
|
||||||
pickBannerImageLauncher.launch(this)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
) {
|
|
||||||
Row(
|
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
|
||||||
horizontalArrangement = Arrangement.spacedBy(4.dp)
|
|
||||||
) {
|
|
||||||
// 更换封面图标
|
|
||||||
Icon(
|
|
||||||
painter = painterResource(id = R.mipmap.fengm),
|
|
||||||
contentDescription = null,
|
|
||||||
modifier = Modifier.size(16.dp),
|
|
||||||
tint = Color.White
|
|
||||||
)
|
|
||||||
Text(
|
|
||||||
text = stringResource(R.string.change_cover),
|
|
||||||
fontSize = 12.sp,
|
|
||||||
color = Color.White
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 状态栏区域(时间、信号、电池)
|
|
||||||
// 这里使用系统状态栏,不单独实现
|
|
||||||
|
|
||||||
// 导航栏区域
|
|
||||||
Column(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(horizontal = 16.dp)
|
|
||||||
) {
|
|
||||||
Spacer(modifier = Modifier.height(statusBarPadding + 12.dp))
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(bottom = 12.dp)
|
|
||||||
) {
|
|
||||||
// 返回按钮
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.size(44.dp)
|
|
||||||
.clip(CircleShape)
|
|
||||||
.background(Color.White.copy(alpha = 0.3f))
|
|
||||||
.noRippleClickable {
|
|
||||||
navController.navigateUp()
|
|
||||||
}
|
|
||||||
.align(Alignment.CenterStart),
|
|
||||||
contentAlignment = Alignment.Center
|
|
||||||
) {
|
|
||||||
Image(
|
|
||||||
painter = painterResource(id = R.drawable.rider_pro_back_icon),
|
|
||||||
contentDescription = "Back",
|
|
||||||
modifier = Modifier.size(24.dp),
|
|
||||||
colorFilter = ColorFilter.tint(Color.White)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 标题
|
|
||||||
Text(
|
|
||||||
text = stringResource(R.string.edit_profile_info),
|
|
||||||
fontSize = 17.sp,
|
|
||||||
fontWeight = FontWeight.SemiBold,
|
|
||||||
color = Color.White,
|
|
||||||
modifier = Modifier.align(Alignment.Center)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 用户头像区域(距离顶部-50dp,包含状态栏高度,左右居中)
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.offset(y = (-50).dp - statusBarPadding),
|
|
||||||
contentAlignment = Alignment.Center
|
|
||||||
) {
|
|
||||||
val it = model.profile!!
|
|
||||||
Box(
|
|
||||||
modifier = Modifier.size(96.dp),
|
|
||||||
contentAlignment = Alignment.BottomEnd
|
|
||||||
) {
|
|
||||||
// 头像
|
|
||||||
CustomAsyncImage(
|
|
||||||
context,
|
|
||||||
model.croppedBitmap ?: it.avatar,
|
|
||||||
modifier = Modifier
|
|
||||||
.size(96.dp)
|
|
||||||
.clip(CircleShape)
|
|
||||||
.border(2.4.dp, appColors.background, CircleShape),
|
|
||||||
contentDescription = "",
|
|
||||||
contentScale = ContentScale.Crop
|
|
||||||
)
|
|
||||||
|
|
||||||
// 编辑头像按钮
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.size(28.dp)
|
|
||||||
.clip(CircleShape)
|
|
||||||
.background(Color(0xFF110C13))
|
|
||||||
.border(2.dp, Color.White, CircleShape)
|
|
||||||
.debouncedClickable(debounceTime = 800L) {
|
|
||||||
debouncedNavigation {
|
|
||||||
navController.navigate(NavigationRoute.ImageCrop.route)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
contentAlignment = Alignment.Center
|
|
||||||
) {
|
|
||||||
Icon(
|
|
||||||
painter = painterResource(id = R.mipmap.bi),
|
|
||||||
contentDescription = "Edit Avatar",
|
|
||||||
modifier = Modifier.size(16.dp),
|
|
||||||
tint = Color.White
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Column(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.weight(1f)
|
|
||||||
.padding(horizontal = 16.dp)
|
|
||||||
.offset(y = (-74).dp)//
|
|
||||||
) {
|
|
||||||
// 昵称输入框
|
|
||||||
ProfileInfoCard(
|
|
||||||
label = stringResource(R.string.nickname),
|
|
||||||
value = model.name,
|
|
||||||
placeholder = "Value",
|
|
||||||
onValueChange = { onNicknameChange(it) },
|
|
||||||
isMultiline = false
|
|
||||||
)
|
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(16.dp))
|
|
||||||
|
|
||||||
// 个人简介输入框
|
|
||||||
ProfileInfoCard(
|
|
||||||
label = stringResource(R.string.personal_intro),
|
|
||||||
value = model.bio,
|
|
||||||
placeholder = "Welcome to my fantiac word i will show you something about magic",
|
|
||||||
onValueChange = { onBioChange(it) },
|
|
||||||
isMultiline = true
|
|
||||||
)
|
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(16.dp))
|
|
||||||
|
|
||||||
// MBTI 类型和星座
|
|
||||||
Column(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.clip(RoundedCornerShape(16.dp))
|
|
||||||
.background(appColors.secondaryBackground)
|
|
||||||
) {
|
|
||||||
// MBTI 类型
|
|
||||||
ProfileSelectItem(
|
|
||||||
label = stringResource(R.string.mbti_type),
|
|
||||||
value = model.mbti ?: "ENFP",
|
|
||||||
iconColor = Color(0xFF7C45ED),
|
|
||||||
iconResDark = null, // TODO: 添加MBTI暗色模式图标
|
|
||||||
iconResLight = null, // TODO: 添加MBTI亮色模式图标
|
|
||||||
onClick = {
|
|
||||||
debouncedNavigation {
|
|
||||||
navController.navigate(NavigationRoute.MbtiSelect.route)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
// 分隔线
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.height(0.3.dp)
|
|
||||||
.background(appColors.divider)
|
|
||||||
.padding(horizontal = 16.dp)
|
|
||||||
)
|
|
||||||
|
|
||||||
// 星座(使用当前图标)
|
|
||||||
ProfileSelectItem(
|
|
||||||
label = stringResource(R.string.zodiac),
|
|
||||||
value = model.zodiac?.let { storedZodiac ->
|
|
||||||
// 尝试找到对应的资源ID并显示当前语言的文本
|
|
||||||
findZodiacResId(storedZodiac)?.let { resId ->
|
|
||||||
stringResource(resId)
|
|
||||||
} ?: storedZodiac // 如果找不到,显示原始存储的值
|
|
||||||
} ?: stringResource(R.string.zodiac_aries),
|
|
||||||
iconColor = Color(0xFFFFCC00),
|
|
||||||
iconResDark = R.mipmap.frame_4, // 星座暗色模式图标
|
|
||||||
iconResLight = R.mipmap.xingzuo, // 星座亮色模式图标
|
|
||||||
onClick = {
|
|
||||||
debouncedNavigation {
|
|
||||||
navController.navigate(NavigationRoute.ZodiacSelect.route)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
Spacer(modifier = Modifier.weight(1f))
|
|
||||||
|
|
||||||
// 保存按钮
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.height(50.dp)
|
|
||||||
.clip(RoundedCornerShape(1000.dp))
|
|
||||||
.background(
|
|
||||||
brush = Brush.horizontalGradient(
|
|
||||||
colors = listOf(
|
|
||||||
Color(0xFF7C45ED), // RGB(124, 69, 237) - 左侧
|
|
||||||
Color(0xFF7C57EE), // RGB(124, 87, 238) - 中间
|
|
||||||
Color(0xFF7BD8F8) // RGB(123, 216, 248) - 右侧
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.debouncedClickable(
|
|
||||||
enabled = !model.isUpdating,
|
|
||||||
debounceTime = 1000L
|
|
||||||
) {
|
|
||||||
if (model.isUpdating) return@debouncedClickable
|
|
||||||
|
|
||||||
// 点击保存时重新验证
|
|
||||||
val nicknameErrorMsg = validateNickname()
|
|
||||||
val bioErrorMsg = validateBio()
|
|
||||||
|
|
||||||
// 如果有错误,显示对应的错误提示
|
|
||||||
when {
|
|
||||||
nicknameErrorMsg != null -> {
|
|
||||||
Toast.makeText(context, nicknameErrorMsg, Toast.LENGTH_SHORT).show()
|
|
||||||
return@debouncedClickable
|
|
||||||
}
|
|
||||||
bioErrorMsg != null -> {
|
|
||||||
Toast.makeText(context, bioErrorMsg, Toast.LENGTH_SHORT).show()
|
|
||||||
return@debouncedClickable
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 验证通过,执行保存
|
|
||||||
model.viewModelScope.launch {
|
|
||||||
model.isUpdating = true
|
|
||||||
model.updateUserProfile(context)
|
|
||||||
model.viewModelScope.launch(Dispatchers.Main) {
|
|
||||||
debouncedNavigation {
|
|
||||||
navController.navigateUp()
|
|
||||||
}
|
|
||||||
model.isUpdating = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
contentAlignment = Alignment.Center
|
|
||||||
) {
|
|
||||||
Text(
|
|
||||||
text = stringResource(R.string.save),
|
|
||||||
fontSize = 17.sp,
|
|
||||||
fontWeight = FontWeight.Normal,
|
|
||||||
color = Color.White
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else -> {
|
else -> {
|
||||||
|
Log.d("AccountEditScreen2", "显示错误信息 - 没有数据且不在加载中")
|
||||||
// 没有数据且不在加载中,显示错误信息
|
// 没有数据且不在加载中,显示错误信息
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier.fillMaxSize(),
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.padding(16.dp),
|
||||||
contentAlignment = Alignment.Center
|
contentAlignment = Alignment.Center
|
||||||
) {
|
) {
|
||||||
Text(
|
androidx.compose.material3.Text(
|
||||||
text = stringResource(R.string.error_load_profile_failed),
|
text = "加载用户资料失败,请重试",
|
||||||
color = appColors.text
|
color = appColors.text
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 信息输入卡片组件
|
|
||||||
*/
|
|
||||||
@Composable
|
|
||||||
fun ProfileInfoCard(
|
|
||||||
label: String,
|
|
||||||
value: String,
|
|
||||||
placeholder: String,
|
|
||||||
onValueChange: (String) -> Unit,
|
|
||||||
isMultiline: Boolean = false
|
|
||||||
) {
|
|
||||||
val appColors = LocalAppTheme.current
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.height(if (isMultiline) 66.dp else 56.dp) // 昵称框高度56dp,个人简介66dp
|
|
||||||
.clip(RoundedCornerShape(16.dp))
|
|
||||||
.background(appColors.secondaryBackground),
|
|
||||||
contentAlignment = if (isMultiline) Alignment.TopStart else Alignment.CenterStart
|
|
||||||
) {
|
|
||||||
Row(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(horizontal = 16.dp)
|
|
||||||
.padding(vertical = if (isMultiline) 11.dp else 0.dp),
|
|
||||||
verticalAlignment = if (isMultiline) Alignment.Top else Alignment.CenterVertically
|
|
||||||
) {
|
|
||||||
// 标签
|
|
||||||
Text(
|
|
||||||
text = label,
|
|
||||||
fontSize = 17.sp,
|
|
||||||
fontWeight = FontWeight.Normal,
|
|
||||||
color = appColors.text,
|
|
||||||
modifier = Modifier.width(100.dp)
|
|
||||||
)
|
|
||||||
|
|
||||||
Spacer(modifier = Modifier.width(16.dp))
|
|
||||||
|
|
||||||
// 输入框
|
|
||||||
Box(
|
|
||||||
modifier = Modifier.weight(1f)
|
|
||||||
) {
|
|
||||||
if (value.isEmpty()) {
|
|
||||||
Text(
|
|
||||||
text = placeholder,
|
|
||||||
fontSize = if (isMultiline) 15.sp else 17.sp,
|
|
||||||
fontWeight = FontWeight.Normal,
|
|
||||||
color = appColors.secondaryText,
|
|
||||||
modifier = Modifier.fillMaxWidth()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
BasicTextField(
|
|
||||||
value = value,
|
|
||||||
onValueChange = onValueChange,
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
|
||||||
textStyle = androidx.compose.ui.text.TextStyle(
|
|
||||||
fontSize = if (isMultiline) 15.sp else 17.sp,
|
|
||||||
fontWeight = FontWeight.Normal,
|
|
||||||
color = appColors.text
|
|
||||||
),
|
|
||||||
cursorBrush = SolidColor(appColors.text),
|
|
||||||
maxLines = if (isMultiline) Int.MAX_VALUE else 1,
|
|
||||||
singleLine = !isMultiline
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 选择项组件(MBTI、星座)
|
|
||||||
*/
|
|
||||||
@Composable
|
|
||||||
fun ProfileSelectItem(
|
|
||||||
label: String,
|
|
||||||
value: String,
|
|
||||||
iconColor: Color,
|
|
||||||
onClick: () -> Unit,
|
|
||||||
iconResDark: Int? = null,
|
|
||||||
iconResLight: Int? = null
|
|
||||||
) {
|
|
||||||
val appColors = LocalAppTheme.current
|
|
||||||
Row(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.height(56.dp)
|
|
||||||
.clickable(onClick = onClick)
|
|
||||||
.padding(horizontal = 16.dp),
|
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
|
||||||
horizontalArrangement = Arrangement.SpaceBetween
|
|
||||||
) {
|
|
||||||
Row(
|
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
|
||||||
horizontalArrangement = Arrangement.spacedBy(8.dp)
|
|
||||||
) {
|
|
||||||
// 自定义图标
|
|
||||||
Icon(
|
|
||||||
painter = painterResource(
|
|
||||||
id = if (AppState.darkMode) {
|
|
||||||
// 暗色模式下使用和亮色模式一样的图标
|
|
||||||
iconResLight ?: iconResDark ?: R.mipmap.naoz
|
|
||||||
} else {
|
|
||||||
iconResLight ?: R.mipmap.naoz // 使用传入的亮色模式图标,或默认占位
|
|
||||||
}
|
|
||||||
),
|
|
||||||
contentDescription = null,
|
|
||||||
modifier = Modifier.size(24.dp),
|
|
||||||
tint = iconColor
|
|
||||||
)
|
|
||||||
|
|
||||||
Text(
|
|
||||||
text = label,
|
|
||||||
fontSize = 17.sp,
|
|
||||||
fontWeight = FontWeight.Normal,
|
|
||||||
color = appColors.text
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
Row(
|
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
|
||||||
horizontalArrangement = Arrangement.spacedBy(16.dp)
|
|
||||||
) {
|
|
||||||
Text(
|
|
||||||
text = value,
|
|
||||||
fontSize = 17.sp,
|
|
||||||
fontWeight = FontWeight.Normal,
|
|
||||||
color = appColors.secondaryText
|
|
||||||
)
|
|
||||||
|
|
||||||
Icon(
|
|
||||||
imageVector = Icons.Default.ArrowForward,
|
|
||||||
contentDescription = null,
|
|
||||||
modifier = Modifier.size(8.dp),
|
|
||||||
tint = appColors.secondaryText
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -79,12 +79,11 @@ import com.aiosman.ravenow.R
|
|||||||
import com.aiosman.ravenow.entity.ChatItem
|
import com.aiosman.ravenow.entity.ChatItem
|
||||||
import com.aiosman.ravenow.exp.formatChatTime
|
import com.aiosman.ravenow.exp.formatChatTime
|
||||||
import com.aiosman.ravenow.ui.composables.CustomAsyncImage
|
import com.aiosman.ravenow.ui.composables.CustomAsyncImage
|
||||||
|
import com.aiosman.ravenow.ui.composables.DropdownMenu
|
||||||
|
import com.aiosman.ravenow.ui.composables.MenuItem
|
||||||
import com.aiosman.ravenow.ui.composables.StatusBarSpacer
|
import com.aiosman.ravenow.ui.composables.StatusBarSpacer
|
||||||
import com.aiosman.ravenow.ui.modifiers.noRippleClickable
|
import com.aiosman.ravenow.ui.modifiers.noRippleClickable
|
||||||
import com.aiosman.ravenow.utils.NetworkUtils
|
import com.aiosman.ravenow.utils.NetworkUtils
|
||||||
import com.aiosman.ravenow.ui.NavigationRoute
|
|
||||||
import com.aiosman.ravenow.AppState
|
|
||||||
import androidx.compose.ui.layout.ContentScale
|
|
||||||
import io.openim.android.sdk.enums.MessageType
|
import io.openim.android.sdk.enums.MessageType
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
@@ -92,10 +91,10 @@ import java.util.UUID
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ChatAiScreen(userId: String) {
|
fun ChatAiScreen(userId: String) {
|
||||||
|
var isMenuExpanded by remember { mutableStateOf(false) }
|
||||||
val navController = LocalNavController.current
|
val navController = LocalNavController.current
|
||||||
val context = LocalNavController.current.context
|
val context = LocalNavController.current.context
|
||||||
val AppColors = LocalAppTheme.current
|
val AppColors = LocalAppTheme.current
|
||||||
val chatBackgroundUrl = AppState.chatBackgroundUrl
|
|
||||||
var goToNewCount by remember { mutableStateOf(0) }
|
var goToNewCount by remember { mutableStateOf(0) }
|
||||||
val viewModel = viewModel<ChatAiViewModel>(
|
val viewModel = viewModel<ChatAiViewModel>(
|
||||||
key = "ChatAiViewModel_$userId",
|
key = "ChatAiViewModel_$userId",
|
||||||
@@ -159,25 +158,14 @@ fun ChatAiScreen(userId: String) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Box(modifier = Modifier.fillMaxSize()) {
|
Scaffold(
|
||||||
if (chatBackgroundUrl != null && chatBackgroundUrl.isNotEmpty()) {
|
modifier = Modifier
|
||||||
CustomAsyncImage(
|
.fillMaxSize(),
|
||||||
imageUrl = chatBackgroundUrl,
|
topBar = {
|
||||||
modifier = Modifier.fillMaxSize(),
|
|
||||||
contentDescription = "chat_background",
|
|
||||||
contentScale = ContentScale.Crop
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
Scaffold(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxSize(),
|
|
||||||
backgroundColor = Color.Transparent,
|
|
||||||
topBar = {
|
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.background(Color.Transparent)
|
.background(AppColors.background)
|
||||||
) {
|
) {
|
||||||
StatusBarSpacer()
|
StatusBarSpacer()
|
||||||
Row(
|
Row(
|
||||||
@@ -225,32 +213,56 @@ fun ChatAiScreen(userId: String) {
|
|||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.size(28.dp)
|
.size(28.dp)
|
||||||
.noRippleClickable {
|
.noRippleClickable {
|
||||||
navController.navigate(NavigationRoute.ChatSetting.route)
|
isMenuExpanded = true
|
||||||
},
|
},
|
||||||
contentDescription = null,
|
contentDescription = null,
|
||||||
colorFilter = ColorFilter.tint(
|
colorFilter = ColorFilter.tint(
|
||||||
AppColors.text)
|
AppColors.text)
|
||||||
)
|
)
|
||||||
|
DropdownMenu(
|
||||||
|
expanded = isMenuExpanded,
|
||||||
|
onDismissRequest = {
|
||||||
|
isMenuExpanded = false
|
||||||
|
},
|
||||||
|
menuItems = listOf(
|
||||||
|
MenuItem(
|
||||||
|
title = if (viewModel.notificationStrategy == "mute") "Unmute" else "Mute",
|
||||||
|
icon = if (viewModel.notificationStrategy == "mute") R.drawable.rider_pro_notice_mute else R.drawable.rider_pro_notice_active,
|
||||||
|
) {
|
||||||
|
|
||||||
|
isMenuExpanded = false
|
||||||
|
if (NetworkUtils.isNetworkAvailable(context)) {
|
||||||
|
viewModel.viewModelScope.launch {
|
||||||
|
if (viewModel.notificationStrategy == "mute") {
|
||||||
|
viewModel.updateNotificationStrategy("active")
|
||||||
|
} else {
|
||||||
|
viewModel.updateNotificationStrategy("mute")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
android.widget.Toast.makeText(context, "网络连接异常,请检查网络设置", android.widget.Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
),
|
||||||
|
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
bottomBar = {
|
bottomBar = {
|
||||||
val hasChatBackground = AppState.chatBackgroundUrl != null && AppState.chatBackgroundUrl!!.isNotEmpty()
|
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.imePadding()
|
.imePadding()
|
||||||
) {
|
) {
|
||||||
if (!hasChatBackground) {
|
Box(
|
||||||
Box(
|
modifier = Modifier
|
||||||
modifier = Modifier
|
.fillMaxWidth()
|
||||||
.fillMaxWidth()
|
.height(1.dp)
|
||||||
.height(1.dp)
|
.background(
|
||||||
.background(
|
AppColors.decentBackground)
|
||||||
AppColors.decentBackground)
|
)
|
||||||
)
|
|
||||||
}
|
|
||||||
Spacer(modifier = Modifier.height(8.dp))
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
ChatAiInput(
|
ChatAiInput(
|
||||||
onSendImage = {
|
onSendImage = {
|
||||||
@@ -271,7 +283,7 @@ fun ChatAiScreen(userId: String) {
|
|||||||
Box(
|
Box(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
.background(Color.Transparent)
|
.background(Color.White)
|
||||||
.padding(paddingValues)
|
.padding(paddingValues)
|
||||||
) {
|
) {
|
||||||
LazyColumn(
|
LazyColumn(
|
||||||
@@ -334,7 +346,8 @@ fun ChatAiScreen(userId: String) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -558,8 +571,7 @@ fun ChatAiInput(
|
|||||||
}
|
}
|
||||||
Box( modifier = Modifier
|
Box( modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.background(Color.Transparent)
|
.padding(start = 16.dp, end = 16.dp, bottom = 12.dp),){
|
||||||
.padding(start = 16.dp, end = 16.dp, bottom = 45.dp),){
|
|
||||||
|
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
|
|||||||
@@ -64,7 +64,6 @@ import androidx.compose.ui.platform.LocalFocusManager
|
|||||||
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
|
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
|
||||||
import androidx.compose.ui.platform.SoftwareKeyboardController
|
import androidx.compose.ui.platform.SoftwareKeyboardController
|
||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
import androidx.compose.ui.layout.ContentScale
|
|
||||||
import androidx.compose.ui.text.TextStyle
|
import androidx.compose.ui.text.TextStyle
|
||||||
import androidx.compose.ui.text.input.ImeAction
|
import androidx.compose.ui.text.input.ImeAction
|
||||||
import androidx.compose.ui.text.style.TextAlign
|
import androidx.compose.ui.text.style.TextAlign
|
||||||
@@ -75,12 +74,10 @@ import androidx.lifecycle.ViewModelProvider
|
|||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||||
import com.aiosman.ravenow.LocalAppTheme
|
import com.aiosman.ravenow.LocalAppTheme
|
||||||
import com.aiosman.ravenow.AppState
|
|
||||||
import com.aiosman.ravenow.LocalNavController
|
import com.aiosman.ravenow.LocalNavController
|
||||||
import com.aiosman.ravenow.R
|
import com.aiosman.ravenow.R
|
||||||
import com.aiosman.ravenow.entity.ChatItem
|
import com.aiosman.ravenow.entity.ChatItem
|
||||||
import com.aiosman.ravenow.exp.formatChatTime
|
import com.aiosman.ravenow.exp.formatChatTime
|
||||||
import com.aiosman.ravenow.ui.NavigationRoute
|
|
||||||
import com.aiosman.ravenow.ui.composables.CustomAsyncImage
|
import com.aiosman.ravenow.ui.composables.CustomAsyncImage
|
||||||
import com.aiosman.ravenow.ui.composables.DropdownMenu
|
import com.aiosman.ravenow.ui.composables.DropdownMenu
|
||||||
import com.aiosman.ravenow.ui.composables.MenuItem
|
import com.aiosman.ravenow.ui.composables.MenuItem
|
||||||
@@ -94,6 +91,7 @@ import java.util.UUID
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ChatScreen(userId: String) {
|
fun ChatScreen(userId: String) {
|
||||||
|
var isMenuExpanded by remember { mutableStateOf(false) }
|
||||||
val navController = LocalNavController.current
|
val navController = LocalNavController.current
|
||||||
val context = LocalNavController.current.context
|
val context = LocalNavController.current.context
|
||||||
val AppColors = LocalAppTheme.current
|
val AppColors = LocalAppTheme.current
|
||||||
@@ -160,37 +158,14 @@ fun ChatScreen(userId: String) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Box(
|
Scaffold(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxSize()
|
.fillMaxSize(),
|
||||||
) {
|
|
||||||
// 背景图层
|
|
||||||
val bgUrl = AppState.chatBackgroundUrl
|
|
||||||
if (bgUrl != null) {
|
|
||||||
CustomAsyncImage(
|
|
||||||
imageUrl = bgUrl,
|
|
||||||
modifier = Modifier.fillMaxSize(),
|
|
||||||
contentDescription = "chat_background",
|
|
||||||
contentScale = ContentScale.Crop
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
// 无背景时使用主题背景色
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxSize()
|
|
||||||
.background(AppColors.background)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
Scaffold(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxSize(),
|
|
||||||
backgroundColor = Color.Transparent,
|
|
||||||
topBar = {
|
topBar = {
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.background(Color.Transparent)
|
.background(AppColors.background)
|
||||||
) {
|
) {
|
||||||
StatusBarSpacer()
|
StatusBarSpacer()
|
||||||
Row(
|
Row(
|
||||||
@@ -239,12 +214,39 @@ fun ChatScreen(userId: String) {
|
|||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.size(28.dp)
|
.size(28.dp)
|
||||||
.noRippleClickable {
|
.noRippleClickable {
|
||||||
navController.navigate(NavigationRoute.ChatSetting.route)
|
isMenuExpanded = true
|
||||||
},
|
},
|
||||||
contentDescription = null,
|
contentDescription = null,
|
||||||
colorFilter = ColorFilter.tint(
|
colorFilter = ColorFilter.tint(
|
||||||
AppColors.text)
|
AppColors.text)
|
||||||
)
|
)
|
||||||
|
DropdownMenu(
|
||||||
|
expanded = isMenuExpanded,
|
||||||
|
onDismissRequest = {
|
||||||
|
isMenuExpanded = false
|
||||||
|
},
|
||||||
|
menuItems = listOf(
|
||||||
|
MenuItem(
|
||||||
|
title = if (viewModel.notificationStrategy == "mute") "取消静音" else "静音",
|
||||||
|
icon = if (viewModel.notificationStrategy == "mute") R.drawable.rider_pro_notice_mute else R.drawable.rider_pro_notice_active,
|
||||||
|
) {
|
||||||
|
|
||||||
|
isMenuExpanded = false
|
||||||
|
if (NetworkUtils.isNetworkAvailable(context)) {
|
||||||
|
viewModel.viewModelScope.launch {
|
||||||
|
if (viewModel.notificationStrategy == "mute") {
|
||||||
|
viewModel.updateNotificationStrategy("active")
|
||||||
|
} else {
|
||||||
|
viewModel.updateNotificationStrategy("mute")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
android.widget.Toast.makeText(context, "网络连接异常,请检查网络设置", android.widget.Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
),
|
||||||
|
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -277,11 +279,11 @@ fun ChatScreen(userId: String) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
) { paddingValues ->
|
) { paddingValues ->
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
.background(Color.Transparent)
|
.background(AppColors.background)
|
||||||
.padding(paddingValues)
|
.padding(paddingValues)
|
||||||
) {
|
) {
|
||||||
LazyColumn(
|
LazyColumn(
|
||||||
@@ -345,7 +347,6 @@ fun ChatScreen(userId: String) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -571,7 +572,7 @@ fun ChatInput(
|
|||||||
}
|
}
|
||||||
Box( modifier = Modifier
|
Box( modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.padding(start = 16.dp, end = 16.dp, bottom = 45.dp),){
|
.padding(start = 16.dp, end = 16.dp, bottom = 12.dp),){
|
||||||
|
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
|
|||||||
@@ -1,362 +0,0 @@
|
|||||||
package com.aiosman.ravenow.ui.chat
|
|
||||||
|
|
||||||
import androidx.compose.foundation.background
|
|
||||||
import androidx.compose.foundation.clickable
|
|
||||||
import androidx.compose.foundation.layout.Box
|
|
||||||
import androidx.compose.foundation.layout.Column
|
|
||||||
import androidx.compose.foundation.layout.FlowRow
|
|
||||||
import androidx.compose.foundation.layout.Row
|
|
||||||
import androidx.compose.foundation.layout.Spacer
|
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
|
||||||
import androidx.compose.foundation.layout.height
|
|
||||||
import androidx.compose.foundation.layout.padding
|
|
||||||
import androidx.compose.foundation.layout.size
|
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
||||||
import androidx.compose.material3.Icon
|
|
||||||
import androidx.compose.material3.MaterialTheme
|
|
||||||
import androidx.compose.material3.ModalBottomSheet
|
|
||||||
import androidx.compose.material3.SheetState
|
|
||||||
import androidx.compose.material3.rememberModalBottomSheetState
|
|
||||||
import androidx.compose.material3.Text
|
|
||||||
import androidx.compose.runtime.Composable
|
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
|
||||||
import androidx.compose.ui.Alignment
|
|
||||||
import androidx.compose.ui.Modifier
|
|
||||||
import androidx.compose.ui.draw.clip
|
|
||||||
import androidx.compose.ui.graphics.Color
|
|
||||||
import androidx.compose.ui.res.painterResource
|
|
||||||
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 com.aiosman.ravenow.LocalAppTheme
|
|
||||||
import com.aiosman.ravenow.LocalNavController
|
|
||||||
import com.aiosman.ravenow.R
|
|
||||||
import com.aiosman.ravenow.ui.composables.StatusBarSpacer
|
|
||||||
import com.aiosman.ravenow.ui.comment.NoticeScreenHeader
|
|
||||||
import androidx.compose.runtime.mutableStateOf
|
|
||||||
import androidx.compose.runtime.remember
|
|
||||||
import androidx.compose.runtime.getValue
|
|
||||||
import androidx.compose.runtime.setValue
|
|
||||||
import androidx.compose.foundation.lazy.grid.GridCells
|
|
||||||
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
|
|
||||||
import androidx.compose.foundation.lazy.grid.items
|
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
|
||||||
import androidx.compose.foundation.layout.aspectRatio
|
|
||||||
import androidx.compose.foundation.shape.CircleShape
|
|
||||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
|
||||||
import androidx.compose.material3.IconButton
|
|
||||||
import androidx.compose.ui.graphics.Brush
|
|
||||||
import androidx.compose.ui.layout.ContentScale
|
|
||||||
import androidx.compose.ui.platform.LocalConfiguration
|
|
||||||
import androidx.compose.ui.text.style.TextAlign
|
|
||||||
import com.aiosman.ravenow.ui.composables.CustomAsyncImage
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun ChatSettingScreen() {
|
|
||||||
val appColors = LocalAppTheme.current
|
|
||||||
val navController = LocalNavController.current
|
|
||||||
var showThemeSheet by remember { mutableStateOf(false) }
|
|
||||||
|
|
||||||
Column(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxSize()
|
|
||||||
.background(appColors.secondaryBackground)
|
|
||||||
) {
|
|
||||||
StatusBarSpacer()
|
|
||||||
Box(modifier = Modifier.padding(horizontal = 24.dp, vertical = 16.dp)) {
|
|
||||||
NoticeScreenHeader(title = stringResource(R.string.chat_settings), moreIcon = false)
|
|
||||||
}
|
|
||||||
|
|
||||||
Column(modifier = Modifier.padding(horizontal = 16.dp)) {
|
|
||||||
SettingCard(
|
|
||||||
title = stringResource(R.string.chat_theme_settings),
|
|
||||||
onClick = { showThemeSheet = true }
|
|
||||||
)
|
|
||||||
Spacer(modifier = Modifier.height(12.dp))
|
|
||||||
SettingCard(
|
|
||||||
title = stringResource(R.string.report),
|
|
||||||
onClick = { /* TODO: 跳转举报 */ }
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (showThemeSheet) {
|
|
||||||
ThemePickerSheet(onClose = { showThemeSheet = false })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
private fun SettingCard(title: String, onClick: () -> Unit) {
|
|
||||||
val appColors = LocalAppTheme.current
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.clip(RoundedCornerShape(12.dp))
|
|
||||||
.background(appColors.background)
|
|
||||||
.clickable { onClick() }
|
|
||||||
.padding(horizontal = 12.dp, vertical = 14.dp)
|
|
||||||
) {
|
|
||||||
Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxWidth()) {
|
|
||||||
Text(
|
|
||||||
text = title,
|
|
||||||
color = appColors.text,
|
|
||||||
fontSize = 16.sp,
|
|
||||||
fontWeight = FontWeight.W500,
|
|
||||||
modifier = Modifier.weight(1f)
|
|
||||||
)
|
|
||||||
Icon(
|
|
||||||
painter = painterResource(id = R.drawable.rave_now_nav_right),
|
|
||||||
contentDescription = null,
|
|
||||||
tint = appColors.text,
|
|
||||||
modifier = Modifier.size(20.dp)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
|
||||||
@Composable
|
|
||||||
private fun ThemePickerSheet(onClose: () -> Unit) {
|
|
||||||
val appColors = LocalAppTheme.current
|
|
||||||
val sheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true)
|
|
||||||
val configuration = LocalConfiguration.current
|
|
||||||
val screenHeight = configuration.screenHeightDp.dp
|
|
||||||
val sheetHeight = screenHeight * 0.9f
|
|
||||||
var previewUrl by remember { mutableStateOf<String?>(null) }
|
|
||||||
ModalBottomSheet(
|
|
||||||
onDismissRequest = onClose,
|
|
||||||
sheetState = sheetState,
|
|
||||||
containerColor = appColors.secondaryBackground,
|
|
||||||
dragHandle = null,
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.height(sheetHeight),
|
|
||||||
) {
|
|
||||||
Column(modifier = Modifier.padding(horizontal = 16.dp)) {
|
|
||||||
Row(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(top = 4.dp, bottom = 8.dp),
|
|
||||||
verticalAlignment = Alignment.CenterVertically
|
|
||||||
) {
|
|
||||||
Spacer(modifier = Modifier.size(24.dp))
|
|
||||||
Text(
|
|
||||||
text = stringResource(R.string.custom_background),
|
|
||||||
color = appColors.text,
|
|
||||||
fontSize = 16.sp,
|
|
||||||
fontWeight = FontWeight.W600,
|
|
||||||
modifier = Modifier.weight(1f).padding(start = 90.dp),
|
|
||||||
)
|
|
||||||
IconButton(onClick = onClose) {
|
|
||||||
Icon(
|
|
||||||
painter = painterResource(id = R.drawable.rider_pro_close),
|
|
||||||
contentDescription = "close",
|
|
||||||
tint = appColors.text
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 从相册选择
|
|
||||||
Row(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.clip(RoundedCornerShape(12.dp))
|
|
||||||
.background(appColors.background)
|
|
||||||
.clickable { /* TODO: 打开相册选择 */ }
|
|
||||||
.padding(horizontal = 16.dp, vertical = 14.dp),
|
|
||||||
verticalAlignment = Alignment.CenterVertically
|
|
||||||
) {
|
|
||||||
Text(text = stringResource(R.string.select_from_gallery), color = appColors.text, fontSize = 15.sp, modifier = Modifier.weight(1f))
|
|
||||||
Icon(
|
|
||||||
painter = painterResource(id = R.drawable.group_info_edit),
|
|
||||||
contentDescription = null,
|
|
||||||
tint = appColors.text,
|
|
||||||
modifier = Modifier.size(20.dp)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(12.dp))
|
|
||||||
Text(text = stringResource(R.string.featured_backgrounds), color = appColors.text, fontSize = 12.sp)
|
|
||||||
Spacer(modifier = Modifier.height(8.dp))
|
|
||||||
|
|
||||||
val presets = remember {
|
|
||||||
listOf(
|
|
||||||
"https://picsum.photos/seed/ai1/400/600",
|
|
||||||
"https://picsum.photos/seed/ai2/400/600",
|
|
||||||
"https://picsum.photos/seed/ai3/400/600",
|
|
||||||
"https://picsum.photos/seed/ai4/400/600",
|
|
||||||
"https://picsum.photos/seed/ai5/400/600",
|
|
||||||
"https://picsum.photos/seed/ai6/400/600",
|
|
||||||
"https://picsum.photos/seed/ai7/400/600",
|
|
||||||
"https://picsum.photos/seed/ai8/400/600",
|
|
||||||
"https://picsum.photos/seed/ai9/400/600",
|
|
||||||
"https://picsum.photos/seed/ai10/400/600",
|
|
||||||
"https://picsum.photos/seed/ai11/400/600",
|
|
||||||
"https://picsum.photos/seed/ai12/400/600",
|
|
||||||
"https://picsum.photos/seed/ai13/400/600",
|
|
||||||
"https://picsum.photos/seed/ai14/400/600",
|
|
||||||
"https://picsum.photos/seed/ai15/400/600",
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
LazyVerticalGrid(
|
|
||||||
columns = GridCells.Fixed(3),
|
|
||||||
horizontalArrangement = Arrangement.spacedBy(12.dp),
|
|
||||||
verticalArrangement = Arrangement.spacedBy(12.dp),
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
) {
|
|
||||||
items(presets) { url ->
|
|
||||||
Column(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.clickable { previewUrl = url }
|
|
||||||
) {
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.clip(RoundedCornerShape(12.dp))
|
|
||||||
.background(appColors.decentBackground)
|
|
||||||
) {
|
|
||||||
CustomAsyncImage(
|
|
||||||
imageUrl = url,
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.aspectRatio(3f / 4f),
|
|
||||||
contentDescription = "preset",
|
|
||||||
contentScale = ContentScale.Crop
|
|
||||||
)
|
|
||||||
}
|
|
||||||
Spacer(modifier = Modifier.height(6.dp))
|
|
||||||
Text(
|
|
||||||
text = "Heart Drive",
|
|
||||||
color = appColors.text,
|
|
||||||
fontSize = 12.sp
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 预览自定义背景弹窗
|
|
||||||
if (previewUrl != null) {
|
|
||||||
ModalBottomSheet(
|
|
||||||
onDismissRequest = { previewUrl = null },
|
|
||||||
sheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true),
|
|
||||||
containerColor = appColors.secondaryBackground,
|
|
||||||
dragHandle = null,
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.height(sheetHeight)
|
|
||||||
) {
|
|
||||||
Box(modifier = Modifier.fillMaxSize()) {
|
|
||||||
CustomAsyncImage(
|
|
||||||
imageUrl = previewUrl!!,
|
|
||||||
modifier = Modifier.fillMaxSize(),
|
|
||||||
contentDescription = "preview_bg",
|
|
||||||
contentScale = ContentScale.Crop
|
|
||||||
)
|
|
||||||
|
|
||||||
Column(modifier = Modifier
|
|
||||||
.fillMaxSize()
|
|
||||||
.padding(horizontal = 16.dp, vertical = 8.dp)) {
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.align(Alignment.CenterHorizontally)
|
|
||||||
.padding(horizontal = 12.dp, vertical = 16.dp)
|
|
||||||
) {
|
|
||||||
Text(text = stringResource(R.string.previewing_custom_background), color = Color.White, fontSize = 15.sp)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Column(modifier = Modifier.padding(8.dp)) {
|
|
||||||
Row {
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.clip(RoundedCornerShape(24.dp))
|
|
||||||
.background(Color.White)
|
|
||||||
.padding(horizontal = 14.dp, vertical = 8.dp)
|
|
||||||
) {
|
|
||||||
Text(text = stringResource(R.string.each_theme_unique_experience), color = Color.Black, fontSize = 12.sp)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Spacer(modifier = Modifier.height(12.dp))
|
|
||||||
Row {
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.clip(RoundedCornerShape(24.dp))
|
|
||||||
.background(Color.White)
|
|
||||||
.padding(horizontal = 14.dp, vertical = 8.dp)
|
|
||||||
) {
|
|
||||||
Text(text = stringResource(R.string.select_apply_to_use_theme), color = Color.Black, fontSize = 12.sp)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Spacer(modifier = Modifier.height(12.dp))
|
|
||||||
Row {
|
|
||||||
Spacer(modifier = Modifier.weight(1f))
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.clip(RoundedCornerShape(20.dp))
|
|
||||||
.background(Color(0xFF7C4DFF))
|
|
||||||
.padding(horizontal = 16.dp, vertical = 8.dp)
|
|
||||||
) {
|
|
||||||
Text(text = stringResource(R.string.tap_cancel_to_preview_other_themes), color = Color.White, fontSize = 12.sp)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Spacer(modifier = Modifier.weight(1f))
|
|
||||||
|
|
||||||
// 底部按钮
|
|
||||||
Row(
|
|
||||||
modifier = Modifier.fillMaxWidth()
|
|
||||||
.padding(bottom = 60.dp),
|
|
||||||
verticalAlignment = Alignment.CenterVertically
|
|
||||||
) {
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.weight(1f)
|
|
||||||
.clip(RoundedCornerShape(12.dp))
|
|
||||||
.background(Color.White)
|
|
||||||
.clickable { previewUrl = null }
|
|
||||||
.padding(vertical = 12.dp),
|
|
||||||
contentAlignment = Alignment.Center
|
|
||||||
) {
|
|
||||||
Text(text = stringResource(R.string.cancel), color = Color.Black, fontSize = 14.sp)
|
|
||||||
}
|
|
||||||
Spacer(modifier = Modifier.size(12.dp))
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.weight(1f)
|
|
||||||
.clip(RoundedCornerShape(12.dp))
|
|
||||||
.background(
|
|
||||||
brush = Brush.horizontalGradient(
|
|
||||||
colors = listOf(
|
|
||||||
Color(0xFFEE2A33),
|
|
||||||
Color(0xFFD80264),
|
|
||||||
Color(0xFF664C92)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.clickable {
|
|
||||||
previewUrl?.let { url ->
|
|
||||||
com.aiosman.ravenow.AppStore.saveChatBackgroundUrl(url)
|
|
||||||
previewUrl = null
|
|
||||||
onClose()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.padding(vertical = 12.dp),
|
|
||||||
contentAlignment = Alignment.Center
|
|
||||||
) {
|
|
||||||
Text(text = stringResource(R.string.moment_ai_apply), color = Color.White, fontSize = 14.sp)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@@ -125,13 +125,12 @@ fun CommentNoticeScreen() {
|
|||||||
) {
|
) {
|
||||||
androidx.compose.foundation.Image(
|
androidx.compose.foundation.Image(
|
||||||
painter = painterResource(
|
painter = painterResource(
|
||||||
id = if(AppState.darkMode) R.mipmap.tietie_dark
|
id =if(AppState.darkMode) R.mipmap.qst_pl_qs_as_img
|
||||||
else R.mipmap.invalid_name_11),
|
else R.mipmap.invalid_name_11),
|
||||||
contentDescription = "No Comment",
|
contentDescription = "No Comment",
|
||||||
modifier = Modifier
|
modifier = Modifier.size(181.dp)
|
||||||
.size(width = 181.dp, height = 153.dp)
|
|
||||||
)
|
)
|
||||||
Spacer(modifier = Modifier.height(24.dp))
|
Spacer(modifier = Modifier.size(24.dp))
|
||||||
Text(
|
Text(
|
||||||
text = "等一位旅人~",
|
text = "等一位旅人~",
|
||||||
color = AppColors.text,
|
color = AppColors.text,
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ import androidx.compose.runtime.getValue
|
|||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.clip
|
import androidx.compose.ui.draw.clip
|
||||||
import androidx.compose.ui.graphics.Brush
|
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.compose.ui.text.style.TextAlign
|
import androidx.compose.ui.text.style.TextAlign
|
||||||
@@ -33,7 +32,6 @@ fun ActionButton(
|
|||||||
text: String,
|
text: String,
|
||||||
color: Color? = null,
|
color: Color? = null,
|
||||||
backgroundColor: Color? = null,
|
backgroundColor: Color? = null,
|
||||||
backgroundBrush: Brush? = null,
|
|
||||||
leading: @Composable (() -> Unit)? = null,
|
leading: @Composable (() -> Unit)? = null,
|
||||||
expandText: Boolean = false,
|
expandText: Boolean = false,
|
||||||
contentPadding: PaddingValues = PaddingValues(vertical = 16.dp),
|
contentPadding: PaddingValues = PaddingValues(vertical = 16.dp),
|
||||||
@@ -67,11 +65,7 @@ fun ActionButton(
|
|||||||
Box(
|
Box(
|
||||||
modifier = modifier
|
modifier = modifier
|
||||||
.clip(RoundedCornerShape(roundCorner.dp))
|
.clip(RoundedCornerShape(roundCorner.dp))
|
||||||
.background(
|
.background(animatedBackgroundColor)
|
||||||
brush = backgroundBrush ?: Brush.linearGradient(
|
|
||||||
colors = listOf(animatedBackgroundColor, animatedBackgroundColor)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.noRippleClickable {
|
.noRippleClickable {
|
||||||
if (enabled && !isLoading) {
|
if (enabled && !isLoading) {
|
||||||
click()
|
click()
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import androidx.compose.animation.togetherWith
|
|||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.text.style.TextOverflow
|
|
||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
import com.aiosman.ravenow.LocalAppTheme
|
import com.aiosman.ravenow.LocalAppTheme
|
||||||
|
|
||||||
@@ -37,13 +36,6 @@ fun AnimatedCounter(count: Int, modifier: Modifier = Modifier, fontSize: Int = 2
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
) { targetCount ->
|
) { targetCount ->
|
||||||
Text(
|
Text(text = "$targetCount", modifier = modifier, fontSize = fontSize.sp, color = AppColors.text)
|
||||||
text = "$targetCount",
|
|
||||||
modifier = modifier,
|
|
||||||
fontSize = fontSize.sp,
|
|
||||||
color = AppColors.text,
|
|
||||||
maxLines = 1,
|
|
||||||
overflow = TextOverflow.Ellipsis
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -56,14 +56,15 @@ fun AnimatedFavouriteIcon(
|
|||||||
}) {
|
}) {
|
||||||
Image(
|
Image(
|
||||||
painter = if (isFavourite) {
|
painter = if (isFavourite) {
|
||||||
painterResource(id = R.mipmap.icon_variant_2)
|
painterResource(id = R.drawable.rider_pro_favourited)
|
||||||
} else {
|
} else {
|
||||||
painterResource(id = R.mipmap.icon_collect)
|
painterResource(id = R.drawable.rider_pro_favourite)
|
||||||
},
|
},
|
||||||
contentDescription = "Favourite",
|
contentDescription = "Favourite",
|
||||||
modifier = modifier.graphicsLayer {
|
modifier = modifier.graphicsLayer {
|
||||||
rotationZ = animatableRotation.value
|
rotationZ = animatableRotation.value
|
||||||
},
|
},
|
||||||
|
colorFilter = ColorFilter.tint(AppColors.text)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -51,8 +51,7 @@ import com.aiosman.ravenow.ui.modifiers.noRippleClickable
|
|||||||
@Composable
|
@Composable
|
||||||
fun EditCommentBottomModal(
|
fun EditCommentBottomModal(
|
||||||
replyComment: CommentEntity? = null,
|
replyComment: CommentEntity? = null,
|
||||||
autoFocus: Boolean = false,
|
onSend: (String) -> Unit = {}
|
||||||
onSend: (String) -> Unit = {},
|
|
||||||
) {
|
) {
|
||||||
val AppColors = LocalAppTheme.current
|
val AppColors = LocalAppTheme.current
|
||||||
var text by remember { mutableStateOf("") }
|
var text by remember { mutableStateOf("") }
|
||||||
@@ -60,10 +59,8 @@ fun EditCommentBottomModal(
|
|||||||
val focusRequester = remember { FocusRequester() }
|
val focusRequester = remember { FocusRequester() }
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
|
|
||||||
LaunchedEffect(autoFocus) {
|
LaunchedEffect(Unit) {
|
||||||
if (autoFocus) {
|
focusRequester.requestFocus()
|
||||||
focusRequester.requestFocus()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Column(
|
Column(
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import androidx.compose.runtime.Composable
|
|||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.clip
|
import androidx.compose.ui.draw.clip
|
||||||
import androidx.compose.ui.graphics.Color
|
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.text.TextStyle
|
import androidx.compose.ui.text.TextStyle
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
@@ -33,7 +32,7 @@ fun FollowButton(
|
|||||||
.wrapContentWidth()
|
.wrapContentWidth()
|
||||||
.clip(RoundedCornerShape(8.dp))
|
.clip(RoundedCornerShape(8.dp))
|
||||||
.background(
|
.background(
|
||||||
color = if (isFollowing) AppColors.nonActive else AppColors.nonActive
|
color = if (isFollowing) AppColors.main else AppColors.nonActive
|
||||||
)
|
)
|
||||||
.padding(horizontal = 16.dp, vertical = 8.dp)
|
.padding(horizontal = 16.dp, vertical = 8.dp)
|
||||||
.noRippleClickable {
|
.noRippleClickable {
|
||||||
@@ -42,9 +41,11 @@ fun FollowButton(
|
|||||||
contentAlignment = Alignment.Center
|
contentAlignment = Alignment.Center
|
||||||
) {
|
) {
|
||||||
Text(
|
Text(
|
||||||
text = if (isFollowing) stringResource(R.string.follow_upper_had) else stringResource(R.string.follow_upper),
|
text = if (isFollowing) stringResource(R.string.following_upper) else stringResource(
|
||||||
|
R.string.follow_upper
|
||||||
|
),
|
||||||
fontSize = fontSize,
|
fontSize = fontSize,
|
||||||
color = if (isFollowing) AppColors.text else AppColors.text,
|
color = if (isFollowing) AppColors.mainText else AppColors.text,
|
||||||
style = TextStyle(fontWeight = FontWeight.Bold)
|
style = TextStyle(fontWeight = FontWeight.Bold)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -364,6 +364,16 @@ fun MomentContentGroup(
|
|||||||
onPageChange: (Int) -> Unit = {}
|
onPageChange: (Int) -> Unit = {}
|
||||||
) {
|
) {
|
||||||
val AppColors = LocalAppTheme.current
|
val AppColors = LocalAppTheme.current
|
||||||
|
if (momentEntity.momentTextContent.isNotEmpty()) {
|
||||||
|
Text(
|
||||||
|
text = momentEntity.momentTextContent,
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(start = 16.dp, end = 16.dp, bottom = 8.dp),
|
||||||
|
fontSize = 16.sp,
|
||||||
|
color = AppColors.text
|
||||||
|
)
|
||||||
|
}
|
||||||
if (momentEntity.relMoment != null) {
|
if (momentEntity.relMoment != null) {
|
||||||
RelPostCard(
|
RelPostCard(
|
||||||
momentEntity = momentEntity.relMoment!!,
|
momentEntity = momentEntity.relMoment!!,
|
||||||
@@ -379,17 +389,6 @@ fun MomentContentGroup(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (momentEntity.momentTextContent.isNotEmpty()) {
|
|
||||||
Text(
|
|
||||||
text = momentEntity.momentTextContent,
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(start = 16.dp, end = 16.dp, top = 8.dp),
|
|
||||||
fontSize = 16.sp,
|
|
||||||
color = AppColors.text
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -402,15 +401,14 @@ fun MomentOperateBtn(@DrawableRes icon: Int, count: String) {
|
|||||||
.size(width = 24.dp, height = 24.dp),
|
.size(width = 24.dp, height = 24.dp),
|
||||||
painter = painterResource(id = icon),
|
painter = painterResource(id = icon),
|
||||||
contentDescription = "",
|
contentDescription = "",
|
||||||
|
colorFilter = ColorFilter.tint(AppColors.text)
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
text = count,
|
||||||
|
modifier = Modifier.padding(start = 7.dp),
|
||||||
|
fontSize = 14.sp,
|
||||||
|
color = AppColors.text
|
||||||
)
|
)
|
||||||
if (count.isNotEmpty()) {
|
|
||||||
Text(
|
|
||||||
text = count,
|
|
||||||
modifier = Modifier.padding(start = 7.dp),
|
|
||||||
fontSize = 14.sp,
|
|
||||||
color = AppColors.text
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -426,6 +424,7 @@ fun MomentOperateBtn(count: String, content: @Composable () -> Unit) {
|
|||||||
fontSize = 14,
|
fontSize = 14,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.padding(start = 7.dp)
|
.padding(start = 7.dp)
|
||||||
|
.width(24.dp)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -511,11 +510,49 @@ fun MomentBottomOperateRowGroup(
|
|||||||
.weight(1f),
|
.weight(1f),
|
||||||
verticalAlignment = Alignment.CenterVertically
|
verticalAlignment = Alignment.CenterVertically
|
||||||
) {
|
) {
|
||||||
Row(
|
Box(
|
||||||
modifier = Modifier.weight(1f).fillMaxHeight(),
|
modifier = Modifier
|
||||||
verticalAlignment = Alignment.CenterVertically
|
.weight(1f)
|
||||||
|
.fillMaxHeight(),
|
||||||
|
contentAlignment = Alignment.CenterStart
|
||||||
|
) {
|
||||||
|
MomentOperateBtn(count = momentEntity.favoriteCount.toString()) {
|
||||||
|
AnimatedFavouriteIcon(
|
||||||
|
modifier = Modifier.size(24.dp),
|
||||||
|
isFavourite = momentEntity.isFavorite
|
||||||
|
) {
|
||||||
|
onFavoriteClick()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.wrapContentWidth()
|
||||||
|
.fillMaxHeight()
|
||||||
|
.noRippleClickable {
|
||||||
|
val currentTime = System.currentTimeMillis()
|
||||||
|
if (currentTime - lastClickTime.value > clickDelay) {
|
||||||
|
lastClickTime.value = currentTime
|
||||||
|
onCommentClick()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
contentAlignment = Alignment.CenterEnd
|
||||||
|
) {
|
||||||
|
MomentOperateBtn(
|
||||||
|
icon = R.drawable.rider_pro_comment,
|
||||||
|
count = momentEntity.commentCount.toString()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
Spacer(modifier = Modifier.width(24.dp))
|
||||||
|
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.wrapContentWidth()
|
||||||
|
.fillMaxHeight(),
|
||||||
|
contentAlignment = Alignment.CenterEnd
|
||||||
) {
|
) {
|
||||||
// 点赞按钮
|
|
||||||
MomentOperateBtn(count = momentEntity.likeCount.toString()) {
|
MomentOperateBtn(count = momentEntity.likeCount.toString()) {
|
||||||
AnimatedLikeIcon(
|
AnimatedLikeIcon(
|
||||||
modifier = Modifier.size(24.dp),
|
modifier = Modifier.size(24.dp),
|
||||||
@@ -524,44 +561,6 @@ fun MomentBottomOperateRowGroup(
|
|||||||
onLikeClick()
|
onLikeClick()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Spacer(modifier = Modifier.width(10.dp))
|
|
||||||
// 评论按钮
|
|
||||||
Box(
|
|
||||||
modifier = Modifier.noRippleClickable {
|
|
||||||
val currentTime = System.currentTimeMillis()
|
|
||||||
if (currentTime - lastClickTime.value > clickDelay) {
|
|
||||||
lastClickTime.value = currentTime
|
|
||||||
onCommentClick()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
) {
|
|
||||||
MomentOperateBtn(
|
|
||||||
icon = R.mipmap.icon_comment,
|
|
||||||
count = momentEntity.commentCount.toString()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
Spacer(modifier = Modifier.width(28.dp))
|
|
||||||
// 转发按钮
|
|
||||||
Box(
|
|
||||||
modifier = Modifier.noRippleClickable {
|
|
||||||
// TODO: 实现转发功能
|
|
||||||
}
|
|
||||||
) {
|
|
||||||
MomentOperateBtn(
|
|
||||||
icon = R.mipmap.icon_share,
|
|
||||||
count = ""
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 收藏按钮
|
|
||||||
MomentOperateBtn(count = momentEntity.favoriteCount.toString()) {
|
|
||||||
AnimatedFavouriteIcon(
|
|
||||||
modifier = Modifier.size(24.dp),
|
|
||||||
isFavourite = momentEntity.isFavorite
|
|
||||||
) {
|
|
||||||
onFavoriteClick()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,10 @@
|
|||||||
package com.aiosman.ravenow.ui.composables
|
package com.aiosman.ravenow.ui.composables
|
||||||
|
|
||||||
import androidx.compose.foundation.Image
|
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Box
|
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.Spacer
|
import androidx.compose.foundation.layout.Spacer
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
|
||||||
import androidx.compose.foundation.layout.height
|
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.layout.size
|
|
||||||
import androidx.compose.foundation.layout.width
|
import androidx.compose.foundation.layout.width
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
@@ -17,14 +12,11 @@ import androidx.compose.runtime.Composable
|
|||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.clip
|
import androidx.compose.ui.draw.clip
|
||||||
import androidx.compose.ui.res.painterResource
|
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
import com.aiosman.ravenow.LocalAppTheme
|
import com.aiosman.ravenow.LocalAppTheme
|
||||||
import com.aiosman.ravenow.R
|
|
||||||
import com.aiosman.ravenow.ui.modifiers.noRippleClickable
|
import com.aiosman.ravenow.ui.modifiers.noRippleClickable
|
||||||
import androidx.compose.ui.graphics.Brush
|
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
|
||||||
/**
|
/**
|
||||||
* 可复用的标签页组件
|
* 可复用的标签页组件
|
||||||
*/
|
*/
|
||||||
@@ -62,43 +54,3 @@ fun TabItem(
|
|||||||
fun TabSpacer() {
|
fun TabSpacer() {
|
||||||
Spacer(modifier = Modifier.width(8.dp))
|
Spacer(modifier = Modifier.width(8.dp))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun UnderlineTabItem(
|
|
||||||
text: String,
|
|
||||||
isSelected: Boolean,
|
|
||||||
onClick: () -> Unit,
|
|
||||||
modifier: Modifier = Modifier
|
|
||||||
) {
|
|
||||||
val AppColors = LocalAppTheme.current
|
|
||||||
|
|
||||||
Column(
|
|
||||||
modifier = modifier
|
|
||||||
.noRippleClickable { onClick() },
|
|
||||||
verticalArrangement = Arrangement.Center,
|
|
||||||
horizontalAlignment = Alignment.CenterHorizontally
|
|
||||||
) {
|
|
||||||
Text(
|
|
||||||
text = text,
|
|
||||||
fontSize = 15.sp,
|
|
||||||
fontWeight = FontWeight.ExtraBold,
|
|
||||||
color = if (isSelected) AppColors.text else AppColors.text.copy(alpha = 0.6f),
|
|
||||||
modifier = Modifier.padding(horizontal = 16.dp).padding(top = 13.dp)
|
|
||||||
)
|
|
||||||
|
|
||||||
// 选中状态下显示图标
|
|
||||||
Box(
|
|
||||||
modifier = Modifier.size(24.dp),
|
|
||||||
contentAlignment = Alignment.Center
|
|
||||||
) {
|
|
||||||
if (isSelected) {
|
|
||||||
Image(
|
|
||||||
painter = painterResource(id = R.mipmap.underline),
|
|
||||||
contentDescription = "selected indicator",
|
|
||||||
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -43,10 +43,6 @@ import com.aiosman.ravenow.LocalAppTheme
|
|||||||
import com.aiosman.ravenow.R
|
import com.aiosman.ravenow.R
|
||||||
import com.aiosman.ravenow.ui.modifiers.noRippleClickable
|
import com.aiosman.ravenow.ui.modifiers.noRippleClickable
|
||||||
|
|
||||||
private val LabelTextColor = Color(red = 60f / 255f, green = 60f / 255f, blue = 67f / 255f, alpha = 0.6f)
|
|
||||||
private val HintTextColor = Color(red = 60f / 255f, green = 60f / 255f, blue = 67f / 255f, alpha = 0.3f)
|
|
||||||
private val PasswordIconColor = Color(red = 17f / 255f, green = 12f / 255f, blue = 19f / 255f)
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun TextInputField(
|
fun TextInputField(
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
@@ -56,96 +52,69 @@ fun TextInputField(
|
|||||||
label: String? = null,
|
label: String? = null,
|
||||||
hint: String? = null,
|
hint: String? = null,
|
||||||
error: String? = null,
|
error: String? = null,
|
||||||
enabled: Boolean = true,
|
enabled: Boolean = true
|
||||||
leadingIcon: @Composable (() -> Unit)? = null,
|
|
||||||
customBackgroundColor: Color? = null,
|
|
||||||
customCornerRadius: Float = 24f
|
|
||||||
) {
|
) {
|
||||||
val AppColors = LocalAppTheme.current
|
val AppColors = LocalAppTheme.current
|
||||||
var showPassword by remember { mutableStateOf(!password) }
|
var showPassword by remember { mutableStateOf(!password) }
|
||||||
var isFocused by remember { mutableStateOf(false) }
|
var isFocused by remember { mutableStateOf(false) }
|
||||||
val backgroundColor = customBackgroundColor ?: AppColors.inputBackground
|
|
||||||
Column(modifier = modifier) {
|
Column(modifier = modifier) {
|
||||||
label?.let {
|
label?.let {
|
||||||
Text(
|
Text(it, color = AppColors.secondaryText)
|
||||||
text = it,
|
Spacer(modifier = Modifier.height(16.dp))
|
||||||
color = LabelTextColor,
|
|
||||||
fontSize = 13.sp,
|
|
||||||
modifier = Modifier.padding(start = 8.dp, top = 8.dp, bottom = 8.dp)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
Box(
|
Box(
|
||||||
contentAlignment = Alignment.CenterStart,
|
contentAlignment = Alignment.CenterStart,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.clip(RoundedCornerShape(customCornerRadius.dp))
|
.clip(RoundedCornerShape(24.dp))
|
||||||
.background(backgroundColor)
|
.background(AppColors.inputBackground)
|
||||||
.border(
|
.border(
|
||||||
width = 2.dp,
|
width = 2.dp,
|
||||||
color = if (error == null) Color.Transparent else AppColors.error,
|
color = if (error == null) Color.Transparent else AppColors.error,
|
||||||
shape = RoundedCornerShape(customCornerRadius.dp)
|
shape = RoundedCornerShape(24.dp)
|
||||||
)
|
)
|
||||||
.padding(horizontal = 16.dp, vertical = 16.dp)
|
.padding(horizontal = 16.dp, vertical = 16.dp)
|
||||||
) {
|
) {
|
||||||
Row(
|
Row(verticalAlignment = Alignment.CenterVertically){
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
BasicTextField(
|
||||||
modifier = Modifier.fillMaxWidth()
|
value = text,
|
||||||
){
|
onValueChange = onValueChange,
|
||||||
leadingIcon?.let {
|
modifier = Modifier
|
||||||
Box(modifier = Modifier.size(24.dp)) {
|
.weight(1f)
|
||||||
it()
|
.onFocusChanged { focusState ->
|
||||||
}
|
isFocused = focusState.isFocused
|
||||||
Spacer(modifier = Modifier.size(12.dp))
|
},
|
||||||
}
|
textStyle = TextStyle(
|
||||||
Box(modifier = Modifier.weight(1f)) {
|
fontSize = 16.sp,
|
||||||
BasicTextField(
|
fontWeight = FontWeight.W500,
|
||||||
value = text,
|
color = AppColors.text
|
||||||
onValueChange = onValueChange,
|
),
|
||||||
modifier = Modifier
|
keyboardOptions = KeyboardOptions(
|
||||||
.fillMaxWidth()
|
keyboardType = if (password) KeyboardType.Password else KeyboardType.Text
|
||||||
.onFocusChanged { focusState ->
|
),
|
||||||
isFocused = focusState.isFocused
|
visualTransformation = if (showPassword) VisualTransformation.None else PasswordVisualTransformation(),
|
||||||
},
|
singleLine = true,
|
||||||
textStyle = TextStyle(
|
enabled = enabled,
|
||||||
fontSize = 16.sp,
|
cursorBrush = SolidColor(AppColors.text),
|
||||||
fontWeight = FontWeight.W400,
|
)
|
||||||
color = AppColors.text
|
|
||||||
),
|
|
||||||
keyboardOptions = KeyboardOptions(
|
|
||||||
keyboardType = if (password) KeyboardType.Password else KeyboardType.Email
|
|
||||||
),
|
|
||||||
visualTransformation = if (showPassword) VisualTransformation.None else PasswordVisualTransformation(),
|
|
||||||
singleLine = true,
|
|
||||||
enabled = enabled,
|
|
||||||
cursorBrush = SolidColor(AppColors.text),
|
|
||||||
)
|
|
||||||
if (text.isEmpty() && hint != null) {
|
|
||||||
Text(
|
|
||||||
text = hint,
|
|
||||||
color = HintTextColor,
|
|
||||||
fontSize = 16.sp,
|
|
||||||
fontWeight = FontWeight.W400
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (password) {
|
if (password) {
|
||||||
Image(
|
Image(
|
||||||
painter = painterResource(
|
painter = painterResource(id = R.drawable.rider_pro_eye),
|
||||||
id = if (showPassword) {
|
|
||||||
R.drawable.rider_pro_eye
|
|
||||||
} else {
|
|
||||||
R.mipmap.icon_eyes_closed_light
|
|
||||||
}
|
|
||||||
),
|
|
||||||
contentDescription = "Password",
|
contentDescription = "Password",
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.size(24.dp)
|
.size(18.dp)
|
||||||
.noRippleClickable {
|
.noRippleClickable {
|
||||||
showPassword = !showPassword
|
showPassword = !showPassword
|
||||||
},
|
},
|
||||||
colorFilter = ColorFilter.tint(PasswordIconColor)
|
colorFilter = ColorFilter.tint(AppColors.text)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (text.isEmpty()) {
|
||||||
|
hint?.let {
|
||||||
|
Text(it, modifier = Modifier.padding(start = 5.dp), color = AppColors.inputHint, fontWeight = FontWeight.W600)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Spacer(modifier = Modifier.height(8.dp))
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
Row(
|
Row(
|
||||||
|
|||||||
@@ -134,12 +134,12 @@ fun FavouriteListPage() {
|
|||||||
) {
|
) {
|
||||||
Image(
|
Image(
|
||||||
painter = painterResource(
|
painter = painterResource(
|
||||||
id = if (com.aiosman.ravenow.AppState.darkMode) R.mipmap.invalid_dark
|
id = if (com.aiosman.ravenow.AppState.darkMode) R.mipmap.syss_yh_qs_as_img
|
||||||
else R.mipmap.invalid_name_1),
|
else R.mipmap.invalid_name_1),
|
||||||
contentDescription = "No favourites",
|
contentDescription = "No favourites",
|
||||||
modifier = Modifier.size(181.dp, 153.dp)
|
modifier = Modifier.size(110.dp)
|
||||||
)
|
)
|
||||||
Spacer(modifier = Modifier.size(9.dp)) // 调整间距为9dp
|
Spacer(modifier = Modifier.size(24.dp))
|
||||||
Text(
|
Text(
|
||||||
text = stringResource(R.string.favourites_null),
|
text = stringResource(R.string.favourites_null),
|
||||||
color = AppColors.text,
|
color = AppColors.text,
|
||||||
|
|||||||
@@ -24,8 +24,6 @@ import androidx.compose.ui.platform.LocalContext
|
|||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.compose.ui.text.style.TextAlign
|
|
||||||
import androidx.compose.ui.text.style.TextOverflow
|
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||||
@@ -126,32 +124,24 @@ fun FollowerListScreen(userId: Int) {
|
|||||||
) {
|
) {
|
||||||
Image(
|
Image(
|
||||||
painter = painterResource(
|
painter = painterResource(
|
||||||
id = if(AppState.darkMode) R.mipmap.frame_4
|
id =if(AppState.darkMode) R.mipmap.qst_fs_qs_as_img
|
||||||
else R.mipmap.invalid_name_8),
|
else R.mipmap.invalid_name_8),
|
||||||
contentDescription = null,
|
contentDescription = null,
|
||||||
modifier = Modifier.size(181.dp, 153.dp)
|
modifier = Modifier.size(181.dp)
|
||||||
)
|
)
|
||||||
Spacer(modifier = Modifier.size(9.dp)) // 调整间距为9dp
|
Spacer(modifier = Modifier.size(24.dp))
|
||||||
androidx.compose.material.Text(
|
androidx.compose.material.Text(
|
||||||
text = stringResource(R.string.follower_empty_title),
|
text = "还没有人关注哦",
|
||||||
color = appColors.text,
|
color = appColors.text,
|
||||||
fontSize = 16.sp,
|
fontSize = 16.sp,
|
||||||
fontWeight = FontWeight.W600,
|
fontWeight = FontWeight.W600
|
||||||
textAlign = TextAlign.Center,
|
|
||||||
modifier = Modifier.padding(horizontal = 24.dp),
|
|
||||||
maxLines = 2,
|
|
||||||
overflow = TextOverflow.Ellipsis
|
|
||||||
)
|
)
|
||||||
Spacer(modifier = Modifier.size(8.dp))
|
Spacer(modifier = Modifier.size(8.dp))
|
||||||
androidx.compose.material.Text(
|
androidx.compose.material.Text(
|
||||||
text = stringResource(R.string.follower_empty_subtitle),
|
text = "去发布动态,吸引更多粉丝~",
|
||||||
color = appColors.text,
|
color = appColors.text,
|
||||||
fontSize = 14.sp,
|
fontSize = 14.sp,
|
||||||
fontWeight = FontWeight.W400,
|
fontWeight = FontWeight.W400
|
||||||
textAlign = TextAlign.Center,
|
|
||||||
modifier = Modifier.padding(horizontal = 24.dp),
|
|
||||||
maxLines = 3,
|
|
||||||
overflow = TextOverflow.Ellipsis
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,8 +25,6 @@ import androidx.compose.ui.platform.LocalContext
|
|||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.compose.ui.text.style.TextAlign
|
|
||||||
import androidx.compose.ui.text.style.TextOverflow
|
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
import androidx.paging.compose.collectAsLazyPagingItems
|
import androidx.paging.compose.collectAsLazyPagingItems
|
||||||
@@ -116,33 +114,24 @@ fun FollowerNoticeScreen() {
|
|||||||
) {
|
) {
|
||||||
Image(
|
Image(
|
||||||
painter = painterResource(
|
painter = painterResource(
|
||||||
id = if(AppState.darkMode) R.mipmap.frame_4
|
id =if(AppState.darkMode) R.mipmap.qst_fs_qs_as_img
|
||||||
else R.mipmap.invalid_name_8),
|
else R.mipmap.invalid_name_8),
|
||||||
contentDescription = "No Followers",
|
contentDescription = "No Followers",
|
||||||
modifier = Modifier
|
modifier = Modifier.size(181.dp)
|
||||||
.size(width = 181.dp, height = 153.dp)
|
|
||||||
)
|
)
|
||||||
Spacer(modifier = Modifier.height(if (AppState.darkMode) 9.dp else 24.dp))
|
Spacer(modifier = Modifier.size(24.dp))
|
||||||
androidx.compose.material.Text(
|
androidx.compose.material.Text(
|
||||||
text = stringResource(R.string.follower_empty_title),
|
text = "还没有人关注哦",
|
||||||
color = AppColors.text,
|
color = AppColors.text,
|
||||||
fontSize = 16.sp,
|
fontSize = 16.sp,
|
||||||
fontWeight = FontWeight.W600,
|
fontWeight = FontWeight.W600
|
||||||
textAlign = TextAlign.Center,
|
|
||||||
modifier = Modifier.padding(horizontal = 24.dp),
|
|
||||||
maxLines = 2,
|
|
||||||
overflow = TextOverflow.Ellipsis
|
|
||||||
)
|
)
|
||||||
Spacer(modifier = Modifier.size(8.dp))
|
Spacer(modifier = Modifier.size(8.dp))
|
||||||
androidx.compose.material.Text(
|
androidx.compose.material.Text(
|
||||||
text = stringResource(R.string.follower_empty_subtitle),
|
text = "去发布动态,吸引更多粉丝~",
|
||||||
color = AppColors.text,
|
color = AppColors.text,
|
||||||
fontSize = 14.sp,
|
fontSize = 14.sp,
|
||||||
fontWeight = FontWeight.W400,
|
fontWeight = FontWeight.W400
|
||||||
textAlign = TextAlign.Center,
|
|
||||||
modifier = Modifier.padding(horizontal = 24.dp),
|
|
||||||
maxLines = 3,
|
|
||||||
overflow = TextOverflow.Ellipsis
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,8 +24,6 @@ import androidx.compose.ui.platform.LocalContext
|
|||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.compose.ui.text.style.TextAlign
|
|
||||||
import androidx.compose.ui.text.style.TextOverflow
|
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||||
@@ -128,32 +126,24 @@ fun FollowingListScreen(userId: Int) {
|
|||||||
) {
|
) {
|
||||||
Image(
|
Image(
|
||||||
painter = painterResource(
|
painter = painterResource(
|
||||||
id = if(AppState.darkMode) R.mipmap.frame_3
|
id =if(AppState.darkMode) R.mipmap.qst_gz_qs_as_img_my
|
||||||
else R.mipmap.invalid_name_9),
|
else R.mipmap.invalid_name_9),
|
||||||
contentDescription = null,
|
contentDescription = null,
|
||||||
modifier = Modifier.size(181.dp, 153.dp)
|
modifier = Modifier.size(181.dp)
|
||||||
)
|
)
|
||||||
Spacer(modifier = Modifier.size(9.dp)) // 调整间距为9dp
|
Spacer(modifier = Modifier.size(24.dp))
|
||||||
androidx.compose.material.Text(
|
androidx.compose.material.Text(
|
||||||
text = stringResource(R.string.following_empty_title),
|
text = "没有关注任何灵魂",
|
||||||
color = appColors.text,
|
color = appColors.text,
|
||||||
fontSize = 16.sp,
|
fontSize = 16.sp,
|
||||||
fontWeight = FontWeight.W600,
|
fontWeight = FontWeight.W600
|
||||||
textAlign = TextAlign.Center,
|
|
||||||
modifier = Modifier.padding(horizontal = 24.dp),
|
|
||||||
maxLines = 2,
|
|
||||||
overflow = TextOverflow.Ellipsis
|
|
||||||
)
|
)
|
||||||
Spacer(modifier = Modifier.size(8.dp))
|
Spacer(modifier = Modifier.size(8.dp))
|
||||||
androidx.compose.material.Text(
|
androidx.compose.material.Text(
|
||||||
text = stringResource(R.string.following_empty_subtitle),
|
text = "探索一下,总有一个你想靠近的光点 ✨",
|
||||||
color = appColors.secondaryText,
|
color = appColors.secondaryText,
|
||||||
fontSize = 14.sp,
|
fontSize = 14.sp,
|
||||||
fontWeight = FontWeight.W400,
|
fontWeight = FontWeight.W400
|
||||||
textAlign = TextAlign.Center,
|
|
||||||
modifier = Modifier.padding(horizontal = 24.dp),
|
|
||||||
maxLines = 3,
|
|
||||||
overflow = TextOverflow.Ellipsis
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package com.aiosman.ravenow.ui.group
|
package com.aiosman.ravenow.ui.group
|
||||||
|
|
||||||
import android.util.Log
|
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
@@ -9,11 +8,6 @@ import androidx.lifecycle.viewModelScope
|
|||||||
import com.aiosman.ravenow.AppStore
|
import com.aiosman.ravenow.AppStore
|
||||||
import com.aiosman.ravenow.ChatState
|
import com.aiosman.ravenow.ChatState
|
||||||
import com.aiosman.ravenow.data.api.ApiClient
|
import com.aiosman.ravenow.data.api.ApiClient
|
||||||
import com.aiosman.ravenow.data.api.AgentRule
|
|
||||||
import com.aiosman.ravenow.data.api.AgentRuleQuota
|
|
||||||
import com.aiosman.ravenow.data.api.CreateAgentRuleRequestBody
|
|
||||||
import com.aiosman.ravenow.data.api.UpdateAgentRuleRequestBody
|
|
||||||
import com.aiosman.ravenow.data.parseErrorResponse
|
|
||||||
import com.aiosman.ravenow.entity.ChatNotification
|
import com.aiosman.ravenow.entity.ChatNotification
|
||||||
import com.aiosman.ravenow.entity.GroupInfo
|
import com.aiosman.ravenow.entity.GroupInfo
|
||||||
import com.aiosman.ravenow.entity.GroupMember
|
import com.aiosman.ravenow.entity.GroupMember
|
||||||
@@ -28,36 +22,9 @@ class GroupChatInfoViewModel(
|
|||||||
var isLoading by mutableStateOf(false)
|
var isLoading by mutableStateOf(false)
|
||||||
var error by mutableStateOf<String?>(null)
|
var error by mutableStateOf<String?>(null)
|
||||||
var chatNotification by mutableStateOf<ChatNotification?>(null)
|
var chatNotification by mutableStateOf<ChatNotification?>(null)
|
||||||
var isAddingMemory by mutableStateOf(false)
|
|
||||||
var addMemoryError by mutableStateOf<String?>(null)
|
|
||||||
var addMemorySuccess by mutableStateOf(false)
|
|
||||||
val notificationStrategy get() = chatNotification?.strategy ?: "default"
|
val notificationStrategy get() = chatNotification?.strategy ?: "default"
|
||||||
|
|
||||||
// 记忆管理相关状态
|
|
||||||
var memoryQuota by mutableStateOf<AgentRuleQuota?>(null)
|
|
||||||
var memoryList by mutableStateOf<List<AgentRule>>(emptyList())
|
|
||||||
var isLoadingMemory by mutableStateOf(false)
|
|
||||||
var memoryError by mutableStateOf<String?>(null)
|
|
||||||
var promptOpenId by mutableStateOf<String?>(null)
|
|
||||||
init {
|
init {
|
||||||
loadGroupInfo()
|
loadGroupInfo()
|
||||||
loadPromptOpenId()
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取群聊中智能体的 OpenID
|
|
||||||
*/
|
|
||||||
private fun loadPromptOpenId() {
|
|
||||||
viewModelScope.launch {
|
|
||||||
try {
|
|
||||||
val response = ApiClient.api.createGroupChatAi(trtcGroupId = groupId)
|
|
||||||
val groupChatResponse = response.body()?.data
|
|
||||||
val prompts = groupChatResponse?.prompts
|
|
||||||
promptOpenId = prompts?.firstOrNull()?.openId
|
|
||||||
} catch (e: Exception) {
|
|
||||||
Log.e("GroupChatInfoViewModel", "获取智能体OpenID失败: ${e.message}", e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
suspend fun updateNotificationStrategy(strategy: String) {
|
suspend fun updateNotificationStrategy(strategy: String) {
|
||||||
val result = ChatState.updateChatNotification(groupId.hashCode(), strategy)
|
val result = ChatState.updateChatNotification(groupId.hashCode(), strategy)
|
||||||
@@ -104,218 +71,4 @@ class GroupChatInfoViewModel(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 添加群记忆
|
|
||||||
* @param memoryText 记忆内容
|
|
||||||
* @param promptOpenId 智能体的 OpenID(可选),如果不提供则从群聊信息中获取
|
|
||||||
*/
|
|
||||||
fun addGroupMemory(memoryText: String, promptOpenId: String? = null) {
|
|
||||||
viewModelScope.launch {
|
|
||||||
try {
|
|
||||||
isAddingMemory = true
|
|
||||||
addMemoryError = null
|
|
||||||
addMemorySuccess = false
|
|
||||||
|
|
||||||
// 如果没有提供 promptOpenId,需要先获取群聊的智能体信息
|
|
||||||
val openId = promptOpenId ?: run {
|
|
||||||
// 通过 createGroupChatAi 接口获取群聊详细信息(包含 prompts)
|
|
||||||
val response = ApiClient.api.createGroupChatAi(trtcGroupId = groupId)
|
|
||||||
val groupChatResponse = response.body()?.data
|
|
||||||
val prompts = groupChatResponse?.prompts
|
|
||||||
|
|
||||||
if (prompts.isNullOrEmpty()) {
|
|
||||||
throw Exception("群聊中没有找到智能体,无法添加记忆")
|
|
||||||
}
|
|
||||||
|
|
||||||
// 使用第一个智能体的 openId
|
|
||||||
prompts.firstOrNull()?.openId
|
|
||||||
?: throw Exception("无法获取智能体信息")
|
|
||||||
}
|
|
||||||
|
|
||||||
if (openId.isBlank()) {
|
|
||||||
throw Exception("智能体ID不能为空")
|
|
||||||
}
|
|
||||||
|
|
||||||
// 创建智能体规则(群记忆)
|
|
||||||
val requestBody = CreateAgentRuleRequestBody(
|
|
||||||
rule = memoryText,
|
|
||||||
openId = openId
|
|
||||||
)
|
|
||||||
|
|
||||||
val response = ApiClient.api.createAgentRule(requestBody)
|
|
||||||
|
|
||||||
if (response.isSuccessful) {
|
|
||||||
addMemorySuccess = true
|
|
||||||
Log.d("GroupChatInfoViewModel", "群记忆添加成功")
|
|
||||||
// 刷新记忆列表和配额
|
|
||||||
loadMemoryQuota(openId)
|
|
||||||
loadMemoryList(openId)
|
|
||||||
} else {
|
|
||||||
val errorResponse = parseErrorResponse(response.errorBody())
|
|
||||||
val errorMessage = errorResponse?.toServiceException()?.message
|
|
||||||
?: "添加群记忆失败: ${response.code()}"
|
|
||||||
throw Exception(errorMessage)
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
|
||||||
addMemoryError = e.message ?: "添加群记忆失败"
|
|
||||||
Log.e("GroupChatInfoViewModel", "添加群记忆失败: ${e.message}", e)
|
|
||||||
} finally {
|
|
||||||
isAddingMemory = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取记忆配额信息
|
|
||||||
*/
|
|
||||||
fun loadMemoryQuota(openId: String? = null) {
|
|
||||||
viewModelScope.launch {
|
|
||||||
try {
|
|
||||||
isLoadingMemory = true
|
|
||||||
memoryError = null
|
|
||||||
|
|
||||||
val targetOpenId = openId ?: promptOpenId
|
|
||||||
if (targetOpenId.isNullOrBlank()) {
|
|
||||||
// 如果还没有获取到 openId,先获取
|
|
||||||
val response = ApiClient.api.createGroupChatAi(trtcGroupId = groupId)
|
|
||||||
val groupChatResponse = response.body()?.data
|
|
||||||
val prompts = groupChatResponse?.prompts
|
|
||||||
val fetchedOpenId = prompts?.firstOrNull()?.openId
|
|
||||||
?: throw Exception("无法获取智能体信息")
|
|
||||||
|
|
||||||
promptOpenId = fetchedOpenId
|
|
||||||
val quotaResponse = ApiClient.api.getAgentRuleQuota(fetchedOpenId)
|
|
||||||
if (quotaResponse.isSuccessful) {
|
|
||||||
memoryQuota = quotaResponse.body()?.data
|
|
||||||
} else {
|
|
||||||
throw Exception("获取配额信息失败: ${quotaResponse.code()}")
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
val quotaResponse = ApiClient.api.getAgentRuleQuota(targetOpenId)
|
|
||||||
if (quotaResponse.isSuccessful) {
|
|
||||||
memoryQuota = quotaResponse.body()?.data
|
|
||||||
} else {
|
|
||||||
throw Exception("获取配额信息失败: ${quotaResponse.code()}")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
|
||||||
memoryError = e.message ?: "获取配额信息失败"
|
|
||||||
Log.e("GroupChatInfoViewModel", "获取配额信息失败: ${e.message}", e)
|
|
||||||
} finally {
|
|
||||||
isLoadingMemory = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取记忆列表
|
|
||||||
*/
|
|
||||||
fun loadMemoryList(openId: String? = null, page: Int = 1, pageSize: Int = 20) {
|
|
||||||
viewModelScope.launch {
|
|
||||||
try {
|
|
||||||
isLoadingMemory = true
|
|
||||||
memoryError = null
|
|
||||||
|
|
||||||
val targetOpenId = openId ?: promptOpenId
|
|
||||||
if (targetOpenId.isNullOrBlank()) {
|
|
||||||
// 如果还没有获取到 openId,先获取
|
|
||||||
val response = ApiClient.api.createGroupChatAi(trtcGroupId = groupId)
|
|
||||||
val groupChatResponse = response.body()?.data
|
|
||||||
val prompts = groupChatResponse?.prompts
|
|
||||||
val fetchedOpenId = prompts?.firstOrNull()?.openId
|
|
||||||
?: throw Exception("无法获取智能体信息")
|
|
||||||
|
|
||||||
promptOpenId = fetchedOpenId
|
|
||||||
val listResponse = ApiClient.api.getAgentRuleList(fetchedOpenId, page = page, pageSize = pageSize)
|
|
||||||
if (listResponse.isSuccessful) {
|
|
||||||
memoryList = listResponse.body()?.data?.list ?: emptyList()
|
|
||||||
} else {
|
|
||||||
throw Exception("获取记忆列表失败: ${listResponse.code()}")
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
val listResponse = ApiClient.api.getAgentRuleList(targetOpenId, page = page, pageSize = pageSize)
|
|
||||||
if (listResponse.isSuccessful) {
|
|
||||||
memoryList = listResponse.body()?.data?.list ?: emptyList()
|
|
||||||
} else {
|
|
||||||
throw Exception("获取记忆列表失败: ${listResponse.code()}")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
|
||||||
memoryError = e.message ?: "获取记忆列表失败"
|
|
||||||
Log.e("GroupChatInfoViewModel", "获取记忆列表失败: ${e.message}", e)
|
|
||||||
} finally {
|
|
||||||
isLoadingMemory = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除记忆
|
|
||||||
*/
|
|
||||||
fun deleteMemory(ruleId: Int) {
|
|
||||||
viewModelScope.launch {
|
|
||||||
try {
|
|
||||||
isLoadingMemory = true
|
|
||||||
memoryError = null
|
|
||||||
|
|
||||||
val response = ApiClient.api.deleteAgentRule(ruleId)
|
|
||||||
if (response.isSuccessful) {
|
|
||||||
// 刷新记忆列表和配额
|
|
||||||
promptOpenId?.let { openId ->
|
|
||||||
loadMemoryQuota(openId)
|
|
||||||
loadMemoryList(openId)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
val errorResponse = parseErrorResponse(response.errorBody())
|
|
||||||
val errorMessage = errorResponse?.toServiceException()?.message
|
|
||||||
?: "删除记忆失败: ${response.code()}"
|
|
||||||
throw Exception(errorMessage)
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
|
||||||
memoryError = e.message ?: "删除记忆失败"
|
|
||||||
Log.e("GroupChatInfoViewModel", "删除记忆失败: ${e.message}", e)
|
|
||||||
} finally {
|
|
||||||
isLoadingMemory = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新记忆
|
|
||||||
*/
|
|
||||||
fun updateMemory(ruleId: Int, newRuleText: String, targetOpenId: String? = null) {
|
|
||||||
viewModelScope.launch {
|
|
||||||
try {
|
|
||||||
isLoadingMemory = true
|
|
||||||
memoryError = null
|
|
||||||
|
|
||||||
val openId = targetOpenId ?: promptOpenId
|
|
||||||
?: throw Exception("无法获取智能体ID")
|
|
||||||
|
|
||||||
val requestBody = UpdateAgentRuleRequestBody(
|
|
||||||
id = ruleId,
|
|
||||||
rule = newRuleText,
|
|
||||||
openId = openId
|
|
||||||
)
|
|
||||||
|
|
||||||
val response = ApiClient.api.updateAgentRule(requestBody)
|
|
||||||
if (response.isSuccessful) {
|
|
||||||
// 刷新记忆列表和配额
|
|
||||||
loadMemoryQuota(openId)
|
|
||||||
loadMemoryList(openId)
|
|
||||||
} else {
|
|
||||||
val errorResponse = parseErrorResponse(response.errorBody())
|
|
||||||
val errorMessage = errorResponse?.toServiceException()?.message
|
|
||||||
?: "更新记忆失败: ${response.code()}"
|
|
||||||
throw Exception(errorMessage)
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
|
||||||
memoryError = e.message ?: "更新记忆失败"
|
|
||||||
Log.e("GroupChatInfoViewModel", "更新记忆失败: ${e.message}", e)
|
|
||||||
} finally {
|
|
||||||
isLoadingMemory = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,625 +0,0 @@
|
|||||||
package com.aiosman.ravenow.ui.group
|
|
||||||
|
|
||||||
import androidx.compose.foundation.background
|
|
||||||
import androidx.compose.foundation.layout.*
|
|
||||||
import androidx.compose.foundation.lazy.LazyColumn
|
|
||||||
import androidx.compose.foundation.lazy.items
|
|
||||||
import androidx.compose.foundation.shape.CircleShape
|
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
||||||
import androidx.compose.material3.CircularProgressIndicator
|
|
||||||
import androidx.compose.material3.Text
|
|
||||||
import androidx.compose.runtime.Composable
|
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
|
||||||
import androidx.compose.ui.Alignment
|
|
||||||
import androidx.compose.ui.Modifier
|
|
||||||
import androidx.compose.ui.draw.clip
|
|
||||||
import androidx.compose.ui.graphics.Color
|
|
||||||
import androidx.compose.ui.graphics.ColorFilter
|
|
||||||
import androidx.compose.ui.platform.LocalConfiguration
|
|
||||||
import androidx.compose.ui.res.painterResource
|
|
||||||
import androidx.compose.ui.text.TextStyle
|
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
|
||||||
import androidx.compose.ui.text.style.TextAlign
|
|
||||||
import androidx.compose.ui.text.style.TextOverflow
|
|
||||||
import androidx.compose.ui.unit.dp
|
|
||||||
import androidx.compose.ui.unit.sp
|
|
||||||
import com.aiosman.ravenow.LocalAppTheme
|
|
||||||
import com.aiosman.ravenow.R
|
|
||||||
import com.aiosman.ravenow.ui.modifiers.noRippleClickable
|
|
||||||
import androidx.compose.foundation.Image
|
|
||||||
import androidx.compose.foundation.text.BasicTextField
|
|
||||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
|
||||||
import androidx.compose.material3.ModalBottomSheet
|
|
||||||
import androidx.compose.material3.rememberModalBottomSheetState
|
|
||||||
import androidx.compose.runtime.getValue
|
|
||||||
import androidx.compose.runtime.mutableStateOf
|
|
||||||
import androidx.compose.runtime.remember
|
|
||||||
import androidx.compose.runtime.setValue
|
|
||||||
import androidx.compose.ui.graphics.SolidColor
|
|
||||||
import androidx.compose.ui.platform.LocalContext
|
|
||||||
import android.widget.Toast
|
|
||||||
import androidx.compose.ui.graphics.Brush
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun GroupMemoryManageContent(
|
|
||||||
groupId: String,
|
|
||||||
viewModel: GroupChatInfoViewModel,
|
|
||||||
onAddMemoryClick: () -> Unit = {},
|
|
||||||
onDismiss: () -> Unit = {}
|
|
||||||
) {
|
|
||||||
val AppColors = LocalAppTheme.current
|
|
||||||
val configuration = LocalConfiguration.current
|
|
||||||
val screenHeight = configuration.screenHeightDp.dp
|
|
||||||
val sheetHeight = screenHeight * 0.95f
|
|
||||||
val context = LocalContext.current
|
|
||||||
|
|
||||||
// 编辑记忆的状态 - 存储正在编辑的记忆ID
|
|
||||||
var editingMemoryId by remember { mutableStateOf<Int?>(null) }
|
|
||||||
|
|
||||||
// 加载配额和列表数据
|
|
||||||
LaunchedEffect(Unit) {
|
|
||||||
viewModel.loadMemoryQuota()
|
|
||||||
viewModel.loadMemoryList()
|
|
||||||
}
|
|
||||||
|
|
||||||
val quota = viewModel.memoryQuota
|
|
||||||
val memoryList = viewModel.memoryList
|
|
||||||
val isLoading = viewModel.isLoadingMemory
|
|
||||||
|
|
||||||
Column(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.height(sheetHeight)
|
|
||||||
.background(Color(0xFFFAF9FB))
|
|
||||||
) {
|
|
||||||
// 顶部栏:返回按钮 + 标题 + 加号按钮
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.height(44.dp)
|
|
||||||
.padding(horizontal = 16.dp)
|
|
||||||
) {
|
|
||||||
// 中间标题 - 绝对居中,不受其他组件影响
|
|
||||||
Text(
|
|
||||||
text = "记忆管理",
|
|
||||||
style = TextStyle(
|
|
||||||
color = Color.Black,
|
|
||||||
fontSize = 17.sp,
|
|
||||||
fontWeight = FontWeight.SemiBold
|
|
||||||
),
|
|
||||||
modifier = Modifier.align(Alignment.Center),
|
|
||||||
textAlign = TextAlign.Center
|
|
||||||
)
|
|
||||||
|
|
||||||
// 左侧返回按钮
|
|
||||||
Row(
|
|
||||||
modifier = Modifier
|
|
||||||
.align(Alignment.CenterStart)
|
|
||||||
.clip(RoundedCornerShape(296.dp))
|
|
||||||
.background(Color.White) // 浅灰色背景
|
|
||||||
.noRippleClickable { onDismiss() }
|
|
||||||
.padding(horizontal = 12.dp, vertical = 8.dp),
|
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
|
||||||
horizontalArrangement = Arrangement.spacedBy(4.dp)
|
|
||||||
) {
|
|
||||||
Image(
|
|
||||||
painter = painterResource(R.drawable.rider_pro_back_icon),
|
|
||||||
contentDescription = "返回",
|
|
||||||
modifier = Modifier.size(16.dp),
|
|
||||||
colorFilter = ColorFilter.tint(Color.Black)
|
|
||||||
)
|
|
||||||
Text(
|
|
||||||
text = "返回",
|
|
||||||
style = TextStyle(
|
|
||||||
color = Color.Black,
|
|
||||||
fontSize = 15.sp,
|
|
||||||
fontWeight = FontWeight.Normal
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 右侧圆形加号按钮
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.align(Alignment.CenterEnd)
|
|
||||||
.size(32.dp)
|
|
||||||
.clip(CircleShape)
|
|
||||||
.background(Color.White)
|
|
||||||
.noRippleClickable { onAddMemoryClick() },
|
|
||||||
contentAlignment = Alignment.Center
|
|
||||||
) {
|
|
||||||
Text(
|
|
||||||
text = "+",
|
|
||||||
style = TextStyle(
|
|
||||||
color = Color.Black,
|
|
||||||
fontSize = 20.sp,
|
|
||||||
fontWeight = FontWeight.Medium
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 浅黄色提示栏 - 显示真实的配额数据
|
|
||||||
Row(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.background(Color(0xFFFBF8EF))
|
|
||||||
.padding(horizontal = 16.dp, vertical = 12.dp),
|
|
||||||
horizontalArrangement = Arrangement.SpaceBetween,
|
|
||||||
verticalAlignment = Alignment.CenterVertically
|
|
||||||
) {
|
|
||||||
Row(horizontalArrangement = Arrangement.spacedBy(16.dp), verticalAlignment = Alignment.CenterVertically) {
|
|
||||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
|
||||||
Text("已付费:", style = TextStyle(color = Color(0x993C3C43), fontSize = 13.sp))
|
|
||||||
Spacer(Modifier.width(3.dp))
|
|
||||||
Text(
|
|
||||||
"${quota?.purchasedCount ?: 0}",
|
|
||||||
style = TextStyle(color = Color(0xFFFF8D28), fontSize = 13.sp)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
|
||||||
Text("已使用:", style = TextStyle(color = Color(0x993C3C43), fontSize = 13.sp))
|
|
||||||
Spacer(Modifier.width(3.dp))
|
|
||||||
Text(
|
|
||||||
"${quota?.currentCount ?: 0}",
|
|
||||||
style = TextStyle(color = Color(0xFFFF8D28), fontSize = 13.sp)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
|
||||||
Text("可用上限:", style = TextStyle(color = Color(0x993C3C43), fontSize = 13.sp))
|
|
||||||
Spacer(Modifier.width(3.dp))
|
|
||||||
Text(
|
|
||||||
"50",
|
|
||||||
style = TextStyle(color = Color(0xFFFF8D28), fontSize = 13.sp)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 记忆列表或空状态
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.weight(1f)
|
|
||||||
) {
|
|
||||||
if (isLoading) {
|
|
||||||
// 加载中状态
|
|
||||||
Box(
|
|
||||||
modifier = Modifier.fillMaxSize(),
|
|
||||||
contentAlignment = Alignment.Center
|
|
||||||
) {
|
|
||||||
CircularProgressIndicator(
|
|
||||||
modifier = Modifier.size(40.dp),
|
|
||||||
color = Color(0xFFFF8D28)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
} else if (memoryList.isNotEmpty()) {
|
|
||||||
// 显示记忆列表
|
|
||||||
LazyColumn(
|
|
||||||
modifier = Modifier.fillMaxSize(),
|
|
||||||
contentPadding = PaddingValues(horizontal = 16.dp, vertical = 12.dp),
|
|
||||||
verticalArrangement = Arrangement.spacedBy(12.dp)
|
|
||||||
) {
|
|
||||||
items(memoryList) { memory ->
|
|
||||||
MemoryItem(
|
|
||||||
memory = memory,
|
|
||||||
isEditing = editingMemoryId == memory.id,
|
|
||||||
onEdit = {
|
|
||||||
editingMemoryId = memory.id
|
|
||||||
},
|
|
||||||
onCancel = {
|
|
||||||
editingMemoryId = null
|
|
||||||
},
|
|
||||||
onSave = { newText ->
|
|
||||||
viewModel.updateMemory(memory.id, newText)
|
|
||||||
editingMemoryId = null
|
|
||||||
},
|
|
||||||
onDelete = {
|
|
||||||
viewModel.deleteMemory(memory.id)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Column(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxSize()
|
|
||||||
.padding(vertical = 60.dp),
|
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
|
||||||
verticalArrangement = Arrangement.Center
|
|
||||||
) {
|
|
||||||
Image(
|
|
||||||
painter = painterResource(id = R.mipmap.group),
|
|
||||||
contentDescription = "暂无记忆",
|
|
||||||
modifier = Modifier
|
|
||||||
.height(150.dp).width(180.dp)
|
|
||||||
)
|
|
||||||
|
|
||||||
Spacer(Modifier.height(10.dp))
|
|
||||||
Text(
|
|
||||||
text = "暂无记忆",
|
|
||||||
style = TextStyle(color = Color.Black, fontSize = 16.sp, fontWeight = FontWeight.SemiBold)
|
|
||||||
)
|
|
||||||
Spacer(Modifier.height(6.dp))
|
|
||||||
Text(
|
|
||||||
text = "点击上方按钮添加群记忆",
|
|
||||||
style = TextStyle(color = Color.Black, fontSize = 14.sp, fontWeight = FontWeight.Normal)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 编辑记忆对话框
|
|
||||||
*/
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
|
||||||
@Composable
|
|
||||||
fun EditGroupMemoryDialog(
|
|
||||||
memory: com.aiosman.ravenow.data.api.AgentRule,
|
|
||||||
viewModel: GroupChatInfoViewModel,
|
|
||||||
onDismiss: () -> Unit,
|
|
||||||
onUpdateMemory: (String) -> Unit
|
|
||||||
) {
|
|
||||||
val AppColors = LocalAppTheme.current
|
|
||||||
val context = LocalContext.current
|
|
||||||
var memoryText by remember { mutableStateOf(memory.rule) }
|
|
||||||
val maxLength = 500
|
|
||||||
val sheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true)
|
|
||||||
|
|
||||||
val gradientColors = listOf(
|
|
||||||
Color(0xFF7C45ED),
|
|
||||||
Color(0xFF7C57EE),
|
|
||||||
Color(0xFF7BD8F8)
|
|
||||||
)
|
|
||||||
val gradientBrush = Brush.horizontalGradient(colors = gradientColors)
|
|
||||||
|
|
||||||
ModalBottomSheet(
|
|
||||||
onDismissRequest = onDismiss,
|
|
||||||
sheetState = sheetState,
|
|
||||||
containerColor = Color(0xFFFAF9FB),
|
|
||||||
dragHandle = {
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.width(36.dp)
|
|
||||||
.height(5.dp)
|
|
||||||
.padding(top = 5.dp)
|
|
||||||
.background(
|
|
||||||
Color(0xFFCCCCCC),
|
|
||||||
RoundedCornerShape(100.dp)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
},
|
|
||||||
shape = RoundedCornerShape(topStart = 20.dp, topEnd = 20.dp)
|
|
||||||
) {
|
|
||||||
Column(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(horizontal = 12.dp, vertical = 16.dp),
|
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
|
||||||
verticalArrangement = Arrangement.spacedBy(12.dp)
|
|
||||||
) {
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.height(88.dp)
|
|
||||||
) {
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxSize()
|
|
||||||
.clip(RoundedCornerShape(16.dp))
|
|
||||||
.background(brush = gradientBrush)
|
|
||||||
)
|
|
||||||
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxSize()
|
|
||||||
.padding(1.dp)
|
|
||||||
.clip(RoundedCornerShape(15.dp))
|
|
||||||
.background(Color.White)
|
|
||||||
.padding(12.dp),
|
|
||||||
contentAlignment = Alignment.TopStart
|
|
||||||
) {
|
|
||||||
BasicTextField(
|
|
||||||
value = memoryText,
|
|
||||||
onValueChange = { newText ->
|
|
||||||
if (newText.length <= maxLength) {
|
|
||||||
memoryText = newText
|
|
||||||
}
|
|
||||||
},
|
|
||||||
cursorBrush = SolidColor(Color.Black),
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
|
||||||
textStyle = TextStyle(
|
|
||||||
fontSize = 13.sp,
|
|
||||||
color = Color.Black,
|
|
||||||
lineHeight = 18.sp
|
|
||||||
),
|
|
||||||
decorationBox = { innerTextField ->
|
|
||||||
Box(
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
|
||||||
contentAlignment = Alignment.TopStart
|
|
||||||
) {
|
|
||||||
innerTextField()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Row(
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
|
||||||
horizontalArrangement = Arrangement.spacedBy(12.dp)
|
|
||||||
) {
|
|
||||||
// 取消按钮
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.weight(1f)
|
|
||||||
.height(34.dp)
|
|
||||||
.clip(RoundedCornerShape(653.8.dp))
|
|
||||||
.background(Color(0x147C7480))
|
|
||||||
.noRippleClickable { onDismiss() },
|
|
||||||
contentAlignment = Alignment.Center
|
|
||||||
) {
|
|
||||||
Text(
|
|
||||||
text = "取消",
|
|
||||||
style = TextStyle(
|
|
||||||
fontSize = 15.sp,
|
|
||||||
color = Color.Black
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 保存按钮
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.weight(1f)
|
|
||||||
.height(34.dp)
|
|
||||||
.clip(RoundedCornerShape(653.8.dp))
|
|
||||||
.background(Color(0xFF110C13))
|
|
||||||
.noRippleClickable {
|
|
||||||
if (memoryText.isNotBlank() && memoryText != memory.rule) {
|
|
||||||
onUpdateMemory(memoryText)
|
|
||||||
Toast.makeText(context, "记忆更新成功", Toast.LENGTH_SHORT).show()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
contentAlignment = Alignment.Center
|
|
||||||
) {
|
|
||||||
Text(
|
|
||||||
text = "保存",
|
|
||||||
style = TextStyle(
|
|
||||||
fontSize = 15.sp,
|
|
||||||
color = Color.White
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 记忆项组件
|
|
||||||
*/
|
|
||||||
@Composable
|
|
||||||
fun MemoryItem(
|
|
||||||
memory: com.aiosman.ravenow.data.api.AgentRule,
|
|
||||||
isEditing: Boolean = false,
|
|
||||||
onEdit: () -> Unit = {},
|
|
||||||
onCancel: () -> Unit = {},
|
|
||||||
onSave: (String) -> Unit = {},
|
|
||||||
onDelete: () -> Unit
|
|
||||||
) {
|
|
||||||
val AppColors = LocalAppTheme.current
|
|
||||||
val context = LocalContext.current
|
|
||||||
var memoryText by remember { mutableStateOf(memory.rule) }
|
|
||||||
val maxLength = 500
|
|
||||||
|
|
||||||
// 渐变边框颜色
|
|
||||||
val gradientColors = listOf(
|
|
||||||
Color(0xFF7C45ED),
|
|
||||||
Color(0xFF7C57EE),
|
|
||||||
Color(0xFF7BD8F8)
|
|
||||||
)
|
|
||||||
val gradientBrush = Brush.horizontalGradient(colors = gradientColors)
|
|
||||||
|
|
||||||
// 当进入编辑模式时,重置文本
|
|
||||||
LaunchedEffect(isEditing) {
|
|
||||||
if (isEditing) {
|
|
||||||
memoryText = memory.rule
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isEditing) {
|
|
||||||
// 编辑模式:显示编辑界面
|
|
||||||
Column(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.clip(RoundedCornerShape(16.dp))
|
|
||||||
.background(Color.White)
|
|
||||||
.padding(horizontal = 12.dp, vertical = 16.dp),
|
|
||||||
verticalArrangement = Arrangement.spacedBy(12.dp)
|
|
||||||
) {
|
|
||||||
// 文本输入框 - 带渐变边框
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.height(88.dp)
|
|
||||||
) {
|
|
||||||
// 渐变边框层
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxSize()
|
|
||||||
.clip(RoundedCornerShape(16.dp))
|
|
||||||
.background(brush = gradientBrush)
|
|
||||||
)
|
|
||||||
|
|
||||||
// 内容层 - 白色背景,通过padding形成边框效果
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxSize()
|
|
||||||
.padding(1.dp)
|
|
||||||
.clip(RoundedCornerShape(15.dp))
|
|
||||||
.background(Color.White)
|
|
||||||
.padding(12.dp),
|
|
||||||
contentAlignment = Alignment.TopStart
|
|
||||||
) {
|
|
||||||
BasicTextField(
|
|
||||||
value = memoryText,
|
|
||||||
onValueChange = { newText ->
|
|
||||||
if (newText.length <= maxLength) {
|
|
||||||
memoryText = newText
|
|
||||||
}
|
|
||||||
},
|
|
||||||
cursorBrush = SolidColor(Color.Black),
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
|
||||||
textStyle = TextStyle(
|
|
||||||
fontSize = 13.sp,
|
|
||||||
color = Color.Black,
|
|
||||||
lineHeight = 18.sp
|
|
||||||
),
|
|
||||||
decorationBox = { innerTextField ->
|
|
||||||
Box(
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
|
||||||
contentAlignment = Alignment.TopStart
|
|
||||||
) {
|
|
||||||
innerTextField()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 按钮行:取消和保存
|
|
||||||
Row(
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
|
||||||
horizontalArrangement = Arrangement.spacedBy(12.dp)
|
|
||||||
) {
|
|
||||||
// 取消按钮
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.weight(1f)
|
|
||||||
.height(34.dp)
|
|
||||||
.clip(RoundedCornerShape(653.8.dp))
|
|
||||||
.background(Color(0x147C7480))
|
|
||||||
.noRippleClickable { onCancel() },
|
|
||||||
contentAlignment = Alignment.Center
|
|
||||||
) {
|
|
||||||
Text(
|
|
||||||
text = "取消",
|
|
||||||
style = TextStyle(
|
|
||||||
fontSize = 15.sp,
|
|
||||||
color = Color.Black
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 保存按钮
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.weight(1f)
|
|
||||||
.height(34.dp)
|
|
||||||
.clip(RoundedCornerShape(653.8.dp))
|
|
||||||
.background(Color(0xFF110C13))
|
|
||||||
.noRippleClickable {
|
|
||||||
if (memoryText.isNotBlank() && memoryText != memory.rule) {
|
|
||||||
onSave(memoryText)
|
|
||||||
Toast.makeText(context, "记忆更新成功", Toast.LENGTH_SHORT).show()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
contentAlignment = Alignment.Center
|
|
||||||
) {
|
|
||||||
Text(
|
|
||||||
text = "保存",
|
|
||||||
style = TextStyle(
|
|
||||||
fontSize = 15.sp,
|
|
||||||
color = Color.White
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// 显示模式:显示记忆内容
|
|
||||||
// 格式化日期:从 "2025-10-20T10:30:00Z" 格式转换为 "2025年10月20日"
|
|
||||||
val formattedDate = try {
|
|
||||||
if (memory.createdAt.length >= 10) {
|
|
||||||
val dateStr = memory.createdAt.substring(0, 10)
|
|
||||||
val parts = dateStr.split("-")
|
|
||||||
if (parts.size == 3) {
|
|
||||||
"${parts[0]}年${parts[1].toInt()}月${parts[2].toInt()}日"
|
|
||||||
} else {
|
|
||||||
dateStr
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
memory.createdAt
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
|
||||||
if (memory.createdAt.length >= 10) memory.createdAt.substring(0, 10) else memory.createdAt
|
|
||||||
}
|
|
||||||
|
|
||||||
Column(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.clip(RoundedCornerShape(16.dp))
|
|
||||||
.background(Color.White)
|
|
||||||
.padding(horizontal = 12.dp, vertical = 16.dp)
|
|
||||||
) {
|
|
||||||
// 主文本 - 顶部
|
|
||||||
Text(
|
|
||||||
text = memory.rule,
|
|
||||||
style = TextStyle(
|
|
||||||
color = Color.Black,
|
|
||||||
fontSize = 13.sp,
|
|
||||||
lineHeight = 18.sp
|
|
||||||
),
|
|
||||||
maxLines = 3,
|
|
||||||
overflow = TextOverflow.Ellipsis
|
|
||||||
)
|
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(16.dp))
|
|
||||||
|
|
||||||
// 底部行:日期 + 编辑删除按钮
|
|
||||||
Row(
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
|
||||||
horizontalArrangement = Arrangement.SpaceBetween,
|
|
||||||
verticalAlignment = Alignment.Bottom
|
|
||||||
) {
|
|
||||||
// 日期文本 - 左侧
|
|
||||||
Text(
|
|
||||||
text = formattedDate,
|
|
||||||
style = TextStyle(
|
|
||||||
color = Color(0x993C3C43),
|
|
||||||
fontSize = 11.sp
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
// 编辑和删除图标 - 右侧
|
|
||||||
Row(
|
|
||||||
horizontalArrangement = Arrangement.spacedBy(16.dp),
|
|
||||||
verticalAlignment = Alignment.CenterVertically
|
|
||||||
) {
|
|
||||||
// 编辑图标
|
|
||||||
Image(
|
|
||||||
painter = painterResource(R.mipmap.icons_infor_edit),
|
|
||||||
contentDescription = "编辑",
|
|
||||||
modifier = Modifier
|
|
||||||
.size(20.dp)
|
|
||||||
.noRippleClickable { onEdit() },
|
|
||||||
colorFilter = ColorFilter.tint(Color.Black)
|
|
||||||
)
|
|
||||||
|
|
||||||
Image(
|
|
||||||
painter = painterResource(R.mipmap.iconsdelete),
|
|
||||||
contentDescription = "删除",
|
|
||||||
modifier = Modifier
|
|
||||||
.size(20.dp)
|
|
||||||
.noRippleClickable { onDelete() },
|
|
||||||
colorFilter = ColorFilter.tint(Color(0xFFEE2A33))
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,12 +1,6 @@
|
|||||||
package com.aiosman.ravenow.ui.index
|
package com.aiosman.ravenow.ui.index
|
||||||
|
|
||||||
import androidx.compose.animation.animateColorAsState
|
import androidx.compose.animation.animateColorAsState
|
||||||
import androidx.compose.animation.core.animateFloatAsState
|
|
||||||
import androidx.compose.animation.core.FastOutLinearInEasing
|
|
||||||
import androidx.compose.animation.core.LinearOutSlowInEasing
|
|
||||||
import androidx.compose.animation.core.updateTransition
|
|
||||||
import androidx.compose.animation.core.animateFloat
|
|
||||||
import androidx.compose.animation.core.FastOutSlowInEasing
|
|
||||||
import androidx.compose.animation.core.tween
|
import androidx.compose.animation.core.tween
|
||||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||||
import androidx.compose.foundation.Image
|
import androidx.compose.foundation.Image
|
||||||
@@ -17,21 +11,15 @@ import androidx.compose.foundation.layout.Column
|
|||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.Spacer
|
import androidx.compose.foundation.layout.Spacer
|
||||||
import androidx.compose.foundation.layout.WindowInsets
|
import androidx.compose.foundation.layout.WindowInsets
|
||||||
import androidx.compose.foundation.layout.asPaddingValues
|
|
||||||
import androidx.compose.foundation.layout.systemBars
|
|
||||||
import androidx.compose.foundation.layout.fillMaxHeight
|
import androidx.compose.foundation.layout.fillMaxHeight
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.height
|
import androidx.compose.foundation.layout.height
|
||||||
import androidx.compose.foundation.layout.heightIn
|
|
||||||
import androidx.compose.foundation.layout.navigationBars
|
import androidx.compose.foundation.layout.navigationBars
|
||||||
import androidx.compose.foundation.layout.requiredHeight
|
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.layout.offset
|
|
||||||
import androidx.compose.foundation.layout.requiredWidth
|
import androidx.compose.foundation.layout.requiredWidth
|
||||||
import androidx.compose.foundation.layout.size
|
import androidx.compose.foundation.layout.size
|
||||||
import androidx.compose.foundation.layout.width
|
import androidx.compose.foundation.layout.width
|
||||||
import androidx.compose.foundation.shape.CircleShape
|
|
||||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||||
import androidx.compose.foundation.pager.HorizontalPager
|
import androidx.compose.foundation.pager.HorizontalPager
|
||||||
import androidx.compose.foundation.pager.rememberPagerState
|
import androidx.compose.foundation.pager.rememberPagerState
|
||||||
@@ -54,10 +42,8 @@ import androidx.compose.runtime.CompositionLocalProvider
|
|||||||
import androidx.compose.runtime.DisposableEffect
|
import androidx.compose.runtime.DisposableEffect
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableStateOf
|
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.rememberCoroutineScope
|
import androidx.compose.runtime.rememberCoroutineScope
|
||||||
import androidx.compose.runtime.setValue
|
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.alpha
|
import androidx.compose.ui.draw.alpha
|
||||||
@@ -73,11 +59,7 @@ import androidx.compose.ui.text.font.FontWeight
|
|||||||
import androidx.compose.ui.unit.LayoutDirection
|
import androidx.compose.ui.unit.LayoutDirection
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
import androidx.compose.ui.zIndex
|
|
||||||
import com.aiosman.ravenow.AppState
|
import com.aiosman.ravenow.AppState
|
||||||
import java.text.SimpleDateFormat
|
|
||||||
import java.util.Date
|
|
||||||
import java.util.Locale
|
|
||||||
import com.aiosman.ravenow.AppStore
|
import com.aiosman.ravenow.AppStore
|
||||||
import com.aiosman.ravenow.GuestLoginCheckOut
|
import com.aiosman.ravenow.GuestLoginCheckOut
|
||||||
import com.aiosman.ravenow.GuestLoginCheckOutScene
|
import com.aiosman.ravenow.GuestLoginCheckOutScene
|
||||||
@@ -141,16 +123,151 @@ fun IndexScreen() {
|
|||||||
gesturesEnabled = drawerState.isOpen,
|
gesturesEnabled = drawerState.isOpen,
|
||||||
drawerContent = {
|
drawerContent = {
|
||||||
CompositionLocalProvider(LocalLayoutDirection provides LayoutDirection.Ltr) {
|
CompositionLocalProvider(LocalLayoutDirection provides LayoutDirection.Ltr) {
|
||||||
SideMenuContent(
|
Column(
|
||||||
onClose = {
|
modifier = Modifier
|
||||||
coroutineScope.launch {
|
.requiredWidth(250.dp)
|
||||||
drawerState.close()
|
.fillMaxHeight()
|
||||||
|
.background(
|
||||||
|
AppColors.background
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
Spacer(modifier = Modifier.height(88.dp))
|
||||||
|
NavItem(
|
||||||
|
iconRes = R.drawable.rave_now_nav_account,
|
||||||
|
label = stringResource(R.string.account_and_security),
|
||||||
|
modifier = Modifier.noRippleClickable {
|
||||||
|
coroutineScope.launch {
|
||||||
|
drawerState.close()
|
||||||
|
navController.navigate(NavigationRoute.AccountSetting.route)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
},
|
)
|
||||||
navController = navController,
|
Spacer(modifier = Modifier.height(16.dp))
|
||||||
context = context,
|
NavItem(
|
||||||
isDrawerOpen = drawerState.isOpen
|
iconRes = R.drawable.rider_pro_favourited,
|
||||||
)
|
label = stringResource(R.string.favourites),
|
||||||
|
modifier = Modifier.noRippleClickable {
|
||||||
|
coroutineScope.launch {
|
||||||
|
drawerState.close()
|
||||||
|
navController.navigate(NavigationRoute.FavouriteList.route)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
NavItem(
|
||||||
|
iconRes = R.drawable.rave_now_nav_night,
|
||||||
|
label = stringResource(R.string.dark_mode),
|
||||||
|
rightContent = {
|
||||||
|
Switch(
|
||||||
|
checked = AppState.darkMode,
|
||||||
|
onCheckedChange = {
|
||||||
|
AppState.switchTheme()
|
||||||
|
},
|
||||||
|
|
||||||
|
colors = SwitchDefaults.colors(
|
||||||
|
checkedThumbColor = Color.White,
|
||||||
|
checkedTrackColor = AppColors.main,
|
||||||
|
uncheckedThumbColor = Color.White,
|
||||||
|
uncheckedTrackColor = AppColors.main.copy(alpha = 0.5f),
|
||||||
|
uncheckedBorderColor = Color.Transparent
|
||||||
|
),
|
||||||
|
modifier = Modifier.scale(0.8f)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
// divider
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(top = 16.dp, bottom = 16.dp, start = 16.dp, end = 16.dp)
|
||||||
|
) {
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.height(1.dp)
|
||||||
|
.background(AppColors.divider)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
NavItem(
|
||||||
|
iconRes = R.drawable.rave_now_nav_about,
|
||||||
|
label = stringResource(R.string.blocked),
|
||||||
|
modifier = Modifier.noRippleClickable {
|
||||||
|
coroutineScope.launch {
|
||||||
|
drawerState.close()
|
||||||
|
navController.navigate(NavigationRoute.AboutScreen.route)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
NavItem(
|
||||||
|
iconRes = R.drawable.rave_now_nav_about,
|
||||||
|
label = stringResource(R.string.feedback),
|
||||||
|
modifier = Modifier.noRippleClickable {
|
||||||
|
coroutineScope.launch {
|
||||||
|
drawerState.close()
|
||||||
|
navController.navigate(NavigationRoute.AboutScreen.route)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
NavItem(
|
||||||
|
iconRes = R.drawable.rave_now_nav_about,
|
||||||
|
label = stringResource(R.string.about_rave_now),
|
||||||
|
modifier = Modifier.noRippleClickable {
|
||||||
|
coroutineScope.launch {
|
||||||
|
drawerState.close()
|
||||||
|
navController.navigate(NavigationRoute.AboutScreen.route)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
// divider
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(top = 16.dp, bottom = 16.dp, start = 16.dp, end = 16.dp)
|
||||||
|
) {
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.height(1.dp)
|
||||||
|
.background(AppColors.divider)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NavItem(
|
||||||
|
// iconRes = R.drawable.rave_now_nav_switch,
|
||||||
|
// label = "Switch Account"
|
||||||
|
// )
|
||||||
|
// Spacer(modifier = Modifier.height(16.dp))
|
||||||
|
NavItem(
|
||||||
|
iconRes = R.drawable.rave_now_nav_logout,
|
||||||
|
label = stringResource(R.string.logout),
|
||||||
|
modifier = Modifier.noRippleClickable {
|
||||||
|
coroutineScope.launch {
|
||||||
|
drawerState.close()
|
||||||
|
// 只有非游客用户才需要取消注册推送设备
|
||||||
|
if (!AppStore.isGuest) {
|
||||||
|
Messaging.unregisterDevice(context)
|
||||||
|
}
|
||||||
|
AppStore.apply {
|
||||||
|
token = null
|
||||||
|
rememberMe = false
|
||||||
|
isGuest = false // 清除游客状态
|
||||||
|
saveData()
|
||||||
|
}
|
||||||
|
// 删除推送渠道
|
||||||
|
|
||||||
|
navController.navigate(NavigationRoute.Login.route) {
|
||||||
|
popUpTo(NavigationRoute.Login.route) {
|
||||||
|
inclusive = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
AppState.ReloadAppState(context)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
@@ -159,15 +276,12 @@ fun IndexScreen() {
|
|||||||
bottomBar = {
|
bottomBar = {
|
||||||
NavigationBar(
|
NavigationBar(
|
||||||
modifier = Modifier.height(58.dp + navigationBarHeight),
|
modifier = Modifier.height(58.dp + navigationBarHeight),
|
||||||
containerColor = AppColors.tabUnselectedBackground
|
containerColor = AppColors.background
|
||||||
) {
|
) {
|
||||||
item.forEachIndexed { idx, it ->
|
item.forEachIndexed { idx, it ->
|
||||||
val isSelected = model.tabIndex == idx
|
val isSelected = model.tabIndex == idx
|
||||||
// 定义新的选中颜色
|
|
||||||
val selectedColor = Color(0xFF7C45ED)
|
|
||||||
|
|
||||||
val iconTint by animateColorAsState(
|
val iconTint by animateColorAsState(
|
||||||
targetValue = if (isSelected) selectedColor else AppColors.text,
|
targetValue = if (isSelected) AppColors.brandColorsColor else AppColors.text,
|
||||||
animationSpec = tween(durationMillis = 250), label = ""
|
animationSpec = tween(durationMillis = 250), label = ""
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -229,7 +343,7 @@ fun IndexScreen() {
|
|||||||
.width(48.dp)
|
.width(48.dp)
|
||||||
.height(32.dp)
|
.height(32.dp)
|
||||||
.background(
|
.background(
|
||||||
color = if (isSelected) selectedColor.copy(alpha = 0.15f) else Color.Transparent,
|
color = if (isSelected) AppColors.brandColorsColor.copy(alpha = 0.15f) else Color.Transparent,
|
||||||
shape = RoundedCornerShape(12.dp)
|
shape = RoundedCornerShape(12.dp)
|
||||||
),
|
),
|
||||||
contentAlignment = Alignment.Center
|
contentAlignment = Alignment.Center
|
||||||
@@ -248,7 +362,7 @@ fun IndexScreen() {
|
|||||||
Text(
|
Text(
|
||||||
text = it.label(),
|
text = it.label(),
|
||||||
fontSize = 10.sp,
|
fontSize = 10.sp,
|
||||||
color = if (isSelected) selectedColor else AppColors.text,
|
color = if (isSelected) Color.Blue else AppColors.text,
|
||||||
fontWeight = if (isSelected) FontWeight.W600 else FontWeight.Normal
|
fontWeight = if (isSelected) FontWeight.W600 else FontWeight.Normal
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -330,6 +444,7 @@ fun IndexScreen() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@@ -506,369 +621,3 @@ fun NavItem(
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun SideMenuContent(
|
|
||||||
onClose: () -> Unit,
|
|
||||||
navController: androidx.navigation.NavController,
|
|
||||||
context: android.content.Context,
|
|
||||||
isDrawerOpen: Boolean
|
|
||||||
) {
|
|
||||||
val appColors = LocalAppTheme.current
|
|
||||||
val coroutineScope = rememberCoroutineScope()
|
|
||||||
var messageNotificationEnabled by remember { mutableStateOf(true) }
|
|
||||||
var darkModeEnabled by remember { mutableStateOf(AppState.darkMode) }
|
|
||||||
|
|
||||||
// 同步暗色模式状态
|
|
||||||
LaunchedEffect(AppState.darkMode) {
|
|
||||||
darkModeEnabled = AppState.darkMode
|
|
||||||
}
|
|
||||||
|
|
||||||
// 菜单背景色 - 根据暗色模式适配
|
|
||||||
val menuBackgroundColor = if (darkModeEnabled) {
|
|
||||||
appColors.secondaryBackground // 暗色模式:深灰色
|
|
||||||
} else {
|
|
||||||
Color(0xFFFAF9FB) // 亮色模式:浅灰色
|
|
||||||
}
|
|
||||||
// 遮罩颜色 黑色透明度0.6
|
|
||||||
val overlayColor = Color.Black.copy(alpha = 0.6f)
|
|
||||||
// 卡片背景色 - 根据暗色模式适配
|
|
||||||
val cardBackgroundColor = if (darkModeEnabled) {
|
|
||||||
appColors.background // 暗色模式:深色背景
|
|
||||||
} else {
|
|
||||||
Color.White // 亮色模式:白色
|
|
||||||
}
|
|
||||||
// 文字颜色 - 根据暗色模式适配
|
|
||||||
val textColor = appColors.text
|
|
||||||
// 图标颜色 - 根据暗色模式适配
|
|
||||||
val iconColor = appColors.text
|
|
||||||
// 跟随系统文字颜色 - 根据暗色模式适配
|
|
||||||
val followSystemTextColor = appColors.secondaryText
|
|
||||||
// 开关开启颜色 #7C45ED
|
|
||||||
val switchActiveColor = Color(0xFF7C45ED)
|
|
||||||
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxSize()
|
|
||||||
) {
|
|
||||||
// 左侧半透明遮罩(平滑淡入淡出)
|
|
||||||
val overlayTransition = updateTransition(targetState = isDrawerOpen, label = "overlay")
|
|
||||||
val overlayAlpha by overlayTransition.animateFloat(
|
|
||||||
transitionSpec = {
|
|
||||||
if (targetState) {
|
|
||||||
tween(durationMillis = 400, easing = LinearOutSlowInEasing)
|
|
||||||
} else {
|
|
||||||
tween(durationMillis = 300, easing = FastOutLinearInEasing)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
label = "overlayAlpha"
|
|
||||||
) { open -> if (open) 0.6f else 0f }
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxSize()
|
|
||||||
.background(Color.Black.copy(alpha = overlayAlpha))
|
|
||||||
)
|
|
||||||
|
|
||||||
// 右侧菜单面板
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.requiredWidth(302.dp)
|
|
||||||
.requiredHeight(874.dp)
|
|
||||||
.align(Alignment.CenterEnd)
|
|
||||||
.background(menuBackgroundColor)
|
|
||||||
) {
|
|
||||||
// 顶部状态栏间距
|
|
||||||
val statusBarHeight = WindowInsets.systemBars.asPaddingValues().calculateTopPadding()
|
|
||||||
|
|
||||||
// 扫一扫功能入口 - 右边距离右边66pt
|
|
||||||
Row(
|
|
||||||
modifier = Modifier
|
|
||||||
.align(Alignment.TopEnd)
|
|
||||||
.offset(x = (-112).dp, y = 88.dp)
|
|
||||||
.noRippleClickable {
|
|
||||||
// TODO: 实现扫一扫功能
|
|
||||||
},
|
|
||||||
horizontalArrangement = Arrangement.spacedBy(16.dp),
|
|
||||||
verticalAlignment = Alignment.CenterVertically
|
|
||||||
) {
|
|
||||||
// 扫一扫图标(使用现有图标或占位)
|
|
||||||
Image(
|
|
||||||
painter = painterResource(id = R.mipmap.sao),
|
|
||||||
contentDescription = null,
|
|
||||||
modifier = Modifier.size(24.dp),
|
|
||||||
colorFilter = ColorFilter.tint(iconColor)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
// 绝对定位的"扫一扫"文字:上方71.5dp,右侧66dp
|
|
||||||
Text(
|
|
||||||
text = stringResource(R.string.scan_qr),
|
|
||||||
fontSize = 14.sp,
|
|
||||||
color = textColor,
|
|
||||||
modifier = Modifier
|
|
||||||
.align(Alignment.TopEnd)
|
|
||||||
.offset(x = (-66).dp, y = 91.5.dp)
|
|
||||||
)
|
|
||||||
// QR码图标 - 右边距离右边112dp,上边距离上边68pt
|
|
||||||
Image(
|
|
||||||
painter = painterResource(id = R.mipmap.qr_code_icon),
|
|
||||||
contentDescription = null,
|
|
||||||
modifier = Modifier
|
|
||||||
.size(24.dp)
|
|
||||||
.align(Alignment.TopEnd)
|
|
||||||
.offset(x = (-26).dp, y = 88.dp)
|
|
||||||
.noRippleClickable {
|
|
||||||
// TODO: 实现QR码功能
|
|
||||||
},
|
|
||||||
colorFilter = ColorFilter.tint(iconColor)
|
|
||||||
)
|
|
||||||
|
|
||||||
// 菜单选项卡片组 - 第一组卡片上方距离上方108pt(绝对定位)
|
|
||||||
Column(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.offset(y = 128.dp) // 直接距离顶部128dp(整体下移20dp)
|
|
||||||
.padding(horizontal = 16.dp),
|
|
||||||
verticalArrangement = Arrangement.spacedBy(8.dp)
|
|
||||||
) {
|
|
||||||
// 第一组卡片:编辑资料、账号安全、收藏
|
|
||||||
MenuCard(
|
|
||||||
backgroundColor = cardBackgroundColor,
|
|
||||||
textColor = textColor,
|
|
||||||
iconColor = iconColor,
|
|
||||||
width = 270.dp,
|
|
||||||
height = 164.dp,
|
|
||||||
items = listOf(
|
|
||||||
MenuItem(
|
|
||||||
icon = R.mipmap.icons_edited_data,
|
|
||||||
label = stringResource(R.string.edit_profile_info),
|
|
||||||
onClick = {
|
|
||||||
coroutineScope.launch {
|
|
||||||
onClose()
|
|
||||||
navController.navigate(NavigationRoute.AccountEdit.route)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
),
|
|
||||||
MenuItem(
|
|
||||||
icon = R.mipmap.icons_account_and_security,
|
|
||||||
label = stringResource(R.string.account_and_security),
|
|
||||||
onClick = {
|
|
||||||
coroutineScope.launch {
|
|
||||||
onClose()
|
|
||||||
navController.navigate(NavigationRoute.AccountSetting.route)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
),
|
|
||||||
MenuItem(
|
|
||||||
icon = R.mipmap.collect,
|
|
||||||
label = stringResource(R.string.favourites),
|
|
||||||
onClick = {
|
|
||||||
coroutineScope.launch {
|
|
||||||
onClose()
|
|
||||||
navController.navigate(NavigationRoute.FavouriteList.route)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
// 第二组卡片:暗色模式、消息通知
|
|
||||||
MenuCard(
|
|
||||||
backgroundColor = cardBackgroundColor,
|
|
||||||
textColor = textColor,
|
|
||||||
iconColor = iconColor,
|
|
||||||
width = 270.dp,
|
|
||||||
height = 112.dp, // 根据设计图,第二组卡片高度为112dp
|
|
||||||
items = listOf(
|
|
||||||
MenuItem(
|
|
||||||
icon = R.mipmap.icons_dark_mode,
|
|
||||||
label = stringResource(R.string.dark_mode),
|
|
||||||
rightContent = {
|
|
||||||
Switch(
|
|
||||||
checked = darkModeEnabled,
|
|
||||||
onCheckedChange = {
|
|
||||||
darkModeEnabled = it
|
|
||||||
AppState.darkMode = it
|
|
||||||
AppState.appTheme = if (it) {
|
|
||||||
com.aiosman.ravenow.DarkThemeColors()
|
|
||||||
} else {
|
|
||||||
com.aiosman.ravenow.LightThemeColors()
|
|
||||||
}
|
|
||||||
AppStore.saveDarkMode(it)
|
|
||||||
},
|
|
||||||
colors = SwitchDefaults.colors(
|
|
||||||
checkedThumbColor = Color.White,
|
|
||||||
checkedTrackColor = switchActiveColor,
|
|
||||||
uncheckedThumbColor = Color.White,
|
|
||||||
uncheckedTrackColor = switchActiveColor.copy(alpha = 0.5f),
|
|
||||||
uncheckedBorderColor = Color.Transparent
|
|
||||||
),
|
|
||||||
modifier = Modifier.size(width = 64.dp, height = 28.dp)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
),
|
|
||||||
MenuItem(
|
|
||||||
icon = R.mipmap.icons_bell,
|
|
||||||
label = stringResource(R.string.message_notification),
|
|
||||||
rightContent = {
|
|
||||||
Switch(
|
|
||||||
checked = messageNotificationEnabled,
|
|
||||||
onCheckedChange = { messageNotificationEnabled = it },
|
|
||||||
colors = SwitchDefaults.colors(
|
|
||||||
checkedThumbColor = Color.White,
|
|
||||||
checkedTrackColor = switchActiveColor,
|
|
||||||
uncheckedThumbColor = Color.White,
|
|
||||||
uncheckedTrackColor = switchActiveColor.copy(alpha = 0.5f),
|
|
||||||
uncheckedBorderColor = Color.Transparent
|
|
||||||
),
|
|
||||||
modifier = Modifier.size(width = 64.dp, height = 28.dp)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
// 第三组卡片:关于派派、反馈、退出登录
|
|
||||||
MenuCard(
|
|
||||||
backgroundColor = cardBackgroundColor,
|
|
||||||
textColor = textColor,
|
|
||||||
iconColor = iconColor,
|
|
||||||
width = 270.dp,
|
|
||||||
height = 164.dp,
|
|
||||||
items = listOf(
|
|
||||||
MenuItem(
|
|
||||||
icon = R.mipmap.icons_about,
|
|
||||||
label = stringResource(R.string.about_paipai),
|
|
||||||
onClick = {
|
|
||||||
coroutineScope.launch {
|
|
||||||
onClose()
|
|
||||||
navController.navigate(NavigationRoute.AboutScreen.route)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
),
|
|
||||||
MenuItem(
|
|
||||||
icon = R.mipmap.feedback_icon,
|
|
||||||
label = stringResource(R.string.feedback),
|
|
||||||
onClick = {
|
|
||||||
coroutineScope.launch {
|
|
||||||
onClose()
|
|
||||||
navController.navigate(NavigationRoute.AboutScreen.route)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
),
|
|
||||||
MenuItem(
|
|
||||||
icon = R.mipmap.log_out_icon,
|
|
||||||
label = stringResource(R.string.logout_confirm),
|
|
||||||
onClick = {
|
|
||||||
coroutineScope.launch {
|
|
||||||
onClose()
|
|
||||||
// 只有非游客用户才需要取消注册推送设备
|
|
||||||
if (!AppStore.isGuest) {
|
|
||||||
Messaging.unregisterDevice(context)
|
|
||||||
}
|
|
||||||
AppStore.apply {
|
|
||||||
token = null
|
|
||||||
rememberMe = false
|
|
||||||
isGuest = false
|
|
||||||
saveData()
|
|
||||||
}
|
|
||||||
navController.navigate(NavigationRoute.Login.route) {
|
|
||||||
popUpTo(NavigationRoute.Login.route) {
|
|
||||||
inclusive = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
AppState.ReloadAppState(context)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
showRightArrow = false
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
data class MenuItem(
|
|
||||||
val icon: Int,
|
|
||||||
val label: String,
|
|
||||||
val onClick: (() -> Unit)? = null,
|
|
||||||
val rightContent: @Composable (() -> Unit)? = null,
|
|
||||||
val showRightArrow: Boolean = true
|
|
||||||
)
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun MenuCard(
|
|
||||||
backgroundColor: Color,
|
|
||||||
textColor: Color,
|
|
||||||
iconColor: Color,
|
|
||||||
items: List<MenuItem>,
|
|
||||||
width: androidx.compose.ui.unit.Dp? = null,
|
|
||||||
height: androidx.compose.ui.unit.Dp? = null
|
|
||||||
) {
|
|
||||||
Column(
|
|
||||||
modifier = Modifier
|
|
||||||
.then(if (width != null) Modifier.requiredWidth(width) else Modifier.fillMaxWidth())
|
|
||||||
.then(if (height != null) Modifier.requiredHeight(height) else Modifier)
|
|
||||||
.background(backgroundColor, RoundedCornerShape(16.dp))
|
|
||||||
.padding(horizontal = 16.dp),
|
|
||||||
verticalArrangement = if (height != null) Arrangement.SpaceEvenly else Arrangement.spacedBy(8.dp) // 固定高度时均匀分布
|
|
||||||
) {
|
|
||||||
items.forEachIndexed { index, item ->
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.then(if (height != null) Modifier.weight(1f) else Modifier),
|
|
||||||
contentAlignment = Alignment.Center
|
|
||||||
) {
|
|
||||||
MenuItemRow(item = item, compact = height != null, textColor = textColor, iconColor = iconColor) // 传递颜色参数
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun MenuItemRow(item: MenuItem, compact: Boolean = false, textColor: Color, iconColor: Color) {
|
|
||||||
val appColors = LocalAppTheme.current
|
|
||||||
Row(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.then(
|
|
||||||
if (item.onClick != null) {
|
|
||||||
Modifier.noRippleClickable { item.onClick?.invoke() }
|
|
||||||
} else {
|
|
||||||
Modifier
|
|
||||||
}
|
|
||||||
)
|
|
||||||
.padding(vertical = if (compact) 4.dp else 8.dp), // 紧凑模式下减少垂直padding
|
|
||||||
horizontalArrangement = Arrangement.SpaceBetween,
|
|
||||||
verticalAlignment = Alignment.CenterVertically
|
|
||||||
) {
|
|
||||||
Row(
|
|
||||||
horizontalArrangement = Arrangement.spacedBy(12.dp),
|
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
|
||||||
modifier = Modifier.weight(1f)
|
|
||||||
) {
|
|
||||||
Image(
|
|
||||||
painter = painterResource(id = item.icon),
|
|
||||||
contentDescription = null,
|
|
||||||
modifier = Modifier.size(24.dp),
|
|
||||||
colorFilter = ColorFilter.tint(iconColor)
|
|
||||||
)
|
|
||||||
Text(
|
|
||||||
text = item.label,
|
|
||||||
fontSize = 14.sp,
|
|
||||||
color = textColor
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (item.rightContent != null) {
|
|
||||||
item.rightContent?.invoke()
|
|
||||||
} else if (item.showRightArrow) {
|
|
||||||
Image(
|
|
||||||
painter = painterResource(id = R.drawable.rave_now_nav_right),
|
|
||||||
contentDescription = null,
|
|
||||||
modifier = Modifier.size(24.dp),
|
|
||||||
colorFilter = ColorFilter.tint(appColors.text)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -16,9 +16,9 @@ sealed class NavigationItem(
|
|||||||
) {
|
) {
|
||||||
|
|
||||||
data object Home : NavigationItem("Home",
|
data object Home : NavigationItem("Home",
|
||||||
icon = { R.mipmap.bars_x_buttons_home_n_copy },
|
icon = { R.drawable.rider_pro_nav_home },
|
||||||
selectedIcon = { R.mipmap.bars_x_buttons_home_n_copy_2 },
|
selectedIcon = { R.mipmap.bars_x_buttons_home_s },
|
||||||
label = { stringResource(R.string.main_ai) }
|
label = { stringResource(R.string.main_home) }
|
||||||
)
|
)
|
||||||
|
|
||||||
data object Ai : NavigationItem("Ai",
|
data object Ai : NavigationItem("Ai",
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import androidx.compose.foundation.layout.Row
|
|||||||
import androidx.compose.foundation.layout.Spacer
|
import androidx.compose.foundation.layout.Spacer
|
||||||
import androidx.compose.foundation.layout.WindowInsets
|
import androidx.compose.foundation.layout.WindowInsets
|
||||||
import androidx.compose.foundation.layout.asPaddingValues
|
import androidx.compose.foundation.layout.asPaddingValues
|
||||||
|
import androidx.compose.foundation.layout.fillMaxHeight
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.height
|
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.foundation.shape.RoundedCornerShape
|
||||||
import androidx.compose.material.Icon
|
import androidx.compose.material.Icon
|
||||||
import androidx.compose.material.Text
|
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.Composable
|
||||||
import androidx.compose.runtime.DisposableEffect
|
import androidx.compose.runtime.DisposableEffect
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.runtime.derivedStateOf
|
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.rememberCoroutineScope
|
import androidx.compose.runtime.rememberCoroutineScope
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
|
import androidx.compose.runtime.snapshotFlow
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.clip
|
import androidx.compose.ui.draw.clip
|
||||||
@@ -50,10 +47,12 @@ import androidx.compose.ui.graphics.graphicsLayer
|
|||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.compose.ui.text.style.TextAlign
|
|
||||||
import androidx.compose.ui.text.style.TextOverflow
|
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.sp
|
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.lifecycle.viewmodel.compose.viewModel
|
||||||
import androidx.navigation.NavHostController
|
import androidx.navigation.NavHostController
|
||||||
import com.aiosman.ravenow.AppStore
|
import com.aiosman.ravenow.AppStore
|
||||||
@@ -80,14 +79,7 @@ import androidx.compose.foundation.lazy.LazyColumn
|
|||||||
import androidx.compose.foundation.lazy.LazyListState
|
import androidx.compose.foundation.lazy.LazyListState
|
||||||
import androidx.compose.foundation.lazy.items
|
import androidx.compose.foundation.lazy.items
|
||||||
import androidx.compose.foundation.lazy.rememberLazyListState
|
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||||
import androidx.compose.foundation.lazy.grid.GridCells
|
import androidx.compose.ui.zIndex
|
||||||
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
|
|
||||||
import androidx.compose.ui.platform.LocalContext
|
|
||||||
import androidx.compose.ui.window.Dialog
|
|
||||||
import androidx.compose.ui.window.DialogProperties
|
|
||||||
import androidx.compose.foundation.lazy.grid.items as gridItems
|
|
||||||
import androidx.compose.material.CircularProgressIndicator
|
|
||||||
import androidx.compose.ui.draw.alpha
|
|
||||||
|
|
||||||
// 检测是否接近列表底部的扩展函数
|
// 检测是否接近列表底部的扩展函数
|
||||||
fun LazyListState.isScrolledToEnd(buffer: Int = 3): Boolean {
|
fun LazyListState.isScrolledToEnd(buffer: Int = 3): Boolean {
|
||||||
@@ -98,7 +90,7 @@ fun LazyListState.isScrolledToEnd(buffer: Int = 3): Boolean {
|
|||||||
return lastVisibleItemIndex >= (totalItemsCount - buffer)
|
return lastVisibleItemIndex >= (totalItemsCount - buffer)
|
||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(ExperimentalFoundationApi::class, ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalFoundationApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun Agent() {
|
fun Agent() {
|
||||||
val AppColors = LocalAppTheme.current
|
val AppColors = LocalAppTheme.current
|
||||||
@@ -118,6 +110,19 @@ fun Agent() {
|
|||||||
viewModel.ensureDataLoaded()
|
viewModel.ensureDataLoaded()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 列表滚动状态(用于吸顶与加载更多)
|
||||||
|
val listState = rememberLazyListState()
|
||||||
|
|
||||||
|
// 监听滚动到底部,加载更多网格数据
|
||||||
|
LaunchedEffect(listState) {
|
||||||
|
snapshotFlow { listState.isScrolledToEnd() }
|
||||||
|
.collect { atEnd ->
|
||||||
|
if (atEnd && !viewModel.isLoading) {
|
||||||
|
viewModel.loadMoreGridAgentData()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 防抖状态
|
// 防抖状态
|
||||||
var lastClickTime by remember { mutableStateOf(0L) }
|
var lastClickTime by remember { mutableStateOf(0L) }
|
||||||
|
|
||||||
@@ -129,78 +134,61 @@ fun Agent() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val agentItems = viewModel.agentItems
|
Box(
|
||||||
var selectedTabIndex by remember { mutableStateOf(0) }
|
modifier = Modifier.fillMaxSize()
|
||||||
|
) {
|
||||||
// 无限滚动状态
|
// 固定顶部搜索条
|
||||||
val listState = rememberLazyListState()
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
// 创建一个可观察的滚动到底部状态
|
.fillMaxWidth()
|
||||||
val isScrolledToEnd by remember {
|
.background(AppColors.background)
|
||||||
derivedStateOf {
|
.zIndex(999.0f)
|
||||||
listState.isScrolledToEnd()
|
.height(44.dp + statusBarPaddingValues.calculateTopPadding())
|
||||||
}
|
) {
|
||||||
}
|
Row(
|
||||||
|
|
||||||
// 检测滚动到底部并加载更多数据
|
|
||||||
LaunchedEffect(isScrolledToEnd) {
|
|
||||||
if (isScrolledToEnd && !viewModel.isLoadingMore && agentItems.isNotEmpty() && viewModel.hasMoreData) {
|
|
||||||
viewModel.loadMoreAgents()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Scaffold(
|
|
||||||
topBar = {
|
|
||||||
TopAppBar(
|
|
||||||
title = {
|
|
||||||
Image(
|
|
||||||
painter = painterResource(id = R.drawable.home_logo),
|
|
||||||
contentDescription = "Rave AI Logo",
|
|
||||||
modifier = Modifier
|
|
||||||
.height(44.dp)
|
|
||||||
.padding(top =9.dp,bottom=9.dp)
|
|
||||||
.wrapContentSize(),
|
|
||||||
// colorFilter = ColorFilter.tint(AppColors.text)
|
|
||||||
)
|
|
||||||
},
|
|
||||||
actions = {
|
|
||||||
Image(
|
|
||||||
painter = painterResource(id = R.drawable.rider_pro_nav_search),
|
|
||||||
contentDescription = "search",
|
|
||||||
modifier = Modifier
|
|
||||||
.size(44.dp)
|
|
||||||
.padding(top = 9.dp,bottom=9.dp)
|
|
||||||
.noRippleClickable {
|
|
||||||
navController.navigate(NavigationRoute.Search.route)
|
|
||||||
},
|
|
||||||
colorFilter = ColorFilter.tint(AppColors.text)
|
|
||||||
)
|
|
||||||
},
|
|
||||||
colors = TopAppBarDefaults.topAppBarColors(
|
|
||||||
containerColor = AppColors.background
|
|
||||||
),
|
|
||||||
windowInsets = WindowInsets(0, 0, 0, 0),
|
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.height(44.dp + statusBarPaddingValues.calculateTopPadding())
|
.fillMaxWidth()
|
||||||
.padding(top = statusBarPaddingValues.calculateTopPadding())
|
.fillMaxHeight().padding(top = 32.dp, start = 16.dp, end = 16.dp),
|
||||||
)
|
horizontalArrangement = Arrangement.Start,
|
||||||
},
|
verticalAlignment = Alignment.CenterVertically
|
||||||
containerColor = AppColors.background,
|
) {
|
||||||
contentWindowInsets = WindowInsets(0, 0, 0, 0)
|
Text(
|
||||||
) { paddingValues ->
|
text = "Rave AI",
|
||||||
|
fontSize = 20.sp,
|
||||||
|
fontWeight = FontWeight.W900,
|
||||||
|
color = AppColors.text,
|
||||||
|
modifier = Modifier
|
||||||
|
.align(Alignment.CenterVertically)
|
||||||
|
)
|
||||||
|
|
||||||
|
Spacer(modifier = Modifier.weight(1f))
|
||||||
|
|
||||||
|
Image(
|
||||||
|
painter = painterResource(id = R.drawable.rider_pro_nav_search),
|
||||||
|
contentDescription = "search",
|
||||||
|
modifier = Modifier
|
||||||
|
.size(24.dp)
|
||||||
|
.noRippleClickable {
|
||||||
|
navController.navigate(NavigationRoute.Search.route)
|
||||||
|
},
|
||||||
|
colorFilter = ColorFilter.tint(AppColors.text)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
LazyColumn(
|
LazyColumn(
|
||||||
state = listState,
|
state = listState,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
.padding(paddingValues)
|
|
||||||
.padding(
|
.padding(
|
||||||
|
top = 44.dp + statusBarPaddingValues.calculateTopPadding() + 15.dp,
|
||||||
bottom = navigationBarPaddings,
|
bottom = navigationBarPaddings,
|
||||||
start = 8.dp,
|
start = 16.dp,
|
||||||
end = 8.dp
|
end = 16.dp
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
|
|
||||||
// 类别标签页 - 吸顶
|
// 动态标签页
|
||||||
stickyHeader(key = "category_tabs") {
|
stickyHeader(key = "category_tabs") {
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
@@ -208,49 +196,33 @@ fun Agent() {
|
|||||||
.background(AppColors.background)
|
.background(AppColors.background)
|
||||||
.padding(top = 4.dp, bottom = 8.dp)
|
.padding(top = 4.dp, bottom = 8.dp)
|
||||||
) {
|
) {
|
||||||
LazyRow(
|
val selectedTabIndex = viewModel.selectedCategoryIndex
|
||||||
modifier = Modifier
|
if (viewModel.categories.isNotEmpty()) {
|
||||||
.fillMaxWidth()
|
LazyRow(
|
||||||
.wrapContentHeight()
|
modifier = Modifier
|
||||||
.padding(bottom = 8.dp),
|
.fillMaxWidth()
|
||||||
horizontalArrangement = Arrangement.Start,
|
.wrapContentHeight()
|
||||||
verticalAlignment = Alignment.CenterVertically
|
.padding(bottom = 16.dp),
|
||||||
) {
|
horizontalArrangement = Arrangement.Start,
|
||||||
item {
|
verticalAlignment = Alignment.CenterVertically
|
||||||
CustomTabItem(
|
) {
|
||||||
text = stringResource(R.string.agent_recommend),
|
viewModel.categories.forEachIndexed { index, category ->
|
||||||
isSelected = selectedTabIndex == 0,
|
item {
|
||||||
onClick = {
|
CustomTabItem(
|
||||||
selectedTabIndex = 0
|
text = category.getLocalizedName(),
|
||||||
viewModel.loadAllAgents()
|
isSelected = selectedTabIndex == index,
|
||||||
|
onClick = { viewModel.selectCategory(index) }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (index < viewModel.categories.size - 1) {
|
||||||
|
item { TabSpacer() }
|
||||||
}
|
}
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
item {
|
|
||||||
TabSpacer()
|
|
||||||
}
|
|
||||||
|
|
||||||
// 动态添加分类标签
|
|
||||||
viewModel.categories.forEachIndexed { index, category ->
|
|
||||||
item {
|
|
||||||
CustomTabItem(
|
|
||||||
text = category.name,
|
|
||||||
isSelected = selectedTabIndex == index + 1,
|
|
||||||
onClick = {
|
|
||||||
selectedTabIndex = index + 1
|
|
||||||
viewModel.loadAgentsByCategory(category.id)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
item {
|
|
||||||
TabSpacer()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 推荐内容区域
|
// 推荐内容区域
|
||||||
item {
|
item {
|
||||||
Column(
|
Column(
|
||||||
@@ -258,18 +230,7 @@ fun Agent() {
|
|||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.padding(vertical = 8.dp)
|
.padding(vertical = 8.dp)
|
||||||
) {
|
) {
|
||||||
when {
|
AgentViewPagerSection(agentItems = viewModel.topAgentItems, viewModel)
|
||||||
selectedTabIndex == 0 -> {
|
|
||||||
AgentViewPagerSection(agentItems = viewModel.agentItems.take(15), 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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -321,7 +282,7 @@ fun Agent() {
|
|||||||
|
|
||||||
item { Spacer(modifier = Modifier.height(20.dp)) }
|
item { Spacer(modifier = Modifier.height(20.dp)) }
|
||||||
|
|
||||||
// "发现更多" 标题 - 吸顶
|
// 发现区域
|
||||||
stickyHeader(key = "discover_more") {
|
stickyHeader(key = "discover_more") {
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
@@ -340,43 +301,47 @@ fun Agent() {
|
|||||||
androidx.compose.material3.Text(
|
androidx.compose.material3.Text(
|
||||||
text = stringResource(R.string.agent_find),
|
text = stringResource(R.string.agent_find),
|
||||||
fontSize = 16.sp,
|
fontSize = 16.sp,
|
||||||
fontWeight = androidx.compose.ui.text.font.FontWeight.W900,
|
fontWeight = androidx.compose.ui.text.font.FontWeight.W600,
|
||||||
color = AppColors.text
|
color = AppColors.text
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
item { Spacer(modifier = Modifier.height(20.dp)) }
|
||||||
|
|
||||||
// Agent网格 - 使用行式布局
|
// Agent 两列网格行
|
||||||
items(
|
items(viewModel.gridAgentItems.chunked(2)) { rowItems ->
|
||||||
items = agentItems.chunked(2),
|
|
||||||
key = { row -> row.firstOrNull()?.openId ?: "" }
|
|
||||||
) { rowItems ->
|
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.padding(vertical = 16.dp),
|
.padding(
|
||||||
|
top = 20.dp,
|
||||||
|
bottom = 20.dp
|
||||||
|
),
|
||||||
horizontalArrangement = Arrangement.spacedBy(16.dp)
|
horizontalArrangement = Arrangement.spacedBy(16.dp)
|
||||||
) {
|
) {
|
||||||
rowItems.forEach { agentItem ->
|
Box(modifier = Modifier.weight(1f)) {
|
||||||
Box(
|
AgentCardSquare(
|
||||||
modifier = Modifier.weight(1f)
|
agentItem = rowItems[0],
|
||||||
) {
|
viewModel = viewModel,
|
||||||
|
navController = LocalNavController.current
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (rowItems.size > 1) {
|
||||||
|
Box(modifier = Modifier.weight(1f)) {
|
||||||
AgentCardSquare(
|
AgentCardSquare(
|
||||||
agentItem = agentItem,
|
agentItem = rowItems[1],
|
||||||
viewModel = viewModel,
|
viewModel = viewModel,
|
||||||
navController = LocalNavController.current
|
navController = LocalNavController.current
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
// 如果这一行只有一个item,添加一个空的占位符
|
|
||||||
if (rowItems.size == 1) {
|
|
||||||
Spacer(modifier = Modifier.weight(1f))
|
Spacer(modifier = Modifier.weight(1f))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 加载更多指示器
|
// 加载更多指示器
|
||||||
if (viewModel.isLoadingMore) {
|
if (viewModel.isLoading) {
|
||||||
item {
|
item {
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
@@ -391,7 +356,7 @@ fun Agent() {
|
|||||||
)
|
)
|
||||||
Spacer(modifier = Modifier.width(12.dp))
|
Spacer(modifier = Modifier.width(12.dp))
|
||||||
androidx.compose.material3.Text(
|
androidx.compose.material3.Text(
|
||||||
text = "加载中...",
|
text = stringResource(R.string.agent_chat_loading),
|
||||||
color = AppColors.secondaryText,
|
color = AppColors.secondaryText,
|
||||||
fontSize = 14.sp
|
fontSize = 14.sp
|
||||||
)
|
)
|
||||||
@@ -534,20 +499,20 @@ fun AgentCardSquare(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 聊天按钮
|
// 聊天按钮,固定在底部居中,距离底部有一定边距
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.align(Alignment.BottomCenter)
|
.align(Alignment.BottomCenter)
|
||||||
.padding(bottom = 12.dp)
|
.padding(bottom = 12.dp) // 距离底部的边距
|
||||||
.width(60.dp)
|
.width(60.dp)
|
||||||
.height(32.dp)
|
.height(32.dp)
|
||||||
.background(
|
.background(
|
||||||
color = AppColors.text,
|
color = AppColors.text,
|
||||||
shape = RoundedCornerShape(
|
shape = RoundedCornerShape(
|
||||||
topStart = 14.dp,
|
topStart = 10.dp,
|
||||||
topEnd = 14.dp,
|
topEnd = 10.dp,
|
||||||
bottomStart = 0.dp,
|
bottomStart = 0.dp,
|
||||||
bottomEnd = 14.dp
|
bottomEnd = 10.dp
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.clickable {
|
.clickable {
|
||||||
@@ -577,9 +542,10 @@ fun AgentCardSquare(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(ExperimentalFoundationApi::class)
|
@OptIn(ExperimentalFoundationApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun AgentViewPagerSection(agentItems: List<AgentItem>,viewModel: AgentViewModel) {
|
fun AgentViewPagerSection(agentItems: List<AgentItem>, viewModel: AgentViewModel) {
|
||||||
val AppColors = LocalAppTheme.current
|
val AppColors = LocalAppTheme.current
|
||||||
|
|
||||||
// 每页显示5个agent
|
// 每页显示5个agent
|
||||||
@@ -593,7 +559,7 @@ fun AgentViewPagerSection(agentItems: List<AgentItem>,viewModel: AgentViewModel)
|
|||||||
// Agent内容
|
// Agent内容
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.height(310.dp)
|
.height(300.dp)
|
||||||
) {
|
) {
|
||||||
HorizontalPager(
|
HorizontalPager(
|
||||||
state = pagerState,
|
state = pagerState,
|
||||||
@@ -615,7 +581,7 @@ fun AgentViewPagerSection(agentItems: List<AgentItem>,viewModel: AgentViewModel)
|
|||||||
agentItems = agentItems.drop(page * itemsPerPage).take(itemsPerPage),
|
agentItems = agentItems.drop(page * itemsPerPage).take(itemsPerPage),
|
||||||
page = page,
|
page = page,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.height(310.dp)
|
.height(300.dp)
|
||||||
.graphicsLayer {
|
.graphicsLayer {
|
||||||
scaleX = scale
|
scaleX = scale
|
||||||
scaleY = scale
|
scaleY = scale
|
||||||
@@ -652,7 +618,13 @@ fun AgentViewPagerSection(agentItems: List<AgentItem>,viewModel: AgentViewModel)
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@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(
|
Column(
|
||||||
modifier = modifier
|
modifier = modifier
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
@@ -660,7 +632,11 @@ fun AgentPage(viewModel: AgentViewModel,agentItems: List<AgentItem>, page: Int,
|
|||||||
) {
|
) {
|
||||||
// 显示3个agent
|
// 显示3个agent
|
||||||
agentItems.forEachIndexed { index, agentItem ->
|
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) {
|
if (index < agentItems.size - 1) {
|
||||||
Spacer(modifier = Modifier.height(8.dp))
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
}
|
}
|
||||||
@@ -670,7 +646,7 @@ fun AgentPage(viewModel: AgentViewModel,agentItems: List<AgentItem>, page: Int,
|
|||||||
|
|
||||||
@SuppressLint("SuspiciousIndentation")
|
@SuppressLint("SuspiciousIndentation")
|
||||||
@Composable
|
@Composable
|
||||||
fun AgentCard2(viewModel: AgentViewModel,agentItem: AgentItem,navController: NavHostController) {
|
fun AgentCard2(viewModel: AgentViewModel, agentItem: AgentItem, navController: NavHostController) {
|
||||||
val AppColors = LocalAppTheme.current
|
val AppColors = LocalAppTheme.current
|
||||||
|
|
||||||
// 防抖状态
|
// 防抖状态
|
||||||
@@ -686,7 +662,7 @@ fun AgentCard2(viewModel: AgentViewModel,agentItem: AgentItem,navController: Nav
|
|||||||
Box(
|
Box(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.size(48.dp)
|
.size(48.dp)
|
||||||
.background(Color(0x00F5F5F5), RoundedCornerShape(24.dp))
|
.background(AppColors.secondaryBackground, RoundedCornerShape(24.dp))
|
||||||
.clickable {
|
.clickable {
|
||||||
if (DebounceUtils.simpleDebounceClick(lastClickTime, 500L) {
|
if (DebounceUtils.simpleDebounceClick(lastClickTime, 500L) {
|
||||||
viewModel.goToProfile(agentItem.openId, navController)
|
viewModel.goToProfile(agentItem.openId, navController)
|
||||||
@@ -696,12 +672,6 @@ fun AgentCard2(viewModel: AgentViewModel,agentItem: AgentItem,navController: Nav
|
|||||||
},
|
},
|
||||||
contentAlignment = Alignment.Center
|
contentAlignment = Alignment.Center
|
||||||
) {
|
) {
|
||||||
Image(
|
|
||||||
painter = painterResource(R.mipmap.group_copy),
|
|
||||||
contentDescription = "默认头像",
|
|
||||||
modifier = Modifier.size(48.dp),
|
|
||||||
)
|
|
||||||
|
|
||||||
if (agentItem.avatar.isNotEmpty()) {
|
if (agentItem.avatar.isNotEmpty()) {
|
||||||
CustomAsyncImage(
|
CustomAsyncImage(
|
||||||
imageUrl = agentItem.avatar,
|
imageUrl = agentItem.avatar,
|
||||||
@@ -711,6 +681,13 @@ fun AgentCard2(viewModel: AgentViewModel,agentItem: AgentItem,navController: Nav
|
|||||||
.clip(RoundedCornerShape(24.dp)),
|
.clip(RoundedCornerShape(24.dp)),
|
||||||
contentScale = androidx.compose.ui.layout.ContentScale.Crop
|
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)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -749,13 +726,8 @@ fun AgentCard2(viewModel: AgentViewModel,agentItem: AgentItem,navController: Nav
|
|||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.size(width = 60.dp, height = 32.dp)
|
.size(width = 60.dp, height = 32.dp)
|
||||||
.background(
|
.background(
|
||||||
color = Color(0X147c7480),
|
color = AppColors.inputBackground,
|
||||||
shape = RoundedCornerShape(
|
shape = RoundedCornerShape(8.dp)
|
||||||
topStart = 14.dp,
|
|
||||||
topEnd = 14.dp,
|
|
||||||
bottomStart = 0.dp,
|
|
||||||
bottomEnd = 14.dp
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
.clickable {
|
.clickable {
|
||||||
if (DebounceUtils.simpleDebounceClick(lastClickTime, 500L) {
|
if (DebounceUtils.simpleDebounceClick(lastClickTime, 500L) {
|
||||||
@@ -784,6 +756,7 @@ fun AgentCard2(viewModel: AgentViewModel,agentItem: AgentItem,navController: Nav
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ChatRoomsSection(
|
fun ChatRoomsSection(
|
||||||
chatRooms: List<ChatRoom>,
|
chatRooms: List<ChatRoom>,
|
||||||
@@ -845,7 +818,7 @@ fun ChatRoomCard(
|
|||||||
modifier: Modifier = Modifier
|
modifier: Modifier = Modifier
|
||||||
) {
|
) {
|
||||||
val AppColors = LocalAppTheme.current
|
val AppColors = LocalAppTheme.current
|
||||||
val cardSize = 180.dp
|
val cardSize = 160.dp
|
||||||
val viewModel: AgentViewModel = viewModel()
|
val viewModel: AgentViewModel = viewModel()
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
|
|
||||||
@@ -893,7 +866,7 @@ fun ChatRoomCard(
|
|||||||
Box(
|
Box(
|
||||||
modifier = modifier
|
modifier = modifier
|
||||||
.size(cardSize)
|
.size(cardSize)
|
||||||
.background(AppColors.tabUnselectedBackground, RoundedCornerShape(12.dp))
|
.background(AppColors.secondaryBackground, RoundedCornerShape(12.dp))
|
||||||
.clickable(enabled = !viewModel.isJoiningRoom) {
|
.clickable(enabled = !viewModel.isJoiningRoom) {
|
||||||
if (!viewModel.isJoiningRoom && DebounceUtils.simpleDebounceClick(lastClickTime, 500L) {
|
if (!viewModel.isJoiningRoom && DebounceUtils.simpleDebounceClick(lastClickTime, 500L) {
|
||||||
// 加入群聊房间
|
// 加入群聊房间
|
||||||
@@ -923,13 +896,8 @@ fun ChatRoomCard(
|
|||||||
imageUrl = imageUrl,
|
imageUrl = imageUrl,
|
||||||
contentDescription = if (chatRoom.banner.isNotEmpty()) "房间banner" else "房间头像",
|
contentDescription = if (chatRoom.banner.isNotEmpty()) "房间banner" else "房间头像",
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.width(cardSize)
|
.size(cardSize)
|
||||||
.height(120.dp)
|
.clip(RoundedCornerShape(12.dp)),
|
||||||
.clip(RoundedCornerShape(
|
|
||||||
topStart = 12.dp,
|
|
||||||
topEnd = 12.dp,
|
|
||||||
bottomStart = 0.dp,
|
|
||||||
bottomEnd = 0.dp)),
|
|
||||||
contentScale = androidx.compose.ui.layout.ContentScale.Crop
|
contentScale = androidx.compose.ui.layout.ContentScale.Crop
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
@@ -947,51 +915,21 @@ fun ChatRoomCard(
|
|||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.align(Alignment.BottomCenter)
|
.align(Alignment.BottomCenter)
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.padding(bottom = 32.dp, start = 10.dp, end = 10.dp)
|
.background(
|
||||||
.clip(RoundedCornerShape(12.dp))
|
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(
|
androidx.compose.material3.Text(
|
||||||
text = chatRoom.name,
|
text = chatRoom.name,
|
||||||
fontSize = 14.sp,
|
fontSize = 12.sp,
|
||||||
fontWeight = androidx.compose.ui.text.font.FontWeight.W900,
|
color = Color.White,
|
||||||
color = AppColors.text,
|
|
||||||
maxLines = 1,
|
maxLines = 1,
|
||||||
overflow = androidx.compose.ui.text.style.TextOverflow.Ellipsis,
|
overflow = androidx.compose.ui.text.style.TextOverflow.Ellipsis,
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
textAlign = androidx.compose.ui.text.style.TextAlign.Left
|
textAlign = androidx.compose.ui.text.style.TextAlign.Center
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
// 显示人数
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.align(Alignment.BottomCenter)
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(bottom = 10.dp, start = 10.dp, end = 10.dp)
|
|
||||||
) {
|
|
||||||
Row(
|
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
|
||||||
modifier = Modifier.fillMaxWidth()
|
|
||||||
) {
|
|
||||||
Image(
|
|
||||||
painter = painterResource(R.drawable.rider_pro_nav_profile),
|
|
||||||
contentDescription = "chat",
|
|
||||||
modifier = Modifier.size(16.dp),
|
|
||||||
colorFilter = ColorFilter.tint(AppColors.secondaryText)
|
|
||||||
)
|
|
||||||
Spacer(modifier = Modifier.width(4.dp))
|
|
||||||
Text(
|
|
||||||
text = "${chatRoom.memberCount} ${stringResource(R.string.chatting_now)}",
|
|
||||||
fontSize = 12.sp,
|
|
||||||
modifier = Modifier
|
|
||||||
.alpha(0.6f)
|
|
||||||
.weight(1f),
|
|
||||||
color = AppColors.text,
|
|
||||||
fontWeight = androidx.compose.ui.text.font.FontWeight.W500,
|
|
||||||
maxLines = 1,
|
|
||||||
overflow = TextOverflow.Ellipsis
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,65 +1,52 @@
|
|||||||
package com.aiosman.ravenow.ui.index.tabs.ai
|
package com.aiosman.ravenow.ui.index.tabs.ai
|
||||||
|
|
||||||
|
import android.util.Log
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import androidx.navigation.NavHostController
|
import androidx.navigation.NavHostController
|
||||||
import com.aiosman.ravenow.data.Agent
|
|
||||||
import com.aiosman.ravenow.data.ListContainer
|
|
||||||
import com.aiosman.ravenow.data.api.ApiClient
|
|
||||||
import com.aiosman.ravenow.data.api.CategoryTemplate
|
|
||||||
import com.aiosman.ravenow.data.api.RaveNowAPI
|
|
||||||
import com.aiosman.ravenow.data.api.SingleChatRequestBody
|
|
||||||
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.moment.tabs.expolre.AgentItem
|
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
import android.util.Log
|
|
||||||
import com.aiosman.ravenow.data.Room
|
|
||||||
import com.aiosman.ravenow.AppState
|
import com.aiosman.ravenow.AppState
|
||||||
import com.aiosman.ravenow.AppStore
|
import com.aiosman.ravenow.AppStore
|
||||||
import com.aiosman.ravenow.ConstVars
|
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.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.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.ui.navigateToGroupChat
|
||||||
import com.aiosman.ravenow.data.api.ApiErrorResponse
|
import com.aiosman.ravenow.data.api.ApiErrorResponse
|
||||||
import com.google.gson.Gson
|
import com.google.gson.Gson
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import com.aiosman.ravenow.data.api.JoinGroupChatRequestBody
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 缓存数据结构,用于存储每个分类的Agent列表
|
|
||||||
*/
|
|
||||||
data class AgentCacheData(
|
|
||||||
val items: List<AgentItem>,
|
|
||||||
val currentPage: Int,
|
|
||||||
val hasMoreData: Boolean
|
|
||||||
)
|
|
||||||
data class ChatRoom(
|
data class ChatRoom(
|
||||||
val id: Int,
|
val id: Int,
|
||||||
val name: String,
|
val name: String,
|
||||||
val avatar: String = "",
|
val avatar: String = "",
|
||||||
val banner: String = "",
|
val banner: String = "",
|
||||||
val memberCount: Int
|
val memberCount: Int = 0
|
||||||
)
|
)
|
||||||
|
|
||||||
object AgentViewModel: ViewModel() {
|
object AgentViewModel : ViewModel() {
|
||||||
|
|
||||||
private val apiClient: RaveNowAPI = ApiClient.api
|
private val apiClient: RaveNowAPI = ApiClient.api
|
||||||
|
|
||||||
var agentItems by mutableStateOf<List<AgentItem>>(emptyList())
|
// 顶部Agent列表数据(用于ViewPager)
|
||||||
|
var topAgentItems by mutableStateOf<List<AgentItem>>(emptyList())
|
||||||
private set
|
private set
|
||||||
|
|
||||||
var categories by mutableStateOf<List<CategoryItem>>(emptyList())
|
// 底部网格布局Agent数据
|
||||||
private set
|
var gridAgentItems by mutableStateOf<List<AgentItem>>(emptyList())
|
||||||
|
|
||||||
var errorMessage by mutableStateOf<String?>(null)
|
|
||||||
private set
|
private set
|
||||||
|
|
||||||
var chatRooms by mutableStateOf<List<ChatRoom>>(emptyList())
|
var chatRooms by mutableStateOf<List<ChatRoom>>(emptyList())
|
||||||
@@ -68,124 +55,131 @@ object AgentViewModel: ViewModel() {
|
|||||||
var rooms by mutableStateOf<List<Room>>(emptyList())
|
var rooms by mutableStateOf<List<Room>>(emptyList())
|
||||||
private set
|
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)
|
var isRefreshing by mutableStateOf(false)
|
||||||
private set
|
private set
|
||||||
|
|
||||||
var isLoading by mutableStateOf(false)
|
var isLoading by mutableStateOf(false)
|
||||||
private set
|
private set
|
||||||
|
|
||||||
// 分页相关状态
|
|
||||||
var isLoadingMore by mutableStateOf(false)
|
|
||||||
private set
|
|
||||||
|
|
||||||
var currentPage by mutableStateOf(1)
|
|
||||||
private set
|
|
||||||
|
|
||||||
var hasMoreData by mutableStateOf(true)
|
|
||||||
private set
|
|
||||||
|
|
||||||
var isJoiningRoom by mutableStateOf(false)
|
var isJoiningRoom by mutableStateOf(false)
|
||||||
private set
|
private set
|
||||||
|
|
||||||
private val pageSize = 20
|
private var topCurrentPage = 1
|
||||||
private var currentCategoryId: Int? = null
|
private var topHasMoreData = true
|
||||||
|
|
||||||
// 缓存:使用分类ID作为key,null表示推荐列表
|
private var gridCurrentPage = 1
|
||||||
private val agentCache = mutableMapOf<Int?, AgentCacheData>()
|
private var gridHasMoreData = true
|
||||||
|
|
||||||
init {
|
init {
|
||||||
loadAgentData()
|
loadTopAgentData()
|
||||||
loadCategories()
|
loadGridAgentData()
|
||||||
loadChatRooms()
|
loadChatRooms()
|
||||||
|
loadCategories()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun loadAgentData(categoryId: Int? = null, page: Int = 1, isLoadMore: Boolean = false, forceRefresh: Boolean = false) {
|
/**
|
||||||
|
* 加载顶部Agent列表数据(用于ViewPager)
|
||||||
|
*/
|
||||||
|
private fun loadTopAgentData(categoryIndex: Int = 0) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
// 如果不是强制刷新且不是加载更多,检查缓存
|
isLoading = true
|
||||||
if (!forceRefresh && !isLoadMore) {
|
|
||||||
val cached = agentCache[categoryId]
|
|
||||||
if (cached != null && cached.items.isNotEmpty()) {
|
|
||||||
// 使用缓存数据
|
|
||||||
agentItems = cached.items
|
|
||||||
currentPage = cached.currentPage
|
|
||||||
hasMoreData = cached.hasMoreData
|
|
||||||
currentCategoryId = categoryId
|
|
||||||
println("使用缓存数据,分类ID: $categoryId, 数据数量: ${cached.items.size}")
|
|
||||||
return@launch
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isLoadMore) {
|
|
||||||
isLoadingMore = true
|
|
||||||
} else {
|
|
||||||
isLoading = true
|
|
||||||
// 重置分页状态
|
|
||||||
currentPage = 1
|
|
||||||
hasMoreData = true
|
|
||||||
currentCategoryId = categoryId
|
|
||||||
}
|
|
||||||
|
|
||||||
errorMessage = null
|
errorMessage = null
|
||||||
|
topCurrentPage = 1
|
||||||
|
topHasMoreData = true
|
||||||
try {
|
try {
|
||||||
val response = if (categoryId != null) {
|
val selectedCategory =
|
||||||
// 根据分类ID获取智能体
|
if (categoryIndex < categories.size) categories[categoryIndex] else null
|
||||||
|
|
||||||
|
val response = if (categoryIndex == 0 || selectedCategory == null) {
|
||||||
|
// 推荐分类或无效分类,加载所有 Agent
|
||||||
apiClient.getAgent(
|
apiClient.getAgent(
|
||||||
page = page,
|
page = topCurrentPage,
|
||||||
pageSize = pageSize,
|
pageSize = 15,
|
||||||
withWorkflow = 1,
|
withWorkflow = "1",
|
||||||
categoryIds = listOf(categoryId),
|
random = "1"
|
||||||
random = 1
|
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
// 获取推荐智能体,使用random=1
|
// 特定分类,使用 categoryName 参数
|
||||||
apiClient.getAgent(
|
apiClient.getAgent(
|
||||||
page = page,
|
page = topCurrentPage,
|
||||||
pageSize = pageSize,
|
pageSize = 15,
|
||||||
withWorkflow = 1,
|
withWorkflow = "1",
|
||||||
categoryIds = null,
|
categoryName = selectedCategory.name,
|
||||||
random = 1
|
random = "1"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response.isSuccessful) {
|
if (response.isSuccessful) {
|
||||||
val responseData = response.body()?.data
|
val agents = response.body()?.data?.list ?: emptyList()
|
||||||
val agents = responseData?.list ?: emptyList<Agent>()
|
topAgentItems = agents.map { agent ->
|
||||||
val newAgentItems = agents.map { agent ->
|
|
||||||
AgentItem.fromAgent(agent)
|
AgentItem.fromAgent(agent)
|
||||||
}
|
}
|
||||||
|
topHasMoreData = agents.size >= 15
|
||||||
if (isLoadMore) {
|
|
||||||
// 加载更多:追加到现有列表
|
|
||||||
agentItems = agentItems + newAgentItems
|
|
||||||
currentPage = page
|
|
||||||
} else {
|
|
||||||
// 首次加载或刷新:替换整个列表
|
|
||||||
agentItems = newAgentItems
|
|
||||||
currentPage = 1
|
|
||||||
}
|
|
||||||
|
|
||||||
// 检查是否还有更多数据
|
|
||||||
hasMoreData = agents.size >= pageSize
|
|
||||||
|
|
||||||
// 更新缓存
|
|
||||||
agentCache[categoryId] = AgentCacheData(
|
|
||||||
items = agentItems,
|
|
||||||
currentPage = currentPage,
|
|
||||||
hasMoreData = hasMoreData
|
|
||||||
)
|
|
||||||
println("更新缓存,分类ID: $categoryId, 数据数量: ${agentItems.size}")
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
errorMessage = "获取Agent数据失败: ${response.code()}"
|
errorMessage = "获取顶部Agent数据失败: ${response.code()}"
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
errorMessage = "网络请求失败: ${e.message}"
|
errorMessage = "网络请求失败: ${e.message}"
|
||||||
} finally {
|
} finally {
|
||||||
if (isLoadMore) {
|
isLoading = false
|
||||||
isLoadingMore = 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 {
|
} else {
|
||||||
isLoading = false
|
// 特定分类,使用 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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -195,13 +189,14 @@ object AgentViewModel: ViewModel() {
|
|||||||
try {
|
try {
|
||||||
val response = apiClient.getRooms(
|
val response = apiClient.getRooms(
|
||||||
page = 1,
|
page = 1,
|
||||||
pageSize = 20,
|
pageSize = 21,
|
||||||
isRecommended = 1,
|
isRecommended = 1,
|
||||||
random = 1
|
random = 1
|
||||||
)
|
) // 请求21个,确保是3的倍数
|
||||||
if (response.isSuccessful) {
|
if (response.isSuccessful) {
|
||||||
val allRooms = response.body()?.list ?: emptyList()
|
val allRooms = response.body()?.list ?: emptyList()
|
||||||
val targetCount = (allRooms.size / 2) * 2
|
// 确保房间数量是3的倍数,如果不足则截取,如果超出则取前几个
|
||||||
|
val targetCount = (allRooms.size / 3) * 3 // 向下取整到最近的3的倍数
|
||||||
rooms = allRooms.take(targetCount)
|
rooms = allRooms.take(targetCount)
|
||||||
|
|
||||||
// 转换为ChatRoom格式用于兼容现有UI
|
// 转换为ChatRoom格式用于兼容现有UI
|
||||||
@@ -226,105 +221,138 @@ object AgentViewModel: ViewModel() {
|
|||||||
|
|
||||||
private fun loadCategories() {
|
private fun loadCategories() {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
// 如果分类已经加载,不重复请求
|
|
||||||
if (categories.isNotEmpty()) {
|
|
||||||
println("使用已缓存的分类数据,数量: ${categories.size}")
|
|
||||||
return@launch
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 获取完整的语言标记(如 "zh-CN")
|
val categoriesResponse = apiClient.getCategories(
|
||||||
val fullLangTag = com.aiosman.ravenow.utils.Utils.getPreferredLanguageTag()
|
|
||||||
// 转换为后端支持的语言代码(仅支持 zh、cn、ja)
|
|
||||||
val sysLang = convertToSupportedLangCode(fullLangTag)
|
|
||||||
val response = apiClient.getCategories(
|
|
||||||
page = 1,
|
page = 1,
|
||||||
pageSize = 100,
|
pageSize = 100,
|
||||||
isActive = true,
|
|
||||||
// withChildren = false,
|
|
||||||
// withParent = false,
|
|
||||||
// withCount = true,
|
|
||||||
// hideEmpty = true,
|
|
||||||
lang = sysLang
|
|
||||||
)
|
)
|
||||||
println("分类数据请求完成,响应成功: ${response.isSuccessful}, 原始语言标记: $fullLangTag, 转换后: $sysLang")
|
if (categoriesResponse.isSuccessful && categoriesResponse.body() != null) {
|
||||||
if (response.isSuccessful) {
|
// 添加一个默认的"推荐"分类在第一位
|
||||||
val categoryList = response.body()?.list ?: emptyList()
|
val recommendCategory = createRecommendCategory()
|
||||||
println("获取到 ${categoryList.size} 个分类")
|
val categoriesList = categoriesResponse.body()?.list ?: emptyList()
|
||||||
// 使用转换后的语言代码获取翻译后的分类名称
|
categories = listOf(recommendCategory) + categoriesList
|
||||||
categories = categoryList.map { category ->
|
|
||||||
CategoryItem.fromCategoryTemplate(category, sysLang)
|
// 分类加载完成后,重新加载当前选中分类的 Agent 数据
|
||||||
|
if (topAgentItems.isEmpty()) {
|
||||||
|
loadTopAgentData(selectedCategoryIndex)
|
||||||
|
}
|
||||||
|
if (gridAgentItems.isEmpty()) {
|
||||||
|
loadGridAgentData(selectedCategoryIndex)
|
||||||
}
|
}
|
||||||
println("成功处理并映射了 ${categories.size} 个分类")
|
|
||||||
} else {
|
} else {
|
||||||
errorMessage = "获取分类数据失败: ${response.code()}"
|
// 如果请求失败,使用默认分类
|
||||||
println("获取分类数据失败: ${response.code()}")
|
categories = listOf(createRecommendCategory())
|
||||||
|
errorMessage = "获取分类失败: ${categoriesResponse.code()}"
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
errorMessage = "获取分类数据失败: ${e.message}"
|
// 如果网络请求失败,使用默认分类
|
||||||
println("获取分类数据异常: ${e.message}")
|
categories = listOf(createRecommendCategory())
|
||||||
e.printStackTrace()
|
errorMessage = "网络请求失败: ${e.message}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将完整的语言标记转换为后端支持的语言代码
|
* 创建推荐分类
|
||||||
* 后端仅支持: zh, cn, ja
|
|
||||||
*
|
|
||||||
* @param langTag 完整的语言标记,如 "zh-CN", "zh-TW", "ja-JP", "en-US" 等
|
|
||||||
* @return 后端支持的语言代码,默认返回 "zh"
|
|
||||||
*/
|
*/
|
||||||
private fun convertToSupportedLangCode(langTag: String): String {
|
private fun createRecommendCategory(): CategoryTemplate {
|
||||||
return when {
|
return CategoryTemplate(
|
||||||
langTag.startsWith("zh", ignoreCase = true) -> "zh"
|
id = 0,
|
||||||
langTag.startsWith("ja", ignoreCase = true) -> "ja"
|
name = "推荐",
|
||||||
// 如果是中文相关的其他标记,也返回 zh
|
description = "推荐内容",
|
||||||
langTag.equals("cn", ignoreCase = true) -> "cn"
|
avatar = "",
|
||||||
// 默认返回中文
|
parentId = null,
|
||||||
else -> "zh"
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun loadAgentsByCategory(categoryId: Int) {
|
|
||||||
loadAgentData(categoryId)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun loadAllAgents() {
|
|
||||||
loadAgentData()
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 加载更多Agent数据
|
* 选择分类并加载对应的 Agent 数据
|
||||||
*/
|
*/
|
||||||
fun loadMoreAgents() {
|
fun selectCategory(categoryIndex: Int) {
|
||||||
// 检查是否正在加载或没有更多数据
|
if (categoryIndex != selectedCategoryIndex && categoryIndex >= 0 && categoryIndex < categories.size) {
|
||||||
if (isLoadingMore || !hasMoreData) {
|
selectedCategoryIndex = categoryIndex
|
||||||
return
|
// 同时加载顶部和网格的数据
|
||||||
|
loadTopAgentData(categoryIndex)
|
||||||
|
loadGridAgentData(categoryIndex)
|
||||||
}
|
}
|
||||||
|
|
||||||
val nextPage = currentPage + 1
|
|
||||||
loadAgentData(
|
|
||||||
categoryId = currentCategoryId,
|
|
||||||
page = nextPage,
|
|
||||||
isLoadMore = true
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun createSingleChat(
|
fun createSingleChat(
|
||||||
openId: String,
|
openId: String,
|
||||||
) {
|
) {
|
||||||
viewModelScope.launch {
|
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(
|
fun goToChatAi(
|
||||||
openId: String,
|
openId: String,
|
||||||
navController: NavHostController
|
navController: NavHostController
|
||||||
) {
|
) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
val profile = userService.getUserProfileByOpenId(openId)
|
val profile = userService.getUserProfileByOpenId(openId)
|
||||||
createGroup2ChatAi(profile.trtcUserId,"ai_group",navController,profile.id)
|
createGroup2ChatAi(profile.trtcUserId, "ai_group", navController, profile.id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -348,20 +376,26 @@ object AgentViewModel: ViewModel() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 刷新当前分类的Agent数据(强制刷新,清除缓存)
|
* 刷新推荐Agent数据
|
||||||
*/
|
*/
|
||||||
fun refreshAgentData() {
|
fun refreshAgentData() {
|
||||||
// 清除当前分类的缓存
|
loadTopAgentData()
|
||||||
agentCache.remove(currentCategoryId)
|
loadGridAgentData()
|
||||||
loadAgentData(categoryId = currentCategoryId, forceRefresh = true)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 检查数据是否为空,如果为空则重新加载
|
* 检查数据是否为空,如果为空则重新加载
|
||||||
*/
|
*/
|
||||||
fun ensureDataLoaded() {
|
fun ensureDataLoaded() {
|
||||||
if (agentItems.isEmpty() && !isLoading) {
|
if (topAgentItems.isEmpty() && !isLoading) {
|
||||||
loadAgentData()
|
loadTopAgentData()
|
||||||
|
}
|
||||||
|
if (gridAgentItems.isEmpty() && !isLoading) {
|
||||||
|
loadGridAgentData()
|
||||||
|
}
|
||||||
|
// 同时确保分类数据已加载
|
||||||
|
if (categories.isEmpty() && !isLoading) {
|
||||||
|
loadCategories()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -444,36 +478,18 @@ object AgentViewModel: ViewModel() {
|
|||||||
* 重置ViewModel状态,用于登出或切换账号时清理数据
|
* 重置ViewModel状态,用于登出或切换账号时清理数据
|
||||||
*/
|
*/
|
||||||
fun ResetModel() {
|
fun ResetModel() {
|
||||||
agentItems = emptyList()
|
topAgentItems = emptyList()
|
||||||
|
gridAgentItems = emptyList()
|
||||||
categories = emptyList()
|
categories = emptyList()
|
||||||
|
selectedCategoryIndex = 0
|
||||||
errorMessage = null
|
errorMessage = null
|
||||||
isRefreshing = false
|
isRefreshing = false
|
||||||
isLoading = false
|
isLoading = false
|
||||||
isLoadingMore = false
|
isJoiningRoom = false
|
||||||
currentPage = 1
|
topCurrentPage = 1
|
||||||
hasMoreData = true
|
topHasMoreData = true
|
||||||
currentCategoryId = null
|
gridCurrentPage = 1
|
||||||
// 清空缓存
|
gridHasMoreData = true
|
||||||
agentCache.clear()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
data class CategoryItem(
|
|
||||||
val id: Int,
|
|
||||||
val name: String,
|
|
||||||
val description: String,
|
|
||||||
val avatar: String,
|
|
||||||
val promptCount: Int?
|
|
||||||
) {
|
|
||||||
companion object {
|
|
||||||
fun fromCategoryTemplate(template: CategoryTemplate, lang: String): CategoryItem {
|
|
||||||
return CategoryItem(
|
|
||||||
id = template.id,
|
|
||||||
name = template.getLocalizedName(lang),
|
|
||||||
description = template.getLocalizedDescription(lang),
|
|
||||||
avatar = "${ApiClient.BASE_API_URL}${template.avatar}",
|
|
||||||
promptCount = template.promptCount
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ import androidx.compose.ui.graphics.ColorFilter
|
|||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.compose.ui.text.style.TextAlign
|
|
||||||
import androidx.compose.ui.text.style.TextOverflow
|
import androidx.compose.ui.text.style.TextOverflow
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
@@ -96,34 +95,26 @@ fun AgentChatListScreen() {
|
|||||||
|
|
||||||
if (isNetworkAvailable) {
|
if (isNetworkAvailable) {
|
||||||
Spacer(modifier = Modifier.height(39.dp))
|
Spacer(modifier = Modifier.height(39.dp))
|
||||||
Image(
|
Image(
|
||||||
painter = painterResource(
|
painter = painterResource(
|
||||||
id = if(AppState.darkMode) R.mipmap.juhao_dark
|
id = if(AppState.darkMode) R.mipmap.qs_znt_qs_as_img
|
||||||
else R.mipmap.invalid_name_5),
|
else R.mipmap.invalid_name_5),
|
||||||
contentDescription = "null data",
|
contentDescription = "null data",
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.size(width = 181.dp, height = 153.dp)
|
.size(181.dp)
|
||||||
)
|
)
|
||||||
Spacer(modifier = Modifier.height(if (AppState.darkMode) 9.dp else 24.dp))
|
Spacer(modifier = Modifier.height(24.dp))
|
||||||
Text(
|
Text(
|
||||||
text = stringResource(R.string.agent_chat_empty_title),
|
text = stringResource(R.string.agent_chat_empty_title),
|
||||||
color = AppColors.text,
|
color = AppColors.text,
|
||||||
fontSize = 16.sp,
|
fontSize = 16.sp,
|
||||||
fontWeight = FontWeight.W600,
|
fontWeight = FontWeight.W600
|
||||||
textAlign = TextAlign.Center,
|
)
|
||||||
modifier = Modifier.padding(horizontal = 24.dp),
|
|
||||||
maxLines = 2,
|
|
||||||
overflow = TextOverflow.Ellipsis
|
|
||||||
)
|
|
||||||
Spacer(modifier = Modifier.height(8.dp))
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
Text(
|
Text(
|
||||||
text = stringResource(R.string.agent_chat_empty_subtitle),
|
text = stringResource(R.string.agent_chat_empty_subtitle),
|
||||||
color = AppColors.secondaryText,
|
color = AppColors.secondaryText,
|
||||||
fontSize = 14.sp,
|
fontSize = 14.sp
|
||||||
textAlign = TextAlign.Center,
|
|
||||||
modifier = Modifier.padding(horizontal = 24.dp),
|
|
||||||
maxLines = 3,
|
|
||||||
overflow = TextOverflow.Ellipsis
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -139,21 +130,13 @@ fun AgentChatListScreen() {
|
|||||||
text = stringResource(R.string.friend_chat_no_network_title),
|
text = stringResource(R.string.friend_chat_no_network_title),
|
||||||
color = AppColors.text,
|
color = AppColors.text,
|
||||||
fontSize = 16.sp,
|
fontSize = 16.sp,
|
||||||
fontWeight = FontWeight.W600,
|
fontWeight = FontWeight.W600
|
||||||
textAlign = TextAlign.Center,
|
|
||||||
modifier = Modifier.padding(horizontal = 24.dp),
|
|
||||||
maxLines = 2,
|
|
||||||
overflow = TextOverflow.Ellipsis
|
|
||||||
)
|
)
|
||||||
Spacer(modifier = Modifier.height(8.dp))
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
Text(
|
Text(
|
||||||
text = stringResource(R.string.friend_chat_no_network_subtitle),
|
text = stringResource(R.string.friend_chat_no_network_subtitle),
|
||||||
color = AppColors.secondaryText,
|
color = AppColors.secondaryText,
|
||||||
fontSize = 14.sp,
|
fontSize = 14.sp
|
||||||
textAlign = TextAlign.Center,
|
|
||||||
modifier = Modifier.padding(horizontal = 24.dp),
|
|
||||||
maxLines = 3,
|
|
||||||
overflow = TextOverflow.Ellipsis
|
|
||||||
)
|
)
|
||||||
Spacer(modifier = Modifier.height(16.dp))
|
Spacer(modifier = Modifier.height(16.dp))
|
||||||
ReloadButton(
|
ReloadButton(
|
||||||
|
|||||||
@@ -175,32 +175,24 @@ fun AllChatListScreen() {
|
|||||||
Spacer(modifier = Modifier.height(39.dp))
|
Spacer(modifier = Modifier.height(39.dp))
|
||||||
Image(
|
Image(
|
||||||
painter = painterResource(
|
painter = painterResource(
|
||||||
id = if(AppState.darkMode) R.mipmap.piao_dark
|
id = if(AppState.darkMode) R.mipmap.qs_py_qs_as_img
|
||||||
else R.mipmap.invalid_name_2),
|
else R.mipmap.invalid_name_2),
|
||||||
contentDescription = "null data",
|
contentDescription = "null data",
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.size(width = 181.dp, height = 153.dp)
|
.size(181.dp)
|
||||||
)
|
)
|
||||||
Spacer(modifier = Modifier.height(if (AppState.darkMode) 9.dp else 24.dp))
|
Spacer(modifier = Modifier.height(24.dp))
|
||||||
Text(
|
Text(
|
||||||
text = stringResource(R.string.friend_chat_empty_title),
|
text = stringResource(R.string.friend_chat_empty_title),
|
||||||
color = AppColors.text,
|
color = AppColors.text,
|
||||||
fontSize = 16.sp,
|
fontSize = 16.sp,
|
||||||
fontWeight = FontWeight.W600,
|
fontWeight = FontWeight.W600
|
||||||
textAlign = TextAlign.Center,
|
|
||||||
modifier = Modifier.padding(horizontal = 24.dp),
|
|
||||||
maxLines = 2,
|
|
||||||
overflow = TextOverflow.Ellipsis
|
|
||||||
)
|
)
|
||||||
Spacer(modifier = Modifier.height(8.dp))
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
Text(
|
Text(
|
||||||
text = stringResource(R.string.friend_chat_empty_subtitle),
|
text = stringResource(R.string.friend_chat_empty_subtitle),
|
||||||
color = AppColors.secondaryText,
|
color = AppColors.secondaryText,
|
||||||
fontSize = 14.sp,
|
fontSize = 14.sp
|
||||||
textAlign = TextAlign.Center,
|
|
||||||
modifier = Modifier.padding(horizontal = 24.dp),
|
|
||||||
maxLines = 3,
|
|
||||||
overflow = TextOverflow.Ellipsis
|
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
Spacer(modifier = Modifier.height(39.dp))
|
Spacer(modifier = Modifier.height(39.dp))
|
||||||
@@ -215,21 +207,13 @@ fun AllChatListScreen() {
|
|||||||
text = stringResource(R.string.friend_chat_no_network_title),
|
text = stringResource(R.string.friend_chat_no_network_title),
|
||||||
color = AppColors.text,
|
color = AppColors.text,
|
||||||
fontSize = 16.sp,
|
fontSize = 16.sp,
|
||||||
fontWeight = FontWeight.W600,
|
fontWeight = FontWeight.W600
|
||||||
textAlign = TextAlign.Center,
|
|
||||||
modifier = Modifier.padding(horizontal = 24.dp),
|
|
||||||
maxLines = 2,
|
|
||||||
overflow = TextOverflow.Ellipsis
|
|
||||||
)
|
)
|
||||||
Spacer(modifier = Modifier.height(8.dp))
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
Text(
|
Text(
|
||||||
text = stringResource(R.string.friend_chat_no_network_subtitle),
|
text = stringResource(R.string.friend_chat_no_network_subtitle),
|
||||||
color = AppColors.secondaryText,
|
color = AppColors.secondaryText,
|
||||||
fontSize = 14.sp,
|
fontSize = 14.sp
|
||||||
textAlign = TextAlign.Center,
|
|
||||||
modifier = Modifier.padding(horizontal = 24.dp),
|
|
||||||
maxLines = 3,
|
|
||||||
overflow = TextOverflow.Ellipsis
|
|
||||||
)
|
)
|
||||||
Spacer(modifier = Modifier.height(16.dp))
|
Spacer(modifier = Modifier.height(16.dp))
|
||||||
ReloadButton(
|
ReloadButton(
|
||||||
|
|||||||
@@ -83,34 +83,26 @@ fun FriendChatListScreen() {
|
|||||||
|
|
||||||
if (isNetworkAvailable) {
|
if (isNetworkAvailable) {
|
||||||
Spacer(modifier = Modifier.height(39.dp))
|
Spacer(modifier = Modifier.height(39.dp))
|
||||||
Image(
|
Image(
|
||||||
painter = painterResource(
|
painter = painterResource(
|
||||||
id = if(AppState.darkMode) R.mipmap.piao_dark
|
id = if(AppState.darkMode) R.mipmap.qs_py_qs_as_img
|
||||||
else R.mipmap.invalid_name_2),
|
else R.mipmap.invalid_name_2),
|
||||||
contentDescription = "null data",
|
contentDescription = "null data",
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.size(width = 181.dp, height = 153.dp)
|
.size(181.dp)
|
||||||
)
|
)
|
||||||
Spacer(modifier = Modifier.height(if (AppState.darkMode) 9.dp else 24.dp))
|
Spacer(modifier = Modifier.height(24.dp))
|
||||||
Text(
|
Text(
|
||||||
text = stringResource(R.string.friend_chat_empty_title),
|
text = stringResource(R.string.friend_chat_empty_title),
|
||||||
color = AppColors.text,
|
color = AppColors.text,
|
||||||
fontSize = 16.sp,
|
fontSize = 16.sp,
|
||||||
fontWeight = FontWeight.W600,
|
fontWeight = FontWeight.W600
|
||||||
textAlign = TextAlign.Center,
|
)
|
||||||
modifier = Modifier.padding(horizontal = 24.dp),
|
|
||||||
maxLines = 2,
|
|
||||||
overflow = TextOverflow.Ellipsis
|
|
||||||
)
|
|
||||||
Spacer(modifier = Modifier.height(8.dp))
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
Text(
|
Text(
|
||||||
text = stringResource(R.string.friend_chat_empty_subtitle),
|
text = stringResource(R.string.friend_chat_empty_subtitle),
|
||||||
color = AppColors.secondaryText,
|
color = AppColors.secondaryText,
|
||||||
fontSize = 14.sp,
|
fontSize = 14.sp
|
||||||
textAlign = TextAlign.Center,
|
|
||||||
modifier = Modifier.padding(horizontal = 24.dp),
|
|
||||||
maxLines = 3,
|
|
||||||
overflow = TextOverflow.Ellipsis
|
|
||||||
)
|
)
|
||||||
}else {
|
}else {
|
||||||
Spacer(modifier = Modifier.height(39.dp))
|
Spacer(modifier = Modifier.height(39.dp))
|
||||||
@@ -125,21 +117,13 @@ fun FriendChatListScreen() {
|
|||||||
text = stringResource(R.string.friend_chat_no_network_title),
|
text = stringResource(R.string.friend_chat_no_network_title),
|
||||||
color = AppColors.text,
|
color = AppColors.text,
|
||||||
fontSize = 16.sp,
|
fontSize = 16.sp,
|
||||||
fontWeight = FontWeight.W600,
|
fontWeight = FontWeight.W600
|
||||||
textAlign = TextAlign.Center,
|
|
||||||
modifier = Modifier.padding(horizontal = 24.dp),
|
|
||||||
maxLines = 2,
|
|
||||||
overflow = TextOverflow.Ellipsis
|
|
||||||
)
|
)
|
||||||
Spacer(modifier = Modifier.height(8.dp))
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
Text(
|
Text(
|
||||||
text = stringResource(R.string.friend_chat_no_network_subtitle),
|
text = stringResource(R.string.friend_chat_no_network_subtitle),
|
||||||
color = AppColors.secondaryText,
|
color = AppColors.secondaryText,
|
||||||
fontSize = 14.sp,
|
fontSize = 14.sp
|
||||||
textAlign = TextAlign.Center,
|
|
||||||
modifier = Modifier.padding(horizontal = 24.dp),
|
|
||||||
maxLines = 3,
|
|
||||||
overflow = TextOverflow.Ellipsis
|
|
||||||
)
|
)
|
||||||
Spacer(modifier = Modifier.height(16.dp))
|
Spacer(modifier = Modifier.height(16.dp))
|
||||||
ReloadButton(
|
ReloadButton(
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ import androidx.compose.ui.platform.LocalContext
|
|||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.compose.ui.text.style.TextAlign
|
|
||||||
import androidx.compose.ui.text.style.TextOverflow
|
import androidx.compose.ui.text.style.TextOverflow
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
@@ -76,34 +75,26 @@ fun GroupChatListScreen() {
|
|||||||
|
|
||||||
if (isNetworkAvailable) {
|
if (isNetworkAvailable) {
|
||||||
Spacer(modifier = Modifier.height(39.dp))
|
Spacer(modifier = Modifier.height(39.dp))
|
||||||
Image(
|
Image(
|
||||||
painter = painterResource(
|
painter = painterResource(
|
||||||
id = if(AppState.darkMode) R.mipmap.fei_dark
|
id = if(AppState.darkMode) R.mipmap.qs_ql_qs_as_img
|
||||||
else R.mipmap.invalid_name_12),
|
else R.mipmap.invalid_name_12),
|
||||||
contentDescription = "null data",
|
contentDescription = "null data",
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.size(width = 181.dp, height = 153.dp)
|
.size(181.dp)
|
||||||
)
|
)
|
||||||
Spacer(modifier = Modifier.height(if (AppState.darkMode) 9.dp else 24.dp))
|
Spacer(modifier = Modifier.height(24.dp))
|
||||||
Text(
|
Text(
|
||||||
text = stringResource(R.string.group_chat_empty),
|
text = stringResource(R.string.group_chat_empty),
|
||||||
color = AppColors.text,
|
color = AppColors.text,
|
||||||
fontSize = 16.sp,
|
fontSize = 16.sp,
|
||||||
fontWeight = FontWeight.W600,
|
fontWeight = FontWeight.W600
|
||||||
textAlign = TextAlign.Center,
|
)
|
||||||
modifier = Modifier.padding(horizontal = 24.dp),
|
|
||||||
maxLines = 2,
|
|
||||||
overflow = TextOverflow.Ellipsis
|
|
||||||
)
|
|
||||||
Spacer(modifier = Modifier.height(8.dp))
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
Text(
|
Text(
|
||||||
text = stringResource(R.string.group_chat_empty_join),
|
text = stringResource(R.string.group_chat_empty_join),
|
||||||
color = AppColors.secondaryText,
|
color = AppColors.secondaryText,
|
||||||
fontSize = 14.sp,
|
fontSize = 14.sp
|
||||||
textAlign = TextAlign.Center,
|
|
||||||
modifier = Modifier.padding(horizontal = 24.dp),
|
|
||||||
maxLines = 3,
|
|
||||||
overflow = TextOverflow.Ellipsis
|
|
||||||
)
|
)
|
||||||
}else {
|
}else {
|
||||||
Spacer(modifier = Modifier.height(39.dp))
|
Spacer(modifier = Modifier.height(39.dp))
|
||||||
@@ -118,21 +109,13 @@ fun GroupChatListScreen() {
|
|||||||
text = stringResource(R.string.friend_chat_no_network_title),
|
text = stringResource(R.string.friend_chat_no_network_title),
|
||||||
color = AppColors.text,
|
color = AppColors.text,
|
||||||
fontSize = 16.sp,
|
fontSize = 16.sp,
|
||||||
fontWeight = FontWeight.W600,
|
fontWeight = FontWeight.W600
|
||||||
textAlign = TextAlign.Center,
|
|
||||||
modifier = Modifier.padding(horizontal = 24.dp),
|
|
||||||
maxLines = 2,
|
|
||||||
overflow = TextOverflow.Ellipsis
|
|
||||||
)
|
)
|
||||||
Spacer(modifier = Modifier.height(8.dp))
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
Text(
|
Text(
|
||||||
text = stringResource(R.string.friend_chat_no_network_subtitle),
|
text = stringResource(R.string.friend_chat_no_network_subtitle),
|
||||||
color = AppColors.secondaryText,
|
color = AppColors.secondaryText,
|
||||||
fontSize = 14.sp,
|
fontSize = 14.sp
|
||||||
textAlign = TextAlign.Center,
|
|
||||||
modifier = Modifier.padding(horizontal = 24.dp),
|
|
||||||
maxLines = 3,
|
|
||||||
overflow = TextOverflow.Ellipsis
|
|
||||||
)
|
)
|
||||||
Spacer(modifier = Modifier.height(16.dp))
|
Spacer(modifier = Modifier.height(16.dp))
|
||||||
ReloadButton(
|
ReloadButton(
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ import com.aiosman.ravenow.event.MomentAddEvent
|
|||||||
import com.aiosman.ravenow.event.MomentFavouriteChangeEvent
|
import com.aiosman.ravenow.event.MomentFavouriteChangeEvent
|
||||||
import com.aiosman.ravenow.event.MomentLikeChangeEvent
|
import com.aiosman.ravenow.event.MomentLikeChangeEvent
|
||||||
import com.aiosman.ravenow.event.MomentRemoveEvent
|
import com.aiosman.ravenow.event.MomentRemoveEvent
|
||||||
import com.aiosman.ravenow.ui.follower.FollowerNoticeViewModel
|
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import org.greenrobot.eventbus.EventBus
|
import org.greenrobot.eventbus.EventBus
|
||||||
import org.greenrobot.eventbus.Subscribe
|
import org.greenrobot.eventbus.Subscribe
|
||||||
@@ -73,12 +72,9 @@ open class BaseMomentModel :ViewModel(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun onAddComment(id: Int) {
|
suspend fun onAddComment(id: Int) {
|
||||||
momentLoader.updateCommentCount(id, +1)
|
// val currentPagingData = _momentsFlow.value
|
||||||
}
|
// updateCommentCount(id)
|
||||||
|
|
||||||
fun onDeleteComment(id: Int) {
|
|
||||||
momentLoader.updateCommentCount(id, -1)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -87,7 +83,6 @@ open class BaseMomentModel :ViewModel(){
|
|||||||
fun onMomentFavoriteChangeEvent(event: MomentFavouriteChangeEvent) {
|
fun onMomentFavoriteChangeEvent(event: MomentFavouriteChangeEvent) {
|
||||||
momentLoader.updateFavoriteCount(event.postId, event.isFavourite)
|
momentLoader.updateFavoriteCount(event.postId, event.isFavourite)
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun favoriteMoment(id: Int) {
|
suspend fun favoriteMoment(id: Int) {
|
||||||
momentService.favoriteMoment(id)
|
momentService.favoriteMoment(id)
|
||||||
momentLoader.updateFavoriteCount(id, true)
|
momentLoader.updateFavoriteCount(id, true)
|
||||||
@@ -123,11 +118,10 @@ open class BaseMomentModel :ViewModel(){
|
|||||||
userService.unFollowUser(moment.authorId.toString())
|
userService.unFollowUser(moment.authorId.toString())
|
||||||
EventBus.getDefault().post(FollowChangeEvent(moment.authorId, false))
|
EventBus.getDefault().post(FollowChangeEvent(moment.authorId, false))
|
||||||
} else {
|
} else {
|
||||||
// 调用 FollowerNoticeViewModel.followUser() 实现与 FollowerNotice.kt 相同的效果
|
userService.followUser(moment.authorId.toString())
|
||||||
// 该方法内部会调用 userService.followUser() 并发布 FollowChangeEvent 事件
|
EventBus.getDefault().post(FollowChangeEvent(moment.authorId, true))
|
||||||
FollowerNoticeViewModel.followUser(moment.authorId)
|
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package com.aiosman.ravenow.ui.index.tabs.moment
|
|||||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||||
import androidx.compose.foundation.Image
|
import androidx.compose.foundation.Image
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.horizontalScroll
|
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
@@ -21,7 +20,6 @@ import androidx.compose.foundation.layout.systemBars
|
|||||||
import androidx.compose.foundation.layout.width
|
import androidx.compose.foundation.layout.width
|
||||||
import androidx.compose.foundation.pager.HorizontalPager
|
import androidx.compose.foundation.pager.HorizontalPager
|
||||||
import androidx.compose.foundation.pager.rememberPagerState
|
import androidx.compose.foundation.pager.rememberPagerState
|
||||||
import androidx.compose.foundation.rememberScrollState
|
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
import androidx.compose.material.ExperimentalMaterialApi
|
import androidx.compose.material.ExperimentalMaterialApi
|
||||||
import androidx.compose.material.Icon
|
import androidx.compose.material.Icon
|
||||||
@@ -47,7 +45,6 @@ import com.aiosman.ravenow.ui.index.tabs.moment.tabs.dynamic.Dynamic
|
|||||||
import com.aiosman.ravenow.ui.index.tabs.moment.tabs.expolre.Explore
|
import com.aiosman.ravenow.ui.index.tabs.moment.tabs.expolre.Explore
|
||||||
import com.aiosman.ravenow.ui.index.tabs.moment.tabs.hot.HotMomentsList
|
import com.aiosman.ravenow.ui.index.tabs.moment.tabs.hot.HotMomentsList
|
||||||
import com.aiosman.ravenow.ui.index.tabs.moment.tabs.timeline.TimelineMomentsList
|
import com.aiosman.ravenow.ui.index.tabs.moment.tabs.timeline.TimelineMomentsList
|
||||||
import com.aiosman.ravenow.ui.index.tabs.moment.tabs.news.NewsScreen
|
|
||||||
import com.aiosman.ravenow.ui.index.tabs.search.SearchViewModel
|
import com.aiosman.ravenow.ui.index.tabs.search.SearchViewModel
|
||||||
import com.aiosman.ravenow.ui.modifiers.noRippleClickable
|
import com.aiosman.ravenow.ui.modifiers.noRippleClickable
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
@@ -57,9 +54,8 @@ import androidx.compose.runtime.remember
|
|||||||
import androidx.compose.ui.draw.clip
|
import androidx.compose.ui.draw.clip
|
||||||
import androidx.compose.ui.graphics.ColorFilter
|
import androidx.compose.ui.graphics.ColorFilter
|
||||||
import com.aiosman.ravenow.ui.composables.TabItem
|
import com.aiosman.ravenow.ui.composables.TabItem
|
||||||
import com.aiosman.ravenow.ui.composables.UnderlineTabItem
|
import com.aiosman.ravenow.ui.composables.TabSpacer
|
||||||
import com.aiosman.ravenow.ui.composables.rememberDebouncer
|
import com.aiosman.ravenow.ui.composables.rememberDebouncer
|
||||||
import com.aiosman.ravenow.ui.index.tabs.moment.tabs.shorts.ShortVideoScreen
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 动态列表
|
* 动态列表
|
||||||
@@ -72,8 +68,8 @@ fun MomentsList() {
|
|||||||
val navigationBarPaddings =
|
val navigationBarPaddings =
|
||||||
WindowInsets.navigationBars.asPaddingValues().calculateBottomPadding() + 48.dp
|
WindowInsets.navigationBars.asPaddingValues().calculateBottomPadding() + 48.dp
|
||||||
val statusBarPaddingValues = WindowInsets.systemBars.asPaddingValues()
|
val statusBarPaddingValues = WindowInsets.systemBars.asPaddingValues()
|
||||||
// 根据登录状态设置标签页数量:游客模式5个tab,非游客模式6个tab
|
// 游客模式下不显示timeline,只显示2个tab:Dynamic、Hot // 游客模式下不显示timeline,只显示3个tab:Explore、Dynamic、Hot
|
||||||
val tabCount = if (AppStore.isGuest) 5 else 6
|
val tabCount = if (AppStore.isGuest) 2 else 3 // val tabCount = if (AppStore.isGuest) 3 else 4
|
||||||
var pagerState = rememberPagerState { tabCount }
|
var pagerState = rememberPagerState { tabCount }
|
||||||
var scope = rememberCoroutineScope()
|
var scope = rememberCoroutineScope()
|
||||||
Column(
|
Column(
|
||||||
@@ -85,128 +81,60 @@ fun MomentsList() {
|
|||||||
),
|
),
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
) {
|
) {
|
||||||
// 顶部区域:可滚动的标签页 + 搜索按钮
|
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.height(44.dp)
|
.height(44.dp)
|
||||||
.padding(horizontal = 16.dp),
|
.padding(horizontal = 16.dp),
|
||||||
horizontalArrangement = Arrangement.SpaceBetween,
|
// center the tabs
|
||||||
|
horizontalArrangement = Arrangement.Start,
|
||||||
verticalAlignment = Alignment.CenterVertically
|
verticalAlignment = Alignment.CenterVertically
|
||||||
) {
|
) {
|
||||||
// 可滚动的标签页行
|
//原探索//
|
||||||
Row(
|
// Column(
|
||||||
modifier = Modifier
|
// modifier = Modifier
|
||||||
.weight(1f)
|
// .noRippleClickable {
|
||||||
.horizontalScroll(rememberScrollState()),
|
// scope.launch {
|
||||||
horizontalArrangement = Arrangement.Start,
|
// pagerState.animateScrollToPage(0)
|
||||||
verticalAlignment = Alignment.CenterVertically
|
// }
|
||||||
) {
|
// }.padding(start = 16.dp),
|
||||||
val tabDebouncer = rememberDebouncer()
|
// verticalArrangement = Arrangement.Center,
|
||||||
|
// horizontalAlignment = Alignment.CenterHorizontally
|
||||||
// 推荐标签
|
//
|
||||||
UnderlineTabItem(
|
// ) {
|
||||||
text = stringResource(R.string.tab_recommend),
|
// Text(
|
||||||
isSelected = pagerState.currentPage == 0,
|
// text = stringResource(R.string.index_worldwide),
|
||||||
onClick = {
|
// fontSize = if (pagerState.currentPage == 0)18.sp else 16.sp,
|
||||||
tabDebouncer {
|
// color = if (pagerState.currentPage == 0) AppColors.text else AppColors.nonActiveText,
|
||||||
scope.launch {
|
// fontWeight = FontWeight.W600)
|
||||||
pagerState.animateScrollToPage(0)
|
// Spacer(modifier = Modifier.height(4.dp))
|
||||||
}
|
//
|
||||||
}
|
// Image(
|
||||||
}
|
// painter = painterResource(
|
||||||
)
|
// if (pagerState.currentPage == 0) R.mipmap.tab_indicator_selected
|
||||||
|
// else R.drawable.tab_indicator_unselected
|
||||||
|
// ),
|
||||||
// 短视频标签
|
// contentDescription = "tab indicator",
|
||||||
UnderlineTabItem(
|
// modifier = Modifier
|
||||||
text = stringResource(R.string.tab_short_video),
|
// .width(34.dp)
|
||||||
isSelected = pagerState.currentPage == 1,
|
// .height(4.dp)
|
||||||
onClick = {
|
// )
|
||||||
tabDebouncer {
|
//
|
||||||
scope.launch {
|
// }
|
||||||
pagerState.animateScrollToPage(1)
|
// Spacer(modifier = Modifier.width(16.dp))
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
// 动态标签
|
|
||||||
UnderlineTabItem(
|
|
||||||
text = stringResource(R.string.moment),
|
|
||||||
isSelected = pagerState.currentPage == 2,
|
|
||||||
onClick = {
|
|
||||||
tabDebouncer {
|
|
||||||
scope.launch {
|
|
||||||
pagerState.animateScrollToPage(2)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
// 只有非游客用户才显示"关注"tab
|
|
||||||
if (!AppStore.isGuest) {
|
|
||||||
UnderlineTabItem(
|
|
||||||
text = stringResource(R.string.index_following),
|
|
||||||
isSelected = pagerState.currentPage == 3,
|
|
||||||
onClick = {
|
|
||||||
tabDebouncer {
|
|
||||||
scope.launch {
|
|
||||||
pagerState.animateScrollToPage(3)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
// 热门标签
|
|
||||||
UnderlineTabItem(
|
|
||||||
text = stringResource(R.string.index_hot),
|
|
||||||
isSelected = pagerState.currentPage == 4,
|
|
||||||
onClick = {
|
|
||||||
tabDebouncer {
|
|
||||||
scope.launch {
|
|
||||||
pagerState.animateScrollToPage(4)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
// 热门标签 (游客模式) - 在游客模式下,热门标签对应第3页
|
|
||||||
UnderlineTabItem(
|
|
||||||
text = stringResource(R.string.index_hot),
|
|
||||||
isSelected = pagerState.currentPage == 3,
|
|
||||||
onClick = {
|
|
||||||
tabDebouncer {
|
|
||||||
scope.launch {
|
|
||||||
pagerState.animateScrollToPage(3)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// 新闻标签 - 在游客模式下对应第4页,非游客模式下对应第5页
|
|
||||||
val newsPageIndex = if (AppStore.isGuest) 4 else 5
|
|
||||||
UnderlineTabItem(
|
|
||||||
text = stringResource(R.string.tab_news),
|
|
||||||
isSelected = pagerState.currentPage == newsPageIndex,
|
|
||||||
onClick = {
|
|
||||||
tabDebouncer {
|
|
||||||
scope.launch {
|
|
||||||
pagerState.animateScrollToPage(newsPageIndex)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 搜索按钮
|
|
||||||
val lastClickTime = remember { mutableStateOf(0L) }
|
val lastClickTime = remember { mutableStateOf(0L) }
|
||||||
val clickDelay = 500L
|
val clickDelay = 500L
|
||||||
|
Text(
|
||||||
|
text = stringResource(R.string.moment),
|
||||||
|
fontSize = 20.sp,
|
||||||
|
fontWeight = FontWeight.W900,
|
||||||
|
color = AppColors.text,
|
||||||
|
modifier = Modifier
|
||||||
|
.align(Alignment.CenterVertically)
|
||||||
|
)
|
||||||
|
|
||||||
|
Spacer(modifier = Modifier.weight(1f))
|
||||||
|
|
||||||
Image(
|
Image(
|
||||||
painter = painterResource(id = R.drawable.rider_pro_nav_search),
|
painter = painterResource(id = R.drawable.rider_pro_nav_search),
|
||||||
contentDescription = "search",
|
contentDescription = "search",
|
||||||
@@ -223,47 +151,114 @@ fun MomentsList() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Spacer(modifier = Modifier.height(23.dp))
|
||||||
|
|
||||||
|
Row(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.wrapContentHeight()
|
||||||
|
.padding(start = 16.dp, bottom = 16.dp),
|
||||||
|
horizontalArrangement = Arrangement.Start,
|
||||||
|
verticalAlignment = Alignment.Bottom
|
||||||
|
) {
|
||||||
|
val tabDebouncer = rememberDebouncer()
|
||||||
|
|
||||||
|
// 新探索标签
|
||||||
|
Box {
|
||||||
|
CustomTabItem(
|
||||||
|
text = stringResource(R.string.index_worldwide),
|
||||||
|
isSelected = pagerState.currentPage == 0,
|
||||||
|
onClick = {
|
||||||
|
tabDebouncer {
|
||||||
|
scope.launch {
|
||||||
|
pagerState.animateScrollToPage(0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
TabSpacer()
|
||||||
|
|
||||||
|
// 只有非游客用户才显示"关注"tab
|
||||||
|
if (!AppStore.isGuest) {
|
||||||
|
Box {
|
||||||
|
CustomTabItem(
|
||||||
|
text = stringResource(R.string.index_following),
|
||||||
|
isSelected = pagerState.currentPage == 1,
|
||||||
|
onClick = {
|
||||||
|
tabDebouncer {
|
||||||
|
scope.launch {
|
||||||
|
pagerState.animateScrollToPage(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
TabSpacer()
|
||||||
|
|
||||||
|
// 热门标签
|
||||||
|
Box {
|
||||||
|
CustomTabItem(
|
||||||
|
text = stringResource(R.string.index_hot),
|
||||||
|
isSelected = pagerState.currentPage == 2,
|
||||||
|
onClick = {
|
||||||
|
tabDebouncer {
|
||||||
|
scope.launch {
|
||||||
|
pagerState.animateScrollToPage(2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 热门标签 (游客模式)
|
||||||
|
Box {
|
||||||
|
CustomTabItem(
|
||||||
|
text = stringResource(R.string.index_hot),
|
||||||
|
isSelected = pagerState.currentPage == 1,
|
||||||
|
onClick = {
|
||||||
|
tabDebouncer {
|
||||||
|
scope.launch {
|
||||||
|
pagerState.animateScrollToPage(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
HorizontalPager(
|
HorizontalPager(
|
||||||
state = pagerState,
|
state = pagerState,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.weight(1f)
|
.weight(1f)
|
||||||
) {
|
) {
|
||||||
when (it) {
|
if (AppStore.isGuest) {
|
||||||
0 -> {
|
// 游客模式:Dynamic(0), Hot(1)
|
||||||
// 推荐页面
|
when (it) {
|
||||||
NewsScreen()
|
0 -> {
|
||||||
}
|
Dynamic()
|
||||||
1 -> {
|
}
|
||||||
// 短视频页面
|
1 -> {
|
||||||
ShortVideoScreen()
|
|
||||||
}
|
|
||||||
2 -> {
|
|
||||||
// 动态页面 - 暂时显示时间线内容
|
|
||||||
Dynamic()
|
|
||||||
}
|
|
||||||
3 -> {
|
|
||||||
// 关注页面 (仅非游客用户) 或 热门页面 (游客用户)
|
|
||||||
if (AppStore.isGuest) {
|
|
||||||
HotMomentsList()
|
HotMomentsList()
|
||||||
} else {
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 正常用户:Dynamic(0), Timeline(1), Hot(2)
|
||||||
|
when (it) {
|
||||||
|
0 -> {
|
||||||
|
Dynamic()
|
||||||
|
}
|
||||||
|
1 -> {
|
||||||
TimelineMomentsList()
|
TimelineMomentsList()
|
||||||
}
|
}
|
||||||
}
|
2 -> {
|
||||||
4 -> {
|
|
||||||
// 热门页面 (仅非游客用户) 或 新闻页面 (游客用户)
|
|
||||||
if (AppStore.isGuest) {
|
|
||||||
NewsScreen()
|
|
||||||
} else {
|
|
||||||
HotMomentsList()
|
HotMomentsList()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
5 -> {
|
|
||||||
// 新闻页面 (仅非游客用户)
|
|
||||||
if (!AppStore.isGuest) {
|
|
||||||
NewsScreen()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -168,7 +168,6 @@ fun Dynamic() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PullRefreshIndicator(model.refreshing, state, Modifier.align(Alignment.TopCenter))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -524,7 +524,7 @@ fun Explore() {
|
|||||||
Row(
|
Row(
|
||||||
verticalAlignment = Alignment.CenterVertically
|
verticalAlignment = Alignment.CenterVertically
|
||||||
) {
|
) {
|
||||||
Image(
|
/* Image(
|
||||||
painter = painterResource(R.drawable.rider_pro_nav_profile),
|
painter = painterResource(R.drawable.rider_pro_nav_profile),
|
||||||
contentDescription = "chat",
|
contentDescription = "chat",
|
||||||
modifier = Modifier.size(16.dp),
|
modifier = Modifier.size(16.dp),
|
||||||
@@ -536,7 +536,7 @@ fun Explore() {
|
|||||||
fontSize = 12.sp,
|
fontSize = 12.sp,
|
||||||
color = Color.White,
|
color = Color.White,
|
||||||
fontWeight = androidx.compose.ui.text.font.FontWeight.W500
|
fontWeight = androidx.compose.ui.text.font.FontWeight.W500
|
||||||
)
|
)*/
|
||||||
}
|
}
|
||||||
|
|
||||||
// 底部:标题和描述
|
// 底部:标题和描述
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ class ExploreViewModel : ViewModel() {
|
|||||||
isRefreshing = true
|
isRefreshing = true
|
||||||
errorMessage = null
|
errorMessage = null
|
||||||
try {
|
try {
|
||||||
val response = apiClient.getAgent(page = 1, pageSize = 20, withWorkflow = 1)
|
val response = apiClient.getAgent(page = 1, pageSize = 20, withWorkflow = "1")
|
||||||
if (response.isSuccessful) {
|
if (response.isSuccessful) {
|
||||||
val agents = response.body()?.data?.list ?: emptyList()
|
val agents = response.body()?.data?.list ?: emptyList()
|
||||||
agentItems = agents.map { agent ->
|
agentItems = agents.map { agent ->
|
||||||
@@ -118,7 +118,7 @@ class ExploreViewModel : ViewModel() {
|
|||||||
isLoading = true
|
isLoading = true
|
||||||
errorMessage = null
|
errorMessage = null
|
||||||
try {
|
try {
|
||||||
val response = apiClient.getAgent(page = 1, pageSize = 20, withWorkflow = 1)
|
val response = apiClient.getAgent(page = 1, pageSize = 20, withWorkflow = "1")
|
||||||
if (response.isSuccessful) {
|
if (response.isSuccessful) {
|
||||||
val agents = response.body()?.data?.list ?: emptyList()
|
val agents = response.body()?.data?.list ?: emptyList()
|
||||||
agentItems = agents.map { agent ->
|
agentItems = agents.map { agent ->
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import androidx.compose.foundation.Image
|
|||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.Row
|
|
||||||
import androidx.compose.foundation.layout.WindowInsets
|
import androidx.compose.foundation.layout.WindowInsets
|
||||||
import androidx.compose.foundation.layout.asPaddingValues
|
import androidx.compose.foundation.layout.asPaddingValues
|
||||||
import androidx.compose.foundation.layout.aspectRatio
|
import androidx.compose.foundation.layout.aspectRatio
|
||||||
@@ -14,14 +13,11 @@ import androidx.compose.foundation.layout.navigationBars
|
|||||||
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.lazy.LazyColumn
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
import androidx.compose.foundation.layout.height
|
import androidx.compose.foundation.lazy.grid.GridCells
|
||||||
import androidx.compose.foundation.layout.heightIn
|
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
|
||||||
import androidx.compose.foundation.layout.Spacer
|
import androidx.compose.foundation.lazy.grid.items
|
||||||
import androidx.compose.foundation.lazy.staggeredgrid.LazyVerticalStaggeredGrid
|
import androidx.compose.foundation.lazy.grid.rememberLazyGridState
|
||||||
import androidx.compose.foundation.lazy.staggeredgrid.items
|
|
||||||
import androidx.compose.foundation.lazy.staggeredgrid.rememberLazyStaggeredGridState
|
|
||||||
import androidx.compose.foundation.lazy.rememberLazyListState
|
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||||
import androidx.compose.foundation.lazy.staggeredgrid.StaggeredGridCells
|
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
import androidx.compose.material.ExperimentalMaterialApi
|
import androidx.compose.material.ExperimentalMaterialApi
|
||||||
import androidx.compose.material.pullrefresh.PullRefreshIndicator
|
import androidx.compose.material.pullrefresh.PullRefreshIndicator
|
||||||
@@ -43,7 +39,6 @@ import androidx.compose.ui.draw.clip
|
|||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.sp
|
|
||||||
import androidx.compose.runtime.collectAsState
|
import androidx.compose.runtime.collectAsState
|
||||||
import com.aiosman.ravenow.LocalAppTheme
|
import com.aiosman.ravenow.LocalAppTheme
|
||||||
import com.aiosman.ravenow.LocalNavController
|
import com.aiosman.ravenow.LocalNavController
|
||||||
@@ -109,8 +104,8 @@ fun DiscoverView() {
|
|||||||
val isLoading by model.isLoading.collectAsState()
|
val isLoading by model.isLoading.collectAsState()
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
val navController = LocalNavController.current
|
val navController = LocalNavController.current
|
||||||
val gridState = rememberLazyStaggeredGridState()
|
val gridState = rememberLazyGridState()
|
||||||
val AppColors = LocalAppTheme.current
|
|
||||||
// 监听滚动到底部,自动加载更多
|
// 监听滚动到底部,自动加载更多
|
||||||
LaunchedEffect(gridState, moments.size) {
|
LaunchedEffect(gridState, moments.size) {
|
||||||
snapshotFlow {
|
snapshotFlow {
|
||||||
@@ -129,49 +124,18 @@ fun DiscoverView() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LazyVerticalStaggeredGrid(
|
LazyVerticalGrid(
|
||||||
columns = StaggeredGridCells.Fixed(2),
|
columns = GridCells.Fixed(3),
|
||||||
state = gridState,
|
state = gridState,
|
||||||
modifier = Modifier.fillMaxSize().padding(bottom = 8.dp),
|
modifier = Modifier.fillMaxSize().padding(bottom = 8.dp),
|
||||||
contentPadding = androidx.compose.foundation.layout.PaddingValues(horizontal = 8.dp, vertical = 4.dp)
|
// contentPadding = PaddingValues(8.dp)
|
||||||
) {
|
) {
|
||||||
items(moments) { momentItem ->
|
items(moments) { momentItem ->
|
||||||
val debouncer = rememberDebouncer()
|
val debouncer = rememberDebouncer()
|
||||||
|
|
||||||
val textContent = momentItem.momentTextContent
|
|
||||||
// 对于英文和日文,每行字符数会更少,使用更保守的估算
|
|
||||||
val estimatedCharsPerLine = if (textContent.isNotEmpty()) {
|
|
||||||
// 检测是否包含非中文字符(英文、日文等)
|
|
||||||
val hasNonChinese = textContent.any {
|
|
||||||
val code = it.code
|
|
||||||
!(code >= 0x4E00 && code <= 0x9FFF) // 不在中文字符范围内
|
|
||||||
}
|
|
||||||
if (hasNonChinese) 15 else 20 // 英文/日文每行更少字符
|
|
||||||
} else {
|
|
||||||
20
|
|
||||||
}
|
|
||||||
val textLines = if (textContent.isNotEmpty()) {
|
|
||||||
val estimatedLines = (textContent.length / estimatedCharsPerLine) + 1
|
|
||||||
minOf(estimatedLines, 2) // 最多2行
|
|
||||||
} else {
|
|
||||||
0
|
|
||||||
}
|
|
||||||
|
|
||||||
val baseHeight = 200.dp
|
|
||||||
val singleLineTextHeight = 24.dp // 增加高度以适应英文/日文
|
|
||||||
val doubleLineTextHeight = 44.dp // 增加高度以适应英文/日文
|
|
||||||
val authorInfoHeight = 25.dp
|
|
||||||
val paddingHeight = 10.dp
|
|
||||||
val paddingHeight2 = 3.dp
|
|
||||||
val totalHeight = baseHeight + when (textLines) {
|
|
||||||
0 -> authorInfoHeight + paddingHeight
|
|
||||||
1 -> singleLineTextHeight + authorInfoHeight + paddingHeight
|
|
||||||
else -> doubleLineTextHeight + authorInfoHeight + paddingHeight2
|
|
||||||
}
|
|
||||||
|
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
|
.aspectRatio(1f)
|
||||||
.padding(2.dp)
|
.padding(2.dp)
|
||||||
.noRippleClickable {
|
.noRippleClickable {
|
||||||
debouncer {
|
debouncer {
|
||||||
@@ -183,78 +147,14 @@ fun DiscoverView() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
Column(
|
CustomAsyncImage(
|
||||||
|
imageUrl = momentItem.images[0].thumbnail,
|
||||||
|
contentDescription = "",
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxSize(),
|
||||||
.background(AppColors.secondaryBackground, RoundedCornerShape(12.dp))
|
context = context,
|
||||||
) {
|
showShimmer = true
|
||||||
CustomAsyncImage(
|
)
|
||||||
imageUrl = momentItem.images[0].thumbnail,
|
|
||||||
contentDescription = "",
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.height(baseHeight)
|
|
||||||
.clip(RoundedCornerShape(
|
|
||||||
topStart = 12.dp,
|
|
||||||
topEnd = 12.dp,
|
|
||||||
bottomStart = 0.dp,
|
|
||||||
bottomEnd = 0.dp)),
|
|
||||||
context = context,
|
|
||||||
showShimmer = true
|
|
||||||
)
|
|
||||||
|
|
||||||
Column(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(horizontal = 8.dp, vertical = 8.dp)
|
|
||||||
) {
|
|
||||||
// 文本内容区域,限制最大高度
|
|
||||||
if (momentItem.momentTextContent.isNotEmpty()) {
|
|
||||||
androidx.compose.material3.Text(
|
|
||||||
text = momentItem.momentTextContent,
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
|
||||||
fontSize = 12.sp,
|
|
||||||
color = AppColors.text,
|
|
||||||
maxLines = 2,
|
|
||||||
overflow = androidx.compose.ui.text.style.TextOverflow.Ellipsis,
|
|
||||||
lineHeight = 16.sp // 设置行高以适应不同语言
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 使用 Spacer 确保头像昵称栏始终在底部,有足够的空间
|
|
||||||
Spacer(modifier = Modifier.weight(1f))
|
|
||||||
|
|
||||||
// 头像昵称栏,确保始终完整显示,设置最小高度避免被挤压
|
|
||||||
Row(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.heightIn(min = 25.dp) // 最小高度确保完整显示,自适应避免被挤压
|
|
||||||
.padding(top = 5.dp),
|
|
||||||
verticalAlignment = Alignment.CenterVertically
|
|
||||||
) {
|
|
||||||
CustomAsyncImage(
|
|
||||||
imageUrl = momentItem.avatar,
|
|
||||||
contentDescription = "",
|
|
||||||
modifier = Modifier
|
|
||||||
.size(16.dp)
|
|
||||||
.clip(RoundedCornerShape(8.dp)),
|
|
||||||
context = context,
|
|
||||||
showShimmer = true
|
|
||||||
)
|
|
||||||
|
|
||||||
androidx.compose.material3.Text(
|
|
||||||
text = momentItem.nickname,
|
|
||||||
modifier = Modifier
|
|
||||||
.padding(start = 4.dp)
|
|
||||||
.weight(1f),
|
|
||||||
fontSize = 11.sp,
|
|
||||||
color = AppColors.text.copy(alpha = 0.6f),
|
|
||||||
maxLines = 1,
|
|
||||||
overflow = androidx.compose.ui.text.style.TextOverflow.Ellipsis
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (momentItem.images.size > 1) {
|
if (momentItem.images.size > 1) {
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
|
|||||||
@@ -1,205 +0,0 @@
|
|||||||
package com.aiosman.ravenow.ui.index.tabs.moment.tabs.news
|
|
||||||
|
|
||||||
import androidx.compose.foundation.Image
|
|
||||||
import androidx.compose.foundation.background
|
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
|
||||||
import androidx.compose.foundation.layout.Box
|
|
||||||
import androidx.compose.foundation.layout.Column
|
|
||||||
import androidx.compose.foundation.layout.Row
|
|
||||||
import androidx.compose.foundation.layout.Spacer
|
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
|
||||||
import androidx.compose.foundation.layout.height
|
|
||||||
import androidx.compose.foundation.layout.padding
|
|
||||||
import androidx.compose.foundation.rememberScrollState
|
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
||||||
import androidx.compose.foundation.verticalScroll
|
|
||||||
import androidx.compose.material3.Button
|
|
||||||
import androidx.compose.material3.ButtonDefaults
|
|
||||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
|
||||||
import androidx.compose.material3.ModalBottomSheet
|
|
||||||
import androidx.compose.material3.Text
|
|
||||||
import androidx.compose.material3.rememberModalBottomSheetState
|
|
||||||
import androidx.compose.runtime.Composable
|
|
||||||
import androidx.compose.ui.Alignment
|
|
||||||
import androidx.compose.ui.Modifier
|
|
||||||
import androidx.compose.ui.draw.clip
|
|
||||||
import androidx.compose.ui.graphics.Color
|
|
||||||
import androidx.compose.ui.layout.ContentScale
|
|
||||||
import androidx.compose.ui.platform.LocalConfiguration
|
|
||||||
import androidx.compose.ui.platform.LocalContext
|
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
|
||||||
import androidx.compose.ui.unit.dp
|
|
||||||
import androidx.compose.ui.unit.sp
|
|
||||||
import com.aiosman.ravenow.LocalAppTheme
|
|
||||||
import com.aiosman.ravenow.R
|
|
||||||
import com.aiosman.ravenow.entity.MomentEntity
|
|
||||||
import com.aiosman.ravenow.exp.formatPostTime2
|
|
||||||
import com.aiosman.ravenow.ui.composables.CustomAsyncImage
|
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
|
||||||
@Composable
|
|
||||||
fun FullArticleModal(
|
|
||||||
moment: MomentEntity,
|
|
||||||
onDismiss: () -> Unit
|
|
||||||
) {
|
|
||||||
val appColors = LocalAppTheme.current
|
|
||||||
val context = LocalContext.current
|
|
||||||
val configuration = LocalConfiguration.current
|
|
||||||
val screenHeight = configuration.screenHeightDp.dp
|
|
||||||
val sheetHeight = screenHeight * 0.9f // 90% 高度
|
|
||||||
|
|
||||||
ModalBottomSheet(
|
|
||||||
onDismissRequest = onDismiss,
|
|
||||||
sheetState = rememberModalBottomSheetState(
|
|
||||||
skipPartiallyExpanded = true
|
|
||||||
),
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.height(sheetHeight),
|
|
||||||
containerColor = appColors.background,
|
|
||||||
shape = RoundedCornerShape(topStart = 16.dp, topEnd = 16.dp),
|
|
||||||
windowInsets = androidx.compose.foundation.layout.WindowInsets(0)
|
|
||||||
) {
|
|
||||||
Column(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxSize()
|
|
||||||
) {
|
|
||||||
// 滚动内容
|
|
||||||
Column(
|
|
||||||
modifier = Modifier
|
|
||||||
.weight(1f)
|
|
||||||
.verticalScroll(rememberScrollState())
|
|
||||||
) {
|
|
||||||
// 新闻图片区域 - 固定高度和宽度
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.height(250.dp)
|
|
||||||
|
|
||||||
.background(color = appColors.secondaryBackground)
|
|
||||||
) {
|
|
||||||
if (moment.images.isNotEmpty()) {
|
|
||||||
val firstImage = moment.images[0]
|
|
||||||
CustomAsyncImage(
|
|
||||||
context = context,
|
|
||||||
imageUrl = firstImage.url,
|
|
||||||
contentDescription = "新闻图片",
|
|
||||||
contentScale = ContentScale.Fit,
|
|
||||||
blurHash = firstImage.blurHash,
|
|
||||||
modifier = Modifier.fillMaxSize()
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
Image(
|
|
||||||
painter = androidx.compose.ui.res.painterResource(id = R.drawable.default_moment_img),
|
|
||||||
contentDescription = "默认图片",
|
|
||||||
contentScale = ContentScale.Fit,
|
|
||||||
modifier = Modifier.fillMaxSize()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(16.dp))
|
|
||||||
|
|
||||||
// 新闻标题
|
|
||||||
Text(
|
|
||||||
text = if (moment.newsTitle.isNotEmpty()) moment.newsTitle else moment.nickname,
|
|
||||||
fontSize = 20.sp,
|
|
||||||
fontWeight = FontWeight.Bold,
|
|
||||||
color = appColors.text,
|
|
||||||
lineHeight = 28.sp,
|
|
||||||
modifier = Modifier.padding(horizontal = 10.dp)
|
|
||||||
)
|
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(12.dp))
|
|
||||||
|
|
||||||
// 新闻来源和发布时间
|
|
||||||
Row(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(horizontal = 10.dp),
|
|
||||||
horizontalArrangement = Arrangement.SpaceBetween,
|
|
||||||
verticalAlignment = Alignment.CenterVertically
|
|
||||||
) {
|
|
||||||
// 来源按钮
|
|
||||||
Button(
|
|
||||||
onClick = { },
|
|
||||||
modifier = Modifier.height(28.dp),
|
|
||||||
colors = ButtonDefaults.buttonColors(
|
|
||||||
containerColor = Color(0xFF7c68ef)
|
|
||||||
),
|
|
||||||
contentPadding = androidx.compose.foundation.layout.PaddingValues(horizontal = 12.dp, vertical = 4.dp),
|
|
||||||
shape = RoundedCornerShape(14.dp)
|
|
||||||
) {
|
|
||||||
Text(
|
|
||||||
text = if (moment.newsSource.isNotEmpty()) moment.newsSource else moment.nickname,
|
|
||||||
fontSize = 12.sp,
|
|
||||||
color = Color.White,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 发布时间
|
|
||||||
Text(
|
|
||||||
text = moment.time.formatPostTime2(),
|
|
||||||
fontSize = 12.sp,
|
|
||||||
color = appColors.secondaryText
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(16.dp))
|
|
||||||
|
|
||||||
// 帖子内容
|
|
||||||
NewsContent(
|
|
||||||
content = if (moment.newsContent.isNotEmpty()) moment.newsContent else moment.momentTextContent,
|
|
||||||
images = moment.images,
|
|
||||||
context = context
|
|
||||||
)
|
|
||||||
Spacer(modifier = Modifier.height(200.dp))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
private fun NewsContent(
|
|
||||||
content: String,
|
|
||||||
images: List<com.aiosman.ravenow.entity.MomentImageEntity>,
|
|
||||||
context: android.content.Context
|
|
||||||
) {
|
|
||||||
val appColors = LocalAppTheme.current
|
|
||||||
|
|
||||||
Column(
|
|
||||||
modifier = Modifier.padding(horizontal = 16.dp)
|
|
||||||
) {
|
|
||||||
Text(
|
|
||||||
text = content,
|
|
||||||
fontSize = 16.sp,
|
|
||||||
color = appColors.text,
|
|
||||||
lineHeight = 24.sp
|
|
||||||
)
|
|
||||||
|
|
||||||
// 图片内容
|
|
||||||
if (images.isNotEmpty()) {
|
|
||||||
Spacer(modifier = Modifier.height(16.dp))
|
|
||||||
|
|
||||||
images.forEach { image ->
|
|
||||||
Spacer(modifier = Modifier.height(12.dp))
|
|
||||||
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.clip(RoundedCornerShape(8.dp))
|
|
||||||
) {
|
|
||||||
CustomAsyncImage(
|
|
||||||
context = context,
|
|
||||||
imageUrl = image.url,
|
|
||||||
contentDescription = "内容图片",
|
|
||||||
contentScale = ContentScale.Fit,
|
|
||||||
blurHash = image.blurHash,
|
|
||||||
modifier = Modifier.fillMaxWidth()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,306 +0,0 @@
|
|||||||
package com.aiosman.ravenow.ui.index.tabs.moment.tabs.news
|
|
||||||
|
|
||||||
import androidx.compose.foundation.Image
|
|
||||||
import androidx.compose.foundation.background
|
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
|
||||||
import androidx.compose.foundation.layout.Box
|
|
||||||
import androidx.compose.foundation.layout.Column
|
|
||||||
import androidx.compose.foundation.layout.Row
|
|
||||||
import androidx.compose.foundation.layout.Spacer
|
|
||||||
import androidx.compose.foundation.layout.WindowInsets
|
|
||||||
import androidx.compose.foundation.layout.asPaddingValues
|
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
|
||||||
import androidx.compose.foundation.layout.height
|
|
||||||
import androidx.compose.foundation.layout.navigationBars
|
|
||||||
import androidx.compose.foundation.layout.padding
|
|
||||||
import androidx.compose.foundation.layout.size
|
|
||||||
import androidx.compose.foundation.layout.width
|
|
||||||
import androidx.compose.foundation.lazy.LazyColumn
|
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
||||||
import androidx.compose.material.icons.Icons
|
|
||||||
import androidx.compose.material.icons.filled.Close
|
|
||||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
|
||||||
import androidx.compose.material3.HorizontalDivider
|
|
||||||
import androidx.compose.material3.ModalBottomSheet
|
|
||||||
import androidx.compose.material3.Text
|
|
||||||
import androidx.compose.material3.rememberModalBottomSheetState
|
|
||||||
import androidx.compose.runtime.Composable
|
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
|
||||||
import androidx.compose.runtime.getValue
|
|
||||||
import androidx.compose.runtime.mutableStateOf
|
|
||||||
import androidx.compose.runtime.remember
|
|
||||||
import androidx.compose.runtime.setValue
|
|
||||||
import androidx.compose.ui.Alignment
|
|
||||||
import androidx.compose.ui.Modifier
|
|
||||||
import androidx.compose.ui.graphics.Color
|
|
||||||
import androidx.compose.ui.graphics.ColorFilter
|
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
|
||||||
import androidx.compose.ui.unit.dp
|
|
||||||
import androidx.compose.ui.unit.sp
|
|
||||||
import androidx.lifecycle.ViewModel
|
|
||||||
import androidx.lifecycle.ViewModelProvider
|
|
||||||
import androidx.lifecycle.viewModelScope
|
|
||||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
|
||||||
import com.aiosman.ravenow.AppState
|
|
||||||
import com.aiosman.ravenow.GuestLoginCheckOut
|
|
||||||
import com.aiosman.ravenow.GuestLoginCheckOutScene
|
|
||||||
import com.aiosman.ravenow.LocalAppTheme
|
|
||||||
import com.aiosman.ravenow.LocalNavController
|
|
||||||
import com.aiosman.ravenow.R
|
|
||||||
import com.aiosman.ravenow.data.CommentService
|
|
||||||
import com.aiosman.ravenow.data.CommentServiceImpl
|
|
||||||
import com.aiosman.ravenow.entity.CommentEntity
|
|
||||||
import com.aiosman.ravenow.ui.NavigationRoute
|
|
||||||
import com.aiosman.ravenow.ui.composables.EditCommentBottomModal
|
|
||||||
import com.aiosman.ravenow.ui.composables.debouncedClickable
|
|
||||||
import com.aiosman.ravenow.ui.composables.rememberDebouncedNavigation
|
|
||||||
import com.aiosman.ravenow.ui.modifiers.noRippleClickable
|
|
||||||
import com.aiosman.ravenow.ui.post.CommentContent
|
|
||||||
import com.aiosman.ravenow.ui.post.CommentMenuModal
|
|
||||||
import com.aiosman.ravenow.ui.post.CommentsViewModel
|
|
||||||
import com.aiosman.ravenow.ui.post.OrderSelectionComponent
|
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
|
|
||||||
|
|
||||||
class NewsCommentModalViewModel(
|
|
||||||
val postId: Int?
|
|
||||||
) : ViewModel() {
|
|
||||||
var commentsViewModel: CommentsViewModel = CommentsViewModel(postId.toString())
|
|
||||||
var commentService: CommentService = CommentServiceImpl()
|
|
||||||
|
|
||||||
init {
|
|
||||||
commentsViewModel.preTransit()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun likeComment(commentId: Int) {
|
|
||||||
viewModelScope.launch {
|
|
||||||
commentsViewModel.likeComment(commentId)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun unlikeComment(commentId: Int) {
|
|
||||||
viewModelScope.launch {
|
|
||||||
commentsViewModel.unlikeComment(commentId)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun createComment(
|
|
||||||
content: String,
|
|
||||||
parentCommentId: Int? = null,
|
|
||||||
replyUserId: Int? = null,
|
|
||||||
replyCommentId: Int? = null
|
|
||||||
) {
|
|
||||||
viewModelScope.launch {
|
|
||||||
commentsViewModel.createComment(
|
|
||||||
content = content,
|
|
||||||
parentCommentId = parentCommentId,
|
|
||||||
replyUserId = replyUserId,
|
|
||||||
replyCommentId = replyCommentId
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun deleteComment(commentId: Int) {
|
|
||||||
commentsViewModel.deleteComment(commentId)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 新闻评论弹窗
|
|
||||||
// @param postId 新闻帖子ID
|
|
||||||
// @param commentCount 评论数量
|
|
||||||
// @param onDismiss 关闭回调
|
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
|
||||||
@Composable
|
|
||||||
fun NewsCommentModal(
|
|
||||||
postId: Int? = null,
|
|
||||||
commentCount: Int = 0,
|
|
||||||
onDismiss: () -> Unit = {},
|
|
||||||
onCommentAdded: () -> Unit = {},
|
|
||||||
onCommentDeleted: () -> Unit = {}
|
|
||||||
) {
|
|
||||||
val AppColors = LocalAppTheme.current
|
|
||||||
val navController = LocalNavController.current
|
|
||||||
val debouncedNavigation = rememberDebouncedNavigation()
|
|
||||||
|
|
||||||
// 实时评论数状态
|
|
||||||
var currentCommentCount by remember { mutableStateOf(commentCount) }
|
|
||||||
|
|
||||||
val model = viewModel<NewsCommentModalViewModel>(
|
|
||||||
key = "NewsCommentModalViewModel_$postId",
|
|
||||||
factory = object : ViewModelProvider.Factory {
|
|
||||||
override fun <T : ViewModel> create(modelClass: Class<T>): T {
|
|
||||||
return NewsCommentModalViewModel(postId) as T
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
val commentViewModel = model.commentsViewModel
|
|
||||||
var navBarHeight = WindowInsets.navigationBars.asPaddingValues().calculateBottomPadding()
|
|
||||||
|
|
||||||
var showCommentMenu by remember { mutableStateOf(false) }
|
|
||||||
var contextComment by remember { mutableStateOf<CommentEntity?>(null) }
|
|
||||||
var replyComment by remember { mutableStateOf<CommentEntity?>(null) }
|
|
||||||
|
|
||||||
// 菜单弹窗
|
|
||||||
if (showCommentMenu) {
|
|
||||||
ModalBottomSheet(
|
|
||||||
onDismissRequest = {
|
|
||||||
showCommentMenu = false
|
|
||||||
},
|
|
||||||
containerColor = AppColors.background,
|
|
||||||
sheetState = rememberModalBottomSheetState(
|
|
||||||
skipPartiallyExpanded = true
|
|
||||||
),
|
|
||||||
dragHandle = {},
|
|
||||||
shape = RoundedCornerShape(topStart = 16.dp, topEnd = 16.dp),
|
|
||||||
windowInsets = WindowInsets(0)
|
|
||||||
) {
|
|
||||||
CommentMenuModal(
|
|
||||||
onDeleteClick = {
|
|
||||||
showCommentMenu = false
|
|
||||||
contextComment?.let {
|
|
||||||
model.deleteComment(it.id)
|
|
||||||
onCommentDeleted()
|
|
||||||
currentCommentCount = (currentCommentCount - 1).coerceAtLeast(0)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
commentEntity = contextComment,
|
|
||||||
onCloseClick = {
|
|
||||||
showCommentMenu = false
|
|
||||||
},
|
|
||||||
isSelf = AppState.UserId?.toLong() == contextComment?.author,
|
|
||||||
onLikeClick = {
|
|
||||||
if (GuestLoginCheckOut.needLogin(GuestLoginCheckOutScene.LIKE_MOMENT)) {
|
|
||||||
debouncedNavigation {
|
|
||||||
navController.navigate(NavigationRoute.Login.route)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
showCommentMenu = false
|
|
||||||
contextComment?.let {
|
|
||||||
if (it.liked) {
|
|
||||||
model.unlikeComment(it.id)
|
|
||||||
} else {
|
|
||||||
model.likeComment(it.id)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
onReplyClick = {
|
|
||||||
if (GuestLoginCheckOut.needLogin(GuestLoginCheckOutScene.COMMENT_MOMENT)) {
|
|
||||||
debouncedNavigation {
|
|
||||||
navController.navigate(NavigationRoute.Login.route)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
showCommentMenu = false
|
|
||||||
replyComment = contextComment
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Column(
|
|
||||||
modifier = Modifier.background(AppColors.background)
|
|
||||||
) {
|
|
||||||
Row(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(horizontal = 16.dp, vertical = 8.dp),
|
|
||||||
verticalAlignment = Alignment.CenterVertically
|
|
||||||
) {
|
|
||||||
Text(
|
|
||||||
text = "${currentCommentCount}条评论",
|
|
||||||
fontSize = 15.sp,
|
|
||||||
fontWeight = FontWeight.Bold,
|
|
||||||
color = AppColors.text
|
|
||||||
)
|
|
||||||
|
|
||||||
// 排序选择
|
|
||||||
Row(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth(),
|
|
||||||
horizontalArrangement = Arrangement.End
|
|
||||||
) {
|
|
||||||
OrderSelectionComponent {
|
|
||||||
commentViewModel.order = it
|
|
||||||
commentViewModel.reloadComment()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 评论列表
|
|
||||||
Column(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.weight(1f)
|
|
||||||
) {
|
|
||||||
Box(
|
|
||||||
modifier = Modifier.fillMaxWidth()
|
|
||||||
) {
|
|
||||||
LazyColumn {
|
|
||||||
item {
|
|
||||||
CommentContent(
|
|
||||||
viewModel = commentViewModel,
|
|
||||||
onLongClick = { comment ->
|
|
||||||
showCommentMenu = true
|
|
||||||
contextComment = comment
|
|
||||||
},
|
|
||||||
onReply = { parentComment, _, _, _ ->
|
|
||||||
if (GuestLoginCheckOut.needLogin(GuestLoginCheckOutScene.COMMENT_MOMENT)) {
|
|
||||||
debouncedNavigation {
|
|
||||||
navController.navigate(NavigationRoute.Login.route)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
replyComment = parentComment
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 底部输入栏
|
|
||||||
Column(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.background(AppColors.background)
|
|
||||||
) {
|
|
||||||
HorizontalDivider(color = AppColors.inputBackground)
|
|
||||||
|
|
||||||
EditCommentBottomModal(
|
|
||||||
replyComment = replyComment,
|
|
||||||
autoFocus = false
|
|
||||||
) {
|
|
||||||
if (replyComment != null) {
|
|
||||||
if (replyComment?.parentCommentId != null) {
|
|
||||||
// 第三级评论
|
|
||||||
model.createComment(
|
|
||||||
content = it,
|
|
||||||
parentCommentId = replyComment?.parentCommentId,
|
|
||||||
replyUserId = replyComment?.author?.toInt(),
|
|
||||||
replyCommentId = replyComment?.id
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
// 子级评论
|
|
||||||
model.createComment(
|
|
||||||
content = it,
|
|
||||||
parentCommentId = replyComment?.id,
|
|
||||||
replyCommentId = replyComment?.id
|
|
||||||
)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// 顶级评论
|
|
||||||
model.createComment(content = it)
|
|
||||||
}
|
|
||||||
replyComment = null
|
|
||||||
onCommentAdded()
|
|
||||||
currentCommentCount++
|
|
||||||
}
|
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(navBarHeight))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,436 +0,0 @@
|
|||||||
package com.aiosman.ravenow.ui.index.tabs.moment.tabs.news
|
|
||||||
|
|
||||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
|
||||||
import androidx.compose.foundation.Image
|
|
||||||
import androidx.compose.foundation.background
|
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
|
||||||
import androidx.compose.foundation.layout.Box
|
|
||||||
import androidx.compose.foundation.layout.Column
|
|
||||||
import androidx.compose.foundation.layout.Row
|
|
||||||
import androidx.compose.foundation.layout.Spacer
|
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
|
||||||
import androidx.compose.foundation.layout.height
|
|
||||||
import androidx.compose.foundation.layout.statusBars
|
|
||||||
import androidx.compose.foundation.layout.padding
|
|
||||||
import androidx.compose.foundation.layout.size
|
|
||||||
import androidx.compose.foundation.layout.width
|
|
||||||
import androidx.compose.foundation.pager.VerticalPager
|
|
||||||
import androidx.compose.foundation.pager.rememberPagerState
|
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
||||||
import androidx.compose.material.ExperimentalMaterialApi
|
|
||||||
import androidx.compose.material.pullrefresh.PullRefreshIndicator
|
|
||||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
|
||||||
import androidx.compose.material3.ModalBottomSheet
|
|
||||||
import androidx.compose.material3.Text
|
|
||||||
import androidx.compose.material3.rememberModalBottomSheetState
|
|
||||||
import androidx.compose.runtime.Composable
|
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
|
||||||
import androidx.compose.runtime.getValue
|
|
||||||
import androidx.compose.runtime.mutableStateOf
|
|
||||||
import androidx.compose.runtime.remember
|
|
||||||
import androidx.compose.runtime.setValue
|
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
|
||||||
import androidx.compose.runtime.rememberCoroutineScope
|
|
||||||
import androidx.compose.ui.Alignment
|
|
||||||
import androidx.compose.ui.Modifier
|
|
||||||
import androidx.compose.ui.draw.clip
|
|
||||||
import androidx.compose.ui.graphics.Color
|
|
||||||
import androidx.compose.ui.graphics.ColorFilter
|
|
||||||
import androidx.compose.ui.layout.ContentScale
|
|
||||||
import androidx.compose.ui.platform.LocalContext
|
|
||||||
import androidx.compose.ui.res.stringResource
|
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
|
||||||
import androidx.compose.ui.text.style.TextOverflow
|
|
||||||
import androidx.compose.ui.unit.dp
|
|
||||||
import androidx.compose.ui.unit.sp
|
|
||||||
import androidx.compose.ui.platform.LocalConfiguration
|
|
||||||
import com.aiosman.ravenow.GuestLoginCheckOut
|
|
||||||
import com.aiosman.ravenow.GuestLoginCheckOutScene
|
|
||||||
import com.aiosman.ravenow.LocalAppTheme
|
|
||||||
import com.aiosman.ravenow.LocalNavController
|
|
||||||
import com.aiosman.ravenow.R
|
|
||||||
import com.aiosman.ravenow.entity.MomentEntity
|
|
||||||
import com.aiosman.ravenow.exp.timeAgo
|
|
||||||
import com.aiosman.ravenow.exp.formatPostTime2
|
|
||||||
import com.aiosman.ravenow.ui.NavigationRoute
|
|
||||||
import com.aiosman.ravenow.ui.composables.CustomAsyncImage
|
|
||||||
import com.aiosman.ravenow.ui.composables.rememberDebouncer
|
|
||||||
import com.aiosman.ravenow.ui.index.tabs.moment.tabs.news.NewsViewModel
|
|
||||||
import com.aiosman.ravenow.ui.modifiers.noRippleClickable
|
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterialApi::class, ExperimentalMaterial3Api::class, ExperimentalFoundationApi::class)
|
|
||||||
@Composable
|
|
||||||
fun NewsScreen() {
|
|
||||||
val model = NewsViewModel
|
|
||||||
val moments = model.moments
|
|
||||||
val AppColors = LocalAppTheme.current
|
|
||||||
val context = LocalContext.current
|
|
||||||
val navController = LocalNavController.current
|
|
||||||
val scope = rememberCoroutineScope()
|
|
||||||
|
|
||||||
// 评论弹窗状态
|
|
||||||
var showCommentModal by remember { mutableStateOf(false) }
|
|
||||||
var selectedMoment by remember { mutableStateOf<MomentEntity?>(null) }
|
|
||||||
|
|
||||||
// 查看全文弹窗状态
|
|
||||||
var showFullArticleModal by remember { mutableStateOf(false) }
|
|
||||||
var selectedArticleMoment by remember { mutableStateOf<MomentEntity?>(null) }
|
|
||||||
// 垂直翻页状态
|
|
||||||
val pagerState = rememberPagerState(pageCount = { moments.size })
|
|
||||||
|
|
||||||
// 防抖器
|
|
||||||
val likeDebouncer = rememberDebouncer()
|
|
||||||
val favoriteDebouncer = rememberDebouncer()
|
|
||||||
|
|
||||||
// 初始化加载数据
|
|
||||||
LaunchedEffect(Unit) {
|
|
||||||
model.refreshPager()
|
|
||||||
}
|
|
||||||
|
|
||||||
// 监听数据变化,重置加载状态
|
|
||||||
LaunchedEffect(moments.size) {
|
|
||||||
// 当数据增加时,如果接近列表末尾,Pager会自动更新页数
|
|
||||||
}
|
|
||||||
|
|
||||||
// 当翻页接近末尾时加载更多
|
|
||||||
LaunchedEffect(pagerState.currentPage, moments.size) {
|
|
||||||
if (moments.isNotEmpty() && pagerState.currentPage >= moments.size - 2) {
|
|
||||||
model.loadMore()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Column(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxSize()
|
|
||||||
.background(AppColors.background)
|
|
||||||
) {
|
|
||||||
if (moments.isEmpty()) {
|
|
||||||
Box(
|
|
||||||
modifier = Modifier.fillMaxSize(),
|
|
||||||
contentAlignment = Alignment.Center
|
|
||||||
) {
|
|
||||||
Text(text = "暂无新闻内容", color = AppColors.text, fontSize = 16.sp)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
VerticalPager(
|
|
||||||
state = pagerState,
|
|
||||||
modifier = Modifier.fillMaxSize()
|
|
||||||
) { page ->
|
|
||||||
val momentItem = moments.getOrNull(page) ?: return@VerticalPager
|
|
||||||
NewsItem(
|
|
||||||
moment = momentItem,
|
|
||||||
modifier = Modifier.fillMaxSize(),
|
|
||||||
onCommentClick = {
|
|
||||||
selectedMoment = momentItem
|
|
||||||
showCommentModal = true
|
|
||||||
},
|
|
||||||
onReadFullClick = {
|
|
||||||
selectedArticleMoment = momentItem
|
|
||||||
showFullArticleModal = true
|
|
||||||
},
|
|
||||||
onLikeClick = {
|
|
||||||
likeDebouncer {
|
|
||||||
// 检查游客模式
|
|
||||||
if (GuestLoginCheckOut.needLogin(GuestLoginCheckOutScene.LIKE_MOMENT)) {
|
|
||||||
navController.navigate(NavigationRoute.Login.route)
|
|
||||||
} else {
|
|
||||||
scope.launch {
|
|
||||||
if (momentItem.liked) {
|
|
||||||
model.dislikeMoment(momentItem.id)
|
|
||||||
} else {
|
|
||||||
model.likeMoment(momentItem.id)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
onFavoriteClick = {
|
|
||||||
favoriteDebouncer {
|
|
||||||
// 检查游客模式
|
|
||||||
if (GuestLoginCheckOut.needLogin(GuestLoginCheckOutScene.LIKE_MOMENT)) {
|
|
||||||
navController.navigate(NavigationRoute.Login.route)
|
|
||||||
} else {
|
|
||||||
scope.launch {
|
|
||||||
if (momentItem.isFavorite) {
|
|
||||||
model.unfavoriteMoment(momentItem.id)
|
|
||||||
} else {
|
|
||||||
model.favoriteMoment(momentItem.id)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 查看全文弹窗
|
|
||||||
if (showFullArticleModal && selectedArticleMoment != null) {
|
|
||||||
FullArticleModal(
|
|
||||||
moment = selectedArticleMoment!!,
|
|
||||||
onDismiss = {
|
|
||||||
showFullArticleModal = false
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 评论弹窗
|
|
||||||
if (showCommentModal && selectedMoment != null) {
|
|
||||||
val configuration = LocalConfiguration.current
|
|
||||||
val screenHeight = configuration.screenHeightDp.dp
|
|
||||||
val sheetHeight = screenHeight * 0.67f // 三分之二高度
|
|
||||||
|
|
||||||
ModalBottomSheet(
|
|
||||||
onDismissRequest = {
|
|
||||||
showCommentModal = false
|
|
||||||
},
|
|
||||||
sheetState = rememberModalBottomSheetState(
|
|
||||||
skipPartiallyExpanded = true
|
|
||||||
),
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.height(sheetHeight),
|
|
||||||
containerColor = AppColors.background,
|
|
||||||
shape = RoundedCornerShape(topStart = 16.dp, topEnd = 16.dp),
|
|
||||||
windowInsets = androidx.compose.foundation.layout.WindowInsets(0)
|
|
||||||
) {
|
|
||||||
NewsCommentModal(
|
|
||||||
postId = selectedMoment?.id,
|
|
||||||
commentCount = selectedMoment?.commentCount ?: 0,
|
|
||||||
onDismiss = {
|
|
||||||
showCommentModal = false
|
|
||||||
},
|
|
||||||
onCommentAdded = {
|
|
||||||
selectedMoment?.id?.let { model.onAddComment(it) }
|
|
||||||
},
|
|
||||||
onCommentDeleted = {
|
|
||||||
selectedMoment?.id?.let { model.onDeleteComment(it) }
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//单个新闻项
|
|
||||||
@Composable
|
|
||||||
fun NewsItem(
|
|
||||||
moment: MomentEntity,
|
|
||||||
modifier: Modifier = Modifier,
|
|
||||||
onCommentClick: () -> Unit = {},
|
|
||||||
onReadFullClick: () -> Unit = {},
|
|
||||||
onLikeClick: () -> Unit = {},
|
|
||||||
onFavoriteClick: () -> Unit = {}
|
|
||||||
) {
|
|
||||||
val AppColors = LocalAppTheme.current
|
|
||||||
val context = LocalContext.current
|
|
||||||
|
|
||||||
Column(
|
|
||||||
modifier = modifier
|
|
||||||
.fillMaxSize()
|
|
||||||
.background(AppColors.background)
|
|
||||||
.padding(vertical = 8.dp),
|
|
||||||
verticalArrangement = Arrangement.SpaceBetween
|
|
||||||
) {
|
|
||||||
Column(
|
|
||||||
modifier = Modifier
|
|
||||||
.weight(1f)
|
|
||||||
.padding(bottom = 30.dp)
|
|
||||||
) {
|
|
||||||
// 新闻图片
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.height(300.dp)
|
|
||||||
.padding(horizontal = 16.dp)
|
|
||||||
) {
|
|
||||||
if (moment.images.isNotEmpty()) {
|
|
||||||
CustomAsyncImage(
|
|
||||||
context = context,
|
|
||||||
imageUrl = moment.images[0].thumbnail,
|
|
||||||
contentDescription = "新闻图片",
|
|
||||||
contentScale = ContentScale.Crop,
|
|
||||||
blurHash = moment.images[0].blurHash,
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxSize()
|
|
||||||
.clip(RoundedCornerShape(8.dp))
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
Image(
|
|
||||||
painter = androidx.compose.ui.res.painterResource(id = R.drawable.default_moment_img),
|
|
||||||
contentDescription = "默认图片",
|
|
||||||
contentScale = ContentScale.Crop,
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxSize()
|
|
||||||
.clip(RoundedCornerShape(8.dp))
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(16.dp))
|
|
||||||
|
|
||||||
// 新闻标题
|
|
||||||
Text(
|
|
||||||
text = if (moment.newsTitle.isNotEmpty()) moment.newsTitle else moment.nickname,
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(horizontal = 16.dp),
|
|
||||||
fontSize = 20.sp,
|
|
||||||
fontWeight = FontWeight.Bold,
|
|
||||||
color = AppColors.text,
|
|
||||||
maxLines = 2,
|
|
||||||
overflow = TextOverflow.Ellipsis
|
|
||||||
)
|
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(16.dp))
|
|
||||||
|
|
||||||
// 新闻内容(超出使用省略号)
|
|
||||||
Text(
|
|
||||||
text = if (moment.newsContent.isNotEmpty()) moment.newsContent else moment.momentTextContent,
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(horizontal = 16.dp),
|
|
||||||
fontSize = 14.sp,
|
|
||||||
color = AppColors.text,
|
|
||||||
lineHeight = 20.sp,
|
|
||||||
maxLines = 6,
|
|
||||||
overflow = TextOverflow.Ellipsis
|
|
||||||
)
|
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(16.dp))
|
|
||||||
|
|
||||||
// 新闻信息
|
|
||||||
Row(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(horizontal = 16.dp),
|
|
||||||
horizontalArrangement = Arrangement.SpaceBetween,
|
|
||||||
verticalAlignment = Alignment.CenterVertically
|
|
||||||
) {
|
|
||||||
// 来源和时间(显示月份与具体时间)
|
|
||||||
Text(
|
|
||||||
text = if (moment.newsSource.isNotEmpty()) "${moment.newsSource} • ${moment.time.formatPostTime2()}" else "${moment.nickname} • ${moment.time.formatPostTime2()}",
|
|
||||||
fontSize = 12.sp,
|
|
||||||
color = AppColors.secondaryText,
|
|
||||||
modifier = Modifier
|
|
||||||
.weight(1f)
|
|
||||||
.padding(end = 8.dp),
|
|
||||||
maxLines = 2,
|
|
||||||
overflow = TextOverflow.Ellipsis
|
|
||||||
)
|
|
||||||
|
|
||||||
// 查看全文
|
|
||||||
Row(
|
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
|
||||||
modifier = Modifier.noRippleClickable { onReadFullClick() }
|
|
||||||
) {
|
|
||||||
Text(
|
|
||||||
text = stringResource(R.string.read_full_article),
|
|
||||||
fontSize = 13.sp,
|
|
||||||
fontWeight = FontWeight.W600,
|
|
||||||
color = Color(0xFF7c45ed)
|
|
||||||
)
|
|
||||||
Spacer(modifier = Modifier.width(4.dp))
|
|
||||||
Image(
|
|
||||||
painter = androidx.compose.ui.res.painterResource(id = R.mipmap.arrow),
|
|
||||||
contentDescription = "箭头",
|
|
||||||
modifier = Modifier.size(18.dp),
|
|
||||||
colorFilter = ColorFilter.tint(Color(0xFF7c45ed))
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 互动栏
|
|
||||||
Row(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(horizontal = 16.dp)
|
|
||||||
.padding(bottom = 25.dp),
|
|
||||||
horizontalArrangement = Arrangement.SpaceEvenly
|
|
||||||
) {
|
|
||||||
// 点赞
|
|
||||||
NewsActionButton(
|
|
||||||
icon = if (moment.liked) R.drawable.rider_pro_moment_liked else R.drawable.rider_pro_moment_like,
|
|
||||||
count = moment.likeCount.toString(),
|
|
||||||
isActive = moment.liked,
|
|
||||||
modifier = Modifier.noRippleClickable { onLikeClick() }
|
|
||||||
)
|
|
||||||
|
|
||||||
// 评论
|
|
||||||
NewsActionButton(
|
|
||||||
icon = R.mipmap.icon_comment,
|
|
||||||
count = moment.commentCount.toString(),
|
|
||||||
isActive = false,
|
|
||||||
modifier = Modifier.noRippleClickable { onCommentClick() }
|
|
||||||
)
|
|
||||||
|
|
||||||
// 收藏
|
|
||||||
NewsActionButton(
|
|
||||||
icon = if (moment.isFavorite) R.mipmap.icon_variant_2 else R.mipmap.icon_collect,
|
|
||||||
count = moment.favoriteCount.toString(),
|
|
||||||
isActive = moment.isFavorite,
|
|
||||||
modifier = Modifier.noRippleClickable { onFavoriteClick() }
|
|
||||||
)
|
|
||||||
|
|
||||||
// 分享
|
|
||||||
NewsActionButton(
|
|
||||||
icon = R.mipmap.icon_share,
|
|
||||||
count = "",
|
|
||||||
isActive = false,
|
|
||||||
text = stringResource(R.string.share),
|
|
||||||
textSize = 8.sp
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 互动栏按钮
|
|
||||||
@Composable
|
|
||||||
fun NewsActionButton(
|
|
||||||
icon: Int,
|
|
||||||
count: String,
|
|
||||||
isActive: Boolean,
|
|
||||||
modifier: Modifier = Modifier,
|
|
||||||
text: String? = null,
|
|
||||||
textSize: androidx.compose.ui.unit.TextUnit = 12.sp
|
|
||||||
) {
|
|
||||||
val AppColors = LocalAppTheme.current
|
|
||||||
|
|
||||||
Row(
|
|
||||||
modifier = modifier
|
|
||||||
.width(60.dp)
|
|
||||||
.background(
|
|
||||||
color = AppColors.secondaryBackground,
|
|
||||||
shape = RoundedCornerShape(16.dp)
|
|
||||||
)
|
|
||||||
.padding(horizontal = 12.dp, vertical = 8.dp),
|
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
|
||||||
horizontalArrangement = Arrangement.Center
|
|
||||||
) {
|
|
||||||
Image(
|
|
||||||
painter = androidx.compose.ui.res.painterResource(id = icon),
|
|
||||||
contentDescription = "操作图标",
|
|
||||||
modifier = Modifier.size(16.dp)
|
|
||||||
)
|
|
||||||
|
|
||||||
if (count.isNotEmpty()) {
|
|
||||||
Spacer(modifier = Modifier.width(4.dp))
|
|
||||||
Text(
|
|
||||||
text = count,
|
|
||||||
fontSize = 12.sp,
|
|
||||||
color = AppColors.text
|
|
||||||
)
|
|
||||||
}
|
|
||||||
if (text != null) {
|
|
||||||
Spacer(modifier = Modifier.width(4.dp))
|
|
||||||
Text(
|
|
||||||
text = text,
|
|
||||||
fontSize = textSize,
|
|
||||||
color = AppColors.text
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
package com.aiosman.ravenow.ui.index.tabs.moment.tabs.news
|
|
||||||
|
|
||||||
import com.aiosman.ravenow.entity.MomentLoaderExtraArgs
|
|
||||||
import com.aiosman.ravenow.ui.index.tabs.moment.BaseMomentModel
|
|
||||||
|
|
||||||
object NewsViewModel : BaseMomentModel() {
|
|
||||||
override fun extraArgs(): MomentLoaderExtraArgs {
|
|
||||||
// 只拉取新闻
|
|
||||||
return MomentLoaderExtraArgs(
|
|
||||||
explore = false,
|
|
||||||
timelineId = null,
|
|
||||||
authorId = null,
|
|
||||||
newsOnly = true
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,185 +0,0 @@
|
|||||||
package com.aiosman.ravenow.ui.index.tabs.moment.tabs.shorts
|
|
||||||
|
|
||||||
import android.util.Log
|
|
||||||
import androidx.compose.foundation.background
|
|
||||||
import androidx.compose.foundation.layout.Box
|
|
||||||
import androidx.compose.foundation.layout.Column
|
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
|
||||||
import androidx.compose.foundation.layout.padding
|
|
||||||
import androidx.compose.material3.CircularProgressIndicator
|
|
||||||
import androidx.compose.material3.Text
|
|
||||||
import androidx.compose.runtime.Composable
|
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
|
||||||
import androidx.compose.runtime.getValue
|
|
||||||
import androidx.compose.runtime.remember
|
|
||||||
import androidx.compose.runtime.rememberCoroutineScope
|
|
||||||
import androidx.compose.runtime.saveable.rememberSaveable
|
|
||||||
import androidx.compose.ui.Alignment
|
|
||||||
import androidx.compose.ui.Modifier
|
|
||||||
import androidx.compose.ui.unit.dp
|
|
||||||
import androidx.compose.ui.unit.sp
|
|
||||||
import com.aiosman.ravenow.GuestLoginCheckOut
|
|
||||||
import com.aiosman.ravenow.GuestLoginCheckOutScene
|
|
||||||
import com.aiosman.ravenow.LocalAppTheme
|
|
||||||
import com.aiosman.ravenow.LocalNavController
|
|
||||||
import com.aiosman.ravenow.entity.MomentEntity
|
|
||||||
import com.aiosman.ravenow.ui.NavigationRoute
|
|
||||||
import com.aiosman.ravenow.ui.index.tabs.shorts.ShortViewCompose
|
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 短视频页面
|
|
||||||
*/
|
|
||||||
@Composable
|
|
||||||
fun ShortVideoScreen() {
|
|
||||||
val viewModel = ShortVideoViewModel
|
|
||||||
val allMoments = viewModel.moments
|
|
||||||
val navController = LocalNavController.current
|
|
||||||
val scope = rememberCoroutineScope()
|
|
||||||
val AppColors = LocalAppTheme.current
|
|
||||||
val momentLoader = viewModel.momentLoader
|
|
||||||
// 记录当前播放的短视频索引,切换 Tab 返回时恢复
|
|
||||||
val currentIndex = rememberSaveable { androidx.compose.runtime.mutableStateOf(0) }
|
|
||||||
|
|
||||||
// 过滤出包含视频的动态
|
|
||||||
val videoMoments = remember(allMoments) {
|
|
||||||
val filtered = allMoments.filter { it.videos != null && it.videos.isNotEmpty() }
|
|
||||||
Log.d("ShortVideoScreen", "过滤视频动态 - 总动态数: ${allMoments.size}, 包含视频的动态数: ${filtered.size}")
|
|
||||||
filtered.forEach { moment ->
|
|
||||||
Log.d("ShortVideoScreen", "视频动态 ID: ${moment.id}, 视频数: ${moment.videos?.size}, 第一个视频URL: ${moment.videos?.firstOrNull()?.url}")
|
|
||||||
}
|
|
||||||
filtered
|
|
||||||
}
|
|
||||||
|
|
||||||
// 初始加载数据
|
|
||||||
LaunchedEffect(Unit) {
|
|
||||||
Log.d("ShortVideoScreen", "开始加载数据")
|
|
||||||
viewModel.refreshPager()
|
|
||||||
}
|
|
||||||
|
|
||||||
// 加载更多数据
|
|
||||||
LaunchedEffect(allMoments.size, videoMoments.size) {
|
|
||||||
Log.d("ShortVideoScreen", "检查是否需要加载更多 - allMoments: ${allMoments.size}, videoMoments: ${videoMoments.size}, hasNext: ${momentLoader.hasNext}, isLoading: ${momentLoader.isLoading}")
|
|
||||||
if (allMoments.isNotEmpty() && videoMoments.size < 10 && momentLoader.hasNext && !momentLoader.isLoading) {
|
|
||||||
// 如果视频数量少于10个,尝试加载更多
|
|
||||||
Log.d("ShortVideoScreen", "开始加载更多数据")
|
|
||||||
viewModel.loadMore()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 加载状态
|
|
||||||
if (momentLoader.isLoading && videoMoments.isEmpty()) {
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxSize()
|
|
||||||
.background(AppColors.background),
|
|
||||||
contentAlignment = Alignment.Center
|
|
||||||
) {
|
|
||||||
Column(
|
|
||||||
modifier = Modifier.padding(16.dp),
|
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
|
||||||
verticalArrangement = androidx.compose.foundation.layout.Arrangement.Center
|
|
||||||
) {
|
|
||||||
CircularProgressIndicator(color = AppColors.main)
|
|
||||||
Text(
|
|
||||||
text = "加载中...",
|
|
||||||
modifier = Modifier.padding(top = 16.dp),
|
|
||||||
color = AppColors.text,
|
|
||||||
fontSize = 14.sp
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// 错误状态
|
|
||||||
else if (momentLoader.error != null && videoMoments.isEmpty()) {
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxSize()
|
|
||||||
.background(AppColors.background),
|
|
||||||
contentAlignment = Alignment.Center
|
|
||||||
) {
|
|
||||||
Text(
|
|
||||||
text = "加载失败: ${momentLoader.error}",
|
|
||||||
color = AppColors.error,
|
|
||||||
fontSize = 14.sp
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// 空状态 - 已加载但无视频
|
|
||||||
else if (!momentLoader.isLoading && videoMoments.isEmpty() && allMoments.isNotEmpty()) {
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxSize()
|
|
||||||
.background(AppColors.background),
|
|
||||||
contentAlignment = Alignment.Center
|
|
||||||
) {
|
|
||||||
Text(
|
|
||||||
text = "暂无短视频\n已加载 ${allMoments.size} 条动态,但都不包含视频",
|
|
||||||
color = AppColors.text,
|
|
||||||
fontSize = 16.sp
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// 初始状态 - 还没有加载过数据
|
|
||||||
else if (!momentLoader.isLoading && videoMoments.isEmpty() && allMoments.isEmpty() && momentLoader.error == null) {
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxSize()
|
|
||||||
.background(AppColors.background),
|
|
||||||
contentAlignment = Alignment.Center
|
|
||||||
) {
|
|
||||||
Text(
|
|
||||||
text = "准备加载...",
|
|
||||||
color = AppColors.text,
|
|
||||||
fontSize = 16.sp
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// 显示视频列表
|
|
||||||
else if (videoMoments.isNotEmpty()) {
|
|
||||||
ShortViewCompose(
|
|
||||||
videoMoments = videoMoments,
|
|
||||||
clickItemPosition = currentIndex.value,
|
|
||||||
onLikeClick = { moment ->
|
|
||||||
if (GuestLoginCheckOut.needLogin(GuestLoginCheckOutScene.LIKE_MOMENT)) {
|
|
||||||
navController.navigate(NavigationRoute.Login.route)
|
|
||||||
} else {
|
|
||||||
scope.launch {
|
|
||||||
if (moment.liked) {
|
|
||||||
viewModel.dislikeMoment(moment.id)
|
|
||||||
} else {
|
|
||||||
viewModel.likeMoment(moment.id)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
onCommentClick = { moment ->
|
|
||||||
if (GuestLoginCheckOut.needLogin(GuestLoginCheckOutScene.COMMENT_MOMENT)) {
|
|
||||||
navController.navigate(NavigationRoute.Login.route)
|
|
||||||
} else {
|
|
||||||
scope.launch {
|
|
||||||
viewModel.onAddComment(moment.id)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
onFavoriteClick = { moment ->
|
|
||||||
if (GuestLoginCheckOut.needLogin(GuestLoginCheckOutScene.LIKE_MOMENT)) {
|
|
||||||
navController.navigate(NavigationRoute.Login.route)
|
|
||||||
} else {
|
|
||||||
scope.launch {
|
|
||||||
if (moment.isFavorite) {
|
|
||||||
viewModel.unfavoriteMoment(moment.id)
|
|
||||||
} else {
|
|
||||||
viewModel.favoriteMoment(moment.id)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
onShareClick = { moment ->
|
|
||||||
// TODO: 实现分享功能
|
|
||||||
},
|
|
||||||
onPageChanged = { idx -> currentIndex.value = idx }
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
package com.aiosman.ravenow.ui.index.tabs.moment.tabs.shorts
|
|
||||||
|
|
||||||
import com.aiosman.ravenow.entity.MomentLoaderExtraArgs
|
|
||||||
import com.aiosman.ravenow.ui.index.tabs.moment.BaseMomentModel
|
|
||||||
import org.greenrobot.eventbus.EventBus
|
|
||||||
|
|
||||||
object ShortVideoViewModel : BaseMomentModel() {
|
|
||||||
init {
|
|
||||||
EventBus.getDefault().register(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun extraArgs(): MomentLoaderExtraArgs {
|
|
||||||
return MomentLoaderExtraArgs(explore = true, videoOnly = true)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取包含视频的动态列表
|
|
||||||
fun getVideoMoments(): List<com.aiosman.ravenow.entity.MomentEntity> {
|
|
||||||
return moments.filter { it.videos != null && it.videos.isNotEmpty() }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,178 +0,0 @@
|
|||||||
package com.aiosman.ravenow.ui.index.tabs.profile
|
|
||||||
|
|
||||||
import androidx.compose.foundation.background
|
|
||||||
import androidx.compose.foundation.layout.Box
|
|
||||||
import androidx.compose.foundation.layout.Column
|
|
||||||
import androidx.compose.foundation.layout.Row
|
|
||||||
import androidx.compose.foundation.layout.Spacer
|
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
|
||||||
import androidx.compose.foundation.layout.height
|
|
||||||
import androidx.compose.foundation.layout.padding
|
|
||||||
import androidx.compose.foundation.layout.size
|
|
||||||
import androidx.compose.foundation.layout.width
|
|
||||||
import androidx.compose.foundation.shape.CircleShape
|
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
||||||
import androidx.compose.material3.Icon
|
|
||||||
import androidx.compose.material3.Text
|
|
||||||
import androidx.compose.runtime.Composable
|
|
||||||
import androidx.compose.ui.Alignment
|
|
||||||
import androidx.compose.ui.Modifier
|
|
||||||
import androidx.compose.ui.draw.clip
|
|
||||||
import androidx.compose.ui.layout.ContentScale
|
|
||||||
import androidx.compose.ui.platform.LocalContext
|
|
||||||
import androidx.compose.ui.res.painterResource
|
|
||||||
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 com.aiosman.ravenow.LocalAppTheme
|
|
||||||
import com.aiosman.ravenow.R
|
|
||||||
import com.aiosman.ravenow.entity.AccountProfileEntity
|
|
||||||
import com.aiosman.ravenow.ui.composables.CustomAsyncImage
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 拉黑确认弹窗
|
|
||||||
*/
|
|
||||||
@Composable
|
|
||||||
fun BlockConfirmDialog(
|
|
||||||
userProfile: AccountProfileEntity?,
|
|
||||||
onConfirmBlock: () -> Unit = {},
|
|
||||||
onDismiss: () -> Unit = {}
|
|
||||||
) {
|
|
||||||
val AppColors = LocalAppTheme.current
|
|
||||||
|
|
||||||
Box(
|
|
||||||
modifier = Modifier.fillMaxSize(),
|
|
||||||
contentAlignment = Alignment.BottomCenter
|
|
||||||
) {
|
|
||||||
Column(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.background(
|
|
||||||
color = AppColors.background,
|
|
||||||
shape = RoundedCornerShape(topStart = 16.dp, topEnd = 16.dp)
|
|
||||||
)
|
|
||||||
.padding(24.dp)
|
|
||||||
) {
|
|
||||||
// 用户头像
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.align(Alignment.CenterHorizontally)
|
|
||||||
.padding(bottom = 16.dp)
|
|
||||||
) {
|
|
||||||
CustomAsyncImage(
|
|
||||||
LocalContext.current,
|
|
||||||
userProfile?.avatar,
|
|
||||||
modifier = Modifier
|
|
||||||
.size(60.dp)
|
|
||||||
.clip(CircleShape)
|
|
||||||
.background(
|
|
||||||
color = AppColors.background,
|
|
||||||
shape = CircleShape
|
|
||||||
),
|
|
||||||
contentDescription = "用户头像",
|
|
||||||
contentScale = ContentScale.Crop
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 确认文本
|
|
||||||
Text(
|
|
||||||
text = stringResource(R.string.confirm_block_user, userProfile?.nickName ?: "该用户"),
|
|
||||||
|
|
||||||
fontSize = 18.sp,
|
|
||||||
fontWeight = FontWeight.Bold,
|
|
||||||
color = AppColors.text,
|
|
||||||
modifier = Modifier
|
|
||||||
.align(Alignment.CenterHorizontally)
|
|
||||||
.padding(bottom = 24.dp)
|
|
||||||
)
|
|
||||||
|
|
||||||
// 说明信息
|
|
||||||
Column(
|
|
||||||
modifier = Modifier.padding(bottom = 32.dp)
|
|
||||||
) {
|
|
||||||
// 第一条说明
|
|
||||||
Row(
|
|
||||||
modifier = Modifier.padding(bottom = 12.dp),
|
|
||||||
verticalAlignment = Alignment.CenterVertically
|
|
||||||
) {
|
|
||||||
Icon(
|
|
||||||
painter = painterResource(id = R.mipmap.icons_infor_off_eye),
|
|
||||||
contentDescription = "",
|
|
||||||
tint = AppColors.text,
|
|
||||||
modifier = Modifier.size(20.dp)
|
|
||||||
)
|
|
||||||
Spacer(modifier = Modifier.width(12.dp))
|
|
||||||
Text(
|
|
||||||
text = stringResource(R.string.block_description_1),
|
|
||||||
fontSize = 14.sp,
|
|
||||||
color = AppColors.text,
|
|
||||||
lineHeight = 20.sp
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 第二条说明
|
|
||||||
Row(
|
|
||||||
modifier = Modifier.padding(bottom = 12.dp),
|
|
||||||
verticalAlignment = Alignment.CenterVertically
|
|
||||||
) {
|
|
||||||
Icon(
|
|
||||||
painter = painterResource(id = R.drawable.rider_pro_notice_mute),
|
|
||||||
contentDescription = "",
|
|
||||||
tint = AppColors.text,
|
|
||||||
modifier = Modifier.size(20.dp)
|
|
||||||
)
|
|
||||||
Spacer(modifier = Modifier.width(12.dp))
|
|
||||||
Text(
|
|
||||||
text = stringResource(R.string.block_description_2),
|
|
||||||
fontSize = 14.sp,
|
|
||||||
color = AppColors.text,
|
|
||||||
lineHeight = 20.sp
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 第三条说明
|
|
||||||
Row(
|
|
||||||
verticalAlignment = Alignment.CenterVertically
|
|
||||||
) {
|
|
||||||
Icon(
|
|
||||||
painter = painterResource(id = R.mipmap.icons_infor_off_bell),
|
|
||||||
contentDescription = "",
|
|
||||||
tint = AppColors.text,
|
|
||||||
modifier = Modifier.size(20.dp)
|
|
||||||
)
|
|
||||||
Spacer(modifier = Modifier.width(12.dp))
|
|
||||||
Text(
|
|
||||||
text = stringResource(R.string.block_description_3),
|
|
||||||
fontSize = 14.sp,
|
|
||||||
color = AppColors.text,
|
|
||||||
lineHeight = 20.sp
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 确认拉黑按钮
|
|
||||||
androidx.compose.material3.Button(
|
|
||||||
onClick = {
|
|
||||||
onConfirmBlock()
|
|
||||||
onDismiss()
|
|
||||||
},
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.height(48.dp),
|
|
||||||
colors = androidx.compose.material3.ButtonDefaults.buttonColors(
|
|
||||||
containerColor = AppColors.text
|
|
||||||
),
|
|
||||||
shape = RoundedCornerShape(24.dp)
|
|
||||||
) {
|
|
||||||
Text(
|
|
||||||
stringResource(R.string.block),
|
|
||||||
color = AppColors.background,
|
|
||||||
fontSize = 16.sp,
|
|
||||||
fontWeight = FontWeight.Bold
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -7,7 +7,6 @@ import android.util.Log
|
|||||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||||
import androidx.compose.foundation.Image
|
import androidx.compose.foundation.Image
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
@@ -87,8 +86,8 @@ import com.aiosman.ravenow.ui.composables.toolbar.rememberCollapsingToolbarScaff
|
|||||||
import com.aiosman.ravenow.ui.index.IndexViewModel
|
import com.aiosman.ravenow.ui.index.IndexViewModel
|
||||||
import com.aiosman.ravenow.ui.index.tabs.profile.composable.GalleryGrid
|
import com.aiosman.ravenow.ui.index.tabs.profile.composable.GalleryGrid
|
||||||
import com.aiosman.ravenow.ui.post.MenuActionItem
|
import com.aiosman.ravenow.ui.post.MenuActionItem
|
||||||
import com.aiosman.ravenow.ui.index.tabs.profile.composable.GroupChatEmptyContent
|
|
||||||
import com.aiosman.ravenow.ui.index.tabs.profile.composable.OtherProfileAction
|
import com.aiosman.ravenow.ui.index.tabs.profile.composable.OtherProfileAction
|
||||||
|
import com.aiosman.ravenow.ui.index.tabs.profile.composable.SelfProfileAction
|
||||||
import com.aiosman.ravenow.ui.index.tabs.profile.composable.UserAgentsList
|
import com.aiosman.ravenow.ui.index.tabs.profile.composable.UserAgentsList
|
||||||
import com.aiosman.ravenow.ui.index.tabs.profile.composable.UserAgentsRow
|
import com.aiosman.ravenow.ui.index.tabs.profile.composable.UserAgentsRow
|
||||||
import com.aiosman.ravenow.ui.index.tabs.profile.composable.UserContentPageIndicator
|
import com.aiosman.ravenow.ui.index.tabs.profile.composable.UserContentPageIndicator
|
||||||
@@ -100,15 +99,6 @@ import kotlinx.coroutines.delay
|
|||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import androidx.compose.foundation.rememberScrollState
|
import androidx.compose.foundation.rememberScrollState
|
||||||
import androidx.compose.ui.res.stringResource
|
|
||||||
import androidx.compose.foundation.Canvas
|
|
||||||
import androidx.compose.foundation.border
|
|
||||||
import androidx.compose.ui.geometry.Offset
|
|
||||||
import androidx.compose.ui.text.style.TextAlign
|
|
||||||
import androidx.compose.ui.graphics.Brush
|
|
||||||
import java.text.NumberFormat
|
|
||||||
import java.util.Locale
|
|
||||||
|
|
||||||
@OptIn(ExperimentalFoundationApi::class, ExperimentalMaterialApi::class, ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalFoundationApi::class, ExperimentalMaterialApi::class, ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun ProfileV3(
|
fun ProfileV3(
|
||||||
@@ -126,11 +116,10 @@ fun ProfileV3(
|
|||||||
onLike: (MomentEntity) -> Unit = {},
|
onLike: (MomentEntity) -> Unit = {},
|
||||||
onComment: (MomentEntity) -> Unit = {},
|
onComment: (MomentEntity) -> Unit = {},
|
||||||
onAgentClick: (AgentEntity) -> Unit = {},
|
onAgentClick: (AgentEntity) -> Unit = {},
|
||||||
postCount: Long? = null, // 新增参数用于传递帖子总数
|
postCount: Int? = null, // 新增参数用于传递帖子总数
|
||||||
) {
|
) {
|
||||||
val model = MyProfileViewModel
|
val model = MyProfileViewModel
|
||||||
// Tabs: 动态、(可选)智能体、群聊
|
val pagerState = rememberPagerState(pageCount = { if (isAiAccount) 1 else 2 })
|
||||||
val pagerState = rememberPagerState(pageCount = { if (isAiAccount) 2 else 3 })
|
|
||||||
val enabled by remember { mutableStateOf(true) }
|
val enabled by remember { mutableStateOf(true) }
|
||||||
val statusBarPaddingValues = WindowInsets.systemBars.asPaddingValues()
|
val statusBarPaddingValues = WindowInsets.systemBars.asPaddingValues()
|
||||||
var expanded by remember { mutableStateOf(false) }
|
var expanded by remember { mutableStateOf(false) }
|
||||||
@@ -138,13 +127,10 @@ fun ProfileV3(
|
|||||||
var showAgentMenu by remember { mutableStateOf(false) }
|
var showAgentMenu by remember { mutableStateOf(false) }
|
||||||
var contextAgent by remember { mutableStateOf<AgentEntity?>(null) }
|
var contextAgent by remember { mutableStateOf<AgentEntity?>(null) }
|
||||||
var showDeleteConfirmDialog by remember { mutableStateOf(false) }
|
var showDeleteConfirmDialog by remember { mutableStateOf(false) }
|
||||||
var showOtherUserMenu by remember { mutableStateOf(false) }
|
|
||||||
var showBlockConfirmDialog by remember { mutableStateOf(false) }
|
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
val scope = rememberCoroutineScope()
|
val scope = rememberCoroutineScope()
|
||||||
val navController = LocalNavController.current
|
val navController = LocalNavController.current
|
||||||
val bannerWidth = 402
|
val bannerHeight = 400
|
||||||
val bannerHeight = 206
|
|
||||||
val pickBannerImageLauncher = pickupAndCompressLauncher(
|
val pickBannerImageLauncher = pickupAndCompressLauncher(
|
||||||
context,
|
context,
|
||||||
scope,
|
scope,
|
||||||
@@ -166,16 +152,11 @@ fun ProfileV3(
|
|||||||
val gridState = rememberLazyGridState()
|
val gridState = rememberLazyGridState()
|
||||||
val scrollState = rememberScrollState()
|
val scrollState = rememberScrollState()
|
||||||
|
|
||||||
// 计算导航栏背景透明度,根据滚动位置从0到1
|
val toolbarAlpha by remember {
|
||||||
val toolbarBackgroundAlpha by remember {
|
|
||||||
derivedStateOf {
|
derivedStateOf {
|
||||||
if (!isSelf) {
|
val maxScroll = 500f // 最大滚动距离,可调整
|
||||||
1f
|
val progress = (scrollState.value.coerceAtMost(maxScroll.toInt()) / maxScroll).coerceIn(0f, 1f)
|
||||||
} else {
|
progress
|
||||||
val maxScroll = 600f // 增加最大滚动距离,让渐变更平缓
|
|
||||||
val progress = (scrollState.value.coerceAtMost(maxScroll.toInt()) / maxScroll).coerceIn(0f, 1f)
|
|
||||||
progress
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -319,19 +300,12 @@ fun ProfileV3(
|
|||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.height(bannerHeight.dp)
|
.height(bannerHeight.dp)
|
||||||
.background(AppColors.profileBackground),
|
.background(AppColors.profileBackground)
|
||||||
contentAlignment = Alignment.Center
|
|
||||||
) {
|
) {
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.width(bannerWidth.dp)
|
.fillMaxWidth()
|
||||||
.height(bannerHeight.dp)
|
.height(bannerHeight.dp - 24.dp)
|
||||||
.clip(
|
|
||||||
RoundedCornerShape(
|
|
||||||
bottomStart = 32.dp,
|
|
||||||
bottomEnd = 32.dp
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.let {
|
.let {
|
||||||
if (isSelf && isMain) {
|
if (isSelf && isMain) {
|
||||||
it.noRippleClickable {
|
it.noRippleClickable {
|
||||||
@@ -344,6 +318,13 @@ fun ProfileV3(
|
|||||||
it
|
it
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.shadow(
|
||||||
|
elevation = 6.dp,
|
||||||
|
shape = RoundedCornerShape(
|
||||||
|
bottomStart = 32.dp,
|
||||||
|
bottomEnd = 32.dp
|
||||||
|
),
|
||||||
|
)
|
||||||
) {
|
) {
|
||||||
CustomAsyncImage(
|
CustomAsyncImage(
|
||||||
LocalContext.current,
|
LocalContext.current,
|
||||||
@@ -358,9 +339,6 @@ fun ProfileV3(
|
|||||||
Spacer(modifier = Modifier.height(100.dp))
|
Spacer(modifier = Modifier.height(100.dp))
|
||||||
}
|
}
|
||||||
|
|
||||||
// 壁纸下方间距
|
|
||||||
Spacer(modifier = Modifier.height(16.dp))
|
|
||||||
|
|
||||||
// 用户信息
|
// 用户信息
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
@@ -371,34 +349,41 @@ fun ProfileV3(
|
|||||||
profile?.let {
|
profile?.let {
|
||||||
UserItem(
|
UserItem(
|
||||||
accountProfileEntity = it,
|
accountProfileEntity = it,
|
||||||
postCount = postCount ?: if (isSelf) MyProfileViewModel.momentLoader.total else moments.size.toLong(),
|
postCount = postCount ?: if (isSelf) MyProfileViewModel.momentLoader.total else moments.size
|
||||||
isSelf = isSelf,
|
|
||||||
onEditClick = {
|
|
||||||
navController.navigate(NavigationRoute.AccountEdit.route)
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(20.dp))
|
Spacer(modifier = Modifier.height(20.dp))
|
||||||
|
|
||||||
// 操作按钮(仅其他用户显示)
|
// 操作按钮
|
||||||
profile?.let {
|
profile?.let {
|
||||||
if (!isSelf && it.id != AppState.UserId) {
|
Box(
|
||||||
Box(
|
modifier = Modifier
|
||||||
modifier = Modifier
|
.fillMaxWidth()
|
||||||
.fillMaxWidth()
|
.padding(horizontal = 16.dp)
|
||||||
.padding(horizontal = 16.dp)
|
) {
|
||||||
) {
|
if (isSelf) {
|
||||||
OtherProfileAction(
|
SelfProfileAction(
|
||||||
it,
|
onEditProfile = {
|
||||||
onFollow = {
|
navController.navigate(NavigationRoute.AccountEdit.route)
|
||||||
onFollowClick()
|
|
||||||
},
|
},
|
||||||
onChat = {
|
onPremiumClick = {
|
||||||
onChatClick()
|
navController.navigate(NavigationRoute.VipSelPage.route)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
} else {
|
||||||
|
if (it.id != AppState.UserId) {
|
||||||
|
OtherProfileAction(
|
||||||
|
it,
|
||||||
|
onFollow = {
|
||||||
|
onFollowClick()
|
||||||
|
},
|
||||||
|
onChat = {
|
||||||
|
onChatClick()
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -452,50 +437,39 @@ fun ProfileV3(
|
|||||||
pagerState = pagerState,
|
pagerState = pagerState,
|
||||||
showAgentTab = !isAiAccount
|
showAgentTab = !isAiAccount
|
||||||
)
|
)
|
||||||
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
HorizontalPager(
|
HorizontalPager(
|
||||||
state = pagerState,
|
state = pagerState,
|
||||||
modifier = Modifier.height(500.dp) // 固定滚动高度
|
modifier = Modifier.height(500.dp) // 固定滚动高度
|
||||||
) { idx ->
|
) { idx ->
|
||||||
when (idx) {
|
when (idx) {
|
||||||
0 -> GalleryGrid(moments = moments)
|
0 ->
|
||||||
1 -> {
|
GalleryGrid(moments = moments)
|
||||||
if (!isAiAccount) {
|
1 ->
|
||||||
UserAgentsList(
|
UserAgentsList(
|
||||||
agents = agents,
|
agents = agents,
|
||||||
onAgentClick = onAgentClick,
|
onAgentClick = onAgentClick,
|
||||||
onAvatarClick = { agent ->
|
onAvatarClick = { agent ->
|
||||||
// 导航到智能体个人主页,需要通过openId获取用户ID
|
// 导航到智能体个人主页,需要通过openId获取用户ID
|
||||||
scope.launch {
|
scope.launch {
|
||||||
try {
|
try {
|
||||||
val userService = com.aiosman.ravenow.data.UserServiceImpl()
|
val userService = com.aiosman.ravenow.data.UserServiceImpl()
|
||||||
val profile = userService.getUserProfileByOpenId(agent.openId)
|
val profile = userService.getUserProfileByOpenId(agent.openId)
|
||||||
navController.navigate(
|
navController.navigate(
|
||||||
NavigationRoute.AccountProfile.route
|
NavigationRoute.AccountProfile.route
|
||||||
.replace("{id}", profile.id.toString())
|
.replace("{id}", profile.id.toString())
|
||||||
.replace("{isAiAccount}", "true")
|
.replace("{isAiAccount}", "true")
|
||||||
)
|
)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
// 处理错误
|
// 处理错误
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
modifier = Modifier.fillMaxSize()
|
},
|
||||||
)
|
modifier = Modifier.fillMaxSize()
|
||||||
} else {
|
)
|
||||||
GroupChatPlaceholder()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
2 -> {
|
|
||||||
if (!isAiAccount) {
|
|
||||||
GroupChatPlaceholder()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 底部间距,增加滚动距离
|
|
||||||
Spacer(modifier = Modifier.height(100.dp))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 顶部导航栏
|
// 顶部导航栏
|
||||||
@@ -504,14 +478,7 @@ fun ProfileV3(
|
|||||||
isSelf = isSelf,
|
isSelf = isSelf,
|
||||||
profile = profile,
|
profile = profile,
|
||||||
navController = navController,
|
navController = navController,
|
||||||
backgroundAlpha = toolbarBackgroundAlpha,
|
alpha = toolbarAlpha
|
||||||
interactionCount = moments.sumOf { it.likeCount }, // 计算总点赞数作为互动数据
|
|
||||||
onMenuClick = {
|
|
||||||
showOtherUserMenu = true
|
|
||||||
},
|
|
||||||
onShareClick = {
|
|
||||||
// TODO: 实现分享功能
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
PullRefreshIndicator(
|
PullRefreshIndicator(
|
||||||
@@ -519,75 +486,8 @@ fun ProfileV3(
|
|||||||
refreshState,
|
refreshState,
|
||||||
Modifier.align(Alignment.TopCenter)
|
Modifier.align(Alignment.TopCenter)
|
||||||
)
|
)
|
||||||
|
|
||||||
// 其他用户菜单弹窗
|
|
||||||
if (showOtherUserMenu) {
|
|
||||||
ModalBottomSheet(
|
|
||||||
onDismissRequest = { showOtherUserMenu = false },
|
|
||||||
sheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true),
|
|
||||||
containerColor = Color.Transparent, // 设置容器背景透明
|
|
||||||
contentColor = Color.Transparent, // 设置内容背景透明
|
|
||||||
dragHandle = null, // 移除拖拽手柄
|
|
||||||
windowInsets = androidx.compose.foundation.layout.WindowInsets(0) // 移除窗口边距
|
|
||||||
) {
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.background(Color.Transparent)
|
|
||||||
) {
|
|
||||||
OtherUserMenuModal(
|
|
||||||
onBlockClick = {
|
|
||||||
showBlockConfirmDialog = true
|
|
||||||
},
|
|
||||||
onReportClick = {
|
|
||||||
// 实现举报逻辑
|
|
||||||
},
|
|
||||||
onCancelClick = {
|
|
||||||
showOtherUserMenu = false
|
|
||||||
},
|
|
||||||
onDismiss = { showOtherUserMenu = false }
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 拉黑确认弹窗
|
|
||||||
if (showBlockConfirmDialog) {
|
|
||||||
ModalBottomSheet(
|
|
||||||
onDismissRequest = {
|
|
||||||
showBlockConfirmDialog = false
|
|
||||||
},
|
|
||||||
sheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true),
|
|
||||||
containerColor = Color.Transparent,
|
|
||||||
contentColor = Color.Transparent,
|
|
||||||
dragHandle = null,
|
|
||||||
windowInsets = androidx.compose.foundation.layout.WindowInsets(0)
|
|
||||||
) {
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.background(Color.Transparent)
|
|
||||||
) {
|
|
||||||
BlockConfirmDialog(
|
|
||||||
userProfile = profile,
|
|
||||||
onConfirmBlock = {
|
|
||||||
// 实现拉黑逻辑
|
|
||||||
},
|
|
||||||
onDismiss = {
|
|
||||||
showBlockConfirmDialog = false
|
|
||||||
showOtherUserMenu = false
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
private fun GroupChatPlaceholder() {
|
|
||||||
GroupChatEmptyContent()
|
|
||||||
}
|
|
||||||
|
|
||||||
//顶部导航栏组件
|
//顶部导航栏组件
|
||||||
@Composable
|
@Composable
|
||||||
@@ -596,201 +496,85 @@ fun TopNavigationBar(
|
|||||||
isSelf: Boolean,
|
isSelf: Boolean,
|
||||||
profile: AccountProfileEntity?,
|
profile: AccountProfileEntity?,
|
||||||
navController: androidx.navigation.NavController,
|
navController: androidx.navigation.NavController,
|
||||||
backgroundAlpha: Float,
|
|
||||||
interactionCount: Int = 0,
|
alpha: Float
|
||||||
onMenuClick: () -> Unit = {},
|
|
||||||
onShareClick: () -> Unit = {}
|
|
||||||
) {
|
) {
|
||||||
val appColors = LocalAppTheme.current
|
val appColors = LocalAppTheme.current
|
||||||
val numberFormat = remember { NumberFormat.getNumberInstance(Locale.getDefault()) }
|
|
||||||
|
|
||||||
// 根据背景透明度和暗色模式决定图标颜色
|
|
||||||
// 暗色模式下:图标始终为白色
|
|
||||||
// 亮色模式下:根据背景透明度决定,透明度为1时变黑,否则为白色
|
|
||||||
val iconColor = if (AppState.darkMode) {
|
|
||||||
Color.White // 暗色模式下图标始终为白色
|
|
||||||
} else {
|
|
||||||
if (backgroundAlpha >= 1f) Color.Black else Color.White
|
|
||||||
}
|
|
||||||
val cardBorderColor = if (AppState.darkMode) {
|
|
||||||
Color.White // 暗色模式下边框应为白色
|
|
||||||
} else {
|
|
||||||
if (backgroundAlpha >= 1f) Color.Black else Color.White
|
|
||||||
}
|
|
||||||
|
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
|
.graphicsLayer { this.alpha = alpha } // 应用透明度
|
||||||
) {
|
) {
|
||||||
val statusBarPadding = WindowInsets.systemBars.asPaddingValues()
|
Column(
|
||||||
val statusBarHeight = statusBarPadding.calculateTopPadding()
|
|
||||||
val navigationBarHeight = 56.dp // 增加导航栏高度,包括图标和额外空间
|
|
||||||
|
|
||||||
// 导航栏背景层,包括状态栏区域,根据滚动位置逐渐变白
|
|
||||||
val totalHeight = statusBarHeight + navigationBarHeight
|
|
||||||
val density = LocalDensity.current
|
|
||||||
val totalHeightPx = with(density) { totalHeight.toPx() }
|
|
||||||
|
|
||||||
// 根据滚动位置计算基础颜色,从深色平滑过渡到白色,透明度从初始值逐渐减到0
|
|
||||||
val baseColor = remember(backgroundAlpha) {
|
|
||||||
val smoothProgress = backgroundAlpha.coerceIn(0f, 1f)
|
|
||||||
|
|
||||||
if (AppState.darkMode) {
|
|
||||||
// 暗色模式下:从黑色(透明度0)逐渐变为黑色(透明度1)
|
|
||||||
val alpha = smoothProgress.coerceIn(0f, 1f)
|
|
||||||
Color.Black.copy(alpha = alpha)
|
|
||||||
} else {
|
|
||||||
// 亮色模式:初始状态:半透明深色,让白色图标清晰可见
|
|
||||||
val initialDarkAlpha = 0.12f
|
|
||||||
|
|
||||||
// 使用平滑的插值函数,让整个过渡更自然
|
|
||||||
val easedProgress = smoothProgress * smoothProgress * (3f - 2f * smoothProgress) // smoothstep
|
|
||||||
|
|
||||||
// 颜色值:从黑色(0)平滑过渡到白色(1)
|
|
||||||
val colorValue = easedProgress
|
|
||||||
|
|
||||||
// 透明度:从初始值(0.12f)逐渐减少到0
|
|
||||||
// 当smoothProgress从0到1时,alpha从initialDarkAlpha减少到0
|
|
||||||
val alpha = initialDarkAlpha * (1f - easedProgress)
|
|
||||||
|
|
||||||
Color(
|
|
||||||
red = colorValue,
|
|
||||||
green = colorValue,
|
|
||||||
blue = colorValue,
|
|
||||||
alpha = alpha.coerceIn(0f, initialDarkAlpha)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.height(totalHeight) // 状态栏高度 + 导航栏高度
|
.background(appColors.profileBackground)
|
||||||
.align(Alignment.TopCenter)
|
|
||||||
.background(
|
|
||||||
brush = Brush.verticalGradient(
|
|
||||||
colors = listOf(
|
|
||||||
baseColor, // 顶部保持基础颜色
|
|
||||||
baseColor, // 中间保持基础颜色
|
|
||||||
baseColor.copy(alpha = baseColor.alpha * 0.5f), // 底部过渡,逐渐变透明
|
|
||||||
Color.Transparent // 最底部完全透明
|
|
||||||
),
|
|
||||||
startY = 0f,
|
|
||||||
endY = totalHeightPx
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
// 功能按钮区域,图标和文字根据背景透明度改变颜色
|
|
||||||
Row(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(top = 16.dp, bottom = 16.dp, end = 16.dp) // 增加上下内边距
|
|
||||||
.align(Alignment.TopEnd)
|
|
||||||
.padding(top = statusBarHeight), // 从状态栏下方开始
|
|
||||||
horizontalArrangement = Arrangement.End,
|
|
||||||
verticalAlignment = Alignment.CenterVertically
|
|
||||||
) {
|
) {
|
||||||
// 左侧:互动数据卡片
|
StatusBarSpacer()
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.height(24.dp)
|
.fillMaxWidth()
|
||||||
.background(
|
|
||||||
color = Color.White.copy(alpha = 0.52f),
|
|
||||||
shape = RoundedCornerShape(16.dp)
|
|
||||||
)
|
|
||||||
.border(
|
|
||||||
width = 0.5.dp,
|
|
||||||
color = cardBorderColor, // 根据背景透明度改变边框颜色
|
|
||||||
shape = RoundedCornerShape(16.dp)
|
|
||||||
)
|
|
||||||
.padding(horizontal = 8.dp),
|
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
|
||||||
horizontalArrangement = Arrangement.Center
|
|
||||||
) {
|
|
||||||
// 互动图标
|
|
||||||
Image(
|
|
||||||
painter = painterResource(id = R.mipmap.paip_coin_img),
|
|
||||||
contentDescription = "互动",
|
|
||||||
modifier = Modifier.size(24.dp),
|
|
||||||
)
|
|
||||||
Spacer(modifier = Modifier.width(4.dp))
|
|
||||||
Text(
|
|
||||||
text = numberFormat.format(interactionCount),
|
|
||||||
fontSize = 14.sp,
|
|
||||||
fontWeight = FontWeight.W500,
|
|
||||||
color = if (AppState.darkMode) Color.White else Color.Black, // 暗色模式下为白色,亮色模式下为黑色
|
|
||||||
textAlign = TextAlign.Center
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
Spacer(modifier = Modifier.width(16.dp))
|
|
||||||
|
|
||||||
// 中间:分享图标
|
|
||||||
Image(
|
|
||||||
painter = painterResource(id = R.mipmap.menu_icon),
|
|
||||||
contentDescription = "分享",
|
|
||||||
modifier = Modifier
|
|
||||||
.size(24.dp)
|
|
||||||
.noRippleClickable {
|
|
||||||
onShareClick()
|
|
||||||
},
|
|
||||||
colorFilter = ColorFilter.tint(iconColor) // 根据背景透明度改变颜色
|
|
||||||
)
|
|
||||||
|
|
||||||
Spacer(modifier = Modifier.width(16.dp))
|
|
||||||
|
|
||||||
// 右侧:菜单图标
|
|
||||||
Image(
|
|
||||||
painter = painterResource(id = R.mipmap.menu_ico),
|
|
||||||
contentDescription = "菜单",
|
|
||||||
modifier = Modifier
|
|
||||||
.size(24.dp)
|
|
||||||
.noRippleClickable {
|
|
||||||
if (isSelf && isMain) {
|
|
||||||
IndexViewModel.openDrawer = true
|
|
||||||
} else {
|
|
||||||
onMenuClick()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
colorFilter = ColorFilter.tint(iconColor) // 根据背景透明度改变颜色
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 如果不是主页面,显示返回按钮和用户信息
|
|
||||||
if (!isMain) {
|
|
||||||
val statusBarPadding = WindowInsets.systemBars.asPaddingValues()
|
|
||||||
// 判断是否有背景图
|
|
||||||
val hasBanner = profile?.banner != null
|
|
||||||
|
|
||||||
Row(
|
|
||||||
modifier = Modifier
|
|
||||||
.align(Alignment.TopStart)
|
|
||||||
.padding(horizontal = 16.dp, vertical = 8.dp)
|
.padding(horizontal = 16.dp, vertical = 8.dp)
|
||||||
.padding(top = statusBarPadding.calculateTopPadding()),
|
.noRippleClickable {
|
||||||
|
},
|
||||||
verticalAlignment = Alignment.CenterVertically
|
verticalAlignment = Alignment.CenterVertically
|
||||||
) {
|
) {
|
||||||
// 返回按钮:深色模式下为白色,亮色模式下为黑色
|
if (!isMain) {
|
||||||
val backButtonColor = if (AppState.darkMode) Color.White else Color.Black
|
Image(
|
||||||
Image(
|
painter = painterResource(id = R.drawable.rider_pro_back_icon),
|
||||||
painter = painterResource(id = R.drawable.rider_pro_back_icon),
|
contentDescription = "Back",
|
||||||
contentDescription = "Back",
|
modifier = Modifier
|
||||||
modifier = Modifier
|
.noRippleClickable {
|
||||||
.noRippleClickable {
|
navController.navigateUp()
|
||||||
navController.navigateUp()
|
}
|
||||||
}
|
.size(24.dp),
|
||||||
.size(24.dp),
|
colorFilter = ColorFilter.tint(appColors.text)
|
||||||
colorFilter = ColorFilter.tint(backButtonColor) // 深色模式下为白色,亮色模式下为黑色
|
)
|
||||||
)
|
|
||||||
|
|
||||||
// 未设置背景的用户(自己的主页且没有背景图)显示昵称
|
|
||||||
if (isSelf && !hasBanner && profile != null) {
|
|
||||||
Spacer(modifier = Modifier.width(8.dp))
|
Spacer(modifier = Modifier.width(8.dp))
|
||||||
|
CustomAsyncImage(
|
||||||
|
LocalContext.current,
|
||||||
|
profile?.avatar,
|
||||||
|
modifier = Modifier
|
||||||
|
.size(32.dp)
|
||||||
|
.clip(CircleShape),
|
||||||
|
contentDescription = "",
|
||||||
|
contentScale = ContentScale.Crop
|
||||||
|
)
|
||||||
|
Spacer(modifier = Modifier.width(16.dp))
|
||||||
Text(
|
Text(
|
||||||
text = profile.nickName ?: "",
|
text = profile?.nickName ?: "",
|
||||||
fontSize = 16.sp,
|
fontSize = 16.sp,
|
||||||
fontWeight = FontWeight.W600,
|
fontWeight = FontWeight.W600,
|
||||||
color = backButtonColor // 深色模式下为白色,亮色模式下为黑色
|
color = appColors.text
|
||||||
|
)
|
||||||
|
}
|
||||||
|
Spacer(modifier = Modifier.weight(1f))
|
||||||
|
if (isSelf && isMain) {
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.size(24.dp)
|
||||||
|
.padding(16.dp)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
|
}
|
||||||
|
if (isSelf && isMain) {
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.align(Alignment.TopEnd)
|
||||||
|
.padding(top = 32.dp, end = 16.dp)
|
||||||
|
.noRippleClickable {
|
||||||
|
IndexViewModel.openDrawer = true
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
Box(
|
||||||
|
modifier = Modifier.padding(16.dp)
|
||||||
|
) {
|
||||||
|
Icon(
|
||||||
|
painter = painterResource(id = R.drawable.rider_pro_more_horizon),
|
||||||
|
contentDescription = "",
|
||||||
|
tint = appColors.text
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -798,77 +582,6 @@ fun TopNavigationBar(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 分享图标(向上箭头)
|
|
||||||
@Composable
|
|
||||||
fun ShareIcon(
|
|
||||||
color: Color,
|
|
||||||
modifier: Modifier = Modifier
|
|
||||||
) {
|
|
||||||
Canvas(modifier = modifier) {
|
|
||||||
val strokeWidth = 2.dp.toPx()
|
|
||||||
val centerX = size.width / 2
|
|
||||||
val centerY = size.height / 2
|
|
||||||
|
|
||||||
// 绘制向上的箭头
|
|
||||||
// 底部横线
|
|
||||||
drawLine(
|
|
||||||
color = color,
|
|
||||||
start = Offset(centerX - 9.dp.toPx(), centerY + 6.dp.toPx()),
|
|
||||||
end = Offset(centerX + 9.dp.toPx(), centerY + 6.dp.toPx()),
|
|
||||||
strokeWidth = strokeWidth
|
|
||||||
)
|
|
||||||
// 顶部横线
|
|
||||||
drawLine(
|
|
||||||
color = color,
|
|
||||||
start = Offset(centerX - 5.dp.toPx(), centerY - 6.5.dp.toPx()),
|
|
||||||
end = Offset(centerX + 5.dp.toPx(), centerY - 6.5.dp.toPx()),
|
|
||||||
strokeWidth = strokeWidth
|
|
||||||
)
|
|
||||||
// 中间竖线
|
|
||||||
drawLine(
|
|
||||||
color = color,
|
|
||||||
start = Offset(centerX, centerY - 3.dp.toPx()),
|
|
||||||
end = Offset(centerX, centerY + 6.dp.toPx()),
|
|
||||||
strokeWidth = strokeWidth
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 菜单图标(三条横线)
|
|
||||||
@Composable
|
|
||||||
fun MenuIcon(
|
|
||||||
color: Color,
|
|
||||||
modifier: Modifier = Modifier
|
|
||||||
) {
|
|
||||||
Canvas(modifier = modifier) {
|
|
||||||
val strokeWidth = 2.dp.toPx()
|
|
||||||
val centerX = size.width / 2
|
|
||||||
val centerY = size.height / 2
|
|
||||||
val lineLength = 16.dp.toPx()
|
|
||||||
val spacing = 6.dp.toPx()
|
|
||||||
|
|
||||||
// 绘制三条横线
|
|
||||||
drawLine(
|
|
||||||
color = color,
|
|
||||||
start = Offset(centerX - lineLength / 2, centerY - spacing),
|
|
||||||
end = Offset(centerX + lineLength / 2, centerY - spacing),
|
|
||||||
strokeWidth = strokeWidth
|
|
||||||
)
|
|
||||||
drawLine(
|
|
||||||
color = color,
|
|
||||||
start = Offset(centerX - lineLength / 2, centerY),
|
|
||||||
end = Offset(centerX + lineLength / 2, centerY),
|
|
||||||
strokeWidth = strokeWidth
|
|
||||||
)
|
|
||||||
drawLine(
|
|
||||||
color = color,
|
|
||||||
start = Offset(centerX - lineLength / 2, centerY + spacing),
|
|
||||||
end = Offset(centerX + lineLength / 2, centerY + spacing),
|
|
||||||
strokeWidth = strokeWidth
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Agent菜单弹窗
|
* Agent菜单弹窗
|
||||||
*/
|
*/
|
||||||
@@ -948,7 +661,7 @@ fun AgentMenuModal(
|
|||||||
if (isSelf) {
|
if (isSelf) {
|
||||||
MenuActionItem(
|
MenuActionItem(
|
||||||
icon = R.drawable.rider_pro_moment_delete,
|
icon = R.drawable.rider_pro_moment_delete,
|
||||||
text = stringResource(R.string.delete)
|
text = "删除"
|
||||||
) {
|
) {
|
||||||
onDeleteClick()
|
onDeleteClick()
|
||||||
}
|
}
|
||||||
@@ -1024,96 +737,3 @@ fun DeleteConfirmDialog(
|
|||||||
containerColor = AppColors.background
|
containerColor = AppColors.background
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 其他用户主页菜单弹窗
|
|
||||||
*/
|
|
||||||
@Composable
|
|
||||||
fun OtherUserMenuModal(
|
|
||||||
onBlockClick: () -> Unit = {},
|
|
||||||
onReportClick: () -> Unit = {},
|
|
||||||
onCancelClick: () -> Unit = {},
|
|
||||||
onDismiss: () -> Unit = {}
|
|
||||||
) {
|
|
||||||
val AppColors = LocalAppTheme.current
|
|
||||||
|
|
||||||
Box(
|
|
||||||
modifier = Modifier.fillMaxSize(),
|
|
||||||
contentAlignment = Alignment.BottomCenter
|
|
||||||
) {
|
|
||||||
Column(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(horizontal = 8.dp)
|
|
||||||
.padding(bottom = 11.dp)
|
|
||||||
) {
|
|
||||||
Column(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.background(
|
|
||||||
color = AppColors.background,
|
|
||||||
shape = RoundedCornerShape(8.dp)
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
// 拉黑选项
|
|
||||||
androidx.compose.material3.TextButton(
|
|
||||||
onClick = {
|
|
||||||
onBlockClick()
|
|
||||||
},
|
|
||||||
modifier = Modifier.fillMaxWidth()
|
|
||||||
) {
|
|
||||||
Text(
|
|
||||||
stringResource(R.string.block),
|
|
||||||
color = AppColors.error,
|
|
||||||
fontWeight = FontWeight.Bold,
|
|
||||||
fontSize = 16.sp
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 分割线
|
|
||||||
androidx.compose.material3.HorizontalDivider(
|
|
||||||
color = AppColors.divider,
|
|
||||||
thickness = 0.5.dp
|
|
||||||
)
|
|
||||||
|
|
||||||
// 举报选项
|
|
||||||
androidx.compose.material3.TextButton(
|
|
||||||
onClick = {
|
|
||||||
onReportClick()
|
|
||||||
onDismiss()
|
|
||||||
},
|
|
||||||
modifier = Modifier.fillMaxWidth()
|
|
||||||
) {
|
|
||||||
Text(
|
|
||||||
stringResource(R.string.report),
|
|
||||||
color = AppColors.error,
|
|
||||||
fontWeight = FontWeight.Bold,
|
|
||||||
fontSize = 16.sp
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(8.dp))
|
|
||||||
|
|
||||||
// 取消按钮
|
|
||||||
androidx.compose.material3.TextButton(
|
|
||||||
onClick = {
|
|
||||||
onCancelClick()
|
|
||||||
onDismiss()
|
|
||||||
},
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.background(
|
|
||||||
color = AppColors.background,
|
|
||||||
shape = RoundedCornerShape(8.dp)
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
Text(
|
|
||||||
stringResource(R.string.cancel),
|
|
||||||
color = AppColors.text,
|
|
||||||
fontSize = 16.sp
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -42,8 +42,6 @@ import androidx.compose.runtime.mutableStateOf
|
|||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.text.style.TextAlign
|
|
||||||
import androidx.compose.ui.text.style.TextOverflow
|
|
||||||
import com.aiosman.ravenow.AppState
|
import com.aiosman.ravenow.AppState
|
||||||
import com.aiosman.ravenow.ui.composables.rememberDebouncer
|
import com.aiosman.ravenow.ui.composables.rememberDebouncer
|
||||||
import com.aiosman.ravenow.ui.index.tabs.profile.MyProfileViewModel
|
import com.aiosman.ravenow.ui.index.tabs.profile.MyProfileViewModel
|
||||||
@@ -191,37 +189,28 @@ fun GalleryGrid(
|
|||||||
) {
|
) {
|
||||||
Image(
|
Image(
|
||||||
painter = painterResource(
|
painter = painterResource(
|
||||||
id = if(AppState.darkMode) R.mipmap.shuihu_dark
|
id = if(AppState.darkMode) R.mipmap.qs_dt_qs_as_img
|
||||||
else R.mipmap.invalid_name_7),
|
else R.mipmap.invalid_name_7),
|
||||||
contentDescription = "暂无图片",
|
contentDescription = "暂无图片",
|
||||||
modifier = Modifier
|
modifier = Modifier.size(181.dp),
|
||||||
.size(width = 181.dp, height = 153.dp),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(if(AppState.darkMode) 9.dp else 24.dp))
|
Spacer(modifier = Modifier.height(24.dp))
|
||||||
|
|
||||||
Text(
|
Text(
|
||||||
text = stringResource(R.string.your_story_not_started),
|
text = "故事还没开始",
|
||||||
fontSize = 16.sp,
|
fontSize = 16.sp,
|
||||||
color = AppColors.text,
|
color = AppColors.text,
|
||||||
fontWeight = FontWeight.W600,
|
fontWeight = FontWeight.W600
|
||||||
textAlign = TextAlign.Center,
|
|
||||||
modifier = Modifier.padding(horizontal = 24.dp),
|
|
||||||
maxLines = 2,
|
|
||||||
overflow = TextOverflow.Ellipsis
|
|
||||||
)
|
)
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(8.dp))
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
|
|
||||||
Text(
|
Text(
|
||||||
text = stringResource(R.string.publish_moment_greeting),
|
text = "发布一条动态,和世界打个招呼吧",
|
||||||
fontSize = 14.sp,
|
fontSize = 14.sp,
|
||||||
color = AppColors.secondaryText,
|
color = AppColors.secondaryText,
|
||||||
fontWeight = FontWeight.W400,
|
fontWeight = FontWeight.W400
|
||||||
textAlign = TextAlign.Center,
|
|
||||||
modifier = Modifier.padding(horizontal = 24.dp),
|
|
||||||
maxLines = 3,
|
|
||||||
overflow = TextOverflow.Ellipsis
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -231,7 +220,7 @@ fun GalleryGrid(
|
|||||||
modifier = Modifier.fillMaxSize().padding(bottom = 8.dp),
|
modifier = Modifier.fillMaxSize().padding(bottom = 8.dp),
|
||||||
) {
|
) {
|
||||||
itemsIndexed(moments) { idx, moment ->
|
itemsIndexed(moments) { idx, moment ->
|
||||||
if (moment != null && moment.images.isNotEmpty()) {
|
if (moment != null) {
|
||||||
val itemDebouncer = rememberDebouncer()
|
val itemDebouncer = rememberDebouncer()
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
|
|||||||
@@ -1,177 +0,0 @@
|
|||||||
package com.aiosman.ravenow.ui.index.tabs.profile.composable
|
|
||||||
|
|
||||||
import androidx.compose.foundation.Image
|
|
||||||
import androidx.compose.foundation.background
|
|
||||||
import androidx.compose.foundation.clickable
|
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
|
||||||
import androidx.compose.foundation.layout.Box
|
|
||||||
import androidx.compose.foundation.layout.Column
|
|
||||||
import androidx.compose.foundation.layout.Row
|
|
||||||
import androidx.compose.foundation.layout.Spacer
|
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
|
||||||
import androidx.compose.foundation.layout.height
|
|
||||||
import androidx.compose.foundation.layout.padding
|
|
||||||
import androidx.compose.foundation.layout.size
|
|
||||||
import androidx.compose.foundation.layout.width
|
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
||||||
import androidx.compose.material3.Text
|
|
||||||
import androidx.compose.runtime.Composable
|
|
||||||
import androidx.compose.runtime.getValue
|
|
||||||
import androidx.compose.runtime.mutableStateOf
|
|
||||||
import androidx.compose.runtime.remember
|
|
||||||
import androidx.compose.runtime.setValue
|
|
||||||
import androidx.compose.ui.Alignment
|
|
||||||
import androidx.compose.ui.Modifier
|
|
||||||
import androidx.compose.ui.graphics.Color
|
|
||||||
import androidx.compose.ui.layout.ContentScale
|
|
||||||
import androidx.compose.ui.res.painterResource
|
|
||||||
import androidx.compose.ui.res.stringResource
|
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
|
||||||
import androidx.compose.ui.text.style.TextAlign
|
|
||||||
import androidx.compose.ui.text.style.TextOverflow
|
|
||||||
import androidx.compose.ui.unit.dp
|
|
||||||
import androidx.compose.ui.unit.sp
|
|
||||||
import com.aiosman.ravenow.LocalAppTheme
|
|
||||||
import com.aiosman.ravenow.R
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun GroupChatEmptyContent() {
|
|
||||||
var selectedSegment by remember { mutableStateOf(0) } // 0: 全部, 1: 公开, 2: 私有
|
|
||||||
val AppColors = LocalAppTheme.current
|
|
||||||
|
|
||||||
Column(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxSize()
|
|
||||||
.padding(horizontal = 16.dp)
|
|
||||||
) {
|
|
||||||
Spacer(modifier = Modifier.height(16.dp))
|
|
||||||
|
|
||||||
// 分段控制器
|
|
||||||
SegmentedControl(
|
|
||||||
selectedIndex = selectedSegment,
|
|
||||||
onSegmentSelected = { selectedSegment = it },
|
|
||||||
modifier = Modifier.fillMaxWidth()
|
|
||||||
)
|
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(8.dp))
|
|
||||||
|
|
||||||
// 空状态内容(居中)
|
|
||||||
Column(
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
|
||||||
horizontalAlignment = Alignment.CenterHorizontally
|
|
||||||
) {
|
|
||||||
// 空状态插图
|
|
||||||
EmptyStateIllustration()
|
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(9.dp))
|
|
||||||
|
|
||||||
// 空状态文本
|
|
||||||
Text(
|
|
||||||
text = stringResource(R.string.empty_nothing),
|
|
||||||
fontSize = 16.sp,
|
|
||||||
fontWeight = FontWeight.SemiBold,
|
|
||||||
color = AppColors.text,
|
|
||||||
textAlign = TextAlign.Center,
|
|
||||||
modifier = Modifier.padding(horizontal = 24.dp),
|
|
||||||
maxLines = 2,
|
|
||||||
overflow = TextOverflow.Ellipsis
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
private fun SegmentedControl(
|
|
||||||
selectedIndex: Int,
|
|
||||||
onSegmentSelected: (Int) -> Unit,
|
|
||||||
modifier: Modifier = Modifier
|
|
||||||
) {
|
|
||||||
val AppColors = LocalAppTheme.current
|
|
||||||
Row(
|
|
||||||
modifier = modifier
|
|
||||||
.height(32.dp),
|
|
||||||
horizontalArrangement = Arrangement.Start,
|
|
||||||
verticalAlignment = Alignment.CenterVertically
|
|
||||||
) {
|
|
||||||
// 全部
|
|
||||||
SegmentButton(
|
|
||||||
text = stringResource(R.string.chat_all),
|
|
||||||
isSelected = selectedIndex == 0,
|
|
||||||
onClick = { onSegmentSelected(0) },
|
|
||||||
width = 54.dp,
|
|
||||||
appColors = AppColors
|
|
||||||
)
|
|
||||||
|
|
||||||
Spacer(modifier = Modifier.width(8.dp))
|
|
||||||
|
|
||||||
// 公开
|
|
||||||
SegmentButton(
|
|
||||||
text = stringResource(R.string.public_label),
|
|
||||||
isSelected = selectedIndex == 1,
|
|
||||||
onClick = { onSegmentSelected(1) },
|
|
||||||
width = 59.dp,
|
|
||||||
appColors = AppColors
|
|
||||||
)
|
|
||||||
|
|
||||||
Spacer(modifier = Modifier.width(8.dp))
|
|
||||||
|
|
||||||
// 私有
|
|
||||||
SegmentButton(
|
|
||||||
text = stringResource(R.string.private_label),
|
|
||||||
isSelected = selectedIndex == 2,
|
|
||||||
onClick = { onSegmentSelected(2) },
|
|
||||||
width = 54.dp,
|
|
||||||
appColors = AppColors
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
private fun SegmentButton(
|
|
||||||
text: String,
|
|
||||||
isSelected: Boolean,
|
|
||||||
onClick: () -> Unit,
|
|
||||||
width: androidx.compose.ui.unit.Dp,
|
|
||||||
appColors: com.aiosman.ravenow.AppThemeData
|
|
||||||
) {
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.width(width)
|
|
||||||
.height(32.dp)
|
|
||||||
.background(
|
|
||||||
color = if (isSelected) {
|
|
||||||
appColors.checkedBackground // 使用选中背景色(暗色模式下是白色,亮色模式下是黑色)
|
|
||||||
} else {
|
|
||||||
Color(0x147C7480) // RGB(124, 116, 128, alpha 0.08)
|
|
||||||
},
|
|
||||||
shape = RoundedCornerShape(1000.dp)
|
|
||||||
)
|
|
||||||
.clickable(onClick = onClick),
|
|
||||||
contentAlignment = Alignment.Center
|
|
||||||
) {
|
|
||||||
Text(
|
|
||||||
text = text,
|
|
||||||
fontSize = 13.sp,
|
|
||||||
fontWeight = FontWeight.Normal,
|
|
||||||
color = if (isSelected) {
|
|
||||||
appColors.checkedText // 选中时使用选中文本颜色(暗色模式下是黑色,亮色模式下是白色)
|
|
||||||
} else {
|
|
||||||
appColors.text // 未选中时使用文本颜色
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
private fun EmptyStateIllustration() {
|
|
||||||
Image(
|
|
||||||
painter = painterResource(id = R.mipmap.l_empty_img),
|
|
||||||
contentDescription = "空状态",
|
|
||||||
modifier = Modifier
|
|
||||||
.width(181.dp)
|
|
||||||
.height(153.dp),
|
|
||||||
contentScale = ContentScale.Fit
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -98,7 +98,7 @@ fun OtherProfileAction(
|
|||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
Text(
|
Text(
|
||||||
text = if (profile.isFollowing) stringResource(R.string.follow_upper_had) else stringResource(R.string.follow_upper),
|
text = if (profile.isFollowing) "已关注" else stringResource(R.string.follow_upper),
|
||||||
fontSize = 14.sp,
|
fontSize = 14.sp,
|
||||||
fontWeight = FontWeight.W900,
|
fontWeight = FontWeight.W900,
|
||||||
color = if (profile.isFollowing) {
|
color = if (profile.isFollowing) {
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import androidx.compose.foundation.layout.Arrangement
|
|||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.Spacer
|
import androidx.compose.foundation.layout.Spacer
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.height
|
|
||||||
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.width
|
import androidx.compose.foundation.layout.width
|
||||||
@@ -48,72 +47,66 @@ fun SelfProfileAction(
|
|||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
horizontalArrangement = Arrangement.Center,
|
horizontalArrangement = Arrangement.Center,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.width(60.dp).height(25.dp)
|
.weight(1f)
|
||||||
.clip(RoundedCornerShape(12.dp))
|
.clip(RoundedCornerShape(10.dp))
|
||||||
.background(androidx.compose.ui.graphics.Color(0x229284BD))
|
.background(AppColors.nonActive)
|
||||||
|
.padding(horizontal = 5.dp, vertical = 12.dp)
|
||||||
.noRippleClickable {
|
.noRippleClickable {
|
||||||
editProfileDebouncer {
|
editProfileDebouncer {
|
||||||
onEditProfile()
|
onEditProfile()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
Image(
|
|
||||||
painter = painterResource(id = R.mipmap.fill_and_sign),
|
|
||||||
contentDescription = "",
|
|
||||||
modifier = Modifier.size(12.dp),
|
|
||||||
colorFilter = ColorFilter.tint(androidx.compose.ui.graphics.Color(0xFF9284BD))
|
|
||||||
)
|
|
||||||
Spacer(modifier = Modifier.width(4.dp))
|
|
||||||
Text(
|
Text(
|
||||||
text = stringResource(R.string.edit_profile),
|
text = stringResource(R.string.edit_profile),
|
||||||
fontSize = 12.sp,
|
fontSize = 14.sp,
|
||||||
fontWeight = FontWeight.W600,
|
fontWeight = FontWeight.W900,
|
||||||
color = androidx.compose.ui.graphics.Color(0xFF9284BD),
|
color = AppColors.text,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// // 预留按钮位置
|
// 预留按钮位置
|
||||||
// Row(
|
Row(
|
||||||
// verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
// horizontalArrangement = Arrangement.Center,
|
horizontalArrangement = Arrangement.Center,
|
||||||
// modifier = Modifier
|
modifier = Modifier
|
||||||
// .weight(1f)
|
.weight(1f)
|
||||||
// .clip(RoundedCornerShape(10.dp))
|
.clip(RoundedCornerShape(10.dp))
|
||||||
// .padding(horizontal = 16.dp, vertical = 12.dp)
|
.padding(horizontal = 16.dp, vertical = 12.dp)
|
||||||
// .noRippleClickable {
|
.noRippleClickable {
|
||||||
//
|
|
||||||
// }
|
}
|
||||||
// ) {
|
) {
|
||||||
// Text(
|
Text(
|
||||||
// text = "",
|
text = "",
|
||||||
// fontSize = 14.sp,
|
fontSize = 14.sp,
|
||||||
// fontWeight = FontWeight.W900,
|
fontWeight = FontWeight.W900,
|
||||||
// color = AppColors.text,
|
color = AppColors.text,
|
||||||
// )
|
)
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// // 分享按钮
|
// 分享按钮
|
||||||
// Row(
|
Row(
|
||||||
// verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
// horizontalArrangement = Arrangement.Center,
|
horizontalArrangement = Arrangement.Center,
|
||||||
// modifier = Modifier
|
modifier = Modifier
|
||||||
// .weight(1f)
|
.weight(1f)
|
||||||
// .clip(RoundedCornerShape(10.dp))
|
.clip(RoundedCornerShape(10.dp))
|
||||||
// .background(AppColors.nonActive)
|
.background(AppColors.nonActive)
|
||||||
// .padding(horizontal = 16.dp, vertical = 12.dp)
|
.padding(horizontal = 16.dp, vertical = 12.dp)
|
||||||
// .noRippleClickable {
|
.noRippleClickable {
|
||||||
// shareDebouncer {
|
shareDebouncer {
|
||||||
// // TODO: 添加分享逻辑
|
// TODO: 添加分享逻辑
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// ) {
|
) {
|
||||||
// Text(
|
Text(
|
||||||
// text = stringResource(R.string.share),
|
text = stringResource(R.string.share),
|
||||||
// fontSize = 14.sp,
|
fontSize = 14.sp,
|
||||||
// fontWeight = FontWeight.W900,
|
fontWeight = FontWeight.W900,
|
||||||
// color = AppColors.text,
|
color = AppColors.text,
|
||||||
// )
|
)
|
||||||
// }
|
}
|
||||||
|
|
||||||
// // Rave Premium 按钮(右侧)
|
// // Rave Premium 按钮(右侧)
|
||||||
// Row(
|
// Row(
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ import androidx.compose.ui.platform.LocalContext
|
|||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.compose.ui.text.style.TextAlign
|
|
||||||
import androidx.compose.ui.text.style.TextOverflow
|
import androidx.compose.ui.text.style.TextOverflow
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
@@ -61,14 +60,15 @@ fun UserAgentsList(
|
|||||||
) {
|
) {
|
||||||
val AppColors = LocalAppTheme.current
|
val AppColors = LocalAppTheme.current
|
||||||
|
|
||||||
if (agents.isEmpty()) {
|
LazyColumn(
|
||||||
// 使用带分段控制器的空状态布局
|
modifier = modifier.fillMaxSize(),
|
||||||
AgentEmptyContentWithSegments()
|
verticalArrangement = Arrangement.spacedBy(8.dp)
|
||||||
} else {
|
) {
|
||||||
LazyColumn(
|
if (agents.isEmpty()) {
|
||||||
modifier = modifier.fillMaxSize(),
|
item {
|
||||||
verticalArrangement = Arrangement.spacedBy(8.dp)
|
EmptyAgentsView()
|
||||||
) {
|
}
|
||||||
|
} else {
|
||||||
items(agents) { agent ->
|
items(agents) { agent ->
|
||||||
UserAgentCard(
|
UserAgentCard(
|
||||||
agent = agent,
|
agent = agent,
|
||||||
@@ -76,11 +76,11 @@ fun UserAgentsList(
|
|||||||
onAvatarClick = onAvatarClick
|
onAvatarClick = onAvatarClick
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 底部间距
|
// 底部间距
|
||||||
item {
|
item {
|
||||||
Spacer(modifier = Modifier.height(120.dp))
|
Spacer(modifier = Modifier.height(120.dp))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -198,188 +198,6 @@ fun UserAgentCard(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun AgentEmptyContentWithSegments() {
|
|
||||||
var selectedSegment by remember { mutableStateOf(0) } // 0: 全部, 1: 公开, 2: 私有
|
|
||||||
val AppColors = LocalAppTheme.current
|
|
||||||
val isNetworkAvailable = NetworkUtils.isNetworkAvailable(LocalContext.current)
|
|
||||||
|
|
||||||
Column(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxSize()
|
|
||||||
.padding(horizontal = 16.dp)
|
|
||||||
) {
|
|
||||||
Spacer(modifier = Modifier.height(16.dp))
|
|
||||||
|
|
||||||
// 分段控制器
|
|
||||||
AgentSegmentedControl(
|
|
||||||
selectedIndex = selectedSegment,
|
|
||||||
onSegmentSelected = { selectedSegment = it },
|
|
||||||
modifier = Modifier.fillMaxWidth()
|
|
||||||
)
|
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(8.dp))
|
|
||||||
|
|
||||||
// 空状态内容(使用智能体原本的图标和文字)
|
|
||||||
Column(
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
|
||||||
horizontalAlignment = Alignment.CenterHorizontally
|
|
||||||
) {
|
|
||||||
if (isNetworkAvailable) {
|
|
||||||
Image(
|
|
||||||
painter = painterResource(
|
|
||||||
id = if(AppState.darkMode) R.mipmap.ai_dark
|
|
||||||
else R.mipmap.ai),
|
|
||||||
contentDescription = "暂无Agent",
|
|
||||||
modifier = Modifier
|
|
||||||
.size(width = 181.dp, height = 153.dp)
|
|
||||||
.align(Alignment.CenterHorizontally),
|
|
||||||
)
|
|
||||||
|
|
||||||
// 根据是否为深色模式调整间距
|
|
||||||
Spacer(modifier = Modifier.height(if(AppState.darkMode) 9.dp else 24.dp))
|
|
||||||
|
|
||||||
Text(
|
|
||||||
text = stringResource(R.string.exclusive_ai_waiting),
|
|
||||||
fontSize = 16.sp,
|
|
||||||
color = AppColors.text,
|
|
||||||
fontWeight = FontWeight.W600,
|
|
||||||
textAlign = TextAlign.Center,
|
|
||||||
modifier = Modifier.padding(horizontal = 24.dp),
|
|
||||||
maxLines = 2,
|
|
||||||
overflow = TextOverflow.Ellipsis
|
|
||||||
)
|
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(8.dp))
|
|
||||||
|
|
||||||
Text(
|
|
||||||
text = stringResource(R.string.ai_companion_not_tool),
|
|
||||||
fontSize = 14.sp,
|
|
||||||
color = AppColors.secondaryText,
|
|
||||||
fontWeight = FontWeight.W400,
|
|
||||||
textAlign = TextAlign.Center,
|
|
||||||
modifier = Modifier.padding(horizontal = 24.dp),
|
|
||||||
maxLines = 3,
|
|
||||||
overflow = TextOverflow.Ellipsis
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
Image(
|
|
||||||
painter = painterResource(id = R.mipmap.invalid_name_10),
|
|
||||||
contentDescription = "network error",
|
|
||||||
modifier = Modifier.size(181.dp),
|
|
||||||
)
|
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(24.dp))
|
|
||||||
|
|
||||||
Text(
|
|
||||||
text = stringResource(R.string.friend_chat_no_network_title),
|
|
||||||
fontSize = 16.sp,
|
|
||||||
color = AppColors.text,
|
|
||||||
fontWeight = FontWeight.W600
|
|
||||||
)
|
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(8.dp))
|
|
||||||
|
|
||||||
Text(
|
|
||||||
text = stringResource(R.string.friend_chat_no_network_subtitle),
|
|
||||||
fontSize = 14.sp,
|
|
||||||
color = AppColors.secondaryText,
|
|
||||||
fontWeight = FontWeight.W400
|
|
||||||
)
|
|
||||||
Spacer(modifier = Modifier.height(16.dp))
|
|
||||||
ReloadButton(
|
|
||||||
onClick = {
|
|
||||||
MyProfileViewModel.ResetModel()
|
|
||||||
MyProfileViewModel.loadProfile(pullRefresh = true)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
private fun AgentSegmentedControl(
|
|
||||||
selectedIndex: Int,
|
|
||||||
onSegmentSelected: (Int) -> Unit,
|
|
||||||
modifier: Modifier = Modifier
|
|
||||||
) {
|
|
||||||
val AppColors = LocalAppTheme.current
|
|
||||||
Row(
|
|
||||||
modifier = modifier
|
|
||||||
.height(32.dp),
|
|
||||||
horizontalArrangement = Arrangement.Start,
|
|
||||||
verticalAlignment = Alignment.CenterVertically
|
|
||||||
) {
|
|
||||||
// 全部
|
|
||||||
AgentSegmentButton(
|
|
||||||
text = stringResource(R.string.chat_all),
|
|
||||||
isSelected = selectedIndex == 0,
|
|
||||||
onClick = { onSegmentSelected(0) },
|
|
||||||
width = 54.dp,
|
|
||||||
appColors = AppColors
|
|
||||||
)
|
|
||||||
|
|
||||||
Spacer(modifier = Modifier.width(8.dp))
|
|
||||||
|
|
||||||
// 公开
|
|
||||||
AgentSegmentButton(
|
|
||||||
text = stringResource(R.string.public_label),
|
|
||||||
isSelected = selectedIndex == 1,
|
|
||||||
onClick = { onSegmentSelected(1) },
|
|
||||||
width = 59.dp,
|
|
||||||
appColors = AppColors
|
|
||||||
)
|
|
||||||
|
|
||||||
Spacer(modifier = Modifier.width(8.dp))
|
|
||||||
|
|
||||||
// 私有
|
|
||||||
AgentSegmentButton(
|
|
||||||
text = stringResource(R.string.private_label),
|
|
||||||
isSelected = selectedIndex == 2,
|
|
||||||
onClick = { onSegmentSelected(2) },
|
|
||||||
width = 54.dp,
|
|
||||||
appColors = AppColors
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
private fun AgentSegmentButton(
|
|
||||||
text: String,
|
|
||||||
isSelected: Boolean,
|
|
||||||
onClick: () -> Unit,
|
|
||||||
width: androidx.compose.ui.unit.Dp,
|
|
||||||
appColors: com.aiosman.ravenow.AppThemeData
|
|
||||||
) {
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.width(width)
|
|
||||||
.height(32.dp)
|
|
||||||
.background(
|
|
||||||
color = if (isSelected) {
|
|
||||||
appColors.checkedBackground // 使用选中背景色(暗色模式下是白色,亮色模式下是黑色)
|
|
||||||
} else {
|
|
||||||
Color(0x147C7480) // RGB(124, 116, 128, alpha 0.08)
|
|
||||||
},
|
|
||||||
shape = RoundedCornerShape(1000.dp)
|
|
||||||
)
|
|
||||||
.clickable(onClick = onClick),
|
|
||||||
contentAlignment = Alignment.Center
|
|
||||||
) {
|
|
||||||
Text(
|
|
||||||
text = text,
|
|
||||||
fontSize = 13.sp,
|
|
||||||
fontWeight = FontWeight.Normal,
|
|
||||||
color = if (isSelected) {
|
|
||||||
appColors.checkedText // 选中时使用选中文本颜色(暗色模式下是黑色,亮色模式下是白色)
|
|
||||||
} else {
|
|
||||||
appColors.text // 未选中时使用文本颜色
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun EmptyAgentsView() {
|
fun EmptyAgentsView() {
|
||||||
val AppColors = LocalAppTheme.current
|
val AppColors = LocalAppTheme.current
|
||||||
@@ -394,16 +212,13 @@ fun EmptyAgentsView() {
|
|||||||
if (isNetworkAvailable) {
|
if (isNetworkAvailable) {
|
||||||
Image(
|
Image(
|
||||||
painter = painterResource(
|
painter = painterResource(
|
||||||
id = if(AppState.darkMode) R.mipmap.ai_dark
|
id =if(AppState.darkMode) R.mipmap.qs_ai_qs_as_img
|
||||||
else R.mipmap.ai),
|
else R.mipmap.ai),
|
||||||
contentDescription = "暂无Agent",
|
contentDescription = "暂无Agent",
|
||||||
modifier = Modifier
|
modifier = Modifier.size(181.dp),
|
||||||
.size(width = 181.dp, height = 153.dp)
|
|
||||||
.align(Alignment.CenterHorizontally),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// 根据是否为深色模式调整间距
|
Spacer(modifier = Modifier.height(24.dp))
|
||||||
Spacer(modifier = Modifier.height(if(AppState.darkMode) 9.dp else 24.dp))
|
|
||||||
|
|
||||||
Text(
|
Text(
|
||||||
text = "专属AI等你召唤",
|
text = "专属AI等你召唤",
|
||||||
|
|||||||
@@ -65,94 +65,94 @@ fun UserAgentsRow(
|
|||||||
viewModel.loadUserAgents(userId)
|
viewModel.loadUserAgents(userId)
|
||||||
}
|
}
|
||||||
|
|
||||||
// // 总是显示智能体区域,即使没有数据也显示标题和状态
|
// 总是显示智能体区域,即使没有数据也显示标题和状态
|
||||||
// Column(
|
Column(
|
||||||
// modifier = modifier
|
modifier = modifier
|
||||||
// .fillMaxWidth()
|
.fillMaxWidth()
|
||||||
// .padding(horizontal = 16.dp)
|
.padding(horizontal = 16.dp)
|
||||||
// ) {
|
) {
|
||||||
// Text(
|
Text(
|
||||||
// text = if (isSelf) "我的智能体" else "TA的智能体",
|
text = if (isSelf) "我的智能体" else "TA的智能体",
|
||||||
// fontSize = 16.sp,
|
fontSize = 16.sp,
|
||||||
// fontWeight = FontWeight.W600,
|
fontWeight = FontWeight.W600,
|
||||||
// color = AppColors.text,
|
color = AppColors.text,
|
||||||
// modifier = Modifier.padding(bottom = 12.dp)
|
modifier = Modifier.padding(bottom = 12.dp)
|
||||||
// )
|
)
|
||||||
//
|
|
||||||
// when {
|
when {
|
||||||
// viewModel.isLoading -> {
|
viewModel.isLoading -> {
|
||||||
// // 显示加载状态
|
// 显示加载状态
|
||||||
// Box(
|
Box(
|
||||||
// modifier = Modifier
|
modifier = Modifier
|
||||||
// .fillMaxWidth()
|
.fillMaxWidth()
|
||||||
// .height(60.dp),
|
.height(60.dp),
|
||||||
// contentAlignment = Alignment.Center
|
contentAlignment = Alignment.Center
|
||||||
// ) {
|
) {
|
||||||
// Text(
|
Text(
|
||||||
// text = "加载中...",
|
text = "加载中...",
|
||||||
// fontSize = 14.sp,
|
fontSize = 14.sp,
|
||||||
// color = AppColors.text.copy(alpha = 0.6f)
|
color = AppColors.text.copy(alpha = 0.6f)
|
||||||
// )
|
)
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// viewModel.error != null -> {
|
viewModel.error != null -> {
|
||||||
// // 显示错误状态
|
// 显示错误状态
|
||||||
// Box(
|
Box(
|
||||||
// modifier = Modifier
|
modifier = Modifier
|
||||||
// .fillMaxWidth()
|
.fillMaxWidth()
|
||||||
// .height(60.dp),
|
.height(60.dp),
|
||||||
// contentAlignment = Alignment.Center
|
contentAlignment = Alignment.Center
|
||||||
// ) {
|
) {
|
||||||
// Text(
|
Text(
|
||||||
// text = "加载失败: ${viewModel.error}",
|
text = "加载失败: ${viewModel.error}",
|
||||||
// fontSize = 14.sp,
|
fontSize = 14.sp,
|
||||||
// color = AppColors.text.copy(alpha = 0.6f)
|
color = AppColors.text.copy(alpha = 0.6f)
|
||||||
// )
|
)
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// viewModel.agents.isEmpty() -> {
|
viewModel.agents.isEmpty() -> {
|
||||||
// // 显示空状态
|
// 显示空状态
|
||||||
// Box(
|
Box(
|
||||||
// modifier = Modifier
|
modifier = Modifier
|
||||||
// .fillMaxWidth()
|
.fillMaxWidth()
|
||||||
// .height(60.dp),
|
.height(60.dp),
|
||||||
// contentAlignment = Alignment.Center
|
contentAlignment = Alignment.Center
|
||||||
// ) {
|
) {
|
||||||
// Text(
|
Text(
|
||||||
// text = if (isSelf) "您还没有创建智能体" else "TA还没有创建智能体",
|
text = if (isSelf) "您还没有创建智能体" else "TA还没有创建智能体",
|
||||||
// fontSize = 14.sp,
|
fontSize = 14.sp,
|
||||||
// color = AppColors.text.copy(alpha = 0.6f)
|
color = AppColors.text.copy(alpha = 0.6f)
|
||||||
// )
|
)
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// else -> {
|
else -> {
|
||||||
// // 显示智能体列表
|
// 显示智能体列表
|
||||||
// LazyRow(
|
LazyRow(
|
||||||
// horizontalArrangement = Arrangement.spacedBy(12.dp),
|
horizontalArrangement = Arrangement.spacedBy(12.dp),
|
||||||
// modifier = Modifier.fillMaxWidth()
|
modifier = Modifier.fillMaxWidth()
|
||||||
// ) {
|
) {
|
||||||
// // 显示智能体项目
|
// 显示智能体项目
|
||||||
// items(viewModel.agents) { agent ->
|
items(viewModel.agents) { agent ->
|
||||||
// AgentItem(
|
AgentItem(
|
||||||
// agent = agent,
|
agent = agent,
|
||||||
// onClick = { onAgentClick(agent) },
|
onClick = { onAgentClick(agent) },
|
||||||
// onAvatarClick = { onAvatarClick(agent) },
|
onAvatarClick = { onAvatarClick(agent) },
|
||||||
// onLongClick = { onAgentLongClick(agent) }
|
onLongClick = { onAgentLongClick(agent) }
|
||||||
// )
|
)
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// // 添加"更多"按钮
|
// 添加"更多"按钮
|
||||||
// item {
|
item {
|
||||||
// MoreAgentItem(
|
MoreAgentItem(
|
||||||
// onClick = onMoreClick
|
onClick = onMoreClick
|
||||||
// )
|
)
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// Spacer(modifier = Modifier.height(16.dp))
|
Spacer(modifier = Modifier.height(16.dp))
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(ExperimentalFoundationApi::class)
|
@OptIn(ExperimentalFoundationApi::class)
|
||||||
|
|||||||
@@ -10,14 +10,21 @@ import androidx.compose.foundation.layout.Spacer
|
|||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.height
|
import androidx.compose.foundation.layout.height
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.layout.size
|
||||||
import androidx.compose.foundation.layout.width
|
import androidx.compose.foundation.layout.width
|
||||||
import androidx.compose.foundation.pager.PagerState
|
import androidx.compose.foundation.pager.PagerState
|
||||||
|
import androidx.compose.foundation.rememberScrollState
|
||||||
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
|
import androidx.compose.foundation.verticalScroll
|
||||||
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.rememberCoroutineScope
|
import androidx.compose.runtime.rememberCoroutineScope
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.draw.clip
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import androidx.compose.ui.res.painterResource
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
@@ -45,7 +52,7 @@ fun UserContentPageIndicator(
|
|||||||
.padding(horizontal = 16.dp),
|
.padding(horizontal = 16.dp),
|
||||||
horizontalArrangement = Arrangement.SpaceEvenly
|
horizontalArrangement = Arrangement.SpaceEvenly
|
||||||
) {
|
) {
|
||||||
// 动态 Tab
|
// 图片/相册 Tab
|
||||||
Column(
|
Column(
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
@@ -57,24 +64,15 @@ fun UserContentPageIndicator(
|
|||||||
}
|
}
|
||||||
.padding(vertical = 12.dp)
|
.padding(vertical = 12.dp)
|
||||||
) {
|
) {
|
||||||
Text(
|
Icon(
|
||||||
text = stringResource(R.string.index_dynamic),
|
painter = painterResource(id = R.drawable.rider_pro_images),
|
||||||
fontSize = 16.sp,
|
contentDescription = "Gallery",
|
||||||
fontWeight = if (pagerState.currentPage == 0) FontWeight.SemiBold else FontWeight.Medium,
|
tint = if (pagerState.currentPage == 0) AppColors.text else AppColors.text.copy(alpha = 0.6f),
|
||||||
color = if (pagerState.currentPage == 0) AppColors.text else AppColors.secondaryText
|
modifier = Modifier.size(24.dp)
|
||||||
)
|
)
|
||||||
Spacer(modifier = Modifier.height(if (pagerState.currentPage == 0) 6.dp else 4.dp))
|
|
||||||
if (pagerState.currentPage == 0) {
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.width(20.dp)
|
|
||||||
.height(2.dp)
|
|
||||||
.background(AppColors.text)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 智能体 Tab (只在非智能体用户时显示)
|
// Agent Tab (只在非智能体用户时显示)
|
||||||
if (showAgentTab) {
|
if (showAgentTab) {
|
||||||
Column(
|
Column(
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
@@ -87,53 +85,39 @@ fun UserContentPageIndicator(
|
|||||||
}
|
}
|
||||||
.padding(vertical = 12.dp)
|
.padding(vertical = 12.dp)
|
||||||
) {
|
) {
|
||||||
Text(
|
Icon(
|
||||||
text = stringResource(R.string.chat_ai),
|
painter = painterResource(id = R.drawable.rider_pro_nav_ai),
|
||||||
fontSize = 16.sp,
|
contentDescription = "Agents",
|
||||||
fontWeight = if (pagerState.currentPage == 1) FontWeight.SemiBold else FontWeight.Medium,
|
tint = if (pagerState.currentPage == 1) AppColors.text else AppColors.text.copy(alpha = 0.6f),
|
||||||
color = if (pagerState.currentPage == 1) AppColors.text else AppColors.secondaryText
|
modifier = Modifier.size(24.dp)
|
||||||
)
|
)
|
||||||
Spacer(modifier = Modifier.height(if (pagerState.currentPage == 1) 6.dp else 4.dp))
|
|
||||||
if (pagerState.currentPage == 1) {
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.width(20.dp)
|
|
||||||
.height(2.dp)
|
|
||||||
.background(AppColors.text)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 群聊 Tab (只在非智能体用户时显示)
|
// 下划线指示器
|
||||||
|
Row(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(horizontal = 16.dp)
|
||||||
|
) {
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.weight(1f)
|
||||||
|
.height(2.dp)
|
||||||
|
.background(
|
||||||
|
if (pagerState.currentPage == 0) AppColors.text else Color.Transparent
|
||||||
|
)
|
||||||
|
)
|
||||||
if (showAgentTab) {
|
if (showAgentTab) {
|
||||||
Column(
|
Box(
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.weight(1f)
|
.weight(1f)
|
||||||
.noRippleClickable {
|
.height(2.dp)
|
||||||
scope.launch {
|
.background(
|
||||||
pagerState.scrollToPage(2)
|
if (pagerState.currentPage == 1) AppColors.text else Color.Transparent
|
||||||
}
|
|
||||||
}
|
|
||||||
.padding(vertical = 12.dp)
|
|
||||||
) {
|
|
||||||
Text(
|
|
||||||
text = stringResource(R.string.chat_group),
|
|
||||||
fontSize = 16.sp,
|
|
||||||
fontWeight = if (pagerState.currentPage == 2) FontWeight.SemiBold else FontWeight.Medium,
|
|
||||||
color = if (pagerState.currentPage == 2) AppColors.text else AppColors.secondaryText
|
|
||||||
)
|
|
||||||
Spacer(modifier = Modifier.height(if (pagerState.currentPage == 2) 6.dp else 4.dp))
|
|
||||||
if (pagerState.currentPage == 2) {
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.width(20.dp)
|
|
||||||
.height(2.dp)
|
|
||||||
.background(AppColors.text)
|
|
||||||
)
|
)
|
||||||
}
|
)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,39 +1,26 @@
|
|||||||
package com.aiosman.ravenow.ui.index.tabs.profile.composable
|
package com.aiosman.ravenow.ui.index.tabs.profile.composable
|
||||||
|
|
||||||
import androidx.compose.foundation.Image
|
|
||||||
import androidx.compose.foundation.background
|
|
||||||
import androidx.compose.foundation.clickable
|
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Box
|
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.Spacer
|
import androidx.compose.foundation.layout.Spacer
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.height
|
import androidx.compose.foundation.layout.height
|
||||||
import androidx.compose.foundation.layout.offset
|
|
||||||
import androidx.compose.foundation.layout.padding
|
|
||||||
import androidx.compose.foundation.layout.size
|
import androidx.compose.foundation.layout.size
|
||||||
import androidx.compose.foundation.layout.width
|
import androidx.compose.foundation.layout.width
|
||||||
import androidx.compose.foundation.shape.CircleShape
|
import androidx.compose.foundation.shape.CircleShape
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.remember
|
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.clip
|
import androidx.compose.ui.draw.clip
|
||||||
import androidx.compose.ui.graphics.Color
|
|
||||||
import androidx.compose.ui.graphics.ColorFilter
|
|
||||||
import androidx.compose.ui.layout.ContentScale
|
import androidx.compose.ui.layout.ContentScale
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.res.painterResource
|
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.compose.ui.text.style.TextAlign
|
|
||||||
import androidx.compose.ui.text.style.TextOverflow
|
import androidx.compose.ui.text.style.TextOverflow
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
import com.aiosman.ravenow.AppStore
|
|
||||||
import com.aiosman.ravenow.LocalAppTheme
|
import com.aiosman.ravenow.LocalAppTheme
|
||||||
import com.aiosman.ravenow.LocalNavController
|
import com.aiosman.ravenow.LocalNavController
|
||||||
import com.aiosman.ravenow.R
|
import com.aiosman.ravenow.R
|
||||||
@@ -42,52 +29,23 @@ import com.aiosman.ravenow.ui.NavigationRoute
|
|||||||
import com.aiosman.ravenow.ui.composables.CustomAsyncImage
|
import com.aiosman.ravenow.ui.composables.CustomAsyncImage
|
||||||
import com.aiosman.ravenow.ui.composables.rememberDebouncer
|
import com.aiosman.ravenow.ui.composables.rememberDebouncer
|
||||||
import com.aiosman.ravenow.ui.modifiers.noRippleClickable
|
import com.aiosman.ravenow.ui.modifiers.noRippleClickable
|
||||||
import java.text.NumberFormat
|
|
||||||
import java.util.Locale
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun UserItem(
|
fun UserItem(
|
||||||
accountProfileEntity: AccountProfileEntity,
|
accountProfileEntity: AccountProfileEntity,
|
||||||
postCount: Long = 0,
|
postCount: Int = 0
|
||||||
isSelf: Boolean = false,
|
|
||||||
onEditClick: () -> Unit = {}
|
|
||||||
) {
|
) {
|
||||||
val navController = LocalNavController.current
|
val navController = LocalNavController.current
|
||||||
val AppColors = LocalAppTheme.current
|
val AppColors = LocalAppTheme.current
|
||||||
val followerDebouncer = rememberDebouncer()
|
val followerDebouncer = rememberDebouncer()
|
||||||
val followingDebouncer = rememberDebouncer()
|
val followingDebouncer = rememberDebouncer()
|
||||||
|
|
||||||
// 获取 MBTI 和星座信息
|
|
||||||
val mbti = remember(accountProfileEntity.id) {
|
|
||||||
AppStore.getUserMbti(accountProfileEntity.id)
|
|
||||||
}
|
|
||||||
val zodiac = remember(accountProfileEntity.id) {
|
|
||||||
AppStore.getUserZodiac(accountProfileEntity.id)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 格式化粉丝数
|
|
||||||
val numberFormat = remember { NumberFormat.getNumberInstance(Locale.getDefault()) }
|
|
||||||
val formattedFollowerCount = remember(accountProfileEntity.followerCount) {
|
|
||||||
if (accountProfileEntity.followerCount >= 10000) {
|
|
||||||
val wan = accountProfileEntity.followerCount / 10000.0
|
|
||||||
if (wan >= 100) {
|
|
||||||
"${wan.toInt()}万"
|
|
||||||
} else {
|
|
||||||
String.format("%.1f万", wan)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
numberFormat.format(accountProfileEntity.followerCount)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
) {
|
) {
|
||||||
// 顶部:头像和统计数据
|
|
||||||
Row(
|
Row(
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically
|
||||||
horizontalArrangement = Arrangement.spacedBy(16.dp)
|
|
||||||
) {
|
) {
|
||||||
// 头像
|
// 头像
|
||||||
CustomAsyncImage(
|
CustomAsyncImage(
|
||||||
@@ -95,47 +53,39 @@ fun UserItem(
|
|||||||
accountProfileEntity.avatar,
|
accountProfileEntity.avatar,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.clip(CircleShape)
|
.clip(CircleShape)
|
||||||
.size(96.dp),
|
.size(48.dp),
|
||||||
contentDescription = "",
|
contentDescription = "",
|
||||||
contentScale = ContentScale.Crop
|
contentScale = ContentScale.Crop
|
||||||
)
|
)
|
||||||
|
Spacer(modifier = Modifier.width(32.dp))
|
||||||
// 统计数据
|
//个人统计
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier.weight(1f),
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
horizontalArrangement = Arrangement.spacedBy(0.dp),
|
modifier = Modifier.weight(1f)
|
||||||
verticalAlignment = Alignment.CenterVertically
|
|
||||||
) {
|
) {
|
||||||
// 帖子数
|
// 帖子数
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier
|
|
||||||
.width(80.dp)
|
|
||||||
.height(40.dp),
|
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
verticalArrangement = Arrangement.Center
|
modifier = Modifier.weight(1f)
|
||||||
) {
|
) {
|
||||||
Text(
|
Text(
|
||||||
text = postCount.toString(),
|
text = postCount.toString(),
|
||||||
fontWeight = FontWeight.Medium,
|
fontWeight = FontWeight.W600,
|
||||||
fontSize = 15.sp,
|
fontSize = 16.sp,
|
||||||
color = AppColors.text,
|
color = AppColors.text
|
||||||
textAlign = TextAlign.Center
|
|
||||||
)
|
)
|
||||||
Spacer(modifier = Modifier.height(2.dp))
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
Text(
|
Text(
|
||||||
text = stringResource(R.string.posts),
|
text = "帖子",
|
||||||
fontWeight = FontWeight.Normal,
|
color = AppColors.text
|
||||||
fontSize = 11.sp,
|
|
||||||
color = AppColors.text,
|
|
||||||
textAlign = TextAlign.Center
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 粉丝数
|
// 粉丝数
|
||||||
Column(
|
Column(
|
||||||
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.width(80.dp)
|
.weight(1f)
|
||||||
.height(40.dp)
|
|
||||||
.noRippleClickable {
|
.noRippleClickable {
|
||||||
followerDebouncer {
|
followerDebouncer {
|
||||||
navController.navigate(
|
navController.navigate(
|
||||||
@@ -145,33 +95,26 @@ fun UserItem(
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
|
||||||
verticalArrangement = Arrangement.Center
|
|
||||||
) {
|
) {
|
||||||
Text(
|
Text(
|
||||||
text = formattedFollowerCount,
|
text = accountProfileEntity.followerCount.toString(),
|
||||||
fontWeight = FontWeight.Medium,
|
fontWeight = FontWeight.W600,
|
||||||
fontSize = 15.sp,
|
fontSize = 16.sp,
|
||||||
color = AppColors.text,
|
color = AppColors.text
|
||||||
textAlign = TextAlign.Center
|
|
||||||
)
|
)
|
||||||
Spacer(modifier = Modifier.height(2.dp))
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
Text(
|
Text(
|
||||||
text = stringResource(R.string.followers_upper),
|
text = "粉丝",
|
||||||
fontWeight = FontWeight.Normal,
|
color = AppColors.text
|
||||||
fontSize = 11.sp,
|
|
||||||
color = AppColors.text,
|
|
||||||
textAlign = TextAlign.Center
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 关注数
|
// 关注数
|
||||||
Column(
|
Column(
|
||||||
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.width(80.dp)
|
.weight(1f)
|
||||||
.height(40.dp)
|
|
||||||
.offset(x = 6.dp)
|
|
||||||
.noRippleClickable {
|
.noRippleClickable {
|
||||||
followingDebouncer {
|
followingDebouncer {
|
||||||
navController.navigate(
|
navController.navigate(
|
||||||
@@ -181,161 +124,49 @@ fun UserItem(
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
|
||||||
verticalArrangement = Arrangement.Center
|
|
||||||
) {
|
) {
|
||||||
Text(
|
Text(
|
||||||
text = accountProfileEntity.followingCount.toString(),
|
text = accountProfileEntity.followingCount.toString(),
|
||||||
fontWeight = FontWeight.Medium,
|
fontWeight = FontWeight.W600,
|
||||||
fontSize = 15.sp,
|
fontSize = 16.sp,
|
||||||
color = AppColors.text,
|
color = AppColors.text
|
||||||
textAlign = TextAlign.Center
|
|
||||||
)
|
)
|
||||||
Spacer(modifier = Modifier.height(2.dp))
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
Text(
|
Text(
|
||||||
text = stringResource(R.string.following_upper),
|
text = "关注",
|
||||||
fontWeight = FontWeight.Normal,
|
color = AppColors.text
|
||||||
fontSize = 11.sp,
|
|
||||||
color = AppColors.text,
|
|
||||||
textAlign = TextAlign.Center
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(12.dp))
|
Spacer(modifier = Modifier.height(12.dp))
|
||||||
|
// 昵称
|
||||||
// 中间:昵称、简介、创建者信息
|
Text(
|
||||||
Column(
|
text = accountProfileEntity.nickName,
|
||||||
modifier = Modifier
|
fontWeight = FontWeight.W600,
|
||||||
.fillMaxWidth()
|
fontSize = 16.sp,
|
||||||
) {
|
color = AppColors.text
|
||||||
// 昵称
|
)
|
||||||
|
Spacer(modifier = Modifier.height(4.dp))
|
||||||
|
// 个人简介
|
||||||
|
if (accountProfileEntity.bio.isNotEmpty()){
|
||||||
Text(
|
Text(
|
||||||
text = accountProfileEntity.nickName,
|
text = accountProfileEntity.bio,
|
||||||
fontWeight = FontWeight.Bold,
|
fontSize = 14.sp,
|
||||||
fontSize = 22.sp,
|
color = AppColors.secondaryText,
|
||||||
letterSpacing = (-0.3).sp,
|
maxLines = 1,
|
||||||
color = AppColors.text
|
overflow = TextOverflow.Ellipsis
|
||||||
)
|
)
|
||||||
|
}else{
|
||||||
Spacer(modifier = Modifier.height(4.dp))
|
|
||||||
|
|
||||||
// 个人简介
|
|
||||||
if (accountProfileEntity.bio.isNotEmpty()) {
|
|
||||||
Text(
|
|
||||||
text = accountProfileEntity.bio,
|
|
||||||
fontSize = 13.sp,
|
|
||||||
color = AppColors.secondaryText,
|
|
||||||
maxLines = 2,
|
|
||||||
overflow = TextOverflow.Ellipsis
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
Text(
|
|
||||||
text = "Welcome to my fantiac word i will show you something about magic",
|
|
||||||
fontSize = 13.sp,
|
|
||||||
color = AppColors.secondaryText,
|
|
||||||
maxLines = 2,
|
|
||||||
overflow = TextOverflow.Ellipsis
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 创建者信息(如果是 AI 账户,可以显示创建者)
|
|
||||||
// 注意:当前 AccountProfileEntity 没有创建者字段,这里暂时留空
|
|
||||||
// 如果需要显示,需要从其他地方获取创建者信息
|
|
||||||
}
|
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(12.dp))
|
|
||||||
|
|
||||||
// 底部:标签按钮
|
|
||||||
Row(
|
|
||||||
horizontalArrangement = Arrangement.spacedBy(4.dp),
|
|
||||||
verticalAlignment = Alignment.CenterVertically
|
|
||||||
) {
|
|
||||||
// MBTI 标签
|
|
||||||
if (!mbti.isNullOrEmpty()) {
|
|
||||||
ProfileTag(
|
|
||||||
text = mbti,
|
|
||||||
backgroundColor = Color(0x33FF8D28), // 255/255, 141/255, 40/255, alpha 0.2
|
|
||||||
textColor = AppColors.text
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 星座标签
|
|
||||||
if (!zodiac.isNullOrEmpty()) {
|
|
||||||
ProfileTag(
|
|
||||||
text = zodiac,
|
|
||||||
backgroundColor = Color(0x33FFCC00), // 255/255, 204/255, 0/255, alpha 0.2
|
|
||||||
textColor = AppColors.text
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 编辑标签(仅自己可见)
|
|
||||||
if (isSelf) {
|
|
||||||
ProfileTag(
|
|
||||||
text = stringResource(R.string.edit_profile),
|
|
||||||
backgroundColor = Color(0x14947A80), // 124/255, 116/255, 128/255, alpha 0.08
|
|
||||||
textColor = AppColors.text,
|
|
||||||
leadingIcon = {
|
|
||||||
EditIcon(
|
|
||||||
color = AppColors.text,
|
|
||||||
modifier = Modifier.size(16.dp)
|
|
||||||
)
|
|
||||||
},
|
|
||||||
onClick = onEditClick
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
private fun ProfileTag(
|
|
||||||
text: String,
|
|
||||||
backgroundColor: Color,
|
|
||||||
textColor: Color,
|
|
||||||
leadingIcon: (@Composable () -> Unit)? = null,
|
|
||||||
onClick: (() -> Unit)? = null
|
|
||||||
) {
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.height(25.dp)
|
|
||||||
.clip(RoundedCornerShape(12.dp))
|
|
||||||
.background(backgroundColor)
|
|
||||||
.then(
|
|
||||||
if (onClick != null) {
|
|
||||||
Modifier.clickable(onClick = onClick)
|
|
||||||
} else {
|
|
||||||
Modifier
|
|
||||||
}
|
|
||||||
)
|
|
||||||
.padding(horizontal = 8.dp, vertical = 4.dp),
|
|
||||||
contentAlignment = Alignment.Center
|
|
||||||
) {
|
|
||||||
Row(
|
|
||||||
horizontalArrangement = Arrangement.spacedBy(4.dp),
|
|
||||||
verticalAlignment = Alignment.CenterVertically
|
|
||||||
) {
|
|
||||||
leadingIcon?.invoke()
|
|
||||||
Text(
|
Text(
|
||||||
text = text,
|
text = "No bio here.",
|
||||||
fontSize = 12.sp,
|
fontSize = 14.sp,
|
||||||
color = textColor
|
color = AppColors.secondaryText,
|
||||||
|
maxLines = 1,
|
||||||
|
overflow = TextOverflow.Ellipsis
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
private fun EditIcon(
|
|
||||||
color: Color,
|
|
||||||
modifier: Modifier = Modifier
|
|
||||||
) {
|
|
||||||
Image(
|
|
||||||
painter = painterResource(id = R.mipmap.bi),
|
|
||||||
contentDescription = stringResource(R.string.edit_profile),
|
|
||||||
modifier = modifier,
|
|
||||||
colorFilter = ColorFilter.tint(color)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ import androidx.compose.foundation.layout.fillMaxWidth
|
|||||||
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.shape.RoundedCornerShape
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
import androidx.compose.ui.graphics.RectangleShape
|
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.filled.PlayArrow
|
import androidx.compose.material.icons.filled.PlayArrow
|
||||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
@@ -62,65 +61,27 @@ import androidx.media3.common.util.UnstableApi
|
|||||||
import androidx.media3.common.util.Util
|
import androidx.media3.common.util.Util
|
||||||
import androidx.media3.datasource.DataSource
|
import androidx.media3.datasource.DataSource
|
||||||
import androidx.media3.datasource.DefaultDataSourceFactory
|
import androidx.media3.datasource.DefaultDataSourceFactory
|
||||||
import androidx.media3.datasource.DefaultHttpDataSource
|
|
||||||
import androidx.media3.exoplayer.ExoPlayer
|
import androidx.media3.exoplayer.ExoPlayer
|
||||||
import androidx.media3.exoplayer.source.ProgressiveMediaSource
|
import androidx.media3.exoplayer.source.ProgressiveMediaSource
|
||||||
import androidx.media3.ui.AspectRatioFrameLayout
|
import androidx.media3.ui.AspectRatioFrameLayout
|
||||||
import androidx.media3.ui.PlayerView
|
import androidx.media3.ui.PlayerView
|
||||||
import com.aiosman.ravenow.R
|
import com.aiosman.ravenow.R
|
||||||
import com.aiosman.ravenow.entity.MomentEntity
|
|
||||||
import com.aiosman.ravenow.ui.comment.CommentModalContent
|
import com.aiosman.ravenow.ui.comment.CommentModalContent
|
||||||
import com.aiosman.ravenow.ui.composables.CustomAsyncImage
|
|
||||||
import com.aiosman.ravenow.ui.modifiers.noRippleClickable
|
import com.aiosman.ravenow.ui.modifiers.noRippleClickable
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ShortViewCompose(
|
fun ShortViewCompose(
|
||||||
videoItemsUrl: List<String> = emptyList(),
|
videoItemsUrl: List<String>,
|
||||||
videoMoments: List<MomentEntity> = emptyList(),
|
|
||||||
clickItemPosition: Int = 0,
|
clickItemPosition: Int = 0,
|
||||||
videoHeader: @Composable () -> Unit = {},
|
videoHeader: @Composable () -> Unit = {},
|
||||||
videoBottom: @Composable ((MomentEntity) -> Unit)? = null,
|
videoBottom: @Composable () -> Unit = {}
|
||||||
onLikeClick: ((MomentEntity) -> Unit)? = null,
|
|
||||||
onCommentClick: ((MomentEntity) -> Unit)? = null,
|
|
||||||
onFavoriteClick: ((MomentEntity) -> Unit)? = null,
|
|
||||||
onShareClick: ((MomentEntity) -> Unit)? = null,
|
|
||||||
onPageChanged: ((Int) -> Unit)? = null
|
|
||||||
) {
|
) {
|
||||||
// 优先使用 videoMoments,如果没有则使用 videoItemsUrl
|
val pagerState: PagerState = run {
|
||||||
val items = if (videoMoments.isNotEmpty()) {
|
remember {
|
||||||
videoMoments.mapNotNull { moment ->
|
PagerState(clickItemPosition, 0, videoItemsUrl.size - 1)
|
||||||
// MomentVideoEntity 的 url 已经在 toMomentItem() 中添加了 BASE_SERVER 前缀
|
|
||||||
moment.videos?.firstOrNull()?.url
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
videoItemsUrl
|
|
||||||
}
|
|
||||||
|
|
||||||
// 如果视频列表为空,显示空状态
|
|
||||||
if (items.isEmpty()) {
|
|
||||||
Box(
|
|
||||||
modifier = Modifier.fillMaxSize(),
|
|
||||||
contentAlignment = Alignment.Center
|
|
||||||
) {
|
|
||||||
Text(
|
|
||||||
text = "暂无视频",
|
|
||||||
color = Color.White,
|
|
||||||
fontSize = 16.sp
|
|
||||||
)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 确保 items 不为空后再创建 PagerState
|
|
||||||
val pagerState: PagerState = remember(items.size) {
|
|
||||||
val maxPage = maxOf(0, items.size - 1)
|
|
||||||
PagerState(
|
|
||||||
currentPage = clickItemPosition.coerceIn(0, maxPage),
|
|
||||||
minPage = 0,
|
|
||||||
maxPage = maxPage
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
val initialLayout = remember {
|
val initialLayout = remember {
|
||||||
mutableStateOf(true)
|
mutableStateOf(true)
|
||||||
@@ -128,39 +89,20 @@ fun ShortViewCompose(
|
|||||||
val pauseIconVisibleState = remember {
|
val pauseIconVisibleState = remember {
|
||||||
mutableStateOf(false)
|
mutableStateOf(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
Pager(
|
Pager(
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxSize()
|
|
||||||
.clip(RectangleShape),
|
|
||||||
state = pagerState,
|
state = pagerState,
|
||||||
orientation = Orientation.Vertical,
|
orientation = Orientation.Vertical,
|
||||||
offscreenLimit = 1
|
offscreenLimit = 1
|
||||||
) {
|
) {
|
||||||
pauseIconVisibleState.value = false
|
pauseIconVisibleState.value = false
|
||||||
val currentMoment = if (videoMoments.isNotEmpty() && page < videoMoments.size) {
|
|
||||||
videoMoments[page]
|
|
||||||
} else {
|
|
||||||
null
|
|
||||||
}
|
|
||||||
|
|
||||||
// 同步页码到外部(用于返回时恢复进度)
|
|
||||||
LaunchedEffect(pagerState.currentPage) {
|
|
||||||
onPageChanged?.invoke(pagerState.currentPage)
|
|
||||||
}
|
|
||||||
SingleVideoItemContent(
|
SingleVideoItemContent(
|
||||||
videoUrl = items[page],
|
videoItemsUrl[page],
|
||||||
moment = currentMoment,
|
pagerState,
|
||||||
pagerState = pagerState,
|
page,
|
||||||
pager = page,
|
initialLayout,
|
||||||
initialLayout = initialLayout,
|
pauseIconVisibleState,
|
||||||
pauseIconVisibleState = pauseIconVisibleState,
|
videoHeader,
|
||||||
VideoHeader = videoHeader,
|
videoBottom
|
||||||
VideoBottom = videoBottom,
|
|
||||||
onLikeClick = onLikeClick,
|
|
||||||
onCommentClick = onCommentClick,
|
|
||||||
onFavoriteClick = onFavoriteClick,
|
|
||||||
onShareClick = onShareClick
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -174,39 +116,18 @@ fun ShortViewCompose(
|
|||||||
@Composable
|
@Composable
|
||||||
private fun SingleVideoItemContent(
|
private fun SingleVideoItemContent(
|
||||||
videoUrl: String,
|
videoUrl: String,
|
||||||
moment: MomentEntity?,
|
|
||||||
pagerState: PagerState,
|
pagerState: PagerState,
|
||||||
pager: Int,
|
pager: Int,
|
||||||
initialLayout: MutableState<Boolean>,
|
initialLayout: MutableState<Boolean>,
|
||||||
pauseIconVisibleState: MutableState<Boolean>,
|
pauseIconVisibleState: MutableState<Boolean>,
|
||||||
VideoHeader: @Composable() () -> Unit = {},
|
VideoHeader: @Composable() () -> Unit,
|
||||||
VideoBottom: @Composable ((MomentEntity) -> Unit)? = null,
|
VideoBottom: @Composable() () -> Unit,
|
||||||
onLikeClick: ((MomentEntity) -> Unit)? = null,
|
|
||||||
onCommentClick: ((MomentEntity) -> Unit)? = null,
|
|
||||||
onFavoriteClick: ((MomentEntity) -> Unit)? = null,
|
|
||||||
onShareClick: ((MomentEntity) -> Unit)? = null
|
|
||||||
) {
|
) {
|
||||||
Box(
|
Box(modifier = Modifier.fillMaxSize()) {
|
||||||
modifier = Modifier
|
VideoPlayer(videoUrl, pagerState, pager, pauseIconVisibleState)
|
||||||
.fillMaxSize()
|
|
||||||
.clip(RectangleShape) // 确保内容不会溢出到box外
|
|
||||||
) {
|
|
||||||
VideoPlayer(
|
|
||||||
videoUrl = videoUrl,
|
|
||||||
moment = moment,
|
|
||||||
pagerState = pagerState,
|
|
||||||
pager = pager,
|
|
||||||
pauseIconVisibleState = pauseIconVisibleState,
|
|
||||||
onLikeClick = onLikeClick,
|
|
||||||
onCommentClick = onCommentClick,
|
|
||||||
onFavoriteClick = onFavoriteClick,
|
|
||||||
onShareClick = onShareClick
|
|
||||||
)
|
|
||||||
VideoHeader.invoke()
|
VideoHeader.invoke()
|
||||||
if (moment != null && VideoBottom != null) {
|
Box(modifier = Modifier.align(Alignment.BottomStart)) {
|
||||||
Box(modifier = Modifier.align(Alignment.BottomStart)) {
|
VideoBottom.invoke()
|
||||||
VideoBottom.invoke(moment)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (initialLayout.value) {
|
if (initialLayout.value) {
|
||||||
Box(
|
Box(
|
||||||
@@ -222,14 +143,9 @@ private fun SingleVideoItemContent(
|
|||||||
@Composable
|
@Composable
|
||||||
fun VideoPlayer(
|
fun VideoPlayer(
|
||||||
videoUrl: String,
|
videoUrl: String,
|
||||||
moment: MomentEntity?,
|
|
||||||
pagerState: PagerState,
|
pagerState: PagerState,
|
||||||
pager: Int,
|
pager: Int,
|
||||||
pauseIconVisibleState: MutableState<Boolean>,
|
pauseIconVisibleState: MutableState<Boolean>,
|
||||||
onLikeClick: ((MomentEntity) -> Unit)? = null,
|
|
||||||
onCommentClick: ((MomentEntity) -> Unit)? = null,
|
|
||||||
onFavoriteClick: ((MomentEntity) -> Unit)? = null,
|
|
||||||
onShareClick: ((MomentEntity) -> Unit)? = null,
|
|
||||||
) {
|
) {
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
val scope = rememberCoroutineScope()
|
val scope = rememberCoroutineScope()
|
||||||
@@ -242,20 +158,9 @@ fun VideoPlayer(
|
|||||||
ExoPlayer.Builder(context)
|
ExoPlayer.Builder(context)
|
||||||
.build()
|
.build()
|
||||||
.apply {
|
.apply {
|
||||||
// 创建带有认证头的 HttpDataSource.Factory
|
|
||||||
val httpDataSourceFactory = DefaultHttpDataSource.Factory()
|
|
||||||
.setUserAgent(Util.getUserAgent(context, context.packageName))
|
|
||||||
.setDefaultRequestProperties(
|
|
||||||
mapOf(
|
|
||||||
"Authorization" to "Bearer ${com.aiosman.ravenow.AppStore.token ?: ""}",
|
|
||||||
"DEVICE-OS" to "Android"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
// 创建 DataSource.Factory,使用自定义的 HttpDataSource.Factory
|
|
||||||
val dataSourceFactory: DataSource.Factory = DefaultDataSourceFactory(
|
val dataSourceFactory: DataSource.Factory = DefaultDataSourceFactory(
|
||||||
context,
|
context,
|
||||||
httpDataSourceFactory
|
Util.getUserAgent(context, context.packageName)
|
||||||
)
|
)
|
||||||
val source = ProgressiveMediaSource.Factory(dataSourceFactory)
|
val source = ProgressiveMediaSource.Factory(dataSourceFactory)
|
||||||
.createMediaSource(MediaItem.fromUri(Uri.parse(videoUrl)))
|
.createMediaSource(MediaItem.fromUri(Uri.parse(videoUrl)))
|
||||||
@@ -370,107 +275,70 @@ fun VideoPlayer(
|
|||||||
modifier = Modifier.padding(bottom = 72.dp, end = 12.dp),
|
modifier = Modifier.padding(bottom = 72.dp, end = 12.dp),
|
||||||
horizontalAlignment = Alignment.CenterHorizontally
|
horizontalAlignment = Alignment.CenterHorizontally
|
||||||
) {
|
) {
|
||||||
if (moment != null) {
|
UserAvatar()
|
||||||
UserAvatar(avatarUrl = moment.avatar)
|
VideoBtn(icon = R.drawable.rider_pro_video_like, text = "975.9k")
|
||||||
VideoBtn(
|
VideoBtn(icon = R.drawable.rider_pro_video_comment, text = "1896") {
|
||||||
icon = R.drawable.rider_pro_video_like,
|
showCommentModal = true
|
||||||
text = formatCount(moment.likeCount)
|
|
||||||
) {
|
|
||||||
moment?.let { onLikeClick?.invoke(it) }
|
|
||||||
}
|
|
||||||
VideoBtn(
|
|
||||||
icon = R.drawable.rider_pro_video_comment,
|
|
||||||
text = formatCount(moment.commentCount)
|
|
||||||
) {
|
|
||||||
moment?.let {
|
|
||||||
showCommentModal = true
|
|
||||||
onCommentClick?.invoke(it)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
VideoBtn(
|
|
||||||
icon = R.drawable.rider_pro_video_favor,
|
|
||||||
text = formatCount(moment.favoriteCount)
|
|
||||||
) {
|
|
||||||
moment?.let { onFavoriteClick?.invoke(it) }
|
|
||||||
}
|
|
||||||
VideoBtn(
|
|
||||||
icon = R.drawable.rider_pro_video_share,
|
|
||||||
text = formatCount(moment.shareCount)
|
|
||||||
) {
|
|
||||||
moment?.let { onShareClick?.invoke(it) }
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
UserAvatar()
|
|
||||||
VideoBtn(icon = R.drawable.rider_pro_video_like, text = "0")
|
|
||||||
VideoBtn(icon = R.drawable.rider_pro_video_comment, text = "0") {
|
|
||||||
showCommentModal = true
|
|
||||||
}
|
|
||||||
VideoBtn(icon = R.drawable.rider_pro_video_favor, text = "0")
|
|
||||||
VideoBtn(icon = R.drawable.rider_pro_video_share, text = "0")
|
|
||||||
}
|
}
|
||||||
|
VideoBtn(icon = R.drawable.rider_pro_video_favor, text = "234")
|
||||||
|
VideoBtn(icon = R.drawable.rider_pro_video_share, text = "677k")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// info
|
// info
|
||||||
if (moment != null) {
|
Box(
|
||||||
Box(
|
modifier = Modifier.fillMaxSize(),
|
||||||
modifier = Modifier.fillMaxSize(),
|
contentAlignment = Alignment.BottomStart
|
||||||
contentAlignment = Alignment.BottomStart
|
) {
|
||||||
) {
|
Column(modifier = Modifier.padding(start = 16.dp, bottom = 16.dp)) {
|
||||||
Column(modifier = Modifier.padding(start = 16.dp, bottom = 16.dp)) {
|
Row(
|
||||||
if (moment.location.isNotEmpty() && moment.location != "Worldwide") {
|
modifier = Modifier
|
||||||
Row(
|
.padding(bottom = 8.dp)
|
||||||
modifier = Modifier
|
.background(color = Color.Gray),
|
||||||
.padding(bottom = 8.dp)
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
.background(color = Color.Gray),
|
horizontalArrangement = Arrangement.Start,
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
) {
|
||||||
horizontalArrangement = Arrangement.Start,
|
Image(
|
||||||
) {
|
modifier = Modifier
|
||||||
Image(
|
.size(20.dp)
|
||||||
modifier = Modifier
|
.padding(start = 4.dp, end = 6.dp),
|
||||||
.size(20.dp)
|
painter = painterResource(id = R.drawable.rider_pro_video_location),
|
||||||
.padding(start = 4.dp, end = 6.dp),
|
contentDescription = ""
|
||||||
painter = painterResource(id = R.drawable.rider_pro_video_location),
|
)
|
||||||
contentDescription = ""
|
|
||||||
)
|
|
||||||
Text(
|
|
||||||
modifier = Modifier.padding(end = 4.dp),
|
|
||||||
text = moment.location,
|
|
||||||
fontSize = 12.sp,
|
|
||||||
color = Color.White,
|
|
||||||
style = TextStyle(fontWeight = FontWeight.Bold)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Text(
|
Text(
|
||||||
text = "@${moment.nickname}",
|
modifier = Modifier.padding(end = 4.dp),
|
||||||
fontSize = 16.sp,
|
text = "USA",
|
||||||
|
fontSize = 12.sp,
|
||||||
color = Color.White,
|
color = Color.White,
|
||||||
style = TextStyle(fontWeight = FontWeight.Bold)
|
style = TextStyle(fontWeight = FontWeight.Bold)
|
||||||
)
|
)
|
||||||
if (moment.momentTextContent.isNotEmpty()) {
|
|
||||||
Text(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(top = 4.dp),
|
|
||||||
text = moment.momentTextContent,
|
|
||||||
fontSize = 16.sp,
|
|
||||||
color = Color.White,
|
|
||||||
style = TextStyle(fontWeight = FontWeight.Bold),
|
|
||||||
overflow = TextOverflow.Ellipsis,
|
|
||||||
maxLines = 2
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Text(
|
||||||
|
text = "@Kevinlinpr",
|
||||||
|
fontSize = 16.sp,
|
||||||
|
color = Color.White,
|
||||||
|
style = TextStyle(fontWeight = FontWeight.Bold)
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(top = 4.dp), // 确保Text占用可用宽度
|
||||||
|
text = "Pedro Acosta to join KTM in 2025 on a multi-year deal! \uD83D\uDFE0",
|
||||||
|
fontSize = 16.sp,
|
||||||
|
color = Color.White,
|
||||||
|
style = TextStyle(fontWeight = FontWeight.Bold),
|
||||||
|
overflow = TextOverflow.Ellipsis, // 超出范围时显示省略号
|
||||||
|
maxLines = 2 // 最多显示两行
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (showCommentModal && moment != null) {
|
if (showCommentModal) {
|
||||||
ModalBottomSheet(
|
ModalBottomSheet(
|
||||||
onDismissRequest = { showCommentModal = false },
|
onDismissRequest = { showCommentModal = false },
|
||||||
containerColor = Color.White,
|
containerColor = Color.White,
|
||||||
sheetState = sheetState
|
sheetState = sheetState
|
||||||
) {
|
) {
|
||||||
CommentModalContent(postId = moment.id) {
|
CommentModalContent() {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -478,37 +346,16 @@ fun VideoPlayer(
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun UserAvatar(avatarUrl: String? = null) {
|
fun UserAvatar() {
|
||||||
Box(
|
Image(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.padding(bottom = 16.dp)
|
.padding(bottom = 16.dp)
|
||||||
.size(40.dp)
|
.size(40.dp)
|
||||||
.border(width = 3.dp, color = Color.White, shape = RoundedCornerShape(40.dp))
|
.border(width = 3.dp, color = Color.White, shape = RoundedCornerShape(40.dp))
|
||||||
.clip(RoundedCornerShape(40.dp))
|
.clip(
|
||||||
) {
|
RoundedCornerShape(40.dp)
|
||||||
if (avatarUrl != null && avatarUrl.isNotEmpty()) {
|
), painter = painterResource(id = R.drawable.default_avatar), contentDescription = ""
|
||||||
CustomAsyncImage(
|
)
|
||||||
imageUrl = avatarUrl,
|
|
||||||
contentDescription = "用户头像",
|
|
||||||
modifier = Modifier.fillMaxSize(),
|
|
||||||
defaultRes = R.drawable.default_avatar
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
Image(
|
|
||||||
painter = painterResource(id = R.drawable.default_avatar),
|
|
||||||
contentDescription = "用户头像"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 格式化数字显示
|
|
||||||
private fun formatCount(count: Int): String {
|
|
||||||
return when {
|
|
||||||
count >= 1_000_000 -> String.format("%.1fM", count / 1_000_000.0)
|
|
||||||
count >= 1_000 -> String.format("%.1fK", count / 1_000.0)
|
|
||||||
else -> count.toString()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
|
|||||||
@@ -123,15 +123,14 @@ fun LikeNoticeScreen() {
|
|||||||
) {
|
) {
|
||||||
Image(
|
Image(
|
||||||
painter = painterResource(
|
painter = painterResource(
|
||||||
id = if(AppState.darkMode) R.mipmap.sanqiu_dark
|
id =if(AppState.darkMode) R.mipmap.qst_z_qs_as_img
|
||||||
else R.mipmap.invalid_name_6),
|
else R.mipmap.invalid_name_6),
|
||||||
contentDescription = "No Notice",
|
contentDescription = "No Notice",
|
||||||
modifier = Modifier
|
modifier = Modifier.size(181.dp)
|
||||||
.size(width = 181.dp, height = 153.dp)
|
|
||||||
)
|
)
|
||||||
Spacer(modifier = Modifier.height(if (AppState.darkMode) 9.dp else 24.dp))
|
Spacer(modifier = Modifier.height(24.dp))
|
||||||
Text(
|
Text(
|
||||||
text = "你的赞在赶来的路上",
|
text = "你的赞在路上~",
|
||||||
color = AppColors.text,
|
color = AppColors.text,
|
||||||
fontSize = 16.sp,
|
fontSize = 16.sp,
|
||||||
fontWeight = FontWeight.W600,
|
fontWeight = FontWeight.W600,
|
||||||
|
|||||||
@@ -1,19 +1,15 @@
|
|||||||
package com.aiosman.ravenow.ui.login
|
package com.aiosman.ravenow.ui.login
|
||||||
|
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.compose.foundation.Image
|
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.Row
|
|
||||||
import androidx.compose.foundation.layout.Spacer
|
import androidx.compose.foundation.layout.Spacer
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.height
|
import androidx.compose.foundation.layout.height
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.layout.size
|
|
||||||
import androidx.compose.foundation.layout.width
|
import androidx.compose.foundation.layout.width
|
||||||
import androidx.compose.material3.Text
|
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
@@ -23,13 +19,9 @@ import androidx.compose.runtime.setValue
|
|||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.graphics.ColorFilter
|
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.res.painterResource
|
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.sp
|
|
||||||
import com.aiosman.ravenow.AppState
|
import com.aiosman.ravenow.AppState
|
||||||
import com.aiosman.ravenow.AppStore
|
import com.aiosman.ravenow.AppStore
|
||||||
import com.aiosman.ravenow.LocalAppTheme
|
import com.aiosman.ravenow.LocalAppTheme
|
||||||
@@ -41,28 +33,25 @@ import com.aiosman.ravenow.data.ServiceException
|
|||||||
import com.aiosman.ravenow.data.AccountServiceImpl
|
import com.aiosman.ravenow.data.AccountServiceImpl
|
||||||
import com.aiosman.ravenow.data.api.getErrorMessageCode
|
import com.aiosman.ravenow.data.api.getErrorMessageCode
|
||||||
import com.aiosman.ravenow.ui.NavigationRoute
|
import com.aiosman.ravenow.ui.NavigationRoute
|
||||||
|
import com.aiosman.ravenow.ui.comment.NoticeScreenHeader
|
||||||
import com.aiosman.ravenow.ui.composables.ActionButton
|
import com.aiosman.ravenow.ui.composables.ActionButton
|
||||||
import com.aiosman.ravenow.ui.composables.CheckboxWithLabel
|
import com.aiosman.ravenow.ui.composables.CheckboxWithLabel
|
||||||
import com.aiosman.ravenow.ui.composables.PolicyCheckbox
|
import com.aiosman.ravenow.ui.composables.PolicyCheckbox
|
||||||
import com.aiosman.ravenow.ui.composables.StatusBarSpacer
|
import com.aiosman.ravenow.ui.composables.StatusBarSpacer
|
||||||
import com.aiosman.ravenow.ui.composables.TextInputField
|
import com.aiosman.ravenow.ui.composables.TextInputField
|
||||||
import com.aiosman.ravenow.ui.modifiers.noRippleClickable
|
|
||||||
import com.aiosman.ravenow.utils.PasswordValidator
|
import com.aiosman.ravenow.utils.PasswordValidator
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
private val LightGrayBackground = Color(red = 250f / 255f, green = 249f / 255f, blue = 251f / 255f)
|
|
||||||
private val IconGray = Color(red = 151f / 255f, green = 148f / 255f, blue = 153f / 255f)
|
|
||||||
private val PurpleButton = Color(0xFF7C45ED)
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun EmailSignupScreen() {
|
fun EmailSignupScreen() {
|
||||||
val appColor = LocalAppTheme.current
|
var appColor = LocalAppTheme.current
|
||||||
var email by remember { mutableStateOf("") }
|
var email by remember { mutableStateOf("") }
|
||||||
var password by remember { mutableStateOf("") }
|
var password by remember { mutableStateOf("") }
|
||||||
var confirmPassword by remember { mutableStateOf("") }
|
var confirmPassword by remember { mutableStateOf("") }
|
||||||
var rememberMe by remember { mutableStateOf(false) }
|
var rememberMe by remember { mutableStateOf(false) }
|
||||||
var acceptTerms by remember { mutableStateOf(false) }
|
var acceptTerms by remember { mutableStateOf(false) }
|
||||||
|
var acceptPromotions by remember { mutableStateOf(false) }
|
||||||
val scope = rememberCoroutineScope()
|
val scope = rememberCoroutineScope()
|
||||||
val navController = LocalNavController.current
|
val navController = LocalNavController.current
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
@@ -71,13 +60,14 @@ fun EmailSignupScreen() {
|
|||||||
var passwordError by remember { mutableStateOf<String?>(null) }
|
var passwordError by remember { mutableStateOf<String?>(null) }
|
||||||
var confirmPasswordError by remember { mutableStateOf<String?>(null) }
|
var confirmPasswordError by remember { mutableStateOf<String?>(null) }
|
||||||
var termsError by remember { mutableStateOf<Boolean>(false) }
|
var termsError by remember { mutableStateOf<Boolean>(false) }
|
||||||
|
var promotionsError by remember { mutableStateOf<Boolean>(false) }
|
||||||
fun validateForm(): Boolean {
|
fun validateForm(): Boolean {
|
||||||
emailError = when {
|
emailError = when {
|
||||||
// 非空
|
// 非空
|
||||||
email.isEmpty() -> context.getString(R.string.text_error_email_required)
|
email.isEmpty() -> context.getString(R.string.text_error_email_required)
|
||||||
// 邮箱格式
|
// 邮箱格式
|
||||||
!android.util.Patterns.EMAIL_ADDRESS.matcher(email)
|
!android.util.Patterns.EMAIL_ADDRESS.matcher(email)
|
||||||
.matches() -> context.getString(R.string.text_error_email_format_1)
|
.matches() -> context.getString(R.string.text_error_email_format)
|
||||||
|
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
@@ -98,8 +88,22 @@ fun EmailSignupScreen() {
|
|||||||
}
|
}
|
||||||
termsError = true
|
termsError = true
|
||||||
return false
|
return false
|
||||||
|
} else {
|
||||||
|
termsError = false
|
||||||
|
}
|
||||||
|
if (!acceptPromotions) {
|
||||||
|
scope.launch(Dispatchers.Main) {
|
||||||
|
Toast.makeText(
|
||||||
|
context,
|
||||||
|
context.getString(R.string.error_not_accept_recive_notice),
|
||||||
|
Toast.LENGTH_SHORT
|
||||||
|
).show()
|
||||||
|
}
|
||||||
|
promotionsError = true
|
||||||
|
return false
|
||||||
|
} else {
|
||||||
|
promotionsError = false
|
||||||
}
|
}
|
||||||
termsError = false
|
|
||||||
|
|
||||||
return emailError == null && passwordError == null && confirmPasswordError == null
|
return emailError == null && passwordError == null && confirmPasswordError == null
|
||||||
}
|
}
|
||||||
@@ -154,127 +158,63 @@ fun EmailSignupScreen() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Column(
|
Column(
|
||||||
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
.background(appColor.background)
|
.background(appColor.background)
|
||||||
) {
|
) {
|
||||||
StatusBarSpacer()
|
StatusBarSpacer()
|
||||||
// 顶部导航栏:返回箭头 + "注册"标题,左对齐
|
Box(
|
||||||
Row(
|
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.padding(top = 15.dp, start = 16.dp, bottom = 15.dp, end = 16.dp),
|
.padding(top = 16.dp, start = 16.dp, end = 16.dp)
|
||||||
verticalAlignment = Alignment.CenterVertically
|
|
||||||
) {
|
) {
|
||||||
Image(
|
NoticeScreenHeader(stringResource(R.string.sign_up_upper), moreIcon = false)
|
||||||
painter = painterResource(id = R.drawable.rider_pro_back_icon),
|
|
||||||
contentDescription = "Back",
|
|
||||||
modifier = Modifier
|
|
||||||
.size(24.dp)
|
|
||||||
.noRippleClickable {
|
|
||||||
navController.navigateUp()
|
|
||||||
},
|
|
||||||
colorFilter = ColorFilter.tint(Color.Black)
|
|
||||||
)
|
|
||||||
Spacer(modifier = Modifier.width(8.dp))
|
|
||||||
Text(
|
|
||||||
text = stringResource(R.string.sign_up_upper),
|
|
||||||
fontSize = 20.sp,
|
|
||||||
fontWeight = FontWeight.W600,
|
|
||||||
color = Color.Black
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
Spacer(modifier = Modifier.padding(32.dp))
|
||||||
// 输入区域
|
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.weight(1f)
|
.weight(1f)
|
||||||
.padding(horizontal = 0.dp)
|
.padding(horizontal = 24.dp)
|
||||||
) {
|
) {
|
||||||
Spacer(modifier = Modifier.height(16.dp))
|
|
||||||
|
|
||||||
// 邮箱输入框
|
|
||||||
TextInputField(
|
TextInputField(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth(),
|
||||||
.padding(horizontal = 24.dp),
|
|
||||||
text = email,
|
text = email,
|
||||||
onValueChange = {
|
onValueChange = {
|
||||||
email = it
|
email = it
|
||||||
},
|
},
|
||||||
label = stringResource(R.string.login_email_label),
|
|
||||||
hint = stringResource(R.string.text_hint_email),
|
hint = stringResource(R.string.text_hint_email),
|
||||||
error = emailError,
|
error = emailError
|
||||||
leadingIcon = {
|
|
||||||
Image(
|
|
||||||
painter = painterResource(id = R.mipmap.icon_email_light),
|
|
||||||
contentDescription = "Email",
|
|
||||||
modifier = Modifier.size(24.dp),
|
|
||||||
colorFilter = ColorFilter.tint(IconGray)
|
|
||||||
)
|
|
||||||
},
|
|
||||||
customBackgroundColor = LightGrayBackground,
|
|
||||||
customCornerRadius = 16f
|
|
||||||
)
|
)
|
||||||
|
Spacer(modifier = Modifier.padding(4.dp))
|
||||||
// 密码输入框
|
|
||||||
TextInputField(
|
TextInputField(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth(),
|
||||||
.padding(horizontal = 24.dp),
|
|
||||||
text = password,
|
text = password,
|
||||||
onValueChange = {
|
onValueChange = {
|
||||||
password = it
|
password = it
|
||||||
},
|
},
|
||||||
password = true,
|
password = true,
|
||||||
label = stringResource(R.string.text_hint_password).replace("输入", ""),
|
|
||||||
hint = stringResource(R.string.text_hint_password),
|
hint = stringResource(R.string.text_hint_password),
|
||||||
error = passwordError,
|
error = passwordError
|
||||||
leadingIcon = {
|
|
||||||
Image(
|
|
||||||
painter = painterResource(id = R.mipmap.icon_lock_light),
|
|
||||||
contentDescription = "Lock",
|
|
||||||
modifier = Modifier.size(24.dp),
|
|
||||||
colorFilter = ColorFilter.tint(IconGray)
|
|
||||||
)
|
|
||||||
},
|
|
||||||
customBackgroundColor = LightGrayBackground,
|
|
||||||
customCornerRadius = 16f
|
|
||||||
)
|
)
|
||||||
|
Spacer(modifier = Modifier.padding(4.dp))
|
||||||
// 确认密码输入框
|
|
||||||
TextInputField(
|
TextInputField(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth(),
|
||||||
.padding(horizontal = 24.dp),
|
|
||||||
text = confirmPassword,
|
text = confirmPassword,
|
||||||
onValueChange = {
|
onValueChange = {
|
||||||
confirmPassword = it
|
confirmPassword = it
|
||||||
},
|
},
|
||||||
password = true,
|
password = true,
|
||||||
label = stringResource(R.string.confirm_password_label),
|
hint = stringResource(R.string.text_hint_confirm_password),
|
||||||
hint = stringResource(R.string.text_hint_password),
|
error = confirmPasswordError
|
||||||
error = confirmPasswordError,
|
|
||||||
leadingIcon = {
|
|
||||||
Image(
|
|
||||||
painter = painterResource(id = R.mipmap.icon_lock_light),
|
|
||||||
contentDescription = "Lock",
|
|
||||||
modifier = Modifier.size(24.dp),
|
|
||||||
colorFilter = ColorFilter.tint(IconGray)
|
|
||||||
)
|
|
||||||
},
|
|
||||||
customBackgroundColor = LightGrayBackground,
|
|
||||||
customCornerRadius = 16f
|
|
||||||
)
|
)
|
||||||
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
Spacer(modifier = Modifier.height(16.dp))
|
|
||||||
|
|
||||||
// 功能选项区域
|
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier
|
modifier = Modifier.fillMaxWidth(),
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(horizontal = 24.dp),
|
|
||||||
horizontalAlignment = Alignment.Start,
|
horizontalAlignment = Alignment.Start,
|
||||||
) {
|
) {
|
||||||
CheckboxWithLabel(
|
CheckboxWithLabel(
|
||||||
@@ -296,31 +236,42 @@ fun EmailSignupScreen() {
|
|||||||
termsError = false
|
termsError = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Spacer(modifier = Modifier.height(16.dp))
|
||||||
|
CheckboxWithLabel(
|
||||||
|
checked = acceptPromotions,
|
||||||
|
checkSize = 16,
|
||||||
|
fontSize = 12,
|
||||||
|
label = stringResource(R.string.agree_promotion),
|
||||||
|
error = promotionsError
|
||||||
|
) {
|
||||||
|
acceptPromotions = it
|
||||||
|
// 当用户勾选时,立即清除错误状态
|
||||||
|
if (it) {
|
||||||
|
promotionsError = false
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(76.dp))
|
Spacer(modifier = Modifier.height(32.dp))
|
||||||
|
|
||||||
// 底部注册按钮
|
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier
|
modifier = Modifier.fillMaxWidth(),
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(horizontal = 24.dp),
|
|
||||||
contentAlignment = Alignment.Center
|
contentAlignment = Alignment.Center
|
||||||
) {
|
) {
|
||||||
ActionButton(
|
ActionButton(
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier
|
||||||
text = stringResource(R.string.sign_up_upper),
|
.width(345.dp),
|
||||||
backgroundColor = PurpleButton,
|
text = stringResource(R.string.lets_ride_upper),
|
||||||
color = Color.White,
|
backgroundColor = Color(0xffda3832),
|
||||||
fontSize = 17.sp,
|
color = Color.White
|
||||||
fontWeight = FontWeight.W600
|
|
||||||
) {
|
) {
|
||||||
scope.launch(Dispatchers.IO) {
|
scope.launch(Dispatchers.IO) {
|
||||||
registerUser()
|
registerUser()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -6,11 +6,9 @@ import android.util.Log
|
|||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.compose.foundation.Image
|
import androidx.compose.foundation.Image
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.border
|
|
||||||
import androidx.compose.foundation.gestures.Orientation
|
import androidx.compose.foundation.gestures.Orientation
|
||||||
import androidx.compose.foundation.gestures.rememberScrollableState
|
import androidx.compose.foundation.gestures.rememberScrollableState
|
||||||
import androidx.compose.foundation.gestures.scrollable
|
import androidx.compose.foundation.gestures.scrollable
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.PaddingValues
|
import androidx.compose.foundation.layout.PaddingValues
|
||||||
@@ -42,14 +40,12 @@ import androidx.compose.ui.draw.clip
|
|||||||
import androidx.compose.ui.draw.scale
|
import androidx.compose.ui.draw.scale
|
||||||
import androidx.compose.ui.graphics.Brush
|
import androidx.compose.ui.graphics.Brush
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.graphics.ColorFilter
|
|
||||||
import androidx.compose.ui.graphics.graphicsLayer
|
import androidx.compose.ui.graphics.graphicsLayer
|
||||||
import androidx.compose.ui.layout.ContentScale
|
import androidx.compose.ui.layout.ContentScale
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.compose.ui.text.style.TextAlign
|
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
@@ -74,11 +70,6 @@ import com.google.accompanist.systemuicontroller.rememberSystemUiController
|
|||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import com.airbnb.lottie.compose.LottieAnimation
|
|
||||||
import com.airbnb.lottie.compose.LottieCompositionSpec
|
|
||||||
import com.airbnb.lottie.compose.LottieConstants
|
|
||||||
import com.airbnb.lottie.compose.rememberLottieComposition
|
|
||||||
|
|
||||||
@Preview
|
@Preview
|
||||||
@Composable
|
@Composable
|
||||||
fun LoginPage() {
|
fun LoginPage() {
|
||||||
@@ -218,14 +209,14 @@ fun LoginPage() {
|
|||||||
saveData()
|
saveData()
|
||||||
}
|
}
|
||||||
|
|
||||||
// // 显示成功提示
|
// 显示成功提示
|
||||||
// coroutineScope.launch(Dispatchers.Main) {
|
coroutineScope.launch(Dispatchers.Main) {
|
||||||
// Toast.makeText(
|
Toast.makeText(
|
||||||
// context,
|
context,
|
||||||
// "游客登录成功",
|
"游客登录成功",
|
||||||
// Toast.LENGTH_SHORT
|
Toast.LENGTH_SHORT
|
||||||
// ).show()
|
).show()
|
||||||
// }
|
}
|
||||||
|
|
||||||
// 初始化应用状态(游客模式会自动跳过推送和TRTC初始化)
|
// 初始化应用状态(游客模式会自动跳过推送和TRTC初始化)
|
||||||
try {
|
try {
|
||||||
@@ -269,37 +260,13 @@ fun LoginPage() {
|
|||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
.background(AppColors.background)
|
.background(AppColors.background)
|
||||||
) {
|
) {
|
||||||
Row(
|
Box(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxSize()
|
||||||
.padding(horizontal = 24.dp)
|
|
||||||
.padding(top = 60.dp),
|
|
||||||
horizontalArrangement = Arrangement.SpaceBetween,
|
|
||||||
verticalAlignment = Alignment.CenterVertically
|
|
||||||
) {
|
) {
|
||||||
Box(
|
val localContext = LocalContext.current // 获取 Context
|
||||||
modifier = Modifier
|
MovingImageWall(localContext.resources) // 将 resources 传递给 MovingImageWall
|
||||||
.size(30.dp)
|
|
||||||
.background(
|
|
||||||
color = AppColors.text.copy(alpha = 0.1f),
|
|
||||||
shape = androidx.compose.foundation.shape.CircleShape
|
|
||||||
)
|
|
||||||
.noRippleClickable {
|
|
||||||
guestLogin()
|
|
||||||
},
|
|
||||||
contentAlignment = Alignment.Center
|
|
||||||
) {
|
|
||||||
Image(
|
|
||||||
painter = painterResource(id = R.drawable.rider_pro_close),
|
|
||||||
contentDescription = "Close",
|
|
||||||
modifier = Modifier.size(16.dp),
|
|
||||||
colorFilter = ColorFilter.tint(AppColors.text)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(20.dp))
|
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
@@ -307,109 +274,78 @@ fun LoginPage() {
|
|||||||
horizontalAlignment = Alignment.CenterHorizontally
|
horizontalAlignment = Alignment.CenterHorizontally
|
||||||
) {
|
) {
|
||||||
Spacer(modifier = Modifier.weight(1f))
|
Spacer(modifier = Modifier.weight(1f))
|
||||||
Box(
|
Image(
|
||||||
|
painter = painterResource(id = R.mipmap.invalid_name),
|
||||||
|
contentDescription = "Rave Now",
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.size(52.dp)
|
||||||
.height(400.dp)
|
.clip(RoundedCornerShape(10.dp))
|
||||||
|
)
|
||||||
) {
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
val lottieFile = if (AppState.darkMode) "login.lottie" else "login_light.lottie"
|
|
||||||
LottieAnimation(
|
|
||||||
composition = rememberLottieComposition(LottieCompositionSpec.Asset(lottieFile)).value,
|
|
||||||
iterations = LottieConstants.IterateForever,
|
|
||||||
modifier = Modifier.fillMaxSize()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
Text(
|
Text(
|
||||||
text = stringResource(R.string.join_party_carnival),
|
"Rave Now",
|
||||||
fontSize = 17.sp,
|
fontSize = 28.sp,
|
||||||
fontWeight = FontWeight.W600,
|
fontWeight = FontWeight.W900,
|
||||||
color = AppColors.text
|
color = AppColors.text
|
||||||
)
|
)
|
||||||
// Image(
|
Spacer(modifier = Modifier.height(16.dp))
|
||||||
// painter = painterResource(id = R.mipmap.invalid_name),
|
Text(
|
||||||
// contentDescription = "Rave Now",
|
"Your Night Starts Here",
|
||||||
// modifier = Modifier
|
fontSize = 20.sp,
|
||||||
// .size(52.dp)
|
fontWeight = FontWeight.W700,
|
||||||
// .clip(RoundedCornerShape(10.dp))
|
color = AppColors.text
|
||||||
// )
|
)
|
||||||
// Spacer(modifier = Modifier.height(8.dp))
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
// Text(
|
|
||||||
// "Rave Now",
|
|
||||||
// fontSize = 28.sp,
|
|
||||||
// fontWeight = FontWeight.W900,
|
|
||||||
// color = AppColors.text
|
|
||||||
// )
|
|
||||||
// Spacer(modifier = Modifier.height(16.dp))
|
|
||||||
// Text(
|
|
||||||
// "Your Night Starts Here",
|
|
||||||
// fontSize = 20.sp,
|
|
||||||
// fontWeight = FontWeight.W700,
|
|
||||||
// color = AppColors.text
|
|
||||||
// )
|
|
||||||
//注册tab
|
|
||||||
Spacer(modifier = Modifier.height(48.dp))
|
|
||||||
ActionButton(
|
ActionButton(
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
text = stringResource(R.string.sign_up_upper),
|
text = stringResource(R.string.sign_up_upper),
|
||||||
color = if (AppState.darkMode) Color.Black else Color.White,
|
color = AppColors.mainText,
|
||||||
backgroundColor = if (AppState.darkMode) Color.White else Color.Black
|
backgroundColor = AppColors.main
|
||||||
) {
|
) {
|
||||||
navController.navigate(
|
navController.navigate(
|
||||||
NavigationRoute.EmailSignUp.route,
|
NavigationRoute.EmailSignUp.route,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
//谷歌登录tab
|
if (showGoogleLogin) {
|
||||||
Spacer(modifier = Modifier.height(16.dp))
|
Spacer(modifier = Modifier.height(16.dp))
|
||||||
ActionButton(
|
ActionButton(
|
||||||
modifier = Modifier
|
modifier = Modifier.fillMaxWidth(),
|
||||||
.fillMaxWidth()
|
|
||||||
.height(52.dp)
|
|
||||||
.border(
|
|
||||||
width = 1.5.dp,
|
|
||||||
color = if (AppState.darkMode) Color.White else Color.Black,
|
|
||||||
shape = RoundedCornerShape(24.dp)
|
|
||||||
),
|
|
||||||
text = stringResource(R.string.sign_in_with_google),
|
text = stringResource(R.string.sign_in_with_google),
|
||||||
color = if (AppState.darkMode) Color.White else Color.Black,
|
color = AppColors.text,
|
||||||
backgroundColor = if (AppState.darkMode) Color.Black else Color.White,
|
|
||||||
leading = {
|
leading = {
|
||||||
Image(
|
Image(
|
||||||
painter = painterResource(id = R.mipmap.rider_pro_signup_google),
|
painter = painterResource(id = R.drawable.rider_pro_google),
|
||||||
contentDescription = "Google",
|
contentDescription = "Google",
|
||||||
modifier = Modifier.size(18.dp),
|
modifier = Modifier.size(36.dp)
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
expandText = true,
|
expandText = true,
|
||||||
contentPadding = PaddingValues(vertical = 8.dp, horizontal = 10.dp)
|
contentPadding = PaddingValues(vertical = 8.dp, horizontal = 8.dp)
|
||||||
) {
|
) {
|
||||||
googleLogin()
|
googleLogin()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
//登录tab
|
//登录tab
|
||||||
Spacer(modifier = Modifier.height(24.dp))
|
Spacer(modifier = Modifier.height(24.dp))
|
||||||
Text(
|
ActionButton(
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
text = stringResource(R.string.login_upper),
|
text = stringResource(R.string.login_upper),
|
||||||
color = AppColors.text.copy(alpha = 0.5f),
|
color = AppColors.text,
|
||||||
fontSize = 16.sp,
|
) {
|
||||||
textAlign = TextAlign.Center,
|
navController.navigate(
|
||||||
modifier = Modifier
|
NavigationRoute.UserAuth.route,
|
||||||
.fillMaxWidth()
|
)
|
||||||
.noRippleClickable {
|
}
|
||||||
navController.navigate(
|
|
||||||
NavigationRoute.UserAuth.route,
|
// 游客登录按钮
|
||||||
)
|
Spacer(modifier = Modifier.height(16.dp))
|
||||||
}
|
ActionButton(
|
||||||
)
|
modifier = Modifier.fillMaxWidth(),
|
||||||
// // 游客登录按钮
|
text = "游客模式",
|
||||||
// Spacer(modifier = Modifier.height(16.dp))
|
color = AppColors.text.copy(alpha = 0.7f),
|
||||||
// ActionButton(
|
) {
|
||||||
// modifier = Modifier.fillMaxWidth(),
|
guestLogin()
|
||||||
// text = "游客模式",
|
}
|
||||||
// color = AppColors.text.copy(alpha = 0.7f),
|
|
||||||
// ) {
|
|
||||||
// guestLogin()
|
|
||||||
// }
|
|
||||||
Spacer(modifier = Modifier.height(70.dp))
|
Spacer(modifier = Modifier.height(70.dp))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,8 +22,6 @@ import androidx.compose.runtime.rememberCoroutineScope
|
|||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.Brush
|
|
||||||
import androidx.compose.ui.graphics.Color
|
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
@@ -62,7 +60,7 @@ fun UserAuthScreen() {
|
|||||||
val AppColors = LocalAppTheme.current
|
val AppColors = LocalAppTheme.current
|
||||||
var email by remember { mutableStateOf("") }
|
var email by remember { mutableStateOf("") }
|
||||||
var password by remember { mutableStateOf("") }
|
var password by remember { mutableStateOf("") }
|
||||||
var rememberMe by remember { mutableStateOf(true) }
|
var rememberMe by remember { mutableStateOf(false) }
|
||||||
val accountService: AccountService = AccountServiceImpl()
|
val accountService: AccountService = AccountServiceImpl()
|
||||||
val captchaService: CaptchaService = CaptchaServiceImpl()
|
val captchaService: CaptchaService = CaptchaServiceImpl()
|
||||||
val scope = rememberCoroutineScope()
|
val scope = rememberCoroutineScope()
|
||||||
@@ -72,17 +70,8 @@ fun UserAuthScreen() {
|
|||||||
var passwordError by remember { mutableStateOf<String?>(null) }
|
var passwordError by remember { mutableStateOf<String?>(null) }
|
||||||
var captchaInfo by remember { mutableStateOf<CaptchaInfo?>(null) }
|
var captchaInfo by remember { mutableStateOf<CaptchaInfo?>(null) }
|
||||||
fun validateForm(): Boolean {
|
fun validateForm(): Boolean {
|
||||||
// 如果密码为空,先检查邮箱格式
|
emailError =
|
||||||
if (password.isEmpty()) {
|
if (email.isEmpty()) context.getString(R.string.text_error_email_required) else null
|
||||||
emailError = when {
|
|
||||||
email.isEmpty() -> context.getString(R.string.text_error_email_required)
|
|
||||||
!android.util.Patterns.EMAIL_ADDRESS.matcher(email).matches() ->
|
|
||||||
context.getString(R.string.text_error_email_format)
|
|
||||||
else -> null
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
emailError = if (email.isEmpty()) context.getString(R.string.text_error_email_required) else null
|
|
||||||
}
|
|
||||||
|
|
||||||
// 使用通用密码校验器
|
// 使用通用密码校验器
|
||||||
val passwordValidation = PasswordValidator.validateCurrentPassword(password, context)
|
val passwordValidation = PasswordValidator.validateCurrentPassword(password, context)
|
||||||
@@ -310,38 +299,32 @@ fun UserAuthScreen() {
|
|||||||
ActionButton(
|
ActionButton(
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
text = stringResource(R.string.lets_ride_upper),
|
text = stringResource(R.string.lets_ride_upper),
|
||||||
backgroundBrush = Brush.linearGradient(
|
backgroundColor = AppColors.main,
|
||||||
colors = listOf(
|
|
||||||
Color(0xFF7c45ed),
|
|
||||||
Color(0x777c68ef),
|
|
||||||
Color(0x777bd8f8)
|
|
||||||
)
|
|
||||||
),
|
|
||||||
color = AppColors.mainText,
|
color = AppColors.mainText,
|
||||||
) {
|
) {
|
||||||
onLogin()
|
onLogin()
|
||||||
}
|
}
|
||||||
// if (AppState.enableGoogleLogin) {
|
if (AppState.enableGoogleLogin) {
|
||||||
// Spacer(modifier = Modifier.height(16.dp))
|
Spacer(modifier = Modifier.height(16.dp))
|
||||||
// Text(stringResource(R.string.or_login_with), color = AppColors.secondaryText)
|
Text(stringResource(R.string.or_login_with), color = AppColors.secondaryText)
|
||||||
// Spacer(modifier = Modifier.height(16.dp))
|
Spacer(modifier = Modifier.height(16.dp))
|
||||||
// ActionButton(
|
ActionButton(
|
||||||
// modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
// text = stringResource(R.string.sign_in_with_google),
|
text = stringResource(R.string.sign_in_with_google),
|
||||||
// color = AppColors.text,
|
color = AppColors.text,
|
||||||
// leading = {
|
leading = {
|
||||||
// Image(
|
Image(
|
||||||
// painter = painterResource(id = R.drawable.rider_pro_google),
|
painter = painterResource(id = R.drawable.rider_pro_google),
|
||||||
// contentDescription = "Google",
|
contentDescription = "Google",
|
||||||
// modifier = Modifier.size(36.dp)
|
modifier = Modifier.size(36.dp)
|
||||||
// )
|
)
|
||||||
// },
|
},
|
||||||
// expandText = true,
|
expandText = true,
|
||||||
// contentPadding = PaddingValues(vertical = 8.dp, horizontal = 8.dp)
|
contentPadding = PaddingValues(vertical = 8.dp, horizontal = 8.dp)
|
||||||
// ) {
|
) {
|
||||||
// googleLogin()
|
googleLogin()
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,8 +26,6 @@ import androidx.compose.foundation.layout.heightIn
|
|||||||
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.width
|
import androidx.compose.foundation.layout.width
|
||||||
import androidx.compose.foundation.layout.widthIn
|
|
||||||
import androidx.compose.foundation.layout.wrapContentWidth
|
|
||||||
import androidx.compose.foundation.lazy.grid.GridCells
|
import androidx.compose.foundation.lazy.grid.GridCells
|
||||||
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
|
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
@@ -54,8 +52,6 @@ import androidx.compose.ui.draw.rotate
|
|||||||
import androidx.compose.ui.draw.scale
|
import androidx.compose.ui.draw.scale
|
||||||
import androidx.compose.ui.draw.shadow
|
import androidx.compose.ui.draw.shadow
|
||||||
import androidx.compose.ui.geometry.CornerRadius
|
import androidx.compose.ui.geometry.CornerRadius
|
||||||
import androidx.compose.ui.geometry.Offset
|
|
||||||
import androidx.compose.ui.graphics.Brush
|
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.graphics.ColorFilter
|
import androidx.compose.ui.graphics.ColorFilter
|
||||||
import androidx.compose.ui.graphics.PathEffect
|
import androidx.compose.ui.graphics.PathEffect
|
||||||
@@ -70,7 +66,6 @@ import androidx.compose.ui.res.stringResource
|
|||||||
import androidx.compose.ui.text.TextStyle
|
import androidx.compose.ui.text.TextStyle
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.compose.ui.text.style.TextAlign
|
import androidx.compose.ui.text.style.TextAlign
|
||||||
import androidx.compose.ui.text.style.TextOverflow
|
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
@@ -156,45 +151,71 @@ fun NewPostScreen() {
|
|||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.height(1.dp)
|
.height(1.dp)
|
||||||
.padding(horizontal = 16.dp)
|
|
||||||
.background(AppColors.divider)
|
.background(AppColors.divider)
|
||||||
)
|
)
|
||||||
Spacer(modifier = Modifier.height(24.dp))
|
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.padding(start = 16.dp)
|
.fillMaxWidth()
|
||||||
.height(40.dp)
|
.padding(top = 8.dp, start = 16.dp, end = 16.dp, bottom = 8.dp),
|
||||||
.widthIn(min = 100.dp, max = 200.dp)
|
verticalAlignment = Alignment.CenterVertically
|
||||||
.wrapContentWidth()
|
|
||||||
.clip(RoundedCornerShape(20.dp))
|
|
||||||
.background(
|
|
||||||
brush = Brush.linearGradient(
|
|
||||||
colors = listOf(
|
|
||||||
Color(0xFF8CDDFF),
|
|
||||||
Color(0xFF9887FF),
|
|
||||||
Color(0xFFFF8D28)
|
|
||||||
),
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.padding(horizontal = 14.dp, vertical = 8.dp),
|
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
|
||||||
horizontalArrangement = Arrangement.Center
|
|
||||||
) {
|
) {
|
||||||
Image(
|
Image(
|
||||||
painter = painterResource(id = R.mipmap.icon_ai),
|
painter = painterResource(id = R.mipmap.rider_pro_moment_ai),
|
||||||
contentDescription = null,
|
contentDescription = null,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.size(16.dp)
|
.size(24.dp)
|
||||||
|
|
||||||
)
|
)
|
||||||
Text(
|
Text(
|
||||||
text = stringResource(R.string.moment_ai_co),
|
text = stringResource(R.string.moment_ai_co),
|
||||||
fontWeight = FontWeight.Normal,
|
fontWeight = FontWeight.Bold,
|
||||||
fontSize = 13.sp,
|
fontSize = 15.sp,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.padding(start = 2.dp),
|
.padding(start = 8.dp)
|
||||||
color = Color.White,
|
.weight(1f),
|
||||||
maxLines = 1,
|
color = AppColors.text,
|
||||||
overflow = TextOverflow.Ellipsis
|
)
|
||||||
|
Switch(
|
||||||
|
checked = isAiEnabled,
|
||||||
|
onCheckedChange = {
|
||||||
|
isChecked ->
|
||||||
|
isAiEnabled = isChecked
|
||||||
|
if (isChecked) {
|
||||||
|
// 收起键盘
|
||||||
|
keyboardController?.hide()
|
||||||
|
isRequesting = true
|
||||||
|
isRotating = true
|
||||||
|
model.viewModelScope.launch {
|
||||||
|
try {
|
||||||
|
model.agentMoment(model.textContent)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
e.printStackTrace()
|
||||||
|
}finally {
|
||||||
|
isRequesting = false
|
||||||
|
isRotating = false
|
||||||
|
isAiEnabled = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
}
|
||||||
|
},
|
||||||
|
enabled = !isRequesting && model.textContent.isNotEmpty(),
|
||||||
|
colors = SwitchDefaults.colors(
|
||||||
|
checkedThumbColor = Color.White,
|
||||||
|
checkedTrackColor = AppColors.brandColorsColor,
|
||||||
|
uncheckedThumbColor = Color.White,
|
||||||
|
uncheckedTrackColor = AppColors.nonActive,
|
||||||
|
uncheckedBorderColor = Color.White,
|
||||||
|
disabledCheckedTrackColor = AppColors.brandColorsColor.copy(alpha = 0.8f),
|
||||||
|
disabledCheckedThumbColor= Color.White,
|
||||||
|
disabledUncheckedTrackColor = AppColors.nonActive,
|
||||||
|
disabledUncheckedThumbColor= Color.White
|
||||||
|
|
||||||
|
),
|
||||||
|
modifier = Modifier.scale(0.8f)
|
||||||
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -331,7 +352,7 @@ fun NewPostTopBar(onSendClick: () -> Unit = {}) {
|
|||||||
modifier = Modifier.align(Alignment.CenterStart),
|
modifier = Modifier.align(Alignment.CenterStart),
|
||||||
) {
|
) {
|
||||||
Image(
|
Image(
|
||||||
painter = painterResource(id = R.drawable.rider_pro_back_icon),
|
painter = painterResource(id = R.drawable.rider_pro_close),
|
||||||
contentDescription = "Back",
|
contentDescription = "Back",
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.size(24.dp)
|
.size(24.dp)
|
||||||
@@ -345,31 +366,9 @@ fun NewPostTopBar(onSendClick: () -> Unit = {}) {
|
|||||||
},
|
},
|
||||||
colorFilter = ColorFilter.tint(AppColors.text)
|
colorFilter = ColorFilter.tint(AppColors.text)
|
||||||
)
|
)
|
||||||
Spacer(modifier = Modifier.width(8.dp))
|
|
||||||
Text(
|
|
||||||
modifier = Modifier.align(Alignment.CenterVertically),
|
|
||||||
text = stringResource(R.string.publish_dynamic),
|
|
||||||
fontSize = 17.sp,
|
|
||||||
color = AppColors.text,
|
|
||||||
)
|
|
||||||
Spacer(modifier = Modifier.weight(1f))
|
Spacer(modifier = Modifier.weight(1f))
|
||||||
Image(
|
Image(
|
||||||
painter = painterResource(id = R.mipmap.icon_draft_box_light),
|
painter = painterResource(id = R.mipmap.rider_pro_moment_post),
|
||||||
contentDescription = "",
|
|
||||||
modifier = Modifier
|
|
||||||
.size(24.dp)
|
|
||||||
.noRippleClickable {
|
|
||||||
// 添加防抖逻辑
|
|
||||||
val currentTime = System.currentTimeMillis()
|
|
||||||
if (currentTime - lastSendClickTime > debounceTime) {
|
|
||||||
lastSendClickTime = currentTime
|
|
||||||
}
|
|
||||||
},
|
|
||||||
colorFilter = ColorFilter.tint(AppColors.text)
|
|
||||||
)
|
|
||||||
Spacer(modifier = Modifier.width(20.dp))
|
|
||||||
Image(
|
|
||||||
painter = painterResource(id = R.mipmap.icon_released_light),
|
|
||||||
contentDescription = "Send",
|
contentDescription = "Send",
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.size(24.dp)
|
.size(24.dp)
|
||||||
@@ -392,8 +391,11 @@ fun NewPostTopBar(onSendClick: () -> Unit = {}) {
|
|||||||
}finally {
|
}finally {
|
||||||
uploading = false
|
uploading = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -486,24 +488,72 @@ fun AddImageGrid() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val addImageDebouncer = rememberDebouncer()
|
val addImageDebouncer = rememberDebouncer()
|
||||||
|
val takePhotoDebouncer = rememberDebouncer()
|
||||||
|
|
||||||
|
val stroke = Stroke(
|
||||||
|
width = 2f,
|
||||||
|
pathEffect = PathEffect.dashPathEffect(floatArrayOf(10f, 10f), 0f)
|
||||||
|
)
|
||||||
|
DraggableGrid(
|
||||||
|
items = NewPostViewModel.imageList,
|
||||||
|
onMove = { from, to ->
|
||||||
|
NewPostViewModel.imageList = NewPostViewModel.imageList.toMutableList().apply {
|
||||||
|
add(to, removeAt(from))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
lockedIndices = listOf(
|
||||||
|
|
||||||
|
),
|
||||||
|
onDragModeEnd = {},
|
||||||
|
onDragModeStart = {},
|
||||||
|
additionalItems = listOf(
|
||||||
|
|
||||||
|
),
|
||||||
|
getItemId = { it.id }
|
||||||
|
) { item, isDrag ->
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
) {
|
||||||
|
CustomAsyncImage(
|
||||||
|
LocalContext.current,
|
||||||
|
item.bitmap,
|
||||||
|
contentDescription = "Image",
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.aspectRatio(1f)
|
||||||
|
.noRippleClickable {
|
||||||
|
navController.navigate(NavigationRoute.NewPostImageGrid.route)
|
||||||
|
},
|
||||||
|
contentScale = ContentScale.Crop
|
||||||
|
)
|
||||||
|
if (isDrag) {
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.background(Color.Black.copy(alpha = 0.4f))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
val canAddMoreImages = model.imageList.size < 9
|
val canAddMoreImages = model.imageList.size < 9
|
||||||
|
|
||||||
LazyVerticalGrid(
|
LazyVerticalGrid(
|
||||||
columns = GridCells.Fixed(5),
|
columns = GridCells.Fixed(5),
|
||||||
contentPadding = PaddingValues(horizontal = 19.dp, vertical = 4.dp),
|
contentPadding = PaddingValues(8.dp),
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(horizontal = 8.dp),
|
||||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||||
verticalArrangement = Arrangement.spacedBy(8.dp)
|
verticalArrangement = Arrangement.spacedBy(8.dp)
|
||||||
) {
|
) {
|
||||||
// 添加按钮
|
|
||||||
if (canAddMoreImages) {
|
if (canAddMoreImages) {
|
||||||
item {
|
item {
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.aspectRatio(1f)
|
.aspectRatio(1f)
|
||||||
.clip(RoundedCornerShape(24.dp))
|
.clip(RoundedCornerShape(16.dp)) // 设置圆角
|
||||||
.background(Color(0xFFFAF9FB))
|
.background(AppColors.basicMain) // 设置背景色
|
||||||
.noRippleClickable {
|
.noRippleClickable {
|
||||||
addImageDebouncer {
|
addImageDebouncer {
|
||||||
if (model.imageList.size < 9) {
|
if (model.imageList.size < 9) {
|
||||||
@@ -522,21 +572,20 @@ fun AddImageGrid() {
|
|||||||
painter = painterResource(id = R.drawable.rider_pro_new_post_add_pic),
|
painter = painterResource(id = R.drawable.rider_pro_new_post_add_pic),
|
||||||
contentDescription = "Add Image",
|
contentDescription = "Add Image",
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.size(23.3.dp)
|
.size(24.dp)
|
||||||
.align(Alignment.Center),
|
.align(Alignment.Center),
|
||||||
tint = AppColors.nonActiveText
|
tint = AppColors.nonActiveText
|
||||||
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 相机按钮
|
|
||||||
item {
|
item {
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.aspectRatio(1f)
|
.aspectRatio(1f)
|
||||||
.clip(RoundedCornerShape(24.dp))
|
.clip(RoundedCornerShape(16.dp)) // 设置圆角
|
||||||
.background(Color(0xFFFAF9FB))
|
.background(AppColors.basicMain) // 设置背景色
|
||||||
.noRippleClickable {
|
.noRippleClickable {
|
||||||
if (model.imageList.size < 9) {
|
if (model.imageList.size < 9) {
|
||||||
val photoFile = File(context.cacheDir, "photo.jpg")
|
val photoFile = File(context.cacheDir, "photo.jpg")
|
||||||
@@ -556,60 +605,13 @@ fun AddImageGrid() {
|
|||||||
painter = painterResource(id = R.drawable.rider_pro_camera),
|
painter = painterResource(id = R.drawable.rider_pro_camera),
|
||||||
contentDescription = "Take Photo",
|
contentDescription = "Take Photo",
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.size(23.3.dp)
|
.size(24.dp)
|
||||||
.align(Alignment.Center),
|
.align(Alignment.Center),
|
||||||
tint = AppColors.nonActiveText
|
tint = AppColors.nonActiveText
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 已添加的图片,显示在相机按钮后面
|
|
||||||
items(model.imageList.size) { index ->
|
|
||||||
val item = model.imageList[index]
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.aspectRatio(1f)
|
|
||||||
.clip(RoundedCornerShape(24.dp))
|
|
||||||
.background(Color(0xFFFAF9FB))
|
|
||||||
) {
|
|
||||||
CustomAsyncImage(
|
|
||||||
context,
|
|
||||||
item.bitmap,
|
|
||||||
contentDescription = "Image",
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxSize()
|
|
||||||
.noRippleClickable {
|
|
||||||
navController.navigate(NavigationRoute.NewPostImageGrid.route)
|
|
||||||
},
|
|
||||||
contentScale = ContentScale.Crop
|
|
||||||
)
|
|
||||||
|
|
||||||
// // 删除按钮 - 右上角
|
|
||||||
// Box(
|
|
||||||
// modifier = Modifier
|
|
||||||
// .align(Alignment.TopEnd)
|
|
||||||
// .padding(4.dp)
|
|
||||||
// .size(20.dp)
|
|
||||||
// .clip(RoundedCornerShape(10.dp))
|
|
||||||
// .background(Color.Black.copy(alpha = 0.6f))
|
|
||||||
// .noRippleClickable {
|
|
||||||
// model.imageList = model.imageList.toMutableList().apply {
|
|
||||||
// removeAt(index)
|
|
||||||
// }
|
|
||||||
// },
|
|
||||||
// contentAlignment = Alignment.Center
|
|
||||||
// ) {
|
|
||||||
// Icon(
|
|
||||||
// painter = painterResource(id = R.drawable.rider_pro_close),
|
|
||||||
// contentDescription = "Delete",
|
|
||||||
// modifier = Modifier.size(12.dp),
|
|
||||||
// tint = Color.White
|
|
||||||
// )
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import com.aiosman.ravenow.data.UserServiceImpl
|
|||||||
import com.aiosman.ravenow.entity.AccountProfileEntity
|
import com.aiosman.ravenow.entity.AccountProfileEntity
|
||||||
import com.aiosman.ravenow.entity.MomentEntity
|
import com.aiosman.ravenow.entity.MomentEntity
|
||||||
import com.aiosman.ravenow.entity.MomentServiceImpl
|
import com.aiosman.ravenow.entity.MomentServiceImpl
|
||||||
import com.aiosman.ravenow.event.FollowChangeEvent
|
|
||||||
import com.aiosman.ravenow.event.MomentFavouriteChangeEvent
|
import com.aiosman.ravenow.event.MomentFavouriteChangeEvent
|
||||||
import com.aiosman.ravenow.event.MomentLikeChangeEvent
|
import com.aiosman.ravenow.event.MomentLikeChangeEvent
|
||||||
import com.aiosman.ravenow.event.MomentRemoveEvent
|
import com.aiosman.ravenow.event.MomentRemoveEvent
|
||||||
@@ -167,8 +166,7 @@ class PostViewModel(
|
|||||||
moment?.let {
|
moment?.let {
|
||||||
userService.followUser(it.authorId.toString())
|
userService.followUser(it.authorId.toString())
|
||||||
moment = moment?.copy(followStatus = true)
|
moment = moment?.copy(followStatus = true)
|
||||||
// 发送关注事件,通知动态列表更新关注状态
|
// 更新我的关注页面的关注数
|
||||||
EventBus.getDefault().post(FollowChangeEvent(it.authorId, true))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -176,8 +174,7 @@ class PostViewModel(
|
|||||||
moment?.let {
|
moment?.let {
|
||||||
userService.unFollowUser(it.authorId.toString())
|
userService.unFollowUser(it.authorId.toString())
|
||||||
moment = moment?.copy(followStatus = false)
|
moment = moment?.copy(followStatus = false)
|
||||||
// 发送取消关注事件,通知动态列表更新关注状态
|
// 更新我的关注页面的关注数
|
||||||
EventBus.getDefault().post(FollowChangeEvent(it.authorId, false))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ fun SplashScreen() {
|
|||||||
) {
|
) {
|
||||||
// 居中的图标
|
// 居中的图标
|
||||||
Image(
|
Image(
|
||||||
painter = painterResource(id = R.mipmap.kp_logo_img),
|
painter = painterResource(id = R.mipmap.invalid_name),
|
||||||
contentDescription = "App Logo",
|
contentDescription = "App Logo",
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.align(Alignment.Center)
|
.align(Alignment.Center)
|
||||||
|
|||||||
@@ -63,23 +63,6 @@ object Utils {
|
|||||||
return Locale.getDefault().language
|
return Locale.getDefault().language
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取完整的语言标记,如 "zh-CN", "en-US"
|
|
||||||
* 优先使用完整的 BCP-47 语言标记,提升与后端 translations 键的匹配率
|
|
||||||
*/
|
|
||||||
fun getPreferredLanguageTag(): String {
|
|
||||||
val locale = Locale.getDefault()
|
|
||||||
val language = locale.language
|
|
||||||
val country = locale.country
|
|
||||||
|
|
||||||
// 如果有国家/地区代码,返回完整的语言标记
|
|
||||||
return if (country.isNotEmpty()) {
|
|
||||||
"$language-$country"
|
|
||||||
} else {
|
|
||||||
language
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun compressImage(context: Context, uri: Uri, maxSize: Int = 512, quality: Int = 85): File {
|
fun compressImage(context: Context, uri: Uri, maxSize: Int = 512, quality: Int = 85): File {
|
||||||
val inputStream = context.contentResolver.openInputStream(uri)
|
val inputStream = context.contentResolver.openInputStream(uri)
|
||||||
val originalBitmap = BitmapFactory.decodeStream(inputStream)
|
val originalBitmap = BitmapFactory.decodeStream(inputStream)
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 1.4 KiB |
|
Before Width: | Height: | Size: 2.4 KiB |
|
Before Width: | Height: | Size: 356 B |
|
Before Width: | Height: | Size: 247 B |
|
Before Width: | Height: | Size: 331 B |
|
Before Width: | Height: | Size: 438 B |
|
Before Width: | Height: | Size: 434 B |
|
Before Width: | Height: | Size: 3.1 KiB |
|
Before Width: | Height: | Size: 331 B |
|
Before Width: | Height: | Size: 335 B |
|
Before Width: | Height: | Size: 3.8 KiB |
|
Before Width: | Height: | Size: 2.1 KiB |
|
Before Width: | Height: | Size: 509 B |
|
Before Width: | Height: | Size: 461 B |
|
Before Width: | Height: | Size: 446 B |
|
Before Width: | Height: | Size: 384 B |