调整了个人营养数据计算逻辑,修复了摄像头逻辑

This commit is contained in:
zxj
2025-08-07 10:49:50 +08:00
parent 561a2fc9b2
commit 71ce668e3c
9 changed files with 283 additions and 164 deletions
@@ -8,6 +8,7 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.inputmethod.EditorInfo
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.GridLayoutManager
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
@@ -30,6 +31,7 @@ class CustomBottomSheetDialog(
private lateinit var binding: BottomSheetDialogBinding
private lateinit var adapter: GenericItemAdapter<FoodInfo, ItemSearchFoodInfoBinding>
private var checkedItem: FoodInfo? = null
private val debouncer = Debouncer(2000)
override fun onCreateView(
inflater: LayoutInflater,
@@ -42,13 +44,8 @@ class CustomBottomSheetDialog(
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val debouncer = Debouncer(3000)
initView()
binding.ivSearch.setOnClickListener {
debouncer.debounce {
viewModel.searchByFoodName(binding.etSearch.text.toString())
}
}
}
override fun onCreate(savedInstanceState: Bundle?) {
@@ -95,9 +92,26 @@ class CustomBottomSheetDialog(
)
)
binding.recyclerview.adapter = adapter
binding.ivSearch.setOnClickListener {
searchInfo()
}
binding.etSearch.setOnEditorActionListener { _, actionId, _ ->
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
searchInfo()
true
} else {
false
}
}
registerDataChange()
}
private fun searchInfo(){
debouncer.debounce {
viewModel.searchByFoodName(binding.etSearch.text.toString())
}
}
private fun registerDataChange() {
lifecycleScope.launch {
viewModel.searchFoodInfoList.collect {
@@ -15,6 +15,8 @@ import android.view.animation.AlphaAnimation;
import com.sw.dualscreen.R;
import com.sw.plate.utils.AppUtil;
import timber.log.Timber;
public class CustomImageView extends androidx.appcompat.widget.AppCompatImageView {
private AlphaAnimation alphaAnimation;
private String textToDraw;
@@ -95,16 +97,21 @@ public class CustomImageView extends androidx.appcompat.widget.AppCompatImageVie
}
public void setCustomHeightPercent(float percent, boolean isAnimation) {
// if (percent<= 0){
// percent = 0.01f;
// }
setCustomHeight((int) (percent * MAX_HEIGHT), isAnimation);
Timber.d("setCustomHeightPercent percent = %s", percent);
if (percent<= 0){
percent = 0f;
}
setCustomHeight((int) (percent * MAX_HEIGHT), false);
}
// 用于设置自定义高度的方法
public void setCustomHeight(int height, boolean isAnimation) {
Timber.d("setCustomHeight height = %s", height);
if (height > 0) {
height += 40;
height += 30;
}
if (height > MAX_HEIGHT){
height = MAX_HEIGHT;
}
ViewGroup.LayoutParams layoutParams = getLayoutParams();
int height1 = layoutParams.height;