Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8145eb588b | ||
|
|
c91d5656aa | ||
|
|
532b22a5c6 | ||
|
|
e9d04bfb70 | ||
|
|
afba5220b3 | ||
|
|
4ace12c6c7 | ||
|
|
ee36869003 | ||
|
|
c23c215941 | ||
|
|
3d67dd2c2d | ||
|
|
133f309d4b | ||
|
|
3e5c7c6caa | ||
|
|
04fe3ec2c1 | ||
|
|
9a795b9710 | ||
|
|
fff6a2a3b3 | ||
|
|
3b79f6d6aa | ||
|
|
76b67b545d | ||
|
|
3bd60990b9 | ||
|
|
a116c4fc6c | ||
|
|
40cd27fa7b | ||
|
|
e6cfc4dff2 | ||
|
|
85903eb646 |
@@ -44,6 +44,7 @@ android {
|
|||||||
}
|
}
|
||||||
buildFeatures {
|
buildFeatures {
|
||||||
viewBinding = true
|
viewBinding = true
|
||||||
|
buildConfig = true
|
||||||
}
|
}
|
||||||
|
|
||||||
ndkVersion = "29.0.13846066"
|
ndkVersion = "29.0.13846066"
|
||||||
@@ -67,10 +68,10 @@ dependencies {
|
|||||||
|
|
||||||
implementation("io.github.jeadyx:kmp-serialport:1.0.0")
|
implementation("io.github.jeadyx:kmp-serialport:1.0.0")
|
||||||
|
|
||||||
// 基础依赖包,必须要依赖
|
// // 基础依赖包,必须要依赖
|
||||||
implementation("com.geyifeng.immersionbar:immersionbar:3.2.2")
|
// implementation("com.geyifeng.immersionbar:immersionbar:3.2.2")
|
||||||
// kotlin扩展(可选)
|
// // kotlin扩展(可选)
|
||||||
implementation("com.geyifeng.immersionbar:immersionbar-ktx:3.2.2")
|
// implementation("com.geyifeng.immersionbar:immersionbar-ktx:3.2.2")
|
||||||
|
|
||||||
implementation("com.squareup.okhttp3:okhttp:4.9.1")
|
implementation("com.squareup.okhttp3:okhttp:4.9.1")
|
||||||
implementation("com.squareup.okhttp3:logging-interceptor:4.9.1")
|
implementation("com.squareup.okhttp3:logging-interceptor:4.9.1")
|
||||||
|
|||||||
@@ -43,7 +43,7 @@
|
|||||||
android:name=".activity.ShelfActivity"
|
android:name=".activity.ShelfActivity"
|
||||||
android:screenOrientation="portrait"
|
android:screenOrientation="portrait"
|
||||||
tools:ignore="DiscouragedApi,LockedOrientationActivity" />
|
tools:ignore="DiscouragedApi,LockedOrientationActivity" />
|
||||||
<activity android:name="com.shuwei.intelligent.shelves.activity.SettingActivity" />
|
<!-- <activity android:name="com.shuwei.intelligent.shelves.activity.SettingActivity" />-->
|
||||||
<activity android:name="com.shuwei.intelligent.shelves.activity.LogActivity" />
|
<activity android:name="com.shuwei.intelligent.shelves.activity.LogActivity" />
|
||||||
|
|
||||||
<receiver
|
<receiver
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package com.shuwei.intelligent.shelves
|
||||||
|
|
||||||
|
object GlobalData {
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * 设备id
|
||||||
|
// */
|
||||||
|
// var deviceId: String = ""
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * app版本号
|
||||||
|
// */
|
||||||
|
// var appVersion: String = "1"
|
||||||
|
|
||||||
|
var appBaseUrl: String = ""
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 具体业务 BaseUrl
|
||||||
|
*/
|
||||||
|
const val TEST_BASE_URL = "http://192.168.1.201:14801"
|
||||||
|
const val UAT_BASE_URL = "https://dev.yixiong-tech.com:8081"
|
||||||
|
const val PROD_BASE_URL = "https://api.dm.yixiong-tech.com:8443"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 全局常量
|
||||||
|
*/
|
||||||
|
object Constants {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* key
|
||||||
|
*/
|
||||||
|
object GlobalKey {
|
||||||
|
const val KEY_BASE_URL = "baseUrlKey"
|
||||||
|
}
|
||||||
@@ -3,11 +3,11 @@ package com.shuwei.intelligent.shelves.activity
|
|||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
import android.util.Log
|
import androidx.activity.addCallback
|
||||||
import android.util.SparseIntArray
|
|
||||||
import androidx.activity.viewModels
|
import androidx.activity.viewModels
|
||||||
import androidx.lifecycle.Lifecycle
|
import androidx.lifecycle.Lifecycle
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
@@ -25,126 +25,132 @@ import com.shuwei.intelligent.shelves.model.SendWeightEvent
|
|||||||
import com.shuwei.intelligent.shelves.model.ShelfBody
|
import com.shuwei.intelligent.shelves.model.ShelfBody
|
||||||
import com.shuwei.intelligent.shelves.model.ShelfModel
|
import com.shuwei.intelligent.shelves.model.ShelfModel
|
||||||
import com.shuwei.intelligent.shelves.model.ShelfResult
|
import com.shuwei.intelligent.shelves.model.ShelfResult
|
||||||
import com.shuwei.intelligent.shelves.model.WeightEvent
|
|
||||||
import com.shuwei.intelligent.shelves.net.Loading
|
import com.shuwei.intelligent.shelves.net.Loading
|
||||||
import com.shuwei.intelligent.shelves.net.NetViewModel
|
import com.shuwei.intelligent.shelves.net.NetViewModel
|
||||||
import com.shuwei.intelligent.shelves.net.RespData
|
import com.shuwei.intelligent.shelves.net.RespData
|
||||||
import com.shuwei.intelligent.shelves.net.UiState
|
import com.shuwei.intelligent.shelves.net.UiState
|
||||||
import com.shuwei.intelligent.shelves.net.apiService
|
import com.shuwei.intelligent.shelves.serial.ProtocolConstants.C_TEMP_CMD
|
||||||
|
import com.shuwei.intelligent.shelves.serial.ProtocolConstants.FOOTER
|
||||||
|
import com.shuwei.intelligent.shelves.serial.ProtocolConstants.HEADER
|
||||||
|
import com.shuwei.intelligent.shelves.serial.ProtocolConstants.LEFT_SHELF_OPEN_CMD
|
||||||
|
import com.shuwei.intelligent.shelves.serial.ProtocolConstants.RIGHT_SHELF_OPEN_CMD
|
||||||
|
import com.shuwei.intelligent.shelves.serial.ProtocolConstants.START_TEMP_CTRL_CMD
|
||||||
|
import com.shuwei.intelligent.shelves.serial.SerialFrameParser
|
||||||
import com.shuwei.intelligent.shelves.serial.SerialPortManager
|
import com.shuwei.intelligent.shelves.serial.SerialPortManager
|
||||||
import com.shuwei.intelligent.shelves.utils.HexUtils
|
import com.shuwei.intelligent.shelves.serial.SerialProtocolHandler
|
||||||
|
import com.shuwei.intelligent.shelves.utils.GridLayoutTool
|
||||||
import com.shuwei.intelligent.shelves.utils.IntervalExecutor
|
import com.shuwei.intelligent.shelves.utils.IntervalExecutor
|
||||||
import com.shuwei.intelligent.shelves.utils.binaryToHex
|
|
||||||
import com.shuwei.intelligent.shelves.utils.ext.copyTextToClipboard
|
import com.shuwei.intelligent.shelves.utils.ext.copyTextToClipboard
|
||||||
import com.shuwei.intelligent.shelves.utils.ext.gone
|
import com.shuwei.intelligent.shelves.utils.ext.gone
|
||||||
import com.shuwei.intelligent.shelves.utils.ext.toJsonString
|
import com.shuwei.intelligent.shelves.utils.ext.toJsonString
|
||||||
import com.shuwei.intelligent.shelves.utils.ext.toast
|
import com.shuwei.intelligent.shelves.utils.ext.toast
|
||||||
import com.shuwei.intelligent.shelves.utils.ext.visible
|
import com.shuwei.intelligent.shelves.utils.ext.visible
|
||||||
import com.shuwei.intelligent.shelves.utils.hexToBinary
|
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.runBlocking
|
||||||
import org.greenrobot.eventbus.EventBus
|
import org.greenrobot.eventbus.EventBus
|
||||||
import org.greenrobot.eventbus.Subscribe
|
import org.greenrobot.eventbus.Subscribe
|
||||||
import org.greenrobot.eventbus.ThreadMode
|
import org.greenrobot.eventbus.ThreadMode
|
||||||
import java.text.SimpleDateFormat
|
|
||||||
import java.util.Date
|
|
||||||
import java.util.Locale
|
|
||||||
|
|
||||||
class HomeActivity : BaseActivity() {
|
class HomeActivity : BaseActivity() {
|
||||||
|
|
||||||
companion object {
|
companion object {}
|
||||||
private const val TAG = "HomeActivity"
|
|
||||||
private const val LOG_PREFIX = "receiveSerialPortData:收到"
|
|
||||||
|
|
||||||
private const val MM_DD_EEEE__HH_MM_SS = "MM月dd日 EEEE HH:mm:ss"
|
override val enableRightStatusMenu: Boolean = true
|
||||||
|
|
||||||
//协议头
|
// 货架列表数据
|
||||||
const val HEADER = "D6DADEDB"
|
private val list: MutableList<ShelfModel> = mutableListOf()
|
||||||
|
|
||||||
//协议尾
|
// 当前选中货架下标
|
||||||
const val FOOTER = "FFFF"
|
private var shelfIndex = 0
|
||||||
// const val ACTIVE_CMD =
|
|
||||||
// "${HEADER}000281C5D70A7D428A4FA67B50F7DACA241938938B4B9CBD73673E9C8E7F2E15062D${FOOTER}"
|
|
||||||
|
|
||||||
const val LEFT_SHELF_OPEN_CMD =
|
// 当前温度(摄氏)
|
||||||
"${HEADER}020101000000000000000000000000000000000000${FOOTER}"
|
private var showTemperatureC = "0"
|
||||||
const val RIGHT_SHELF_OPEN_CMD =
|
|
||||||
"${HEADER}020100010000000000000000000000000000000000${FOOTER}"
|
|
||||||
|
|
||||||
//const val TEMPERATURE_CMD = "${HEADER}1001${FOOTER}"
|
// 当前湿度
|
||||||
|
private var showHumidity = "0"
|
||||||
|
|
||||||
const val DEVICE_INFO_CMD = "${HEADER}0301000000000000000000000000${FOOTER}"
|
// 仅特定 deviceId 的部署点需要发送开锁指令
|
||||||
|
private fun isNeedOpenLock() = App.deviceId == "4787e213-90ab-3e32-88e0-ac271a937751"
|
||||||
|
|
||||||
const val START_TEMP_CTRL_CMD = "${HEADER}0F01360000${FOOTER}"
|
private var deviceName = ""
|
||||||
|
|
||||||
//const val START_CMD= "${HEADER}0F01050020${FOOTER}"
|
|
||||||
// const val ACTIVE_CMD = "${HEADER}000281C5D70A7D428948AD7254FADBB1516738938B4B9CBD73673E9D8E7F2E15062D$FOOTER"
|
|
||||||
// 410激活码
|
|
||||||
// const val ACTIVE_CMD = "${HEADER}000281C5D70A7D42894EA17650F5D0BB516838E7863C9ABD766C38958AFF0F3C062D${FOOTER}"
|
|
||||||
//1楼餐厅激活码
|
|
||||||
const val ACTIVE_CMD =
|
|
||||||
"${HEADER}000281C5D70A7D428B44A57454F5DACA241938938B4B9CBD73673E9C8E7FC0C4992D${FOOTER}"
|
|
||||||
|
|
||||||
//华氏温度单位
|
|
||||||
const val F_TEMP_CMD = "${HEADER}0F01390000${FOOTER}"
|
|
||||||
|
|
||||||
//摄氏温度单位
|
|
||||||
const val C_TEMP_CMD = "${HEADER}0F01390001${FOOTER}"
|
|
||||||
|
|
||||||
//开灯(开 继电器1)
|
|
||||||
const val LIGHT_CLOSE = "${HEADER}020102020102020000000000000000000000000000${FOOTER}"
|
|
||||||
const val LIGHT_OPEN = "${HEADER}020102020002020000000000000000000000000000${FOOTER}"
|
|
||||||
|
|
||||||
const val TEMPERATURE_CTRL = "${HEADER}0F01040000${FOOTER}"
|
|
||||||
|
|
||||||
val list: MutableList<ShelfModel> = mutableListOf()
|
|
||||||
val weightArray = SparseIntArray()
|
|
||||||
var shelfIndex = 0
|
|
||||||
|
|
||||||
// public fun getRealWeight():Double = weightArray[shelfIndex]?:0.0
|
|
||||||
// 温度
|
|
||||||
var showTemperatureC = "0"
|
|
||||||
|
|
||||||
// 湿度
|
|
||||||
var showHumidity = "0"
|
|
||||||
}
|
|
||||||
|
|
||||||
//401-false,1楼餐厅-true
|
|
||||||
private var isNeedOpenLock = true
|
|
||||||
|
|
||||||
private lateinit var binding: ActivityHomeBinding
|
private lateinit var binding: ActivityHomeBinding
|
||||||
|
|
||||||
private val viewModel: NetViewModel by viewModels()
|
private val viewModel: NetViewModel by viewModels()
|
||||||
|
|
||||||
@SuppressLint("NotifyDataSetChanged", "HardwareIds")
|
// 串口协议解析器,通过回调通知本 Activity
|
||||||
|
private val serialProtocolHandler =
|
||||||
|
SerialProtocolHandler(object : SerialProtocolHandler.Callback {
|
||||||
|
override fun onSendCmd(cmd: String) = sendCmd(cmd)
|
||||||
|
|
||||||
|
override fun onWeightUpdated(shelfNo: Int, weight: Int) {
|
||||||
|
if (shelfNo in 1..list.size) {
|
||||||
|
list.firstOrNull { it.deviceNo == shelfNo }?.let { model ->
|
||||||
|
model.weight = weight.toDouble()
|
||||||
|
val pos = list.indexOf(model)
|
||||||
|
shelfAdapter.notifyItemChanged(pos)
|
||||||
|
log("getWeightInfo: deviceNo=${model.deviceNo},realWeight=$weight")
|
||||||
|
EventBus.getDefault().post(SendWeightEvent(model.deviceNo, weight))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onTempReport(logMsg: String) {
|
||||||
|
updateLeftStatus(deviceName)
|
||||||
|
log(logMsg)
|
||||||
|
// if (tipDialog == null) {
|
||||||
|
// tipDialog = CommonDialog(this@HomeActivity).apply {
|
||||||
|
// dialogTitle = "温馨提示"
|
||||||
|
// confirmBlock = { logMsg.copyTextToClipboard(this@HomeActivity) }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// if (tipDialog?.isShowing == false) {
|
||||||
|
// tipDialog?.dialogContent = logMsg
|
||||||
|
// tipDialog?.show()
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onLog(message: String) = log(message)
|
||||||
|
})
|
||||||
|
|
||||||
|
private val serialFrameParser = SerialFrameParser()
|
||||||
|
|
||||||
|
@SuppressLint("NotifyDataSetChanged")
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
binding = ActivityHomeBinding.inflate(layoutInflater)
|
binding = ActivityHomeBinding.inflate(layoutInflater)
|
||||||
EventBus.getDefault().register(this)
|
EventBus.getDefault().register(this)
|
||||||
setBackground()
|
setBackground()
|
||||||
setContentView(binding.root)
|
setContentView(binding.root)
|
||||||
|
onBackPressedDispatcher.addCallback(this) {
|
||||||
|
|
||||||
// updateLeftStatus("-°C / -%")
|
}
|
||||||
updateLeftStatus("")
|
updateLeftStatus("")
|
||||||
|
|
||||||
initRecyclerView()
|
initRecyclerView()
|
||||||
|
|
||||||
|
// 串口初始化,独立协程,不阻塞网络状态监听
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
val openState = SerialPortManager.open()
|
val openState = SerialPortManager.open()
|
||||||
log("onCreate: openState=$openState")
|
log("onCreate: openState=$openState")
|
||||||
if (openState) {
|
if (openState) {
|
||||||
SerialPortManager.startReceive { data ->
|
SerialPortManager.startReceive { data ->
|
||||||
// 更新UI显示接收数据
|
// 切换到主线程协程处理串口数据
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
try {
|
runCatching { receiveSerialPortData(data) }
|
||||||
receiveSerialPortData(data)
|
.onFailure {
|
||||||
} catch (e: Exception) {
|
it.printStackTrace()
|
||||||
e.printStackTrace()
|
log("串口数据处理异常: ${it.message}")
|
||||||
|
toast("串口数据处理异常,请检查设备连接")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//SerialPortManager.send(DEVICE_INFO_CMD)
|
|
||||||
}
|
}
|
||||||
repeatOnLifecycle(Lifecycle.State.CREATED) {
|
}
|
||||||
|
|
||||||
|
// 网络状态监听,独立协程,与串口初始化并行执行
|
||||||
|
lifecycleScope.launch {
|
||||||
|
repeatOnLifecycle(Lifecycle.State.STARTED) {
|
||||||
launch {
|
launch {
|
||||||
viewModel.getAccessTokenUiState.collect { state ->
|
viewModel.getAccessTokenUiState.collect { state ->
|
||||||
when (state) {
|
when (state) {
|
||||||
@@ -165,61 +171,53 @@ class HomeActivity : BaseActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
launch {
|
||||||
|
viewModel.updateOverdueStateUiState.collect { state ->
|
||||||
|
if (state is UiState.Success<*>) {
|
||||||
|
val respData = state.data as? RespData<*>
|
||||||
|
if (respData == null) {
|
||||||
|
log("updateOverdueState: 数据类型错误,期望 RespData")
|
||||||
|
return@collect
|
||||||
|
}
|
||||||
|
val shelfResult = respData.data as? ShelfResult
|
||||||
|
if (shelfResult == null) {
|
||||||
|
log("updateOverdueState: 数据类型错误,期望 ShelfResult")
|
||||||
|
return@collect
|
||||||
|
}
|
||||||
|
val items = shelfResult.containerGoodsList
|
||||||
|
if (items.isNullOrEmpty()) {
|
||||||
|
log("updateOverdueState: 货架列表为空")
|
||||||
|
return@collect
|
||||||
|
}
|
||||||
|
applyOverdueState(items)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//sendCmd(ACTIVE_CMD)
|
|
||||||
|
|
||||||
binding.root.postDelayed({
|
binding.root.postDelayed({
|
||||||
sendCmd(START_TEMP_CTRL_CMD)
|
sendCmd(START_TEMP_CTRL_CMD)
|
||||||
sendCmd(C_TEMP_CMD)
|
sendCmd(C_TEMP_CMD)
|
||||||
}, 5000)
|
}, 5000)
|
||||||
|
|
||||||
// TaskManager.startTask()
|
|
||||||
|
|
||||||
saveGoodsTask()
|
saveGoodsTask()
|
||||||
overdueTask()
|
overdueTask()
|
||||||
|
|
||||||
// var androidId = Settings.Secure.getString(contentResolver, Settings.Secure.ANDROID_ID)
|
|
||||||
//// androidId = "d0e7a2d5f25c775c"
|
|
||||||
// log("onCreate: androidId=${androidId}")
|
|
||||||
// if (androidId == "65e1012638f78260" || androidId == "40f89e91ee40611d") {
|
|
||||||
// androidId = "d0e7a2d5f25c775c"
|
|
||||||
// }
|
|
||||||
// App.deviceId = androidId
|
|
||||||
// //"53babf69-0d2f-3875-a649-f2e12f80ad4c1"
|
|
||||||
//
|
|
||||||
// val swDpValue = resources?.configuration?.smallestScreenWidthDp
|
|
||||||
// log("onCreate: swDpValue=$swDpValue")
|
|
||||||
|
|
||||||
|
|
||||||
// viewModel.getAccessToken(App.deviceId)
|
|
||||||
|
|
||||||
viewModel.getShelfList(deviceId = App.deviceId)
|
viewModel.getShelfList(deviceId = App.deviceId)
|
||||||
|
|
||||||
// binding.root.postDelayed({
|
|
||||||
// loadTestData()
|
|
||||||
// }, 30*1000)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun loadTestData() {
|
private val defDeviceList = listOf(
|
||||||
list.add(ShelfModel(deviceNo = 1, goodsName = "鸡蛋", deviceId = App.deviceId))
|
//原410货柜
|
||||||
list.add(ShelfModel(deviceNo = 6, goodsName = "", deviceId = App.deviceId))
|
"7a991439-3a12-3ef7-809b-c0258b839473",
|
||||||
list.add(ShelfModel(deviceNo = 2, goodsName = "", deviceId = App.deviceId))
|
//原1楼餐厅货柜
|
||||||
list.add(ShelfModel(deviceNo = 7, goodsName = "生姜", deviceId = App.deviceId))
|
"4787e213-90ab-3e32-88e0-ac271a937751"
|
||||||
list.add(ShelfModel(deviceNo = 3, goodsName = "黄瓜", deviceId = App.deviceId))
|
)
|
||||||
list.add(ShelfModel(deviceNo = 8, goodsName = "", deviceId = App.deviceId))
|
|
||||||
list.add(ShelfModel(deviceNo = 4, goodsName = "梨", deviceId = App.deviceId))
|
|
||||||
list.add(ShelfModel(deviceNo = 9, goodsName = "梨", deviceId = App.deviceId))
|
|
||||||
list.add(ShelfModel(deviceNo = 5, goodsName = "", deviceId = App.deviceId))
|
|
||||||
list.add(ShelfModel(deviceNo = 10, goodsName = "", deviceId = App.deviceId))
|
|
||||||
shelfAdapter.notifyDataSetChanged()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getTokenSuccess(data: RespData<*>) {
|
private fun getTokenSuccess(data: RespData<*>) {
|
||||||
log("getTokenSuccess: $data")
|
log("getTokenSuccess: $data")
|
||||||
data.data?.let {
|
data.data?.let {
|
||||||
App.accessToken = it.toString()
|
App.accessToken = it.toString()
|
||||||
//UIUtils.toast(it.toString())
|
|
||||||
viewModel.getShelfList(deviceId = App.deviceId)
|
viewModel.getShelfList(deviceId = App.deviceId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -232,32 +230,24 @@ class HomeActivity : BaseActivity() {
|
|||||||
private fun updateUI(data: RespData<*>) {
|
private fun updateUI(data: RespData<*>) {
|
||||||
binding.include?.root?.gone()
|
binding.include?.root?.gone()
|
||||||
window?.decorView?.postDelayed({ Loading.dismiss() }, 500)
|
window?.decorView?.postDelayed({ Loading.dismiss() }, 500)
|
||||||
if (data.data !is ShelfResult) {
|
val shelfResult = data.data as? ShelfResult
|
||||||
|
if (shelfResult == null) {
|
||||||
|
log("updateUI: 数据类型错误,期望 ShelfResult,实际类型:${data.data?.javaClass?.simpleName}")
|
||||||
loadEmptyView()
|
loadEmptyView()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
deviceName = data.data.deviceName
|
deviceName = shelfResult.deviceName
|
||||||
|
updateLeftStatus(deviceName)
|
||||||
|
|
||||||
// updateLeftStatus("$deviceName -°C / -%")
|
App.canteenId = shelfResult.placeId
|
||||||
updateLeftStatus("$deviceName")
|
var tempList = shelfResult.containerGoodsList
|
||||||
|
|
||||||
App.canteenId = data.data.placeId
|
|
||||||
val tempList = data.data.containerGoodsList
|
|
||||||
if (tempList.isNullOrEmpty()) {
|
if (tempList.isNullOrEmpty()) {
|
||||||
loadEmptyView()
|
loadEmptyView()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// if (tempList.size < 10) {
|
|
||||||
// toast("数据错误")
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
list.clear()
|
list.clear()
|
||||||
val subList01 = tempList.subList(0, tempList.size / 2)
|
tempList = GridLayoutTool.initListSort(tempList)
|
||||||
val subList02 = tempList.subList(tempList.size / 2, tempList.size)
|
list.addAll(tempList)
|
||||||
repeat(tempList.size / 2) { index ->
|
|
||||||
list.add(subList01[index].also { it.deviceId = App.deviceId })
|
|
||||||
list.add(subList02[index].also { it.deviceId = App.deviceId })
|
|
||||||
}
|
|
||||||
shelfAdapter.notifyDataSetChanged()
|
shelfAdapter.notifyDataSetChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -267,375 +257,112 @@ class HomeActivity : BaseActivity() {
|
|||||||
loadEmptyView()
|
loadEmptyView()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 终端id
|
|
||||||
*/
|
|
||||||
private var terminalId: String = ""
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 固件版本
|
|
||||||
*/
|
|
||||||
private var terminalVersion: String = ""
|
|
||||||
|
|
||||||
private val serialReader by lazy { StringBuilder() }
|
|
||||||
|
|
||||||
private fun receiveSerialPortData(srcData: String) {
|
private fun receiveSerialPortData(srcData: String) {
|
||||||
log("receiveSerialPortData: $srcData")
|
log("receiveSerialPortData: $srcData")
|
||||||
var data = ""
|
// 重置无数据计时,并关闭已显示的超时提示弹窗
|
||||||
if (srcData.contains(HEADER) && srcData.contains(FOOTER)) {
|
lastDataReceivedTime = System.currentTimeMillis()
|
||||||
serialReader.clear()
|
noDataWarningDialog?.takeIf { it.isShowing }?.dismiss()
|
||||||
val startIndex = srcData.lastIndexOf(HEADER)
|
val frame = serialFrameParser.parse(srcData) ?: return
|
||||||
var endIndex = srcData.indexOf(FOOTER) + FOOTER.length
|
serialProtocolHandler.handle(frame)
|
||||||
if (endIndex < startIndex) {
|
|
||||||
//类似这种:31314FFFFFD6DADEDB01010C,FOOTER在HEADER前
|
|
||||||
data = srcData.substring(startIndex)
|
|
||||||
if (data.contains(FOOTER)) {
|
|
||||||
endIndex = srcData.indexOf(FOOTER) + FOOTER.length
|
|
||||||
data = data.substring(0, endIndex)
|
|
||||||
handleReceivedData(data)
|
|
||||||
serialReader.clear()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
serialReader.clear()
|
|
||||||
serialReader.append(data).append(",")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
serialReader.append(srcData.substring(startIndex, endIndex))
|
|
||||||
data = serialReader.toString()
|
|
||||||
handleReceivedData(data)
|
|
||||||
serialReader.clear()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (srcData.contains(HEADER) && srcData.contains(FOOTER).not()) {
|
|
||||||
serialReader.clear()
|
|
||||||
val startIndex = srcData.lastIndexOf(HEADER)
|
|
||||||
serialReader.append(srcData.substring(startIndex)).append(",")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (srcData.contains(HEADER).not() && srcData.contains(FOOTER).not()) {
|
|
||||||
serialReader.append(srcData).append(",")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
//if (srcData.contains(HEADER).not() && srcData.contains(FOOTER))
|
|
||||||
val endIndex = srcData.indexOf(FOOTER) + FOOTER.length
|
|
||||||
serialReader.append(srcData.substring(0, endIndex))
|
|
||||||
log("receiveSerialPortData:serialReader: $serialReader")
|
|
||||||
data = serialReader.toString().replace(",", "")
|
|
||||||
handleReceivedData(data)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun handleReceivedData(data: String) {
|
|
||||||
if (data.isEmpty()) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
val cmd = data.substring(HEADER.length, HEADER.length + 4)
|
|
||||||
val cmdFlag = cmd.substring(0, 2)
|
|
||||||
when (cmd) {
|
|
||||||
"0001" -> {
|
|
||||||
//终端发起激活指令,拿到固定数据体(终端ID-15字节、固件版本-5字节、命令次数-1字节)
|
|
||||||
val reqBody =
|
|
||||||
data.substring(HEADER.length + cmd.length, data.length - FOOTER.length)
|
|
||||||
if (reqBody.length == 44) {
|
|
||||||
terminalId = reqBody.substring(2, 32)
|
|
||||||
terminalVersion = reqBody.substring(32, 42)
|
|
||||||
log("${LOG_PREFIX}[激活]${cmdFlag}指令:${data},终端id:${terminalId},固件版本:${terminalVersion},发送激活命令:$ACTIVE_CMD")
|
|
||||||
sendCmd(ACTIVE_CMD)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
"0101", "8101" -> {
|
|
||||||
//心跳0102${p1}${p2}${version}
|
|
||||||
//心跳81(终端发起,当终端发送此命令时需要服务端存储串口屏显示信息)
|
|
||||||
val respCmd = "${HEADER}01020506${terminalVersion}$FOOTER"
|
|
||||||
log("${LOG_PREFIX}[心跳]${cmdFlag}指令:${data},发送应答指令:${respCmd}")
|
|
||||||
sendCmd(respCmd)
|
|
||||||
heartBeat(data)
|
|
||||||
}
|
|
||||||
|
|
||||||
"0202" -> {
|
|
||||||
//开关锁反馈020200${deviceId}${version}
|
|
||||||
val respCmd = "${HEADER}020200${terminalId}${terminalVersion}$FOOTER"
|
|
||||||
log("${LOG_PREFIX}[开锁]${cmdFlag}指令:${data},发送应答指令:${respCmd}")
|
|
||||||
sendCmd(respCmd)
|
|
||||||
//lockFeedback(data)
|
|
||||||
}
|
|
||||||
|
|
||||||
"0302" -> {
|
|
||||||
//获取设备状态
|
|
||||||
log("${LOG_PREFIX}[获取设备状态]${cmdFlag}指令:${data}")
|
|
||||||
getDeviceInfo(data)
|
|
||||||
}
|
|
||||||
|
|
||||||
"0501" -> {
|
|
||||||
//卡号上发
|
|
||||||
val respCmd = "${HEADER}050203$FOOTER"
|
|
||||||
log("${LOG_PREFIX}[卡号上发]${cmdFlag}指令:${data},发送应答指令:${respCmd}")
|
|
||||||
sendCmd(respCmd)
|
|
||||||
}
|
|
||||||
|
|
||||||
"0B01" -> {
|
|
||||||
//操作记录上传
|
|
||||||
val respCmd = "${HEADER}0B0203$FOOTER"
|
|
||||||
log("${LOG_PREFIX}[操作记录上传]${cmdFlag}指令:${data},发送应答指令:${respCmd}")
|
|
||||||
sendCmd(respCmd)
|
|
||||||
}
|
|
||||||
|
|
||||||
"0C01" -> {
|
|
||||||
//对时
|
|
||||||
val timeLong = System.currentTimeMillis() / 1000 + (8 * 3600)
|
|
||||||
val timeStr = "0000000" + String.format("%X", timeLong)
|
|
||||||
val time =
|
|
||||||
timeStr.substring(timeStr.length - 8).chunked(2).reversed().joinToString("")
|
|
||||||
val respCmd = "${HEADER}0B02${time}$FOOTER"
|
|
||||||
log("${LOG_PREFIX}[对时]${cmdFlag}指令:${data},发送应答指令:${respCmd}")
|
|
||||||
sendCmd(respCmd)
|
|
||||||
}
|
|
||||||
|
|
||||||
"0E01" -> {
|
|
||||||
//终端位置上报
|
|
||||||
val respCmd = "${HEADER}0E0200$FOOTER"
|
|
||||||
log("${LOG_PREFIX}[终端位置上报]${cmdFlag}指令:${data},发送应答指令:${respCmd}")
|
|
||||||
sendCmd(respCmd)
|
|
||||||
}
|
|
||||||
|
|
||||||
"1001" -> {
|
|
||||||
//温控信息上报
|
|
||||||
val respCmd = "${HEADER}100200$FOOTER"
|
|
||||||
val logMsg =
|
|
||||||
"${LOG_PREFIX}[温控信息上报]${cmdFlag}指令:${data},发送应答指令:${respCmd}"
|
|
||||||
log(logMsg)
|
|
||||||
sendCmd(respCmd)
|
|
||||||
//val tempC = HexUtils.signedHexToDec(data.take(4)) * 0.1
|
|
||||||
// updateLeftStatus("$deviceName ${"%.1f".format(tempC)}°C / -%")
|
|
||||||
// updateLeftStatus("$deviceName -°C / -%")
|
|
||||||
updateLeftStatus("$deviceName")
|
|
||||||
|
|
||||||
//D6DADEDB1001015D020000000027001E00020000001E001C00B40000000000010000000100040000001900440003000F00000000000FFFE6000200010002FFD80044000300010005001E0001FFD80056001400280000000000000000008300090000003C00D2000000000000007F003700000000A100000031323136334238423134303233303456322E313100FFFF
|
|
||||||
runOnUiThread {
|
|
||||||
if (tipDialog == null) {
|
|
||||||
CommonDialog(this).apply {
|
|
||||||
dialogTitle = "温馨提示"
|
|
||||||
// dialogContent = logMsg
|
|
||||||
confirmBlock = {
|
|
||||||
logMsg?.copyTextToClipboard(this@HomeActivity)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (tipDialog?.isShowing == false) {
|
|
||||||
tipDialog?.dialogContent = logMsg
|
|
||||||
tipDialog?.show()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
"1002" -> {
|
|
||||||
log("${LOG_PREFIX}[温控信息应答]1002数据:${data}")
|
|
||||||
}
|
|
||||||
|
|
||||||
"0F02" -> {
|
|
||||||
log("${LOG_PREFIX}[温控信息应答]0F02数据:${data}")
|
|
||||||
//D6DADEDB0F020331323136334238423134303233303456322E31313EFFFF00000055010000000000002707000001000000220100000000000091040000120100000100000095140080611400800000000000000000000000000000000000000000010100005031323136334238423134303233303456322E31313EFFFF
|
|
||||||
runOnUiThread { }
|
|
||||||
}
|
|
||||||
|
|
||||||
else -> {}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private var tipDialog: CommonDialog? = null
|
private var tipDialog: CommonDialog? = null
|
||||||
|
|
||||||
private var fixedDataBody = ""
|
/** 最后一次成功收到串口数据的时间戳(毫秒) */
|
||||||
|
private var lastDataReceivedTime = System.currentTimeMillis()
|
||||||
|
|
||||||
// private fun lockFeedback(data: String) {
|
/** 无数据超时提示弹窗 */
|
||||||
// runCatching {
|
private var noDataWarningDialog: CommonDialog? = null
|
||||||
// val fixedDataBodyEndIndex = data.length - FOOTER.length
|
|
||||||
// val fixedDataBodyStartIndex = HEADER.length + "0202".length + 42
|
|
||||||
// fixedDataBody = data.substring(fixedDataBodyStartIndex, fixedDataBodyEndIndex)
|
|
||||||
//
|
|
||||||
// val lockNo = if (list[shelfIndex].deviceNo in 1..5) "01" else "02"
|
|
||||||
// val lockOneState = data.substring(HEADER.length + 4, HEADER.length + 6)
|
|
||||||
// if (lockOneState == "00") {
|
|
||||||
// //锁1关
|
|
||||||
// SerialPortManager.send("${HEADER}0202${lockNo}${FOOTER}")
|
|
||||||
// }
|
|
||||||
// val lockTwoState = data.substring(HEADER.length + 6, HEADER.length + 8)
|
|
||||||
// if (lockTwoState == "00") {
|
|
||||||
// //锁2关
|
|
||||||
// SerialPortManager.send("${HEADER}0202${lockNo}${FOOTER}")
|
|
||||||
// }
|
|
||||||
// }.onFailure {
|
|
||||||
// it.printStackTrace()
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
private fun heartBeat(data: String) {
|
/**
|
||||||
runCatching {
|
* 无数据看门狗:每30秒检查一次,若超过5分钟未收到数据则弹出提示。
|
||||||
if (data.length < 200) {
|
* 收到数据后会自动重置计时并关闭弹窗。
|
||||||
return
|
*/
|
||||||
|
private val noDataWatchdogTask = object : Runnable {
|
||||||
|
override fun run() {
|
||||||
|
// 生命周期检查,防止 Activity 销毁后继续执行
|
||||||
|
if (isFinishing || isDestroyed) return
|
||||||
|
|
||||||
|
val elapsed = System.currentTimeMillis() - lastDataReceivedTime
|
||||||
|
if (elapsed >= 5 * 60 * 1000L) {
|
||||||
|
if (noDataWarningDialog == null) {
|
||||||
|
noDataWarningDialog = CommonDialog(this@HomeActivity).apply {
|
||||||
|
dialogTitle = "设备提示"
|
||||||
|
dialogContent =
|
||||||
|
"长时间未收到数据,若无法开门或秤重量不更新情况,请考虑断电重启设备"
|
||||||
}
|
}
|
||||||
val weightStartIndex = 14
|
}
|
||||||
val weightEndIndex = weightStartIndex + 12 * 8
|
if (noDataWarningDialog?.isShowing == false) {
|
||||||
getWeightInfo(
|
noDataWarningDialog?.show()
|
||||||
start = weightStartIndex,
|
}
|
||||||
end = weightEndIndex,
|
}
|
||||||
data = data
|
handler.postDelayed(this, 30 * 1000L)
|
||||||
)
|
|
||||||
val temperatureStartIndex = 158
|
|
||||||
val temperatureEndIndex = temperatureStartIndex + 2
|
|
||||||
// val temperatureHex = data.substring(temperatureStartIndex, temperatureEndIndex)
|
|
||||||
// val temperature = hexToDec(temperatureHex)
|
|
||||||
// val tempC = f2C(temperature.toDouble())
|
|
||||||
// showTemperatureC = "%.1f".format(tempC)
|
|
||||||
|
|
||||||
//val percent = 10 * list.count { it.goodsName.isNullOrBlank().not() }
|
|
||||||
|
|
||||||
// updateLeftStatus("${deviceName} [$temperatureHex] ${showTemperatureC}°C / -%")
|
|
||||||
|
|
||||||
getFixDataBody(data, temperatureEndIndex)
|
|
||||||
}.onFailure {
|
|
||||||
it.printStackTrace()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private var deviceName = ""
|
/**
|
||||||
|
* 用户超时无操作时关灯
|
||||||
private fun getWeightInfo(start: Int, end: Int, data: String) {
|
*/
|
||||||
var index = 1
|
override fun onUserInactive() {
|
||||||
var count = start
|
switchLight(false)
|
||||||
while (count < end) {
|
|
||||||
val weightInfo = data.substring(count, count + 8)
|
|
||||||
var weightHex = ""
|
|
||||||
weightInfo.run {
|
|
||||||
weightHex =
|
|
||||||
substring(6, 8) + substring(4, 6) + substring(2, 4) + substring(0, 2)
|
|
||||||
}
|
|
||||||
var realWeight = 0
|
|
||||||
var firstByteBinary = hexToBinary(weightHex.substring(0, 2))
|
|
||||||
if (firstByteBinary.startsWith("0")) {
|
|
||||||
//正数
|
|
||||||
realWeight = weightHex.toInt()
|
|
||||||
} else {
|
|
||||||
//负数
|
|
||||||
firstByteBinary = "0${firstByteBinary.substring(1)}"
|
|
||||||
val firstByteHex = binaryToHex(firstByteBinary)
|
|
||||||
weightHex = firstByteHex + weightHex.substring(2)
|
|
||||||
realWeight = -1 * weightHex.toInt()
|
|
||||||
}
|
|
||||||
weightArray.put(index, realWeight)
|
|
||||||
|
|
||||||
if (index in 1..10 && list.size == 10) {
|
|
||||||
list.firstOrNull { it.deviceNo == index }?.let {
|
|
||||||
it.weight = realWeight.toDouble()
|
|
||||||
val pos = list.indexOf(it)
|
|
||||||
shelfAdapter.notifyItemChanged(pos)
|
|
||||||
log("getWeightInfo: deviceNo=${it.deviceNo},realWeight=${realWeight}")
|
|
||||||
EventBus.getDefault().post(SendWeightEvent(it.deviceNo, realWeight))
|
|
||||||
}
|
|
||||||
// val pos = index - 1
|
|
||||||
// val item = list[pos]
|
|
||||||
// item.weight = realWeight.toDouble()
|
|
||||||
// shelfAdapter.notifyItemChanged(pos)
|
|
||||||
// log("getWeightInfo: deviceNo=${item.deviceNo},realWeight=${realWeight}")
|
|
||||||
// EventBus.getDefault().post(SendWeightEvent(item.deviceNo, realWeight))
|
|
||||||
}
|
|
||||||
|
|
||||||
count += 8
|
|
||||||
index++
|
|
||||||
}
|
|
||||||
// ShelfActivity.updateWeight(getRealWeight())
|
|
||||||
// if (list.isNotEmpty()) {
|
|
||||||
// val intent = Intent(ShelfActivity.RECEIVER_DEVICE_INFO + list[shelfIndex].deviceNo)
|
|
||||||
// intent.putExtra(ShelfActivity.SHELF_WEIGHT, weightArray[shelfIndex])
|
|
||||||
// LocalBroadcastManager.getInstance(this).sendBroadcast(intent)
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getDeviceInfo(data: String) {
|
|
||||||
log("getDeviceInfo: data=$data")
|
|
||||||
val weightStartIndex = HEADER.length + 14
|
|
||||||
val temperatureStartIndex = weightStartIndex + 12 * 8
|
|
||||||
val temperatureEndIndex = temperatureStartIndex + 2
|
|
||||||
val temperatureHex = try {
|
|
||||||
data.substring(temperatureStartIndex, temperatureEndIndex)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
e.printStackTrace()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
// val temperature = hexToDec(temperatureHex)
|
|
||||||
// val tempC = f2C(temperature.toDouble())
|
|
||||||
// showTemperatureC = "%.1f".format(tempC)
|
|
||||||
|
|
||||||
//val percent = 10 * list.count { it.goodsName.isNullOrBlank().not() }
|
|
||||||
|
|
||||||
// updateLeftStatus("${deviceName} ${showTemperatureC}°C / -%")
|
|
||||||
|
|
||||||
|
|
||||||
// val tempC = HexUtils.signedHexToDec(temperatureHex) * 0.1
|
|
||||||
// updateLeftStatus("$deviceName -°C / -%")
|
|
||||||
updateLeftStatus("$deviceName")
|
|
||||||
|
|
||||||
getWeightInfo(
|
|
||||||
start = weightStartIndex,
|
|
||||||
end = temperatureStartIndex,
|
|
||||||
data = data
|
|
||||||
)
|
|
||||||
|
|
||||||
getFixDataBody(data, temperatureEndIndex)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getFixDataBody(data: String, temperatureEndIndex: Int) {
|
|
||||||
try {
|
|
||||||
if (terminalId.isNotBlank() && terminalVersion.isNotBlank()) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
val fixDataBodyStartIndex = temperatureEndIndex + 1
|
|
||||||
val fixDataBody = data.substring(fixDataBodyStartIndex, data.length - FOOTER.length)
|
|
||||||
if (fixDataBody.length == 42) {
|
|
||||||
terminalId = fixDataBody.substring(0, 30)
|
|
||||||
terminalVersion = fixDataBody.substring(30, 40)
|
|
||||||
log("receiveSerialPortData:从设备状态获取数据,终端id:${terminalId},固件版本:${terminalVersion}")
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
|
||||||
e.printStackTrace()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
lifecycleScope.launch {
|
// 清理 Handler 所有回调,防止内存泄漏
|
||||||
SerialPortManager.close()
|
handler.removeCallbacksAndMessages(null)
|
||||||
}
|
|
||||||
// TaskManager.cancelTask()
|
// 关闭并释放 Dialog 引用,防止内存泄漏
|
||||||
|
tipDialog?.dismiss()
|
||||||
|
tipDialog = null
|
||||||
|
noDataWarningDialog?.dismiss()
|
||||||
|
noDataWarningDialog = null
|
||||||
|
|
||||||
|
runBlocking { SerialPortManager.close() }
|
||||||
saveTaskJob?.cancel()
|
saveTaskJob?.cancel()
|
||||||
overdueTaskJob?.cancel()
|
overdueTaskJob?.cancel()
|
||||||
EventBus.getDefault().unregister(this)
|
EventBus.getDefault().unregister(this)
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("DEPRECATION")
|
|
||||||
private val shelfAdapter by lazy {
|
private val shelfAdapter by lazy {
|
||||||
ShelfAdapter(list).apply {
|
ShelfAdapter(list).apply {
|
||||||
setOnItemClickListener { _, _, position ->
|
setOnItemClickListener { _, _, position ->
|
||||||
|
onShelfItemClicked(position)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理货架格子点击事件:按需开锁,然后跳转 ShelfActivity
|
||||||
|
*/
|
||||||
|
private fun onShelfItemClicked(position: Int) {
|
||||||
shelfIndex = position
|
shelfIndex = position
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
if (isNeedOpenLock) {
|
if (isNeedOpenLock()) {
|
||||||
val openCmd = if (list[position].deviceNo in 1..5)
|
val openCmd = if (list[position].deviceNo in 1..5)
|
||||||
LEFT_SHELF_OPEN_CMD
|
LEFT_SHELF_OPEN_CMD
|
||||||
else
|
else
|
||||||
RIGHT_SHELF_OPEN_CMD
|
RIGHT_SHELF_OPEN_CMD
|
||||||
val openState = SerialPortManager.send(openCmd)
|
SerialPortManager.send(openCmd)
|
||||||
}
|
}
|
||||||
// if (openState.not()) {
|
|
||||||
// toast("${list[position].goodsName}柜门开启失败")
|
|
||||||
// return@launch
|
|
||||||
// }
|
|
||||||
//SerialPortManager.send(START_CMD)
|
|
||||||
launch(Intent(this@HomeActivity, ShelfActivity::class.java).also {
|
launch(Intent(this@HomeActivity, ShelfActivity::class.java).also {
|
||||||
it.putExtra(ShelfActivity.SHELF_MODEL, list[position])
|
it.putExtra(ShelfActivity.SHELF_MODEL, list[position])
|
||||||
}) {
|
}) { result ->
|
||||||
it?.run {
|
result?.let { onShelfActivityResult(position, it) }
|
||||||
val model =
|
}
|
||||||
getSerializableExtra(ShelfActivity.SHELF_MODEL) as ShelfModel
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理 ShelfActivity 返回结果:更新本地列表数据并同步到服务端
|
||||||
|
*/
|
||||||
|
private fun onShelfActivityResult(position: Int, intent: Intent) {
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
val model = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||||
|
intent.getSerializableExtra(ShelfActivity.SHELF_MODEL, ShelfModel::class.java)
|
||||||
|
} else {
|
||||||
|
intent.getSerializableExtra(ShelfActivity.SHELF_MODEL) as? ShelfModel
|
||||||
|
} ?: return
|
||||||
list[position].apply {
|
list[position].apply {
|
||||||
goodsId = model.goodsId
|
goodsId = model.goodsId
|
||||||
goodsName = model.goodsName
|
goodsName = model.goodsName
|
||||||
@@ -644,40 +371,16 @@ class HomeActivity : BaseActivity() {
|
|||||||
putCabinetDay = model.putCabinetDay
|
putCabinetDay = model.putCabinetDay
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
notifyItemChanged(position)
|
shelfAdapter.notifyItemChanged(position)
|
||||||
|
syncShelfGoodsToServer()
|
||||||
try {
|
|
||||||
|
|
||||||
val submitList = list.sortedBy { item -> item.deviceNo }
|
|
||||||
val body = ShelfBody().also { body ->
|
|
||||||
body.deviceId = App.deviceId ?: ""
|
|
||||||
body.canteenId = App.canteenId
|
|
||||||
body.temperature = showTemperatureC
|
|
||||||
body.humidity = showHumidity
|
|
||||||
body.goodsList = submitList
|
|
||||||
}
|
|
||||||
Log.d("mzf", "performSync: body:${body.toJsonString()}")
|
|
||||||
lifecycleScope.launch {
|
|
||||||
val resp = apiService.saveShelfGoodsList(body = body)
|
|
||||||
Log.d("mzf", "performSync: resp:${resp.toJsonString()}")
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
|
||||||
e.printStackTrace()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initRecyclerView() {
|
private fun initRecyclerView() {
|
||||||
binding.rvShelf.run {
|
val layoutManager = GridLayoutTool.getLayoutManager(this@HomeActivity) ?: return
|
||||||
layoutManager =
|
binding.rvShelf.let {
|
||||||
GridLayoutManager(this@HomeActivity, 2, GridLayoutManager.VERTICAL, false)
|
it.layoutManager = layoutManager
|
||||||
adapter = shelfAdapter
|
it.adapter = shelfAdapter
|
||||||
|
it.itemAnimator.let {
|
||||||
itemAnimator.let {
|
|
||||||
if (it is DefaultItemAnimator) {
|
if (it is DefaultItemAnimator) {
|
||||||
it.supportsChangeAnimations = false
|
it.supportsChangeAnimations = false
|
||||||
}
|
}
|
||||||
@@ -685,42 +388,28 @@ class HomeActivity : BaseActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateDateTime() {
|
|
||||||
val sdf = SimpleDateFormat(MM_DD_EEEE__HH_MM_SS, Locale.CHINA)
|
|
||||||
val dateTime = sdf.format(Date())
|
|
||||||
updateRightStatus(dateTime)
|
|
||||||
}
|
|
||||||
|
|
||||||
private val handler = Handler(Looper.getMainLooper())
|
private val handler = Handler(Looper.getMainLooper())
|
||||||
private val updateTask = object : Runnable {
|
|
||||||
override fun run() {
|
|
||||||
updateDateTime()
|
|
||||||
handler.postDelayed(this, 1000)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
hideStatusBar()
|
hideStatusBar()
|
||||||
handler.post(updateTask)
|
// 启动无数据看门狗(每30秒检查一次)
|
||||||
// D6DADEDB00010031323136334238423134303233303456322E313100FFFF
|
handler.postDelayed(noDataWatchdogTask, 30 * 1000L)
|
||||||
// sendCmd("${HEADER}00010031323136334238423134303233303456322E313152${FOOTER}")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPause() {
|
override fun onPause() {
|
||||||
super.onPause()
|
super.onPause()
|
||||||
handler.removeCallbacks(updateTask)
|
// 停止无数据看门狗
|
||||||
|
handler.removeCallbacks(noDataWatchdogTask)
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("NotifyDataSetChanged")
|
@SuppressLint("NotifyDataSetChanged")
|
||||||
private fun loadEmptyView() {
|
private fun loadEmptyView() {
|
||||||
list.clear()
|
list.clear()
|
||||||
shelfAdapter.notifyDataSetChanged()
|
shelfAdapter.notifyDataSetChanged()
|
||||||
|
|
||||||
binding.include?.let {
|
binding.include?.let {
|
||||||
it.root.visible()
|
it.root.visible()
|
||||||
it.root.setOnClickListener {
|
it.root.setOnClickListener {
|
||||||
//viewModel.getAccessToken(App.deviceId)
|
|
||||||
viewModel.getShelfList(deviceId = App.deviceId)
|
viewModel.getShelfList(deviceId = App.deviceId)
|
||||||
}
|
}
|
||||||
it.ivEmptyIcon.setImageResource(R.drawable.ic_empty_white)
|
it.ivEmptyIcon.setImageResource(R.drawable.ic_empty_white)
|
||||||
@@ -729,12 +418,7 @@ class HomeActivity : BaseActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||||
public fun weightEvent(event: WeightEvent) {
|
fun clearEmptyShelf(event: ClearShelfEvent) {
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
|
||||||
public fun clearEmptyShelf(event: ClearShelfEvent) {
|
|
||||||
val item = list.firstOrNull { it.deviceNo == event.shelfNo }
|
val item = list.firstOrNull { it.deviceNo == event.shelfNo }
|
||||||
item?.apply {
|
item?.apply {
|
||||||
goodsId = ""
|
goodsId = ""
|
||||||
@@ -748,33 +432,40 @@ class HomeActivity : BaseActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private val taskExecutor by lazy { IntervalExecutor() }
|
private val taskExecutor by lazy { IntervalExecutor() }
|
||||||
private var saveTaskJob: Job?=null
|
private var saveTaskJob: Job? = null
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 保存定时任务
|
* 保存定时任务
|
||||||
*/
|
*/
|
||||||
private fun saveGoodsTask() {
|
private fun saveGoodsTask() {
|
||||||
saveTaskJob = taskExecutor.startIntervalTaskWithInitialDelay(1 * 60 * 1000L, 5 * 60 * 1000L) {
|
saveTaskJob =
|
||||||
saveShelfGoodsList()
|
taskExecutor.startIntervalTaskWithInitialDelay(1 * 60 * 1000L, 5 * 60 * 1000L) {
|
||||||
|
syncShelfGoodsToServer()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private var overdueTaskJob: Job?=null
|
private var overdueTaskJob: Job? = null
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 过期时间定时任务
|
* 过期时间定时任务
|
||||||
*/
|
*/
|
||||||
private fun overdueTask() {
|
private fun overdueTask() {
|
||||||
overdueTaskJob = taskExecutor.startIntervalTaskWithInitialDelay(5 * 1000L, 5 * 60* 1000L) {
|
overdueTaskJob = taskExecutor.startIntervalTaskWithInitialDelay(5 * 1000L, 5 * 60 * 1000L) {
|
||||||
updateOverdueState()
|
updateOverdueState()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateOverdueState() {
|
private fun updateOverdueState() {
|
||||||
viewModel.updateOverdueState { state, items ->
|
viewModel.updateOverdueState()
|
||||||
if (items.isNullOrEmpty()) return@updateOverdueState
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将接口返回的过期状态应用到本地列表,仅在状态变化时刷新对应 item
|
||||||
|
*/
|
||||||
|
private fun applyOverdueState(items: List<ShelfModel>) {
|
||||||
|
if (items.size != list.size) return
|
||||||
list.forEachIndexed { index, model ->
|
list.forEachIndexed { index, model ->
|
||||||
//接口过期状态变化后更新状态
|
// 接口过期状态变化后更新状态
|
||||||
if (items[index].overdue != model.overdue) {
|
if (items[index].overdue != model.overdue) {
|
||||||
model.overdue = items[index].overdue
|
model.overdue = items[index].overdue
|
||||||
shelfAdapter.notifyItemChanged(index)
|
shelfAdapter.notifyItemChanged(index)
|
||||||
@@ -782,30 +473,26 @@ class HomeActivity : BaseActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private fun saveShelfGoodsList() {
|
/**
|
||||||
log("performSync: list:${list.toJsonString()}")
|
* 构建 ShelfBody 并提交到服务端(被定时任务与 ShelfActivity 返回共用)
|
||||||
val submitList = list.sortedBy { it.deviceNo }
|
*/
|
||||||
|
private fun syncShelfGoodsToServer() {
|
||||||
|
log("performSync显示list:${list.toJsonString()}")
|
||||||
|
val submitList = GridLayoutTool.submitListSort(list)
|
||||||
submitList.forEach {
|
submitList.forEach {
|
||||||
if (it.goodsId.isNullOrBlank()) {
|
if (it.goodsId.isNullOrBlank()) {
|
||||||
it.weight = it.weightBak
|
it.weight = it.weightBak
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// submitList.forEach {
|
|
||||||
// it.temperature = HomeActivity.showTemperatureC
|
|
||||||
// it.humidity = HomeActivity.showHumidity
|
|
||||||
// }
|
|
||||||
val body = ShelfBody().also {
|
val body = ShelfBody().also {
|
||||||
it.deviceId = App.deviceId
|
it.deviceId = App.deviceId ?: ""
|
||||||
it.canteenId = App.canteenId
|
it.canteenId = App.canteenId
|
||||||
it.temperature = showTemperatureC
|
it.temperature = showTemperatureC
|
||||||
it.humidity = showHumidity
|
it.humidity = showHumidity
|
||||||
it.goodsList = submitList
|
it.goodsList = submitList
|
||||||
}
|
}
|
||||||
log("performSync: body:${body.toJsonString()}")
|
log("performSync提交body:${body.toJsonString()}")
|
||||||
viewModel.saveShelfGoodsList(body)
|
viewModel.saveShelfGoodsList(body)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,13 +1,22 @@
|
|||||||
package com.shuwei.intelligent.shelves.activity
|
package com.shuwei.intelligent.shelves.activity
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
|
import android.content.Intent
|
||||||
|
import android.graphics.Color
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.os.Handler
|
||||||
|
import android.os.Looper
|
||||||
|
import android.os.SystemClock
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
import android.view.KeyEvent
|
||||||
|
import android.view.animation.RotateAnimation
|
||||||
import androidx.activity.viewModels
|
import androidx.activity.viewModels
|
||||||
|
import androidx.core.graphics.toColorInt
|
||||||
import androidx.lifecycle.Lifecycle
|
import androidx.lifecycle.Lifecycle
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.lifecycle.repeatOnLifecycle
|
import androidx.lifecycle.repeatOnLifecycle
|
||||||
import com.shuwei.intelligent.shelves.App
|
import com.shuwei.intelligent.shelves.App
|
||||||
|
import com.shuwei.intelligent.shelves.GlobalData
|
||||||
import com.shuwei.intelligent.shelves.base.BaseActivity
|
import com.shuwei.intelligent.shelves.base.BaseActivity
|
||||||
import com.shuwei.intelligent.shelves.databinding.ActivityInitBinding
|
import com.shuwei.intelligent.shelves.databinding.ActivityInitBinding
|
||||||
import com.shuwei.intelligent.shelves.model.DeviceConfigInfo
|
import com.shuwei.intelligent.shelves.model.DeviceConfigInfo
|
||||||
@@ -15,6 +24,7 @@ import com.shuwei.intelligent.shelves.net.NetViewModel
|
|||||||
import com.shuwei.intelligent.shelves.net.UiState
|
import com.shuwei.intelligent.shelves.net.UiState
|
||||||
import com.shuwei.intelligent.shelves.net.UrlConfig
|
import com.shuwei.intelligent.shelves.net.UrlConfig
|
||||||
import com.shuwei.intelligent.shelves.utils.AppUtil
|
import com.shuwei.intelligent.shelves.utils.AppUtil
|
||||||
|
import com.shuwei.intelligent.shelves.utils.NetworkUtils
|
||||||
import com.shuwei.intelligent.shelves.utils.QRCodeUtil
|
import com.shuwei.intelligent.shelves.utils.QRCodeUtil
|
||||||
import com.shuwei.intelligent.shelves.utils.SpTool
|
import com.shuwei.intelligent.shelves.utils.SpTool
|
||||||
import com.shuwei.intelligent.shelves.utils.ext.dp
|
import com.shuwei.intelligent.shelves.utils.ext.dp
|
||||||
@@ -39,6 +49,9 @@ class InitActivity : BaseActivity() {
|
|||||||
private lateinit var binding: ActivityInitBinding
|
private lateinit var binding: ActivityInitBinding
|
||||||
|
|
||||||
private val viewModel: NetViewModel by viewModels()
|
private val viewModel: NetViewModel by viewModels()
|
||||||
|
private val handler = Handler(Looper.getMainLooper())
|
||||||
|
private var startTime = 0L // 倒计时开始时间
|
||||||
|
private var lastNetworkCheckTime = 0L // 上次检测网络的时间
|
||||||
|
|
||||||
@SuppressLint("HardwareIds")
|
@SuppressLint("HardwareIds")
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
@@ -51,7 +64,12 @@ class InitActivity : BaseActivity() {
|
|||||||
// App.deviceId = "4787e213-90ab-3e32-88e0-ac271a937751"
|
// App.deviceId = "4787e213-90ab-3e32-88e0-ac271a937751"
|
||||||
Log.d(TAG, "onCreate: deviceId = ${App.deviceId}")
|
Log.d(TAG, "onCreate: deviceId = ${App.deviceId}")
|
||||||
SpTool.put(SpTool.DEVICE_ID, App.deviceId)
|
SpTool.put(SpTool.DEVICE_ID, App.deviceId)
|
||||||
App.configUrl = UrlConfig.BASE_URL
|
val appBaseUrl = SpTool.baseUrl
|
||||||
|
if (!appBaseUrl.isBlank()) {
|
||||||
|
GlobalData.appBaseUrl = appBaseUrl
|
||||||
|
} else {
|
||||||
|
GlobalData.appBaseUrl = GlobalData.PROD_BASE_URL
|
||||||
|
}
|
||||||
App.canteenId = "0"
|
App.canteenId = "0"
|
||||||
|
|
||||||
// var deviceId = AppUtil.getUDID(this)
|
// var deviceId = AppUtil.getUDID(this)
|
||||||
@@ -73,7 +91,8 @@ class InitActivity : BaseActivity() {
|
|||||||
binding.ivQrCode.invisible()
|
binding.ivQrCode.invisible()
|
||||||
binding.btnInit.invisible()
|
binding.btnInit.invisible()
|
||||||
|
|
||||||
countDown()
|
// countDown()
|
||||||
|
initViews()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun countDown() {
|
private fun countDown() {
|
||||||
@@ -131,7 +150,7 @@ class InitActivity : BaseActivity() {
|
|||||||
state.data.data?.let {
|
state.data.data?.let {
|
||||||
if (it is DeviceConfigInfo) {
|
if (it is DeviceConfigInfo) {
|
||||||
SpTool.put(SpTool.DEVICE_CONFIG_CACHE, it.toJsonString())
|
SpTool.put(SpTool.DEVICE_CONFIG_CACHE, it.toJsonString())
|
||||||
App.configUrl = it.appPackageUrl?:""
|
GlobalData.appBaseUrl = it.appPackageUrl?:""
|
||||||
App.canteenId = it.canteenId?:""
|
App.canteenId = it.canteenId?:""
|
||||||
|
|
||||||
startActivity<HomeActivity>()
|
startActivity<HomeActivity>()
|
||||||
@@ -156,9 +175,147 @@ class InitActivity : BaseActivity() {
|
|||||||
if (config == null) {
|
if (config == null) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
App.configUrl = config.appPackageUrl?:""
|
GlobalData.appBaseUrl = config.appPackageUrl?:""
|
||||||
App.canteenId = config.canteenId?:""
|
App.canteenId = config.canteenId?:""
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化控件事件
|
||||||
|
*/
|
||||||
|
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 // 旋转周期 1.2 秒
|
||||||
|
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()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 定时更新倒计时
|
||||||
|
* 使用 SystemClock.elapsedRealtime() 确保精确计时
|
||||||
|
*/
|
||||||
|
private fun scheduleCountdown() {
|
||||||
|
handler.postDelayed({
|
||||||
|
val elapsedTime = SystemClock.elapsedRealtime() - startTime
|
||||||
|
val remainingTime = 60 - (elapsedTime / 1000).toInt()
|
||||||
|
val currentNetworkCheckTime = (elapsedTime / 1000).toInt()
|
||||||
|
|
||||||
|
// 每 10 秒检测一次网络
|
||||||
|
if (currentNetworkCheckTime > 0 && currentNetworkCheckTime % 10 == 0 && currentNetworkCheckTime != lastNetworkCheckTime.toInt()) {
|
||||||
|
lastNetworkCheckTime = currentNetworkCheckTime.toLong()
|
||||||
|
checkNetworkConnection()
|
||||||
|
}
|
||||||
|
|
||||||
|
// 倒计时未结束,继续更新 UI
|
||||||
|
if (remainingTime > 0) {
|
||||||
|
binding.tvCountdown.text = "${remainingTime}秒"
|
||||||
|
scheduleCountdown()
|
||||||
|
} else {
|
||||||
|
// 倒计时结束,最后检测一次网络
|
||||||
|
if (NetworkUtils.isNetworkConnected(this)) {
|
||||||
|
navigateToHome()
|
||||||
|
} else {
|
||||||
|
// 网络未连接,显示"连接网络"按钮
|
||||||
|
showNetworkButton()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 100) // 每 100ms 检查一次,确保精确性
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检测网络连接
|
||||||
|
*/
|
||||||
|
private fun checkNetworkConnection() {
|
||||||
|
if (NetworkUtils.isNetworkConnected(this)) {
|
||||||
|
// 网络连接成功,停止倒计时并跳转到 HomeActivity
|
||||||
|
handler.removeCallbacksAndMessages(null)
|
||||||
|
navigateToHome()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 跳转到 HomeActivity
|
||||||
|
*/
|
||||||
|
private fun navigateToHome() {
|
||||||
|
startActivity<HomeActivity>()
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 禁用返回键
|
||||||
|
*/
|
||||||
|
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
|
||||||
|
return if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||||
|
// 禁用返回键,不执行任何操作
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
super.onKeyDown(keyCode, event)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,28 +1,53 @@
|
|||||||
package com.shuwei.intelligent.shelves.activity
|
package com.shuwei.intelligent.shelves.activity
|
||||||
|
|
||||||
|
import android.graphics.Color
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.view.Gravity
|
||||||
|
import android.widget.TextView
|
||||||
|
import androidx.core.widget.addTextChangedListener
|
||||||
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
import com.shuwei.intelligent.shelves.adapter.LogAdapter
|
import com.shuwei.intelligent.shelves.adapter.LogAdapter
|
||||||
import com.shuwei.intelligent.shelves.base.BaseActivity
|
import com.shuwei.intelligent.shelves.base.BaseActivity
|
||||||
import com.shuwei.intelligent.shelves.databinding.ActivityLogListBinding
|
import com.shuwei.intelligent.shelves.databinding.ActivityLogListBinding
|
||||||
import com.shuwei.intelligent.shelves.dialog.CommonDialog
|
import com.shuwei.intelligent.shelves.dialog.CommonDialog
|
||||||
import com.shuwei.intelligent.shelves.utils.ext.copyTextToClipboard
|
import com.shuwei.intelligent.shelves.utils.ext.copyTextToClipboard
|
||||||
|
import com.shuwei.intelligent.shelves.utils.ext.dp
|
||||||
import com.shuwei.intelligent.shelves.utils.ext.gone
|
import com.shuwei.intelligent.shelves.utils.ext.gone
|
||||||
import com.shuwei.intelligent.shelves.utils.ext.startActivity
|
import com.shuwei.intelligent.shelves.utils.ext.startActivity
|
||||||
import com.shuwei.intelligent.shelves.utils.ext.toast
|
import com.shuwei.intelligent.shelves.utils.ext.toast
|
||||||
|
import com.shuwei.intelligent.shelves.serial.ProtocolConstants
|
||||||
import com.shuwei.intelligent.shelves.utils.ext.visible
|
import com.shuwei.intelligent.shelves.utils.ext.visible
|
||||||
|
import java.text.SimpleDateFormat
|
||||||
|
import java.util.Date
|
||||||
|
import java.util.Locale
|
||||||
|
|
||||||
class LogActivity : BaseActivity() {
|
class LogActivity : BaseActivity() {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val IS_LOG_DIR = "isLogDir"
|
const val IS_LOG_DIR = "isLogDir"
|
||||||
const val LOG_DATE = "logDate"
|
const val LOG_DATE = "logDate"
|
||||||
|
const val YYYY_MM_DD__EEEE_HH_MM_SS = "yyyy年MM月dd日 EEEE***HH:mm:ss"
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 覆写时钟回调:左侧状态栏显示年月日星期,右侧状态栏显示时分秒
|
||||||
|
*/
|
||||||
|
override fun onClockTick() {
|
||||||
|
val sdf = SimpleDateFormat(YYYY_MM_DD__EEEE_HH_MM_SS, Locale.CHINA)
|
||||||
|
val arr = sdf.format(Date()).split("***")
|
||||||
|
updateLeftStatus(arr[0])
|
||||||
|
updateRightStatus(arr[1])
|
||||||
}
|
}
|
||||||
|
|
||||||
private lateinit var binding:ActivityLogListBinding
|
private lateinit var binding:ActivityLogListBinding
|
||||||
private var isLogDir = false
|
private var isLogDir = false
|
||||||
private var logDate = ""
|
private var logDate = ""
|
||||||
private val logList = mutableListOf<String>()
|
private val logList = mutableListOf<String>()
|
||||||
|
private val originalLogList = mutableListOf<String>() // 原始日志备份
|
||||||
private val logAdapter by lazy {
|
private val logAdapter by lazy {
|
||||||
LogAdapter(logList).apply {
|
LogAdapter(logList).apply {
|
||||||
setOnItemClickListener { _, _, position ->
|
setOnItemClickListener { _, _, position ->
|
||||||
@@ -62,24 +87,20 @@ class LogActivity : BaseActivity() {
|
|||||||
logAdapter.notifyDataSetChanged()
|
logAdapter.notifyDataSetChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isLogDir) {
|
|
||||||
logList.addAll(fileLogger.getLogFiles())
|
|
||||||
} else {
|
|
||||||
logList.addAll(fileLogger.readLogsByName(logDate))
|
|
||||||
}
|
|
||||||
|
|
||||||
binding.rvLogList.let {
|
binding.rvLogList.let {
|
||||||
it.layoutManager = LinearLayoutManager(this)
|
it.layoutManager = LinearLayoutManager(this)
|
||||||
it.adapter = logAdapter
|
it.adapter = logAdapter
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setupSearch()
|
||||||
|
setupJumpButton()
|
||||||
|
|
||||||
binding.btnFind.run {
|
binding.btnFind.run {
|
||||||
if (isLogDir) gone() else visible()
|
if (isLogDir) gone() else visible()
|
||||||
}
|
}
|
||||||
binding.btnFind.setOnClickListener {
|
binding.btnFind.setOnClickListener {
|
||||||
if (isLogDir) {
|
if (isLogDir) return@setOnClickListener
|
||||||
return@setOnClickListener
|
val list = logList.filter { it.contains("${ProtocolConstants.HEADER}${ProtocolConstants.CMD_TEMP_REPORT}") }
|
||||||
}
|
|
||||||
val list = logList.filter { it.contains("${HomeActivity.HEADER}1001") }
|
|
||||||
if (list.isEmpty()) {
|
if (list.isEmpty()) {
|
||||||
toast("未找到到1001指令")
|
toast("未找到到1001指令")
|
||||||
return@setOnClickListener
|
return@setOnClickListener
|
||||||
@@ -88,6 +109,95 @@ class LogActivity : BaseActivity() {
|
|||||||
logList.addAll(list)
|
logList.addAll(list)
|
||||||
logAdapter.notifyDataSetChanged()
|
logAdapter.notifyDataSetChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 后台加载日志数据
|
||||||
|
lifecycleScope.launch {
|
||||||
|
binding.progressBar.visible()
|
||||||
|
val data = withContext(Dispatchers.IO) {
|
||||||
|
if (isLogDir) fileLogger.getLogFiles()
|
||||||
|
else fileLogger.readLogsByName(logDate)
|
||||||
|
}
|
||||||
|
logList.addAll(data)
|
||||||
|
originalLogList.addAll(data)
|
||||||
|
logAdapter.notifyDataSetChanged()
|
||||||
|
binding.progressBar.gone()
|
||||||
|
setupTimeNavigation()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 搜索功能
|
||||||
|
private fun setupSearch() {
|
||||||
|
binding.etSearch.addTextChangedListener(afterTextChanged = { s ->
|
||||||
|
val keyword = s?.toString() ?: ""
|
||||||
|
logList.clear()
|
||||||
|
logList.addAll(if (keyword.isEmpty()) originalLogList else originalLogList.filter { it.contains(keyword, ignoreCase = true) })
|
||||||
|
logAdapter.notifyDataSetChanged()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// 快速跳转功能
|
||||||
|
private fun setupJumpButton() {
|
||||||
|
var isAtTop = true
|
||||||
|
binding.fabJump.setOnClickListener {
|
||||||
|
if (isAtTop) {
|
||||||
|
binding.rvLogList.scrollToPosition(logList.size - 1)
|
||||||
|
} else {
|
||||||
|
binding.rvLogList.scrollToPosition(0)
|
||||||
|
}
|
||||||
|
isAtTop = !isAtTop
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 时间导航功能
|
||||||
|
private fun setupTimeNavigation() {
|
||||||
|
if (isLogDir) {
|
||||||
|
binding.hsvTimeNav.gone()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val timeMap = mutableMapOf<String, Int>()
|
||||||
|
val dateFormat = SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault())
|
||||||
|
|
||||||
|
originalLogList.forEachIndexed { index, log ->
|
||||||
|
val timeStr = log.substringAfter("[").substringBefore("]")
|
||||||
|
try {
|
||||||
|
val date = dateFormat.parse(timeStr)
|
||||||
|
date?.let {
|
||||||
|
val hourKey = SimpleDateFormat("HH:00", Locale.getDefault()).format(it)
|
||||||
|
if (!timeMap.containsKey(hourKey)) {
|
||||||
|
timeMap[hourKey] = index
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
// 忽略解析失败的日志
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (timeMap.isEmpty()) {
|
||||||
|
binding.hsvTimeNav.gone()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
timeMap.toSortedMap().forEach { (hour, position) ->
|
||||||
|
val btn = TextView(this).apply {
|
||||||
|
text = hour
|
||||||
|
textSize = 14f
|
||||||
|
setTextColor(Color.BLACK)
|
||||||
|
setPadding(12.dp, 8.dp, 12.dp, 8.dp)
|
||||||
|
gravity = Gravity.CENTER
|
||||||
|
setBackgroundColor(Color.parseColor("#E0E0E0"))
|
||||||
|
setOnClickListener {
|
||||||
|
binding.rvLogList.scrollToPosition(position)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val params = android.widget.LinearLayout.LayoutParams(
|
||||||
|
android.widget.LinearLayout.LayoutParams.WRAP_CONTENT,
|
||||||
|
android.widget.LinearLayout.LayoutParams.MATCH_PARENT
|
||||||
|
).apply {
|
||||||
|
marginEnd = 8.dp
|
||||||
|
}
|
||||||
|
binding.llTimeNav.addView(btn, params)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,66 +1,66 @@
|
|||||||
package com.shuwei.intelligent.shelves.activity
|
//package com.shuwei.intelligent.shelves.activity
|
||||||
|
//
|
||||||
import android.os.Bundle
|
//import android.os.Bundle
|
||||||
import android.os.Handler
|
//import android.os.Handler
|
||||||
import android.os.Looper
|
//import android.os.Looper
|
||||||
import com.shuwei.intelligent.shelves.base.BaseActivity
|
//import com.shuwei.intelligent.shelves.base.BaseActivity
|
||||||
import com.shuwei.intelligent.shelves.databinding.ActivitySettingBinding
|
//import com.shuwei.intelligent.shelves.databinding.ActivitySettingBinding
|
||||||
import com.shuwei.intelligent.shelves.utils.KeyboardUtil
|
//import com.shuwei.intelligent.shelves.utils.KeyboardUtil
|
||||||
import java.text.SimpleDateFormat
|
//import java.text.SimpleDateFormat
|
||||||
import java.util.Date
|
//import java.util.Date
|
||||||
import java.util.Locale
|
//import java.util.Locale
|
||||||
|
//
|
||||||
class SettingActivity: BaseActivity() {
|
//class SettingActivity: BaseActivity() {
|
||||||
|
//
|
||||||
private lateinit var binding: ActivitySettingBinding
|
// private lateinit var binding: ActivitySettingBinding
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
// override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
// super.onCreate(savedInstanceState)
|
||||||
binding = ActivitySettingBinding.inflate(layoutInflater)
|
// binding = ActivitySettingBinding.inflate(layoutInflater)
|
||||||
setBackground()
|
// setBackground()
|
||||||
setContentView(binding.root)
|
// setContentView(binding.root)
|
||||||
binding.btnSendCmd.setOnClickListener{
|
// binding.btnSendCmd.setOnClickListener{
|
||||||
val cmd = binding.etInputCmd.text.toString().trim()
|
// val cmd = binding.etInputCmd.text.toString().trim()
|
||||||
if (cmd.isBlank()) {
|
// if (cmd.isBlank()) {
|
||||||
return@setOnClickListener
|
// return@setOnClickListener
|
||||||
}
|
// }
|
||||||
var record = binding.tvCmdRecord.text.toString().trim()
|
// var record = binding.tvCmdRecord.text.toString().trim()
|
||||||
record = cmd+"\n"+record
|
// record = cmd+"\n"+record
|
||||||
binding.tvCmdRecord.text = record
|
// binding.tvCmdRecord.text = record
|
||||||
val realCmd = "${HomeActivity.HEADER}0F01${cmd}${HomeActivity.FOOTER}"
|
// val realCmd = "${HomeActivity.HEADER}0F01${cmd}${HomeActivity.FOOTER}"
|
||||||
sendCmd(realCmd)
|
// sendCmd(realCmd)
|
||||||
}
|
// }
|
||||||
binding.ivBack.setOnClickListener { finish() }
|
// binding.ivBack.setOnClickListener { finish() }
|
||||||
binding.root.setOnClickListener { v ->
|
// binding.root.setOnClickListener { v ->
|
||||||
KeyboardUtil.hideKeyboard(v)
|
// KeyboardUtil.hideKeyboard(v)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
private fun updateDateTime() {
|
// private fun updateDateTime() {
|
||||||
val sdf = SimpleDateFormat(ShelfActivity.YYYY_MM_DD__EEEE_HH_MM_SS, Locale.CHINA)
|
// val sdf = SimpleDateFormat(ShelfActivity.YYYY_MM_DD__EEEE_HH_MM_SS, Locale.CHINA)
|
||||||
val dateTime = sdf.format(Date())
|
// val dateTime = sdf.format(Date())
|
||||||
val arr = dateTime.split("***")
|
// val arr = dateTime.split("***")
|
||||||
updateLeftStatus(arr[0])
|
// updateLeftStatus(arr[0])
|
||||||
updateRightStatus(arr[1])
|
// updateRightStatus(arr[1])
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
private val handler = Handler(Looper.getMainLooper())
|
// private val handler = Handler(Looper.getMainLooper())
|
||||||
private val updateTask = object : Runnable {
|
// private val updateTask = object : Runnable {
|
||||||
override fun run() {
|
// override fun run() {
|
||||||
updateDateTime()
|
// updateDateTime()
|
||||||
handler.postDelayed(this, 1000)
|
// handler.postDelayed(this, 1000)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
override fun onResume() {
|
// override fun onResume() {
|
||||||
super.onResume()
|
// super.onResume()
|
||||||
hideStatusBar()
|
// hideStatusBar()
|
||||||
handler.post(updateTask)
|
// handler.post(updateTask)
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
override fun onPause() {
|
// override fun onPause() {
|
||||||
super.onPause()
|
// super.onPause()
|
||||||
handler.removeCallbacks(updateTask)
|
// handler.removeCallbacks(updateTask)
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
}
|
//}
|
||||||
@@ -3,8 +3,6 @@ package com.shuwei.intelligent.shelves.activity
|
|||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.Handler
|
|
||||||
import android.os.Looper
|
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.widget.LinearLayout
|
import android.widget.LinearLayout
|
||||||
import androidx.activity.viewModels
|
import androidx.activity.viewModels
|
||||||
@@ -18,7 +16,7 @@ import com.chad.library.adapter4.util.setOnDebouncedItemClick
|
|||||||
import com.scwang.smart.refresh.layout.constant.RefreshState
|
import com.scwang.smart.refresh.layout.constant.RefreshState
|
||||||
import com.shuwei.intelligent.shelves.App
|
import com.shuwei.intelligent.shelves.App
|
||||||
import com.shuwei.intelligent.shelves.R
|
import com.shuwei.intelligent.shelves.R
|
||||||
import com.shuwei.intelligent.shelves.activity.HomeActivity.Companion.DEVICE_INFO_CMD
|
import com.shuwei.intelligent.shelves.serial.ProtocolConstants
|
||||||
import com.shuwei.intelligent.shelves.adapter.SearchAdapter
|
import com.shuwei.intelligent.shelves.adapter.SearchAdapter
|
||||||
import com.shuwei.intelligent.shelves.base.BaseActivity
|
import com.shuwei.intelligent.shelves.base.BaseActivity
|
||||||
import com.shuwei.intelligent.shelves.databinding.ActivityShelfBinding
|
import com.shuwei.intelligent.shelves.databinding.ActivityShelfBinding
|
||||||
@@ -148,7 +146,7 @@ class ShelfActivity : BaseActivity() {
|
|||||||
//binding.tvFoodWeight.text = "0克"
|
//binding.tvFoodWeight.text = "0克"
|
||||||
EventBus.getDefault().post(ClearShelfEvent(shelfModel!!.deviceNo, tempWeight))
|
EventBus.getDefault().post(ClearShelfEvent(shelfModel!!.deviceNo, tempWeight))
|
||||||
}
|
}
|
||||||
sendCmd(DEVICE_INFO_CMD)
|
sendCmd(ProtocolConstants.DEVICE_INFO_CMD)
|
||||||
lifecycleScope.launch {
|
lifecycleScope.launch {
|
||||||
repeatOnLifecycle(Lifecycle.State.STARTED) {
|
repeatOnLifecycle(Lifecycle.State.STARTED) {
|
||||||
viewModel.getGoodsListUiState.collect { state ->
|
viewModel.getGoodsListUiState.collect { state ->
|
||||||
@@ -305,31 +303,23 @@ class ShelfActivity : BaseActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateDateTime() {
|
/**
|
||||||
|
* 覆写时钟回调:左侧状态栏显示年月日星期,右侧状态栏显示时分秒
|
||||||
|
*/
|
||||||
|
override fun onClockTick() {
|
||||||
val sdf = SimpleDateFormat(YYYY_MM_DD__EEEE_HH_MM_SS, Locale.CHINA)
|
val sdf = SimpleDateFormat(YYYY_MM_DD__EEEE_HH_MM_SS, Locale.CHINA)
|
||||||
val dateTime = sdf.format(Date())
|
val arr = sdf.format(Date()).split("***")
|
||||||
val arr = dateTime.split("***")
|
|
||||||
updateLeftStatus(arr[0])
|
updateLeftStatus(arr[0])
|
||||||
updateRightStatus(arr[1])
|
updateRightStatus(arr[1])
|
||||||
}
|
}
|
||||||
|
|
||||||
private val handler = Handler(Looper.getMainLooper())
|
|
||||||
private val updateTask = object : Runnable {
|
|
||||||
override fun run() {
|
|
||||||
updateDateTime()
|
|
||||||
handler.postDelayed(this, 1000)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
hideStatusBar()
|
hideStatusBar()
|
||||||
handler.post(updateTask)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPause() {
|
override fun onPause() {
|
||||||
super.onPause()
|
super.onPause()
|
||||||
handler.removeCallbacks(updateTask)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("NotifyDataSetChanged")
|
@SuppressLint("NotifyDataSetChanged")
|
||||||
@@ -371,20 +361,20 @@ class ShelfActivity : BaseActivity() {
|
|||||||
val shelfNo = shelfModel?.deviceNo ?: 0
|
val shelfNo = shelfModel?.deviceNo ?: 0
|
||||||
val hex = shelfNo.toString(16).padStart(2, '0').uppercase()
|
val hex = shelfNo.toString(16).padStart(2, '0').uppercase()
|
||||||
Log.d(TAG, "onCreate: hex=$hex")
|
Log.d(TAG, "onCreate: hex=$hex")
|
||||||
val zeroClearingCmd = "${HomeActivity.HEADER}0401${hex}${HomeActivity.FOOTER}"
|
val zeroClearingCmd = "${ProtocolConstants.HEADER}0401${hex}${ProtocolConstants.FOOTER}"
|
||||||
log("编号${shelfNo}货架执行清零指令:${zeroClearingCmd}")
|
log("编号${shelfNo}货架执行清零指令:${zeroClearingCmd}")
|
||||||
sendCmd(zeroClearingCmd)
|
sendCmd(zeroClearingCmd)
|
||||||
sendCmd(
|
// sendCmd(
|
||||||
if (shelfNo in 1..5) HomeActivity.LEFT_SHELF_OPEN_CMD else HomeActivity.RIGHT_SHELF_OPEN_CMD
|
// if (shelfNo in 1..5) ProtocolConstants.LEFT_SHELF_OPEN_CMD else ProtocolConstants.RIGHT_SHELF_OPEN_CMD
|
||||||
)
|
// )
|
||||||
//清零
|
//清零
|
||||||
realWeight = 0
|
realWeight = 0
|
||||||
// binding.tvFoodWeight.text = "${realWeight}克"
|
// binding.tvFoodWeight.text = "${realWeight}克"
|
||||||
|
|
||||||
sendCmd(DEVICE_INFO_CMD)
|
sendCmd(ProtocolConstants.DEVICE_INFO_CMD)
|
||||||
startTime = System.currentTimeMillis()
|
startTime = System.currentTimeMillis()
|
||||||
Loading.show(this@ShelfActivity)
|
Loading.show(this@ShelfActivity)
|
||||||
// window.decorView.postDelayed({ Loading.dismiss() }, 5000)
|
window.decorView.postDelayed({ Loading.dismiss() }, 10000)
|
||||||
}
|
}
|
||||||
KeyboardUtil.hideKeyboard(window.decorView)
|
KeyboardUtil.hideKeyboard(window.decorView)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,27 +5,35 @@ import android.os.Bundle
|
|||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import android.widget.PopupWindow
|
||||||
import androidx.activity.result.ActivityResultLauncher
|
import androidx.activity.result.ActivityResultLauncher
|
||||||
import androidx.activity.result.contract.ActivityResultContracts
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import com.gyf.immersionbar.BarHide
|
|
||||||
import com.gyf.immersionbar.ImmersionBar
|
|
||||||
import com.shuwei.intelligent.shelves.activity.HomeActivity
|
|
||||||
import com.shuwei.intelligent.shelves.activity.HomeActivity.Companion.LIGHT_CLOSE
|
|
||||||
import com.shuwei.intelligent.shelves.activity.HomeActivity.Companion.LIGHT_OPEN
|
|
||||||
import com.shuwei.intelligent.shelves.R
|
|
||||||
import com.shuwei.intelligent.shelves.activity.LogActivity
|
import com.shuwei.intelligent.shelves.activity.LogActivity
|
||||||
import com.shuwei.intelligent.shelves.activity.SettingActivity
|
import com.shuwei.intelligent.shelves.R
|
||||||
import com.shuwei.intelligent.shelves.databinding.ActivityBaseBinding
|
import com.shuwei.intelligent.shelves.databinding.ActivityBaseBinding
|
||||||
|
import com.shuwei.intelligent.shelves.databinding.PopupRightStatusMenuBinding
|
||||||
|
import com.shuwei.intelligent.shelves.serial.ProtocolConstants.LIGHT_CLOSE
|
||||||
|
import com.shuwei.intelligent.shelves.serial.ProtocolConstants.LIGHT_OPEN
|
||||||
import com.shuwei.intelligent.shelves.serial.SerialPortManager
|
import com.shuwei.intelligent.shelves.serial.SerialPortManager
|
||||||
import com.shuwei.intelligent.shelves.utils.FileLogger
|
import com.shuwei.intelligent.shelves.utils.FileLogger
|
||||||
import com.shuwei.intelligent.shelves.utils.ext.clickWithDebounce
|
import com.shuwei.intelligent.shelves.utils.ext.clickWithDebounce
|
||||||
|
import com.shuwei.intelligent.shelves.utils.ext.dp
|
||||||
import com.shuwei.intelligent.shelves.utils.ext.startActivity
|
import com.shuwei.intelligent.shelves.utils.ext.startActivity
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
|
import androidx.core.view.WindowCompat
|
||||||
|
import androidx.core.view.WindowInsetsCompat
|
||||||
|
import androidx.core.view.WindowInsetsControllerCompat
|
||||||
|
import com.shuwei.intelligent.shelves.utils.ext.setOnDoubleClickListener
|
||||||
|
import java.text.SimpleDateFormat
|
||||||
|
import java.util.Date
|
||||||
|
import java.util.Locale
|
||||||
|
|
||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
open class BaseActivity : AppCompatActivity() {
|
open class BaseActivity : AppCompatActivity() {
|
||||||
val TAG = this.javaClass.simpleName
|
val TAG = this.javaClass.simpleName
|
||||||
@@ -46,6 +54,7 @@ open class BaseActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
hideSystemBars()
|
||||||
binding = ActivityBaseBinding.inflate(layoutInflater)
|
binding = ActivityBaseBinding.inflate(layoutInflater)
|
||||||
setContentView(binding.root)
|
setContentView(binding.root)
|
||||||
statusBarDarkFont()
|
statusBarDarkFont()
|
||||||
@@ -56,31 +65,28 @@ open class BaseActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
|
||||||
// window.setDecorFitsSystemWindows(false)
|
|
||||||
// window.insetsController?.apply {
|
|
||||||
// hide(WindowInsets.Type.statusBars()) // 隐藏状态栏
|
|
||||||
// systemBarsBehavior =
|
|
||||||
// WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE // 滑动时临时显示
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
lightSwitchClick()
|
lightSwitchClick()
|
||||||
|
|
||||||
|
binding.tvLeftStatus.setOnDoubleClickListener {
|
||||||
|
//finish()
|
||||||
|
val intent = Intent(Intent.ACTION_MAIN).apply {
|
||||||
|
addCategory(Intent.CATEGORY_HOME)
|
||||||
|
flags = Intent.FLAG_ACTIVITY_NEW_TASK
|
||||||
|
}
|
||||||
|
startActivity(intent)
|
||||||
|
|
||||||
|
}
|
||||||
|
binding.tvRightStatus.setOnDoubleClickListener {
|
||||||
|
if (enableRightStatusMenu) showRightStatusPopup(binding.tvRightStatus)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun hideStatusBar() {
|
/** 是否允许右侧状态栏双击弹出菜单,默认关闭,仅 HomeActivity 开启 */
|
||||||
// enableEdgeToEdge()
|
protected open val enableRightStatusMenu: Boolean = false
|
||||||
// val uiOptions = (View.SYSTEM_UI_FLAG_FULLSCREEN // 隐藏状态栏
|
|
||||||
// or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) // 隐藏导航栏(可选)
|
|
||||||
// window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_FULLSCREEN
|
|
||||||
|
|
||||||
ImmersionBar.with(this)
|
fun hideStatusBar() {}
|
||||||
.hideBar(BarHide.FLAG_HIDE_STATUS_BAR)
|
|
||||||
.init()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun statusBarDarkFont() {
|
fun statusBarDarkFont() {
|
||||||
//window.decorView.systemUiVisibility = if (enable) View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR else 0
|
|
||||||
val color = ContextCompat.getColor(this, R.color.white)
|
val color = ContextCompat.getColor(this, R.color.white)
|
||||||
binding.tvLeftStatus.setTextColor(color)
|
binding.tvLeftStatus.setTextColor(color)
|
||||||
binding.tvRightStatus.setTextColor(color)
|
binding.tvRightStatus.setTextColor(color)
|
||||||
@@ -99,7 +105,7 @@ open class BaseActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun updateLeftStatus(data: String) {
|
fun updateLeftStatus(data: String) {
|
||||||
binding.tvLeftStatus.text = data
|
binding.tvLeftStatus.text = data.ifBlank { " " }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateRightStatus(data: String) {
|
fun updateRightStatus(data: String) {
|
||||||
@@ -110,11 +116,35 @@ open class BaseActivity : AppCompatActivity() {
|
|||||||
private val TIME_OUT: Long = (5 * 60 * 1000).toLong()
|
private val TIME_OUT: Long = (5 * 60 * 1000).toLong()
|
||||||
private val mHandler by lazy { Handler(Looper.getMainLooper()) }
|
private val mHandler by lazy { Handler(Looper.getMainLooper()) }
|
||||||
private val mTimeoutRunnable = Runnable {
|
private val mTimeoutRunnable = Runnable {
|
||||||
if (this is HomeActivity) {
|
// 用户长时间无操作时回调,子类可覆写实现具体逻辑(如关灯)
|
||||||
this.switchLight(false)
|
onUserInactive()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---- 右侧状态栏时钟 ----
|
||||||
|
// 默认时间格式:月日星期 时:分:秒
|
||||||
|
private val CLOCK_FORMAT = "MM月dd日 EEEE HH:mm:ss"
|
||||||
|
private val clockFormatter by lazy { SimpleDateFormat(CLOCK_FORMAT, Locale.CHINA) }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 每秒时钟回调,默认将当前时间显示在右侧状态栏。
|
||||||
|
* 子类可覆写以自定义格式或同时更新左侧状态栏。
|
||||||
|
*/
|
||||||
|
open fun onClockTick() {
|
||||||
|
updateRightStatus(clockFormatter.format(Date()))
|
||||||
|
}
|
||||||
|
|
||||||
|
private val clockTask = object : Runnable {
|
||||||
|
override fun run() {
|
||||||
|
onClockTick()
|
||||||
|
mHandler.postDelayed(this, 1000)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户超时无操作时回调,默认空实现,子类按需覆写
|
||||||
|
*/
|
||||||
|
open fun onUserInactive() {}
|
||||||
|
|
||||||
override fun onUserInteraction() {
|
override fun onUserInteraction() {
|
||||||
super.onUserInteraction()
|
super.onUserInteraction()
|
||||||
//开灯
|
//开灯
|
||||||
@@ -131,14 +161,18 @@ open class BaseActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
// 启动定时器
|
// 启动超时定时器
|
||||||
mHandler.postDelayed(mTimeoutRunnable, TIME_OUT)
|
mHandler.postDelayed(mTimeoutRunnable, TIME_OUT)
|
||||||
|
// 启动右侧状态栏时钟
|
||||||
|
mHandler.post(clockTask)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPause() {
|
override fun onPause() {
|
||||||
super.onPause()
|
super.onPause()
|
||||||
// 取消定时器
|
// 取消超时定时器
|
||||||
mHandler.removeCallbacks(mTimeoutRunnable)
|
mHandler.removeCallbacks(mTimeoutRunnable)
|
||||||
|
// 停止右侧状态栏时钟
|
||||||
|
mHandler.removeCallbacks(clockTask)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun switchLight(isOpen: Boolean) {
|
fun switchLight(isOpen: Boolean) {
|
||||||
@@ -156,15 +190,27 @@ open class BaseActivity : AppCompatActivity() {
|
|||||||
val tag = binding.tvLeftStatus.tag?.toString()?.toBoolean() ?: true
|
val tag = binding.tvLeftStatus.tag?.toString()?.toBoolean() ?: true
|
||||||
switchLight(tag.not())
|
switchLight(tag.not())
|
||||||
}
|
}
|
||||||
binding.tvRightStatus.clickWithDebounce {
|
}
|
||||||
if (this is HomeActivity) {
|
|
||||||
|
private fun showRightStatusPopup(anchor: View) {
|
||||||
|
val menuBinding = PopupRightStatusMenuBinding.inflate(LayoutInflater.from(this))
|
||||||
|
val popup = PopupWindow(
|
||||||
|
menuBinding.root,
|
||||||
|
120.dp,
|
||||||
|
101.dp,
|
||||||
|
true
|
||||||
|
)
|
||||||
|
menuBinding.tvEnvSwitch.setOnClickListener {
|
||||||
|
popup.dismiss()
|
||||||
|
EnvSwitchDialog(this).show()
|
||||||
|
}
|
||||||
|
menuBinding.tvLog.setOnClickListener {
|
||||||
|
popup.dismiss()
|
||||||
startActivity<LogActivity> {
|
startActivity<LogActivity> {
|
||||||
putExtra(LogActivity.IS_LOG_DIR, true)
|
putExtra(LogActivity.IS_LOG_DIR, true)
|
||||||
}
|
}
|
||||||
return@clickWithDebounce
|
|
||||||
}
|
|
||||||
startActivity<SettingActivity> { }
|
|
||||||
}
|
}
|
||||||
|
popup.showAsDropDown(anchor)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -181,4 +227,34 @@ open class BaseActivity : AppCompatActivity() {
|
|||||||
fileLogger.log(message)
|
fileLogger.log(message)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 窗口焦点变化时回调
|
||||||
|
* 场景:弹出 Dialog 后焦点丢失,Dialog 消失后焦点恢复,此时需重新隐藏系统栏,
|
||||||
|
* 避免系统栏在 Dialog 关闭后意外"复活"
|
||||||
|
*/
|
||||||
|
override fun onWindowFocusChanged(hasFocus: Boolean) {
|
||||||
|
super.onWindowFocusChanged(hasFocus)
|
||||||
|
if (hasFocus) {
|
||||||
|
hideSystemBars()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 隐藏状态栏和导航栏
|
||||||
|
* 使用 WindowInsetsControllerCompat(Androidx 推荐方式,向下兼容性好)
|
||||||
|
* - 状态栏:完全隐藏
|
||||||
|
* - 导航栏:完全隐藏,底部上滑时临时出现,松手后自动收回(BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE)
|
||||||
|
*/
|
||||||
|
private fun hideSystemBars() {
|
||||||
|
// 允许布局延伸到系统栏区域(edge-to-edge),避免内容被系统栏遮挡
|
||||||
|
WindowCompat.setDecorFitsSystemWindows(window, false)
|
||||||
|
WindowInsetsControllerCompat(window, window.decorView).apply {
|
||||||
|
// 同时隐藏状态栏和导航栏
|
||||||
|
hide(WindowInsetsCompat.Type.systemBars())
|
||||||
|
// 底部上滑时临时显示导航栏,松手后自动隐藏(沉浸式 Sticky 模式)
|
||||||
|
systemBarsBehavior =
|
||||||
|
WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
package com.shuwei.intelligent.shelves.base
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
|
import android.view.WindowManager
|
||||||
|
import com.shuwei.intelligent.shelves.GlobalData
|
||||||
|
import com.shuwei.intelligent.shelves.databinding.DialogEnvSwitchBinding
|
||||||
|
import com.shuwei.intelligent.shelves.utils.SpTool
|
||||||
|
import com.shuwei.intelligent.shelves.utils.ToastUtil
|
||||||
|
import com.shuwei.intelligent.shelves.utils.ext.dp
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 环境切换弹窗
|
||||||
|
*
|
||||||
|
* 提供 TEST / UAT / PROD 三套环境的切换功能,
|
||||||
|
* 初始化时自动根据 [GlobalData.appBaseUrl] 选中当前环境,
|
||||||
|
* 确认后更新 [GlobalData.appBaseUrl] 并通过 [onEnvChanged] 回调通知外部。
|
||||||
|
*
|
||||||
|
* @param context 上下文
|
||||||
|
* @param onEnvChanged 确认切换后的回调,参数为新的 baseUrl
|
||||||
|
*/
|
||||||
|
class EnvSwitchDialog(
|
||||||
|
context: Context,
|
||||||
|
private val onEnvChanged: (newBaseUrl: String) -> Unit = {}
|
||||||
|
) : BaseDialog(
|
||||||
|
context,
|
||||||
|
defWidth = 600.dp,
|
||||||
|
defHeight = WindowManager.LayoutParams.WRAP_CONTENT
|
||||||
|
) {
|
||||||
|
|
||||||
|
private lateinit var binding: DialogEnvSwitchBinding
|
||||||
|
|
||||||
|
override fun getRootView(): View {
|
||||||
|
binding = DialogEnvSwitchBinding.inflate(LayoutInflater.from(context))
|
||||||
|
return binding.root
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun initView() {
|
||||||
|
// 根据当前 appBaseUrl 预选对应 RadioButton,不匹配则不选
|
||||||
|
when (GlobalData.appBaseUrl) {
|
||||||
|
GlobalData.TEST_BASE_URL -> binding.rbTest.isChecked = true
|
||||||
|
GlobalData.UAT_BASE_URL -> binding.rbUat.isChecked = true
|
||||||
|
GlobalData.PROD_BASE_URL -> binding.rbProd.isChecked = true
|
||||||
|
}
|
||||||
|
|
||||||
|
// 取消按钮
|
||||||
|
binding.btnCancel.setOnClickListener { dismiss() }
|
||||||
|
|
||||||
|
// 确认按钮
|
||||||
|
binding.btnConfirm.setOnClickListener {
|
||||||
|
// 未选中任何选项时提示用户
|
||||||
|
if (binding.rgEnv.checkedRadioButtonId == -1) {
|
||||||
|
ToastUtil.show(context,"请选择环境")
|
||||||
|
return@setOnClickListener
|
||||||
|
}
|
||||||
|
val newUrl = when (binding.rgEnv.checkedRadioButtonId) {
|
||||||
|
binding.rbTest.id -> GlobalData.TEST_BASE_URL
|
||||||
|
binding.rbUat.id -> GlobalData.UAT_BASE_URL
|
||||||
|
binding.rbProd.id -> GlobalData.PROD_BASE_URL
|
||||||
|
else -> return@setOnClickListener
|
||||||
|
}
|
||||||
|
GlobalData.appBaseUrl = newUrl
|
||||||
|
SpTool.baseUrl = newUrl
|
||||||
|
onEnvChanged(newUrl)
|
||||||
|
dismiss()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,7 +2,8 @@ package com.shuwei.intelligent.shelves.net
|
|||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import com.shuwei.intelligent.shelves.App
|
import com.shuwei.intelligent.shelves.BuildConfig
|
||||||
|
import com.shuwei.intelligent.shelves.GlobalData
|
||||||
import okhttp3.Interceptor
|
import okhttp3.Interceptor
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
import okhttp3.Response
|
import okhttp3.Response
|
||||||
@@ -18,7 +19,7 @@ import kotlin.apply
|
|||||||
|
|
||||||
val apiService: ApiService = Retrofit.Builder()
|
val apiService: ApiService = Retrofit.Builder()
|
||||||
// .baseUrl(UrlConfig.BASE_URL)
|
// .baseUrl(UrlConfig.BASE_URL)
|
||||||
.baseUrl(UrlConfig.DEVICE_BASE_URL)
|
.baseUrl(GlobalData.appBaseUrl)
|
||||||
.client(HttpManager.instance.client)
|
.client(HttpManager.instance.client)
|
||||||
.addConverterFactory(GsonConverterFactory.create())
|
.addConverterFactory(GsonConverterFactory.create())
|
||||||
.build()
|
.build()
|
||||||
@@ -28,9 +29,9 @@ class HttpManager private constructor() {
|
|||||||
val client: OkHttpClient by lazy {
|
val client: OkHttpClient by lazy {
|
||||||
OkHttpClient.Builder()
|
OkHttpClient.Builder()
|
||||||
.apply {
|
.apply {
|
||||||
connectTimeout(15, TimeUnit.SECONDS)
|
connectTimeout(30, TimeUnit.SECONDS)
|
||||||
readTimeout(30, TimeUnit.SECONDS)
|
readTimeout(30, TimeUnit.SECONDS)
|
||||||
writeTimeout(15, TimeUnit.SECONDS)
|
writeTimeout(30, TimeUnit.SECONDS)
|
||||||
sslSocketFactory(createSSLSocketFactory(), TrustAllCerts())
|
sslSocketFactory(createSSLSocketFactory(), TrustAllCerts())
|
||||||
hostnameVerifier { _, _ -> true }
|
hostnameVerifier { _, _ -> true }
|
||||||
// addInterceptor(LoggingInterceptor())
|
// addInterceptor(LoggingInterceptor())
|
||||||
@@ -38,11 +39,11 @@ class HttpManager private constructor() {
|
|||||||
Log.d("HttpManager","okhttp logger ==>${it}")
|
Log.d("HttpManager","okhttp logger ==>${it}")
|
||||||
}).apply {
|
}).apply {
|
||||||
level =
|
level =
|
||||||
// if (MyApp.DEBUG) {
|
if (BuildConfig.DEBUG) {
|
||||||
HttpLoggingInterceptor.Level.BODY
|
HttpLoggingInterceptor.Level.BODY
|
||||||
// } else {
|
} else {
|
||||||
// HttpLoggingInterceptor.Level.NONE
|
HttpLoggingInterceptor.Level.NONE
|
||||||
// }
|
}
|
||||||
})
|
})
|
||||||
// addInterceptor { chain ->
|
// addInterceptor { chain ->
|
||||||
// val request = chain.request().newBuilder()
|
// val request = chain.request().newBuilder()
|
||||||
|
|||||||
@@ -5,31 +5,16 @@ import androidx.lifecycle.ViewModel
|
|||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import com.shuwei.intelligent.shelves.App
|
import com.shuwei.intelligent.shelves.App
|
||||||
import com.shuwei.intelligent.shelves.model.ShelfBody
|
import com.shuwei.intelligent.shelves.model.ShelfBody
|
||||||
import com.shuwei.intelligent.shelves.model.ShelfModel
|
|
||||||
import com.shuwei.intelligent.shelves.net.HttpManager.Companion.instance
|
|
||||||
import com.shuwei.intelligent.shelves.utils.ext.toJsonString
|
import com.shuwei.intelligent.shelves.utils.ext.toJsonString
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import retrofit2.Retrofit
|
|
||||||
import retrofit2.converter.gson.GsonConverterFactory
|
|
||||||
|
|
||||||
class NetViewModel : ViewModel() {
|
class NetViewModel : ViewModel() {
|
||||||
|
|
||||||
// val apiService: ApiService = HttpManager.instance.apiService
|
|
||||||
// val apiService: ApiService = Retrofit.Builder()
|
|
||||||
// .baseUrl(UrlConfig.BASE_URL)
|
|
||||||
// .client(HttpManager.instance.client)
|
|
||||||
// .addConverterFactory(GsonConverterFactory.create())
|
|
||||||
// .build()
|
|
||||||
// .create(ApiService::class.java)
|
|
||||||
|
|
||||||
private val _getShelfListUiState = MutableStateFlow<UiState>(UiState.Initial)
|
private val _getShelfListUiState = MutableStateFlow<UiState>(UiState.Initial)
|
||||||
val getShelfListUiState: StateFlow<UiState> = _getShelfListUiState
|
val getShelfListUiState: StateFlow<UiState> = _getShelfListUiState
|
||||||
|
|
||||||
// private val _saveShelfGoodsListUiState = MutableStateFlow<UiState>(UiState.Initial)
|
|
||||||
// val saveShelfGoodsListUiState: StateFlow<UiState> = _saveShelfGoodsListUiState
|
|
||||||
|
|
||||||
private val _getGoodsListUiState = MutableStateFlow<UiState>(UiState.Initial)
|
private val _getGoodsListUiState = MutableStateFlow<UiState>(UiState.Initial)
|
||||||
val getGoodsListUiState: StateFlow<UiState> = _getGoodsListUiState
|
val getGoodsListUiState: StateFlow<UiState> = _getGoodsListUiState
|
||||||
|
|
||||||
@@ -42,6 +27,8 @@ class NetViewModel : ViewModel() {
|
|||||||
private val _getDeviceConfigUiState = MutableStateFlow<UiState>(UiState.Initial)
|
private val _getDeviceConfigUiState = MutableStateFlow<UiState>(UiState.Initial)
|
||||||
val getDeviceConfigUiState: StateFlow<UiState> = _getDeviceConfigUiState
|
val getDeviceConfigUiState: StateFlow<UiState> = _getDeviceConfigUiState
|
||||||
|
|
||||||
|
private val _updateOverdueStateUiState = MutableStateFlow<UiState>(UiState.Initial)
|
||||||
|
val updateOverdueStateUiState: StateFlow<UiState> = _updateOverdueStateUiState
|
||||||
|
|
||||||
fun getDeviceToken(deviceId: String) {
|
fun getDeviceToken(deviceId: String) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
@@ -61,17 +48,16 @@ class NetViewModel : ViewModel() {
|
|||||||
|
|
||||||
fun getDeviceConfig(deviceId: String, deviceToken: String) {
|
fun getDeviceConfig(deviceId: String, deviceToken: String) {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
_getDeviceTokenUiState.value = UiState.Loading
|
_getDeviceConfigUiState.value = UiState.Loading
|
||||||
runCatching {
|
runCatching {
|
||||||
val response =
|
val response = apiService.getDeviceInfo(equipmentCode = deviceId)
|
||||||
apiService.getDeviceInfo(equipmentCode = deviceId)
|
|
||||||
if (response.isSuccess()) {
|
if (response.isSuccess()) {
|
||||||
_getDeviceTokenUiState.value = UiState.Success(response)
|
_getDeviceConfigUiState.value = UiState.Success(response)
|
||||||
} else {
|
} else {
|
||||||
_getDeviceTokenUiState.value = UiState.Error(response.msg ?: "请求失败")
|
_getDeviceConfigUiState.value = UiState.Error(response.msg ?: "请求失败")
|
||||||
}
|
}
|
||||||
}.onFailure {
|
}.onFailure {
|
||||||
_getDeviceTokenUiState.value = UiState.Error(it.message ?: "请求异常")
|
_getDeviceConfigUiState.value = UiState.Error(it.message ?: "请求异常")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -108,37 +94,21 @@ class NetViewModel : ViewModel() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateOverdueState(block:(Boolean, List<ShelfModel>?)-> Unit) {
|
fun updateOverdueState() {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
runCatching {
|
runCatching {
|
||||||
val response = apiService.getShelfList(deviceId = App.deviceId)
|
val response = apiService.getShelfList(deviceId = App.deviceId)
|
||||||
if (response.isSuccess()) {
|
if (response.isSuccess()) {
|
||||||
block(true, response.data?.containerGoodsList)
|
_updateOverdueStateUiState.value = UiState.Success(response)
|
||||||
} else {
|
} else {
|
||||||
block(false, emptyList())
|
_updateOverdueStateUiState.value = UiState.Error(response.msg ?: "请求失败")
|
||||||
}
|
}
|
||||||
}.onFailure {
|
}.onFailure {
|
||||||
block(false, null)
|
_updateOverdueStateUiState.value = UiState.Error(it.message ?: "请求异常")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// fun saveShelfGoodsList(body: ShelfBody) {
|
|
||||||
// viewModelScope.launch {
|
|
||||||
// _saveShelfGoodsListUiState.value = UiState.Loading
|
|
||||||
// runCatching {
|
|
||||||
// val response = apiService.saveShelfGoodsList(body)
|
|
||||||
// if (response.success) {
|
|
||||||
// _saveShelfGoodsListUiState.value = UiState.Success(response)
|
|
||||||
// } else {
|
|
||||||
// _saveShelfGoodsListUiState.value = UiState.Error(response.message ?: "请求失败")
|
|
||||||
// }
|
|
||||||
// }.onFailure {
|
|
||||||
// _saveShelfGoodsListUiState.value = UiState.Error(it.message ?: "请求异常")
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
fun getGoodsList(
|
fun getGoodsList(
|
||||||
canteenId: String = "",
|
canteenId: String = "",
|
||||||
goodsName: String = "",
|
goodsName: String = "",
|
||||||
@@ -148,9 +118,6 @@ class NetViewModel : ViewModel() {
|
|||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
_getGoodsListUiState.value = UiState.Loading
|
_getGoodsListUiState.value = UiState.Loading
|
||||||
runCatching {
|
runCatching {
|
||||||
if (App.configUrl.isNullOrBlank()) {
|
|
||||||
App.configUrl = UrlConfig.BASE_URL
|
|
||||||
}
|
|
||||||
val response = apiService.getGoodsList(
|
val response = apiService.getGoodsList(
|
||||||
canteenId = canteenId,
|
canteenId = canteenId,
|
||||||
goodsName = goodsName,
|
goodsName = goodsName,
|
||||||
@@ -178,7 +145,5 @@ class NetViewModel : ViewModel() {
|
|||||||
Log.d("NetViewModel", "saveShelfGoodsList异常:${it.message}")
|
Log.d("NetViewModel", "saveShelfGoodsList异常:${it.message}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.shuwei.intelligent.shelves.net
|
package com.shuwei.intelligent.shelves.net
|
||||||
|
|
||||||
import com.shuwei.intelligent.shelves.App
|
import com.shuwei.intelligent.shelves.App
|
||||||
|
import com.shuwei.intelligent.shelves.GlobalData
|
||||||
|
|
||||||
object UrlConfig {
|
object UrlConfig {
|
||||||
// const val DEVICE_BASE_URL = "http://device.shuziweidao.com:8889"
|
// const val DEVICE_BASE_URL = "http://device.shuziweidao.com:8889"
|
||||||
@@ -13,18 +14,18 @@ object UrlConfig {
|
|||||||
// */
|
// */
|
||||||
// const val DEVICE_CONFIG = "${DEVICE_BASE_URL}/equipment/stEquipment/queryByEquipmentCode"
|
// const val DEVICE_CONFIG = "${DEVICE_BASE_URL}/equipment/stEquipment/queryByEquipmentCode"
|
||||||
|
|
||||||
const val BASE_URL = "https://dev.yixiong-tech.com:8081"
|
// const val BASE_URL = "https://dev.yixiong-tech.com:8081"
|
||||||
// const val BASE_URL = "https://yyjk.shuziweidao.com/gateway"
|
//// const val BASE_URL = "https://yyjk.shuziweidao.com/gateway"
|
||||||
// const val BASE_URL = "http://192.168.1.201:14801"
|
//// const val BASE_URL = "http://192.168.1.201:14801"
|
||||||
const val DEVICE_BASE_URL = BASE_URL
|
// const val DEVICE_BASE_URL = BASE_URL
|
||||||
|
|
||||||
var GET_ACCESS_TOKEN = "${App.configUrl}/restaurant/equipment/stEquipment/getEquipmentToken"
|
var GET_ACCESS_TOKEN = "${GlobalData.appBaseUrl}/restaurant/equipment/stEquipment/getEquipmentToken"
|
||||||
var GET_SHELF_LIST =
|
var GET_SHELF_LIST =
|
||||||
"${App.configUrl}/terminal/neglect/smartShelves/app/smartShelves/app/getShelvesListByDeviceId"
|
"${GlobalData.appBaseUrl}/terminal/neglect/smartShelves/app/smartShelves/app/getShelvesListByDeviceId"
|
||||||
var GET_GOODS_LIST =
|
var GET_GOODS_LIST =
|
||||||
"${App.configUrl}/terminal/neglect/smartShelves/app/smartShelves/app/getGoodsPageList"
|
"${GlobalData.appBaseUrl}/terminal/neglect/smartShelves/app/smartShelves/app/getGoodsPageList"
|
||||||
var SAVE_SHELF_GOODS_LIST =
|
var SAVE_SHELF_GOODS_LIST =
|
||||||
"${App.configUrl}/terminal/neglect/smartShelves/app/smartShelves/app/saveShelvesGoodsList"
|
"${GlobalData.appBaseUrl}/terminal/neglect/smartShelves/app/smartShelves/app/saveShelvesGoodsList"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,180 @@
|
|||||||
|
package com.shuwei.intelligent.shelves.serial
|
||||||
|
|
||||||
|
import com.shuwei.intelligent.shelves.App
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 串口通信协议常量定义
|
||||||
|
* 统一管理所有协议头、协议尾、各类指令及帧解析偏移量
|
||||||
|
*/
|
||||||
|
object ProtocolConstants {
|
||||||
|
|
||||||
|
/** 协议头 */
|
||||||
|
const val HEADER = "D6DADEDB"
|
||||||
|
|
||||||
|
/** 协议尾 */
|
||||||
|
const val FOOTER = "FFFF"
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
// 指令码(cmd 字段,4字符)
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
|
||||||
|
/** 终端激活指令 */
|
||||||
|
const val CMD_ACTIVATE = "0001"
|
||||||
|
|
||||||
|
/** 心跳指令(服务端发起) */
|
||||||
|
const val CMD_HEARTBEAT = "0101"
|
||||||
|
|
||||||
|
/** 心跳指令(终端发起) */
|
||||||
|
const val CMD_HEARTBEAT_TERMINAL = "8101"
|
||||||
|
|
||||||
|
/** 开关锁反馈 */
|
||||||
|
const val CMD_LOCK_FEEDBACK = "0202"
|
||||||
|
|
||||||
|
/** 获取设备状态 */
|
||||||
|
const val CMD_DEVICE_STATUS = "0302"
|
||||||
|
|
||||||
|
/** 卡号上发 */
|
||||||
|
const val CMD_CARD_UPLOAD = "0501"
|
||||||
|
|
||||||
|
/** 操作记录上传 */
|
||||||
|
const val CMD_OPERATION_RECORD = "0B01"
|
||||||
|
|
||||||
|
/** 对时 */
|
||||||
|
const val CMD_TIME_SYNC = "0C01"
|
||||||
|
|
||||||
|
/** 终端位置上报 */
|
||||||
|
const val CMD_POSITION_REPORT = "0E01"
|
||||||
|
|
||||||
|
/** 温控信息上报 */
|
||||||
|
const val CMD_TEMP_REPORT = "1001"
|
||||||
|
|
||||||
|
/** 温控信息应答 */
|
||||||
|
const val CMD_TEMP_RESPONSE = "1002"
|
||||||
|
|
||||||
|
/** 温控应答(备用) */
|
||||||
|
const val CMD_TEMP_RESPONSE_ALT = "0F02"
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
// 帧数据偏移 / 尺寸常量
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
|
||||||
|
/** 心跳帧中重量数据起始偏移(相对帧起始) */
|
||||||
|
const val HEARTBEAT_WEIGHT_OFFSET = 14
|
||||||
|
|
||||||
|
/** 设备状态帧中重量数据起始偏移(含协议头长度) */
|
||||||
|
const val DEVICE_STATUS_WEIGHT_OFFSET = HEADER.length + 14
|
||||||
|
|
||||||
|
/** 货架数量(每侧5格,共10格,协议中12组) */
|
||||||
|
fun shelfSensorCount(): Int {
|
||||||
|
return if (device2Columns.contains(App.deviceId)) 12
|
||||||
|
else if (device3Columns.contains(App.deviceId)) 24
|
||||||
|
else 0
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 每组重量数据字节数(十六进制字符数) */
|
||||||
|
const val BYTES_PER_WEIGHT = 8
|
||||||
|
|
||||||
|
/** 温度字段字符长度 */
|
||||||
|
const val TEMPERATURE_FIELD_LEN = 2
|
||||||
|
|
||||||
|
/** 心跳帧最小有效长度 */
|
||||||
|
fun heartbeatMinLength(): Int {
|
||||||
|
return if (device2Columns.contains(App.deviceId)) 200
|
||||||
|
else if (device3Columns.contains(App.deviceId)) 296
|
||||||
|
else 0
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 心跳帧中温度字段起始偏移(经协议分析得出,前面含重量+其他传感器数据) */
|
||||||
|
fun heartbeatTemperatureStart(): Int {
|
||||||
|
return if (device2Columns.contains(App.deviceId)) 158
|
||||||
|
else if (device3Columns.contains(App.deviceId)) 158+96
|
||||||
|
else 0
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 激活请求体有效长度 */
|
||||||
|
const val ACTIVATE_BODY_LENGTH = 44
|
||||||
|
|
||||||
|
/** 固定数据体有效长度(terminalId 30 + terminalVersion 10 + 其他 2) */
|
||||||
|
const val FIX_BODY_LENGTH = 42
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
// 完整指令
|
||||||
|
// ----------------------------------------------------------------
|
||||||
|
|
||||||
|
/** 激活指令(1楼餐厅) */
|
||||||
|
// const val ACTIVE_CMD =
|
||||||
|
// "${HEADER}000281C5D70A7D428B44A57454F5DACA241938938B4B9CBD73673E9C8E7FC0C4992D${FOOTER}"
|
||||||
|
|
||||||
|
// 410激活码
|
||||||
|
// const val ACTIVE_CMD = "${HEADER}000281C5D70A7D42894EA17650F5D0BB516838E7863C9ABD766C38958AFF0F3C062D${FOOTER}"
|
||||||
|
|
||||||
|
/** 左货架开锁指令 */
|
||||||
|
const val LEFT_SHELF_OPEN_CMD =
|
||||||
|
"${HEADER}020101000000000000000000000000000000000000${FOOTER}"
|
||||||
|
|
||||||
|
/** 右货架开锁指令 */
|
||||||
|
const val RIGHT_SHELF_OPEN_CMD =
|
||||||
|
"${HEADER}020100010000000000000000000000000000000000${FOOTER}"
|
||||||
|
|
||||||
|
/** 获取设备信息指令 */
|
||||||
|
const val DEVICE_INFO_CMD = "${HEADER}0301000000000000000000000000${FOOTER}"
|
||||||
|
|
||||||
|
/** 启动温控指令 */
|
||||||
|
const val START_TEMP_CTRL_CMD = "${HEADER}0F01360000${FOOTER}"
|
||||||
|
|
||||||
|
/** 华氏温度单位指令 */
|
||||||
|
const val F_TEMP_CMD = "${HEADER}0F01390000${FOOTER}"
|
||||||
|
|
||||||
|
/** 摄氏温度单位指令 */
|
||||||
|
const val C_TEMP_CMD = "${HEADER}0F01390001${FOOTER}"
|
||||||
|
|
||||||
|
/** 关灯指令(继电器1关) */
|
||||||
|
const val LIGHT_CLOSE = "${HEADER}020102020102020000000000000000000000000000${FOOTER}"
|
||||||
|
|
||||||
|
/** 开灯指令(继电器1开) */
|
||||||
|
const val LIGHT_OPEN = "${HEADER}020102020002020000000000000000000000000000${FOOTER}"
|
||||||
|
|
||||||
|
/** 温控指令 */
|
||||||
|
const val TEMPERATURE_CTRL = "${HEADER}0F01040000${FOOTER}"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设备2列,10格
|
||||||
|
*/
|
||||||
|
val device2Columns = listOf(
|
||||||
|
//原410货柜
|
||||||
|
"7a991439-3a12-3ef7-809b-c0258b839473",
|
||||||
|
//原1楼餐厅货柜
|
||||||
|
"4787e213-90ab-3e32-88e0-ac271a937751"
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设备3列,15格,左侧1列竖向编号1、2、3、4、5,右侧2列5行编号为6-7、8-9、10-11、12-13、14-15
|
||||||
|
*/
|
||||||
|
val device3ColumnsOrder = listOf(1, 6, 7, 2, 8, 9, 3, 10, 11, 4, 12, 13, 5, 14, 15)
|
||||||
|
/**
|
||||||
|
* 设备2列,10格,左侧1列竖向编号1、2、3、4、5,右侧1列6,7,8,9,10
|
||||||
|
*/
|
||||||
|
val device2ColumnsOrder = listOf(1, 6, 2, 7, 3, 8, 4, 9, 5, 10)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设备3列,15格,左侧1列竖向编号1、2、3、4、5,右侧2列5行编号为6-7、8-9、10-11、12-13、14-15
|
||||||
|
*/
|
||||||
|
val device3Columns = listOf(
|
||||||
|
//新设备1
|
||||||
|
"d369f9b0-1c5b-3066-ba72-988e1449cecc",
|
||||||
|
//新设备2
|
||||||
|
"505ce1b1-facc-3eb2-855a-3dadda5ba358"
|
||||||
|
)
|
||||||
|
|
||||||
|
/** 激活指令map,key为设备号,value为激活码 */
|
||||||
|
val ACTIVE_MAP = mutableMapOf(
|
||||||
|
//原410货柜
|
||||||
|
"7a991439-3a12-3ef7-809b-c0258b839473" to "${HEADER}000281C5D70A7D42894EA17650F5D0BB516838E7863C9ABD766C38958AFF0F3C062D${FOOTER}",
|
||||||
|
//原1楼餐厅货柜
|
||||||
|
"4787e213-90ab-3e32-88e0-ac271a937751" to "${HEADER}000281C5D70A7D428B44A57454F5DACA241938938B4B9CBD73673E9C8E7FC0C4992D${FOOTER}",
|
||||||
|
//新设备1,临时使用1楼餐厅激活码
|
||||||
|
"d369f9b0-1c5b-3066-ba72-988e1449cecc" to "${HEADER}000281C5D70A7D428B44A57454F5DACA241938938B4B9CBD73673E9C8E7FC0C4992D${FOOTER}",
|
||||||
|
//新设备2,临时使用1楼餐厅激活码
|
||||||
|
"505ce1b1-facc-3eb2-855a-3dadda5ba358" to "${HEADER}000281C5D70A7D428B44A57454F5DACA241938938B4B9CBD73673E9C8E7FC0C4992D${FOOTER}",
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
package com.shuwei.intelligent.shelves.serial
|
||||||
|
|
||||||
|
import com.shuwei.intelligent.shelves.serial.ProtocolConstants.FOOTER
|
||||||
|
import com.shuwei.intelligent.shelves.serial.ProtocolConstants.HEADER
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 串口数据帧解析器
|
||||||
|
* 负责将串口原始分片数据拼装为完整协议帧
|
||||||
|
* 完整帧格式:[HEADER][CMD][BODY][FOOTER]
|
||||||
|
*/
|
||||||
|
class SerialFrameParser {
|
||||||
|
|
||||||
|
/** 数据帧缓冲区,用于跨分片拼装 */
|
||||||
|
private val buffer = StringBuilder()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解析原始串口分片数据,尝试拼装为完整帧
|
||||||
|
* @param srcData 原始串口数据片段
|
||||||
|
* @return 完整数据帧字符串;帧不完整时返回 null
|
||||||
|
*/
|
||||||
|
fun parse(srcData: String): String? {
|
||||||
|
val hasHeader = srcData.contains(HEADER)
|
||||||
|
val hasFooter = srcData.contains(FOOTER)
|
||||||
|
|
||||||
|
return when {
|
||||||
|
hasHeader && hasFooter -> parseCompleteInSingleChunk(srcData)
|
||||||
|
hasHeader && !hasFooter -> {
|
||||||
|
// 仅含帧头,等待后续分片
|
||||||
|
buffer.clear()
|
||||||
|
buffer.append(srcData.substring(srcData.lastIndexOf(HEADER))).append(",")
|
||||||
|
null
|
||||||
|
}
|
||||||
|
!hasHeader && !hasFooter -> {
|
||||||
|
// 中间分片,追加缓冲
|
||||||
|
buffer.append(srcData).append(",")
|
||||||
|
null
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
// 仅含帧尾,与缓冲区拼接完整帧
|
||||||
|
val endIndex = srcData.indexOf(FOOTER) + FOOTER.length
|
||||||
|
buffer.append(srcData.substring(0, endIndex))
|
||||||
|
val frame = buffer.toString().replace(",", "")
|
||||||
|
buffer.clear()
|
||||||
|
frame.takeIf { it.isNotEmpty() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 单个分片中同时含有帧头和帧尾的情况
|
||||||
|
*/
|
||||||
|
private fun parseCompleteInSingleChunk(srcData: String): String? {
|
||||||
|
buffer.clear()
|
||||||
|
val startIndex = srcData.lastIndexOf(HEADER)
|
||||||
|
val endIndex = srcData.indexOf(FOOTER) + FOOTER.length
|
||||||
|
|
||||||
|
return if (endIndex < startIndex) {
|
||||||
|
// 帧尾在帧头之前,说明是上一帧的残留尾部 + 新帧的头部
|
||||||
|
// 例:31314FFFFFD6DADEDB01010C
|
||||||
|
val partial = srcData.substring(startIndex)
|
||||||
|
if (partial.contains(FOOTER)) {
|
||||||
|
// 当前片段中新帧已完整
|
||||||
|
val newEnd = partial.indexOf(FOOTER) + FOOTER.length
|
||||||
|
partial.substring(0, newEnd)
|
||||||
|
} else {
|
||||||
|
// 新帧不完整,缓存等待后续分片
|
||||||
|
buffer.append(partial).append(",")
|
||||||
|
null
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 帧头在帧尾之前,正常完整帧
|
||||||
|
srcData.substring(startIndex, endIndex)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 清空缓冲区 */
|
||||||
|
fun reset() {
|
||||||
|
buffer.clear()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,8 +13,9 @@ import java.nio.charset.Charset
|
|||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
|
|
||||||
object SerialPortManager {
|
object SerialPortManager {
|
||||||
private const val portName: String = "/dev/ttyS1"
|
|
||||||
private const val baudRate: Int = 115200
|
private const val PORT_NAME: String = "/dev/ttyS1"
|
||||||
|
private const val BAUD_RATE: Int = 115200
|
||||||
private var serialPort: AndroidSerialPort? = null
|
private var serialPort: AndroidSerialPort? = null
|
||||||
|
|
||||||
// private var serialPort: SerialPort? = null
|
// private var serialPort: SerialPort? = null
|
||||||
@@ -25,8 +26,8 @@ object SerialPortManager {
|
|||||||
return try {
|
return try {
|
||||||
serialPort = SerialPortFactory.create().apply {
|
serialPort = SerialPortFactory.create().apply {
|
||||||
open(
|
open(
|
||||||
portName = portName,
|
portName = PORT_NAME,
|
||||||
baudRate = baudRate,
|
baudRate = BAUD_RATE,
|
||||||
dataBits = 8,
|
dataBits = 8,
|
||||||
stopBits = 1,
|
stopBits = 1,
|
||||||
parity = SerialPort.PARITY_NONE
|
parity = SerialPort.PARITY_NONE
|
||||||
@@ -51,15 +52,13 @@ object SerialPortManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 启动接收协程
|
// 启动接收协程
|
||||||
@Suppress("DEPRECATION")
|
|
||||||
@SuppressLint("DefaultLocale")
|
|
||||||
fun startReceive(callback: (String) -> Unit) {
|
fun startReceive(callback: (String) -> Unit) {
|
||||||
scope.launch {
|
scope.launch {
|
||||||
while (isActive) {
|
while (isActive) {
|
||||||
try {
|
try {
|
||||||
val flow = serialPort?.read()
|
val flow = serialPort?.read()
|
||||||
flow?.collect { buffer ->
|
flow?.collect { buffer ->
|
||||||
val data = buffer.toHexString2().toUpperCase()
|
val data = buffer.toHexString2().uppercase(Locale.ROOT)
|
||||||
callback(data)
|
callback(data)
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
|||||||
@@ -0,0 +1,247 @@
|
|||||||
|
package com.shuwei.intelligent.shelves.serial
|
||||||
|
|
||||||
|
import com.shuwei.intelligent.shelves.App
|
||||||
|
import com.shuwei.intelligent.shelves.serial.ProtocolConstants.ACTIVATE_BODY_LENGTH
|
||||||
|
import com.shuwei.intelligent.shelves.serial.ProtocolConstants.ACTIVE_MAP
|
||||||
|
import com.shuwei.intelligent.shelves.serial.ProtocolConstants.BYTES_PER_WEIGHT
|
||||||
|
import com.shuwei.intelligent.shelves.serial.ProtocolConstants.CMD_ACTIVATE
|
||||||
|
import com.shuwei.intelligent.shelves.serial.ProtocolConstants.CMD_CARD_UPLOAD
|
||||||
|
import com.shuwei.intelligent.shelves.serial.ProtocolConstants.CMD_DEVICE_STATUS
|
||||||
|
import com.shuwei.intelligent.shelves.serial.ProtocolConstants.CMD_HEARTBEAT
|
||||||
|
import com.shuwei.intelligent.shelves.serial.ProtocolConstants.CMD_HEARTBEAT_TERMINAL
|
||||||
|
import com.shuwei.intelligent.shelves.serial.ProtocolConstants.CMD_LOCK_FEEDBACK
|
||||||
|
import com.shuwei.intelligent.shelves.serial.ProtocolConstants.CMD_OPERATION_RECORD
|
||||||
|
import com.shuwei.intelligent.shelves.serial.ProtocolConstants.CMD_POSITION_REPORT
|
||||||
|
import com.shuwei.intelligent.shelves.serial.ProtocolConstants.CMD_TEMP_REPORT
|
||||||
|
import com.shuwei.intelligent.shelves.serial.ProtocolConstants.CMD_TEMP_RESPONSE
|
||||||
|
import com.shuwei.intelligent.shelves.serial.ProtocolConstants.CMD_TEMP_RESPONSE_ALT
|
||||||
|
import com.shuwei.intelligent.shelves.serial.ProtocolConstants.CMD_TIME_SYNC
|
||||||
|
import com.shuwei.intelligent.shelves.serial.ProtocolConstants.DEVICE_STATUS_WEIGHT_OFFSET
|
||||||
|
import com.shuwei.intelligent.shelves.serial.ProtocolConstants.FIX_BODY_LENGTH
|
||||||
|
import com.shuwei.intelligent.shelves.serial.ProtocolConstants.FOOTER
|
||||||
|
import com.shuwei.intelligent.shelves.serial.ProtocolConstants.HEADER
|
||||||
|
import com.shuwei.intelligent.shelves.serial.ProtocolConstants.HEARTBEAT_WEIGHT_OFFSET
|
||||||
|
import com.shuwei.intelligent.shelves.serial.ProtocolConstants.TEMPERATURE_FIELD_LEN
|
||||||
|
import com.shuwei.intelligent.shelves.utils.binaryToHex
|
||||||
|
import com.shuwei.intelligent.shelves.utils.hexToBinary
|
||||||
|
import java.util.TimeZone
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 串口协议解析处理器
|
||||||
|
*
|
||||||
|
* 负责将原始协议帧字符串解析为业务事件,通过 [Callback] 接口通知调用方。
|
||||||
|
* 设计为无状态(除 terminalId/terminalVersion 外),便于单元测试。
|
||||||
|
*
|
||||||
|
* @param callback 业务回调,由 Activity/ViewModel 实现
|
||||||
|
*/
|
||||||
|
class SerialProtocolHandler(private val callback: Callback) {
|
||||||
|
|
||||||
|
/** 终端 ID(15字节/30字符),由激活指令或心跳兜底填充 */
|
||||||
|
var terminalId: String = ""
|
||||||
|
private set
|
||||||
|
|
||||||
|
/** 固件版本(5字节/10字符),由激活指令或心跳兜底填充 */
|
||||||
|
var terminalVersion: String = ""
|
||||||
|
private set
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 协议解析结果回调接口
|
||||||
|
*/
|
||||||
|
interface Callback {
|
||||||
|
/** 需要向串口发送一条指令 */
|
||||||
|
fun onSendCmd(cmd: String)
|
||||||
|
|
||||||
|
/** 解析到一组重量数据:货架编号 → 重量(克) */
|
||||||
|
fun onWeightUpdated(shelfNo: Int, weight: Int)
|
||||||
|
|
||||||
|
/** 温控信息上报,附带完整帧日志用于显示/复制 */
|
||||||
|
fun onTempReport(logMsg: String)
|
||||||
|
|
||||||
|
/** 记录日志 */
|
||||||
|
fun onLog(message: String)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 处理一帧完整的协议数据
|
||||||
|
*
|
||||||
|
* @param data 经 SerialFrameParser 解析后的完整帧字符串
|
||||||
|
*/
|
||||||
|
fun handle(data: String) {
|
||||||
|
if (data.isEmpty()) return
|
||||||
|
|
||||||
|
val cmd = data.substring(HEADER.length, HEADER.length + 4)
|
||||||
|
val cmdFlag = cmd.substring(0, 2)
|
||||||
|
|
||||||
|
when (cmd) {
|
||||||
|
CMD_ACTIVATE -> handleActivate(data, cmd, cmdFlag)
|
||||||
|
CMD_HEARTBEAT, CMD_HEARTBEAT_TERMINAL -> handleHeartbeat(data, cmd, cmdFlag)
|
||||||
|
CMD_LOCK_FEEDBACK -> handleLockFeedback(data, cmd, cmdFlag)
|
||||||
|
CMD_DEVICE_STATUS -> handleDeviceStatus(data, cmdFlag)
|
||||||
|
CMD_CARD_UPLOAD -> handleCardUpload(data, cmd, cmdFlag)
|
||||||
|
CMD_OPERATION_RECORD -> handleOperationRecord(data, cmd, cmdFlag)
|
||||||
|
CMD_TIME_SYNC -> handleTimeSync(data, cmd, cmdFlag)
|
||||||
|
CMD_POSITION_REPORT -> handlePositionReport(data, cmd, cmdFlag)
|
||||||
|
CMD_TEMP_REPORT -> handleTempReport(data, cmd, cmdFlag)
|
||||||
|
CMD_TEMP_RESPONSE -> callback.onLog("收到[温控信息应答]${CMD_TEMP_RESPONSE}数据:$data")
|
||||||
|
CMD_TEMP_RESPONSE_ALT -> callback.onLog("收到[温控信息应答]${CMD_TEMP_RESPONSE_ALT}数据:$data")
|
||||||
|
else -> {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 处理终端激活指令 */
|
||||||
|
private fun handleActivate(data: String, cmd: String, cmdFlag: String) {
|
||||||
|
val reqBody = data.substring(HEADER.length + cmd.length, data.length - FOOTER.length)
|
||||||
|
if (reqBody.length == ACTIVATE_BODY_LENGTH) {
|
||||||
|
terminalId = reqBody.substring(2, 32)
|
||||||
|
terminalVersion = reqBody.substring(32, 42)
|
||||||
|
val activeCode = ACTIVE_MAP[App.deviceId]?:""
|
||||||
|
callback.onLog("收到[激活]${cmdFlag}指令:${data},终端id:${terminalId},固件版本:${terminalVersion},发送激活命令:$activeCode")
|
||||||
|
callback.onSendCmd(activeCode)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 处理心跳指令(0101 / 8101) */
|
||||||
|
private fun handleHeartbeat(data: String, cmd: String, cmdFlag: String) {
|
||||||
|
val respCmd = "${HEADER}01020506${terminalVersion}$FOOTER"
|
||||||
|
callback.onLog("收到[心跳]${cmdFlag}指令:${data},发送应答指令:${respCmd}")
|
||||||
|
callback.onSendCmd(respCmd)
|
||||||
|
parseHeartbeatData(data)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 处理开关锁反馈 */
|
||||||
|
private fun handleLockFeedback(data: String, cmd: String, cmdFlag: String) {
|
||||||
|
val respCmd = "${HEADER}020200${terminalId}${terminalVersion}$FOOTER"
|
||||||
|
callback.onLog("收到[开锁]${cmdFlag}指令:${data},发送应答指令:${respCmd}")
|
||||||
|
callback.onSendCmd(respCmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 处理获取设备状态(0302) */
|
||||||
|
private fun handleDeviceStatus(data: String, cmdFlag: String) {
|
||||||
|
callback.onLog("收到[获取设备状态]${cmdFlag}指令:${data}")
|
||||||
|
val weightStartIndex = DEVICE_STATUS_WEIGHT_OFFSET
|
||||||
|
val weightEndIndex = weightStartIndex + ProtocolConstants.shelfSensorCount() * BYTES_PER_WEIGHT
|
||||||
|
val temperatureEndIndex = weightEndIndex + TEMPERATURE_FIELD_LEN
|
||||||
|
try {
|
||||||
|
parseWeightData(start = weightStartIndex, end = weightEndIndex, data = data)
|
||||||
|
parseFixDataBody(data, temperatureEndIndex)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 处理卡号上发 */
|
||||||
|
private fun handleCardUpload(data: String, cmd: String, cmdFlag: String) {
|
||||||
|
val respCmd = "${HEADER}050203$FOOTER"
|
||||||
|
callback.onLog("收到[卡号上发]${cmdFlag}指令:${data},发送应答指令:${respCmd}")
|
||||||
|
callback.onSendCmd(respCmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 处理操作记录上传 */
|
||||||
|
private fun handleOperationRecord(data: String, cmd: String, cmdFlag: String) {
|
||||||
|
val respCmd = "${HEADER}0B0203$FOOTER"
|
||||||
|
callback.onLog("收到[操作记录上传]${cmdFlag}指令:${data},发送应答指令:${respCmd}")
|
||||||
|
callback.onSendCmd(respCmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 处理对时请求 */
|
||||||
|
private fun handleTimeSync(data: String, cmd: String, cmdFlag: String) {
|
||||||
|
val nowMs = System.currentTimeMillis()
|
||||||
|
val timeLong = nowMs / 1000 + TimeZone.getDefault().getOffset(nowMs) / 1000
|
||||||
|
val timeStr = "0000000" + String.format("%X", timeLong)
|
||||||
|
val time = timeStr.substring(timeStr.length - 8).chunked(2).reversed().joinToString("")
|
||||||
|
val respCmd = "${HEADER}0B02${time}$FOOTER"
|
||||||
|
callback.onLog("收到[对时]${cmdFlag}指令:${data},发送应答指令:${respCmd}")
|
||||||
|
callback.onSendCmd(respCmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 处理终端位置上报 */
|
||||||
|
private fun handlePositionReport(data: String, cmd: String, cmdFlag: String) {
|
||||||
|
val respCmd = "${HEADER}0E0200$FOOTER"
|
||||||
|
callback.onLog("收到[终端位置上报]${cmdFlag}指令:${data},发送应答指令:${respCmd}")
|
||||||
|
callback.onSendCmd(respCmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 处理温控信息上报 */
|
||||||
|
private fun handleTempReport(data: String, cmd: String, cmdFlag: String) {
|
||||||
|
val respCmd = "${HEADER}100200$FOOTER"
|
||||||
|
val logMsg = "收到[温控信息上报]${cmdFlag}指令:${data},发送应答指令:${respCmd}"
|
||||||
|
callback.onLog(logMsg)
|
||||||
|
callback.onSendCmd(respCmd)
|
||||||
|
callback.onTempReport(logMsg)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解析心跳帧中的重量与固定数据体
|
||||||
|
*/
|
||||||
|
private fun parseHeartbeatData(data: String) {
|
||||||
|
runCatching {
|
||||||
|
if (data.length < ProtocolConstants.heartbeatMinLength()) return
|
||||||
|
val weightStartIndex = HEARTBEAT_WEIGHT_OFFSET
|
||||||
|
val weightEndIndex = weightStartIndex + ProtocolConstants.shelfSensorCount() * BYTES_PER_WEIGHT
|
||||||
|
parseWeightData(start = weightStartIndex, end = weightEndIndex, data = data)
|
||||||
|
val temperatureEndIndex = ProtocolConstants.heartbeatTemperatureStart() + TEMPERATURE_FIELD_LEN
|
||||||
|
parseFixDataBody(data, temperatureEndIndex)
|
||||||
|
}.onFailure { it.printStackTrace() }
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解析连续的重量数据段,每 [BYTES_PER_WEIGHT] 字符一组,依次对应货架 1..N
|
||||||
|
*
|
||||||
|
* @param start 数据段起始索引
|
||||||
|
* @param end 数据段结束索引(不含)
|
||||||
|
* @param data 完整帧字符串
|
||||||
|
*/
|
||||||
|
fun parseWeightData(start: Int, end: Int, data: String) {
|
||||||
|
var index = 1
|
||||||
|
var count = start
|
||||||
|
while (count < end) {
|
||||||
|
val weightInfo = data.substring(count, count + BYTES_PER_WEIGHT)
|
||||||
|
// 小端字节序转换:将4字节按字节倒序拼接
|
||||||
|
var weightHex = weightInfo.run {
|
||||||
|
substring(6, 8) + substring(4, 6) + substring(2, 4) + substring(0, 2)
|
||||||
|
}
|
||||||
|
var firstByteBinary = hexToBinary(weightHex.substring(0, 2))
|
||||||
|
val realWeight = if (firstByteBinary.startsWith("0")) {
|
||||||
|
// 正数:使用 toLongOrNull(16) 转换,避免超出 Int 范围
|
||||||
|
weightHex.toLongOrNull(16)?.toInt() ?: 0
|
||||||
|
} else {
|
||||||
|
// 负数:清除符号位后计算绝对值,再取反
|
||||||
|
firstByteBinary = "0${firstByteBinary.substring(1)}"
|
||||||
|
val firstByteHex = binaryToHex(firstByteBinary)
|
||||||
|
weightHex = firstByteHex + weightHex.substring(2)
|
||||||
|
//-1 * (weightHex.toLongOrNull(16)?.toInt() ?: 0)
|
||||||
|
// 直接用 Long 解析,然后减去 2^32 得到有符号值
|
||||||
|
val unsigned = weightHex.toLongOrNull(16) ?: 0L
|
||||||
|
val signed = if (unsigned >= 0x80000000L) unsigned - 0x100000000L else unsigned
|
||||||
|
signed.toInt()
|
||||||
|
}
|
||||||
|
callback.onWeightUpdated(index, realWeight)
|
||||||
|
count += BYTES_PER_WEIGHT
|
||||||
|
index++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从心跳帧或设备状态帧中补充解析 terminalId / terminalVersion。
|
||||||
|
* 激活指令(CMD_ACTIVATE)是获取这两个字段的首选来源;
|
||||||
|
* 若激活指令尚未到来,则通过此方法从心跳/设备状态帧中兜底解析。
|
||||||
|
*
|
||||||
|
* @param data 完整协议帧字符串
|
||||||
|
* @param temperatureEndIndex 温度字段结束位置(固定数据体紧随其后)
|
||||||
|
*/
|
||||||
|
private fun parseFixDataBody(data: String, temperatureEndIndex: Int) {
|
||||||
|
try {
|
||||||
|
// 已通过激活指令成功解析过,无需重复解析
|
||||||
|
if (terminalId.isNotBlank() && terminalVersion.isNotBlank()) return
|
||||||
|
val fixDataBodyStartIndex = temperatureEndIndex + 1
|
||||||
|
val fixDataBody = data.substring(fixDataBodyStartIndex, data.length - FOOTER.length)
|
||||||
|
if (fixDataBody.length == FIX_BODY_LENGTH) {
|
||||||
|
terminalId = fixDataBody.substring(0, 30)
|
||||||
|
terminalVersion = fixDataBody.substring(30, 40)
|
||||||
|
callback.onLog("从设备状态获取数据,终端id:${terminalId},固件版本:${terminalVersion}")
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
e.printStackTrace()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
package com.shuwei.intelligent.shelves.utils
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import androidx.recyclerview.widget.GridLayoutManager
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import com.shuwei.intelligent.shelves.App
|
||||||
|
import com.shuwei.intelligent.shelves.model.ShelfModel
|
||||||
|
import com.shuwei.intelligent.shelves.serial.ProtocolConstants
|
||||||
|
|
||||||
|
object GridLayoutTool {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设备2列,10格
|
||||||
|
*/
|
||||||
|
private val device2Columns = ProtocolConstants.device2Columns
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设备3列,15格,左侧1列竖向编号1、2、3、4、5,右侧2列5行编号为6-7、8-9、10-11、12-13、14-15
|
||||||
|
*/
|
||||||
|
private val device3Columns = ProtocolConstants.device3Columns
|
||||||
|
|
||||||
|
fun getLayoutManager(context: Context): RecyclerView.LayoutManager? {
|
||||||
|
return if (device2Columns.contains(App.deviceId)) {
|
||||||
|
GridLayoutManager(context, 2, GridLayoutManager.VERTICAL, false)
|
||||||
|
} else if (device3Columns.contains(App.deviceId)) {
|
||||||
|
GridLayoutManager(context, 3, GridLayoutManager.VERTICAL, false)
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化list显示顺序
|
||||||
|
*/
|
||||||
|
fun initListSort(source: List<ShelfModel>): List<ShelfModel> {
|
||||||
|
val map = source.associateBy { it.deviceNo }
|
||||||
|
return if (device3Columns.contains(App.deviceId)) {
|
||||||
|
// 按全局定义的显示顺序取对应数据,找不到则跳过
|
||||||
|
ProtocolConstants.device3ColumnsOrder.mapNotNull { map[it] }
|
||||||
|
} else if (device2Columns.contains(App.deviceId)) {
|
||||||
|
ProtocolConstants.device2ColumnsOrder.mapNotNull { map[it] }
|
||||||
|
} else {
|
||||||
|
source
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 提交接口list顺序
|
||||||
|
*/
|
||||||
|
fun submitListSort(source: List<ShelfModel>): List<ShelfModel> {
|
||||||
|
return source.sortedBy { it.deviceNo }
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package com.shuwei.intelligent.shelves.utils
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.net.ConnectivityManager
|
||||||
|
import android.net.NetworkCapabilities
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 网络连接检测工具类
|
||||||
|
* 提供检测设备网络连接状态的功能
|
||||||
|
*/
|
||||||
|
object NetworkUtils {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检测设备是否连接到网络
|
||||||
|
* @param context 应用上下文
|
||||||
|
* @return true 表示已连接网络,false 表示未连接
|
||||||
|
*/
|
||||||
|
fun isNetworkConnected(context: Context): Boolean {
|
||||||
|
val connectivityManager = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
|
||||||
|
val network = connectivityManager.activeNetwork ?: return false
|
||||||
|
val capabilities = connectivityManager.getNetworkCapabilities(network) ?: return false
|
||||||
|
return capabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.shuwei.intelligent.shelves.utils
|
package com.shuwei.intelligent.shelves.utils
|
||||||
|
|
||||||
import com.shuwei.intelligent.shelves.App
|
import com.shuwei.intelligent.shelves.App
|
||||||
|
import com.shuwei.intelligent.shelves.GlobalKey
|
||||||
import com.shuwei.intelligent.shelves.utils.ext.put
|
import com.shuwei.intelligent.shelves.utils.ext.put
|
||||||
import kotlin.to
|
import kotlin.to
|
||||||
|
|
||||||
@@ -28,4 +29,10 @@ object SpTool {
|
|||||||
fun getBoolean(key: String, defValue: Boolean = false): Boolean {
|
fun getBoolean(key: String, defValue: Boolean = false): Boolean {
|
||||||
return pref.getBoolean(key, defValue)
|
return pref.getBoolean(key, defValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var baseUrl: String
|
||||||
|
get() = getString(GlobalKey.KEY_BASE_URL, "")
|
||||||
|
set(value) {
|
||||||
|
put(GlobalKey.KEY_BASE_URL, value)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -25,6 +25,7 @@ import kotlinx.coroutines.delay
|
|||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import android.content.ClipData
|
import android.content.ClipData
|
||||||
import android.content.ClipboardManager
|
import android.content.ClipboardManager
|
||||||
|
import android.os.SystemClock
|
||||||
|
|
||||||
fun Context.toast(
|
fun Context.toast(
|
||||||
message: String?,
|
message: String?,
|
||||||
@@ -175,3 +176,22 @@ fun String.copyTextToClipboard(context: Context) {
|
|||||||
Toast.makeText(context, "文本已复制到剪贴板", Toast.LENGTH_SHORT).show()
|
Toast.makeText(context, "文本已复制到剪贴板", Toast.LENGTH_SHORT).show()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 为View添加双击点击事件的扩展函数
|
||||||
|
*/
|
||||||
|
fun View.setOnDoubleClickListener(onDoubleClickListener: (View) -> Unit) {
|
||||||
|
var lastClickTime = 0L
|
||||||
|
var lastClickView: View? = null
|
||||||
|
|
||||||
|
this.setOnClickListener { view ->
|
||||||
|
val currentTime = SystemClock.elapsedRealtime()
|
||||||
|
if (lastClickView === view && currentTime - lastClickTime < 500) {
|
||||||
|
// 双击事件触发
|
||||||
|
onDoubleClickListener(view)
|
||||||
|
lastClickTime = 0
|
||||||
|
} else {
|
||||||
|
lastClickTime = currentTime
|
||||||
|
lastClickView = view
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:color="#30000000">
|
||||||
|
<item>
|
||||||
|
<shape android:shape="rectangle">
|
||||||
|
|
||||||
|
<solid android:color="@color/white" />
|
||||||
|
<corners android:radius="8dp" />
|
||||||
|
<stroke
|
||||||
|
android:width="1dp"
|
||||||
|
android:color="@color/bg_card_blue" />
|
||||||
|
</shape>
|
||||||
|
</item>
|
||||||
|
</ripple>
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:color="#30000000">
|
||||||
|
<item>
|
||||||
|
<shape android:shape="rectangle">
|
||||||
|
|
||||||
|
<solid android:color="@color/bg_card_blue" />
|
||||||
|
<corners android:radius="8dp" />
|
||||||
|
</shape>
|
||||||
|
</item>
|
||||||
|
</ripple>
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:shape="rectangle">
|
||||||
|
<solid android:color="@color/white"/>
|
||||||
|
<corners android:radius="12dp"/>
|
||||||
|
</shape>
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:shape="rectangle">
|
||||||
|
<solid android:color="#4ECDC4" />
|
||||||
|
<corners android:radius="12dp" />
|
||||||
|
<stroke
|
||||||
|
android:width="2dp"
|
||||||
|
android:color="#2BA39F" />
|
||||||
|
</shape>
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="80dp"
|
||||||
|
android:height="80dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24">
|
||||||
|
<!-- 网络断开的图标 -->
|
||||||
|
<path
|
||||||
|
android:fillColor="#FF6B6B"
|
||||||
|
android:pathData="M1,9l2,2c4.97,-4.97 13.03,-4.97 18,0l2,-2C16.93,2.93 7.08,2.93 1,9zM5,13l2,2c2.76,-2.76 7.24,-2.76 10,0l2,-2c-4.42,-4.42 -11.58,-4.42 -16,0zM9,17h6v2h-6z" />
|
||||||
|
</vector>
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="240dp"
|
||||||
|
android:height="240dp"
|
||||||
|
android:viewportWidth="1024"
|
||||||
|
android:viewportHeight="1024">
|
||||||
|
|
||||||
|
<!-- 由小到大排列的圆点,构成旋转加载指示器 -->
|
||||||
|
<path
|
||||||
|
android:fillColor="#ffffff"
|
||||||
|
android:pathData="M876.864,782.592c3.264,0 6.272,-3.2 6.272,-6.656c0,-3.456 -3.008,-6.592 -6.272,-6.592c-3.264,0 -6.272,3.2 -6.272,6.592c0,3.456 3.008,6.656 6.272,6.656z" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#ffffff"
|
||||||
|
android:pathData="M736.32,935.936c2.304,2.432 5.568,3.84 8.768,3.84a12.16,12.16 0,0 0,8.832 -3.84a13.76,13.76 0,0 0,0 -18.56a12.224,12.224 0,0 0,-8.832 -3.84a12.16,12.16 0,0 0,-8.768 3.84a13.696,13.696 0,0 0,0 18.56z" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#ffffff"
|
||||||
|
android:pathData="M552.32,1018.24c3.456,3.648 8.32,5.76 13.184,5.76a18.368,18.368 0,0 0,13.184 -5.76a20.608,20.608 0,0 0,0 -27.968a18.368,18.368 0,0 0,-13.184 -5.824a18.368,18.368 0,0 0,-13.184 5.76a20.608,20.608 0,0 0,0 28.032z" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#ffffff"
|
||||||
|
android:pathData="M353.984,1012.48c4.608,4.8 11.072,7.68 17.6,7.68a24.448,24.448 0,0 0,17.536 -7.68a27.456,27.456 0,0 0,0 -37.248a24.448,24.448 0,0 0,-17.536 -7.68a24.448,24.448 0,0 0,-17.6 7.68a27.52,27.52 0,0 0,0 37.184z" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#ffffff"
|
||||||
|
android:pathData="M178.304,920.64c5.76,6.08 13.824,9.6 21.952,9.6a30.592,30.592 0,0 0,22.016 -9.6a34.368,34.368 0,0 0,0 -46.592a30.592,30.592 0,0 0,-22.016 -9.6a30.592,30.592 0,0 0,-21.952 9.6a34.368,34.368 0,0 0,0 46.592z" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#ffffff"
|
||||||
|
android:pathData="M57.152,761.28c6.912,7.36 16.64,11.648 26.368,11.648a36.736,36.736 0,0 0,26.432 -11.584a41.28,41.28 0,0 0,0 -55.936a36.736,36.736 0,0 0,-26.432 -11.584a36.8,36.8 0,0 0,-26.368 11.52a41.28,41.28 0,0 0,0 56z" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#ffffff"
|
||||||
|
android:pathData="M12.736,564.672a42.88,42.88 0,0 0,30.784 13.44a42.88,42.88 0,0 0,30.784 -13.44a48.128,48.128 0,0 0,0 -65.216a42.88,42.88 0,0 0,-30.72 -13.44a42.88,42.88 0,0 0,-30.848 13.44a48.128,48.128 0,0 0,0 65.216z" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#ffffff"
|
||||||
|
android:pathData="M52.544,369.28a48.96,48.96 0,0 0,35.2 15.36a48.96,48.96 0,0 0,35.2 -15.36a54.976,54.976 0,0 0,0 -74.56a48.96,48.96 0,0 0,-35.2 -15.424a48.96,48.96 0,0 0,-35.2 15.424a54.976,54.976 0,0 0,0 74.56z" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#ffffff"
|
||||||
|
android:pathData="M168.32,212.48c10.368,11.008 24.96,17.408 39.68,17.408c14.592,0 29.184,-6.4 39.552,-17.408a61.888,61.888 0,0 0,0 -83.84a55.104,55.104 0,0 0,-39.616 -17.408c-14.656,0 -29.248,6.4 -39.616,17.408a61.888,61.888 0,0 0,0 83.84z" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#ffffff"
|
||||||
|
android:pathData="M337.344,124.8c11.52,12.16 27.712,19.264 43.968,19.264c16.256,0 32.448,-7.04 43.968,-19.264a68.672,68.672 0,0 0,0 -93.184a61.248,61.248 0,0 0,-43.968 -19.264a61.248,61.248 0,0 0,-43.968 19.264a68.736,68.736 0,0 0,0 93.184z" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#ffffff"
|
||||||
|
android:pathData="M526.976,123.712c12.672,13.44 30.528,21.248 48.448,21.248s35.712,-7.808 48.384,-21.248a75.584,75.584 0,0 0,0 -102.464A67.392,67.392 0,0 0,575.36 0c-17.92,0 -35.776,7.808 -48.448,21.248a75.584,75.584 0,0 0,0 102.464z" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#ffffff"
|
||||||
|
android:pathData="M700.8,210.304c13.824,14.592 33.28,23.104 52.736,23.104c19.584,0 39.04,-8.512 52.8,-23.104a82.432,82.432 0,0 0,0 -111.744a73.472,73.472 0,0 0,-52.8 -23.168c-19.52,0 -38.912,8.512 -52.736,23.168a82.432,82.432 0,0 0,0 111.744z" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#ffffff"
|
||||||
|
android:pathData="M824.832,368.832c14.976,15.872 36.032,25.088 57.216,25.088c21.12,0 42.24,-9.216 57.152,-25.088a89.344,89.344 0,0 0,0 -121.088a79.616,79.616 0,0 0,-57.152 -25.088c-21.184,0 -42.24,9.216 -57.216,25.088a89.344,89.344 0,0 0,0 121.088z" />
|
||||||
|
<path
|
||||||
|
android:fillColor="#ffffff"
|
||||||
|
android:pathData="M875.264,572.864c16.128,17.088 38.784,27.008 61.632,27.008c22.784,0 45.44,-9.92 61.568,-27.008a96.256,96.256 0,0 0,0 -130.432a85.76,85.76 0,0 0,-61.568 -27.072c-22.848,0 -45.44,9.984 -61.632,27.072a96.192,96.192 0,0 0,0 130.432z" />
|
||||||
|
|
||||||
|
</vector>
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:shape="ring"
|
||||||
|
android:innerRadiusRatio="3"
|
||||||
|
android:thicknessRatio="8"
|
||||||
|
android:useLevel="false">
|
||||||
|
<gradient
|
||||||
|
android:type="sweep"
|
||||||
|
android:startColor="#FF6B6B"
|
||||||
|
android:centerColor="#4ECDC4"
|
||||||
|
android:endColor="#FF6B6B"
|
||||||
|
android:angle="0" />
|
||||||
|
</shape>
|
||||||
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:orientation="vertical"
|
|
||||||
tools:background="@color/bg_page">
|
|
||||||
|
|
||||||
<FrameLayout
|
|
||||||
android:id="@+id/flStatusBar"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="68dp"
|
|
||||||
android:paddingStart="25dp"
|
|
||||||
android:paddingEnd="25dp"
|
|
||||||
android:paddingTop="25dp">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/tv_left_status"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:textColor="@color/white"
|
|
||||||
android:layout_gravity="start"
|
|
||||||
android:textSize="24sp"
|
|
||||||
android:fontFamily="sans-serif-medium"
|
|
||||||
tools:text="1-1冷藏柜 -2°C / 87%" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/tv_right_status"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:textColor="@color/white"
|
|
||||||
android:layout_gravity="end"
|
|
||||||
android:fontFamily="sans-serif-medium"
|
|
||||||
android:textSize="24sp"
|
|
||||||
tools:text="6月22日 星期日 15:26:33" />
|
|
||||||
</FrameLayout>
|
|
||||||
|
|
||||||
|
|
||||||
<FrameLayout
|
|
||||||
android:id="@+id/flContainer"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
|
||||||
tools:background="@color/bg_page">
|
|
||||||
|
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
|
||||||
android:id="@+id/rvShelf"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
|
|
||||||
app:spanCount="2"
|
|
||||||
android:overScrollMode="never"
|
|
||||||
android:layout_marginStart="12dp"
|
|
||||||
android:layout_marginEnd="12dp"
|
|
||||||
tools:listitem="@layout/list_item_shelf"/>
|
|
||||||
|
|
||||||
|
|
||||||
<include
|
|
||||||
android:id="@+id/include"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
layout="@layout/layout_empty_view"
|
|
||||||
android:visibility="gone"/>
|
|
||||||
</FrameLayout>
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:orientation="vertical">
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:layout_width="450dp"
|
|
||||||
android:layout_height="430dp"
|
|
||||||
android:layout_gravity="center_horizontal"
|
|
||||||
android:layout_marginTop="150dp"
|
|
||||||
android:src="@drawable/img_init"
|
|
||||||
tools:ignore="ContentDescription"
|
|
||||||
android:visibility="invisible"/>
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/btnInit"
|
|
||||||
android:layout_width="300dp"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="center_horizontal"
|
|
||||||
android:layout_marginTop="100dp"
|
|
||||||
android:background="@drawable/bg_init_button"
|
|
||||||
android:gravity="center"
|
|
||||||
android:padding="10dp"
|
|
||||||
android:text="设备初始化"
|
|
||||||
android:textColor="@color/white"
|
|
||||||
android:textSize="30sp"
|
|
||||||
android:textStyle="bold"
|
|
||||||
android:visibility="visible"
|
|
||||||
tools:ignore="HardcodedText" />
|
|
||||||
|
|
||||||
<Space
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="0dp"
|
|
||||||
android:layout_weight="1" />
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/ivQrCode"
|
|
||||||
android:layout_width="200dp"
|
|
||||||
android:layout_height="200dp"
|
|
||||||
android:layout_gravity="center_horizontal|bottom"
|
|
||||||
android:layout_marginBottom="50dp"
|
|
||||||
tools:ignore="ContentDescription"
|
|
||||||
tools:src="@mipmap/ic_logo512" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:orientation="vertical">
|
|
||||||
|
|
||||||
<FrameLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="50dp"
|
|
||||||
android:gravity="center_vertical">
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/ivBack"
|
|
||||||
android:layout_width="30dp"
|
|
||||||
android:layout_height="30dp"
|
|
||||||
android:layout_gravity="top|start"
|
|
||||||
android:layout_marginStart="12dp"
|
|
||||||
android:layout_marginTop="12dp"
|
|
||||||
android:src="@drawable/ic_back_512"
|
|
||||||
tools:ignore="ContentDescription" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/tvTitle"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="center"
|
|
||||||
tools:text="设置"
|
|
||||||
android:textColor="@color/black"
|
|
||||||
android:textSize="28sp" />
|
|
||||||
|
|
||||||
<Button
|
|
||||||
android:id="@+id/btnFind"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginEnd="15dp"
|
|
||||||
android:textSize="18sp"
|
|
||||||
android:layout_gravity="end|center_vertical"
|
|
||||||
android:text="查找1001指令"/>
|
|
||||||
</FrameLayout>
|
|
||||||
|
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
|
||||||
android:id="@+id/rvLogList"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent" />
|
|
||||||
</LinearLayout>
|
|
||||||
@@ -1,269 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:orientation="vertical"
|
|
||||||
tools:background="@color/bg_page">
|
|
||||||
|
|
||||||
<com.google.android.material.card.MaterialCardView
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="376dp"
|
|
||||||
android:layout_marginStart="24dp"
|
|
||||||
android:layout_marginTop="12dp"
|
|
||||||
android:layout_marginEnd="24dp"
|
|
||||||
app:cardBackgroundColor="@color/white"
|
|
||||||
app:cardCornerRadius="12dp"
|
|
||||||
app:cardElevation="0dp">
|
|
||||||
|
|
||||||
<FrameLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent">
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:layout_gravity="center"
|
|
||||||
android:layout_marginStart="24dp"
|
|
||||||
android:layout_marginEnd="24dp"
|
|
||||||
android:gravity="center_horizontal"
|
|
||||||
android:orientation="vertical">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/tvShelfName"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="60dp"
|
|
||||||
android:layout_marginTop="24dp"
|
|
||||||
android:fontFamily="sans-serif-medium"
|
|
||||||
android:gravity="center"
|
|
||||||
android:textColor="@color/bg_page"
|
|
||||||
android:textSize="30sp"
|
|
||||||
tools:text="货架 - 03" />
|
|
||||||
|
|
||||||
<Space
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="0dp"
|
|
||||||
android:layout_weight="1" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/tvFoodWeight"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:ellipsize="end"
|
|
||||||
android:includeFontPadding="false"
|
|
||||||
android:maxLines="1"
|
|
||||||
android:textColor="@color/food_weight_orange"
|
|
||||||
android:textSize="60sp"
|
|
||||||
android:textStyle="bold"
|
|
||||||
tools:text="1506克" />
|
|
||||||
|
|
||||||
<Space
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="0dp"
|
|
||||||
android:layout_weight="1" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/tvFoodName"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:ellipsize="end"
|
|
||||||
android:maxLines="1"
|
|
||||||
android:textColor="@color/food_name_black"
|
|
||||||
android:textSize="36sp"
|
|
||||||
android:textStyle="bold"
|
|
||||||
tools:text="金针菇" />
|
|
||||||
|
|
||||||
<Space
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="0dp"
|
|
||||||
android:layout_weight="1" />
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<com.google.android.material.button.MaterialButton
|
|
||||||
android:id="@+id/btnClearZero"
|
|
||||||
android:layout_width="120dp"
|
|
||||||
android:layout_height="60dp"
|
|
||||||
android:layout_gravity="top|end"
|
|
||||||
android:layout_marginTop="24dp"
|
|
||||||
android:layout_marginEnd="24dp"
|
|
||||||
android:backgroundTint="@color/bg_page"
|
|
||||||
android:ellipsize="end"
|
|
||||||
android:fontFamily="sans-serif-medium"
|
|
||||||
android:insetTop="0dp"
|
|
||||||
android:insetBottom="0dp"
|
|
||||||
android:maxLines="1"
|
|
||||||
android:text="清零"
|
|
||||||
android:textColor="@color/white"
|
|
||||||
android:textSize="30sp"
|
|
||||||
app:cornerRadius="12dp"
|
|
||||||
app:elevation="0dp"
|
|
||||||
tools:ignore="HardcodedText" />
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/ivBack"
|
|
||||||
android:layout_width="60dp"
|
|
||||||
android:layout_height="60dp"
|
|
||||||
android:layout_gravity="top|start"
|
|
||||||
android:layout_marginStart="24dp"
|
|
||||||
android:layout_marginTop="24dp"
|
|
||||||
android:src="@drawable/ic_back_512"
|
|
||||||
tools:ignore="ContentDescription" />
|
|
||||||
</FrameLayout>
|
|
||||||
|
|
||||||
</com.google.android.material.card.MaterialCardView>
|
|
||||||
|
|
||||||
<com.google.android.material.card.MaterialCardView
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:layout_marginStart="24dp"
|
|
||||||
android:layout_marginTop="24dp"
|
|
||||||
android:layout_marginEnd="24dp"
|
|
||||||
android:layout_marginBottom="24dp"
|
|
||||||
app:cardBackgroundColor="@color/white"
|
|
||||||
app:cardCornerRadius="12dp"
|
|
||||||
app:cardElevation="0dp">
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:orientation="vertical">
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="80dp"
|
|
||||||
android:layout_marginStart="48dp"
|
|
||||||
android:layout_marginTop="48dp"
|
|
||||||
android:layout_marginEnd="48dp"
|
|
||||||
android:background="@drawable/shape_search"
|
|
||||||
android:gravity="center_vertical"
|
|
||||||
android:orientation="horizontal">
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:layout_width="32dp"
|
|
||||||
android:layout_height="32dp"
|
|
||||||
android:layout_marginStart="24dp"
|
|
||||||
android:layout_marginEnd="24dp"
|
|
||||||
android:src="@drawable/ic_search_food" />
|
|
||||||
|
|
||||||
<EditText
|
|
||||||
android:id="@+id/etInputFood"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="60dp"
|
|
||||||
android:layout_marginEnd="24dp"
|
|
||||||
android:background="@null"
|
|
||||||
android:fontFamily="sans-serif-medium"
|
|
||||||
android:hint="输入食材名称"
|
|
||||||
android:imeOptions="actionSearch"
|
|
||||||
android:inputType="text"
|
|
||||||
android:maxLines="1"
|
|
||||||
android:paddingStart="1dp"
|
|
||||||
android:paddingEnd="1dp"
|
|
||||||
android:text=""
|
|
||||||
android:textColor="@color/food_name_black"
|
|
||||||
android:textColorHint="#B4BEC8"
|
|
||||||
android:textSize="30sp"
|
|
||||||
tools:ignore="Autofill,HardcodedText,TextFields" />
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<FrameLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="0dp"
|
|
||||||
android:layout_marginTop="24dp"
|
|
||||||
android:layout_weight="1">
|
|
||||||
|
|
||||||
<com.scwang.smart.refresh.layout.SmartRefreshLayout
|
|
||||||
android:id="@+id/refreshLayout"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent">
|
|
||||||
|
|
||||||
<com.scwang.smart.refresh.header.ClassicsHeader
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content" />
|
|
||||||
|
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
|
||||||
android:id="@+id/rvSearch"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:clipToPadding="false"
|
|
||||||
android:overScrollMode="never"
|
|
||||||
android:paddingStart="36dp"
|
|
||||||
android:paddingTop="12dp"
|
|
||||||
android:paddingEnd="36dp"
|
|
||||||
android:paddingBottom="12dp"
|
|
||||||
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
|
|
||||||
app:spanCount="2"
|
|
||||||
tools:itemCount="10"
|
|
||||||
tools:listitem="@layout/list_item_search" />
|
|
||||||
|
|
||||||
<com.scwang.smart.refresh.footer.ClassicsFooter
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content" />
|
|
||||||
|
|
||||||
</com.scwang.smart.refresh.layout.SmartRefreshLayout>
|
|
||||||
|
|
||||||
<include
|
|
||||||
android:id="@+id/include"
|
|
||||||
layout="@layout/layout_empty_view"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:visibility="gone" />
|
|
||||||
|
|
||||||
</FrameLayout>
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:gravity="center_vertical"
|
|
||||||
android:orientation="horizontal">
|
|
||||||
|
|
||||||
<com.google.android.material.button.MaterialButton
|
|
||||||
android:id="@+id/btnClearEmpty"
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="80dp"
|
|
||||||
android:layout_marginStart="48dp"
|
|
||||||
android:layout_marginTop="24dp"
|
|
||||||
android:layout_marginEnd="24dp"
|
|
||||||
android:layout_marginBottom="24dp"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:backgroundTint="@color/bg_page"
|
|
||||||
android:ellipsize="end"
|
|
||||||
android:insetTop="0dp"
|
|
||||||
android:insetBottom="0dp"
|
|
||||||
android:maxLines="1"
|
|
||||||
android:text="清空"
|
|
||||||
android:textColor="@color/white"
|
|
||||||
android:textSize="30sp"
|
|
||||||
android:textStyle="bold"
|
|
||||||
app:cornerRadius="12dp"
|
|
||||||
app:elevation="0dp"
|
|
||||||
tools:ignore="HardcodedText" />
|
|
||||||
|
|
||||||
<com.google.android.material.button.MaterialButton
|
|
||||||
android:id="@+id/btnConfirm"
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="80dp"
|
|
||||||
android:layout_marginStart="24dp"
|
|
||||||
android:layout_marginTop="24dp"
|
|
||||||
android:layout_marginEnd="48dp"
|
|
||||||
android:layout_marginBottom="24dp"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:backgroundTint="@color/bg_page"
|
|
||||||
android:ellipsize="end"
|
|
||||||
android:insetTop="0dp"
|
|
||||||
android:insetBottom="0dp"
|
|
||||||
android:maxLines="1"
|
|
||||||
android:text="确定"
|
|
||||||
android:textColor="@color/white"
|
|
||||||
android:textSize="30sp"
|
|
||||||
android:textStyle="bold"
|
|
||||||
app:cornerRadius="12dp"
|
|
||||||
app:elevation="0dp"
|
|
||||||
tools:ignore="HardcodedText" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
</com.google.android.material.card.MaterialCardView>
|
|
||||||
</LinearLayout>
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:background="@drawable/shape_dialog">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/tvMessage"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="center"
|
|
||||||
android:gravity="center"
|
|
||||||
android:paddingStart="25dp"
|
|
||||||
android:paddingTop="13dp"
|
|
||||||
android:paddingBottom="13dp"
|
|
||||||
android:paddingEnd="25dp"
|
|
||||||
android:textColor="@color/white_f6"
|
|
||||||
android:textSize="32sp"
|
|
||||||
tools:text="暂无数据" />
|
|
||||||
|
|
||||||
</FrameLayout>
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:gravity="center_vertical"
|
|
||||||
android:orientation="horizontal"
|
|
||||||
android:paddingStart="20dp"
|
|
||||||
android:paddingTop="10dp"
|
|
||||||
android:paddingEnd="20dp"
|
|
||||||
android:paddingBottom="10dp"
|
|
||||||
android:background="@drawable/shape_dialog"
|
|
||||||
tools:ignore="MissingDefaultResource">
|
|
||||||
|
|
||||||
<ProgressBar
|
|
||||||
android:layout_width="60dp"
|
|
||||||
android:layout_height="60dp"
|
|
||||||
android:indeterminateTint="@color/white_f6" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/tvMessage"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginStart="10dp"
|
|
||||||
android:text="加载中……"
|
|
||||||
android:textColor="@color/white_f6"
|
|
||||||
android:textSize="26sp"
|
|
||||||
tools:ignore="HardcodedText" />
|
|
||||||
</LinearLayout>
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:gravity="center"
|
|
||||||
android:layout_gravity="center"
|
|
||||||
android:orientation="vertical"
|
|
||||||
tools:ignore="MissingDefaultResource,UseCompoundDrawables">
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/ivEmptyIcon"
|
|
||||||
android:layout_width="250dp"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:src="@drawable/ic_empty_gray"
|
|
||||||
android:adjustViewBounds="true"
|
|
||||||
tools:ignore="ContentDescription" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/tvEmptyContent"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:textColor="@color/black999"
|
|
||||||
android:layout_marginTop="50dp"
|
|
||||||
android:textSize="50sp"
|
|
||||||
android:text="暂无数据"
|
|
||||||
tools:ignore="HardcodedText" />
|
|
||||||
</LinearLayout>
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="60dp">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/tvLogName"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="center_vertical"
|
|
||||||
android:layout_marginStart="30dp"
|
|
||||||
android:ellipsize="end"
|
|
||||||
android:maxLines="1"
|
|
||||||
android:textColor="@color/white"
|
|
||||||
android:textSize="20sp"
|
|
||||||
tools:text="2025-11-18" />
|
|
||||||
|
|
||||||
<com.google.android.material.divider.MaterialDivider
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="1dp"
|
|
||||||
android:layout_gravity="bottom"
|
|
||||||
android:layout_marginHorizontal="30dp"
|
|
||||||
app:dividerColor="@color/gray_edit" />
|
|
||||||
</FrameLayout>
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<!--<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"-->
|
|
||||||
<!-- xmlns:tools="http://schemas.android.com/tools"-->
|
|
||||||
<!-- android:layout_width="match_parent"-->
|
|
||||||
<!-- android:layout_height="80dp"-->
|
|
||||||
<!-- android:layout_margin="12dp">-->
|
|
||||||
|
|
||||||
<!-- <TextView-->
|
|
||||||
<!-- android:id="@+id/btnFoodName"-->
|
|
||||||
<!-- android:layout_width="wrap_content"-->
|
|
||||||
<!-- android:layout_height="wrap_content"-->
|
|
||||||
<!-- android:layout_gravity="center"-->
|
|
||||||
<!-- android:ellipsize="end"-->
|
|
||||||
<!-- android:gravity="center"-->
|
|
||||||
<!-- android:maxLines="1"-->
|
|
||||||
<!-- android:paddingStart="5dp"-->
|
|
||||||
<!-- android:paddingEnd="5dp"-->
|
|
||||||
<!-- android:fontFamily="sans-serif-medium"-->
|
|
||||||
<!-- android:textColor="@color/black999"-->
|
|
||||||
<!-- android:textSize="30sp"-->
|
|
||||||
<!-- tools:text="土豆丝" />-->
|
|
||||||
<!--</FrameLayout>-->
|
|
||||||
<com.google.android.material.button.MaterialButton xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
|
||||||
android:id="@+id/btnFoodName"
|
|
||||||
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="80dp"
|
|
||||||
android:layout_margin="12dp"
|
|
||||||
android:ellipsize="end"
|
|
||||||
android:fontFamily="sans-serif-medium"
|
|
||||||
android:gravity="center"
|
|
||||||
android:insetTop="0dp"
|
|
||||||
android:insetBottom="0dp"
|
|
||||||
android:maxLines="1"
|
|
||||||
app:paddingStart="5dp"
|
|
||||||
app:paddingEnd="5dp"
|
|
||||||
android:insetRight="0dp"
|
|
||||||
android:insetLeft="0dp"
|
|
||||||
android:paddingHorizontal="8dp"
|
|
||||||
android:textColor="@color/black999"
|
|
||||||
android:textSize="30sp"
|
|
||||||
app:cornerRadius="12dp"
|
|
||||||
app:strokeWidth="2dp"
|
|
||||||
tools:text="土豆丝土豆丝土豆丝土豆丝土豆丝土豆丝"
|
|
||||||
/>
|
|
||||||
|
|
||||||
@@ -1,87 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
|
||||||
android:id="@+id/layoutCard"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="216dp"
|
|
||||||
android:layout_margin="12dp"
|
|
||||||
app:cardBackgroundColor="@color/bg_card_blue"
|
|
||||||
app:cardCornerRadius="12dp"
|
|
||||||
app:cardElevation="0dp"
|
|
||||||
app:rippleColor="#B0BEC5">
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:gravity="center_horizontal"
|
|
||||||
android:orientation="vertical"
|
|
||||||
android:padding="24dp">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/tvShelfName"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:textColor="@color/shelf_name_white"
|
|
||||||
android:textSize="20sp"
|
|
||||||
android:textStyle="bold"
|
|
||||||
tools:text="货架-01" />
|
|
||||||
|
|
||||||
<Space
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="0dp"
|
|
||||||
android:layout_weight="1" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/tvFoodName"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:ellipsize="end"
|
|
||||||
android:maxLines="1"
|
|
||||||
android:textColor="@color/white"
|
|
||||||
android:textSize="30sp"
|
|
||||||
android:textStyle="bold"
|
|
||||||
tools:text="空" />
|
|
||||||
|
|
||||||
<Space
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="0dp"
|
|
||||||
android:layout_weight="0.833" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/tvFoodWeight"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:ellipsize="end"
|
|
||||||
android:maxLines="1"
|
|
||||||
android:textColor="@color/food_weight_blue"
|
|
||||||
android:textSize="24sp"
|
|
||||||
android:textStyle="bold"
|
|
||||||
tools:text="0千克" />
|
|
||||||
|
|
||||||
<Space
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="0dp"
|
|
||||||
android:layout_weight="0.933" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/tvStoreDate"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:ellipsize="end"
|
|
||||||
android:maxLines="1"
|
|
||||||
android:textColor="@color/food_weight_blue"
|
|
||||||
android:textSize="18sp"
|
|
||||||
tools:text="-" />
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/ivStaleFood"
|
|
||||||
android:layout_width="100dp"
|
|
||||||
android:layout_height="100dp"
|
|
||||||
android:src="@drawable/ic_stale_food_512"
|
|
||||||
android:layout_gravity="top|end"
|
|
||||||
tools:ignore="ContentDescription"
|
|
||||||
android:visibility="gone"/>
|
|
||||||
|
|
||||||
</com.google.android.material.card.MaterialCardView>
|
|
||||||
@@ -5,39 +5,34 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:fitsSystemWindows="false"
|
|
||||||
tools:background="@color/bg_page">
|
tools:background="@color/bg_page">
|
||||||
|
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
android:id="@+id/flStatusBar"
|
android:id="@+id/flStatusBar"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="30dp">
|
android:layout_height="68dp"
|
||||||
<!-- android:paddingTop="9dp"-->
|
android:paddingStart="25dp"
|
||||||
|
android:paddingEnd="25dp"
|
||||||
|
android:paddingTop="25dp">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/tv_left_status"
|
android:id="@+id/tv_left_status"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="wrap_content"
|
||||||
android:gravity="center_vertical"
|
|
||||||
android:textColor="@color/white"
|
android:textColor="@color/white"
|
||||||
android:layout_gravity="start"
|
android:layout_gravity="start"
|
||||||
android:textSize="12sp"
|
android:textSize="24sp"
|
||||||
android:paddingStart="12dp"
|
|
||||||
android:paddingEnd="0dp"
|
|
||||||
android:fontFamily="sans-serif-medium"
|
android:fontFamily="sans-serif-medium"
|
||||||
tools:text="1-1冷藏柜 -2°C / 87%" />
|
android:text=" " />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/tv_right_status"
|
android:id="@+id/tv_right_status"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="wrap_content"
|
||||||
android:gravity="center_vertical"
|
|
||||||
android:textColor="@color/white"
|
android:textColor="@color/white"
|
||||||
android:layout_gravity="end"
|
android:layout_gravity="end"
|
||||||
android:fontFamily="sans-serif-medium"
|
android:fontFamily="sans-serif-medium"
|
||||||
android:textSize="12sp"
|
android:textSize="24sp"
|
||||||
android:paddingStart="0dp"
|
|
||||||
android:paddingEnd="12dp"
|
|
||||||
tools:text="6月22日 星期日 15:26:33" />
|
tools:text="6月22日 星期日 15:26:33" />
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
|
|
||||||
|
|||||||
@@ -13,8 +13,8 @@
|
|||||||
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
|
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
|
||||||
app:spanCount="2"
|
app:spanCount="2"
|
||||||
android:overScrollMode="never"
|
android:overScrollMode="never"
|
||||||
android:layout_marginStart="6dp"
|
android:layout_marginStart="12dp"
|
||||||
android:layout_marginEnd="6dp"
|
android:layout_marginEnd="12dp"
|
||||||
tools:listitem="@layout/list_item_shelf"/>
|
tools:listitem="@layout/list_item_shelf"/>
|
||||||
|
|
||||||
|
|
||||||
@@ -24,12 +24,4 @@
|
|||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
layout="@layout/layout_empty_view"
|
layout="@layout/layout_empty_view"
|
||||||
android:visibility="gone"/>
|
android:visibility="gone"/>
|
||||||
|
|
||||||
<!-- <include-->
|
|
||||||
<!-- android:id="@+id/includeLight"-->
|
|
||||||
<!-- android:layout_width="match_parent"-->
|
|
||||||
<!-- android:layout_height="wrap_content"-->
|
|
||||||
<!-- layout="@layout/layout_light_switch"-->
|
|
||||||
<!-- android:visibility="gone"/>-->
|
|
||||||
|
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
@@ -1,32 +1,38 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/llDeviceInit"
|
||||||
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical"
|
||||||
|
android:visibility="gone">
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:layout_width="225dp"
|
android:layout_width="450dp"
|
||||||
android:layout_height="215dp"
|
android:layout_height="430dp"
|
||||||
android:layout_gravity="center_horizontal"
|
android:layout_gravity="center_horizontal"
|
||||||
android:layout_marginTop="75dp"
|
android:layout_marginTop="150dp"
|
||||||
android:src="@drawable/img_init"
|
android:src="@drawable/img_init"
|
||||||
tools:ignore="ContentDescription"
|
tools:ignore="ContentDescription"
|
||||||
android:visibility="invisible"/>
|
android:visibility="invisible"/>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/btnInit"
|
android:id="@+id/btnInit"
|
||||||
android:layout_width="150dp"
|
android:layout_width="300dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center_horizontal"
|
android:layout_gravity="center_horizontal"
|
||||||
android:layout_marginTop="50dp"
|
android:layout_marginTop="100dp"
|
||||||
android:background="@drawable/bg_init_button"
|
android:background="@drawable/bg_init_button"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:padding="10dp"
|
android:padding="10dp"
|
||||||
android:text="设备初始化"
|
android:text="设备初始化"
|
||||||
android:textColor="@color/white"
|
android:textColor="@color/white"
|
||||||
android:textSize="15sp"
|
android:textSize="30sp"
|
||||||
android:textStyle="bold"
|
android:textStyle="bold"
|
||||||
android:visibility="visible"
|
android:visibility="visible"
|
||||||
tools:ignore="HardcodedText" />
|
tools:ignore="HardcodedText" />
|
||||||
@@ -38,11 +44,102 @@
|
|||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/ivQrCode"
|
android:id="@+id/ivQrCode"
|
||||||
android:layout_width="100dp"
|
android:layout_width="200dp"
|
||||||
android:layout_height="100dp"
|
android:layout_height="200dp"
|
||||||
android:layout_gravity="center_horizontal|bottom"
|
android:layout_gravity="center_horizontal|bottom"
|
||||||
android:layout_marginBottom="25dp"
|
android:layout_marginBottom="50dp"
|
||||||
tools:ignore="ContentDescription"
|
tools:ignore="ContentDescription"
|
||||||
tools:src="@mipmap/ic_logo512" />
|
tools:src="@mipmap/ic_logo512" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/llNetwork"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:gravity="center">
|
||||||
|
|
||||||
|
<!-- Loading 动画容器 -->
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/llLoading"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:gravity="center"
|
||||||
|
android:visibility="visible"
|
||||||
|
android:layout_marginTop="260dp">
|
||||||
|
|
||||||
|
<!-- 加载动画 -->
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/ivLoading"
|
||||||
|
android:layout_width="120dp"
|
||||||
|
android:layout_height="120dp"
|
||||||
|
android:src="@drawable/loading"
|
||||||
|
android:contentDescription="加载中" />
|
||||||
|
|
||||||
|
<!-- 倒计时文字 -->
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvCountdown"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="60秒"
|
||||||
|
android:textSize="40sp"
|
||||||
|
android:textColor="@color/white"
|
||||||
|
android:textStyle="bold"
|
||||||
|
android:layout_marginTop="50dp" />
|
||||||
|
|
||||||
|
<!-- 提示文字 -->
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="网络连接检测中,请稍后……"
|
||||||
|
android:textSize="22sp"
|
||||||
|
android:textColor="@color/white"
|
||||||
|
android:layout_marginTop="20dp" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<!-- 连接网络按钮容器 -->
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/llNetworkButton"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:gravity="center"
|
||||||
|
android:visibility="gone">
|
||||||
|
|
||||||
|
<!-- 网络错误图标 -->
|
||||||
|
<ImageView
|
||||||
|
android:layout_width="140dp"
|
||||||
|
android:layout_height="140dp"
|
||||||
|
android:src="@drawable/ic_network_error"
|
||||||
|
android:contentDescription="网络连接失败"
|
||||||
|
android:layout_marginBottom="30dp" />
|
||||||
|
|
||||||
|
<!-- 连接失败提示 -->
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="网络连接失败"
|
||||||
|
android:textSize="36sp"
|
||||||
|
android:textColor="@color/white"
|
||||||
|
android:textStyle="bold"
|
||||||
|
android:layout_marginBottom="40dp" />
|
||||||
|
|
||||||
|
<!-- 连接网络按钮 -->
|
||||||
|
<Button
|
||||||
|
android:id="@+id/btnConnectNetwork"
|
||||||
|
android:layout_width="350dp"
|
||||||
|
android:layout_height="70dp"
|
||||||
|
android:text="连接网络"
|
||||||
|
android:textSize="24sp"
|
||||||
|
android:textStyle="bold"
|
||||||
|
android:textColor="@android:color/white"
|
||||||
|
android:background="@drawable/btn_connect_network" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</FrameLayout>
|
||||||
@@ -1,6 +1,11 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
@@ -33,14 +38,61 @@
|
|||||||
android:id="@+id/btnFind"
|
android:id="@+id/btnFind"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginEnd="10dp"
|
android:layout_marginEnd="15dp"
|
||||||
android:textSize="12sp"
|
android:textSize="18sp"
|
||||||
android:layout_gravity="end|center_vertical"
|
android:layout_gravity="end|center_vertical"
|
||||||
android:text="查找1001指令"/>
|
android:text="查找1001指令"/>
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
|
|
||||||
|
<EditText
|
||||||
|
android:id="@+id/etSearch"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="40dp"
|
||||||
|
android:layout_marginHorizontal="12dp"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
android:background="@android:color/white"
|
||||||
|
android:hint="搜索日志..."
|
||||||
|
android:paddingHorizontal="12dp"
|
||||||
|
android:textSize="14sp"
|
||||||
|
android:singleLine="true"
|
||||||
|
tools:ignore="Autofill,TextFields" />
|
||||||
|
|
||||||
|
<HorizontalScrollView
|
||||||
|
android:id="@+id/hsvTimeNav"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="40dp"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
android:scrollbars="none">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/llTimeNav"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:paddingHorizontal="12dp" />
|
||||||
|
</HorizontalScrollView>
|
||||||
|
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
android:id="@+id/rvLogList"
|
android:id="@+id/rvLogList"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent" />
|
android:layout_height="match_parent" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||||
|
android:id="@+id/fabJump"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="bottom|end"
|
||||||
|
android:layout_margin="16dp"
|
||||||
|
android:src="@android:drawable/ic_menu_sort_by_size"
|
||||||
|
app:fabSize="normal"
|
||||||
|
tools:ignore="ContentDescription" />
|
||||||
|
|
||||||
|
<ProgressBar
|
||||||
|
android:id="@+id/progressBar"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:visibility="gone" />
|
||||||
|
|
||||||
|
</FrameLayout>
|
||||||
@@ -1,111 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:orientation="vertical"
|
|
||||||
tools:background="@color/bg_page">
|
|
||||||
|
|
||||||
<com.google.android.material.card.MaterialCardView
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="260dp"
|
|
||||||
android:layout_marginStart="12dp"
|
|
||||||
android:layout_marginTop="6dp"
|
|
||||||
android:layout_marginEnd="12dp"
|
|
||||||
app:cardBackgroundColor="@color/white"
|
|
||||||
app:cardCornerRadius="6dp"
|
|
||||||
app:cardElevation="0dp">
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:orientation="vertical"
|
|
||||||
android:padding="10dp">
|
|
||||||
|
|
||||||
<FrameLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="50dp"
|
|
||||||
android:gravity="center_vertical">
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/ivBack"
|
|
||||||
android:layout_width="30dp"
|
|
||||||
android:layout_height="30dp"
|
|
||||||
android:layout_gravity="top|start"
|
|
||||||
android:layout_marginTop="12dp"
|
|
||||||
android:layout_marginStart="12dp"
|
|
||||||
android:src="@drawable/ic_back_512"
|
|
||||||
tools:ignore="ContentDescription" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:textSize="28sp"
|
|
||||||
android:layout_gravity="center"
|
|
||||||
android:text="设置"
|
|
||||||
android:textColor="@color/black"/>
|
|
||||||
|
|
||||||
</FrameLayout>
|
|
||||||
|
|
||||||
<!-- <EditText-->
|
|
||||||
<!-- android:id="@+id/etInputCmdPrefix"-->
|
|
||||||
<!-- android:layout_width="match_parent"-->
|
|
||||||
<!-- android:layout_height="60dp"-->
|
|
||||||
<!-- android:hint="请输入命令"-->
|
|
||||||
<!-- android:maxLines="1"-->
|
|
||||||
<!-- android:text=""-->
|
|
||||||
<!-- android:textSize="22sp" />-->
|
|
||||||
|
|
||||||
<EditText
|
|
||||||
android:id="@+id/etInputCmd"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="60dp"
|
|
||||||
android:hint="请输入命令内容"
|
|
||||||
android:maxLines="1"
|
|
||||||
android:textSize="22sp" />
|
|
||||||
|
|
||||||
<Button
|
|
||||||
android:id="@+id/btnSendCmd"
|
|
||||||
android:layout_width="180dp"
|
|
||||||
android:layout_height="60dp"
|
|
||||||
android:textSize="22sp"
|
|
||||||
android:layout_gravity="center"
|
|
||||||
android:layout_marginTop="30dp"
|
|
||||||
android:text="发送命令" />
|
|
||||||
</LinearLayout>
|
|
||||||
</com.google.android.material.card.MaterialCardView>
|
|
||||||
<com.google.android.material.card.MaterialCardView
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="0dp"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:layout_marginStart="12dp"
|
|
||||||
android:layout_marginTop="12dp"
|
|
||||||
android:layout_marginEnd="12dp"
|
|
||||||
android:layout_marginBottom="12dp"
|
|
||||||
app:cardBackgroundColor="@color/white"
|
|
||||||
app:cardCornerRadius="6dp"
|
|
||||||
app:cardElevation="0dp">
|
|
||||||
|
|
||||||
<ScrollView
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent">
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:orientation="vertical"
|
|
||||||
android:padding="10dp">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/tvCmdRecord"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:textSize="20sp"
|
|
||||||
android:text=""/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
</ScrollView>
|
|
||||||
</com.google.android.material.card.MaterialCardView>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
@@ -9,12 +9,12 @@
|
|||||||
|
|
||||||
<com.google.android.material.card.MaterialCardView
|
<com.google.android.material.card.MaterialCardView
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="190dp"
|
android:layout_height="376dp"
|
||||||
android:layout_marginStart="12dp"
|
android:layout_marginStart="24dp"
|
||||||
android:layout_marginTop="6dp"
|
android:layout_marginTop="12dp"
|
||||||
android:layout_marginEnd="12dp"
|
android:layout_marginEnd="24dp"
|
||||||
app:cardBackgroundColor="@color/white"
|
app:cardBackgroundColor="@color/white"
|
||||||
app:cardCornerRadius="6dp"
|
app:cardCornerRadius="12dp"
|
||||||
app:cardElevation="0dp">
|
app:cardElevation="0dp">
|
||||||
|
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
@@ -25,20 +25,20 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_gravity="center"
|
android:layout_gravity="center"
|
||||||
android:layout_marginStart="12dp"
|
android:layout_marginStart="24dp"
|
||||||
android:layout_marginEnd="12dp"
|
android:layout_marginEnd="24dp"
|
||||||
android:gravity="center_horizontal"
|
android:gravity="center_horizontal"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/tvShelfName"
|
android:id="@+id/tvShelfName"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="30dp"
|
android:layout_height="60dp"
|
||||||
android:layout_marginTop="12dp"
|
android:layout_marginTop="24dp"
|
||||||
android:fontFamily="sans-serif-medium"
|
android:fontFamily="sans-serif-medium"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:textColor="@color/bg_page"
|
android:textColor="@color/bg_page"
|
||||||
android:textSize="15sp"
|
android:textSize="30sp"
|
||||||
tools:text="货架 - 03" />
|
tools:text="货架 - 03" />
|
||||||
|
|
||||||
<Space
|
<Space
|
||||||
@@ -54,7 +54,7 @@
|
|||||||
android:includeFontPadding="false"
|
android:includeFontPadding="false"
|
||||||
android:maxLines="1"
|
android:maxLines="1"
|
||||||
android:textColor="@color/food_weight_orange"
|
android:textColor="@color/food_weight_orange"
|
||||||
android:textSize="30sp"
|
android:textSize="60sp"
|
||||||
android:textStyle="bold"
|
android:textStyle="bold"
|
||||||
tools:text="1506克" />
|
tools:text="1506克" />
|
||||||
|
|
||||||
@@ -70,7 +70,7 @@
|
|||||||
android:ellipsize="end"
|
android:ellipsize="end"
|
||||||
android:maxLines="1"
|
android:maxLines="1"
|
||||||
android:textColor="@color/food_name_black"
|
android:textColor="@color/food_name_black"
|
||||||
android:textSize="18sp"
|
android:textSize="36sp"
|
||||||
android:textStyle="bold"
|
android:textStyle="bold"
|
||||||
tools:text="金针菇" />
|
tools:text="金针菇" />
|
||||||
|
|
||||||
@@ -82,11 +82,11 @@
|
|||||||
|
|
||||||
<com.google.android.material.button.MaterialButton
|
<com.google.android.material.button.MaterialButton
|
||||||
android:id="@+id/btnClearZero"
|
android:id="@+id/btnClearZero"
|
||||||
android:layout_width="65dp"
|
android:layout_width="120dp"
|
||||||
android:layout_height="30dp"
|
android:layout_height="60dp"
|
||||||
android:layout_gravity="top|end"
|
android:layout_gravity="top|end"
|
||||||
android:layout_marginTop="12dp"
|
android:layout_marginTop="24dp"
|
||||||
android:layout_marginEnd="12dp"
|
android:layout_marginEnd="24dp"
|
||||||
android:backgroundTint="@color/bg_page"
|
android:backgroundTint="@color/bg_page"
|
||||||
android:ellipsize="end"
|
android:ellipsize="end"
|
||||||
android:fontFamily="sans-serif-medium"
|
android:fontFamily="sans-serif-medium"
|
||||||
@@ -95,21 +95,20 @@
|
|||||||
android:maxLines="1"
|
android:maxLines="1"
|
||||||
android:text="清零"
|
android:text="清零"
|
||||||
android:textColor="@color/white"
|
android:textColor="@color/white"
|
||||||
android:textSize="15sp"
|
android:textSize="30sp"
|
||||||
app:cornerRadius="6dp"
|
app:cornerRadius="12dp"
|
||||||
app:elevation="0dp"
|
app:elevation="0dp"
|
||||||
tools:ignore="HardcodedText" />
|
tools:ignore="HardcodedText" />
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/ivBack"
|
android:id="@+id/ivBack"
|
||||||
android:layout_width="30dp"
|
android:layout_width="60dp"
|
||||||
android:layout_height="30dp"
|
android:layout_height="60dp"
|
||||||
android:layout_gravity="top|start"
|
android:layout_gravity="top|start"
|
||||||
android:layout_marginTop="12dp"
|
android:layout_marginStart="24dp"
|
||||||
android:layout_marginStart="12dp"
|
android:layout_marginTop="24dp"
|
||||||
android:src="@drawable/ic_back_512"
|
android:src="@drawable/ic_back_512"
|
||||||
tools:ignore="ContentDescription" />
|
tools:ignore="ContentDescription" />
|
||||||
|
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
|
|
||||||
</com.google.android.material.card.MaterialCardView>
|
</com.google.android.material.card.MaterialCardView>
|
||||||
@@ -117,12 +116,12 @@
|
|||||||
<com.google.android.material.card.MaterialCardView
|
<com.google.android.material.card.MaterialCardView
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_marginStart="12dp"
|
android:layout_marginStart="24dp"
|
||||||
android:layout_marginTop="12dp"
|
android:layout_marginTop="24dp"
|
||||||
android:layout_marginEnd="12dp"
|
android:layout_marginEnd="24dp"
|
||||||
android:layout_marginBottom="12dp"
|
android:layout_marginBottom="24dp"
|
||||||
app:cardBackgroundColor="@color/white"
|
app:cardBackgroundColor="@color/white"
|
||||||
app:cardCornerRadius="6dp"
|
app:cardCornerRadius="12dp"
|
||||||
app:cardElevation="0dp">
|
app:cardElevation="0dp">
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
@@ -132,26 +131,26 @@
|
|||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="40dp"
|
android:layout_height="80dp"
|
||||||
android:layout_marginStart="16dp"
|
android:layout_marginStart="48dp"
|
||||||
android:layout_marginTop="16dp"
|
android:layout_marginTop="48dp"
|
||||||
android:layout_marginEnd="16dp"
|
android:layout_marginEnd="48dp"
|
||||||
android:background="@drawable/shape_search"
|
android:background="@drawable/shape_search"
|
||||||
android:gravity="center_vertical"
|
android:gravity="center_vertical"
|
||||||
android:orientation="horizontal">
|
android:orientation="horizontal">
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:layout_width="16dp"
|
android:layout_width="32dp"
|
||||||
android:layout_height="16dp"
|
android:layout_height="32dp"
|
||||||
android:layout_marginStart="12dp"
|
android:layout_marginStart="24dp"
|
||||||
android:layout_marginEnd="12dp"
|
android:layout_marginEnd="24dp"
|
||||||
android:src="@drawable/ic_search_food" />
|
android:src="@drawable/ic_search_food" />
|
||||||
|
|
||||||
<EditText
|
<EditText
|
||||||
android:id="@+id/etInputFood"
|
android:id="@+id/etInputFood"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="36dp"
|
android:layout_height="60dp"
|
||||||
android:layout_marginEnd="12dp"
|
android:layout_marginEnd="24dp"
|
||||||
android:background="@null"
|
android:background="@null"
|
||||||
android:fontFamily="sans-serif-medium"
|
android:fontFamily="sans-serif-medium"
|
||||||
android:hint="输入食材名称"
|
android:hint="输入食材名称"
|
||||||
@@ -163,14 +162,14 @@
|
|||||||
android:text=""
|
android:text=""
|
||||||
android:textColor="@color/food_name_black"
|
android:textColor="@color/food_name_black"
|
||||||
android:textColorHint="#B4BEC8"
|
android:textColorHint="#B4BEC8"
|
||||||
android:textSize="15sp"
|
android:textSize="30sp"
|
||||||
tools:ignore="Autofill,HardcodedText,TextFields" />
|
tools:ignore="Autofill,HardcodedText,TextFields" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="0dp"
|
android:layout_height="0dp"
|
||||||
android:layout_marginTop="8dp"
|
android:layout_marginTop="24dp"
|
||||||
android:layout_weight="1">
|
android:layout_weight="1">
|
||||||
|
|
||||||
<com.scwang.smart.refresh.layout.SmartRefreshLayout
|
<com.scwang.smart.refresh.layout.SmartRefreshLayout
|
||||||
@@ -188,10 +187,10 @@
|
|||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:clipToPadding="false"
|
android:clipToPadding="false"
|
||||||
android:overScrollMode="never"
|
android:overScrollMode="never"
|
||||||
android:paddingStart="12dp"
|
android:paddingStart="36dp"
|
||||||
android:paddingTop="4dp"
|
android:paddingTop="12dp"
|
||||||
android:paddingEnd="12dp"
|
android:paddingEnd="36dp"
|
||||||
android:paddingBottom="4dp"
|
android:paddingBottom="12dp"
|
||||||
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
|
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
|
||||||
app:spanCount="2"
|
app:spanCount="2"
|
||||||
tools:itemCount="10"
|
tools:itemCount="10"
|
||||||
@@ -209,23 +208,24 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:visibility="gone" />
|
android:visibility="gone" />
|
||||||
|
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="horizontal"
|
android:gravity="center_vertical"
|
||||||
android:gravity="center_vertical">
|
android:orientation="horizontal">
|
||||||
|
|
||||||
<com.google.android.material.button.MaterialButton
|
<com.google.android.material.button.MaterialButton
|
||||||
android:id="@+id/btnClearEmpty"
|
android:id="@+id/btnClearEmpty"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="80dp"
|
||||||
|
android:layout_marginStart="48dp"
|
||||||
|
android:layout_marginTop="24dp"
|
||||||
|
android:layout_marginEnd="24dp"
|
||||||
|
android:layout_marginBottom="24dp"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:layout_height="40dp"
|
|
||||||
android:layout_marginStart="24dp"
|
|
||||||
android:layout_marginTop="12dp"
|
|
||||||
android:layout_marginEnd="12dp"
|
|
||||||
android:layout_marginBottom="12dp"
|
|
||||||
android:backgroundTint="@color/bg_page"
|
android:backgroundTint="@color/bg_page"
|
||||||
android:ellipsize="end"
|
android:ellipsize="end"
|
||||||
android:insetTop="0dp"
|
android:insetTop="0dp"
|
||||||
@@ -233,22 +233,21 @@
|
|||||||
android:maxLines="1"
|
android:maxLines="1"
|
||||||
android:text="清空"
|
android:text="清空"
|
||||||
android:textColor="@color/white"
|
android:textColor="@color/white"
|
||||||
android:textSize="15sp"
|
android:textSize="30sp"
|
||||||
android:textStyle="bold"
|
android:textStyle="bold"
|
||||||
app:cornerRadius="6dp"
|
app:cornerRadius="12dp"
|
||||||
app:elevation="0dp"
|
app:elevation="0dp"
|
||||||
tools:ignore="HardcodedText" />
|
tools:ignore="HardcodedText" />
|
||||||
|
|
||||||
|
|
||||||
<com.google.android.material.button.MaterialButton
|
<com.google.android.material.button.MaterialButton
|
||||||
android:id="@+id/btnConfirm"
|
android:id="@+id/btnConfirm"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="80dp"
|
||||||
|
android:layout_marginStart="24dp"
|
||||||
|
android:layout_marginTop="24dp"
|
||||||
|
android:layout_marginEnd="48dp"
|
||||||
|
android:layout_marginBottom="24dp"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:layout_height="40dp"
|
|
||||||
android:layout_marginStart="12dp"
|
|
||||||
android:layout_marginTop="12dp"
|
|
||||||
android:layout_marginEnd="24dp"
|
|
||||||
android:layout_marginBottom="12dp"
|
|
||||||
android:backgroundTint="@color/bg_page"
|
android:backgroundTint="@color/bg_page"
|
||||||
android:ellipsize="end"
|
android:ellipsize="end"
|
||||||
android:insetTop="0dp"
|
android:insetTop="0dp"
|
||||||
@@ -256,11 +255,12 @@
|
|||||||
android:maxLines="1"
|
android:maxLines="1"
|
||||||
android:text="确定"
|
android:text="确定"
|
||||||
android:textColor="@color/white"
|
android:textColor="@color/white"
|
||||||
android:textSize="15sp"
|
android:textSize="30sp"
|
||||||
android:textStyle="bold"
|
android:textStyle="bold"
|
||||||
app:cornerRadius="6dp"
|
app:cornerRadius="12dp"
|
||||||
app:elevation="0dp"
|
app:elevation="0dp"
|
||||||
tools:ignore="HardcodedText" />
|
tools:ignore="HardcodedText" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|||||||
@@ -11,12 +11,12 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center"
|
android:layout_gravity="center"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:paddingStart="12dp"
|
android:paddingStart="25dp"
|
||||||
android:paddingTop="6dp"
|
android:paddingTop="13dp"
|
||||||
android:paddingBottom="6dp"
|
android:paddingBottom="13dp"
|
||||||
android:paddingEnd="12dp"
|
android:paddingEnd="25dp"
|
||||||
android:textColor="@color/white_f6"
|
android:textColor="@color/white_f6"
|
||||||
android:textSize="16sp"
|
android:textSize="32sp"
|
||||||
tools:text="暂无数据" />
|
tools:text="暂无数据" />
|
||||||
|
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
@@ -0,0 +1,106 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="600dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="@drawable/bg_white_radius12"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:paddingHorizontal="40dp"
|
||||||
|
android:paddingVertical="36dp">
|
||||||
|
|
||||||
|
<!-- 标题 -->
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="center"
|
||||||
|
android:text="环境切换"
|
||||||
|
android:textColor="#ff141428"
|
||||||
|
android:textSize="36sp"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
|
||||||
|
<!-- 分割线 -->
|
||||||
|
<View
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="2dp"
|
||||||
|
android:layout_marginTop="24dp"
|
||||||
|
android:background="#FFDCDCF0" />
|
||||||
|
|
||||||
|
<!-- 环境选项 -->
|
||||||
|
<RadioGroup
|
||||||
|
android:id="@+id/rgEnv"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="32dp"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<RadioButton
|
||||||
|
android:id="@+id/rbTest"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="72dp"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:paddingStart="16dp"
|
||||||
|
android:text="测试环境"
|
||||||
|
android:textColor="#ff141428"
|
||||||
|
android:textSize="28sp" />
|
||||||
|
|
||||||
|
<RadioButton
|
||||||
|
android:id="@+id/rbUat"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="72dp"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:paddingStart="16dp"
|
||||||
|
android:text="UAT 环境"
|
||||||
|
android:textColor="#ff141428"
|
||||||
|
android:textSize="28sp" />
|
||||||
|
|
||||||
|
<RadioButton
|
||||||
|
android:id="@+id/rbProd"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="72dp"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:paddingStart="16dp"
|
||||||
|
android:text="生产环境"
|
||||||
|
android:textColor="#ff141428"
|
||||||
|
android:textSize="28sp" />
|
||||||
|
|
||||||
|
</RadioGroup>
|
||||||
|
|
||||||
|
<!-- 分割线 -->
|
||||||
|
<View
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="2dp"
|
||||||
|
android:layout_marginTop="24dp"
|
||||||
|
android:background="#FFDCDCF0" />
|
||||||
|
|
||||||
|
<!-- 底部按钮 -->
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="88dp"
|
||||||
|
android:layout_marginTop="24dp"
|
||||||
|
android:gravity="center"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<androidx.appcompat.widget.AppCompatButton
|
||||||
|
android:id="@+id/btnCancel"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_marginEnd="20dp"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:background="@drawable/bg_cancel"
|
||||||
|
android:text="取消"
|
||||||
|
android:textColor="@color/bg_card_blue"
|
||||||
|
android:textSize="28sp" />
|
||||||
|
|
||||||
|
<androidx.appcompat.widget.AppCompatButton
|
||||||
|
android:id="@+id/btnConfirm"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_marginStart="20dp"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:background="@drawable/bg_confirm"
|
||||||
|
android:text="确认"
|
||||||
|
android:textColor="#FFFFFF"
|
||||||
|
android:textSize="28sp" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
@@ -5,25 +5,25 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:gravity="center_vertical"
|
android:gravity="center_vertical"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
android:paddingStart="10dp"
|
android:paddingStart="20dp"
|
||||||
android:paddingTop="5dp"
|
android:paddingTop="10dp"
|
||||||
android:paddingEnd="10dp"
|
android:paddingEnd="20dp"
|
||||||
android:paddingBottom="5dp"
|
android:paddingBottom="10dp"
|
||||||
android:background="@drawable/shape_dialog_small"
|
android:background="@drawable/shape_dialog"
|
||||||
tools:ignore="MissingDefaultResource">
|
tools:ignore="MissingDefaultResource">
|
||||||
|
|
||||||
<ProgressBar
|
<ProgressBar
|
||||||
android:layout_width="26dp"
|
android:layout_width="60dp"
|
||||||
android:layout_height="26dp"
|
android:layout_height="60dp"
|
||||||
android:indeterminateTint="@color/white_f6" />
|
android:indeterminateTint="@color/white_f6" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/tvMessage"
|
android:id="@+id/tvMessage"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="5dp"
|
android:layout_marginStart="10dp"
|
||||||
android:text="加载中……"
|
android:text="加载中……"
|
||||||
android:textColor="@color/white_f6"
|
android:textColor="@color/white_f6"
|
||||||
android:textSize="14sp"
|
android:textSize="26sp"
|
||||||
tools:ignore="HardcodedText" />
|
tools:ignore="HardcodedText" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
@@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/ivEmptyIcon"
|
android:id="@+id/ivEmptyIcon"
|
||||||
android:layout_width="120dp"
|
android:layout_width="250dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:src="@drawable/ic_empty_gray"
|
android:src="@drawable/ic_empty_gray"
|
||||||
android:adjustViewBounds="true"
|
android:adjustViewBounds="true"
|
||||||
@@ -21,8 +21,8 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:textColor="@color/black999"
|
android:textColor="@color/black999"
|
||||||
android:layout_marginTop="20dp"
|
android:layout_marginTop="50dp"
|
||||||
android:textSize="20sp"
|
android:textSize="50sp"
|
||||||
android:text="暂无数据"
|
android:text="暂无数据"
|
||||||
tools:ignore="HardcodedText" />
|
tools:ignore="HardcodedText" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
@@ -1,126 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:orientation="vertical"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:background="#DDFFFFFF">
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/ivLightHide"
|
|
||||||
android:layout_width="50dp"
|
|
||||||
android:layout_height="50dp"
|
|
||||||
android:layout_marginVertical="10dp"
|
|
||||||
android:layout_marginEnd="10dp"
|
|
||||||
android:layout_gravity="end|center_vertical"
|
|
||||||
android:src="@drawable/close"/>
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="80dp"
|
|
||||||
android:orientation="horizontal"
|
|
||||||
android:gravity="center_vertical">
|
|
||||||
<TextView
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:textSize="20sp"
|
|
||||||
android:text="继电器1"
|
|
||||||
android:layout_marginStart="50dp"
|
|
||||||
android:textColor="@color/black"/>
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/btnLightOpen"
|
|
||||||
android:layout_width="80dp"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:textSize="20sp"
|
|
||||||
android:text="开"
|
|
||||||
android:gravity="center"
|
|
||||||
android:background="@drawable/bg_init_button"
|
|
||||||
android:layout_marginStart="50dp"
|
|
||||||
android:textColor="@color/black"/>
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/btnLightClose"
|
|
||||||
android:layout_width="80dp"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:textSize="20sp"
|
|
||||||
android:text="关"
|
|
||||||
android:gravity="center"
|
|
||||||
android:background="@drawable/bg_init_button"
|
|
||||||
android:layout_marginStart="50dp"
|
|
||||||
android:textColor="@color/black"/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="80dp"
|
|
||||||
android:orientation="horizontal"
|
|
||||||
android:gravity="center_vertical">
|
|
||||||
<TextView
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:textSize="20sp"
|
|
||||||
android:text="继电器2"
|
|
||||||
android:layout_marginStart="50dp"
|
|
||||||
android:textColor="@color/black"/>
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/btnLightOpen2"
|
|
||||||
android:layout_width="80dp"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:textSize="20sp"
|
|
||||||
android:text="开"
|
|
||||||
android:gravity="center"
|
|
||||||
android:background="@drawable/bg_init_button"
|
|
||||||
android:layout_marginStart="50dp"
|
|
||||||
android:textColor="@color/black"/>
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/btnLightClose2"
|
|
||||||
android:layout_width="80dp"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:textSize="20sp"
|
|
||||||
android:text="关"
|
|
||||||
android:gravity="center"
|
|
||||||
android:background="@drawable/bg_init_button"
|
|
||||||
android:layout_marginStart="50dp"
|
|
||||||
android:textColor="@color/black"/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="80dp"
|
|
||||||
android:orientation="horizontal"
|
|
||||||
android:gravity="center_vertical">
|
|
||||||
<TextView
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:textSize="20sp"
|
|
||||||
android:text="继电器3"
|
|
||||||
android:layout_marginStart="50dp"
|
|
||||||
android:textColor="@color/black"/>
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/btnLightOpen3"
|
|
||||||
android:layout_width="80dp"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:textSize="20sp"
|
|
||||||
android:text="开"
|
|
||||||
android:gravity="center"
|
|
||||||
android:background="@drawable/bg_init_button"
|
|
||||||
android:layout_marginStart="50dp"
|
|
||||||
android:textColor="@color/black"/>
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/btnLightClose3"
|
|
||||||
android:layout_width="80dp"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:textSize="20sp"
|
|
||||||
android:text="关"
|
|
||||||
android:gravity="center"
|
|
||||||
android:background="@drawable/bg_init_button"
|
|
||||||
android:layout_marginStart="50dp"
|
|
||||||
android:textColor="@color/black"/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?><!--<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"-->
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"-->
|
||||||
<!-- xmlns:tools="http://schemas.android.com/tools"-->
|
<!-- xmlns:tools="http://schemas.android.com/tools"-->
|
||||||
<!-- android:layout_width="match_parent"-->
|
<!-- android:layout_width="match_parent"-->
|
||||||
<!-- android:layout_height="80dp"-->
|
<!-- android:layout_height="80dp"-->
|
||||||
@@ -25,23 +26,23 @@
|
|||||||
android:id="@+id/btnFoodName"
|
android:id="@+id/btnFoodName"
|
||||||
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
|
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="40dp"
|
android:layout_height="80dp"
|
||||||
android:layout_margin="6dp"
|
android:layout_margin="12dp"
|
||||||
android:ellipsize="end"
|
android:ellipsize="end"
|
||||||
android:fontFamily="sans-serif-medium"
|
android:fontFamily="sans-serif-medium"
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:insetTop="0dp"
|
android:insetTop="0dp"
|
||||||
android:insetBottom="0dp"
|
android:insetBottom="0dp"
|
||||||
android:maxLines="1"
|
android:maxLines="1"
|
||||||
|
app:paddingStart="5dp"
|
||||||
|
app:paddingEnd="5dp"
|
||||||
android:insetRight="0dp"
|
android:insetRight="0dp"
|
||||||
android:insetLeft="0dp"
|
android:insetLeft="0dp"
|
||||||
android:paddingHorizontal="8dp"
|
android:paddingHorizontal="8dp"
|
||||||
android:textColor="@color/black999"
|
android:textColor="@color/black999"
|
||||||
android:textSize="15sp"
|
android:textSize="30sp"
|
||||||
app:cornerRadius="6dp"
|
app:cornerRadius="12dp"
|
||||||
app:strokeWidth="1dp"
|
app:strokeWidth="2dp"
|
||||||
tools:text="土豆丝土豆丝土豆丝土豆丝土豆丝土豆丝" />
|
tools:text="土豆丝土豆丝土豆丝土豆丝土豆丝土豆丝"
|
||||||
<!-- android:paddingHorizontal="2dp"-->
|
/>
|
||||||
<!-- android:paddingLeft="5dp"-->
|
|
||||||
<!-- android:paddingRight="5dp"-->
|
|
||||||
|
|
||||||
|
|||||||
@@ -4,11 +4,11 @@
|
|||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:id="@+id/layoutCard"
|
android:id="@+id/layoutCard"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="140dp"
|
android:layout_height="216dp"
|
||||||
android:layout_margin="6dp"
|
android:layout_margin="12dp"
|
||||||
app:cardBackgroundColor="@color/bg_card_blue"
|
app:cardBackgroundColor="@color/bg_card_blue"
|
||||||
app:cardCornerRadius="6dp"
|
app:cardCornerRadius="12dp"
|
||||||
app:cardElevation="2dp"
|
app:cardElevation="0dp"
|
||||||
app:rippleColor="#B0BEC5">
|
app:rippleColor="#B0BEC5">
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
@@ -16,14 +16,14 @@
|
|||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:gravity="center_horizontal"
|
android:gravity="center_horizontal"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:padding="12dp">
|
android:padding="24dp">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/tvShelfName"
|
android:id="@+id/tvShelfName"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:textColor="@color/shelf_name_white"
|
android:textColor="@color/shelf_name_white"
|
||||||
android:textSize="12sp"
|
android:textSize="20sp"
|
||||||
android:textStyle="bold"
|
android:textStyle="bold"
|
||||||
tools:text="货架-01" />
|
tools:text="货架-01" />
|
||||||
|
|
||||||
@@ -39,7 +39,7 @@
|
|||||||
android:ellipsize="end"
|
android:ellipsize="end"
|
||||||
android:maxLines="1"
|
android:maxLines="1"
|
||||||
android:textColor="@color/white"
|
android:textColor="@color/white"
|
||||||
android:textSize="16sp"
|
android:textSize="30sp"
|
||||||
android:textStyle="bold"
|
android:textStyle="bold"
|
||||||
tools:text="空" />
|
tools:text="空" />
|
||||||
|
|
||||||
@@ -55,7 +55,7 @@
|
|||||||
android:ellipsize="end"
|
android:ellipsize="end"
|
||||||
android:maxLines="1"
|
android:maxLines="1"
|
||||||
android:textColor="@color/food_weight_blue"
|
android:textColor="@color/food_weight_blue"
|
||||||
android:textSize="14sp"
|
android:textSize="24sp"
|
||||||
android:textStyle="bold"
|
android:textStyle="bold"
|
||||||
tools:text="0千克" />
|
tools:text="0千克" />
|
||||||
|
|
||||||
@@ -71,14 +71,14 @@
|
|||||||
android:ellipsize="end"
|
android:ellipsize="end"
|
||||||
android:maxLines="1"
|
android:maxLines="1"
|
||||||
android:textColor="@color/food_weight_blue"
|
android:textColor="@color/food_weight_blue"
|
||||||
android:textSize="12sp"
|
android:textSize="18sp"
|
||||||
tools:text="-" />
|
tools:text="-" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/ivStaleFood"
|
android:id="@+id/ivStaleFood"
|
||||||
android:layout_width="60dp"
|
android:layout_width="100dp"
|
||||||
android:layout_height="60dp"
|
android:layout_height="100dp"
|
||||||
android:src="@drawable/ic_stale_food_512"
|
android:src="@drawable/ic_stale_food_512"
|
||||||
android:layout_gravity="top|end"
|
android:layout_gravity="top|end"
|
||||||
tools:ignore="ContentDescription"
|
tools:ignore="ContentDescription"
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="120dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="@android:color/white"
|
||||||
|
android:elevation="8dp"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tv_env_switch"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="50dp"
|
||||||
|
android:gravity="center"
|
||||||
|
android:text="切换环境"
|
||||||
|
android:textColor="#333333"
|
||||||
|
android:textSize="14sp" />
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="0.5dp"
|
||||||
|
android:background="#E0E0E0" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tv_log"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="50dp"
|
||||||
|
android:gravity="center"
|
||||||
|
android:text="查看日志"
|
||||||
|
android:textColor="#333333"
|
||||||
|
android:textSize="14sp" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
Reference in New Issue
Block a user