docs: add design spec for temp call gid cache and callbacks

This commit is contained in:
fengge 2026-07-06 12:42:11 +08:00
parent d7e9b29513
commit bfa19d36ac
1 changed files with 60 additions and 0 deletions

View File

@ -0,0 +1,60 @@
# 临时群组界面状态缓存与前端接口回调设计规约 (Design Spec)
## 1. 需求概述
为 StandAPP 临时呼叫功能增加群组锁定状态的缓存与回调机制:
1. **创建界面**:缓存当前的临时群十六进制 GID并通知前端页面调用 JS 接口 `startPullGroupLock(gid)`
2. **销毁界面**:清除缓存的临时群 GID并通知前端页面调用 JS 接口 `endPullGroupLock()`
3. **查询接口**:提供一个新的原生桥接方法 `getTempGroupId` 供前端 JS 主动查询当前在临时群的十六进制 GID。
4. **演示页面**:修改 `print_demo.html` 演示接收回调通知,并添加按钮演示查询当前临时群 GID。
## 2. 方案设计
### 2.1 临时群 GID 缓存逻辑 (`TempCallActivity.kt`)
* **静态成员变量**:在 `TempCallActivity.Companion` 中定义 `@Volatile var currentTempGroupId: String = ""`
* **创建逻辑 (`onCreate`)**
* 获取 `intent.getStringExtra("group_name")`(即临时群组名称,如 "临时群组1" )。
* 将名称使用 `SendAtUtil.str2HexStr(name)` 转为十六进制字符串(如 `"D5E1CAE6..."`),并存入 `currentTempGroupId`
* 如果 `intent` 直接传了 `group_id`,可以直接使用;如果没有,则使用上述十六进制 GID 作为 fallback。
* 调用:
```kotlin
MainActivity.executeJs("if(window.startPullGroupLock){ window.startPullGroupLock('$currentTempGroupId'); }")
```
* **销毁逻辑 (`onDestroy` / `clearMinimizedState`)**
* 销毁时如果 `!isMinimized`,则清除 `currentTempGroupId = ""`
* 发生真实销毁时调用:
```kotlin
MainActivity.executeJs("if(window.endPullGroupLock){ window.endPullGroupLock(); }")
```
### 2.2 原生桥接接口增加 (`AndroidInterface.kt`)
* 在 `dispatch` 方法的 `when(method)` 分支中增加:
* `"getTempGroupId" -> getTempGroupId()`
* 实现 `getTempGroupId` 接口:
```kotlin
fun getTempGroupId(): String {
return TempCallActivity.currentTempGroupId
}
```
### 2.3 演示页面修改 (`print_demo.html`)
* **注册回调方法**
```javascript
window.startPullGroupLock = function(gid) {
showPttResult("收到临时群锁定回调 startPullGroupLock, GID: " + gid);
};
window.endPullGroupLock = function() {
showPttResult("收到临时群解锁回调 endPullGroupLock");
};
```
* **新增主动查询按钮**
* 在 PTT 功能区域内添加一个按钮 “查询临时群 GID”
```html
<button onclick="queryTempGroupId()" class="ws-btn">查询当前临时群 GID</button>
```
* JS 触发逻辑:
```javascript
function queryTempGroupId() {
var gid = window.android.getTempGroupId();
showPttResult("当前在临时群的 GID: " + (gid || "无"));
}
```