This commit is contained in:
2025-11-07 08:58:21 +08:00
parent 3366fc02e5
commit c20ce471cb
5 changed files with 76 additions and 52 deletions
@@ -82,12 +82,6 @@ class HomeActivity : BaseActivity() {
//开灯(开 继电器1 //开灯(开 继电器1
const val LIGHT_CLOSE = "${HEADER}020102020102020000000000000000000000000000${FOOTER}" const val LIGHT_CLOSE = "${HEADER}020102020102020000000000000000000000000000${FOOTER}"
const val LIGHT_OPEN = "${HEADER}020102020002020000000000000000000000000000${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<ShelfModel> = mutableListOf() val list: MutableList<ShelfModel> = mutableListOf()
val weightArray = SparseArray<Double?>() val weightArray = SparseArray<Double?>()
@@ -204,27 +198,6 @@ class HomeActivity : BaseActivity() {
// delay(500) // 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<*>) { private fun getTokenSuccess(data: RespData<*>) {
@@ -1,23 +1,26 @@
package com.shuwei.intelligent.shelves.base package com.shuwei.intelligent.shelves.base
import android.content.Intent import android.content.Intent
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.view.View import android.view.View
import android.view.WindowInsets
import android.view.WindowInsetsController
import android.widget.TextView import android.widget.TextView
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 com.gyf.immersionbar.BarHide import com.gyf.immersionbar.BarHide
import com.gyf.immersionbar.ImmersionBar import com.gyf.immersionbar.ImmersionBar
import com.shuwei.intelligent.shelves.HomeActivity 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.R
import com.shuwei.intelligent.shelves.databinding.ActivityBaseBinding 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") @Suppress("DEPRECATION")
open class BaseActivity : AppCompatActivity() { open class BaseActivity : AppCompatActivity() {
@@ -57,6 +60,7 @@ open class BaseActivity : AppCompatActivity() {
// } // }
// } // }
lightSwitchClick()
} }
fun hideStatusBar() { fun hideStatusBar() {
@@ -97,23 +101,6 @@ open class BaseActivity : AppCompatActivity() {
binding.tvRightStatus.text = data 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分钟 // 5分钟
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()) }
@@ -142,8 +129,23 @@ open class BaseActivity : AppCompatActivity() {
mHandler.removeCallbacks(mTimeoutRunnable) 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())
}
} }
} }
@@ -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<ShelfModel>()
// fun load(list: MutableList<ShelfModel>) {
// 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
}
//同一产品
}
}
@@ -110,6 +110,20 @@
android:src="@drawable/ic_back_512" android:src="@drawable/ic_back_512"
tools:ignore="ContentDescription" /> tools:ignore="ContentDescription" />
<TextView
android:id="@+id/btnClearEmpty"
android:layout_width="120dp"
android:layout_height="60dp"
android:layout_gravity="bottom|end"
android:layout_marginBottom="16dp"
android:layout_marginEnd="24dp"
android:maxLines="1"
android:text="清空"
android:gravity="center"
android:textColor="@color/food_name_black"
android:textSize="20sp"
tools:ignore="HardcodedText" />
</FrameLayout> </FrameLayout>
</com.google.android.material.card.MaterialCardView> </com.google.android.material.card.MaterialCardView>
+3 -4
View File
@@ -93,7 +93,7 @@
android:insetTop="0dp" android:insetTop="0dp"
android:insetBottom="0dp" android:insetBottom="0dp"
android:maxLines="1" android:maxLines="1"
android:text="清零00" android:text="清零"
android:textColor="@color/white" android:textColor="@color/white"
android:textSize="15sp" android:textSize="15sp"
app:cornerRadius="6dp" app:cornerRadius="6dp"
@@ -115,14 +115,13 @@
android:layout_width="65dp" android:layout_width="65dp"
android:layout_height="30dp" android:layout_height="30dp"
android:layout_gravity="bottom|end" android:layout_gravity="bottom|end"
android:layout_marginBottom="22dp" android:layout_marginBottom="10dp"
android:layout_marginEnd="12dp" android:layout_marginEnd="12dp"
android:maxLines="1" android:maxLines="1"
android:text="清空" android:text="清空"
android:textStyle="bold"
android:gravity="center" android:gravity="center"
android:textColor="@color/food_name_black" android:textColor="@color/food_name_black"
android:textSize="15sp" android:textSize="12sp"
tools:ignore="HardcodedText" /> tools:ignore="HardcodedText" />
</FrameLayout> </FrameLayout>