功能优化

This commit is contained in:
2025-09-17 14:21:20 +08:00
parent 77b89c7009
commit 16e6c64992
4 changed files with 22 additions and 7 deletions
@@ -21,6 +21,8 @@ import java.util.concurrent.TimeUnit
object HttpUtil { object HttpUtil {
var loopGetToken = true
fun runMainThread(action: () -> Unit) { fun runMainThread(action: () -> Unit) {
Handler(Looper.getMainLooper()).post { Handler(Looper.getMainLooper()).post {
action() action()
@@ -39,7 +41,7 @@ object HttpUtil {
.apply { .apply {
if (header != null) { if (header != null) {
header.forEach { header.forEach {
addHeader(it.value, it.value) addHeader(it.key, it.value)
} }
} else { } else {
val token = getToken() val token = getToken()
@@ -176,7 +178,8 @@ object HttpUtil {
} }
if (baseReq.code != 200) { if (baseReq.code != 200) {
doFailure(baseReq.code, baseReq.message) doFailure(baseReq.code, baseReq.message)
if (baseReq.code == 500 || baseReq.code == 401) { //baseReq.code == 500 ||
if (baseReq.code == 401 && loopGetToken) {
exeTokenThread() exeTokenThread()
} }
return@runCatching return@runCatching
@@ -43,14 +43,14 @@ class HomeActivity : BaseActivity() {
binding = ActivityHomeBinding.inflate(layoutInflater) binding = ActivityHomeBinding.inflate(layoutInflater)
setContentView(binding.root) setContentView(binding.root)
setHeaderBackground(isHomePage = true) setHeaderBackground(isHomePage = true)
binding.radioGroup?.setOnCheckedChangeListener { group, checkedId -> binding.radioGroup.setOnCheckedChangeListener { group, checkedId ->
if (checkedId == R.id.radioSw) { if (checkedId == R.id.radioSw) {
BaseApp.canteenId = "1678234139391512577" BaseApp.canteenId = "1678234139391512577"
} else { } else {
BaseApp.canteenId = "0" BaseApp.canteenId = "0"
} }
} }
binding.radioGroup?.check(R.id.radioZk) // binding.radioGroup.check(R.id.radioZk)
initRecyclerView() initRecyclerView()
// HttpUtil.getAppToken() // HttpUtil.getAppToken()
// WeightUtil.connect { connect -> // WeightUtil.connect { connect ->
@@ -166,5 +166,12 @@ class HomeActivity : BaseActivity() {
} }
} }
@Deprecated("Deprecated in Java")
@SuppressLint("GestureBackNavigation", "MissingSuperCall")
override fun onBackPressed() {
//super.onBackPressed()
//当前页面不允许返回
//dialog = toast("不允许返回操作")
}
} }
@@ -54,10 +54,12 @@ class InitActivity : BaseActivity() {
BaseApp.configUrl = UrlConfig.BASE_URL BaseApp.configUrl = UrlConfig.BASE_URL
BaseApp.canteenId = "0" BaseApp.canteenId = "0"
// TODO: 以上保存deviceId用于临时使用,后续改为下面注释方式 // TODO: 以上保存deviceId用于临时使用,后续改为下面注释方式
// var deviceId = AppUtil.getUDID(this) // var deviceId = AppUtil.getUDID(this)
// Log.d(TAG, "onCreate: deviceId=$deviceId") // Log.d(TAG, "onCreate: deviceId=$deviceId")
//// deviceId = "39a7abdd06b3c7ab" //// deviceId = "39a7abdd06b3c7ab"
//// deviceId = "3ea47dc0-3cf0-3c2f-909c-265a9a65572e" //// deviceId = "3ea47dc0-3cf0-3c2f-909c-265a9a65572e"
//// deviceId = "6ce7cd59-b875-38b2-b73d-88a570be3212"
// //
// BaseApp.deviceId = deviceId // BaseApp.deviceId = deviceId
// //
@@ -71,16 +73,17 @@ class InitActivity : BaseActivity() {
// initConfig() // initConfig()
// return // return
// } // }
binding.ivQrCode.invisible() binding.ivQrCode.invisible()
binding.btnInit.invisible() binding.btnInit.invisible()
initViewModel() initViewModel()
WeightUtil.init() WeightUtil.init()
// WeightUtil.connect {}
WeightUtil.getWeight() WeightUtil.getWeight()
WeightUtil.startContinuousRead() WeightUtil.startContinuousRead()
HttpUtil.getAppToken() HttpUtil.getAppToken()
HttpUtil.loopGetToken = true
countDown() countDown()
} }
@@ -142,7 +145,8 @@ class InitActivity : BaseActivity() {
// 倒计时结束执行跳转 // 倒计时结束执行跳转
if (it == 1) { if (it == 1) {
startNextPage() startNextPage()
finish() //保留初始化页面,不关闭
// finish()
} }
} }
} }
@@ -156,6 +160,7 @@ class InitActivity : BaseActivity() {
) )
) )
binding.btnInit.setOnClickListener { binding.btnInit.setOnClickListener {
HttpUtil.loopGetToken = false
getDeviceConfig() getDeviceConfig()
} }
} }
@@ -181,6 +186,7 @@ class InitActivity : BaseActivity() {
toast("初始化设备失败,请稍后重试") toast("初始化设备失败,请稍后重试")
return@get return@get
} }
HttpUtil.loopGetToken = true
SpTool.put(SpTool.DEVICE_CONFIG_CACHE, data) SpTool.put(SpTool.DEVICE_CONFIG_CACHE, data)
startActivity<HomeActivity>() startActivity<HomeActivity>()
finish() finish()
@@ -59,7 +59,6 @@
android:id="@+id/radioZk" android:id="@+id/radioZk"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="match_parent"
android:checked="true"
android:paddingStart="10dp" android:paddingStart="10dp"
android:paddingEnd="10dp" android:paddingEnd="10dp"
android:text="总库食堂" android:text="总库食堂"