缓存上次加入的群组
This commit is contained in:
parent
15b04be06f
commit
71ba9f3e77
|
|
@ -195,6 +195,9 @@ class AndroidInterface(private val activity: MainActivity) {
|
||||||
fun pttJumpGroup(gid: String) {
|
fun pttJumpGroup(gid: String) {
|
||||||
Timber.tag("PTT").d("pttJumpGroup: gid=%s", gid)
|
Timber.tag("PTT").d("pttJumpGroup: gid=%s", gid)
|
||||||
SendAtUtil.jumpGroup(gid)
|
SendAtUtil.jumpGroup(gid)
|
||||||
|
if (gid.isNotEmpty()) {
|
||||||
|
AppConfig.setLastGroupId(activity, gid)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getPrinterStatus(): String {
|
fun getPrinterStatus(): String {
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ object AppConfig {
|
||||||
private const val KEY_USERNAME = "saved_username"
|
private const val KEY_USERNAME = "saved_username"
|
||||||
private const val KEY_PASSWORD = "saved_password"
|
private const val KEY_PASSWORD = "saved_password"
|
||||||
private const val KEY_ACCESS_TOKEN = "access_token"
|
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"
|
const val DEFAULT_SERVER_URL = "https://template.gyouzhe.com"
|
||||||
|
|
@ -77,4 +78,12 @@ object AppConfig {
|
||||||
fun setAccessToken(context: Context, token: String) {
|
fun setAccessToken(context: Context, token: String) {
|
||||||
getPrefs(context).edit().putString(KEY_ACCESS_TOKEN, token).apply()
|
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()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,18 @@ class MainActivity : AppCompatActivity() {
|
||||||
fun onPttLoginSuccess() {
|
fun onPttLoginSuccess() {
|
||||||
Timber.tag("MainActivity").d("onPttLoginSuccess called from Native")
|
Timber.tag("MainActivity").d("onPttLoginSuccess called from Native")
|
||||||
executeJs("onPttLoginSuccess()")
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 硬件按键触发
|
// 硬件按键触发
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue