Compare commits
4
Commits
c4fbf9dcd6
...
7a75e943db
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7a75e943db | ||
|
|
634f23a76a | ||
|
|
b110cc97a0 | ||
|
|
fda88fff33 |
@@ -0,0 +1,43 @@
|
||||
package com.shuwei.dish.match.adapter
|
||||
|
||||
import android.content.Context
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.content.ContextCompat
|
||||
import com.chad.library.adapter4.BaseQuickAdapter
|
||||
import com.chad.library.adapter4.viewholder.QuickViewHolder
|
||||
import com.shuwei.dish.match.R
|
||||
import com.shuwei.dish.match.databinding.ListItemSearchFoodBinding
|
||||
import com.shuwei.dish.match.databinding.ListItemSearchGoodsInfoBinding
|
||||
import com.shuwei.dish.match.entity.CookFoodGoodsEntity
|
||||
import com.shuwei.dish.match.utils.ext.gone
|
||||
import com.shuwei.dish.match.utils.ext.roundedDecimalPlace
|
||||
import com.shuwei.dish.match.utils.ext.visible
|
||||
|
||||
class FoodSearchAdapter(private var list: MutableList<CookFoodGoodsEntity>) :
|
||||
BaseQuickAdapter<CookFoodGoodsEntity, FoodSearchAdapter.VH>(list) {
|
||||
|
||||
override fun onBindViewHolder(
|
||||
holder: VH,
|
||||
position: Int,
|
||||
item: CookFoodGoodsEntity?
|
||||
) {
|
||||
item ?: return
|
||||
holder.binding.tvFoodName.run {
|
||||
text = item.goodsName
|
||||
isChecked = item.isClicked
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(
|
||||
context: Context,
|
||||
parent: ViewGroup,
|
||||
viewType: Int
|
||||
): VH {
|
||||
val binding = ListItemSearchFoodBinding.inflate(LayoutInflater.from(context), parent, false)
|
||||
return VH(binding)
|
||||
}
|
||||
|
||||
inner class VH(var binding: ListItemSearchFoodBinding) : QuickViewHolder(binding.root)
|
||||
|
||||
}
|
||||
+5
-5
@@ -8,18 +8,18 @@ import android.widget.ImageView
|
||||
import com.chad.library.adapter4.BaseQuickAdapter
|
||||
import com.chad.library.adapter4.viewholder.QuickViewHolder
|
||||
import com.shuwei.dish.match.R
|
||||
import com.shuwei.dish.match.databinding.ListItemFoodCollectionBinding
|
||||
import com.shuwei.dish.match.databinding.ListItemVectorCollectionBinding
|
||||
import com.shuwei.dish.match.objbox.FoodCollectionBean
|
||||
import com.shuwei.dish.match.utils.ext.load
|
||||
|
||||
class FoodCollectionAdapter (var list: MutableList<FoodCollectionBean>) :
|
||||
BaseQuickAdapter<FoodCollectionBean, FoodCollectionAdapter.VH>(list) {
|
||||
class VectorCollectionAdapter (var list: MutableList<FoodCollectionBean>) :
|
||||
BaseQuickAdapter<FoodCollectionBean, VectorCollectionAdapter.VH>(list) {
|
||||
|
||||
inner class VH(var binding: ListItemFoodCollectionBinding) : QuickViewHolder(binding.root)
|
||||
inner class VH(var binding: ListItemVectorCollectionBinding) : QuickViewHolder(binding.root)
|
||||
|
||||
override fun onCreateViewHolder(context: Context, parent: ViewGroup, viewType: Int): VH {
|
||||
val inflater = LayoutInflater.from(context)
|
||||
val binding = ListItemFoodCollectionBinding.inflate(inflater, parent, false)
|
||||
val binding = ListItemVectorCollectionBinding.inflate(inflater, parent, false)
|
||||
return VH(binding)
|
||||
}
|
||||
|
||||
@@ -162,18 +162,22 @@ open class BaseActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
fun showLoading(msg: String = "加载中……") {
|
||||
handler.post {
|
||||
Loading.show(
|
||||
context = this,
|
||||
message = msg
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun dismissLoading() {
|
||||
handler.post {
|
||||
Loading.dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
fun delayDismissLoading() {
|
||||
window.decorView.postDelayed({
|
||||
handler.postDelayed({
|
||||
Loading.dismiss()
|
||||
}, 500)
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ class CollectedFoodActivity : BaseActivity() {
|
||||
appendText(" 删除后无法恢复,${separator}确认要删除吗?")
|
||||
}
|
||||
CommonDialog(this)
|
||||
.setTitle("温馨提示")
|
||||
.setTitle("删除提示")
|
||||
.setContent(content)
|
||||
.setNegativeButton("取消")
|
||||
.setPositiveButton("确认") {
|
||||
|
||||
@@ -117,8 +117,8 @@ class DishSamplingActivity : BaseActivity() {
|
||||
|
||||
private fun saveDataRemindDialog() {
|
||||
CommonDialog(this)
|
||||
.setTitle("温馨提示")
|
||||
.setContent("您好,当前页面存在未保存的数据,确认返回吗?")
|
||||
.setTitle("返回提示")
|
||||
.setContent("您好,当前页面存在未保存的数据,\n确认返回吗?")
|
||||
.setNegativeButton("取消")
|
||||
.setPositiveButton("确认") {
|
||||
if (pageFrom == HOME) {
|
||||
|
||||
@@ -6,6 +6,7 @@ import android.os.Bundle
|
||||
import androidx.activity.addCallback
|
||||
import androidx.core.content.IntentCompat
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.shuwei.dish.match.adapter.GoodsInfoSearchAdapter
|
||||
import com.shuwei.dish.match.base.BaseActivity
|
||||
import com.shuwei.dish.match.databinding.ActivityFoodRecognizeBinding
|
||||
@@ -93,6 +94,15 @@ class FoodRecognizeActivity : BaseActivity() {
|
||||
/** 当前待延迟更新的目标重量,避免相同重量重复重置计时器 */
|
||||
private var pendingWeight = 0.0
|
||||
|
||||
/** 右侧自定义滚动指示条最小高度 */
|
||||
private val scrollIndicatorMinHeightPx by lazy { (24 * resources.displayMetrics.density).toInt() }
|
||||
|
||||
private val scrollListener = object : RecyclerView.OnScrollListener() {
|
||||
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
|
||||
updateScrollIndicator()
|
||||
}
|
||||
}
|
||||
|
||||
private val adapter = GoodsInfoSearchAdapter(list).apply {
|
||||
setOnItemClickListener { _, _, position ->
|
||||
list.forEachIndexed { i, item -> item.isClicked = (i == position) }
|
||||
@@ -166,9 +176,13 @@ class FoodRecognizeActivity : BaseActivity() {
|
||||
* 初始化 RecyclerView
|
||||
*/
|
||||
private fun initRecyclerView() {
|
||||
binding.recyclerView.run {
|
||||
layoutManager = GridLayoutManager(this@FoodRecognizeActivity, 2)
|
||||
adapter = this@FoodRecognizeActivity.adapter
|
||||
binding.recyclerView.let {
|
||||
it.layoutManager = GridLayoutManager(this@FoodRecognizeActivity, 2)
|
||||
it.adapter = adapter
|
||||
it.isVerticalScrollBarEnabled = false
|
||||
it.removeOnScrollListener(scrollListener)
|
||||
it.addOnScrollListener(scrollListener)
|
||||
it.post { updateScrollIndicator() }
|
||||
}
|
||||
updateListVisibility()
|
||||
}
|
||||
@@ -178,12 +192,57 @@ class FoodRecognizeActivity : BaseActivity() {
|
||||
*/
|
||||
private fun updateListVisibility() {
|
||||
if (list.isEmpty()) {
|
||||
binding.recyclerView.gone()
|
||||
binding.flListContainer.gone()
|
||||
} else {
|
||||
binding.recyclerView.visible()
|
||||
binding.flListContainer.visible()
|
||||
binding.recyclerView.post { updateScrollIndicator() }
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 RecyclerView 滚动状态刷新右侧自定义指示条
|
||||
*/
|
||||
private fun updateScrollIndicator() {
|
||||
val recyclerView = binding.recyclerView
|
||||
val track = binding.vScrollIndicatorTrack
|
||||
val thumb = binding.vScrollIndicatorThumb
|
||||
|
||||
if (!recyclerView.canScrollVertically(1) && !recyclerView.canScrollVertically(-1)) {
|
||||
track.gone()
|
||||
thumb.gone()
|
||||
return
|
||||
}
|
||||
|
||||
val range = recyclerView.computeVerticalScrollRange()
|
||||
val extent = recyclerView.computeVerticalScrollExtent()
|
||||
val offset = recyclerView.computeVerticalScrollOffset()
|
||||
if (range <= 0 || extent <= 0 || range <= extent) {
|
||||
track.gone()
|
||||
thumb.gone()
|
||||
return
|
||||
}
|
||||
|
||||
val trackHeight = track.height.takeIf { it > 0 } ?: recyclerView.height
|
||||
if (trackHeight <= 0) return
|
||||
|
||||
val thumbHeight = ((extent.toFloat() / range) * trackHeight)
|
||||
.toInt()
|
||||
.coerceAtLeast(scrollIndicatorMinHeightPx)
|
||||
.coerceAtMost(trackHeight)
|
||||
|
||||
val maxTop = (trackHeight - thumbHeight).coerceAtLeast(0)
|
||||
val scrollable = (range - extent).coerceAtLeast(1)
|
||||
val thumbTop = ((offset.toFloat() / scrollable) * maxTop).toInt().coerceIn(0, maxTop)
|
||||
|
||||
if (thumb.layoutParams.height != thumbHeight) {
|
||||
thumb.layoutParams = thumb.layoutParams.apply { height = thumbHeight }
|
||||
}
|
||||
thumb.translationY = thumbTop.toFloat()
|
||||
|
||||
track.visible()
|
||||
thumb.visible()
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化按钮点击事件
|
||||
*/
|
||||
@@ -219,6 +278,7 @@ class FoodRecognizeActivity : BaseActivity() {
|
||||
adapter.notifyDataSetChanged()
|
||||
binding.tvSelectedFood.text = item.goodsName ?: "-"
|
||||
updateListVisibility()
|
||||
binding.recyclerView.post { updateScrollIndicator() }
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -122,11 +122,22 @@ class PrepareCookActivity : BaseActivity() {
|
||||
}
|
||||
|
||||
private fun addViewClickListener() {
|
||||
binding.tvShowWeight.setOnClickListener {
|
||||
showLoading("正在清零……")
|
||||
WeightUtil.tareTwo(AddressUtil.ONE)
|
||||
delayDismissLoading()
|
||||
}
|
||||
WeightUtil.addWeightListener(
|
||||
weightKey = TAG,
|
||||
getWeight = { address, state, weight ->
|
||||
if (address == AddressUtil.ONE && state == WeightUtil.STATE_STABLE) {
|
||||
runOnUiThread {
|
||||
binding.tvShowWeight.run {
|
||||
if (tag != weight) {
|
||||
text = "称重:${weight}g"
|
||||
tag = weight
|
||||
}
|
||||
}
|
||||
recognizeFood(weight)
|
||||
}
|
||||
}
|
||||
@@ -201,8 +212,10 @@ class PrepareCookActivity : BaseActivity() {
|
||||
return
|
||||
}
|
||||
if (!pageVisible || manualCancelFlag || isTakingPhoto.get() || showRecognizePage || abs(lastWeight - weight) <= WEIGHT_CHANGE_VALUE) {
|
||||
Log.d(TAG, "recognizeFood, lastWeight:$lastWeight, weight:$weight, pageVisible:$pageVisible, manualCancelFlag:$manualCancelFlag, isTakingPhoto:${isTakingPhoto.get()}")
|
||||
return
|
||||
}
|
||||
showLoading("识别中……")
|
||||
isTakingPhoto.set(true)
|
||||
cameraUtils.takePhoto(
|
||||
succCallback = cameraSuccessCallback,
|
||||
@@ -222,13 +235,12 @@ class PrepareCookActivity : BaseActivity() {
|
||||
existing.isSetFinished = true
|
||||
dishPartAdapter.notifyItemChanged(list.indexOf(existing))
|
||||
} else {
|
||||
list.add(entity.also {
|
||||
dishPartAdapter.add(entity.also {
|
||||
it.isNewDishType = true
|
||||
it.isSetFinished = true
|
||||
})
|
||||
val position = list.size - 1
|
||||
dishPartAdapter.notifyItemInserted(position)
|
||||
binding.rvDishPartList.smoothScrollToPosition(position)
|
||||
|
||||
binding.rvDishPartList.smoothScrollToPosition(list.size - 1)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -265,8 +277,8 @@ class PrepareCookActivity : BaseActivity() {
|
||||
|
||||
private fun showRemindDialog() {
|
||||
CommonDialog(this)
|
||||
.setTitle("制作提示")
|
||||
.setContent(getString(R.string.food_remind_01))
|
||||
.setTitle(getString(R.string.food_remind_01))
|
||||
.setContent(getString(R.string.food_remind_02))
|
||||
.setNegativeButton("返回调整")
|
||||
.setPositiveButton("确认无误") { openSubmitPage() }
|
||||
.setOnDismissCallback { hideStatusBar() }
|
||||
@@ -280,11 +292,14 @@ class PrepareCookActivity : BaseActivity() {
|
||||
netViewModel.foodDetailState.collect { state ->
|
||||
when (state) {
|
||||
is UiState.Success -> {
|
||||
// 防止 StateFlow 重放导致 list 被重复清空
|
||||
if (isDetailLoaded) return@collect
|
||||
val detail = state.data
|
||||
if (detail == null) {
|
||||
toast("查询菜品信息为空")
|
||||
return@collect
|
||||
}
|
||||
isDetailLoaded = true
|
||||
loadDishDetail(detail)
|
||||
}
|
||||
|
||||
@@ -336,6 +351,7 @@ class PrepareCookActivity : BaseActivity() {
|
||||
}
|
||||
|
||||
private var firstReqSize = 0
|
||||
private var isDetailLoaded = false
|
||||
private val list = mutableListOf<CookFoodGoodsEntity>()
|
||||
private val dishPartAdapter by lazy {
|
||||
DishPartAdapter(list = list).apply {
|
||||
@@ -438,8 +454,8 @@ class PrepareCookActivity : BaseActivity() {
|
||||
*/
|
||||
private fun saveDataRemindDialog() {
|
||||
CommonDialog(this)
|
||||
.setTitle("温馨提示")
|
||||
.setContent("您好,当前页面存在未保存的数据,确认返回吗?")
|
||||
.setTitle("返回提示")
|
||||
.setContent("您好,当前页面存在未保存的数据,\n确认返回吗?")
|
||||
.setNegativeButton("取消")
|
||||
.setPositiveButton("确认") {
|
||||
if (SpTool.cookMode == 1 && pageFrom == HOME) {
|
||||
@@ -461,12 +477,14 @@ class PrepareCookActivity : BaseActivity() {
|
||||
withContext(Dispatchers.IO) {
|
||||
val bitmap = ImageUtil.uriToBitmap(this@PrepareCookActivity, uri)
|
||||
if (bitmap == null) {
|
||||
dismissLoading()
|
||||
Log.d(TAG, "takePhoto bitmap is null")
|
||||
isTakingPhoto.set(false)
|
||||
return@withContext
|
||||
}
|
||||
val foodScoreList = FoodModule.getFoodScoreList(bitmap)
|
||||
if (foodScoreList.isEmpty()) {
|
||||
dismissLoading()
|
||||
Log.d(TAG, "takePhoto foodScoreList is empty")
|
||||
isTakingPhoto.set(false)
|
||||
return@withContext
|
||||
@@ -485,6 +503,7 @@ class PrepareCookActivity : BaseActivity() {
|
||||
Log.d(TAG, "takePhoto failure")
|
||||
isTakingPhoto.set(false)
|
||||
toast(errMsg)
|
||||
dismissLoading()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -492,10 +511,11 @@ class PrepareCookActivity : BaseActivity() {
|
||||
* @param list 食材列表
|
||||
*/
|
||||
private fun queryFood(list: List<FoodModule.IdNameScore>) {
|
||||
Log.d(TAG, "takePhoto queryFood, list=${list.toString()}")
|
||||
Log.d(TAG, "takePhoto queryFood, list=$list")
|
||||
//调用接口成功,返回食材列表设置isTakingPhoto.set(false),暂时写死数据
|
||||
val foodList = mutableListOf<CookFoodGoodsEntity>()
|
||||
list.forEachIndexed { index, food ->
|
||||
Log.d(TAG, "takePhoto queryFood, index=${index},food=$food")
|
||||
var foodName = ""
|
||||
var foodId = ""
|
||||
food.name.split("WP").let {
|
||||
@@ -517,6 +537,23 @@ class PrepareCookActivity : BaseActivity() {
|
||||
}
|
||||
)
|
||||
}
|
||||
Log.d(TAG, "takePhoto queryFood, 数据添加完成")
|
||||
handler.postDelayed({
|
||||
dismissLoading()
|
||||
loadRecognizeResultPage(foodList)
|
||||
}, 1000)
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载识别结果页面
|
||||
*/
|
||||
private fun loadRecognizeResultPage(foodList: List<CookFoodGoodsEntity>) {
|
||||
if (currentWeight < WEIGHT_RECOGNIZE_VALUE) {
|
||||
Log.d(TAG, "takePhoto queryFood, 已取消")
|
||||
toast("已取消")
|
||||
isTakingPhoto.set(false)
|
||||
return
|
||||
}
|
||||
lastWeight = currentWeight
|
||||
FoodRecognizeActivity.start(
|
||||
activity = this,
|
||||
|
||||
@@ -369,7 +369,7 @@ class SamplingListActivity : BaseActivity() {
|
||||
|
||||
private fun showDeviceConfigDialog() {
|
||||
CommonDialog(this)
|
||||
.setTitle("温馨提示")
|
||||
.setTitle("配置提示")
|
||||
.setContent("请先在设备配置页面进行调料设置")
|
||||
.setNegativeButton("取消")
|
||||
.setPositiveButton("去设置") { startActivity<SettingActivity>() }
|
||||
|
||||
@@ -84,7 +84,7 @@ class SelectDishActivity : BaseActivity() {
|
||||
|
||||
private fun showDeviceConfigDialog() {
|
||||
CommonDialog(this)
|
||||
.setTitle("温馨提示")
|
||||
.setTitle("配置提示")
|
||||
.setContent("请先在设备配置页面进行调料设置")
|
||||
.setNegativeButton("取消")
|
||||
.setPositiveButton("去设置") { startActivity<SettingActivity>() }
|
||||
|
||||
@@ -115,8 +115,8 @@ class SettingActivity : BaseActivity() {
|
||||
|
||||
private fun showNotGrantedCameraPermissionDialog() {
|
||||
CommonDialog(this)
|
||||
.setTitle("温馨提示")
|
||||
.setContent("暂无相机权限,无法使用菜品采集功能,请确认是否同意开始权限?")
|
||||
.setTitle("权限提示")
|
||||
.setContent("暂无相机权限,无法使用食材采集功能,请确认是否同意开始权限?")
|
||||
.setNegativeButton("不同意")
|
||||
.setPositiveButton("同意") {
|
||||
val intent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS).apply {
|
||||
|
||||
@@ -94,7 +94,7 @@ class SingleFragmentActivity : BaseActivity() {
|
||||
* 根据页面类型返回对应标题文本
|
||||
*/
|
||||
private fun getTitleForPage(pageType: PageType): String = when (pageType) {
|
||||
PageType.FOOD_COLLECT -> "食材采样"
|
||||
PageType.FOOD_COLLECT -> "食材采集"
|
||||
PageType.COOK_MODE -> "餐品模式"
|
||||
PageType.SEASONING_CONFIG -> "调料区设置"
|
||||
}
|
||||
|
||||
@@ -103,7 +103,8 @@ class SlaveActivity : BaseActivity() {
|
||||
scale22Adapter = Seasoning22GridAdapter(
|
||||
size.largeSize,
|
||||
size.smallSize,
|
||||
showNameOnly = false
|
||||
showNameOnly = false,
|
||||
showAddress = true
|
||||
).also {
|
||||
it.onItemClick = { scale, _ -> showTareDialog(scale.address) }
|
||||
}
|
||||
@@ -116,7 +117,7 @@ class SlaveActivity : BaseActivity() {
|
||||
override fun getSpanSize(position: Int) = 1
|
||||
}
|
||||
}
|
||||
scale18Adapter = Seasoning18GridAdapter(showNameOnly = false).also {
|
||||
scale18Adapter = Seasoning18GridAdapter(showNameOnly = false, showAddress = true).also {
|
||||
it.onItemClick = { scale, _ -> showTareDialog(scale.address) }
|
||||
}
|
||||
binding.rvScaleList.adapter = scale18Adapter
|
||||
|
||||
@@ -423,8 +423,8 @@ class SubmitFoodActivity : BaseActivity() {
|
||||
*/
|
||||
private fun remindSaveDataDialog() {
|
||||
CommonDialog(this)
|
||||
.setTitle("温馨提示")
|
||||
.setContent("请确认是否存在未保存的数据?")
|
||||
.setTitle("保存提示")
|
||||
.setContent("可能存在未保存的数据,请确认?")
|
||||
.setNegativeButton("取消,留在页面")
|
||||
.setNeutralButton("返回上页,不保存") { finish() }
|
||||
.setPositiveButton("保存为烹饪中菜品") { cook() }
|
||||
@@ -436,7 +436,7 @@ class SubmitFoodActivity : BaseActivity() {
|
||||
*/
|
||||
private fun showRemindDialog(content: CharSequence, action: () -> Unit) {
|
||||
CommonDialog(this)
|
||||
.setTitle("温馨提示")
|
||||
.setTitle(food?.foodName ?: "温馨提示")
|
||||
.setContent(content)
|
||||
.setNegativeButton("取消")
|
||||
.setPositiveButton("确认") { action() }
|
||||
|
||||
@@ -16,11 +16,13 @@ import androidx.core.view.doOnLayout
|
||||
import androidx.core.view.updateLayoutParams
|
||||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import com.shuwei.dish.match.R
|
||||
import com.shuwei.dish.match.adapter.FoodCollectionAdapter
|
||||
import com.shuwei.dish.match.adapter.VectorCollectionAdapter
|
||||
import com.shuwei.dish.match.adapter.FoodSearchAdapter
|
||||
import com.shuwei.dish.match.base.BaseFragment
|
||||
import com.shuwei.dish.match.databinding.FragmentCollectBinding
|
||||
import com.shuwei.dish.match.databinding.LayoutCameraPreviewBinding
|
||||
import com.shuwei.dish.match.dialog.Loading
|
||||
import com.shuwei.dish.match.entity.CookFoodGoodsEntity
|
||||
import com.shuwei.dish.match.objbox.FoodCollectionBean
|
||||
import com.shuwei.dish.match.objbox.FoodModule
|
||||
import com.shuwei.dish.match.ui.CollectedFoodActivity
|
||||
@@ -45,34 +47,47 @@ class CollectFragment : BaseFragment<FragmentCollectBinding>(){
|
||||
private var selectedFoodId: String? = ""
|
||||
private var selectedFoodName: String? = ""
|
||||
|
||||
private val foodCollectionList = mutableListOf<FoodCollectionBean>().apply {
|
||||
private val vectorList = mutableListOf<FoodCollectionBean>().apply {
|
||||
repeat(MAX_COUNT) {
|
||||
add(FoodCollectionBean(isShowCamera = true))
|
||||
}
|
||||
}
|
||||
|
||||
// private val searchFoodList = mutableListOf<FoodInfo>()
|
||||
// private var settingActivity: SettingActivity? = null
|
||||
// private var checkedItem: FoodInfo? = null
|
||||
// private val searchFoodAdapter by lazy {
|
||||
// CollectFoodListAdapter(searchFoodList).apply {
|
||||
// setOnItemClickListener { adapter, view, position ->
|
||||
// searchFoodList.forEachIndexed { index, item -> item.isChecked = index == position }
|
||||
// checkedItem = searchFoodList[position]
|
||||
// notifyDataSetChanged()
|
||||
// selectedFoodId = checkedItem!!.foodId
|
||||
// selectedFoodName = checkedItem!!.foodName
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
private val searchList = mutableListOf<CookFoodGoodsEntity>().apply {
|
||||
add(CookFoodGoodsEntity(goodsId = "200001", goodsName = "土豆丝"))
|
||||
add(CookFoodGoodsEntity(goodsId = "200002", goodsName = "土豆片"))
|
||||
add(CookFoodGoodsEntity(goodsId = "200003", goodsName = "土豆丁"))
|
||||
add(CookFoodGoodsEntity(goodsId = "200004", goodsName = "胡萝卜丝"))
|
||||
add(CookFoodGoodsEntity(goodsId = "200005", goodsName = "胡萝卜片"))
|
||||
add(CookFoodGoodsEntity(goodsId = "200006", goodsName = "胡萝卜丁"))
|
||||
add(CookFoodGoodsEntity(goodsId = "200007", goodsName = "黄瓜丝"))
|
||||
add(CookFoodGoodsEntity(goodsId = "200008", goodsName = "黄瓜片"))
|
||||
add(CookFoodGoodsEntity(goodsId = "200009", goodsName = "黄瓜丁"))
|
||||
add(CookFoodGoodsEntity(goodsId = "200010", goodsName = "洋葱丝"))
|
||||
add(CookFoodGoodsEntity(goodsId = "200011", goodsName = "洋葱丁"))
|
||||
}
|
||||
private var checkedItem: CookFoodGoodsEntity? = null
|
||||
private val searchAdapter by lazy {
|
||||
FoodSearchAdapter(searchList).apply {
|
||||
setOnItemClickListener { adapter, view, position ->
|
||||
searchList.forEachIndexed { index, item -> item.isClicked = index == position }
|
||||
checkedItem = searchList[position]
|
||||
notifyDataSetChanged()
|
||||
checkedItem?.let {
|
||||
selectedFoodId = it.foodId
|
||||
selectedFoodName = it.goodsName
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private val debouncer = Debouncer(2000)
|
||||
// private lateinit var settingActivity: SettingActivity
|
||||
|
||||
private lateinit var currentActivity: SingleFragmentActivity
|
||||
|
||||
private val collectionAdapter: FoodCollectionAdapter by lazy {
|
||||
FoodCollectionAdapter(foodCollectionList).apply {
|
||||
private val vectorAdapter: VectorCollectionAdapter by lazy {
|
||||
VectorCollectionAdapter(vectorList).apply {
|
||||
addOnItemChildClickListener(R.id.ivDelete) { _, _, position ->
|
||||
foodCollectionList[position].let {
|
||||
vectorList[position].let {
|
||||
it.bitmap = null
|
||||
it.imageVector = null
|
||||
it.imageFile = null
|
||||
@@ -96,23 +111,23 @@ class CollectFragment : BaseFragment<FragmentCollectBinding>(){
|
||||
|
||||
//typealias CameraCallback = (Uri) -> Unit
|
||||
|
||||
private val cameraCallback: (Uri) -> Unit = { uri ->
|
||||
private val cameraCallback: (Uri) -> Unit = cameraCallback@{ uri ->
|
||||
try {
|
||||
val index = foodCollectionList.indexOfFirst { it.imageFile == null }
|
||||
val index = vectorList.indexOfFirst { it.imageFile == null }
|
||||
if (index == -1) {
|
||||
toast("每次只允许保存${MAX_COUNT}条数据")
|
||||
hideWaitingDialog()
|
||||
rerurn@ cameraCallback
|
||||
return@cameraCallback
|
||||
}
|
||||
activity?.runOnUiThread {
|
||||
foodCollectionList[index].let {
|
||||
vectorList[index].let {
|
||||
it.imageVector = null
|
||||
it.bitmap = null
|
||||
it.isShowCamera = false
|
||||
it.imageFile = null
|
||||
it.imageUri = uri
|
||||
}
|
||||
collectionAdapter.notifyItemChanged(index)
|
||||
vectorAdapter.notifyItemChanged(index)
|
||||
}
|
||||
// hideWaitingDialog()
|
||||
Thread {
|
||||
@@ -149,13 +164,13 @@ class CollectFragment : BaseFragment<FragmentCollectBinding>(){
|
||||
log("${this.javaClass.simpleName}-cameraCallback-裁剪bitmap保存文件路径:${file?.absolutePath}")
|
||||
|
||||
activity?.runOnUiThread {
|
||||
foodCollectionList[index].let {
|
||||
vectorList[index].let {
|
||||
it.imageVector = imageVector
|
||||
it.bitmap = null
|
||||
it.isShowCamera = false
|
||||
it.imageFile = file
|
||||
}
|
||||
collectionAdapter.notifyItemChanged(index)
|
||||
vectorAdapter.notifyItemChanged(index)
|
||||
}
|
||||
if (bitmap.isRecycled.not()) {
|
||||
bitmap.recycle()
|
||||
@@ -165,12 +180,12 @@ class CollectFragment : BaseFragment<FragmentCollectBinding>(){
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
private fun takePhoto() {
|
||||
val count = foodCollectionList.count { it.bitmap != null }
|
||||
val count = vectorList.count { it.bitmap != null }
|
||||
if (count >= MAX_COUNT) {
|
||||
toast("每次只允许保存${MAX_COUNT}条数据")
|
||||
return
|
||||
}
|
||||
val index = foodCollectionList.indexOfFirst { it.imageFile == null }
|
||||
val index = vectorList.indexOfFirst { it.imageFile == null }
|
||||
if (index == -1) {
|
||||
toast("每次只允许保存${MAX_COUNT}条数据")
|
||||
hideWaitingDialog()
|
||||
@@ -212,7 +227,7 @@ class CollectFragment : BaseFragment<FragmentCollectBinding>(){
|
||||
binding.rvFoodList.let {
|
||||
it.layoutManager =
|
||||
GridLayoutManager(requireActivity(), 3, GridLayoutManager.VERTICAL, false)
|
||||
it.adapter = collectionAdapter
|
||||
it.adapter = vectorAdapter
|
||||
}
|
||||
|
||||
binding.btnFoodSearch.setOnClickListener {
|
||||
@@ -248,7 +263,7 @@ class CollectFragment : BaseFragment<FragmentCollectBinding>(){
|
||||
startActivity(Intent(requireActivity(), CollectedFoodActivity::class.java))
|
||||
}
|
||||
binding.btnTakePhoto.clickWithDebounce {
|
||||
val count = foodCollectionList.count { it.bitmap != null }
|
||||
val count = vectorList.count { it.bitmap != null }
|
||||
if (count >= MAX_COUNT) {
|
||||
toast("每次只允许保存${MAX_COUNT}条数据")
|
||||
return@clickWithDebounce
|
||||
@@ -256,10 +271,10 @@ class CollectFragment : BaseFragment<FragmentCollectBinding>(){
|
||||
takePhoto()
|
||||
}
|
||||
binding.btnClearData.setOnClickListener { clearData() }
|
||||
// binding.rvSearchFood.let {
|
||||
// it.layoutManager = GridLayoutManager(context, 2)
|
||||
// it.adapter = searchFoodAdapter
|
||||
// }
|
||||
binding.rvSearchFood.let {
|
||||
it.layoutManager = GridLayoutManager(context, 2)
|
||||
it.adapter = searchAdapter
|
||||
}
|
||||
|
||||
searchFood()
|
||||
}
|
||||
@@ -342,7 +357,7 @@ class CollectFragment : BaseFragment<FragmentCollectBinding>(){
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
fun clearData() {
|
||||
foodCollectionList.forEach {
|
||||
vectorList.forEach {
|
||||
it.bitmap = null
|
||||
it.imageVector = null
|
||||
it.imageFile = null
|
||||
@@ -351,7 +366,7 @@ class CollectFragment : BaseFragment<FragmentCollectBinding>(){
|
||||
it.isFinish = false
|
||||
it.uploadSuccess = false
|
||||
}
|
||||
collectionAdapter.notifyDataSetChanged()
|
||||
vectorAdapter.notifyDataSetChanged()
|
||||
|
||||
clickIndex = -1
|
||||
binding.editFoodName.setText("")
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:color="@color/dish_green" android:state_checked="true" />
|
||||
<item android:color="#5E7585" android:state_checked="false" />
|
||||
</selector>
|
||||
+3
-3
@@ -4,14 +4,14 @@
|
||||
<shape android:shape="rectangle">
|
||||
<corners android:radius="50dp"/>
|
||||
<solid android:color="@color/white"/>
|
||||
<!-- <stroke android:color="#FFC4CFDA" android:width="2dp"/>-->
|
||||
</shape>
|
||||
</item>
|
||||
<item android:state_checked="true">
|
||||
<shape android:shape="rectangle">
|
||||
<corners android:radius="50dp"/>
|
||||
<solid android:color="#FFFFF0F0"/>
|
||||
<stroke android:color="#FFFF3232" android:width="2dp"/>
|
||||
<!-- <solid android:color="#FFFFF0F0"/>-->
|
||||
<solid android:color="#F0FFF0"/>
|
||||
<stroke android:color="@color/dish_green" android:width="2dp"/>
|
||||
</shape>
|
||||
</item>
|
||||
</selector>
|
||||
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<size android:width="6dp" />
|
||||
<!-- <solid android:color="#66C4C4C4" />-->
|
||||
<solid android:color="@color/dish_green" />
|
||||
<corners android:radius="3dp" />
|
||||
</shape>
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<size android:width="10dp" />
|
||||
<solid android:color="#33000000" />
|
||||
<corners android:radius="5dp" />
|
||||
</shape>
|
||||
@@ -271,7 +271,7 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<androidx.appcompat.widget.AppCompatButton
|
||||
<TextView
|
||||
android:id="@+id/btnCook"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="90dp"
|
||||
@@ -282,6 +282,7 @@
|
||||
android:textSize="32sp"
|
||||
android:textStyle="bold"
|
||||
android:background="@drawable/shape_green_bg"
|
||||
android:foreground="?android:attr/selectableItemBackground"
|
||||
android:clickable="true" />
|
||||
|
||||
<!-- android:background="@drawable/ripple_effect_green"-->
|
||||
|
||||
@@ -9,31 +9,63 @@
|
||||
tools:background="@color/white">
|
||||
|
||||
<!-- 食材照片,权重占满剩余空间 -->
|
||||
<ImageView
|
||||
android:id="@+id/ivFoodPhoto"
|
||||
<androidx.cardview.widget.CardView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
app:cardBackgroundColor="@color/white"
|
||||
app:cardElevation="0dp"
|
||||
app:cardCornerRadius="8dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/ivFoodPhoto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:scaleType="centerCrop"
|
||||
tools:ignore="ContentDescription"
|
||||
tools:src="@color/bg_color" />
|
||||
tools:src="@mipmap/ic_launcher" />
|
||||
</androidx.cardview.widget.CardView>
|
||||
|
||||
<!-- 识别到的食材列表,无数据时隐藏 -->
|
||||
<FrameLayout
|
||||
android:id="@+id/flListContainer"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="260dp"
|
||||
android:layout_marginTop="12dp">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recyclerView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
android:maxHeight="200dp"
|
||||
android:nestedScrollingEnabled="false"
|
||||
android:layout_height="match_parent"
|
||||
android:overScrollMode="never"
|
||||
android:visibility="gone"
|
||||
android:paddingEnd="6dp"
|
||||
android:paddingStart="0dp"
|
||||
android:clipToPadding="false"
|
||||
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
|
||||
app:spanCount="2"
|
||||
tools:itemCount="4"
|
||||
tools:listitem="@layout/list_item_search_goods_info"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<View
|
||||
android:id="@+id/vScrollIndicatorTrack"
|
||||
android:layout_width="4dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="end|top"
|
||||
android:layout_marginEnd="2dp"
|
||||
android:background="@drawable/scrollbar_track_food_recognize"
|
||||
android:visibility="gone" />
|
||||
|
||||
<View
|
||||
android:id="@+id/vScrollIndicatorThumb"
|
||||
android:layout_width="6dp"
|
||||
android:layout_height="24dp"
|
||||
android:layout_gravity="end|top"
|
||||
android:layout_marginEnd="1dp"
|
||||
android:background="@drawable/scrollbar_thumb_food_recognize"
|
||||
android:visibility="gone" />
|
||||
</FrameLayout>
|
||||
|
||||
<!-- 选中的食材名称 -->
|
||||
<TextView
|
||||
android:id="@+id/tvSelectedFood"
|
||||
@@ -63,8 +95,9 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="90dp"
|
||||
android:layout_marginTop="30dp"
|
||||
android:gravity="center"
|
||||
android:background="@drawable/shape_green_bg"
|
||||
android:foreground="?android:attr/selectableItemBackground"
|
||||
android:gravity="center"
|
||||
android:text="更换食材"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="32sp"
|
||||
@@ -77,8 +110,9 @@
|
||||
android:layout_height="90dp"
|
||||
android:layout_marginTop="30dp"
|
||||
android:layout_marginBottom="30dp"
|
||||
android:gravity="center"
|
||||
android:background="@drawable/shape_white_12_corners"
|
||||
android:foreground="?android:attr/selectableItemBackground"
|
||||
android:gravity="center"
|
||||
android:text="取消"
|
||||
android:textColor="@color/black333"
|
||||
android:textSize="32sp"
|
||||
|
||||
@@ -60,21 +60,36 @@
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="20dp"
|
||||
android:layout_marginTop="30dp"
|
||||
android:layout_marginEnd="20dp"
|
||||
android:layout_marginBottom="30dp"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="start"
|
||||
android:layout_marginVertical="30dp"
|
||||
android:layout_marginStart="20dp"
|
||||
android:padding="10dp"
|
||||
android:text="@string/dish_composition"
|
||||
android:textColor="@color/black666"
|
||||
android:textSize="28sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvShowWeight"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="80dp"
|
||||
android:layout_gravity="end|center_vertical"
|
||||
android:paddingHorizontal="30dp"
|
||||
android:gravity="center_vertical"
|
||||
android:maxLines="1"
|
||||
tools:text="称重:0g"
|
||||
android:textColor="@color/black666"
|
||||
android:textSize="28sp" />
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/flCameraContainer"
|
||||
android:layout_width="1dp"
|
||||
android:layout_height="1dp" />
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
@@ -89,17 +104,13 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/flCameraContainer"
|
||||
android:layout_width="1dp"
|
||||
android:layout_height="1dp" />
|
||||
|
||||
<androidx.appcompat.widget.AppCompatButton
|
||||
<TextView
|
||||
android:id="@+id/btnCook"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="90dp"
|
||||
android:layout_margin="30dp"
|
||||
android:background="@drawable/shape_green_bg"
|
||||
android:foreground="?android:attr/selectableItemBackground"
|
||||
android:gravity="center"
|
||||
android:text="@string/goCooking"
|
||||
android:textColor="@color/white"
|
||||
|
||||
@@ -94,7 +94,7 @@
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="食材采样"
|
||||
android:text="食材采集"
|
||||
android:textSize="32sp"
|
||||
android:textStyle="bold"
|
||||
android:layout_marginStart="32dp"
|
||||
|
||||
@@ -112,7 +112,7 @@
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<androidx.appcompat.widget.AppCompatButton
|
||||
<TextView
|
||||
android:id="@+id/btnCook"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="90dp"
|
||||
@@ -121,6 +121,7 @@
|
||||
android:layout_marginBottom="30dp"
|
||||
android:layout_weight="1"
|
||||
android:background="@drawable/shape_green_stroke"
|
||||
android:foreground="?android:attr/selectableItemBackground"
|
||||
android:gravity="center"
|
||||
android:text="制作"
|
||||
android:textColor="@color/dish_green"
|
||||
@@ -128,7 +129,7 @@
|
||||
android:textStyle="bold" />
|
||||
<!-- android:background="@drawable/ripple_effect_light"-->
|
||||
|
||||
<androidx.appcompat.widget.AppCompatButton
|
||||
<TextView
|
||||
android:id="@+id/btnSubmit"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="90dp"
|
||||
@@ -138,6 +139,7 @@
|
||||
android:layout_marginBottom="30dp"
|
||||
android:layout_weight="1"
|
||||
android:background="@drawable/shape_green_bg"
|
||||
android:foreground="?android:attr/selectableItemBackground"
|
||||
android:gravity="center"
|
||||
android:text="提交"
|
||||
android:textColor="@color/white"
|
||||
|
||||
@@ -139,7 +139,7 @@
|
||||
app:spanCount="3"
|
||||
tools:itemCount="12"
|
||||
android:overScrollMode="never"
|
||||
tools:listitem="@layout/list_item_food_collection" />
|
||||
tools:listitem="@layout/list_item_vector_collection" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
@@ -157,9 +157,9 @@
|
||||
android:layout_height="match_parent"
|
||||
android:background="@drawable/setting_border_gray3"
|
||||
android:gravity="center_vertical"
|
||||
android:hint="输入菜品名称"
|
||||
android:inputType="text"
|
||||
android:hint="输入食材名称"
|
||||
android:imeOptions="actionSearch"
|
||||
android:inputType="text"
|
||||
android:maxLines="1"
|
||||
android:paddingStart="47dp"
|
||||
android:paddingEnd="80dp"
|
||||
@@ -191,7 +191,7 @@
|
||||
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
|
||||
tools:listitem="@layout/list_item_search_food"/>
|
||||
|
||||
<androidx.appcompat.widget.AppCompatButton
|
||||
<TextView
|
||||
android:id="@+id/btnSave"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="100dp"
|
||||
@@ -199,8 +199,12 @@
|
||||
android:layout_marginBottom="32dp"
|
||||
android:layout_marginTop="20dp"
|
||||
android:text="保存"
|
||||
android:gravity="center"
|
||||
android:textStyle="bold"
|
||||
android:foreground="?android:attr/selectableItemBackground"
|
||||
android:background="@drawable/bg_btn_save"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="40sp" />
|
||||
android:textSize="40sp"
|
||||
android:clipToOutline="true"/>
|
||||
|
||||
</LinearLayout>
|
||||
@@ -4,7 +4,7 @@
|
||||
android:id="@+id/tvFoodName"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="100dp"
|
||||
tools:background="@drawable/bg_text_main"
|
||||
android:background="@drawable/bg_item_search"
|
||||
android:ellipsize="end"
|
||||
android:gravity="center"
|
||||
android:maxLines="1"
|
||||
@@ -12,7 +12,7 @@
|
||||
android:layout_marginVertical="14dp"
|
||||
android:paddingHorizontal="15dp"
|
||||
android:textAlignment="center"
|
||||
tools:textColor="@color/black"
|
||||
android:textColor="@color/color_item_search"
|
||||
android:textSize="30sp"
|
||||
android:textStyle="bold"
|
||||
tools:text="肉沫干拌面" />
|
||||
tools:text="土豆丝" />
|
||||
Reference in New Issue
Block a user