缓存上次加入的群组

This commit is contained in:
fengge 2026-06-30 12:25:20 +08:00
parent 15b04be06f
commit 71ba9f3e77
3 changed files with 24 additions and 0 deletions

View File

@ -195,6 +195,9 @@ class AndroidInterface(private val activity: MainActivity) {
fun pttJumpGroup(gid: String) {
Timber.tag("PTT").d("pttJumpGroup: gid=%s", gid)
SendAtUtil.jumpGroup(gid)
if (gid.isNotEmpty()) {
AppConfig.setLastGroupId(activity, gid)
}
}
fun getPrinterStatus(): String {

View File

@ -11,6 +11,7 @@ object AppConfig {
private const val KEY_USERNAME = "saved_username"
private const val KEY_PASSWORD = "saved_password"
private const val KEY_ACCESS_TOKEN = "access_token"
private const val KEY_LAST_GROUP_ID = "last_group_id"
// 默认配置
const val DEFAULT_SERVER_URL = "https://template.gyouzhe.com"
@ -77,4 +78,12 @@ object AppConfig {
fun setAccessToken(context: Context, token: String) {
getPrefs(context).edit().putString(KEY_ACCESS_TOKEN, token).apply()
}
fun getLastGroupId(context: Context): String {
return getPrefs(context).getString(KEY_LAST_GROUP_ID, "") ?: ""
}
fun setLastGroupId(context: Context, groupId: String) {
getPrefs(context).edit().putString(KEY_LAST_GROUP_ID, groupId).apply()
}
}

View File

@ -47,6 +47,18 @@ class MainActivity : AppCompatActivity() {
fun onPttLoginSuccess() {
Timber.tag("MainActivity").d("onPttLoginSuccess called from Native")
executeJs("onPttLoginSuccess()")
instance?.let { ctx ->
val lastGroupId = AppConfig.getLastGroupId(ctx)
if (lastGroupId.isNotEmpty()) {
Timber.tag("PTT").d("Auto-jumping to last joined group: %s after delay", lastGroupId)
ctx.runOnUiThread {
android.os.Handler(android.os.Looper.getMainLooper()).postDelayed({
instance?.pttInterface?.pttJumpGroup(lastGroupId)
}, 2000)
}
}
}
}
// 硬件按键触发