From c20ce471cb867e2b33fc8bbeb2ee7228e4db2154 Mon Sep 17 00:00:00 2001 From: lvmeng <848755140@qq.com> Date: Fri, 7 Nov 2025 08:58:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../intelligent/shelves/HomeActivity.kt | 27 ------------ .../intelligent/shelves/base/BaseActivity.kt | 44 ++++++++++--------- .../shelves/utils/StaleFoodRule.kt | 36 +++++++++++++++ .../res/layout-sw600dp/activity_shelf.xml | 14 ++++++ app/src/main/res/layout/activity_shelf.xml | 7 ++- 5 files changed, 76 insertions(+), 52 deletions(-) create mode 100644 app/src/main/java/com/shuwei/intelligent/shelves/utils/StaleFoodRule.kt diff --git a/app/src/main/java/com/shuwei/intelligent/shelves/HomeActivity.kt b/app/src/main/java/com/shuwei/intelligent/shelves/HomeActivity.kt index a557a8f..302f535 100644 --- a/app/src/main/java/com/shuwei/intelligent/shelves/HomeActivity.kt +++ b/app/src/main/java/com/shuwei/intelligent/shelves/HomeActivity.kt @@ -82,12 +82,6 @@ class HomeActivity : BaseActivity() { //开灯(开 继电器1) const val LIGHT_CLOSE = "${HEADER}020102020102020000000000000000000000000000${FOOTER}" const val LIGHT_OPEN = "${HEADER}020102020002020000000000000000000000000000${FOOTER}" -// const val LIGHT_CLOSE = "${HEADER}020102020101010000000000000000000000000000${FOOTER}" -// const val LIGHT_OPEN = "${HEADER}020102020000000000000000000000000000000000${FOOTER}" -// const val LIGHT_CLOSE2 = "${HEADER}020102020102020000000000000000000000000000${FOOTER}" -// const val LIGHT_OPEN2 = "${HEADER}020102020002020000000000000000000000000000${FOOTER}" -// const val LIGHT_CLOSE3 = "${HEADER}020102020102020000000000000000000000000000${FOOTER}" -// const val LIGHT_OPEN3 = "${HEADER}020102020002020000000000000000000000000000${FOOTER}" val list: MutableList = mutableListOf() val weightArray = SparseArray() @@ -204,27 +198,6 @@ class HomeActivity : BaseActivity() { // delay(500) // } // } - - lightSwitchClick() - } - - fun switchLight(isOpen: Boolean) { - val tag = getLeftView().tag?.toString()?.toBoolean() ?: true - if(tag == isOpen) { - return - } - lifecycleScope.launch { - SerialPortManager.send(if (isOpen) LIGHT_OPEN else LIGHT_CLOSE) - } - getLeftView().tag = isOpen - } - - private fun lightSwitchClick() { - switchLight(true) - addLeftClick { - val tag = getLeftView().tag?.toString()?.toBoolean() ?: true - switchLight(tag.not()) - } } private fun getTokenSuccess(data: RespData<*>) { diff --git a/app/src/main/java/com/shuwei/intelligent/shelves/base/BaseActivity.kt b/app/src/main/java/com/shuwei/intelligent/shelves/base/BaseActivity.kt index 433b474..3528ccd 100644 --- a/app/src/main/java/com/shuwei/intelligent/shelves/base/BaseActivity.kt +++ b/app/src/main/java/com/shuwei/intelligent/shelves/base/BaseActivity.kt @@ -1,23 +1,26 @@ package com.shuwei.intelligent.shelves.base import android.content.Intent -import android.os.Build import android.os.Bundle import android.os.Handler import android.os.Looper import android.view.View -import android.view.WindowInsets -import android.view.WindowInsetsController import android.widget.TextView import androidx.activity.result.ActivityResultLauncher import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.core.content.ContextCompat +import androidx.lifecycle.lifecycleScope import com.gyf.immersionbar.BarHide import com.gyf.immersionbar.ImmersionBar import com.shuwei.intelligent.shelves.HomeActivity +import com.shuwei.intelligent.shelves.HomeActivity.Companion.LIGHT_CLOSE +import com.shuwei.intelligent.shelves.HomeActivity.Companion.LIGHT_OPEN import com.shuwei.intelligent.shelves.R import com.shuwei.intelligent.shelves.databinding.ActivityBaseBinding +import com.shuwei.intelligent.shelves.serial.SerialPortManager +import com.shuwei.intelligent.shelves.utils.ext.clickWithDebounce +import kotlinx.coroutines.launch @Suppress("DEPRECATION") open class BaseActivity : AppCompatActivity() { @@ -57,6 +60,7 @@ open class BaseActivity : AppCompatActivity() { // } // } + lightSwitchClick() } fun hideStatusBar() { @@ -97,23 +101,6 @@ open class BaseActivity : AppCompatActivity() { binding.tvRightStatus.text = data } - fun addViewClick(view:View, click: () -> Unit) { - view.setOnClickListener { - click() - } - } - - fun getLeftView(): TextView { - return binding.tvLeftStatus - } - - fun addLeftClick(click: (View) -> Unit) { - binding.tvLeftStatus.setOnClickListener(click) - } - - fun addRightClick(click: (View) -> Unit) { - binding.tvRightStatus.setOnClickListener(click) - } // 5分钟 private val TIME_OUT: Long = (5 * 60 * 1000).toLong() private val mHandler by lazy { Handler(Looper.getMainLooper()) } @@ -142,8 +129,23 @@ open class BaseActivity : AppCompatActivity() { mHandler.removeCallbacks(mTimeoutRunnable) } - fun timeOutOperation() { + fun switchLight(isOpen: Boolean) { + val tag = binding.tvLeftStatus.tag?.toString()?.toBoolean() ?: true + if(tag == isOpen) { + return + } + lifecycleScope.launch { + SerialPortManager.send(if (isOpen) LIGHT_OPEN else LIGHT_CLOSE) + } + binding.tvLeftStatus.tag = isOpen + } + private fun lightSwitchClick() { + switchLight(true) + binding.tvLeftStatus.clickWithDebounce { + val tag = binding.tvLeftStatus.tag?.toString()?.toBoolean() ?: true + switchLight(tag.not()) + } } } \ No newline at end of file diff --git a/app/src/main/java/com/shuwei/intelligent/shelves/utils/StaleFoodRule.kt b/app/src/main/java/com/shuwei/intelligent/shelves/utils/StaleFoodRule.kt new file mode 100644 index 0000000..033d7a3 --- /dev/null +++ b/app/src/main/java/com/shuwei/intelligent/shelves/utils/StaleFoodRule.kt @@ -0,0 +1,36 @@ +package com.shuwei.intelligent.shelves.utils + +import android.util.SparseArray +import androidx.core.util.containsKey +import com.shuwei.intelligent.shelves.model.ShelfModel + +object StaleFoodRule { + + private val shelfMap = SparseArray() + +// fun load(list: MutableList) { +// if (list.isEmpty()) { +// return +// } +// list.forEach { +// shelfMap.put(it.deviceNo, it) +// } +// } + + fun judge(item: ShelfModel, block:(Boolean)-> Unit = {}) { + val deviceNo = item.deviceNo + if (!shelfMap.containsKey(deviceNo)) { + //首次设置数据 + shelfMap.put(deviceNo, item) + return + } + val lastItem = shelfMap.get(deviceNo) + if (lastItem.goodsId != item.goodsId) { + //柜子商品更换 + shelfMap.put(deviceNo, item) + return + } + //同一产品 + } + +} \ No newline at end of file diff --git a/app/src/main/res/layout-sw600dp/activity_shelf.xml b/app/src/main/res/layout-sw600dp/activity_shelf.xml index 2884982..217889e 100644 --- a/app/src/main/res/layout-sw600dp/activity_shelf.xml +++ b/app/src/main/res/layout-sw600dp/activity_shelf.xml @@ -110,6 +110,20 @@ android:src="@drawable/ic_back_512" tools:ignore="ContentDescription" /> + + diff --git a/app/src/main/res/layout/activity_shelf.xml b/app/src/main/res/layout/activity_shelf.xml index a3f73dd..e2a1ca6 100644 --- a/app/src/main/res/layout/activity_shelf.xml +++ b/app/src/main/res/layout/activity_shelf.xml @@ -93,7 +93,7 @@ android:insetTop="0dp" android:insetBottom="0dp" android:maxLines="1" - android:text="清零00" + android:text="清零" android:textColor="@color/white" android:textSize="15sp" app:cornerRadius="6dp" @@ -115,14 +115,13 @@ android:layout_width="65dp" android:layout_height="30dp" android:layout_gravity="bottom|end" - android:layout_marginBottom="22dp" + android:layout_marginBottom="10dp" android:layout_marginEnd="12dp" android:maxLines="1" android:text="清空" - android:textStyle="bold" android:gravity="center" android:textColor="@color/food_name_black" - android:textSize="15sp" + android:textSize="12sp" tools:ignore="HardcodedText" />