feat: LPT Android 客户端首版(学习会话 + 悬浮窗)

This commit is contained in:
2026-10-29 19:44:40 +08:00
commit e1d4bba217
39 changed files with 3514 additions and 0 deletions
@@ -0,0 +1,143 @@
package com.catshark.lpt.data
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.JsonElement
/** lpt-be 的统一响应包装:{ code, message, data } */
@Serializable
data class ApiEnvelope<T>(
val code: Int = 0,
val message: String? = null,
val data: T? = null,
)
@Serializable
data class LoginRequest(
val username: String,
val password: String,
)
@Serializable
data class TaskItem(
val id: Long = 0,
val taskNum: String = "",
val taskName: String = "",
val taskDescription: String? = null,
val materialUrl: String? = null,
val taskPriority: Double = 0.0,
val lastLearningStatus: String? = null,
)
@Serializable
data class TaskPage(
val records: List<TaskItem> = emptyList(),
val total: Int = 0,
val size: Int = 0,
val current: Int = 0,
val pages: Int = 0,
)
@Serializable
data class SessionDetail(
val sessionNum: String = "",
val taskNum: String? = null,
val taskName: String? = null,
val taskId: Long? = null,
val materialUrl: String? = null,
val startTime: String? = null,
val lastStartTime: String? = null,
val endTime: String? = null,
val actualTime: Double = 0.0,
val effectiveTime: Double = 0.0,
val effectivenessRatio: Double = 0.0,
val sessionState: String = "",
val pointerPosition: Double = 0.0,
val systemMessage: String? = null,
val autoConverged: Boolean = false,
)
@Serializable
data class ActiveSession(
val taskNum: String = "",
val sessionNum: String = "",
val taskName: String? = null,
val sessionState: String? = null,
val autoConverged: Boolean = false,
)
@Serializable
data class Expectation(
val description: String = "",
)
@Serializable
data class ExpectationRequest(
val description: String,
)
@Serializable
data class EndSessionRequest(
/** 旧版后端(部署版)要的单段报告正文 */
val content: String? = null,
val sessionSummary: String? = null,
val expectationVerdict: String? = null,
val freeSummary: String? = null,
)
@Serializable
data class AbortRequest(
val confirmation: String,
)
@Serializable
data class CreateFragmentRequest(
/** 新版后端(本地源码)用 contextNum;旧版后端(部署版)用 sessionNum,两个都发 */
val contextNum: String,
val sessionNum: String,
val content: String,
)
@Serializable
data class FragmentItem(
val id: Int = 0,
val contextNum: String = "",
val contextType: String = "SESSION",
val ownerTaskNum: String? = null,
val content: String = "",
val createdTime: String? = null,
)
/** 结束会话时提交的三段报告文本 */
data class ReportSections(
val sessionSummary: String,
val expectationVerdict: String,
val freeSummary: String,
) {
val allBlank: Boolean
get() = sessionSummary.isBlank() && expectationVerdict.isBlank() && freeSummary.isBlank()
/**
* 旧版后端(部署版)只要一段 content。把三段拼成一段,并保留小标题,
* 这样旧后端的报告页也能看出结构;全空时给一个占位,避免被「请填写学习报告内容」拦下。
*/
fun asLegacyContent(): String = buildString {
if (sessionSummary.isNotBlank()) appendLine("【会话摘要】$sessionSummary")
if (expectationVerdict.isNotBlank()) appendLine("【预期达成判断】$expectationVerdict")
if (freeSummary.isNotBlank()) appendLine("【自由总结】$freeSummary")
}.trim().ifBlank { "(在手机上结束了本次学习,未填写总结)" }
}
/** 从登录响应里取 token:线上实际返回纯字符串,源码契约是 {token, aiAdmin},两者都兼容 */
fun extractToken(element: JsonElement?): String? {
if (element == null) return null
return when {
element is JsonElement && element.toString().trim().startsWith("\"") ->
element.toString().trim().trim('"')
else -> {
val obj = element as? kotlinx.serialization.json.JsonObject
obj?.get("token")?.let { token ->
if (token.toString().trim().startsWith("\"")) token.toString().trim().trim('"') else token.toString()
}
}
}
}