修复了多次步骤2到步骤3问题
This commit is contained in:
Generated
+1
-1
@@ -4,7 +4,7 @@
|
|||||||
<selectionStates>
|
<selectionStates>
|
||||||
<SelectionState runConfigName="app">
|
<SelectionState runConfigName="app">
|
||||||
<option name="selectionMode" value="DROPDOWN" />
|
<option name="selectionMode" value="DROPDOWN" />
|
||||||
<DropdownSelection timestamp="2025-07-31T00:35:57.879961400Z">
|
<DropdownSelection timestamp="2025-08-05T03:50:06.075639Z">
|
||||||
<Target type="DEFAULT_BOOT">
|
<Target type="DEFAULT_BOOT">
|
||||||
<handle>
|
<handle>
|
||||||
<DeviceId pluginId="PhysicalDevice" identifier="serial=2FD2511004054749" />
|
<DeviceId pluginId="PhysicalDevice" identifier="serial=2FD2511004054749" />
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import android.content.Context
|
|||||||
import android.graphics.Outline
|
import android.graphics.Outline
|
||||||
import android.graphics.Typeface
|
import android.graphics.Typeface
|
||||||
import android.hardware.display.DisplayManager
|
import android.hardware.display.DisplayManager
|
||||||
|
import android.net.Uri
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewOutlineProvider
|
import android.view.ViewOutlineProvider
|
||||||
@@ -54,7 +55,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
private var checkedItem: FoodInfo? = null
|
private var checkedItem: FoodInfo? = null
|
||||||
private var imageAnalysis: ImageAnalysis? = null
|
private var imageAnalysis: ImageAnalysis? = null
|
||||||
private var cameraProviderFuture: ListenableFuture<ProcessCameraProvider>? = null
|
private var cameraProviderFuture: ListenableFuture<ProcessCameraProvider>? = null
|
||||||
private var canIdentify: Boolean = true
|
private var canIdentify: Boolean = false
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
@@ -132,8 +133,8 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun updateCurrentFood(foodInfo: FoodInfo?) {
|
fun updateCurrentFood(foodInfo: FoodInfo?) {
|
||||||
presentation.updateFood(foodInfo)
|
|
||||||
if (foodInfo != null) {
|
if (foodInfo != null) {
|
||||||
|
presentation.updateFood(foodInfo)
|
||||||
binding.tvFoodName.text = foodInfo.foodName
|
binding.tvFoodName.text = foodInfo.foodName
|
||||||
binding.previewView.visibility = View.GONE
|
binding.previewView.visibility = View.GONE
|
||||||
binding.ivImg.visibility = View.VISIBLE
|
binding.ivImg.visibility = View.VISIBLE
|
||||||
@@ -156,7 +157,6 @@ class MainActivity : AppCompatActivity() {
|
|||||||
// presentation.step2()
|
// presentation.step2()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
viewModel.getIdentifiedFoodList()
|
|
||||||
SensorScaleUtils.startScale { weight ->
|
SensorScaleUtils.startScale { weight ->
|
||||||
// Timber.d("weight = $weight")
|
// Timber.d("weight = $weight")
|
||||||
if (weight > 0.0) {
|
if (weight > 0.0) {
|
||||||
@@ -289,7 +289,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 拍照功能
|
// 拍照功能
|
||||||
private fun takePhoto() {
|
private fun takePhoto(callback: (Uri) -> Unit) {
|
||||||
// 临时停止分析以避免干扰
|
// 临时停止分析以避免干扰
|
||||||
isAnalyzing = false
|
isAnalyzing = false
|
||||||
|
|
||||||
@@ -306,7 +306,11 @@ class MainActivity : AppCompatActivity() {
|
|||||||
object : ImageCapture.OnImageSavedCallback {
|
object : ImageCapture.OnImageSavedCallback {
|
||||||
override fun onImageSaved(outputFileResults: ImageCapture.OutputFileResults) {
|
override fun onImageSaved(outputFileResults: ImageCapture.OutputFileResults) {
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
ToastUtils.showToast("照片保存成功: ${outputFileResults.savedUri}")
|
val savedUri = outputFileResults.savedUri
|
||||||
|
ToastUtils.showToast("照片保存成功: $savedUri")
|
||||||
|
if (savedUri != null) {
|
||||||
|
callback(savedUri)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// 恢复图像分析
|
// 恢复图像分析
|
||||||
isAnalyzing = true
|
isAnalyzing = true
|
||||||
|
|||||||
@@ -75,10 +75,15 @@ class SecondaryScreenPresentation(
|
|||||||
|
|
||||||
// 当前食物信息
|
// 当前食物信息
|
||||||
private var currentFood: FoodInfo? = null
|
private var currentFood: FoodInfo? = null
|
||||||
|
private var lastFood: FoodInfo? = null
|
||||||
private var userNutritionData: UserNutritionData? = null
|
private var userNutritionData: UserNutritionData? = null
|
||||||
private var dinnerType: DinnerTypeInfo? = null
|
private var dinnerType: DinnerTypeInfo? = null
|
||||||
private lateinit var itemUserNutritionBinding: ItemUserNutritionBinding
|
private lateinit var itemUserNutritionBinding: ItemUserNutritionBinding
|
||||||
private lateinit var stepChangeCallback: (Int) -> Unit
|
private lateinit var stepChangeCallback: (Int) -> Unit
|
||||||
|
private var lastCalcResultInfo: UserNutritionUtils.CalcResultInfo? = null
|
||||||
|
private var startSensorScale: Boolean = false
|
||||||
|
private var lastWeight = 0.0
|
||||||
|
private val debouncer = Debouncer(1000)
|
||||||
|
|
||||||
// 当前步骤
|
// 当前步骤
|
||||||
var currentStep: Int = 0
|
var currentStep: Int = 0
|
||||||
@@ -90,6 +95,7 @@ class SecondaryScreenPresentation(
|
|||||||
setContentView(binding.root)
|
setContentView(binding.root)
|
||||||
window?.setBackgroundDrawableResource(android.R.color.transparent)
|
window?.setBackgroundDrawableResource(android.R.color.transparent)
|
||||||
initView()
|
initView()
|
||||||
|
setupArcCamera()
|
||||||
// binding.includeUserHeat.ivHeat.showText("1070千卡")
|
// binding.includeUserHeat.ivHeat.showText("1070千卡")
|
||||||
registerDataChange()
|
registerDataChange()
|
||||||
}
|
}
|
||||||
@@ -138,22 +144,9 @@ class SecondaryScreenPresentation(
|
|||||||
* 启用虹软人脸失败
|
* 启用虹软人脸失败
|
||||||
*/
|
*/
|
||||||
private fun setupArcCamera() {
|
private fun setupArcCamera() {
|
||||||
cameraManager = context.getSystemService(Context.CAMERA_SERVICE) as CameraManager
|
|
||||||
// 获取摄像头列表
|
|
||||||
cameraIdList = cameraManager.cameraIdList
|
|
||||||
if (cameraIdList.isEmpty()) {
|
|
||||||
Toast.makeText(context, "没有可用的摄像头", Toast.LENGTH_SHORT).show()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
cameraIdList.forEach {
|
|
||||||
Timber.d("摄像头id列表 = ${it}")
|
|
||||||
}
|
|
||||||
|
|
||||||
initArcViewModel()
|
initArcViewModel()
|
||||||
initArcView()
|
initArcView()
|
||||||
openRectInfoDraw = true
|
openRectInfoDraw = true
|
||||||
openCamera(cameraIdList.last())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -167,9 +160,8 @@ class SecondaryScreenPresentation(
|
|||||||
binding.ivFaceBg.visibility = View.GONE
|
binding.ivFaceBg.visibility = View.GONE
|
||||||
binding.flPreview.visibility = View.VISIBLE
|
binding.flPreview.visibility = View.VISIBLE
|
||||||
binding.ivImg.visibility = View.VISIBLE
|
binding.ivImg.visibility = View.VISIBLE
|
||||||
binding.flFace.visibility = View.GONE
|
binding.flFace.visibility = View.INVISIBLE
|
||||||
pauseCamera()
|
pauseCamera()
|
||||||
|
|
||||||
binding.tvBottomTip.visibility = View.VISIBLE
|
binding.tvBottomTip.visibility = View.VISIBLE
|
||||||
itemUserNutritionBinding.clNutritionData.visibility = View.GONE
|
itemUserNutritionBinding.clNutritionData.visibility = View.GONE
|
||||||
stopSensorScale()
|
stopSensorScale()
|
||||||
@@ -186,25 +178,31 @@ class SecondaryScreenPresentation(
|
|||||||
currentFood = foodInfo
|
currentFood = foodInfo
|
||||||
resumeCamera()
|
resumeCamera()
|
||||||
binding.tvFoodInfo.text = foodInfo.foodName
|
binding.tvFoodInfo.text = foodInfo.foodName
|
||||||
|
binding.ivImg.visibility = View.GONE
|
||||||
|
|
||||||
binding.ivFaceBg.visibility = View.VISIBLE
|
|
||||||
binding.flPreview.visibility = View.GONE
|
binding.flPreview.visibility = View.GONE
|
||||||
|
|
||||||
binding.flFace.visibility = View.VISIBLE
|
binding.flFace.visibility = View.VISIBLE
|
||||||
binding.ivFaceBg.visibility = View.VISIBLE
|
binding.ivFaceBg.visibility = View.VISIBLE
|
||||||
binding.tvFaceTip.visibility = View.VISIBLE
|
binding.tvFaceTip.visibility = View.VISIBLE
|
||||||
|
binding.tvBottomTip.visibility = View.VISIBLE
|
||||||
setupArcCamera()
|
itemUserNutritionBinding.clNutritionData.visibility = View.GONE
|
||||||
}
|
}
|
||||||
|
|
||||||
fun updateFood(foodInfo: FoodInfo?) {
|
fun updateFood(foodInfo: FoodInfo?) {
|
||||||
Timber.d("step2 updateFood")
|
Timber.d("updateFood")
|
||||||
currentFood = foodInfo
|
currentFood = foodInfo
|
||||||
if (foodInfo != null) {
|
if (foodInfo != null) {
|
||||||
if (currentStep != 2) {
|
if (currentStep == 1) {
|
||||||
step2(foodInfo)
|
step2(foodInfo)
|
||||||
} else {
|
} else {
|
||||||
binding.tvFoodInfo.text = foodInfo.foodName
|
binding.tvFoodInfo.text = foodInfo.foodName
|
||||||
|
GlideUtils.loadRoundCornerImage(
|
||||||
|
context,
|
||||||
|
url = currentFood!!.imgUrl,
|
||||||
|
imageView = binding.ivImg,
|
||||||
|
radius = 12
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -221,7 +219,7 @@ class SecondaryScreenPresentation(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
binding.tvFoodInfo.text = currentFood!!.foodName
|
binding.tvFoodInfo.text = currentFood!!.foodName
|
||||||
|
pauseCamera()
|
||||||
startSensorScale()
|
startSensorScale()
|
||||||
|
|
||||||
GlideUtils.loadRoundCornerImage(
|
GlideUtils.loadRoundCornerImage(
|
||||||
@@ -231,31 +229,36 @@ class SecondaryScreenPresentation(
|
|||||||
radius = 12
|
radius = 12
|
||||||
)
|
)
|
||||||
binding.flPreview.visibility = View.VISIBLE
|
binding.flPreview.visibility = View.VISIBLE
|
||||||
// binding.previewView.visibility = View.GONE
|
|
||||||
binding.ivImg.visibility = View.VISIBLE
|
binding.ivImg.visibility = View.VISIBLE
|
||||||
binding.flFace.visibility = View.GONE
|
binding.flFace.visibility = View.INVISIBLE
|
||||||
binding.ivFaceBg.visibility = View.GONE
|
binding.ivFaceBg.visibility = View.GONE
|
||||||
binding.tvFaceTip.visibility = View.GONE
|
binding.tvFaceTip.visibility = View.GONE
|
||||||
|
|
||||||
binding.tvBottomTip.visibility = View.GONE
|
binding.tvBottomTip.visibility = View.GONE
|
||||||
itemUserNutritionBinding.clNutritionData.visibility = View.VISIBLE
|
itemUserNutritionBinding.clNutritionData.visibility = View.VISIBLE
|
||||||
|
|
||||||
viewModel.getUserNutritionData(
|
|
||||||
userId = userNutritionData!!.userId!!,
|
|
||||||
foodId = currentFood!!.id!!
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun startSensorScale() {
|
private fun startSensorScale() {
|
||||||
var lastWeight = 0.0
|
Timber.d("startSensorScale startSensorScale = $startSensorScale")
|
||||||
val debouncer = Debouncer(1000)
|
if (startSensorScale) return
|
||||||
SensorScaleUtils.startScale { weight ->
|
SensorScaleUtils.startScale { weight ->
|
||||||
if (weight == lastWeight) return@startScale
|
if (currentFood == null) {
|
||||||
|
Timber.e("startSensorScale currentFood is null")
|
||||||
|
return@startScale
|
||||||
|
}
|
||||||
|
if (userNutritionData == null) {
|
||||||
|
Timber.e("startSensorScale userNutritionData is null")
|
||||||
|
return@startScale
|
||||||
|
}
|
||||||
|
if (dinnerType == null) {
|
||||||
|
Timber.e("startSensorScale dinnerType is null")
|
||||||
|
return@startScale
|
||||||
|
}
|
||||||
|
// 重量和 当前食物都没变,则不再计算
|
||||||
|
if (weight == lastWeight && lastFood == currentFood) return@startScale
|
||||||
Timber.d("registerDataChange weight = $weight")
|
Timber.d("registerDataChange weight = $weight")
|
||||||
|
lastFood = currentFood
|
||||||
lastWeight = weight
|
lastWeight = weight
|
||||||
if (currentFood == null) return@startScale
|
|
||||||
if (userNutritionData == null) return@startScale
|
|
||||||
if (dinnerType == null) return@startScale
|
|
||||||
debouncer.debounce {
|
debouncer.debounce {
|
||||||
val calcResultInfo = UserNutritionUtils.calculateNutrition(
|
val calcResultInfo = UserNutritionUtils.calculateNutrition(
|
||||||
currentFood!!,
|
currentFood!!,
|
||||||
@@ -264,11 +267,16 @@ class SecondaryScreenPresentation(
|
|||||||
dinnerType = dinnerType!!.dinnerType!!.dinnerType!!
|
dinnerType = dinnerType!!.dinnerType!!.dinnerType!!
|
||||||
)
|
)
|
||||||
Timber.d("calcResultInfo = $calcResultInfo")
|
Timber.d("calcResultInfo = $calcResultInfo")
|
||||||
|
if (lastCalcResultInfo == calcResultInfo) {
|
||||||
|
return@debounce
|
||||||
|
}
|
||||||
|
lastCalcResultInfo = calcResultInfo
|
||||||
activity.runOnUiThread {
|
activity.runOnUiThread {
|
||||||
val totalKcal = calcResultInfo.totalKcal
|
val totalKcal = calcResultInfo.totalKcal
|
||||||
val grain = calcResultInfo.grain
|
val grain = calcResultInfo.grain
|
||||||
val fruits = calcResultInfo.fruits
|
val fruits = calcResultInfo.fruits
|
||||||
val meat = calcResultInfo.meat
|
val meat = calcResultInfo.meat
|
||||||
|
// 设置热量
|
||||||
itemUserNutritionBinding.customKcalColumn.setImageDrawable(
|
itemUserNutritionBinding.customKcalColumn.setImageDrawable(
|
||||||
true,
|
true,
|
||||||
totalKcal.first < totalKcal.second
|
totalKcal.first < totalKcal.second
|
||||||
@@ -278,7 +286,7 @@ class SecondaryScreenPresentation(
|
|||||||
(totalKcal.second / 100).toFloat(),
|
(totalKcal.second / 100).toFloat(),
|
||||||
true
|
true
|
||||||
)
|
)
|
||||||
|
// 设置主食
|
||||||
itemUserNutritionBinding.customFoodColumn.setImageDrawable(
|
itemUserNutritionBinding.customFoodColumn.setImageDrawable(
|
||||||
false,
|
false,
|
||||||
grain.first < grain.second
|
grain.first < grain.second
|
||||||
@@ -288,7 +296,7 @@ class SecondaryScreenPresentation(
|
|||||||
(grain.second / 100).toFloat(),
|
(grain.second / 100).toFloat(),
|
||||||
true
|
true
|
||||||
)
|
)
|
||||||
|
// 设置果蔬
|
||||||
itemUserNutritionBinding.customVegetableColumn.setImageDrawable(
|
itemUserNutritionBinding.customVegetableColumn.setImageDrawable(
|
||||||
false,
|
false,
|
||||||
fruits.first < fruits.second
|
fruits.first < fruits.second
|
||||||
@@ -298,7 +306,7 @@ class SecondaryScreenPresentation(
|
|||||||
(fruits.second / 100).toFloat(),
|
(fruits.second / 100).toFloat(),
|
||||||
true
|
true
|
||||||
)
|
)
|
||||||
|
// 设置肉蛋
|
||||||
itemUserNutritionBinding.customMeatColumn.setImageDrawable(
|
itemUserNutritionBinding.customMeatColumn.setImageDrawable(
|
||||||
false,
|
false,
|
||||||
meat.first < meat.second
|
meat.first < meat.second
|
||||||
@@ -317,13 +325,28 @@ class SecondaryScreenPresentation(
|
|||||||
SensorScaleUtils.closeScale()
|
SensorScaleUtils.closeScale()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun openCamera(cameraId: String) {
|
private fun openCamera() {
|
||||||
|
Timber.d("openCamera")
|
||||||
if (ContextCompat.checkSelfPermission(context, Manifest.permission.CAMERA) !=
|
if (ContextCompat.checkSelfPermission(context, Manifest.permission.CAMERA) !=
|
||||||
PackageManager.PERMISSION_GRANTED
|
PackageManager.PERMISSION_GRANTED
|
||||||
) {
|
) {
|
||||||
|
ToastUtils.showToast("无摄像头权限")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
cameraManager = context.getSystemService(Context.CAMERA_SERVICE) as CameraManager
|
||||||
|
// 获取摄像头列表
|
||||||
|
cameraIdList = cameraManager.cameraIdList
|
||||||
|
if (cameraIdList.isEmpty()) {
|
||||||
|
Toast.makeText(context, "没有可用的摄像头", Toast.LENGTH_SHORT).show()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
cameraIdList.forEach {
|
||||||
|
Timber.d("摄像头id列表 = $it")
|
||||||
|
}
|
||||||
|
val cameraId = cameraIdList.last()
|
||||||
|
Timber.d("openCamera cameraId = $cameraId")
|
||||||
cameraManager.openCamera(cameraId, object : CameraDevice.StateCallback() {
|
cameraManager.openCamera(cameraId, object : CameraDevice.StateCallback() {
|
||||||
override fun onOpened(device: CameraDevice) {
|
override fun onOpened(device: CameraDevice) {
|
||||||
cameraDevice = device
|
cameraDevice = device
|
||||||
@@ -412,6 +435,7 @@ class SecondaryScreenPresentation(
|
|||||||
recognizeViewModel.recognizeUserId.observe(activity, Observer { userId: String? ->
|
recognizeViewModel.recognizeUserId.observe(activity, Observer { userId: String? ->
|
||||||
Timber.i("recognizeUserId observe userId = $userId")
|
Timber.i("recognizeUserId observe userId = $userId")
|
||||||
if (userId == null) return@Observer
|
if (userId == null) return@Observer
|
||||||
|
|
||||||
viewModel.getUserNutritionData(userId = userId, foodId = currentFood!!.id!!)
|
viewModel.getUserNutritionData(userId = userId, foodId = currentFood!!.id!!)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -599,6 +623,7 @@ class SecondaryScreenPresentation(
|
|||||||
override fun onGlobalLayout() {
|
override fun onGlobalLayout() {
|
||||||
Timber.d("onGlobalLayout")
|
Timber.d("onGlobalLayout")
|
||||||
binding.dualCameraTexturePreviewRgb.getViewTreeObserver().removeOnGlobalLayoutListener(this)
|
binding.dualCameraTexturePreviewRgb.getViewTreeObserver().removeOnGlobalLayoutListener(this)
|
||||||
|
openCamera()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -624,7 +649,7 @@ class SecondaryScreenPresentation(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun resumeCamera() {
|
fun resumeCamera() {
|
||||||
Timber.d("resumeCamera")
|
Timber.d("resumeCamera isRecognition = $isRecognition")
|
||||||
isRecognition = true
|
isRecognition = true
|
||||||
if (rgbCameraHelper != null && rgbCameraHelper!!.isStopped) {
|
if (rgbCameraHelper != null && rgbCameraHelper!!.isStopped) {
|
||||||
rgbCameraHelper!!.start()
|
rgbCameraHelper!!.start()
|
||||||
@@ -632,7 +657,7 @@ class SecondaryScreenPresentation(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun pauseCamera() {
|
fun pauseCamera() {
|
||||||
Timber.d("pauseCamera")
|
Timber.d("pauseCamera isRecognition = $isRecognition")
|
||||||
isRecognition = false
|
isRecognition = false
|
||||||
|
|
||||||
recognizeViewModel.onPreviewFrame(ByteArray(1382400), true)
|
recognizeViewModel.onPreviewFrame(ByteArray(1382400), true)
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ object SensorScaleUtils {
|
|||||||
const val baudRate = 115200
|
const val baudRate = 115200
|
||||||
private var mSensorScale: SensorScale? = null
|
private var mSensorScale: SensorScale? = null
|
||||||
private var isOpened: Boolean = false
|
private var isOpened: Boolean = false
|
||||||
|
private var isRead: Boolean = false
|
||||||
private var callback: Callback? = {}
|
private var callback: Callback? = {}
|
||||||
|
|
||||||
private fun init() {
|
private fun init() {
|
||||||
@@ -58,6 +59,7 @@ object SensorScaleUtils {
|
|||||||
* @param autoScale 是否开启自动读取
|
* @param autoScale 是否开启自动读取
|
||||||
*/
|
*/
|
||||||
fun startScale(autoScale: Boolean = true, callback: Callback?) {
|
fun startScale(autoScale: Boolean = true, callback: Callback?) {
|
||||||
|
Timber.d("startScale isOpened = $isOpened")
|
||||||
if (isOpened) {
|
if (isOpened) {
|
||||||
startContinuousRead(callback = callback)
|
startContinuousRead(callback = callback)
|
||||||
return
|
return
|
||||||
@@ -86,23 +88,24 @@ object SensorScaleUtils {
|
|||||||
* 开启自动读取重量
|
* 开启自动读取重量
|
||||||
*/
|
*/
|
||||||
fun startContinuousRead(callback: Callback?) {
|
fun startContinuousRead(callback: Callback?) {
|
||||||
this.callback = callback
|
Log.d(TAG, "开启自动读取 = $isRead")
|
||||||
Log.d(TAG, "开启自动读取 = $isOpened")
|
if (isRead) {
|
||||||
if (!isOpened) {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
this.callback = callback
|
||||||
mSensorScale?.startContinuousRead()
|
mSensorScale?.startContinuousRead()
|
||||||
|
isRead = true
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 手动读取重量
|
* 手动读取重量
|
||||||
*/
|
*/
|
||||||
fun readWeight(callback: Callback?) {
|
fun readWeight(callback: Callback?) {
|
||||||
this.callback = callback
|
|
||||||
Log.d(TAG, "isOpened = $isOpened")
|
Log.d(TAG, "isOpened = $isOpened")
|
||||||
if (!isOpened) {
|
if (!isOpened) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
this.callback = callback
|
||||||
mSensorScale?.readWeight()
|
mSensorScale?.readWeight()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,6 +140,7 @@ object SensorScaleUtils {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
mSensorScale?.stopContinuousRead()
|
mSensorScale?.stopContinuousRead()
|
||||||
|
isRead = false
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.sw.dualscreen.view
|
package com.sw.dualscreen.view
|
||||||
|
|
||||||
|
import android.content.DialogInterface
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
import android.graphics.Typeface
|
import android.graphics.Typeface
|
||||||
import android.graphics.drawable.ColorDrawable
|
import android.graphics.drawable.ColorDrawable
|
||||||
@@ -82,6 +83,7 @@ class CustomBottomSheetDialog(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun initView() {
|
private fun initView() {
|
||||||
|
binding.viewClose.setOnClickListener { dismiss() }
|
||||||
adapter = createAdapter()
|
adapter = createAdapter()
|
||||||
binding.recyclerview.layoutManager = GridLayoutManager(context, 2)
|
binding.recyclerview.layoutManager = GridLayoutManager(context, 2)
|
||||||
// 添加间距装饰(12dp)
|
// 添加间距装饰(12dp)
|
||||||
@@ -131,7 +133,14 @@ class CustomBottomSheetDialog(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onCancel(dialog: DialogInterface) {
|
||||||
|
Timber.d("onCancel")
|
||||||
|
viewModel.cleanSearchFoodInfoList()
|
||||||
|
super.onCancel(dialog)
|
||||||
|
}
|
||||||
|
|
||||||
override fun dismiss() {
|
override fun dismiss() {
|
||||||
|
Timber.d("dismiss")
|
||||||
viewModel.cleanSearchFoodInfoList()
|
viewModel.cleanSearchFoodInfoList()
|
||||||
super.dismiss()
|
super.dismiss()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -95,11 +95,17 @@ public class CustomImageView extends androidx.appcompat.widget.AppCompatImageVie
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setCustomHeightPercent(float percent, boolean isAnimation) {
|
public void setCustomHeightPercent(float percent, boolean isAnimation) {
|
||||||
|
// if (percent<= 0){
|
||||||
|
// percent = 0.01f;
|
||||||
|
// }
|
||||||
setCustomHeight((int) (percent * MAX_HEIGHT), isAnimation);
|
setCustomHeight((int) (percent * MAX_HEIGHT), isAnimation);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 用于设置自定义高度的方法
|
// 用于设置自定义高度的方法
|
||||||
public void setCustomHeight(int height, boolean isAnimation) {
|
public void setCustomHeight(int height, boolean isAnimation) {
|
||||||
|
if (height > 0) {
|
||||||
|
height += 40;
|
||||||
|
}
|
||||||
ViewGroup.LayoutParams layoutParams = getLayoutParams();
|
ViewGroup.LayoutParams layoutParams = getLayoutParams();
|
||||||
int height1 = layoutParams.height;
|
int height1 = layoutParams.height;
|
||||||
if (height1 != height) {
|
if (height1 != height) {
|
||||||
|
|||||||
@@ -179,6 +179,7 @@ class UserViewModel : BaseViewModel() {
|
|||||||
*/
|
*/
|
||||||
fun getUserNutritionData(userId: String, foodId: String) {
|
fun getUserNutritionData(userId: String, foodId: String) {
|
||||||
Timber.d("getUserNutritionData userId = ${userId}, foodId = $foodId")
|
Timber.d("getUserNutritionData userId = ${userId}, foodId = $foodId")
|
||||||
|
_nutritionData.value = null
|
||||||
launchWithLoading {
|
launchWithLoading {
|
||||||
val response = repository.getUserNutritionData(userId = userId, foodId = foodId)
|
val response = repository.getUserNutritionData(userId = userId, foodId = foodId)
|
||||||
if (parseResponse(response)) {
|
if (parseResponse(response)) {
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
android:paddingBottom="0dp">
|
android:paddingBottom="0dp">
|
||||||
|
|
||||||
<View
|
<View
|
||||||
|
android:id="@+id/view_close"
|
||||||
android:layout_width="90dp"
|
android:layout_width="90dp"
|
||||||
android:layout_height="10dp"
|
android:layout_height="10dp"
|
||||||
android:background="@drawable/view_shape_point" />
|
android:background="@drawable/view_shape_point" />
|
||||||
|
|||||||
Reference in New Issue
Block a user