fix: 修复加载动画变形、补动作反馈,并收紧冲突弹窗
- CircularProgressIndicator 误用 Modifier.height() 会拿到非方形画布,圆环被压扁且旋转中心偏;四处统一改为 Modifier.size() - 保存预期 / 保存 API 地址 / 开始暂停结束 / 记碎片都有 snackbar 反馈(成功短、失败长),不再只靠页面底部静态文案 - API 地址改为先校验再写入(不合法保留旧地址并提示),登录页同样校验;启动时遇到坏地址退回默认,不再抛异常 - 冲突弹窗只保留「前往继续 / 取消」:结束与误操作结束必须回到会话页面里用户自己做,列表页不再提供放弃/结束入口
This commit is contained in:
@@ -29,12 +29,14 @@
|
|||||||
|
|
||||||
- **会话状态只在 `SessionController` 里改**。UI 和 Service 都不得自行维护会话副本,否则会与服务端口径分叉。
|
- **会话状态只在 `SessionController` 里改**。UI 和 Service 都不得自行维护会话副本,否则会与服务端口径分叉。
|
||||||
- **悬浮窗只做三件事:展示倒计时、记一条碎片、暂停/继续**。结束会话、写报告、改预期、看历史一律在 App 页面内完成;不要往浮窗里加按钮或面板(它常驻在其他 App 之上,每多一个控件都是常态干扰)。
|
- **悬浮窗只做三件事:展示倒计时、记一条碎片、暂停/继续**。结束会话、写报告、改预期、看历史一律在 App 页面内完成;不要往浮窗里加按钮或面板(它常驻在其他 App 之上,每多一个控件都是常态干扰)。
|
||||||
- **开始新任务前必须先处理未结束会话**。`startOrContinue` 先查 `GET /study-sessions/active?excludeTaskNum=`,有冲突就只设置 `State.conflict`,由 UI 给出三个出口;不得绕过这一步直接开始,否则会同时存在两个进行中的会话。
|
- **开始新任务前必须先处理未结束会话**。`startOrContinue` 先查 `GET /study-sessions/active?excludeTaskNum=`,有冲突就只设置 `State.conflict`(UI 只给「前往继续 / 取消」);不得绕过这一步直接开始,也不得在列表页代替用户结束或放弃那个会话——结束与误操作结束必须在会话页里由用户自己做。
|
||||||
|
- **写操作必须有可见反馈**。保存预期、保存 API 地址、开始/暂停/结束、记碎片等动作都要给 snackbar 提示(失败文案要写清楚为什么);不要只靠页面底部一行静态文案。
|
||||||
- **学习预期不可为空**。`State.expectationRequired` 为真时用不可关闭的弹窗挡住(只能填预期或误操作结束)。
|
- **学习预期不可为空**。`State.expectationRequired` 为真时用不可关闭的弹窗挡住(只能填预期或误操作结束)。
|
||||||
- **前台服务停之前要确认“确实没有会话”**。对账是异步的,`State.resolved` 为 false 时看到的空状态是“还不知道”,不能据此 `stopSelf()`。
|
- **前台服务停之前要确认“确实没有会话”**。对账是异步的,`State.resolved` 为 false 时看到的空状态是“还不知道”,不能据此 `stopSelf()`。
|
||||||
- **计时不得用 tick 累加**。显示值一律走 `State.effectiveSeconds(nowMs)`,基准取服务端 `effectiveTime`,锚点取 `SystemClock.elapsedRealtime()`。
|
- **计时不得用 tick 累加**。显示值一律走 `State.effectiveSeconds(nowMs)`,基准取服务端 `effectiveTime`,锚点取 `SystemClock.elapsedRealtime()`。
|
||||||
- **悬浮窗窗口标志不要随手改**:`FLAG_NOT_FOCUSABLE | FLAG_NOT_TOUCH_MODAL | FLAG_LAYOUT_NO_LIMITS` 三者缺一都会出问题(抢焦点 / 挡住下层 / 半隐藏被夹回屏幕内)。
|
- **悬浮窗窗口标志不要随手改**:`FLAG_NOT_FOCUSABLE | FLAG_NOT_TOUCH_MODAL | FLAG_LAYOUT_NO_LIMITS` 三者缺一都会出问题(抢焦点 / 挡住下层 / 半隐藏被夹回屏幕内)。
|
||||||
- **不要在浮窗里做文本输入**。App 不在前台时系统不允许后台窗口弹键盘;需要输入时拉起 Activity。
|
- **不要在浮窗里做文本输入**。App 不在前台时系统不允许后台窗口弹键盘;需要输入时拉起 Activity。
|
||||||
|
- **`CircularProgressIndicator` 必须用 `Modifier.size(...)`,不要用 `Modifier.height(...)`**。它不是按容器自适应缩放的:只给高度会得到非方形画布,旋转中心会偏、圆环会被压扁。
|
||||||
- **对接后端先看部署环境的 OpenAPI**(`GET {baseUrl}/v3/api-docs`),不要假设源码与部署一致——两者已经分叉过一次。
|
- **对接后端先看部署环境的 OpenAPI**(`GET {baseUrl}/v3/api-docs`),不要假设源码与部署一致——两者已经分叉过一次。
|
||||||
|
|
||||||
## 后端
|
## 后端
|
||||||
|
|||||||
@@ -20,8 +20,9 @@ LPT 的学习计时原本只能在电脑浏览器里进行;而真实的学习
|
|||||||
| 登录 | `POST /login` 拿 token,DataStore 持久化,OkHttp 拦截器注入 `satoken` 请求头;服务端返回 401 时自动退出登录并在登录页说明原因 |
|
| 登录 | `POST /login` 拿 token,DataStore 持久化,OkHttp 拦截器注入 `satoken` 请求头;服务端返回 401 时自动退出登录并在登录页说明原因 |
|
||||||
| 权限引导 | 悬浮窗权限 / 通知权限 / 电池优化白名单 / MIUI 自启动与后台弹出 |
|
| 权限引导 | 悬浮窗权限 / 通知权限 / 电池优化白名单 / MIUI 自启动与后台弹出 |
|
||||||
| 任务列表 | `GET /tasks`,每个任务带「报告」入口;有进行中的会话时顶部带「回到会话」入口 |
|
| 任务列表 | `GET /tasks`,每个任务带「报告」入口;有进行中的会话时顶部带「回到会话」入口 |
|
||||||
|
| 操作反馈 | 保存预期、保存 API 地址、开始/暂停/结束、记碎片等动作都有 snackbar 提示(成功短、失败长) |
|
||||||
| 学习会话 | 开始/继续、暂停、结束、误操作结束(零数据)、学习预期(必填)、知识碎片、结束报告三段 |
|
| 学习会话 | 开始/继续、暂停、结束、误操作结束(零数据)、学习预期(必填)、知识碎片、结束报告三段 |
|
||||||
| 会话冲突出口 | 开始新任务前先查其他任务上的未结束会话,给出「前往继续 / 结束它并开始 / 放弃它」三个出口 |
|
| 会话冲突出口 | 开始新任务前先查其他任务上的未结束会话;有冲突时只给「前往继续 / 取消」,结束与误操作结束必须回到那个会话的页面里自己做 |
|
||||||
| 悬浮窗 | 前台服务(`specialUse`)托管,跨应用常驻;**只做三件事**:展示倒计时 / 记一条碎片 / 暂停继续 |
|
| 悬浮窗 | 前台服务(`specialUse`)托管,跨应用常驻;**只做三件事**:展示倒计时 / 记一条碎片 / 暂停继续 |
|
||||||
| 学习报告 | 结束会话时取 AI(不可用则规则降级)三段草稿作为编辑起点;任务页可查看历史报告与本次碎片 |
|
| 学习报告 | 结束会话时取 AI(不可用则规则降级)三段草稿作为编辑起点;任务页可查看历史报告与本次碎片 |
|
||||||
| 设置 | API 地址可切(默认 dev) |
|
| 设置 | API 地址可切(默认 dev) |
|
||||||
|
|||||||
@@ -54,7 +54,8 @@ class AppContainer(private val app: Application) {
|
|||||||
apiClient.onUnauthorized = { expireLogin() }
|
apiClient.onUnauthorized = { expireLogin() }
|
||||||
scope.launch {
|
scope.launch {
|
||||||
val settings = tokenStore.load()
|
val settings = tokenStore.load()
|
||||||
apiClient.setBaseUrl(settings.baseUrl)
|
// 历史数据里的地址如果已经解析不出来,退回默认地址,不要带着坏地址启动
|
||||||
|
if (!apiClient.setBaseUrl(settings.baseUrl)) apiClient.setBaseUrl(ApiClient.DEFAULT_BASE_URL)
|
||||||
apiClient.token = settings.token
|
apiClient.token = settings.token
|
||||||
_baseUrl.value = settings.baseUrl
|
_baseUrl.value = settings.baseUrl
|
||||||
_username.value = settings.username
|
_username.value = settings.username
|
||||||
@@ -71,7 +72,10 @@ class AppContainer(private val app: Application) {
|
|||||||
|
|
||||||
fun login(username: String, password: String, baseUrl: String, onResult: (String?) -> Unit) {
|
fun login(username: String, password: String, baseUrl: String, onResult: (String?) -> Unit) {
|
||||||
scope.launch {
|
scope.launch {
|
||||||
apiClient.setBaseUrl(baseUrl)
|
if (!apiClient.setBaseUrl(baseUrl)) {
|
||||||
|
onResult("API 地址不合法,需要形如 https://host/api")
|
||||||
|
return@launch
|
||||||
|
}
|
||||||
repository.login(username, password)
|
repository.login(username, password)
|
||||||
.onSuccess { token ->
|
.onSuccess { token ->
|
||||||
apiClient.token = token
|
apiClient.token = token
|
||||||
@@ -115,11 +119,23 @@ class AppContainer(private val app: Application) {
|
|||||||
_loggedIn.value = false
|
_loggedIn.value = false
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateBaseUrl(url: String) {
|
/**
|
||||||
|
* 保存 API 地址:合法才写入,不合法把错误文案回给界面(由界面弹提示)。
|
||||||
|
*/
|
||||||
|
fun updateBaseUrl(url: String, onResult: (String?) -> Unit) {
|
||||||
|
val value = url.trim()
|
||||||
|
if (value.isBlank()) {
|
||||||
|
onResult("API 地址不能为空")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (!apiClient.setBaseUrl(value)) {
|
||||||
|
onResult("API 地址不合法,需要形如 https://host/api")
|
||||||
|
return
|
||||||
|
}
|
||||||
scope.launch {
|
scope.launch {
|
||||||
apiClient.setBaseUrl(url)
|
tokenStore.saveBaseUrl(value)
|
||||||
tokenStore.saveBaseUrl(url)
|
_baseUrl.value = value
|
||||||
_baseUrl.value = url
|
onResult(null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,9 @@ import androidx.compose.material3.Button
|
|||||||
import androidx.compose.material3.CircularProgressIndicator
|
import androidx.compose.material3.CircularProgressIndicator
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.OutlinedButton
|
import androidx.compose.material3.OutlinedButton
|
||||||
|
import androidx.compose.material3.SnackbarDuration
|
||||||
|
import androidx.compose.material3.SnackbarHost
|
||||||
|
import androidx.compose.material3.SnackbarHostState
|
||||||
import androidx.compose.material3.Surface
|
import androidx.compose.material3.Surface
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.material3.TextButton
|
import androidx.compose.material3.TextButton
|
||||||
@@ -98,6 +101,18 @@ private fun AppRoot(openEndRequest: androidx.compose.runtime.MutableState<Boolea
|
|||||||
var tasksError by remember { mutableStateOf<String?>(null) }
|
var tasksError by remember { mutableStateOf<String?>(null) }
|
||||||
var reportTask by remember { mutableStateOf<TaskItem?>(null) }
|
var reportTask by remember { mutableStateOf<TaskItem?>(null) }
|
||||||
|
|
||||||
|
// 保存/开始/结束这类动作必须给出即时反馈,不能只靠页面底部的静态文案
|
||||||
|
val snackbarHostState = remember { SnackbarHostState() }
|
||||||
|
fun toast(message: String, long: Boolean = false) {
|
||||||
|
scope.launch {
|
||||||
|
snackbarHostState.showSnackbar(
|
||||||
|
message = message,
|
||||||
|
withDismissAction = false,
|
||||||
|
duration = if (long) SnackbarDuration.Long else SnackbarDuration.Short,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun refreshTasks() {
|
fun refreshTasks() {
|
||||||
tasksLoading = true
|
tasksLoading = true
|
||||||
tasksError = null
|
tasksError = null
|
||||||
@@ -139,6 +154,20 @@ private fun AppRoot(openEndRequest: androidx.compose.runtime.MutableState<Boolea
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 会话层的提示与失败统一弹 snackbar(错误停留久一点)
|
||||||
|
LaunchedEffect(sessionState.notice) {
|
||||||
|
sessionState.notice?.let {
|
||||||
|
toast(it)
|
||||||
|
container.session.consumeNotice()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
LaunchedEffect(sessionState.error) {
|
||||||
|
sessionState.error?.let {
|
||||||
|
toast(it, long = true)
|
||||||
|
container.session.consumeError()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Box(modifier = Modifier.fillMaxSize()) {
|
Box(modifier = Modifier.fillMaxSize()) {
|
||||||
Column(modifier = Modifier.fillMaxSize()) {
|
Column(modifier = Modifier.fillMaxSize()) {
|
||||||
// 不在会话页时,会话层的失败也要让用户看到(用正常布局占位,不遮住下面的标题)
|
// 不在会话页时,会话层的失败也要让用户看到(用正常布局占位,不遮住下面的标题)
|
||||||
@@ -233,7 +262,11 @@ private fun AppRoot(openEndRequest: androidx.compose.runtime.MutableState<Boolea
|
|||||||
|
|
||||||
Screen.Settings -> SettingsScreen(
|
Screen.Settings -> SettingsScreen(
|
||||||
baseUrl = baseUrl,
|
baseUrl = baseUrl,
|
||||||
onSave = { container.updateBaseUrl(it) },
|
onSave = { url ->
|
||||||
|
container.updateBaseUrl(url) { error ->
|
||||||
|
toast(error ?: "API 地址已保存", long = error != null)
|
||||||
|
}
|
||||||
|
},
|
||||||
onLogout = {
|
onLogout = {
|
||||||
StudySessionService.stop(context)
|
StudySessionService.stop(context)
|
||||||
container.logout()
|
container.logout()
|
||||||
@@ -245,13 +278,13 @@ private fun AppRoot(openEndRequest: androidx.compose.runtime.MutableState<Boolea
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 会话-05:别的任务上还有未结束会话时,先让用户选出口
|
// 会话-05:别的任务上还有未结束会话时,只能先去把它处理完
|
||||||
sessionState.conflict?.let {
|
sessionState.conflict?.let {
|
||||||
SessionConflictDialog(
|
SessionConflictDialog(
|
||||||
state = sessionState,
|
state = sessionState,
|
||||||
onAction = { action ->
|
onContinue = {
|
||||||
// 处理完必须显式回到会话页:hasSession 一直是 true,靠状态变化不会触发导航
|
// hasSession 一直是 true,靠状态变化不会触发导航,这里必须显式回会话页
|
||||||
container.session.resolveConflict(action) {
|
container.session.continueConflict {
|
||||||
StudySessionService.start(context)
|
StudySessionService.start(context)
|
||||||
screen = Screen.Session
|
screen = Screen.Session
|
||||||
}
|
}
|
||||||
@@ -259,23 +292,30 @@ private fun AppRoot(openEndRequest: androidx.compose.runtime.MutableState<Boolea
|
|||||||
onDismiss = { container.session.dismissConflict() },
|
onDismiss = { container.session.dismissConflict() },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SnackbarHost(
|
||||||
|
hostState = snackbarHostState,
|
||||||
|
modifier = Modifier.align(Alignment.BottomCenter),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 会话-05 的出口选择弹窗:不能直接开始新任务,必须先说清旧会话怎么办。
|
* 会话-05:别的任务上还有未结束会话时的提示。
|
||||||
* 三个出口对应 lpt-docs「离开一个未结束的会话」:前往继续 / 结束它并开始 / 放弃它。
|
*
|
||||||
|
* 这里故意只给「前往继续」与「取消」:结束与误操作结束都必须在那个会话自己的页面里由用户完成,
|
||||||
|
* 列表页不允许一句话就把未完成的会话结掉或丢掉。
|
||||||
*/
|
*/
|
||||||
@Composable
|
@Composable
|
||||||
private fun SessionConflictDialog(
|
private fun SessionConflictDialog(
|
||||||
state: SessionController.State,
|
state: SessionController.State,
|
||||||
onAction: (SessionController.ConflictAction) -> Unit,
|
onContinue: () -> Unit,
|
||||||
onDismiss: () -> Unit,
|
onDismiss: () -> Unit,
|
||||||
) {
|
) {
|
||||||
val conflict = state.conflict ?: return
|
val conflict = state.conflict ?: return
|
||||||
val busy = state.conflictBusy
|
val busy = state.conflictBusy
|
||||||
AlertDialog(
|
AlertDialog(
|
||||||
onDismissRequest = { if (busy == null) onDismiss() },
|
onDismissRequest = { if (!busy) onDismiss() },
|
||||||
title = { Text("还有未结束的学习会话") },
|
title = { Text("还有未结束的学习会话") },
|
||||||
text = {
|
text = {
|
||||||
Column {
|
Column {
|
||||||
@@ -296,15 +336,15 @@ private fun SessionConflictDialog(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
Text(
|
Text(
|
||||||
"可以直接开始当前任务:开始时会先把上面这个会话结束(会生成一份未填总结的学习报告);" +
|
"需要先把它处理完才能开始新任务。结束或误操作结束都请在那个会话的页面里操作," +
|
||||||
"如果它本来就是误操作开启的,可以选择放弃,不会留下任何记录。",
|
"这里不提供「放弃」这个入口。",
|
||||||
style = MaterialTheme.typography.bodySmall,
|
style = MaterialTheme.typography.bodySmall,
|
||||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
)
|
)
|
||||||
if (busy != null) {
|
if (busy) {
|
||||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||||
CircularProgressIndicator(modifier = Modifier.padding(end = 8.dp), strokeWidth = 2.dp)
|
CircularProgressIndicator(modifier = Modifier.padding(end = 8.dp), strokeWidth = 2.dp)
|
||||||
Text("正在处理上一个会话…", style = MaterialTheme.typography.bodySmall)
|
Text("正在打开那个会话…", style = MaterialTheme.typography.bodySmall)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
state.conflictError?.let {
|
state.conflictError?.let {
|
||||||
@@ -315,23 +355,13 @@ private fun SessionConflictDialog(
|
|||||||
confirmButton = {
|
confirmButton = {
|
||||||
Column(modifier = Modifier.fillMaxWidth(), verticalArrangement = Arrangement.spacedBy(6.dp)) {
|
Column(modifier = Modifier.fillMaxWidth(), verticalArrangement = Arrangement.spacedBy(6.dp)) {
|
||||||
Button(
|
Button(
|
||||||
onClick = { onAction(SessionController.ConflictAction.CONTINUE) },
|
onClick = onContinue,
|
||||||
enabled = busy == null,
|
enabled = !busy,
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
) { Text("前往继续") }
|
) { Text("前往继续") }
|
||||||
OutlinedButton(
|
|
||||||
onClick = { onAction(SessionController.ConflictAction.END_AND_START) },
|
|
||||||
enabled = busy == null,
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
|
||||||
) { Text("结束它并开始新任务") }
|
|
||||||
OutlinedButton(
|
|
||||||
onClick = { onAction(SessionController.ConflictAction.ABORT) },
|
|
||||||
enabled = busy == null,
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
|
||||||
) { Text("放弃该会话(零数据)") }
|
|
||||||
TextButton(
|
TextButton(
|
||||||
onClick = onDismiss,
|
onClick = onDismiss,
|
||||||
enabled = busy == null,
|
enabled = !busy,
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
) { Text("取消") }
|
) { Text("取消") }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.catshark.lpt.data
|
|||||||
|
|
||||||
import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory
|
import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory
|
||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
|
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
|
||||||
import okhttp3.MediaType.Companion.toMediaType
|
import okhttp3.MediaType.Companion.toMediaType
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
import retrofit2.Retrofit
|
import retrofit2.Retrofit
|
||||||
@@ -46,15 +47,20 @@ class ApiClient {
|
|||||||
.writeTimeout(60, TimeUnit.SECONDS)
|
.writeTimeout(60, TimeUnit.SECONDS)
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
fun setBaseUrl(url: String) {
|
/**
|
||||||
|
* 切换 baseUrl。地址不合法(解析不出 http/https)时返回 false,并把旧地址保留,不抛异常。
|
||||||
|
*/
|
||||||
|
fun setBaseUrl(url: String): Boolean {
|
||||||
val normalized = url.trim().let { if (it.endsWith("/")) it else "$it/" }
|
val normalized = url.trim().let { if (it.endsWith("/")) it else "$it/" }
|
||||||
if (normalized == baseUrl && retrofit != null) return
|
val parsed = normalized.toHttpUrlOrNull() ?: return false
|
||||||
|
if (normalized == baseUrl && retrofit != null) return true
|
||||||
baseUrl = normalized
|
baseUrl = normalized
|
||||||
retrofit = Retrofit.Builder()
|
retrofit = Retrofit.Builder()
|
||||||
.baseUrl(normalized)
|
.baseUrl(parsed)
|
||||||
.client(okHttp)
|
.client(okHttp)
|
||||||
.addConverterFactory(json.asConverterFactory("application/json".toMediaType()))
|
.addConverterFactory(json.asConverterFactory("application/json".toMediaType()))
|
||||||
.build()
|
.build()
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
val currentBaseUrl: String get() = baseUrl ?: DEFAULT_BASE_URL
|
val currentBaseUrl: String get() = baseUrl ?: DEFAULT_BASE_URL
|
||||||
|
|||||||
@@ -31,9 +31,6 @@ class SessionController(
|
|||||||
|
|
||||||
enum class Status { NONE, ONGOING, PAUSED, ENDED }
|
enum class Status { NONE, ONGOING, PAUSED, ENDED }
|
||||||
|
|
||||||
/** 会话-05 的出口选择 */
|
|
||||||
enum class ConflictAction { CONTINUE, END_AND_START, ABORT }
|
|
||||||
|
|
||||||
/** 别的任务上还有未结束会话:用户必须先选一个出口 */
|
/** 别的任务上还有未结束会话:用户必须先选一个出口 */
|
||||||
data class Conflict(
|
data class Conflict(
|
||||||
/** 用户想开始的任务 */
|
/** 用户想开始的任务 */
|
||||||
@@ -62,7 +59,7 @@ class SessionController(
|
|||||||
val error: String? = null,
|
val error: String? = null,
|
||||||
val notice: String? = null,
|
val notice: String? = null,
|
||||||
val conflict: Conflict? = null,
|
val conflict: Conflict? = null,
|
||||||
val conflictBusy: ConflictAction? = null,
|
val conflictBusy: Boolean = false,
|
||||||
val conflictError: String? = null,
|
val conflictError: String? = null,
|
||||||
/** 报告草稿(AI 或规则降级),仅作为结束弹窗的编辑起点,不落库 */
|
/** 报告草稿(AI 或规则降级),仅作为结束弹窗的编辑起点,不落库 */
|
||||||
val draft: ReportSections? = null,
|
val draft: ReportSections? = null,
|
||||||
@@ -131,52 +128,30 @@ class SessionController(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 处理会话-05 的出口选择 */
|
/**
|
||||||
fun resolveConflict(action: ConflictAction, onSessionReady: () -> Unit = {}) {
|
* 会话-05:有冲突时唯一能做的就是「前往继续」。
|
||||||
|
* 结束 / 误操作结束都必须在那个会话自己的页面里做,列表页不提供这些出口。
|
||||||
|
*/
|
||||||
|
fun continueConflict(onSessionReady: () -> Unit = {}) {
|
||||||
val conflict = _state.value.conflict ?: return
|
val conflict = _state.value.conflict ?: return
|
||||||
if (_state.value.conflictBusy != null) return
|
if (_state.value.conflictBusy) return
|
||||||
_state.update { it.copy(conflictBusy = action, conflictError = null) }
|
_state.update { it.copy(conflictBusy = true, conflictError = null) }
|
||||||
scope.launch {
|
scope.launch {
|
||||||
when (action) {
|
repo.sessionDetail(conflict.sessionNum)
|
||||||
ConflictAction.CONTINUE -> {
|
.onSuccess { detail ->
|
||||||
repo.sessionDetail(conflict.sessionNum)
|
applyDetail(detail)
|
||||||
.onSuccess { detail ->
|
_state.update {
|
||||||
applyDetail(detail)
|
it.copy(
|
||||||
_state.update {
|
taskNum = conflict.taskNum,
|
||||||
it.copy(
|
taskName = conflict.taskName ?: it.taskName,
|
||||||
taskNum = conflict.taskNum,
|
conflict = null,
|
||||||
taskName = conflict.taskName ?: it.taskName,
|
conflictBusy = false,
|
||||||
conflict = null,
|
)
|
||||||
conflictBusy = null,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
loadAuxiliary(conflict.sessionNum)
|
|
||||||
onSessionReady()
|
|
||||||
}
|
|
||||||
.onFailure { failConflict(it) }
|
|
||||||
}
|
|
||||||
|
|
||||||
ConflictAction.END_AND_START -> {
|
|
||||||
// 会为旧会话生成一份未填写总结的学习报告
|
|
||||||
val ended = repo.endSession(conflict.sessionNum, ReportSections("", "", STALE_SESSION_SUMMARY))
|
|
||||||
if (ended.isFailure) {
|
|
||||||
failConflict(ended.exceptionOrNull() ?: Exception("结束上一个会话失败"))
|
|
||||||
return@launch
|
|
||||||
}
|
}
|
||||||
_state.update { it.copy(conflictBusy = null) }
|
loadAuxiliary(conflict.sessionNum)
|
||||||
startTask(conflict.targetTaskNum, onSessionReady, note = ended.getOrNull())
|
onSessionReady()
|
||||||
}
|
}
|
||||||
|
.onFailure { failConflict(it) }
|
||||||
ConflictAction.ABORT -> {
|
|
||||||
val aborted = repo.abortSession(conflict.sessionNum, MISOPERATION_PHRASE)
|
|
||||||
if (aborted.isFailure) {
|
|
||||||
failConflict(aborted.exceptionOrNull() ?: Exception("放弃该会话失败"))
|
|
||||||
return@launch
|
|
||||||
}
|
|
||||||
_state.update { it.copy(conflictBusy = null) }
|
|
||||||
startTask(conflict.targetTaskNum, onSessionReady, note = "已放弃上一个会话,未产生任何数据")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -360,7 +335,7 @@ class SessionController(
|
|||||||
it.copy(
|
it.copy(
|
||||||
busy = false,
|
busy = false,
|
||||||
conflict = null,
|
conflict = null,
|
||||||
conflictBusy = null,
|
conflictBusy = false,
|
||||||
conflictError = null,
|
conflictError = null,
|
||||||
expectationLoaded = false,
|
expectationLoaded = false,
|
||||||
notice = note ?: it.notice,
|
notice = note ?: it.notice,
|
||||||
@@ -373,7 +348,7 @@ class SessionController(
|
|||||||
_state.update {
|
_state.update {
|
||||||
it.copy(
|
it.copy(
|
||||||
busy = false,
|
busy = false,
|
||||||
conflictBusy = null,
|
conflictBusy = false,
|
||||||
conflictError = e.message ?: "开始学习会话失败",
|
conflictError = e.message ?: "开始学习会话失败",
|
||||||
error = if (it.conflict == null) e.message ?: "开始学习会话失败" else null,
|
error = if (it.conflict == null) e.message ?: "开始学习会话失败" else null,
|
||||||
)
|
)
|
||||||
@@ -383,7 +358,7 @@ class SessionController(
|
|||||||
|
|
||||||
private fun failConflict(error: Throwable) {
|
private fun failConflict(error: Throwable) {
|
||||||
_state.update {
|
_state.update {
|
||||||
it.copy(conflictBusy = null, conflictError = error.message ?: "处理上一个会话失败,请重试")
|
it.copy(conflictBusy = false, conflictError = error.message ?: "打开这个会话失败,请重试")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -442,8 +417,5 @@ class SessionController(
|
|||||||
companion object {
|
companion object {
|
||||||
/** 误操作结束的确认语,前后端各校验一次 */
|
/** 误操作结束的确认语,前后端各校验一次 */
|
||||||
const val MISOPERATION_PHRASE = "我误操作导致开启了本次学习"
|
const val MISOPERATION_PHRASE = "我误操作导致开启了本次学习"
|
||||||
|
|
||||||
/** 开始新任务时结束旧会话留下的报告正文,让用户看得出这条报告是怎么来的 */
|
|
||||||
const val STALE_SESSION_SUMMARY = "(开始新任务时结束了这个会话,未填写学习总结)"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ 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.rememberScrollState
|
import androidx.compose.foundation.rememberScrollState
|
||||||
import androidx.compose.foundation.text.KeyboardOptions
|
import androidx.compose.foundation.text.KeyboardOptions
|
||||||
import androidx.compose.foundation.verticalScroll
|
import androidx.compose.foundation.verticalScroll
|
||||||
@@ -117,7 +118,7 @@ fun LoginScreen(
|
|||||||
) {
|
) {
|
||||||
if (loading) {
|
if (loading) {
|
||||||
CircularProgressIndicator(
|
CircularProgressIndicator(
|
||||||
modifier = Modifier.height(18.dp),
|
modifier = Modifier.size(18.dp),
|
||||||
strokeWidth = 2.dp,
|
strokeWidth = 2.dp,
|
||||||
color = MaterialTheme.colorScheme.onPrimary,
|
color = MaterialTheme.colorScheme.onPrimary,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ 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.lazy.LazyColumn
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
import androidx.compose.foundation.lazy.items
|
import androidx.compose.foundation.lazy.items
|
||||||
import androidx.compose.material3.Card
|
import androidx.compose.material3.Card
|
||||||
@@ -92,7 +93,7 @@ fun ReportsScreen(
|
|||||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
if (loading) CircularProgressIndicator(modifier = Modifier.height(18.dp), strokeWidth = 2.dp)
|
if (loading) CircularProgressIndicator(modifier = Modifier.size(18.dp), strokeWidth = 2.dp)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ 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.rememberScrollState
|
import androidx.compose.foundation.rememberScrollState
|
||||||
import androidx.compose.foundation.verticalScroll
|
import androidx.compose.foundation.verticalScroll
|
||||||
import androidx.compose.material3.AlertDialog
|
import androidx.compose.material3.AlertDialog
|
||||||
@@ -99,7 +100,7 @@ fun SessionScreen(
|
|||||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
if (state.busy) CircularProgressIndicator(modifier = Modifier.height(18.dp), strokeWidth = 2.dp)
|
if (state.busy) CircularProgressIndicator(modifier = Modifier.size(18.dp), strokeWidth = 2.dp)
|
||||||
}
|
}
|
||||||
|
|
||||||
Column(
|
Column(
|
||||||
@@ -230,11 +231,8 @@ fun SessionScreen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state.error != null) {
|
if (state.busy) {
|
||||||
Text(state.error, color = MaterialTheme.colorScheme.error, style = MaterialTheme.typography.bodySmall)
|
Text("正在与服务器同步…", style = MaterialTheme.typography.bodySmall)
|
||||||
}
|
|
||||||
if (state.notice != null) {
|
|
||||||
Text(state.notice, color = MaterialTheme.colorScheme.secondary, style = MaterialTheme.typography.bodySmall)
|
|
||||||
}
|
}
|
||||||
Spacer(Modifier.height(24.dp))
|
Spacer(Modifier.height(24.dp))
|
||||||
}
|
}
|
||||||
@@ -399,7 +397,7 @@ private fun EndSessionDialog(
|
|||||||
if (state.draftLoading) {
|
if (state.draftLoading) {
|
||||||
Spacer(Modifier.height(8.dp))
|
Spacer(Modifier.height(8.dp))
|
||||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||||
CircularProgressIndicator(modifier = Modifier.height(16.dp), strokeWidth = 2.dp)
|
CircularProgressIndicator(modifier = Modifier.size(16.dp), strokeWidth = 2.dp)
|
||||||
Text(
|
Text(
|
||||||
" AI 正在根据 ${state.fragments.size} 条碎片生成草稿,已等待 ${state.draftSeconds} 秒",
|
" AI 正在根据 ${state.fragments.size} 条碎片生成草稿,已等待 ${state.draftSeconds} 秒",
|
||||||
style = MaterialTheme.typography.bodySmall,
|
style = MaterialTheme.typography.bodySmall,
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ fun SettingsScreen(
|
|||||||
onBack: () -> Unit,
|
onBack: () -> Unit,
|
||||||
) {
|
) {
|
||||||
var draft by remember { mutableStateOf(baseUrl) }
|
var draft by remember { mutableStateOf(baseUrl) }
|
||||||
var saved by remember { mutableStateOf(false) }
|
|
||||||
|
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
@@ -45,10 +44,7 @@ fun SettingsScreen(
|
|||||||
|
|
||||||
OutlinedTextField(
|
OutlinedTextField(
|
||||||
value = draft,
|
value = draft,
|
||||||
onValueChange = {
|
onValueChange = { draft = it },
|
||||||
draft = it
|
|
||||||
saved = false
|
|
||||||
},
|
|
||||||
label = { Text("API 地址") },
|
label = { Text("API 地址") },
|
||||||
singleLine = true,
|
singleLine = true,
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
@@ -59,12 +55,9 @@ fun SettingsScreen(
|
|||||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||||
)
|
)
|
||||||
Button(
|
Button(
|
||||||
onClick = {
|
onClick = { onSave(draft.trim()) },
|
||||||
onSave(draft.trim())
|
|
||||||
saved = true
|
|
||||||
},
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
) { Text(if (saved) "已保存" else "保存") }
|
) { Text("保存") }
|
||||||
|
|
||||||
Spacer(Modifier.height(8.dp))
|
Spacer(Modifier.height(8.dp))
|
||||||
TextButton(onClick = onLogout, modifier = Modifier.fillMaxWidth()) {
|
TextButton(onClick = onLogout, modifier = Modifier.fillMaxWidth()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user