- 新增 tvFoodType TextView 显示食品分类 - 将搜索框可见性从 gone 改为 visible - 添加 FoodItem 和 FoodType 数据模型 - 添加 SearchFoodRequest 请求模型 - 在 ApiServiceV3 中新增 searchFood 接口 - 在 NetViewModelV3 中新增 searchFood 方法 - 修改 PutSlotRequest 模型字段为可空类型并添加 vegTypeId - 更新 HomeV3Activity 中行列计算逻辑 - 缩短商品数据同步间隔时间 - 修改 InitActivity 中的基础URL配置 - 将 PendingInboundAdapter 适配器改为使用 FoodItem 类型 - 在 ShelfV3Activity 中实现净菜分类选择对话框功能 - 添加 ChipSelectDialog 自定义对话框组件 - 添加 chip 相关的颜色资源文件 - 实现搜索功能替换原有的待入库查询逻辑
179 lines
5.4 KiB
Kotlin
179 lines
5.4 KiB
Kotlin
package com.sw.scalefusion.shelf
|
|
|
|
import android.content.Intent
|
|
import android.graphics.Color
|
|
import android.os.Bundle
|
|
import android.os.Handler
|
|
import android.os.Looper
|
|
import android.os.SystemClock
|
|
import android.util.Log
|
|
import android.view.animation.RotateAnimation
|
|
import androidx.activity.addCallback
|
|
import androidx.core.graphics.toColorInt
|
|
import com.shuwei.intelligent.shelves.App
|
|
import com.shuwei.intelligent.shelves.GlobalData
|
|
import com.shuwei.intelligent.shelves.base.BaseActivity
|
|
import com.shuwei.intelligent.shelves.databinding.ActivityInitBinding
|
|
import com.shuwei.intelligent.shelves.utils.AppUtil
|
|
import com.shuwei.intelligent.shelves.utils.NetworkUtils
|
|
import com.shuwei.intelligent.shelves.utils.SpTool
|
|
import com.shuwei.intelligent.shelves.utils.ext.invisible
|
|
import com.shuwei.intelligent.shelves.utils.ext.startActivity
|
|
|
|
class InitActivity : BaseActivity() {
|
|
companion object {
|
|
const val TAG = "InitActivity"
|
|
}
|
|
|
|
private lateinit var binding: ActivityInitBinding
|
|
|
|
private val handler = Handler(Looper.getMainLooper())
|
|
private var startTime = 0L
|
|
private var lastNetworkCheckTime = 0L
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
super.onCreate(savedInstanceState)
|
|
binding = ActivityInitBinding.inflate(layoutInflater)
|
|
setContentView(binding.root)
|
|
|
|
App.deviceId = AppUtil.getUDID(this)
|
|
// TODO: 测试设备号
|
|
// App.deviceId = "d369f9b0-1c5b-3066-ba72-988e1449cecc"
|
|
// App.deviceId = "25b777a9-6298-30d3-a5f8-3b3eef2a50f7"
|
|
// App.deviceId = "505ce1b1-facc-3eb2-855a-3dadda5ba358"
|
|
Log.d(TAG, "onCreate: deviceId = ${App.deviceId}")
|
|
SpTool.put(SpTool.DEVICE_ID, App.deviceId)
|
|
// val appBaseUrl = SpTool.baseUrl
|
|
// if (!appBaseUrl.isBlank()) {
|
|
// GlobalData.appBaseUrl = appBaseUrl
|
|
// } else {
|
|
// GlobalData.appBaseUrl = GlobalData.PROD_BASE_URL
|
|
// }
|
|
GlobalData.appBaseUrl = GlobalData.TEST_BASE_URL
|
|
App.canteenId = "0"
|
|
|
|
binding.ivQrCode.invisible()
|
|
binding.btnInit.invisible()
|
|
|
|
initViews()
|
|
// 禁用返回键
|
|
onBackPressedDispatcher.addCallback(this) {}
|
|
}
|
|
|
|
/**
|
|
* 初始化控件事件
|
|
*/
|
|
private fun initViews() {
|
|
binding.btnConnectNetwork.setOnClickListener {
|
|
openNetworkSettings()
|
|
}
|
|
|
|
startLoadingAnimation()
|
|
}
|
|
|
|
/**
|
|
* 启动加载动画 - ImageView 持续旋转
|
|
*/
|
|
private fun startLoadingAnimation() {
|
|
val rotateAnimation = RotateAnimation(
|
|
0f, 360f,
|
|
RotateAnimation.RELATIVE_TO_SELF, 0.5f,
|
|
RotateAnimation.RELATIVE_TO_SELF, 0.5f
|
|
).apply {
|
|
duration = 1200
|
|
repeatCount = RotateAnimation.INFINITE
|
|
repeatMode = RotateAnimation.RESTART
|
|
}
|
|
binding.ivLoading.startAnimation(rotateAnimation)
|
|
}
|
|
|
|
override fun onResume() {
|
|
super.onResume()
|
|
if (NetworkUtils.isNetworkConnected(this)) {
|
|
navigateToHome()
|
|
return
|
|
}
|
|
startCountdown()
|
|
}
|
|
|
|
override fun onPause() {
|
|
super.onPause()
|
|
handler.removeCallbacksAndMessages(null)
|
|
}
|
|
|
|
/**
|
|
* 启动 60 秒倒计时
|
|
*/
|
|
private fun startCountdown() {
|
|
startTime = SystemClock.elapsedRealtime()
|
|
lastNetworkCheckTime = 0
|
|
binding.llNetwork.setBackgroundColor(Color.TRANSPARENT)
|
|
binding.llLoading.visibility = android.view.View.VISIBLE
|
|
binding.llNetworkButton.visibility = android.view.View.GONE
|
|
binding.tvCountdown.text = "60秒"
|
|
scheduleCountdown()
|
|
}
|
|
|
|
/**
|
|
* 定时更新倒计时
|
|
*/
|
|
private fun scheduleCountdown() {
|
|
handler.postDelayed({
|
|
val elapsedTime = SystemClock.elapsedRealtime() - startTime
|
|
val remainingTime = 60 - (elapsedTime / 1000).toInt()
|
|
val currentNetworkCheckTime = (elapsedTime / 1000).toInt()
|
|
|
|
if (currentNetworkCheckTime > 0 && currentNetworkCheckTime % 10 == 0 && currentNetworkCheckTime != lastNetworkCheckTime.toInt()) {
|
|
lastNetworkCheckTime = currentNetworkCheckTime.toLong()
|
|
checkNetworkConnection()
|
|
}
|
|
|
|
if (remainingTime > 0) {
|
|
binding.tvCountdown.text = "${remainingTime}秒"
|
|
scheduleCountdown()
|
|
} else {
|
|
if (NetworkUtils.isNetworkConnected(this)) {
|
|
navigateToHome()
|
|
} else {
|
|
showNetworkButton()
|
|
}
|
|
}
|
|
}, 100)
|
|
}
|
|
|
|
/**
|
|
* 检测网络连接
|
|
*/
|
|
private fun checkNetworkConnection() {
|
|
if (NetworkUtils.isNetworkConnected(this)) {
|
|
handler.removeCallbacksAndMessages(null)
|
|
navigateToHome()
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 跳转到 HomeV3Activity
|
|
*/
|
|
private fun navigateToHome() {
|
|
startActivity<HomeV3Activity>()
|
|
finish()
|
|
}
|
|
|
|
/**
|
|
* 显示"连接网络"按钮
|
|
*/
|
|
private fun showNetworkButton() {
|
|
binding.llNetwork.setBackgroundColor("#5C77F7".toColorInt())
|
|
binding.llLoading.visibility = android.view.View.GONE
|
|
binding.llNetworkButton.visibility = android.view.View.VISIBLE
|
|
}
|
|
|
|
/**
|
|
* 打开系统网络设置页面
|
|
*/
|
|
private fun openNetworkSettings() {
|
|
val intent = Intent(android.provider.Settings.ACTION_WIFI_SETTINGS)
|
|
startActivity(intent)
|
|
}
|
|
}
|