From 20bebb586a2fbd1a9e4d1a815c6371122b04a772 Mon Sep 17 00:00:00 2001 From: YuKongA <70465933+YuKongA@users.noreply.github.com> Date: Sat, 16 Dec 2023 10:51:54 +0800 Subject: [PATCH] MainActivity: Only read prefs onCreate --- .../java/top/yukonga/update/logic/utils/LoginUtils.kt | 2 +- app/src/main/java/top/yukonga/update/ui/MainActivity.kt | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/top/yukonga/update/logic/utils/LoginUtils.kt b/app/src/main/java/top/yukonga/update/logic/utils/LoginUtils.kt index 76f21019..7aad9eac 100644 --- a/app/src/main/java/top/yukonga/update/logic/utils/LoginUtils.kt +++ b/app/src/main/java/top/yukonga/update/logic/utils/LoginUtils.kt @@ -57,7 +57,7 @@ class LoginUtils { if (description != "成功") { withContext(Dispatchers.Main) { - Toast.makeText(context, auth["description"].toString(), Toast.LENGTH_SHORT).show() + Toast.makeText(context, description, Toast.LENGTH_SHORT).show() } return false } diff --git a/app/src/main/java/top/yukonga/update/ui/MainActivity.kt b/app/src/main/java/top/yukonga/update/ui/MainActivity.kt index 7f3d48cf..622bab14 100644 --- a/app/src/main/java/top/yukonga/update/ui/MainActivity.kt +++ b/app/src/main/java/top/yukonga/update/ui/MainActivity.kt @@ -67,6 +67,10 @@ class MainActivity : AppCompatActivity() { // Setup default device information. mainContentBinding.apply { + codeName.editText!!.setText(prefs.getString("codeName", "")) + systemVersion.editText!!.setText(prefs.getString("systemVersion", "")) + androidVersion.editText!!.setText(prefs.getString("androidVersion", "")) + (codeName.editText as? MaterialAutoCompleteTextView)?.setSimpleItems(deviceCodeList) (androidVersion.editText as? MaterialAutoCompleteTextView)?.setSimpleItems(dropDownList) } @@ -88,11 +92,6 @@ class MainActivity : AppCompatActivity() { override fun onResume() { super.onResume() mainContentBinding.apply { - - codeName.editText!!.setText(prefs.getString("codeName", "")) - systemVersion.editText!!.setText(prefs.getString("systemVersion", "")) - androidVersion.editText!!.setText(prefs.getString("androidVersion", "")) - val cookiesFile = FileUtils.readFile(this@MainActivity, "cookies.json") if (cookiesFile.isNotEmpty()) { val cookies = Gson().fromJson(cookiesFile, Map::class.java)