|
@@ -15,9 +15,12 @@ import androidx.core.content.ContextCompat
|
|
|
import androidx.lifecycle.lifecycleScope
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager
|
|
|
import com.blankj.utilcode.util.LogUtils
|
|
|
+import com.blankj.utilcode.util.ThreadUtils
|
|
|
+import com.blankj.utilcode.util.ThreadUtils.SimpleTask
|
|
|
import com.bumptech.glide.Glide
|
|
|
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
|
|
import com.bumptech.glide.request.RequestOptions
|
|
|
+import com.kongzue.dialogx.dialogs.PopTip
|
|
|
import com.rc.httpcore.HttpConfig
|
|
|
import com.rc.httpcore.bean.GiveBackBean
|
|
|
import com.rc.httpcore.bean.LockVoListBean
|
|
@@ -32,6 +35,7 @@ import org.greenrobot.eventbus.ThreadMode
|
|
|
import retrofit2.HttpException
|
|
|
import xn.hxp.R
|
|
|
import xn.hxp.app.ChemicalApp
|
|
|
+import xn.hxp.blu.BluetoothConnectionManager
|
|
|
import xn.hxp.comm.Constants
|
|
|
import xn.hxp.databinding.ActivityChemicalsAlsoBinding
|
|
|
import xn.hxp.receiver.OnSerialScanListener
|
|
@@ -48,6 +52,7 @@ import xn.hxp.weidith.*
|
|
|
import java.lang.Runnable
|
|
|
import java.net.ConnectException
|
|
|
import java.net.SocketTimeoutException
|
|
|
+import java.nio.charset.StandardCharsets
|
|
|
|
|
|
//化学品-归还 StorageDialog 柜字信息
|
|
|
class ChemicalsAlsoActivity : BaseCountDownActivity<ActivityChemicalsAlsoBinding>() {
|
|
@@ -738,43 +743,85 @@ class ChemicalsAlsoActivity : BaseCountDownActivity<ActivityChemicalsAlsoBinding
|
|
|
private fun connectToDeviceWithTimeout() {
|
|
|
showToast("连接中...", Toast.LENGTH_SHORT)
|
|
|
lifecycleScope.launch {
|
|
|
- MediaPlayerHelper.playRawMp3(this@ChemicalsAlsoActivity, R.raw.qing_zheng_zhong)
|
|
|
- BluetoothTool.INSTANCE.connect(object : BluetoothCallBack {
|
|
|
- override fun callBack(weight: String) {
|
|
|
- if ("" == weight || weight.isEmpty()) {
|
|
|
- return
|
|
|
- }
|
|
|
- if (weight.toDouble() > 2999) {
|
|
|
- turnOffWeighing()
|
|
|
- } else {
|
|
|
- if (weight.toDouble() > 0) {
|
|
|
- if (mWeighingValue!!.text.toString().trim()
|
|
|
- .isNotEmpty()
|
|
|
- ) {
|
|
|
- if (weight.toDouble() == mWeighingValue!!.text.toString()
|
|
|
- .trim().toDouble()
|
|
|
- ) {
|
|
|
- if (!taskStarted) {
|
|
|
- taskStarted = true
|
|
|
- LogUtils.i("=====执行了")
|
|
|
- delayedTaskToUpdateUI()
|
|
|
- return
|
|
|
+ val deviceAddress = withContext(Dispatchers.IO) {
|
|
|
+ BluetoothConnectionManager.getDeviceAddress()
|
|
|
+ }
|
|
|
+ if (deviceAddress != null) {
|
|
|
+ val socket = withContext(Dispatchers.IO) {
|
|
|
+ BluetoothConnectionManager.connectToDevice(deviceAddress)
|
|
|
+ }
|
|
|
+ if (socket != null) {
|
|
|
+ // 连接成功后的处理逻辑
|
|
|
+ // 在这里使用返回的 BluetoothSocket 对象进行后续操作
|
|
|
+ MediaPlayerHelper.playRawMp3(this@ChemicalsAlsoActivity, R.raw.qing_zheng_zhong)
|
|
|
+ // 连接成功后的处理逻辑
|
|
|
+ withContext(Dispatchers.Main) {
|
|
|
+ do {
|
|
|
+// try {
|
|
|
+ val inputStream = socket!!.inputStream
|
|
|
+ val bt = ByteArray(1024)
|
|
|
+ val content = inputStream!!.read(bt)
|
|
|
+ if (content != null && content > 0) {
|
|
|
+ val contents = String(
|
|
|
+ bt,
|
|
|
+ 0,
|
|
|
+ content,
|
|
|
+ StandardCharsets.UTF_8
|
|
|
+ )
|
|
|
+ val split = contents.split("\n")
|
|
|
+ val weight = split[0].trim()
|
|
|
+ LogUtils.i("===================称重未处理之前=======$contents")
|
|
|
+ LogUtils.i("===================weight=======$weight")
|
|
|
+ LogUtils.i("=====称重数据$weight $taskStarted ${mWeighingValue!!.text.toString()}")
|
|
|
+ if (weight.toDouble() > 2999) {
|
|
|
+ turnOffWeighing()
|
|
|
+ } else {
|
|
|
+ if (weight.toDouble() > 0) {
|
|
|
+ if (mWeighingValue!!.text.toString().trim()
|
|
|
+ .isNotEmpty()
|
|
|
+ ) {
|
|
|
+ if (weight.toDouble() == mWeighingValue!!.text.toString()
|
|
|
+ .trim().toDouble()
|
|
|
+ ) {
|
|
|
+ if (taskStarted == false) {
|
|
|
+ taskStarted = true
|
|
|
+ LogUtils.i("=====执行了")
|
|
|
+ socket.close()
|
|
|
+ delayedTaskToUpdateUI()
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ mWeighingValue!!.setText("$weight")
|
|
|
+ } else {
|
|
|
+ mWeighingValue!!.setText("")
|
|
|
}
|
|
|
}
|
|
|
+ delay(200)
|
|
|
+ } else {
|
|
|
+// jobTow?.cancel()
|
|
|
+ showToast("请手动输入")
|
|
|
+ weiView()
|
|
|
+ break
|
|
|
}
|
|
|
- mWeighingValue!!.setText("$weight")
|
|
|
- } else {
|
|
|
- mWeighingValue!!.setText("")
|
|
|
- }
|
|
|
+// } catch (e: Exception) {
|
|
|
+// jobTow?.cancel()
|
|
|
+// weiView()
|
|
|
+// break
|
|
|
+// }
|
|
|
+ } while (mWeighDialog != null && mWeighDialog!!.isShowing)
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- override fun connectFailed(msg: String) {
|
|
|
- showToast("找不到设备", Toast.LENGTH_SHORT)
|
|
|
+ } else {
|
|
|
+ // 连接失败的处理逻辑
|
|
|
+ showToast("连接失败或超时", Toast.LENGTH_SHORT)
|
|
|
weiView()
|
|
|
}
|
|
|
- })
|
|
|
-
|
|
|
+ } else {
|
|
|
+ // 根据设备名称获取的设备地址为空,处理无法找到设备的情况
|
|
|
+ showToast("找不到设备", Toast.LENGTH_SHORT)
|
|
|
+ weiView()
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1554,15 +1601,14 @@ class ChemicalsAlsoActivity : BaseCountDownActivity<ActivityChemicalsAlsoBinding
|
|
|
} catch (e: Exception) {
|
|
|
|
|
|
}
|
|
|
- showLoading("加载中...")
|
|
|
+ PopTip.show("正在开门")
|
|
|
val disposable = ApiRepository.lockOperate(map)
|
|
|
.subscribe({ data ->
|
|
|
- dismissLoading()
|
|
|
val containsFalse =
|
|
|
mCabinetLockVoList!!.any { it.isOk == false && it.unlockingMethod == 2 }
|
|
|
LogUtils.i("====开锁信息${containsFalse} $isok")
|
|
|
if (containsFalse) {
|
|
|
- showLoading("查询中...")
|
|
|
+ PopTip.show("正在查询开门状态...")
|
|
|
// 开始执行任务,每 3 秒执行一次
|
|
|
startCountdownLock()
|
|
|
handlerUtil.startTask(task, 1000)
|
|
@@ -1570,19 +1616,17 @@ class ChemicalsAlsoActivity : BaseCountDownActivity<ActivityChemicalsAlsoBinding
|
|
|
if (isok) {//再次开门
|
|
|
handlerUtil.stopAllTasks()
|
|
|
countdownTimer?.cancel()
|
|
|
- dismissLoading()
|
|
|
isok = false
|
|
|
} else {
|
|
|
+ PopTip.show("开锁成功!")
|
|
|
//开锁成功
|
|
|
handlerUtil.stopAllTasks()
|
|
|
countdownTimer?.cancel()
|
|
|
- dismissLoading()
|
|
|
//开锁成功
|
|
|
weighData()
|
|
|
}
|
|
|
}
|
|
|
}, { throwable ->
|
|
|
- dismissLoading()
|
|
|
showNetError(throwable)
|
|
|
|
|
|
})
|