This commit is contained in:
2025-08-14 14:26:24 +08:00
parent 3b4ba599bf
commit d609bde82e
13 changed files with 1380 additions and 590 deletions
@@ -6,7 +6,8 @@ object UrlConfig {
// const val DISH_DETAIL = "$BASE_URL/scales/goodsUseList?foodId={foodId}&foodWeight={foodWeight}" // const val DISH_DETAIL = "$BASE_URL/scales/goodsUseList?foodId={foodId}&foodWeight={foodWeight}"
// const val DISH_LIST = "$BASE_URL/scales/getRestInfoFoods?eaId=99&type=0&foodName" // const val DISH_LIST = "$BASE_URL/scales/getRestInfoFoods?eaId=99&type=0&foodName"
const val BASE_URL = "http://192.168.1.207:9102" // const val BASE_URL = "http://192.168.1.207:9102"
const val BASE_URL = "https://yyjk.shuziweidao.com/gateway"
// const val DISH_LIST = "$BASE_URL/scales/getRestInfoFoods?eaId=99&type=0&foodName" // const val DISH_LIST = "$BASE_URL/scales/getRestInfoFoods?eaId=99&type=0&foodName"
const val DISH_DETAIL = "$BASE_URL/food/stFoodInfoMatching/queryById" const val DISH_DETAIL = "$BASE_URL/food/stFoodInfoMatching/queryById"
@@ -1,31 +1,48 @@
package com.shuwei.dish.match.ui package com.shuwei.dish.match.ui
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.content.Intent
import android.os.Bundle import android.os.Bundle
import androidx.fragment.app.Fragment import android.util.Log
import android.view.View
import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.LinearLayoutManager
import com.aithings.Weigher
import com.shuwei.dish.match.R import com.shuwei.dish.match.R
import com.shuwei.dish.match.adapter.DishPartAdapter
import com.shuwei.dish.match.base.BaseActivity import com.shuwei.dish.match.base.BaseActivity
import com.shuwei.dish.match.base.BaseApp import com.shuwei.dish.match.base.BaseApp
import com.shuwei.dish.match.databinding.ActivitySamplingBinding import com.shuwei.dish.match.databinding.ActivityDishSamplingBinding
import com.shuwei.dish.match.databinding.LayoutFoodRemindBinding import com.shuwei.dish.match.databinding.LayoutFoodRemindBinding
import com.shuwei.dish.match.db.AppRepository import com.shuwei.dish.match.db.AppRepository
import com.shuwei.dish.match.dialog.BottomDialog
import com.shuwei.dish.match.dialog.CommonDialog import com.shuwei.dish.match.dialog.CommonDialog
import com.shuwei.dish.match.entity.CookFoodEntity import com.shuwei.dish.match.entity.CookFoodEntity
import com.shuwei.dish.match.ui.fragment.DishSamplingFragment import com.shuwei.dish.match.entity.CookFoodGoodsEntity
import com.shuwei.dish.match.entity.FoodRecord
import com.shuwei.dish.match.utils.KeyboardUtil
import com.shuwei.dish.match.utils.WeightUtil
import com.shuwei.dish.match.utils.ext.addOnActionSearchListener
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.startActivity import com.shuwei.dish.match.utils.ext.startActivity
import com.shuwei.dish.match.utils.ext.toJsonString
import com.shuwei.dish.match.utils.ext.toast
import com.shuwei.dish.match.utils.ext.visible import com.shuwei.dish.match.utils.ext.visible
import com.shuwei.dish.match.viewmodel.AppViewModel import com.shuwei.dish.match.viewmodel.AppViewModel
import com.shuwei.dish.match.viewmodel.factory.AppFactory import com.shuwei.dish.match.viewmodel.factory.AppFactory
import java.io.Serializable
class DishSamplingActivity : BaseActivity() { class DishSamplingActivity : BaseActivity() {
private lateinit var binding: ActivitySamplingBinding private lateinit var binding: ActivityDishSamplingBinding
var foodName: String? = null var foodName: String? = null
private var foodId: String? = null
companion object { companion object {
private const val TAG = "DishSamplingActivity"
public const val FOOD_NAME = "foodName" public const val FOOD_NAME = "foodName"
public const val PAGE_FROM = "pageFrom" public const val PAGE_FROM = "pageFrom"
public const val HOME = "home" public const val HOME = "home"
@@ -35,14 +52,15 @@ class DishSamplingActivity : BaseActivity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
binding = ActivitySamplingBinding.inflate(layoutInflater) binding = ActivityDishSamplingBinding.inflate(layoutInflater)
setContentView(binding.root) setContentView(binding.root)
pageFrom = intent.getStringExtra(PAGE_FROM) pageFrom = intent.getStringExtra(PAGE_FROM)
setTitleBar() setTitleBar()
setHeaderBackground() setHeaderBackground()
addViewClickListener()
initViewModel() initViewModel()
loadDishSamplingPage()
foodName = intent.getStringExtra(FOOD_NAME) foodName = intent.getStringExtra(FOOD_NAME)
binding.etInputDish.setText(foodName)
} }
private fun setTitleBar() { private fun setTitleBar() {
@@ -64,24 +82,6 @@ class DishSamplingActivity : BaseActivity() {
}) })
} }
private var dishSamplingFragment: DishSamplingFragment? = null
private fun loadDishSamplingPage() {
if (dishSamplingFragment == null) {
dishSamplingFragment = DishSamplingFragment()
}
dishSamplingFragment?.let {
loadFragment(it)
}
}
private fun loadFragment(fragment: Fragment) {
supportFragmentManager.beginTransaction().apply {
replace(R.id.flContainer, fragment)
commit()
}
}
private lateinit var appViewModel: AppViewModel private lateinit var appViewModel: AppViewModel
private fun initViewModel() { private fun initViewModel() {
@@ -100,8 +100,7 @@ class DishSamplingActivity : BaseActivity() {
@SuppressLint("GestureBackNavigation") @SuppressLint("GestureBackNavigation")
@Deprecated("Deprecated in Java") @Deprecated("Deprecated in Java")
override fun onBackPressed() { override fun onBackPressed() {
val list = dishSamplingFragment?.list if (list.isEmpty().not()) {
if (list.isNullOrEmpty().not()) {
//说明有新增的食材 //说明有新增的食材
saveDataRemindDialog() saveDataRemindDialog()
return return
@@ -128,4 +127,137 @@ class DishSamplingActivity : BaseActivity() {
onDismiss = { hideStatusBar() } onDismiss = { hideStatusBar() }
}.show() }.show()
} }
val list: MutableList<CookFoodGoodsEntity> = mutableListOf()
private var tempDishEntity: CookFoodGoodsEntity? = null
private var dishMaterialType = 1
private val dishAdapter by lazy {
DishPartAdapter(list).apply {
addOnItemChildClickListener(R.id.ivOperateIcon) { _, _, positon ->
//删除操作
removeAt(positon)
}
}
}
@SuppressLint("NotifyDataSetChanged")
private fun addViewClickListener() {
binding.rvDishPartList.run {
layoutManager =
LinearLayoutManager(this@DishSamplingActivity, LinearLayoutManager.VERTICAL, false)
adapter = dishAdapter
}
binding.tvInputDishType.run {
clickWithDebounce {
BottomDialog(goodsType = 0).show(this@DishSamplingActivity) { item ->
val filterResult = list.firstOrNull { it.goodsName == item.goodsName }
if (filterResult != null) {
toast("不允许重复添加同一食材")
return@show
}
text = item.goodsName
tempDishEntity = CookFoodGoodsEntity().apply {
goodsId = item.goodsId
goodsName = item.goodsName
relateionType = item.relateionType ?: 0
goodsOrRelationCode = item.goodsOrRelationCode
// TODO: 待定
//allEdible = item.allEdible
}
}
}
}
binding.ivWeightClear.setOnClickListener {
Weigher.tareTwo(2)
}
WeightUtil.addWeightListener(getWeight = { address, state, weight ->
Log.d(TAG, "addViewClickListener: address=$address,state=$state,weight=$weight")
if (address == 2) {
tempDishEntity?.useWeight = weight
binding.tvDishPartWeight.text = "${weight}"
}
})
binding.ivWeightAdd.setOnClickListener {
if (tempDishEntity == null) {
toast("请输入食材名称")
return@setOnClickListener
}
if (binding.rgSampling.checkedRadioButtonId == -1) {
toast("请选择主辅材类型")
return@setOnClickListener
}
if (tempDishEntity!!.useWeight == null) {
toast("请将食材放在称上称重")
return@setOnClickListener
}
tempDishEntity!!.apply {
isSamplingPage = true
materialType = dishMaterialType
}
val result = list.firstOrNull { it.goodsId == tempDishEntity!!.goodsId }
if (result != null) {
toast("${result.goodsName}食材已添加,请勿重复操作")
return@setOnClickListener
}
list.add(tempDishEntity!!)
dishAdapter.notifyDataSetChanged()
tempDishEntity = null
binding.tvInputDishType.text = ""
binding.rgSampling.clearCheck()
}
binding.rgSampling.setOnCheckedChangeListener { group, checkedId ->
dishMaterialType = if (checkedId == R.id.rbDishTypeFirst) 1 else 2
}
binding.ivDishSearch.setOnClickListener { v ->
jumpSearch(v)
}
binding.btnCook.clickWithDebounce {
val showFoodName = binding.etInputDish.text.toString().trim()
if (showFoodName.isBlank()) {
toast("菜品名称为空")
return@clickWithDebounce
}
if (list.isEmpty()) {
toast("菜品构成信息未设置")
return@clickWithDebounce
}
val food = FoodRecord()
food.foodId = foodId
food.foodName = showFoodName
food.cookMode = 1
Log.d(TAG, "goToSubmit: goodsList:${list.toJsonString()}")
startActivity<SubmitDishActivity> {
putExtra(SubmitDishActivity.GOODS_LIST, list as java.io.Serializable)
putExtra(SubmitDishActivity.FOOD_ITEM, food as Serializable)
}
}
binding.etInputDish.let { v ->
v.addOnActionSearchListener {
jumpSearch(v)
}
}
}
private fun jumpSearch(v: View) {
launch(Intent(this, FoodSearchActivity::class.java).apply {
putExtra(FoodSearchActivity.FOOD_NAME, binding.etInputDish.text.toString().trim())
}) { intent ->
intent?.let {
foodId = it.getStringExtra(FoodSearchActivity.FOOD_ID)
foodName = it.getStringExtra(FoodSearchActivity.FOOD_NAME)
binding.etInputDish.run {
setText(foodName)
setSelection(text.length)
}
}
}
KeyboardUtil.hideKeyboard(v.context, v)
}
} }
@@ -39,8 +39,10 @@ class HomeActivity : BaseActivity() {
statusBarDarkFont(enable = true) statusBarDarkFont(enable = true)
initViewModel() initViewModel()
// 获取 ANDROID_ID // 获取 ANDROID_ID
BaseApp.instance?.androidId = val deviceId =
Settings.Secure.getString(contentResolver, Settings.Secure.ANDROID_ID) Settings.Secure.getString(contentResolver, Settings.Secure.ANDROID_ID)
Log.d(TAG, "onCreate: deviceId=$deviceId")
BaseApp.instance?.androidId = deviceId
binding = ActivityHomeBinding.inflate(layoutInflater) binding = ActivityHomeBinding.inflate(layoutInflater)
setContentView(binding.root) setContentView(binding.root)
@@ -1,30 +1,44 @@
package com.shuwei.dish.match.ui package com.shuwei.dish.match.ui
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.app.Dialog
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import androidx.fragment.app.Fragment import android.util.Log
import android.view.LayoutInflater
import android.view.MotionEvent
import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.LinearLayoutManager
import com.shuwei.dish.match.R import com.shuwei.dish.match.R
import com.shuwei.dish.match.adapter.SamplingAdapter
import com.shuwei.dish.match.base.BaseActivity import com.shuwei.dish.match.base.BaseActivity
import com.shuwei.dish.match.base.BaseApp import com.shuwei.dish.match.base.BaseApp
import com.shuwei.dish.match.databinding.ActivitySamplingBinding import com.shuwei.dish.match.databinding.ActivitySamplingBinding
import com.shuwei.dish.match.databinding.LayoutEmptyViewBinding
import com.shuwei.dish.match.db.AppRepository import com.shuwei.dish.match.db.AppRepository
import com.shuwei.dish.match.entity.CookFoodEntity import com.shuwei.dish.match.entity.CookFoodEntity
import com.shuwei.dish.match.ui.fragment.SamplingListFragment import com.shuwei.dish.match.entity.FoodRecord
import com.shuwei.dish.match.entity.FoodRecordBean
import com.shuwei.dish.match.http.HttpUtil
import com.shuwei.dish.match.http.UrlConfig
import com.shuwei.dish.match.utils.DateTimeUtil
import com.shuwei.dish.match.utils.SwipeCallback
import com.shuwei.dish.match.utils.ext.gone import com.shuwei.dish.match.utils.ext.gone
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.toObject
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 com.shuwei.dish.match.utils.ext.visible
import com.shuwei.dish.match.viewmodel.AppViewModel import com.shuwei.dish.match.viewmodel.AppViewModel
import com.shuwei.dish.match.viewmodel.factory.AppFactory import com.shuwei.dish.match.viewmodel.factory.AppFactory
import java.io.Serializable
class SamplingListActivity : BaseActivity() { class SamplingListActivity : BaseActivity() {
private lateinit var binding: ActivitySamplingBinding private lateinit var binding: ActivitySamplingBinding
companion object { companion object {
private const val TAG = "SamplingListActivity"
const val IS_COOKING = "isCooking" const val IS_COOKING = "isCooking"
} }
@@ -35,9 +49,12 @@ class SamplingListActivity : BaseActivity() {
setTitleBar() setTitleBar()
setHeaderBackground() setHeaderBackground()
initViewModel() initViewModel()
loadSamplingListPage() initRecyclerView()
addViewListener()
requestData(true)
} }
private fun setTitleBar() { private fun setTitleBar() {
setTitleBar(titleBarAction = { setTitleBar(titleBarAction = {
it.visible() it.visible()
@@ -58,24 +75,6 @@ class SamplingListActivity : BaseActivity() {
} }
private var samplingListFragment: SamplingListFragment? = null
private fun loadSamplingListPage() {
if (samplingListFragment == null) {
samplingListFragment = SamplingListFragment()
}
samplingListFragment?.let {
loadFragment(it)
}
}
private fun loadFragment(fragment: Fragment) {
supportFragmentManager.beginTransaction().apply {
replace(R.id.flContainer, fragment)
commit()
}
}
private lateinit var appViewModel: AppViewModel private lateinit var appViewModel: AppViewModel
private fun initViewModel() { private fun initViewModel() {
@@ -97,7 +96,8 @@ class SamplingListActivity : BaseActivity() {
override fun onNewIntent(intent: Intent?) { override fun onNewIntent(intent: Intent?) {
super.onNewIntent(intent) super.onNewIntent(intent)
val isCooking = intent?.getBooleanExtra(IS_COOKING, false) ?: false val isCooking = intent?.getBooleanExtra(IS_COOKING, false) ?: false
samplingListFragment?.refreshPage(isCooking) //toast("isCooking=$isCooking")
refreshPage(isCooking)
} }
@Deprecated("Deprecated in Java") @Deprecated("Deprecated in Java")
@@ -108,4 +108,253 @@ class SamplingListActivity : BaseActivity() {
//dialog = toast("不允许返回操作") //dialog = toast("不允许返回操作")
} }
private var list: MutableList<FoodRecord> = mutableListOf()
private val dishAdapter by lazy {
SamplingAdapter(list = list).apply {
isStateViewEnable = true
setOnItemClickListener { adapter, view, position ->
val item = list[position]
if (item.isCooking) {
//烹饪中,跳到称熟重页面
context.startActivity<SubmitDishActivity> {
putExtra(
SubmitDishActivity.FOOD_ITEM,
item as Serializable
)
}
return@setOnItemClickListener
}
context.startActivity<DishSamplingActivity> {
putExtra(DishSamplingActivity.FOOD_NAME, item.foodName)
}
}
}
}
@SuppressLint("NotifyDataSetChanged")
private fun initRecyclerView() {
binding.rvSamplingList.run {
layoutManager =
LinearLayoutManager(this@SamplingListActivity, LinearLayoutManager.VERTICAL, false)
adapter = dishAdapter
val itemTouchHelper = ItemTouchHelper(SwipeCallback(dishAdapter) { position ->
if (list[position].isCooking.not()) {
toast("只能删除烹饪中的菜品")
dishAdapter.notifyItemChanged(position)
return@SwipeCallback
}
deleteCookFoodAndGoods(foodId = list[position].foodId ?: "") {
if (list.size > 1) {
dishAdapter.removeAt(position)
} else {
loadEmptyView()
}
toast("已删除")
}
})
itemTouchHelper.attachToRecyclerView(this)
}
}
@SuppressLint("ClickableViewAccessibility")
private fun addViewListener() {
binding.btnAddSampling.setOnClickListener {
startActivity<DishSamplingActivity>()
}
binding.refreshLayout.setOnRefreshListener {
pageNo = 1
getSamplingList()
}
binding.refreshLayout.setOnLoadMoreListener {
getSamplingList()
}
binding.dishRadioGroup.setOnCheckedChangeListener { group, checkedId ->
//Log.d(TAG, "addViewListener: checkId=${if (checkedId == R.id.rbSamplingCooking) "cooking" else "finish"}")
// if (!group.isPressed) return@setOnCheckedChangeListener
// if (checkedId == R.id.rbSamplingCooking) {
// refreshLocalData()
// } else {
// pageNo = 1
// getSamplingList()
// }
}
binding.rbSamplingCooking.setOnClickListener {
// Log.d(TAG, "addViewListener: cooking:${binding.rbSamplingCooking.isChecked}")
if (it.tag == true) {
return@setOnClickListener
}
requestData(true)
binding.rbSamplingCooking.tag = binding.rbSamplingCooking.isChecked
binding.rbSamplingFinished.tag = binding.rbSamplingFinished.isChecked
}
binding.rbSamplingFinished.setOnClickListener {
// Log.d(TAG, "addViewListener: finish:${binding.rbSamplingFinished.isChecked}")
if (it.tag == true) {
return@setOnClickListener
}
requestData(false)
binding.rbSamplingCooking.tag = binding.rbSamplingCooking.isChecked
binding.rbSamplingFinished.tag = binding.rbSamplingFinished.isChecked
}
}
var pageNo = 1
private val pageSize = 30
@SuppressLint("NotifyDataSetChanged")
fun getSamplingList() {
showLoading()
val map = mapOf(
// "foodName" to input,
"pageNo" to "$pageNo",
"pageSize" to "$pageSize",
"canteenId" to "0"
)
val sb = StringBuilder(UrlConfig.SAMPLING_LIST).apply {
append("?")
map.forEach { (key, value) -> append("$key=$value&") }
}
sb.deleteCharAt(sb.length - 1)
HttpUtil.get(
url = sb.toString(),
doSuccess = {
binding.refreshLayout.run {
setEnableRefresh(true)
}
delayDismissLoading()
finishRefresh()
val json = it.toJsonString()
val recordBean: FoodRecordBean? = json.toObject<FoodRecordBean>()
if (recordBean == null || recordBean.records.isNullOrEmpty()) {
//toast("暂未搜索到相关菜品信息")
if (pageNo == 1) {
loadEmptyView()
}
return@get
}
val records = recordBean.records
if (pageNo == 1) {
list.clear()
}
list.addAll(records!!)
dishAdapter.notifyDataSetChanged()
val isLoadMoreEnable = records.size >= pageSize
binding.refreshLayout.setEnableLoadMore(isLoadMoreEnable)
binding.refreshLayout.setEnableRefresh(true)
if (isLoadMoreEnable) {
pageNo++
}
}, doFailure = { code, msg ->
binding.refreshLayout.run {
setEnableRefresh(true)
}
toast(msg)
finishRefresh()
binding.refreshLayout.setEnableRefresh(true)
delayDismissLoading()
if (pageNo == 1) {
loadEmptyView()
}
})
}
private fun finishRefresh() {
if (pageNo == 1) {
binding.refreshLayout.finishRefresh(1200)
} else {
binding.refreshLayout.finishLoadMore(1200)
}
}
private var emptyViewBinding: LayoutEmptyViewBinding? = null
@SuppressLint("NotifyDataSetChanged")
private fun loadEmptyView() {
list.clear()
dishAdapter.notifyDataSetChanged()
if (emptyViewBinding == null) {
emptyViewBinding = LayoutEmptyViewBinding.inflate(
LayoutInflater.from(this),
binding.rvSamplingList,
false
)
}
emptyViewBinding!!.tvContent.text = "暂无数据"
emptyViewBinding!!.tvSubContent.text = "今日暂无采样数据,点击下方按钮新增采样"
dishAdapter.stateView = emptyViewBinding!!.root
//dishAdapter.setStateViewLayout(requireContext(), R.layout.layout_empty_view)
binding.refreshLayout.run {
setEnableRefresh(binding.dishRadioGroup.checkedRadioButtonId == R.id.rbSamplingFinished)
setEnableLoadMore(false)
}
}
fun refreshPage(isCooking: Boolean) {
val checkedId = binding.dishRadioGroup.checkedRadioButtonId
if (checkedId == R.id.rbSamplingFinished) {
//当前是已采样
if (isCooking) {
//需要切换到烹饪中
binding.dishRadioGroup.check(R.id.rbSamplingCooking)
requestData(true)
return
}
//需要切换到已采样,刷新数据
requestData(false)
return
}
//当前是烹饪中
if (isCooking.not()) {
//需要切换到已采样
binding.dishRadioGroup.check(R.id.rbSamplingFinished)
requestData(false)
return
}
//需要切换到烹饪中,刷新数据
requestData(true)
}
@SuppressLint("NotifyDataSetChanged")
fun refreshLocalData() {
showLoading()
//查询本地数据
getCookFoodList { cookFoodEntities ->
delayDismissLoading()
if (cookFoodEntities.isNullOrEmpty()) {
loadEmptyView()
return@getCookFoodList
}
val tempList = mutableListOf<FoodRecord>()
cookFoodEntities
.sortedByDescending { DateTimeUtil.convert(dateStr = it.createTime) }
.forEach { entity ->
tempList.add(FoodRecord().apply {
foodId = entity.foodId
foodName = entity.foodName
cookMode = 1
isCooking = true
})
}
list.clear()
list.addAll(tempList)
dishAdapter.notifyDataSetChanged()
binding.refreshLayout.run {
setEnableRefresh(false)
setEnableLoadMore(false)
}
}
}
private fun requestData(isCooking: Boolean) {
if (isCooking) {
refreshLocalData()
} else {
pageNo = 1
getSamplingList()
}
}
} }
@@ -231,6 +231,16 @@ class DishListFragment : Fragment() {
food.isCooking = true food.isCooking = true
food.sort = index food.sort = index
tempList.add(food) tempList.add(food)
} else {
//当前查询到的list不包括本地数据id,可能数据在很多页以后了,暂时只能直接构造数据
tempList.add(
FoodRecord(
foodId = entity.foodId,
foodName = entity.foodName,
sort = index,
isCooking = true
)
)
} }
} }
list.removeAll(tempList) list.removeAll(tempList)
@@ -1,187 +1,187 @@
package com.shuwei.dish.match.ui.fragment //package com.shuwei.dish.match.ui.fragment
//
import android.annotation.SuppressLint //import android.annotation.SuppressLint
import android.content.Intent //import android.content.Intent
import android.os.Bundle //import android.os.Bundle
import android.util.Log //import android.util.Log
import android.view.LayoutInflater //import android.view.LayoutInflater
import android.view.View //import android.view.View
import android.view.ViewGroup //import android.view.ViewGroup
import androidx.fragment.app.Fragment //import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager //import androidx.recyclerview.widget.LinearLayoutManager
import com.aithings.Weigher //import com.aithings.Weigher
import com.shuwei.dish.match.R //import com.shuwei.dish.match.R
import com.shuwei.dish.match.adapter.DishPartAdapter //import com.shuwei.dish.match.adapter.DishPartAdapter
import com.shuwei.dish.match.databinding.FragmentDishSamplingBinding //import com.shuwei.dish.match.databinding.FragmentDishSamplingBinding
import com.shuwei.dish.match.dialog.BottomDialog //import com.shuwei.dish.match.dialog.BottomDialog
import com.shuwei.dish.match.entity.CookFoodGoodsEntity //import com.shuwei.dish.match.entity.CookFoodGoodsEntity
import com.shuwei.dish.match.entity.FoodRecord //import com.shuwei.dish.match.entity.FoodRecord
import com.shuwei.dish.match.ui.FoodSearchActivity //import com.shuwei.dish.match.ui.FoodSearchActivity
import com.shuwei.dish.match.ui.DishSamplingActivity //import com.shuwei.dish.match.ui.DishSamplingActivity
import com.shuwei.dish.match.ui.SubmitDishActivity //import com.shuwei.dish.match.ui.SubmitDishActivity
import com.shuwei.dish.match.utils.KeyboardUtil //import com.shuwei.dish.match.utils.KeyboardUtil
import com.shuwei.dish.match.utils.WeightUtil //import com.shuwei.dish.match.utils.WeightUtil
import com.shuwei.dish.match.utils.ext.addOnActionSearchListener //import com.shuwei.dish.match.utils.ext.addOnActionSearchListener
import com.shuwei.dish.match.utils.ext.clickWithDebounce //import com.shuwei.dish.match.utils.ext.clickWithDebounce
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.toast //import com.shuwei.dish.match.utils.ext.toast
import java.io.Serializable //import java.io.Serializable
//
class DishSamplingFragment : Fragment() { //class DishSamplingFragment : Fragment() {
//
private val TAG = "DishSamplingFragment" // private val TAG = "DishSamplingFragment"
//
private lateinit var activity: DishSamplingActivity // private lateinit var activity: DishSamplingActivity
private lateinit var binding: FragmentDishSamplingBinding // private lateinit var binding: FragmentDishSamplingBinding
//
val list: MutableList<CookFoodGoodsEntity> = mutableListOf() // val list: MutableList<CookFoodGoodsEntity> = mutableListOf()
//
private var tempDishEntity: CookFoodGoodsEntity? = null // private var tempDishEntity: CookFoodGoodsEntity? = null
//
private var dishMaterialType = 1 // private var dishMaterialType = 1
//
private val dishAdapter by lazy { // private val dishAdapter by lazy {
DishPartAdapter(list).apply { // DishPartAdapter(list).apply {
addOnItemChildClickListener(R.id.ivOperateIcon) { _, _, positon -> // addOnItemChildClickListener(R.id.ivOperateIcon) { _, _, positon ->
//删除操作 // //删除操作
removeAt(positon) // removeAt(positon)
} // }
} // }
} // }
//
override fun onCreateView( // override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? // inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
): View { // ): View {
binding = FragmentDishSamplingBinding.inflate(inflater, container, false) // binding = FragmentDishSamplingBinding.inflate(inflater, container, false)
return binding.root // return binding.root
} // }
//
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { // override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) // super.onViewCreated(view, savedInstanceState)
activity = requireActivity() as DishSamplingActivity // activity = requireActivity() as DishSamplingActivity
addViewClickListener() // addViewClickListener()
foodName = activity.foodName // foodName = activity.foodName
binding.etInputDish.setText(foodName) // binding.etInputDish.setText(foodName)
} // }
//
@SuppressLint("NotifyDataSetChanged") // @SuppressLint("NotifyDataSetChanged")
private fun addViewClickListener() { // private fun addViewClickListener() {
binding.rvDishPartList.run { // binding.rvDishPartList.run {
layoutManager = LinearLayoutManager(activity, LinearLayoutManager.VERTICAL, false) // layoutManager = LinearLayoutManager(activity, LinearLayoutManager.VERTICAL, false)
adapter = dishAdapter // adapter = dishAdapter
} // }
binding.tvInputDishType.run { // binding.tvInputDishType.run {
clickWithDebounce { // clickWithDebounce {
BottomDialog(goodsType = 0).show(activity) { item -> // BottomDialog(goodsType = 0).show(activity) { item ->
val filterResult = list.firstOrNull { it.goodsName == item.goodsName } // val filterResult = list.firstOrNull { it.goodsName == item.goodsName }
if (filterResult != null) { // if (filterResult != null) {
toast("不允许重复添加同一食材") // toast("不允许重复添加同一食材")
return@show // return@show
} // }
text = item.goodsName // text = item.goodsName
tempDishEntity = CookFoodGoodsEntity().apply { // tempDishEntity = CookFoodGoodsEntity().apply {
goodsId = item.goodsId // goodsId = item.goodsId
goodsName = item.goodsName // goodsName = item.goodsName
//
relateionType = item.relateionType?:0 // relateionType = item.relateionType?:0
goodsOrRelationCode = item.goodsOrRelationCode // goodsOrRelationCode = item.goodsOrRelationCode
//
// TODO: 待定 // // TODO: 待定
//allEdible = item.allEdible // //allEdible = item.allEdible
} // }
} // }
} // }
} // }
//
binding.ivWeightClear.setOnClickListener { // binding.ivWeightClear.setOnClickListener {
Weigher.tareTwo(2) // Weigher.tareTwo(2)
} // }
WeightUtil.addWeightListener(getWeight = { address, state, weight -> // WeightUtil.addWeightListener(getWeight = { address, state, weight ->
Log.d(TAG, "addViewClickListener: address=$address,state=$state,weight=$weight") // Log.d(TAG, "addViewClickListener: address=$address,state=$state,weight=$weight")
if (address == 2) { // if (address == 2) {
tempDishEntity?.useWeight = weight // tempDishEntity?.useWeight = weight
binding.tvDishPartWeight.text = "${weight}" // binding.tvDishPartWeight.text = "${weight}"
} // }
}) // })
binding.ivWeightAdd.setOnClickListener { // binding.ivWeightAdd.setOnClickListener {
if (tempDishEntity == null) { // if (tempDishEntity == null) {
activity.toast("请输入食材名称") // activity.toast("请输入食材名称")
return@setOnClickListener // return@setOnClickListener
} // }
if (binding.rgSampling.checkedRadioButtonId == -1) { // if (binding.rgSampling.checkedRadioButtonId == -1) {
activity.toast("请选择主辅材类型") // activity.toast("请选择主辅材类型")
return@setOnClickListener // return@setOnClickListener
} // }
if (tempDishEntity!!.useWeight == null) { // if (tempDishEntity!!.useWeight == null) {
activity.toast("请将食材放在称上称重") // activity.toast("请将食材放在称上称重")
return@setOnClickListener // return@setOnClickListener
} // }
tempDishEntity!!.apply { // tempDishEntity!!.apply {
isSamplingPage = true // isSamplingPage = true
materialType = dishMaterialType // materialType = dishMaterialType
} // }
val result = list.firstOrNull { it.goodsId == tempDishEntity!!.goodsId } // val result = list.firstOrNull { it.goodsId == tempDishEntity!!.goodsId }
if (result != null) { // if (result != null) {
activity.toast("${result.goodsName}食材已添加,请勿重复操作") // activity.toast("${result.goodsName}食材已添加,请勿重复操作")
return@setOnClickListener // return@setOnClickListener
} // }
list.add(tempDishEntity!!) // list.add(tempDishEntity!!)
dishAdapter.notifyDataSetChanged() // dishAdapter.notifyDataSetChanged()
tempDishEntity = null // tempDishEntity = null
binding.tvInputDishType.text = "" // binding.tvInputDishType.text = ""
binding.rgSampling.clearCheck() // binding.rgSampling.clearCheck()
} // }
binding.rgSampling.setOnCheckedChangeListener { group, checkedId -> // binding.rgSampling.setOnCheckedChangeListener { group, checkedId ->
dishMaterialType = if (checkedId == R.id.rbDishTypeFirst) 1 else 2 // dishMaterialType = if (checkedId == R.id.rbDishTypeFirst) 1 else 2
} // }
binding.ivDishSearch.setOnClickListener { v -> // binding.ivDishSearch.setOnClickListener { v ->
jumpSearch(v) // jumpSearch(v)
} // }
binding.btnCook.clickWithDebounce { // binding.btnCook.clickWithDebounce {
val showFoodName = binding.etInputDish.text.toString().trim() // val showFoodName = binding.etInputDish.text.toString().trim()
if (showFoodName.isBlank()) { // if (showFoodName.isBlank()) {
toast("菜品名称为空") // toast("菜品名称为空")
return@clickWithDebounce // return@clickWithDebounce
} // }
if (list.isEmpty()) { // if (list.isEmpty()) {
toast("菜品构成信息未设置") // toast("菜品构成信息未设置")
return@clickWithDebounce // return@clickWithDebounce
} // }
val food = FoodRecord() // val food = FoodRecord()
food.foodId = foodId // food.foodId = foodId
food.foodName = showFoodName // food.foodName = showFoodName
food.cookMode = 1 // food.cookMode = 1
Log.d(TAG, "goToSubmit: goodsList:${list.toJsonString()}") // Log.d(TAG, "goToSubmit: goodsList:${list.toJsonString()}")
activity.startActivity<SubmitDishActivity> { // activity.startActivity<SubmitDishActivity> {
putExtra(SubmitDishActivity.GOODS_LIST, list as Serializable) // putExtra(SubmitDishActivity.GOODS_LIST, list as Serializable)
putExtra(SubmitDishActivity.FOOD_ITEM, food as Serializable) // putExtra(SubmitDishActivity.FOOD_ITEM, food as Serializable)
} // }
} // }
binding.etInputDish.let { v -> // binding.etInputDish.let { v ->
v.addOnActionSearchListener { // v.addOnActionSearchListener {
jumpSearch(v) // jumpSearch(v)
} // }
} // }
} // }
//
private fun jumpSearch(v: View) { // private fun jumpSearch(v: View) {
activity.launch(Intent(activity, FoodSearchActivity::class.java).apply { // activity.launch(Intent(activity, FoodSearchActivity::class.java).apply {
putExtra(FoodSearchActivity.FOOD_NAME, binding.etInputDish.text.toString().trim() ) // putExtra(FoodSearchActivity.FOOD_NAME, binding.etInputDish.text.toString().trim() )
}) { intent -> // }) { intent ->
intent?.let { // intent?.let {
foodId = it.getStringExtra(FoodSearchActivity.FOOD_ID) // foodId = it.getStringExtra(FoodSearchActivity.FOOD_ID)
foodName = it.getStringExtra(FoodSearchActivity.FOOD_NAME) // foodName = it.getStringExtra(FoodSearchActivity.FOOD_NAME)
binding.etInputDish.run { // binding.etInputDish.run {
setText(foodName) // setText(foodName)
setSelection(text.length) // setSelection(text.length)
} // }
} // }
} // }
KeyboardUtil.hideKeyboard(v.context, v) // KeyboardUtil.hideKeyboard(v.context, v)
} // }
//
//
private var foodId: String? = null // private var foodId: String? = null
private var foodName: String? = null // private var foodName: String? = null
} //}
@@ -1,254 +1,254 @@
package com.shuwei.dish.match.ui.fragment //package com.shuwei.dish.match.ui.fragment
//
import android.annotation.SuppressLint //import android.annotation.SuppressLint
import android.os.Bundle //import android.os.Bundle
import android.view.LayoutInflater //import android.view.LayoutInflater
import android.view.View //import android.view.View
import android.view.ViewGroup //import android.view.ViewGroup
import androidx.fragment.app.Fragment //import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.ItemTouchHelper //import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.LinearLayoutManager //import androidx.recyclerview.widget.LinearLayoutManager
import com.shuwei.dish.match.R //import com.shuwei.dish.match.R
import com.shuwei.dish.match.adapter.SamplingAdapter //import com.shuwei.dish.match.adapter.SamplingAdapter
import com.shuwei.dish.match.databinding.FragmentSamplingListBinding //import com.shuwei.dish.match.databinding.FragmentSamplingListBinding
import com.shuwei.dish.match.databinding.LayoutEmptyViewBinding //import com.shuwei.dish.match.databinding.LayoutEmptyViewBinding
//
import com.shuwei.dish.match.entity.FoodRecord //import com.shuwei.dish.match.entity.FoodRecord
import com.shuwei.dish.match.entity.FoodRecordBean //import com.shuwei.dish.match.entity.FoodRecordBean
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.DishSamplingActivity //import com.shuwei.dish.match.ui.DishSamplingActivity
import com.shuwei.dish.match.ui.SamplingListActivity //import com.shuwei.dish.match.ui.SamplingListActivity
import com.shuwei.dish.match.ui.SubmitDishActivity //import com.shuwei.dish.match.ui.SubmitDishActivity
import com.shuwei.dish.match.utils.DateTimeUtil //import com.shuwei.dish.match.utils.DateTimeUtil
import com.shuwei.dish.match.utils.SwipeCallback //import com.shuwei.dish.match.utils.SwipeCallback
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.toObject //import com.shuwei.dish.match.utils.ext.toObject
import com.shuwei.dish.match.utils.ext.toast //import com.shuwei.dish.match.utils.ext.toast
import java.io.Serializable //import java.io.Serializable
//
class SamplingListFragment : Fragment() { //class SamplingListFragment : Fragment() {
//
companion object { // companion object {
private const val TAG = "SamplingListFragment" // private const val TAG = "SamplingListFragment"
} // }
//
private lateinit var activity: SamplingListActivity // private lateinit var activity: SamplingListActivity
private lateinit var binding: FragmentSamplingListBinding // private lateinit var binding: FragmentSamplingListBinding
//
private var list: MutableList<FoodRecord> = mutableListOf() // private var list: MutableList<FoodRecord> = mutableListOf()
private val dishAdapter by lazy { // private val dishAdapter by lazy {
SamplingAdapter(list = list).apply { // SamplingAdapter(list = list).apply {
isStateViewEnable = true // isStateViewEnable = true
setOnItemClickListener { adapter, view, position -> // setOnItemClickListener { adapter, view, position ->
val item = list[position] // val item = list[position]
if (item.isCooking) { // if (item.isCooking) {
//烹饪中,跳到称熟重页面 // //烹饪中,跳到称熟重页面
context.startActivity<SubmitDishActivity> { // context.startActivity<SubmitDishActivity> {
putExtra( // putExtra(
SubmitDishActivity.FOOD_ITEM, // SubmitDishActivity.FOOD_ITEM,
item as Serializable // item as Serializable
) // )
} // }
return@setOnItemClickListener // return@setOnItemClickListener
} // }
context.startActivity<DishSamplingActivity> { // context.startActivity<DishSamplingActivity> {
putExtra(DishSamplingActivity.FOOD_NAME, item.foodName) // putExtra(DishSamplingActivity.FOOD_NAME, item.foodName)
} // }
} // }
} // }
} // }
//
@SuppressLint("NotifyDataSetChanged") // @SuppressLint("NotifyDataSetChanged")
private fun initRecyclerView() { // private fun initRecyclerView() {
binding.rvSamplingList.run { // binding.rvSamplingList.run {
layoutManager = // layoutManager =
LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false) // LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false)
adapter = dishAdapter // adapter = dishAdapter
val itemTouchHelper = ItemTouchHelper(SwipeCallback(dishAdapter) { position -> // val itemTouchHelper = ItemTouchHelper(SwipeCallback(dishAdapter) { position ->
if (list[position].isCooking.not()) { // if (list[position].isCooking.not()) {
activity.toast("只能删除烹饪中的菜品") // activity.toast("只能删除烹饪中的菜品")
dishAdapter.notifyItemChanged(position) // dishAdapter.notifyItemChanged(position)
return@SwipeCallback // return@SwipeCallback
} // }
activity.deleteCookFoodAndGoods(foodId = list[position].foodId?:"") { // activity.deleteCookFoodAndGoods(foodId = list[position].foodId?:"") {
if (list.size > 1) { // if (list.size > 1) {
dishAdapter.removeAt(position) // dishAdapter.removeAt(position)
} else { // } else {
loadEmptyView() // loadEmptyView()
} // }
activity.toast("已删除") // activity.toast("已删除")
} // }
}) // })
itemTouchHelper.attachToRecyclerView(this) // itemTouchHelper.attachToRecyclerView(this)
} // }
} // }
//
private fun addViewListener() { // private fun addViewListener() {
binding.btnAddSampling.setOnClickListener { // binding.btnAddSampling.setOnClickListener {
activity.startActivity<DishSamplingActivity>() // activity.startActivity<DishSamplingActivity>()
} // }
binding.refreshLayout.setOnRefreshListener { // binding.refreshLayout.setOnRefreshListener {
pageNo = 1 // pageNo = 1
getSamplingList() // getSamplingList()
} // }
binding.refreshLayout.setOnLoadMoreListener { // binding.refreshLayout.setOnLoadMoreListener {
getSamplingList() // getSamplingList()
} // }
binding.dishRadioGroup.setOnCheckedChangeListener { group, checkedId -> // binding.dishRadioGroup.setOnCheckedChangeListener { group, checkedId ->
if (checkedId == R.id.rbCooking) { // if (checkedId == R.id.rbCooking) {
refreshLocalData() // refreshLocalData()
} else { // } else {
pageNo = 1 // pageNo = 1
getSamplingList() // getSamplingList()
} // }
} // }
} // }
//
override fun onCreateView( // override fun onCreateView(
inflater: LayoutInflater, // inflater: LayoutInflater,
container: ViewGroup?, // container: ViewGroup?,
savedInstanceState: Bundle? // savedInstanceState: Bundle?
): View { // ): View {
binding = FragmentSamplingListBinding.inflate(inflater, container, false) // binding = FragmentSamplingListBinding.inflate(inflater, container, false)
return binding.root // return binding.root
} // }
//
@SuppressLint("NotifyDataSetChanged") // @SuppressLint("NotifyDataSetChanged")
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { // override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) // super.onViewCreated(view, savedInstanceState)
activity = requireActivity() as SamplingListActivity // activity = requireActivity() as SamplingListActivity
initRecyclerView() // initRecyclerView()
addViewListener() // addViewListener()
refreshLocalData() // refreshLocalData()
} // }
//
var pageNo = 1 // var pageNo = 1
private val pageSize = 30 // private val pageSize = 30
//
@SuppressLint("NotifyDataSetChanged") // @SuppressLint("NotifyDataSetChanged")
fun getSamplingList() { // fun getSamplingList() {
activity.showLoading() // activity.showLoading()
val map = mapOf( // val map = mapOf(
// "foodName" to input, //// "foodName" to input,
"pageNo" to "$pageNo", // "pageNo" to "$pageNo",
"pageSize" to "$pageSize", // "pageSize" to "$pageSize",
"canteenId" to "0" // "canteenId" to "0"
) // )
val sb = StringBuilder(UrlConfig.SAMPLING_LIST).apply { // val sb = StringBuilder(UrlConfig.SAMPLING_LIST).apply {
append("?") // append("?")
map.forEach { (key, value) -> append("$key=$value&") } // map.forEach { (key, value) -> append("$key=$value&") }
} // }
sb.deleteCharAt(sb.length - 1) // sb.deleteCharAt(sb.length - 1)
HttpUtil.get( // HttpUtil.get(
url = sb.toString(), // url = sb.toString(),
doSuccess = { // doSuccess = {
binding.refreshLayout.run { // binding.refreshLayout.run {
setEnableRefresh(true) // setEnableRefresh(true)
} // }
activity.delayDismissLoading() // activity.delayDismissLoading()
finishRefresh() // finishRefresh()
val json = it.toJsonString() // val json = it.toJsonString()
val recordBean: FoodRecordBean? = json.toObject<FoodRecordBean>() // val recordBean: FoodRecordBean? = json.toObject<FoodRecordBean>()
if (recordBean == null || recordBean.records.isNullOrEmpty()) { // if (recordBean == null || recordBean.records.isNullOrEmpty()) {
//toast("暂未搜索到相关菜品信息") // //toast("暂未搜索到相关菜品信息")
if (pageNo == 1) { // if (pageNo == 1) {
loadEmptyView() // loadEmptyView()
} // }
return@get // return@get
} // }
val records = recordBean.records // val records = recordBean.records
if (pageNo == 1) { // if (pageNo == 1) {
list.clear() // list.clear()
} // }
list.addAll(records!!) // list.addAll(records!!)
dishAdapter.notifyDataSetChanged() // dishAdapter.notifyDataSetChanged()
val isLoadMoreEnable = records.size >= pageSize // val isLoadMoreEnable = records.size >= pageSize
binding.refreshLayout.setEnableLoadMore(isLoadMoreEnable) // binding.refreshLayout.setEnableLoadMore(isLoadMoreEnable)
binding.refreshLayout.setEnableRefresh(true) // binding.refreshLayout.setEnableRefresh(true)
if (isLoadMoreEnable) { // if (isLoadMoreEnable) {
pageNo++ // pageNo++
} // }
}, doFailure = { code, msg -> // }, doFailure = { code, msg ->
binding.refreshLayout.run { // binding.refreshLayout.run {
setEnableRefresh(true) // setEnableRefresh(true)
} // }
toast(msg) // toast(msg)
finishRefresh() // finishRefresh()
binding.refreshLayout.setEnableRefresh(true) // binding.refreshLayout.setEnableRefresh(true)
activity.delayDismissLoading() // activity.delayDismissLoading()
if (pageNo == 1) { // if (pageNo == 1) {
loadEmptyView() // loadEmptyView()
} // }
}) // })
} // }
//
private fun finishRefresh() { // private fun finishRefresh() {
if (pageNo == 1) { // if (pageNo == 1) {
binding.refreshLayout.finishRefresh(1200) // binding.refreshLayout.finishRefresh(1200)
} else { // } else {
binding.refreshLayout.finishLoadMore(1200) // binding.refreshLayout.finishLoadMore(1200)
} // }
} // }
//
private var emptyViewBinding:LayoutEmptyViewBinding?=null // private var emptyViewBinding:LayoutEmptyViewBinding?=null
//
@SuppressLint("NotifyDataSetChanged") // @SuppressLint("NotifyDataSetChanged")
private fun loadEmptyView() { // private fun loadEmptyView() {
list.clear() // list.clear()
dishAdapter.notifyDataSetChanged() // dishAdapter.notifyDataSetChanged()
if (emptyViewBinding == null) { // if (emptyViewBinding == null) {
emptyViewBinding = LayoutEmptyViewBinding.inflate(LayoutInflater.from(requireContext()), binding.rvSamplingList, false) // emptyViewBinding = LayoutEmptyViewBinding.inflate(LayoutInflater.from(requireContext()), binding.rvSamplingList, false)
} // }
emptyViewBinding!!.tvContent.text = "暂无数据" // emptyViewBinding!!.tvContent.text = "暂无数据"
emptyViewBinding!!.tvSubContent.text = "今日暂无采样数据,点击下方按钮新增采样" // emptyViewBinding!!.tvSubContent.text = "今日暂无采样数据,点击下方按钮新增采样"
dishAdapter.stateView = emptyViewBinding!!.root // dishAdapter.stateView = emptyViewBinding!!.root
//dishAdapter.setStateViewLayout(requireContext(), R.layout.layout_empty_view) // //dishAdapter.setStateViewLayout(requireContext(), R.layout.layout_empty_view)
//
binding.refreshLayout.run { // binding.refreshLayout.run {
setEnableRefresh(false) // setEnableRefresh(false)
setEnableLoadMore(false) // setEnableLoadMore(false)
} // }
} // }
//
fun refreshPage(isCooking: Boolean) { // fun refreshPage(isCooking: Boolean) {
binding.dishRadioGroup.check( // binding.dishRadioGroup.check(
if (isCooking) R.id.rbCooking else R.id.rbFinished // if (isCooking) R.id.rbCooking else R.id.rbFinished
) // )
} // }
//
@SuppressLint("NotifyDataSetChanged") // @SuppressLint("NotifyDataSetChanged")
fun refreshLocalData() { // fun refreshLocalData() {
activity.showLoading() // activity.showLoading()
//查询本地数据 // //查询本地数据
activity.getCookFoodList { cookFoodEntities -> // activity.getCookFoodList { cookFoodEntities ->
activity.delayDismissLoading() // activity.delayDismissLoading()
if (cookFoodEntities.isNullOrEmpty()) { // if (cookFoodEntities.isNullOrEmpty()) {
loadEmptyView() // loadEmptyView()
return@getCookFoodList // return@getCookFoodList
} // }
val tempList = mutableListOf<FoodRecord>() // val tempList = mutableListOf<FoodRecord>()
//
cookFoodEntities // cookFoodEntities
.sortedByDescending { DateTimeUtil.convert(dateStr = it.createTime) } // .sortedByDescending { DateTimeUtil.convert(dateStr = it.createTime) }
.forEach { entity -> // .forEach { entity ->
tempList.add(FoodRecord().apply { // tempList.add(FoodRecord().apply {
foodId = entity.foodId // foodId = entity.foodId
foodName = entity.foodName // foodName = entity.foodName
cookMode = 1 // cookMode = 1
isCooking = true // isCooking = true
}) // })
} // }
list.clear() // list.clear()
list.addAll(tempList) // list.addAll(tempList)
dishAdapter.notifyDataSetChanged() // dishAdapter.notifyDataSetChanged()
binding.refreshLayout.run { // binding.refreshLayout.run {
setEnableRefresh(false) // setEnableRefresh(false)
setEnableLoadMore(false) // setEnableLoadMore(false)
} // }
} // }
} // }
//
//
} //}
@@ -7,6 +7,7 @@ import com.chad.library.adapter4.viewholder.QuickViewHolder
import com.shuwei.dish.match.adapter.DishPartAdapter import com.shuwei.dish.match.adapter.DishPartAdapter
import com.shuwei.dish.match.adapter.DishShowAdapter import com.shuwei.dish.match.adapter.DishShowAdapter
import com.shuwei.dish.match.adapter.SamplingAdapter import com.shuwei.dish.match.adapter.SamplingAdapter
import androidx.core.view.isEmpty
class SwipeCallback( class SwipeCallback(
private val adapter: BaseQuickAdapter<*,*>, private val adapter: BaseQuickAdapter<*,*>,
@@ -37,14 +38,23 @@ class SwipeCallback(
var swipeFlags = ItemTouchHelper.LEFT or ItemTouchHelper.RIGHT var swipeFlags = ItemTouchHelper.LEFT or ItemTouchHelper.RIGHT
if (adapter is SamplingAdapter) { if (adapter is SamplingAdapter) {
if (adapter.items.isEmpty()) {
return makeMovementFlags(0, 0)
}
if (!adapter.items[position].isCooking) { if (!adapter.items[position].isCooking) {
swipeFlags = 0 swipeFlags = 0
} }
} else if (adapter is DishShowAdapter) { } else if (adapter is DishShowAdapter) {
if (adapter.items.isEmpty()) {
return makeMovementFlags(0, 0)
}
if (!adapter.items[position].isCooking) { if (!adapter.items[position].isCooking) {
swipeFlags = 0 swipeFlags = 0
} }
} else if (adapter is DishPartAdapter) { } else if (adapter is DishPartAdapter) {
if (adapter.items.isEmpty()) {
return makeMovementFlags(0, 0)
}
if (!adapter.items[position].isNewDishType) { if (!adapter.items[position].isNewDishType) {
swipeFlags = 0 swipeFlags = 0
} }
@@ -42,16 +42,16 @@ class AppViewModel(private val rep: AppRepository) : ViewModel() {
} }
} }
fun saveCookFood(cookMode: Int, entity: CookFoodEntity) { // fun saveCookFood(cookMode: Int, entity: CookFoodEntity) {
viewModelScope.launch { // viewModelScope.launch {
val data = rep.getCookFoodById(entity.foodId, cookMode) // val data = rep.getCookFoodById(entity.foodId, cookMode)
if (data == null) { // if (data == null) {
rep.insertCookFood(entity) // rep.insertCookFood(entity)
return@launch // return@launch
} // }
rep.updateCookFood(entity) // rep.updateCookFood(entity)
} // }
} // }
fun saveCookFoodAndGoods( fun saveCookFoodAndGoods(
cookMode: Int, cookMode: Int,
@@ -68,7 +68,12 @@ class AppViewModel(private val rep: AppRepository) : ViewModel() {
} }
//重新保存数据 //重新保存数据
rep.insertCookFood(entity) rep.insertCookFood(entity)
list?.let { rep.insertGoodsList(it) } list?.let { it ->
it.forEach { goods->
goods.id = 0
}
rep.insertGoodsList(it)
}
onFinish() onFinish()
} }
} }
+1 -1
View File
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/black" android:state_checked="true" /> <item android:color="@color/black" android:state_checked="true" />
<item android:color="@color/black666" android:state_checked="false" /> <item android:color="@color/black999" android:state_checked="false" />
</selector> </selector>
@@ -0,0 +1,281 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:background="@drawable/bg_other_page">
<LinearLayout
android:id="@+id/llSearchBar"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_margin="30dp"
android:background="@drawable/shape_white_30_corners"
android:gravity="center_vertical"
android:orientation="horizontal">
<EditText
android:id="@+id/etInputDish"
android:layout_width="0dp"
android:layout_height="80dp"
android:layout_marginStart="28dp"
android:layout_weight="1"
android:autofillHints=""
android:background="@color/white"
android:gravity="center"
android:hint="@string/dish_search_hint"
android:inputType="text"
android:imeOptions="actionSearch"
android:paddingStart="3dp"
android:paddingEnd="3dp"
android:textColor="@color/black333"
android:textColorHint="@color/gray_c8"
android:textSize="40sp"
tools:ignore="TextFields" />
<ImageView
android:id="@+id/ivDishSearch"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:paddingStart="10dp"
android:paddingEnd="10dp"
android:src="@drawable/ic_search_gray"
tools:ignore="ContentDescription" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="30dp"
android:layout_marginEnd="30dp"
android:layout_marginBottom="30dp"
android:background="@drawable/shape_white_30_corners"
android:gravity="center_vertical"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="113dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="30dp"
android:layout_marginEnd="30dp"
android:layout_weight="1"
android:text="@string/dish_name"
android:textColor="@color/black666"
android:textSize="28sp" />
<TextView
android:id="@+id/tvInputDishType"
android:layout_width="wrap_content"
android:layout_height="80dp"
android:background="@color/white"
android:gravity="center_vertical|end"
android:hint="@string/dish_search_hint2"
android:textColor="@color/black333"
android:textColorHint="@color/gray_c8"
android:textSize="28sp"
android:maxLines="1"
android:ellipsize="end"
android:drawablePadding="30dp"
android:paddingEnd="30dp"
android:paddingStart="30dp"
app:drawableEndCompat="@drawable/ic_search_green" />
<!-- <ImageView-->
<!-- android:id="@+id/ivDishTypeSearch"-->
<!-- android:layout_width="62dp"-->
<!-- android:layout_height="62dp"-->
<!-- android:layout_marginStart="15dp"-->
<!-- android:layout_marginEnd="15dp"-->
<!-- android:paddingStart="15dp"-->
<!-- android:paddingEnd="15dp"-->
<!-- android:src="@drawable/ic_search_green"-->
<!-- tools:ignore="ContentDescription" />-->
</LinearLayout>
<com.google.android.material.divider.MaterialDivider
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginStart="30dp"
android:layout_marginEnd="30dp"
android:background="@color/gray_eb" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="113dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="30dp"
android:layout_marginEnd="30dp"
android:text="@string/dish_from_type"
android:textColor="@color/black666"
android:textSize="28sp" />
<RadioGroup
android:id="@+id/rgSampling"
android:layout_width="match_parent"
android:layout_height="80dp"
android:gravity="center_vertical|end"
android:orientation="horizontal">
<RadioButton
android:id="@+id/rbDishTypeFirst"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginStart="30dp"
android:background="@color/white"
android:button="@null"
android:drawableStart="@drawable/selector_dish_type"
android:drawablePadding="30dp"
android:gravity="center"
android:paddingStart="30dp"
android:paddingEnd="30dp"
android:text="@string/dish_type_first"
android:textColor="@color/dish_type_font"
android:textSize="30sp"
android:textStyle="bold" />
<RadioButton
android:id="@+id/rbDishTypeSecond"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginStart="30dp"
android:background="@color/white"
android:button="@null"
android:checked="false"
android:drawableStart="@drawable/selector_dish_type"
android:drawablePadding="30dp"
android:gravity="center"
android:paddingStart="30dp"
android:paddingEnd="30dp"
android:text="@string/dish_type_second"
android:textColor="@color/dish_type_font"
android:textSize="30sp"
android:textStyle="bold" />
</RadioGroup>
</LinearLayout>
<com.google.android.material.divider.MaterialDivider
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginStart="30dp"
android:layout_marginEnd="30dp"
android:background="@color/gray_eb" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="170dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="30dp"
android:layout_marginEnd="30dp"
android:text="@string/dish_part_weight_remind"
android:textColor="@color/black666"
android:textSize="28sp" />
<TextView
android:id="@+id/tvDishPartWeight"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_marginStart="30dp"
android:layout_weight="1"
android:autofillHints=""
android:background="@drawable/shape_white_f6_10_corners"
android:gravity="center"
android:hint="-"
android:maxLines="1"
android:paddingStart="20dp"
android:paddingEnd="20dp"
android:text=""
android:textColor="@color/dish_green"
android:textColorHint="@color/gray_d6"
android:textSize="60sp"
tools:ignore="HardcodedText" />
<ImageView
android:id="@+id/ivWeightClear"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_marginStart="30dp"
android:src="@drawable/ic_weight_clear"
tools:ignore="ContentDescription" />
<ImageView
android:id="@+id/ivWeightAdd"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_marginStart="30dp"
android:layout_marginEnd="30dp"
android:src="@drawable/ic_weight_add"
tools:ignore="ContentDescription" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginStart="30dp"
android:layout_marginTop="30dp"
android:layout_marginEnd="30dp"
android:layout_weight="1"
android:background="@drawable/shape_white_30_corners"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="30dp"
android:layout_marginTop="40dp"
android:layout_marginBottom="40dp"
android:text="@string/dish_composition"
android:textColor="@color/black666"
android:textSize="28sp" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rvDishPartList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:overScrollMode="never"
tools:itemCount="3"
tools:listitem="@layout/list_item_dish_cook" />
</LinearLayout>
<TextView
android:id="@+id/btnCook"
android:layout_width="match_parent"
android:layout_height="90dp"
android:layout_margin="30dp"
android:gravity="center"
android:text="@string/goCooking"
android:textColor="@color/white"
android:textSize="32sp"
android:textStyle="bold"
android:background="@drawable/ripple_effect_green"
android:clickable="true" />
<!-- android:background="@drawable/shape_green_bg"-->
<!-- android:background="?attr/selectableItemBackground"-->
<!-- android:clickable="true"-->
</LinearLayout>
+103 -3
View File
@@ -1,5 +1,105 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/flContainer" 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:orientation="vertical"
tools:background="@drawable/bg_other_page">
<RadioGroup
android:id="@+id/dishRadioGroup"
android:layout_width="match_parent"
android:layout_height="88dp"
android:layout_marginTop="15dp"
android:orientation="horizontal">
<RadioButton
android:id="@+id/rbSamplingCooking"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginStart="30dp"
android:layout_weight="1"
android:background="@drawable/breakfast_bg"
android:button="@null"
android:checked="true"
android:gravity="center"
android:text="@string/rb_sampling_cooking"
android:textColor="@color/breakfast_font"
android:textSize="30sp"
android:textStyle="bold" />
<RadioButton
android:id="@+id/rbSamplingFinished"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginStart="9dp"
android:layout_marginEnd="30dp"
android:layout_weight="1"
android:background="@drawable/breakfast_bg"
android:button="@null"
android:checked="false"
android:gravity="center"
android:text="@string/rb_sampling_finished"
android:textColor="@color/breakfast_font"
android:textSize="30sp"
android:textStyle="bold" />
</RadioGroup>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical"
android:layout_marginTop="30dp"
android:layout_marginStart="30dp"
android:layout_marginEnd="30dp"
android:background="@drawable/shape_white_30_corners">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/dish_list"
android:textColor="@color/black666"
android:textSize="28sp"
android:visibility="gone"/>
<com.scwang.smart.refresh.layout.SmartRefreshLayout
android:id="@+id/refreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="8dp"
android:layout_marginBottom="7dp">
<com.scwang.smart.refresh.header.ClassicsHeader
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rvSamplingList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:overScrollMode="never"
tools:listitem="@layout/list_item_dish" />
<com.scwang.smart.refresh.footer.ClassicsFooter
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.scwang.smart.refresh.layout.SmartRefreshLayout>
</LinearLayout>
<TextView
android:id="@+id/btnAddSampling"
android:layout_width="match_parent"
android:layout_height="90dp"
android:layout_margin="30dp"
android:background="@drawable/ripple_effect_green"
android:gravity="center"
android:text="@string/add_sampling"
android:textColor="@color/white"
android:textSize="32sp"
android:textStyle="bold" />
</LinearLayout>
@@ -6,100 +6,100 @@
android:orientation="vertical" android:orientation="vertical"
tools:background="@drawable/bg_other_page"> tools:background="@drawable/bg_other_page">
<RadioGroup <!-- <RadioGroup-->
android:id="@+id/dishRadioGroup" <!-- android:id="@+id/dishRadioGroup"-->
android:layout_width="match_parent" <!-- android:layout_width="match_parent"-->
android:layout_height="88dp" <!-- android:layout_height="88dp"-->
android:layout_marginTop="15dp" <!-- android:layout_marginTop="15dp"-->
android:orientation="horizontal"> <!-- android:orientation="horizontal">-->
<RadioButton <!-- <RadioButton-->
android:id="@+id/rbCooking" <!-- android:id="@+id/rbCooking"-->
android:layout_width="0dp" <!-- android:layout_width="0dp"-->
android:layout_height="match_parent" <!-- android:layout_height="match_parent"-->
android:layout_marginStart="30dp" <!-- android:layout_marginStart="30dp"-->
android:layout_weight="1" <!-- android:layout_weight="1"-->
android:background="@drawable/breakfast_bg" <!-- android:background="@drawable/breakfast_bg"-->
android:button="@null" <!-- android:button="@null"-->
android:checked="true" <!-- android:checked="true"-->
android:gravity="center" <!-- android:gravity="center"-->
android:text="@string/rb_sampling_cooking" <!-- android:text="@string/rb_sampling_cooking"-->
android:textColor="@color/breakfast_font" <!-- android:textColor="@color/breakfast_font"-->
android:textSize="30sp" <!-- android:textSize="30sp"-->
android:textStyle="bold" /> <!-- android:textStyle="bold" />-->
<RadioButton <!-- <RadioButton-->
android:id="@+id/rbFinished" <!-- android:id="@+id/rbFinished"-->
android:layout_width="0dp" <!-- android:layout_width="0dp"-->
android:layout_height="match_parent" <!-- android:layout_height="match_parent"-->
android:layout_marginStart="9dp" <!-- android:layout_marginStart="9dp"-->
android:layout_marginEnd="30dp" <!-- android:layout_marginEnd="30dp"-->
android:layout_weight="1" <!-- android:layout_weight="1"-->
android:background="@drawable/breakfast_bg" <!-- android:background="@drawable/breakfast_bg"-->
android:button="@null" <!-- android:button="@null"-->
android:checked="false" <!-- android:checked="false"-->
android:gravity="center" <!-- android:gravity="center"-->
android:text="@string/rb_sampling_finished" <!-- android:text="@string/rb_sampling_finished"-->
android:textColor="@color/breakfast_font" <!-- android:textColor="@color/breakfast_font"-->
android:textSize="30sp" <!-- android:textSize="30sp"-->
android:textStyle="bold" /> <!-- android:textStyle="bold" />-->
</RadioGroup> <!-- </RadioGroup>-->
<LinearLayout <!-- <LinearLayout-->
android:layout_width="match_parent" <!-- android:layout_width="match_parent"-->
android:layout_height="0dp" <!-- android:layout_height="0dp"-->
android:layout_weight="1" <!-- android:layout_weight="1"-->
android:orientation="vertical" <!-- android:orientation="vertical"-->
android:layout_marginTop="30dp" <!-- android:layout_marginTop="30dp"-->
android:layout_marginStart="30dp" <!-- android:layout_marginStart="30dp"-->
android:layout_marginEnd="30dp" <!-- android:layout_marginEnd="30dp"-->
android:background="@drawable/shape_white_30_corners"> <!-- android:background="@drawable/shape_white_30_corners">-->
<TextView <!-- <TextView-->
android:layout_width="wrap_content" <!-- android:layout_width="wrap_content"-->
android:layout_height="wrap_content" <!-- android:layout_height="wrap_content"-->
android:text="@string/dish_list" <!-- android:text="@string/dish_list"-->
android:textColor="@color/black666" <!-- android:textColor="@color/black666"-->
android:textSize="28sp" <!-- android:textSize="28sp"-->
android:visibility="gone"/> <!-- android:visibility="gone"/>-->
<com.scwang.smart.refresh.layout.SmartRefreshLayout <!-- <com.scwang.smart.refresh.layout.SmartRefreshLayout-->
android:id="@+id/refreshLayout" <!-- android:id="@+id/refreshLayout"-->
android:layout_width="match_parent" <!-- android:layout_width="match_parent"-->
android:layout_height="match_parent" <!-- android:layout_height="match_parent"-->
android:layout_marginTop="8dp" <!-- android:layout_marginTop="8dp"-->
android:layout_marginBottom="7dp"> <!-- android:layout_marginBottom="7dp">-->
<com.scwang.smart.refresh.header.ClassicsHeader <!-- <com.scwang.smart.refresh.header.ClassicsHeader-->
android:layout_width="match_parent" <!-- android:layout_width="match_parent"-->
android:layout_height="wrap_content" /> <!-- android:layout_height="wrap_content" />-->
<androidx.recyclerview.widget.RecyclerView <!-- <androidx.recyclerview.widget.RecyclerView-->
android:id="@+id/rvSamplingList" <!-- android:id="@+id/rvSamplingList"-->
android:layout_width="match_parent" <!-- android:layout_width="match_parent"-->
android:layout_height="match_parent" <!-- android:layout_height="match_parent"-->
android:overScrollMode="never" <!-- android:overScrollMode="never"-->
tools:listitem="@layout/list_item_dish" /> <!-- tools:listitem="@layout/list_item_dish" />-->
<com.scwang.smart.refresh.footer.ClassicsFooter <!-- <com.scwang.smart.refresh.footer.ClassicsFooter-->
android:layout_width="match_parent" <!-- android:layout_width="match_parent"-->
android:layout_height="wrap_content" /> <!-- android:layout_height="wrap_content" />-->
</com.scwang.smart.refresh.layout.SmartRefreshLayout> <!-- </com.scwang.smart.refresh.layout.SmartRefreshLayout>-->
</LinearLayout> <!-- </LinearLayout>-->
<TextView <!-- <TextView-->
android:id="@+id/btnAddSampling" <!-- android:id="@+id/btnAddSampling"-->
android:layout_width="match_parent" <!-- android:layout_width="match_parent"-->
android:layout_height="90dp" <!-- android:layout_height="90dp"-->
android:layout_margin="30dp" <!-- android:layout_margin="30dp"-->
android:background="@drawable/ripple_effect_green" <!-- android:background="@drawable/ripple_effect_green"-->
android:gravity="center" <!-- android:gravity="center"-->
android:text="@string/add_sampling" <!-- android:text="@string/add_sampling"-->
android:textColor="@color/white" <!-- android:textColor="@color/white"-->
android:textSize="32sp" <!-- android:textSize="32sp"-->
android:textStyle="bold" /> <!-- android:textStyle="bold" />-->
</LinearLayout> </LinearLayout>