2 Commits
20 changed files with 597 additions and 73 deletions
@@ -9,6 +9,7 @@ import com.chad.library.adapter4.viewholder.QuickViewHolder
import com.shuwei.dish.match.R import com.shuwei.dish.match.R
import com.shuwei.dish.match.databinding.ListItemDishCookBinding import com.shuwei.dish.match.databinding.ListItemDishCookBinding
import com.shuwei.dish.match.entity.CookFoodGoodsEntity import com.shuwei.dish.match.entity.CookFoodGoodsEntity
import com.shuwei.dish.match.utils.ext.roundedOneDecimalPlace
import java.text.DecimalFormat import java.text.DecimalFormat
class DishPartAdapter(list: MutableList<CookFoodGoodsEntity>) : class DishPartAdapter(list: MutableList<CookFoodGoodsEntity>) :
@@ -26,8 +27,9 @@ class DishPartAdapter(list: MutableList<CookFoodGoodsEntity>) :
holder.binding.run { holder.binding.run {
tvDishName.text = item!!.goodsName tvDishName.text = item!!.goodsName
tvDishType.text = if (item.materialType == 1) "主辅材:主材" else if (item.materialType == 2) "主辅材:辅材" else "" tvDishType.text = if (item.materialType == 1) "主辅材:主材" else if (item.materialType == 2) "主辅材:辅材" else ""
//"${DecimalFormat("#").format(item.useWeight)}克"
tvDishWeight.text = tvDishWeight.text =
if (item.useWeight == null || item.useWeight == 0.toDouble()) "" else "${DecimalFormat("#").format(item.useWeight)}" if (item.useWeight == null || item.useWeight == 0.toDouble()) "" else "${item.useWeight!!.roundedOneDecimalPlace()}"
tvDishWeight.setTextColor( tvDishWeight.setTextColor(
ContextCompat.getColor( ContextCompat.getColor(
context, context,
@@ -23,6 +23,7 @@ import com.shuwei.dish.match.utils.ext.buildSpannableString
import com.shuwei.dish.match.utils.ext.clickWithDebounce import com.shuwei.dish.match.utils.ext.clickWithDebounce
import com.shuwei.dish.match.utils.ext.dp import com.shuwei.dish.match.utils.ext.dp
import com.shuwei.dish.match.utils.ext.invisible import com.shuwei.dish.match.utils.ext.invisible
import com.shuwei.dish.match.utils.ext.roundedOneDecimalPlace
import com.shuwei.dish.match.utils.ext.visible import com.shuwei.dish.match.utils.ext.visible
class TextCellAdapter(var list: MutableList<SeasoningEntity>) : class TextCellAdapter(var list: MutableList<SeasoningEntity>) :
@@ -123,7 +124,8 @@ class TextCellAdapter(var list: MutableList<SeasoningEntity>) :
val weight = item.useWeight ?: 0.toDouble() val weight = item.useWeight ?: 0.toDouble()
val weightColor = if (weight == 0.toDouble()) "#999999" else "#00BC71" val weightColor = if (weight == 0.toDouble()) "#999999" else "#00BC71"
appendText( appendText(
"${DecimalFormat("#").format(weight)}g", // "${DecimalFormat("#").format(weight)}g",
"${weight.roundedOneDecimalPlace()}g",
ForegroundColorSpan(weightColor.toColorInt()), ForegroundColorSpan(weightColor.toColorInt()),
AbsoluteSizeSpan(30, true) AbsoluteSizeSpan(30, true)
) )
@@ -20,10 +20,13 @@ import com.shuwei.dish.match.dialog.Loading
import com.shuwei.dish.match.http.HttpUtil import com.shuwei.dish.match.http.HttpUtil
import com.shuwei.dish.match.http.UrlConfig import com.shuwei.dish.match.http.UrlConfig
import com.shuwei.dish.match.ui.HomeActivity.Companion.TAG import com.shuwei.dish.match.ui.HomeActivity.Companion.TAG
import com.shuwei.dish.match.ui.InitActivity
import com.shuwei.dish.match.utils.ActivityManager import com.shuwei.dish.match.utils.ActivityManager
import com.shuwei.dish.match.utils.ext.gone import com.shuwei.dish.match.utils.ext.gone
import com.shuwei.dish.match.utils.ext.invisible
import com.shuwei.dish.match.utils.ext.put import com.shuwei.dish.match.utils.ext.put
import com.shuwei.dish.match.utils.ext.toast import com.shuwei.dish.match.utils.ext.toast
import com.shuwei.dish.match.utils.ext.visible
import java.time.LocalDateTime import java.time.LocalDateTime
import java.time.ZoneId import java.time.ZoneId
import java.time.format.DateTimeFormatter import java.time.format.DateTimeFormatter
@@ -50,6 +53,9 @@ open class BaseActivity : AppCompatActivity() {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
ActivityManager.addActivity(this) ActivityManager.addActivity(this)
binding = ActivityBaseBinding.inflate(layoutInflater) binding = ActivityBaseBinding.inflate(layoutInflater)
if (this !is InitActivity) {
binding.root.setBackgroundColor(ContextCompat.getColor(this, R.color.bg_color))
}
setContentView(binding.root) setContentView(binding.root)
statusBarDarkFont(enable = false) statusBarDarkFont(enable = false)
launcher = launcher =
@@ -69,6 +75,11 @@ open class BaseActivity : AppCompatActivity() {
binding.ivBack.setOnClickListener { finish() } binding.ivBack.setOnClickListener { finish() }
} }
private var bgState = true
fun useBackground(enable: Boolean) {
bgState = enable
}
override fun onDestroy() { override fun onDestroy() {
dismissLoading() dismissLoading()
super.onDestroy() super.onDestroy()
@@ -103,6 +114,12 @@ open class BaseActivity : AppCompatActivity() {
rightIconActon?.invoke(binding.ivRightIcon) rightIconActon?.invoke(binding.ivRightIcon)
} }
fun setHeaderBgVisible(show: Boolean) {
binding.ivHeaderBg.let {
if (show) it.visible() else it.invisible()
}
}
public fun setHeaderBackground(isHomePage: Boolean = false) { public fun setHeaderBackground(isHomePage: Boolean = false) {
binding.ivHeaderBg.setImageResource( binding.ivHeaderBg.setImageResource(
if (isHomePage) R.drawable.bg_home_page else R.drawable.bg_other_page if (isHomePage) R.drawable.bg_home_page else R.drawable.bg_other_page
@@ -30,6 +30,7 @@ class BaseApp : Application() {
var token: String? = null var token: String? = null
var deviceId: String? = null var deviceId: String? = null
var appVersion: String = "1"
@Volatile @Volatile
private var sharedPref: SharedPreferences? = null private var sharedPref: SharedPreferences? = null
@@ -65,8 +65,11 @@ interface AppDao {
@Query("SELECT * FROM dm_seasoning WHERE isDel = 0 AND goodsId = :goodsId") @Query("SELECT * FROM dm_seasoning WHERE isDel = 0 AND goodsId = :goodsId")
suspend fun getSeasoningByGoodsId(goodsId: Int): SeasoningEntity? suspend fun getSeasoningByGoodsId(goodsId: Int): SeasoningEntity?
// @Query("SELECT * FROM dm_seasoning WHERE isDel = 0 AND goodsId != -1 AND goodsName != '' ORDER BY sort ASC")
// fun getAllStream(): Flow<MutableList<SeasoningEntity>>
@Query("SELECT * FROM dm_seasoning WHERE isDel = 0 AND goodsId != -1 AND goodsName != '' ORDER BY sort ASC") @Query("SELECT * FROM dm_seasoning WHERE isDel = 0 AND goodsId != -1 AND goodsName != '' ORDER BY sort ASC")
fun getAllStream(): Flow<MutableList<SeasoningEntity>> fun getAllStream(): MutableList<SeasoningEntity>
@Query("SELECT * FROM dm_seasoning WHERE isDel = 0 AND goodsName LIKE '%' || :query || '%'") @Query("SELECT * FROM dm_seasoning WHERE isDel = 0 AND goodsName LIKE '%' || :query || '%'")
suspend fun search(query: String): MutableList<SeasoningEntity> suspend fun search(query: String): MutableList<SeasoningEntity>
@@ -144,7 +144,7 @@ class BottomDialog2(
binding.tvWeight.text = getTextSpan(weight) binding.tvWeight.text = getTextSpan(weight)
} }
}) })
binding.tvWeight.text = getTextSpan(0) binding.tvWeight.text = getTextSpan(0.0)
if (clickName.isNullOrBlank().not()) { if (clickName.isNullOrBlank().not()) {
binding.etSheetInput.setText(clickName!!.trim()) binding.etSheetInput.setText(clickName!!.trim())
@@ -225,11 +225,11 @@ class BottomDialog2(
}) })
} }
fun getTextSpan(weight: Int): SpannableStringBuilder { fun getTextSpan(weight: Double): SpannableStringBuilder {
var topWeight = "$weight" var topWeight = "$weight"
var bottomUnit = "" var bottomUnit = ""
if (weight >= 1000) { if (weight >= 1000) {
topWeight = "${weight / 1000F}" topWeight = "$weight"
bottomUnit = "千克" bottomUnit = "千克"
} }
return buildSpannableString { return buildSpannableString {
@@ -8,6 +8,7 @@ import android.text.style.ForegroundColorSpan
import android.text.style.LineHeightSpan import android.text.style.LineHeightSpan
import android.text.style.StyleSpan import android.text.style.StyleSpan
import android.util.Log import android.util.Log
import android.util.SparseArray
import android.util.SparseIntArray import android.util.SparseIntArray
import android.widget.FrameLayout import android.widget.FrameLayout
import android.widget.TextView import android.widget.TextView
@@ -39,6 +40,7 @@ import com.shuwei.dish.match.databinding.ActivityDeviceConfigBinding
import com.shuwei.dish.match.dialog.BottomDialog2 import com.shuwei.dish.match.dialog.BottomDialog2
import com.shuwei.dish.match.utils.SpTool import com.shuwei.dish.match.utils.SpTool
import com.shuwei.dish.match.utils.ext.clickWithDebounce import com.shuwei.dish.match.utils.ext.clickWithDebounce
import com.shuwei.dish.match.utils.ext.gone
class DeviceConfigActivity : BaseActivity() { class DeviceConfigActivity : BaseActivity() {
@@ -65,7 +67,8 @@ class DeviceConfigActivity : BaseActivity() {
private lateinit var appViewModel: AppViewModel private lateinit var appViewModel: AppViewModel
private var cookMode: Int = 0 private var cookMode: Int = 0
private val weightArray = SparseIntArray() // private val weightArray = SparseIntArray()
private val weightArray = SparseArray<Double>()
private val addressArray = AddressUtil.getWeighAddressArray() private val addressArray = AddressUtil.getWeighAddressArray()
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
@@ -80,14 +83,14 @@ class DeviceConfigActivity : BaseActivity() {
}, titleAction = { }, titleAction = {
it.text = "设备配置" it.text = "设备配置"
}, rightIconActon = { }, rightIconActon = {
it.visible() it.gone()
it.alpha = 0.0F // it.alpha = 0.0F
it.setImageResource(R.drawable.ic_setting) // it.setImageResource(R.drawable.ic_setting)
it.setOnClickListener { // it.setOnClickListener {_->
detector.setOnDelayedMultiClickListener(it) { // detector.setOnDelayedMultiClickListener(it) {
defaultDataSettingDialog() // defaultDataSettingDialog()
} // }
} // }
}) })
loadQualitySpan(isEnable = false) loadQualitySpan(isEnable = false)
@@ -193,9 +196,11 @@ class DeviceConfigActivity : BaseActivity() {
appViewModel.clearAllSeasoning { appViewModel.clearAllSeasoning {
record?.list?.forEach { entity -> record?.list?.forEach { entity ->
entity.useWeight = weightArray[addressArray[entity.sort]].toDouble() entity.useWeight = weightArray[addressArray[entity.sort]].toDouble()
appViewModel.saveSeasoning(entity) {} appViewModel.saveSeasoning(entity) {
updateGridData(entity)
} }
loadSeasoning() }
// loadSeasoning()
} }
}.onFailure { it.printStackTrace() } }.onFailure { it.printStackTrace() }
} }
@@ -28,6 +28,7 @@ import com.shuwei.dish.match.viewmodel.factory.AppFactory
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlin.toString
class InitActivity : BaseActivity() { class InitActivity : BaseActivity() {
companion object { companion object {
@@ -41,9 +42,13 @@ class InitActivity : BaseActivity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
statusBarDarkFont(enable = true) statusBarDarkFont(enable = true)
// useBackground(false)
binding = ActivityInitBinding.inflate(layoutInflater) binding = ActivityInitBinding.inflate(layoutInflater)
setContentView(binding.root) setContentView(binding.root)
setHeaderBackground(isHomePage = true)
// setHeaderBackground(isHomePage = true)
setHeaderBgVisible(false)
BaseApp.appVersion = AppUtil.getAppVersionCode(this).toString()
// 获取 ANDROID_ID // 获取 ANDROID_ID
var androidId = var androidId =
@@ -53,12 +58,12 @@ class InitActivity : BaseActivity() {
SpTool.put(SpTool.DEVICE_ID, androidId) SpTool.put(SpTool.DEVICE_ID, androidId)
BaseApp.configUrl = UrlConfig.BASE_URL BaseApp.configUrl = UrlConfig.BASE_URL
BaseApp.canteenId = "0" BaseApp.canteenId = "0"
// TODO: 以上保存deviceId用于临时使用,后续改为下面注释方式 // // TODO: 以上保存deviceId用于临时使用,后续改为下面注释方式
// var deviceId = AppUtil.getUDID(this) // var deviceId = AppUtil.getUDID(this)
// Log.d(TAG, "onCreate: deviceId=$deviceId") // Log.d(TAG, "onCreate: deviceId=$deviceId")
//// deviceId = "39a7abdd06b3c7ab" //// deviceId = "39a7abdd06b3c7ab"
//// deviceId = "3ea47dc0-3cf0-3c2f-909c-265a9a65572e" // deviceId = "3ea47dc0-3cf0-3c2f-909c-265a9a65572e"
//// deviceId = "6ce7cd59-b875-38b2-b73d-88a570be3212" //// deviceId = "6ce7cd59-b875-38b2-b73d-88a570be3212"
// //
// BaseApp.deviceId = deviceId // BaseApp.deviceId = deviceId
@@ -115,21 +120,21 @@ class InitActivity : BaseActivity() {
if (it.isEmpty()) { if (it.isEmpty()) {
//无调料信息打开采样历史列表页面,点击设置配置调料信息 //无调料信息打开采样历史列表页面,点击设置配置调料信息
startActivity<SamplingListActivity>() startActivity<SamplingListActivity>()
finish() // finish()
return@loadSeasoning return@loadSeasoning
} }
appViewModel.countCookFood(cookMode = 1) { count -> appViewModel.countCookFood(cookMode = 1) { count ->
if (count > 0) { if (count > 0) {
//有烹饪中数据打开采样历史列表页面 //有烹饪中数据打开采样历史列表页面
startActivity<SamplingListActivity>() startActivity<SamplingListActivity>()
finish() // finish()
return@countCookFood return@countCookFood
} }
//无烹饪数据打开新增采样页面 //无烹饪数据打开新增采样页面
startActivity<DishSamplingActivity> { startActivity<DishSamplingActivity> {
putExtra(DishSamplingActivity.PAGE_FROM, DishSamplingActivity.HOME) putExtra(DishSamplingActivity.PAGE_FROM, DishSamplingActivity.HOME)
} }
finish() // finish()
} }
} }
} }
@@ -166,7 +171,7 @@ class InitActivity : BaseActivity() {
} }
private fun getDeviceConfig() { private fun getDeviceConfig() {
val tokenUrl = "${UrlConfig.DEVICE_TOKEN}?qrcodeId=${BaseApp.deviceId}&appVersion=1" val tokenUrl = "${UrlConfig.DEVICE_TOKEN}?qrcodeId=${BaseApp.deviceId}&appVersion=${BaseApp.appVersion}"
HttpUtil.get(url = tokenUrl, doSuccess = { token -> HttpUtil.get(url = tokenUrl, doSuccess = { token ->
Log.d(TAG, "initConfig: $token") Log.d(TAG, "initConfig: $token")
getConfig(token.toString()) getConfig(token.toString())
@@ -175,7 +180,7 @@ class InitActivity : BaseActivity() {
}) })
} }
private fun getConfig(token: String) { private fun getConfig(token: String) {
val deviceConfigUrl = "${UrlConfig.DEVICE_CONFIG}?equipmentCode=${BaseApp.deviceId}&&appVersion=1" val deviceConfigUrl = "${UrlConfig.DEVICE_CONFIG}?equipmentCode=${BaseApp.deviceId}&&appVersion=${BaseApp.appVersion}"
HttpUtil.get(url = deviceConfigUrl, header = mutableMapOf( HttpUtil.get(url = deviceConfigUrl, header = mutableMapOf(
"X-Access-Token" to token "X-Access-Token" to token
), doSuccess = { ), doSuccess = {
@@ -189,7 +194,7 @@ class InitActivity : BaseActivity() {
HttpUtil.loopGetToken = true HttpUtil.loopGetToken = true
SpTool.put(SpTool.DEVICE_CONFIG_CACHE, data) SpTool.put(SpTool.DEVICE_CONFIG_CACHE, data)
startActivity<HomeActivity>() startActivity<HomeActivity>()
finish() // finish()
}, doFailure = { code, msg -> }, doFailure = { code, msg ->
Log.d(TAG, "getDeviceConfig: $code,$msg") Log.d(TAG, "getDeviceConfig: $code,$msg")
toast("初始化设备失败,请稍后重试,code=${code},msg=${msg}") toast("初始化设备失败,请稍后重试,code=${code},msg=${msg}")
@@ -214,4 +219,9 @@ class InitActivity : BaseActivity() {
return true return true
} }
override fun onDestroy() {
WeightUtil.stopContinuousRead()
super.onDestroy()
}
} }
@@ -96,8 +96,8 @@ class PrepareCookActivity : BaseActivity() {
return@setOnClickListener return@setOnClickListener
} }
} }
val weight = binding.tvDishPartWeight.text.toString().toInt() val weight = binding.tvDishPartWeight.text.toString().toDouble()
if (weight <= 0) { if (weight <= 0.toDouble()) {
toast("食材用量需要大于0") toast("食材用量需要大于0")
return@setOnClickListener return@setOnClickListener
} }
@@ -394,4 +394,15 @@ class SamplingListActivity : BaseActivity() {
) )
} }
private var isVisible = false
override fun onResume() {
super.onResume()
isVisible = true
}
override fun onPause() {
super.onPause()
isVisible = false
}
} }
@@ -191,4 +191,15 @@ class SelectDishActivity : BaseActivity() {
// dialog = toast("不允许返回操作") // dialog = toast("不允许返回操作")
} }
private var isVisible = false
override fun onResume() {
super.onResume()
isVisible = true
}
override fun onPause() {
super.onPause()
isVisible = false
}
} }
@@ -27,6 +27,7 @@ import com.shuwei.dish.match.utils.AddressUtil
import com.shuwei.dish.match.utils.WeightUtil import com.shuwei.dish.match.utils.WeightUtil
import com.shuwei.dish.match.utils.ext.clickWithDebounce import com.shuwei.dish.match.utils.ext.clickWithDebounce
import com.shuwei.dish.match.utils.ext.gone import com.shuwei.dish.match.utils.ext.gone
import com.shuwei.dish.match.utils.ext.roundedOneDecimalPlace
import com.shuwei.dish.match.utils.ext.startActivity import com.shuwei.dish.match.utils.ext.startActivity
import com.shuwei.dish.match.utils.ext.toJsonString import com.shuwei.dish.match.utils.ext.toJsonString
import com.shuwei.dish.match.utils.ext.toType import com.shuwei.dish.match.utils.ext.toType
@@ -151,9 +152,7 @@ class SubmitFoodActivity : BaseActivity() {
} }
private val firstGoodsArray by lazy { private val firstGoodsArray = SparseArray<Double>()
SparseArray<Int>()
}
private fun addViewListener() { private fun addViewListener() {
addWeightListener() addWeightListener()
@@ -187,7 +186,7 @@ class SubmitFoodActivity : BaseActivity() {
return@addWeightListener return@addWeightListener
} }
var realUseWeight = firstWeight - weight var realUseWeight = firstWeight - weight
realUseWeight = if (realUseWeight > 0) realUseWeight else 0 realUseWeight = if (realUseWeight > 0) realUseWeight else 0.0
seasoningArray.put(address, realUseWeight.toDouble()) seasoningArray.put(address, realUseWeight.toDouble())
// refreshSeasoningWeight() // refreshSeasoningWeight()
@@ -195,7 +194,7 @@ class SubmitFoodActivity : BaseActivity() {
val item = seasoningItems.firstOrNull { address == addressArray[it.sort]} val item = seasoningItems.firstOrNull { address == addressArray[it.sort]}
item?.let { item?.let {
val lastWeight = seasoningArray.get(address) ?: 0.toDouble() val lastWeight = seasoningArray.get(address) ?: 0.toDouble()
it.useWeight = lastWeight + getCookingSeasoning(address) it.useWeight = (lastWeight + getCookingSeasoning(address)).roundedOneDecimalPlace()
updateGridData(it) updateGridData(it)
} }
}) })
@@ -419,7 +418,10 @@ class SubmitFoodActivity : BaseActivity() {
seasoningItems.clear() seasoningItems.clear()
seasoningItems.addAll(list) seasoningItems.addAll(list)
initConfigData() initConfigData()
setGridData(list) // setGridData(list)
list.forEach { entity ->
updateGridData(entity.also { it.useWeight = 0.0 })
}
seasoningCookingItems = seasoningItems.map { it.copy() }.toList() seasoningCookingItems = seasoningItems.map { it.copy() }.toList()
} }
@@ -55,6 +55,9 @@ class DishListFragment : BaseFragment<FragmentDishListBinding>() {
DishShowAdapter(list = list).apply { DishShowAdapter(list = list).apply {
isStateViewEnable = true isStateViewEnable = true
setOnDebouncedItemClick { adapter, view, position -> setOnDebouncedItemClick { adapter, view, position ->
if (isAdded.not() || isVisible.not()) {
return@setOnDebouncedItemClick
}
activity.judgeDeviceConfig { activity.judgeDeviceConfig {
onItemClick(position) onItemClick(position)
} }
@@ -0,0 +1,425 @@
package com.shuwei.dish.match.utils;
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//
//
//package com.aithings;
import android.os.Build;
import android.util.Log;
import com.blankj.utilcode.util.Utils;
import com.t507.System;
import com.wabon.wbintelligenthardwaresdk.api.SensorScale;
import com.wabon.wbintelligenthardwaresdk.interf.CheckPortListener;
public class Weigher2 {
private static final String TAG = Weigher2.class.getSimpleName();
public static final int STATE_OVER_WEIGHT = 2;
public static final int STATE_STABLE = 1;
public static final int STATE_UNSTABLE = 0;
public static final int ERR_001 = 1001;
public static final int ERR_002 = 1002;
public static final int ERR_003 = 1003;
public static final int ERR_004 = 1004;
public static final int ERR_PCB_NOT_SUPPORT = 2000;
private static SensorScale mSensorScale;
private static String mDevicePort = "/dev/ttyS4";
private static boolean mConnect = false;
private static Listener mListener;
public static void init() {
String var0;
if ((var0 = Build.MODEL) == "pcb_941") {
Log.w(TAG, "pcb not support, " + var0);
Listener var1;
if ((var1 = mListener) != null) {
var1.onFail(2000);
}
} else {
System.init();
initScale();
if (var0 == "pcb_908") {
mDevicePort = "/dev/ttyS4";
}
mSensorScale.openScale(mDevicePort, 115200, (open) -> {
mConnect = open;
Log.d(TAG, "init " + mConnect);
Utils.runOnUiThread(new Runnable() {
public void run() {
if (Weigher2.mListener != null) {
Weigher2.mListener.onInit(Weigher2.mConnect);
}
}
});
});
}
}
public static void unInit() {
// $FF: Couldn't be decompiled
}
public static void config() {
String var0;
if ((var0 = Build.MODEL) == "pcb_941") {
Log.w(TAG, "pcb not support, " + var0);
Listener var2;
if ((var2 = mListener) != null) {
var2.onFail(2000);
}
} else {
System.init();
initScale();
SensorScale var10000 = mSensorScale;
String var10001 = mDevicePort;
CheckPortListener var1 = (open) -> {
};
var10000.config(var10001, 115200, 5000L, var1);
}
}
public static boolean zero() {
mSensorScale.zero(() -> {
Log.d(TAG, "zero ok");
Utils.runOnUiThread(new Runnable() {
public void run() {
if (Weigher2.mListener != null) {
Weigher2.mListener.onZero();
}
}
});
});
return true;
}
public static boolean zeroTwo(int address) {
mSensorScale.zeroTwo(() -> {
Log.d(TAG, "zero ok");
Utils.runOnUiThread(new Runnable() {
public void run() {
if (Weigher2.mListener != null) {
Weigher2.mListener.onZero();
}
}
});
}, address);
return true;
}
public static boolean readParam() {
mSensorScale.readParam(() -> {
Log.d(TAG, "read param ok");
Utils.runOnUiThread(new Runnable() {
public void run() {
if (Weigher2.mListener != null) {
Weigher2.mListener.onReadParam();
}
}
});
});
return true;
}
public static boolean readParamTwo(int address) {
mSensorScale.readParamTwo(() -> {
Log.d(TAG, "read param ok");
Utils.runOnUiThread(new Runnable() {
public void run() {
if (Weigher2.mListener != null) {
Weigher2.mListener.onReadParam();
}
}
});
}, address);
return true;
}
public static boolean rangeCal() {
mSensorScale.rangeCalibration(() -> {
Log.d(TAG, "rang cal ok");
Utils.runOnUiThread(new Runnable() {
public void run() {
if (Weigher2.mListener != null) {
Weigher2.mListener.onRangCal();
}
}
});
});
return true;
}
public static boolean rangeCalValue(int value) {
mSensorScale.rangeCalibrationValue(value, () -> {
Log.d(TAG, "rang cal val ok");
Utils.runOnUiThread(new Runnable() {
public void run() {
if (Weigher2.mListener != null) {
Weigher2.mListener.onRangCal();
}
}
});
});
return true;
}
public static boolean rangeCalValueTwo(int value, int address) {
mSensorScale.rangeCalibrationValueTwo(value, () -> {
Log.d(TAG, "rang cal val ok");
Utils.runOnUiThread(new Runnable() {
public void run() {
if (Weigher2.mListener != null) {
Weigher2.mListener.onRangCal();
}
}
});
}, address);
return true;
}
public static void getWeight() {
mSensorScale.readWeight();
}
public static void startContinuousRead() {
mSensorScale.startContinuousRead();
}
public static void stopContinuousRead() {
mSensorScale.stopContinuousRead();
}
public static void tare() {
mSensorScale.tare(() -> {
Log.d(TAG, "tare ok");
Utils.runOnUiThread(new Runnable() {
public void run() {
if (Weigher2.mListener != null) {
Weigher2.mListener.onTare();
}
}
});
});
}
public static void tareTwo(int address) {
mSensorScale.tareTwo(() -> {
Log.d(TAG, "tare ok");
Utils.runOnUiThread(new Runnable() {
public void run() {
if (Weigher2.mListener != null) {
Weigher2.mListener.onTare();
}
}
});
}, address);
}
public static void readIdentify() {
mSensorScale.readIdentify();
}
public static void readIdentifyTwo(int address) {
mSensorScale.readIdentifyTwo(address);
}
public static void fastFilter() {
mSensorScale.fastFilter(() -> {
Log.d(TAG, "fast filter ok");
Utils.runOnUiThread(new Runnable() {
public void run() {
if (Weigher2.mListener != null) {
Weigher2.mListener.onFastFilter();
}
}
});
}, 0);
}
public static void fastFilter(int speed) {
mSensorScale.fastFilter(() -> {
Log.d(TAG, "fast filter ok");
Utils.runOnUiThread(new Runnable() {
public void run() {
if (Weigher2.mListener != null) {
Weigher2.mListener.onFastFilter();
}
}
});
}, speed);
}
public static void fastFilterTwo(int address) {
mSensorScale.fastFilterTwo(() -> {
Log.d(TAG, "fast filter ok");
Utils.runOnUiThread(new Runnable() {
public void run() {
if (Weigher2.mListener != null) {
Weigher2.mListener.onFastFilter();
}
}
});
}, address, 0);
}
public static void fastFilterTwo(int address, int speed) {
mSensorScale.fastFilterTwo(() -> {
Log.d(TAG, "fast filter ok");
Utils.runOnUiThread(new Runnable() {
public void run() {
if (Weigher2.mListener != null) {
Weigher2.mListener.onFastFilter();
}
}
});
}, address, speed);
}
public static void setParam(int address, int division, int speed, int maxWeight) {
mSensorScale.setParam(() -> {
Log.d(TAG, "setParam ok");
Utils.runOnUiThread(new Runnable() {
public void run() {
if (Weigher2.mListener != null) {
Weigher2.mListener.onSetParam();
}
}
});
}, address, division, speed, maxWeight);
}
public static void setParam(int division, int speed, int maxWeight) {
mSensorScale.setParam(() -> {
Log.d(TAG, "setParam ok");
Utils.runOnUiThread(new Runnable() {
public void run() {
if (Weigher2.mListener != null) {
Weigher2.mListener.onSetParam();
}
}
});
}, division, speed, maxWeight);
}
public static void setIdentify(int rate) {
mSensorScale.setIdentify(rate, () -> {
Log.d(TAG, "setIdentify ok");
Utils.runOnUiThread(new Runnable() {
public void run() {
if (Weigher2.mListener != null) {
Weigher2.mListener.onSetIdentify();
}
}
});
});
}
public static void setIdentifyTwo(int rate, int address) {
mSensorScale.setIdentifyTwo(rate, () -> {
Log.d(TAG, "setIdentify ok");
Utils.runOnUiThread(new Runnable() {
public void run() {
if (Weigher2.mListener != null) {
Weigher2.mListener.onSetIdentify();
}
}
});
}, address);
}
public static void setListener(Listener listener) {
mListener = listener;
}
private static void initScale() {
SensorScale.OnScaleResult var0;
var0 = new SensorScale.OnScaleResult() {
public void readWeight(final int address, final int state, double value) {
if (SensorScale.isLog) {
Log.d(Weigher2.TAG, "readWeight, address=" + address + ", value=" + value);
}
// final int weight = (int)(value * (double)1000.0F);
Utils.runOnUiThread(new Runnable() {
public void run() {
if (Weigher2.mListener != null) {
Weigher2.mListener.onGetWeight(address, state, value);
}
}
});
}
public void readIdentify(final int rate) {
Utils.runOnUiThread(new Runnable() {
public void run() {
if (Weigher2.mListener != null) {
Weigher2.mListener.onReadIdentify(rate);
}
}
});
}
public void fail(int errCode) {
if (Weigher2.mListener != null) {
Weigher2.mListener.onFail(errCode);
}
}
};
//.<init>();
mSensorScale = new SensorScale(var0);
}
public static void setNoPull485Pin(boolean noPull) {
SensorScale.no485Pin = noPull;
}
public interface Listener {
void onInit(boolean var1);
void onZero();
void onTare();
void onSetIdentify();
// void onGetWeight(int var1, int var2, int var3);
void onGetWeight(int var1, int var2, double var3);
void onReadIdentify(int var1);
void onFail(int var1);
void onFastFilter();
void onReadParam();
void onRangCal();
void onSetParam();
}
}
@@ -4,27 +4,39 @@ import android.os.Build
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 com.aithings.Weigher import com.shuwei.dish.match.utils.ext.roundedOneDecimalPlace
//import com.aithings.Weigher
import com.wabon.wbintelligenthardwaresdk.api.SensorScale import com.wabon.wbintelligenthardwaresdk.api.SensorScale
typealias WeightCallback = (address: Int, state: Int, weight: Double) -> Unit
object WeightUtil { object WeightUtil {
private const val TAG = "WeightUtil"
var isConnected = false var isConnected = false
var weightFuncMap: MutableMap<String, ((address: Int, state: Int, weight: Int) -> Unit)?>? = null var weightFuncMap: MutableMap<String, WeightCallback?>? =
null
fun init() { fun init() {
Weigher.init() Weigher2.init()
Weigher2.setListener(object : WeightListenerImpl() {
Weigher.setListener(object : WeightListenerImpl() {
override fun onInit(connect: Boolean) { override fun onInit(connect: Boolean) {
super.onInit(connect) super.onInit(connect)
isConnected = connect isConnected = connect
} }
override fun onGetWeight(address: Int, state: Int, weight: Int) { override fun onGetWeight(address: Int, state: Int, weight: Double) {
super.onGetWeight(address, state, weight) super.onGetWeight(address, state, weight)
val stateStr = when (state) {
SensorScale.STATE_STABLE -> "稳定"
SensorScale.STATE_UNSTABLE -> "不稳定"
SensorScale.STATE_OVER_WEIGHT -> "量程溢出"
else -> "$state"
}
val useWeight = (weight*1000).roundedOneDecimalPlace()
Log.d(TAG, "readWeight, address=$address,state=$stateStr, weight=$useWeight")
weightFuncMap?.forEach { (key, value) -> weightFuncMap?.forEach { (key, value) ->
value?.invoke(address, state, weight) value?.invoke(address, state, useWeight)
} }
} }
@@ -32,15 +44,24 @@ object WeightUtil {
} }
fun getWeight() { fun getWeight() {
Weigher.getWeight() Weigher2.getWeight()
} }
fun startContinuousRead() { fun startContinuousRead() {
Weigher.startContinuousRead() Weigher2.startContinuousRead()
}
fun stopContinuousRead() {
try {
Weigher2.stopContinuousRead()
Weigher2.unInit()
} catch (e: Exception) {
e.printStackTrace()
}
} }
fun tareTwo(address: Int) { fun tareTwo(address: Int) {
Weigher.tareTwo(address) Weigher2.tareTwo(address)
} }
private fun runOnUiThread(action: () -> Unit) { private fun runOnUiThread(action: () -> Unit) {
@@ -50,8 +71,8 @@ object WeightUtil {
} }
fun addWeightListener( fun addWeightListener(
weightKey:String, weightKey: String,
getWeight: ((address: Int, state: Int, weight: Int) -> Unit) = { _, _, _ -> } getWeight: WeightCallback = { _, _, _ -> }
) { ) {
if (weightFuncMap == null) { if (weightFuncMap == null) {
weightFuncMap = mutableMapOf() weightFuncMap = mutableMapOf()
@@ -60,7 +81,7 @@ object WeightUtil {
} }
} }
open class WeightListenerImpl : Weigher.Listener { open class WeightListenerImpl : Weigher2.Listener {
override fun onInit(connect: Boolean) { override fun onInit(connect: Boolean) {
Log.d("WeightUtil", "connect=$connect") Log.d("WeightUtil", "connect=$connect")
} }
@@ -77,15 +98,15 @@ open class WeightListenerImpl : Weigher.Listener {
Log.d("WeightUtil", "鉴别率设置操作成功") Log.d("WeightUtil", "鉴别率设置操作成功")
} }
override fun onGetWeight(address: Int, state: Int, weight: Int) { override fun onGetWeight(address: Int, state: Int, weight: Double) {
val stateStr = when (state) { // val stateStr = when (state) {
SensorScale.STATE_STABLE -> "稳定" // SensorScale.STATE_STABLE -> "稳定"
SensorScale.STATE_UNSTABLE -> "不稳定" // SensorScale.STATE_UNSTABLE -> "不稳定"
SensorScale.STATE_OVER_WEIGHT -> "量程溢出" // SensorScale.STATE_OVER_WEIGHT -> "量程溢出"
else -> "" // else -> ""
} // }
val result1 = String.format("$stateStr 重量:%s kg", weight / 1000f) // val result1 = String.format("$stateStr 重量:%s kg", weight / 1000f)
Log.d("WeightUtil", "ttlReturn, address:$address,$result1") // Log.d("WeightUtil", "ttlReturn, address:$address,$result1")
} }
override fun onReadIdentify(rate: Int) { override fun onReadIdentify(rate: Int) {
@@ -94,11 +115,11 @@ open class WeightListenerImpl : Weigher.Listener {
override fun onFail(errCode: Int) { override fun onFail(errCode: Int) {
val str = when (errCode) { val str = when (errCode) {
Weigher.ERR_001 -> "电子称未初始化" Weigher2.ERR_001 -> "电子称未初始化"
Weigher.ERR_002 -> "开机零位异常" Weigher2.ERR_002 -> "开机零位异常"
Weigher.ERR_003 -> "传感器故障" Weigher2.ERR_003 -> "传感器故障"
Weigher.ERR_004 -> "鉴别率超出范围" Weigher2.ERR_004 -> "鉴别率超出范围"
Weigher.ERR_PCB_NOT_SUPPORT -> "主板不支持, " + Build.MODEL Weigher2.ERR_PCB_NOT_SUPPORT -> "主板不支持, " + Build.MODEL
else -> "" else -> ""
} }
Log.d("WeightUtil", str) Log.d("WeightUtil", str)
@@ -22,6 +22,8 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job import kotlinx.coroutines.Job
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import java.math.BigDecimal
import java.math.RoundingMode
fun Context.toast( fun Context.toast(
message: String?, message: String?,
@@ -173,3 +175,7 @@ fun View.clickWithDebounce(delay: Long = 300, action: () -> Unit) {
} }
} }
} }
fun Double.roundedOneDecimalPlace(): Double {
return BigDecimal(this).setScale(1, RoundingMode.HALF_UP).toDouble()
}
@@ -150,16 +150,15 @@ class AppViewModel(private val rep: AppRepository) : ViewModel() {
// } // }
private var isProcessing = false private var isProcessing = false
fun loadSeasoning(action: (list: MutableList<SeasoningEntity>) -> Unit) { fun loadSeasoning(action: (MutableList<SeasoningEntity>) -> Unit) {
viewModelScope.launch { viewModelScope.launch {
if (isProcessing) return@launch if (isProcessing) return@launch
isProcessing = true isProcessing = true
rep.getAllStream().collect { list -> val list = rep.getAllStream()
action(list) action(list)
isProcessing = false isProcessing = false
} }
} }
}
fun deleteSeasoningBySort(sort: Int) { fun deleteSeasoningBySort(sort: Int) {
viewModelScope.launch { viewModelScope.launch {
@@ -197,7 +196,8 @@ class AppViewModel(private val rep: AppRepository) : ViewModel() {
} }
} }
entity.id = 0 entity.id = 0
rep.insertSeasoning(entity) val id = rep.insertSeasoning(entity)
entity.id = id
block() block()
} }
} }
+6 -2
View File
@@ -6,8 +6,12 @@
<solid android:color="@color/bg_color"/> <solid android:color="@color/bg_color"/>
</shape> </shape>
</item> </item>
<item android:gravity="top" android:width="828dp" android:height="414dp"> <item
<bitmap android:src="@drawable/bg_home_page"/> android:width="450dp"
android:height="430dp"
android:gravity="top|center_horizontal"
android:top="250dp">
<bitmap android:src="@drawable/img_init" android:scaleType="fitCenter"/>
</item> </item>
</layer-list> </layer-list>
+1 -1
View File
@@ -4,7 +4,7 @@
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" android:layout_height="match_parent"
android:background="@color/bg_color"> tools:background="@color/bg_color">
<ImageView <ImageView
android:id="@+id/ivHeaderBg" android:id="@+id/ivHeaderBg"
+4 -3
View File
@@ -7,14 +7,15 @@
android:orientation="vertical"> android:orientation="vertical">
<ImageView <ImageView
android:layout_width="500dp" android:layout_width="450dp"
android:layout_height="500dp" android:layout_height="430dp"
android:layout_marginStart="50dp" android:layout_marginStart="50dp"
android:layout_marginTop="250dp" android:layout_marginTop="250dp"
android:layout_marginEnd="50dp" android:layout_marginEnd="50dp"
android:layout_gravity="center_horizontal" android:layout_gravity="center_horizontal"
android:src="@drawable/img_init" android:src="@drawable/img_init"
tools:ignore="ContentDescription" /> tools:ignore="ContentDescription"
android:visibility="invisible"/>
<TextView <TextView
android:id="@+id/btnInit" android:id="@+id/btnInit"