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_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_DETAIL = "$BASE_URL/food/stFoodInfoMatching/queryById"
@@ -1,31 +1,48 @@
package com.shuwei.dish.match.ui
import android.annotation.SuppressLint
import android.content.Intent
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.util.Log
import android.view.View
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.LinearLayoutManager
import com.aithings.Weigher
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.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.db.AppRepository
import com.shuwei.dish.match.dialog.BottomDialog
import com.shuwei.dish.match.dialog.CommonDialog
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.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.viewmodel.AppViewModel
import com.shuwei.dish.match.viewmodel.factory.AppFactory
import java.io.Serializable
class DishSamplingActivity : BaseActivity() {
private lateinit var binding: ActivitySamplingBinding
private lateinit var binding: ActivityDishSamplingBinding
var foodName: String? = null
private var foodId: String? = null
companion object {
private const val TAG = "DishSamplingActivity"
public const val FOOD_NAME = "foodName"
public const val PAGE_FROM = "pageFrom"
public const val HOME = "home"
@@ -35,14 +52,15 @@ class DishSamplingActivity : BaseActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivitySamplingBinding.inflate(layoutInflater)
binding = ActivityDishSamplingBinding.inflate(layoutInflater)
setContentView(binding.root)
pageFrom = intent.getStringExtra(PAGE_FROM)
setTitleBar()
setHeaderBackground()
addViewClickListener()
initViewModel()
loadDishSamplingPage()
foodName = intent.getStringExtra(FOOD_NAME)
binding.etInputDish.setText(foodName)
}
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 fun initViewModel() {
@@ -100,8 +100,7 @@ class DishSamplingActivity : BaseActivity() {
@SuppressLint("GestureBackNavigation")
@Deprecated("Deprecated in Java")
override fun onBackPressed() {
val list = dishSamplingFragment?.list
if (list.isNullOrEmpty().not()) {
if (list.isEmpty().not()) {
//说明有新增的食材
saveDataRemindDialog()
return
@@ -128,4 +127,137 @@ class DishSamplingActivity : BaseActivity() {
onDismiss = { hideStatusBar() }
}.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)
initViewModel()
// 获取 ANDROID_ID
BaseApp.instance?.androidId =
val deviceId =
Settings.Secure.getString(contentResolver, Settings.Secure.ANDROID_ID)
Log.d(TAG, "onCreate: deviceId=$deviceId")
BaseApp.instance?.androidId = deviceId
binding = ActivityHomeBinding.inflate(layoutInflater)
setContentView(binding.root)
@@ -1,30 +1,44 @@
package com.shuwei.dish.match.ui
import android.annotation.SuppressLint
import android.app.Dialog
import android.content.Intent
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.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.LinearLayoutManager
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.BaseApp
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.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.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.visible
import com.shuwei.dish.match.viewmodel.AppViewModel
import com.shuwei.dish.match.viewmodel.factory.AppFactory
import java.io.Serializable
class SamplingListActivity : BaseActivity() {
private lateinit var binding: ActivitySamplingBinding
companion object {
private const val TAG = "SamplingListActivity"
const val IS_COOKING = "isCooking"
}
@@ -35,9 +49,12 @@ class SamplingListActivity : BaseActivity() {
setTitleBar()
setHeaderBackground()
initViewModel()
loadSamplingListPage()
initRecyclerView()
addViewListener()
requestData(true)
}
private fun setTitleBar() {
setTitleBar(titleBarAction = {
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 fun initViewModel() {
@@ -97,7 +96,8 @@ class SamplingListActivity : BaseActivity() {
override fun onNewIntent(intent: Intent?) {
super.onNewIntent(intent)
val isCooking = intent?.getBooleanExtra(IS_COOKING, false) ?: false
samplingListFragment?.refreshPage(isCooking)
//toast("isCooking=$isCooking")
refreshPage(isCooking)
}
@Deprecated("Deprecated in Java")
@@ -108,4 +108,253 @@ class SamplingListActivity : BaseActivity() {
//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.sort = index
tempList.add(food)
} else {
//当前查询到的list不包括本地数据id,可能数据在很多页以后了,暂时只能直接构造数据
tempList.add(
FoodRecord(
foodId = entity.foodId,
foodName = entity.foodName,
sort = index,
isCooking = true
)
)
}
}
list.removeAll(tempList)
@@ -1,187 +1,187 @@
package com.shuwei.dish.match.ui.fragment
import android.annotation.SuppressLint
import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager
import com.aithings.Weigher
import com.shuwei.dish.match.R
import com.shuwei.dish.match.adapter.DishPartAdapter
import com.shuwei.dish.match.databinding.FragmentDishSamplingBinding
import com.shuwei.dish.match.dialog.BottomDialog
import com.shuwei.dish.match.entity.CookFoodGoodsEntity
import com.shuwei.dish.match.entity.FoodRecord
import com.shuwei.dish.match.ui.FoodSearchActivity
import com.shuwei.dish.match.ui.DishSamplingActivity
import com.shuwei.dish.match.ui.SubmitDishActivity
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.startActivity
import com.shuwei.dish.match.utils.ext.toJsonString
import com.shuwei.dish.match.utils.ext.toast
import java.io.Serializable
class DishSamplingFragment : Fragment() {
private val TAG = "DishSamplingFragment"
private lateinit var activity: DishSamplingActivity
private lateinit var binding: FragmentDishSamplingBinding
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)
}
}
}
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
): View {
binding = FragmentDishSamplingBinding.inflate(inflater, container, false)
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
activity = requireActivity() as DishSamplingActivity
addViewClickListener()
foodName = activity.foodName
binding.etInputDish.setText(foodName)
}
@SuppressLint("NotifyDataSetChanged")
private fun addViewClickListener() {
binding.rvDishPartList.run {
layoutManager = LinearLayoutManager(activity, LinearLayoutManager.VERTICAL, false)
adapter = dishAdapter
}
binding.tvInputDishType.run {
clickWithDebounce {
BottomDialog(goodsType = 0).show(activity) { 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) {
activity.toast("请输入食材名称")
return@setOnClickListener
}
if (binding.rgSampling.checkedRadioButtonId == -1) {
activity.toast("请选择主辅材类型")
return@setOnClickListener
}
if (tempDishEntity!!.useWeight == null) {
activity.toast("请将食材放在称上称重")
return@setOnClickListener
}
tempDishEntity!!.apply {
isSamplingPage = true
materialType = dishMaterialType
}
val result = list.firstOrNull { it.goodsId == tempDishEntity!!.goodsId }
if (result != null) {
activity.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()}")
activity.startActivity<SubmitDishActivity> {
putExtra(SubmitDishActivity.GOODS_LIST, list as Serializable)
putExtra(SubmitDishActivity.FOOD_ITEM, food as Serializable)
}
}
binding.etInputDish.let { v ->
v.addOnActionSearchListener {
jumpSearch(v)
}
}
}
private fun jumpSearch(v: View) {
activity.launch(Intent(activity, 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)
}
private var foodId: String? = null
private var foodName: String? = null
}
//package com.shuwei.dish.match.ui.fragment
//
//import android.annotation.SuppressLint
//import android.content.Intent
//import android.os.Bundle
//import android.util.Log
//import android.view.LayoutInflater
//import android.view.View
//import android.view.ViewGroup
//import androidx.fragment.app.Fragment
//import androidx.recyclerview.widget.LinearLayoutManager
//import com.aithings.Weigher
//import com.shuwei.dish.match.R
//import com.shuwei.dish.match.adapter.DishPartAdapter
//import com.shuwei.dish.match.databinding.FragmentDishSamplingBinding
//import com.shuwei.dish.match.dialog.BottomDialog
//import com.shuwei.dish.match.entity.CookFoodGoodsEntity
//import com.shuwei.dish.match.entity.FoodRecord
//import com.shuwei.dish.match.ui.FoodSearchActivity
//import com.shuwei.dish.match.ui.DishSamplingActivity
//import com.shuwei.dish.match.ui.SubmitDishActivity
//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.startActivity
//import com.shuwei.dish.match.utils.ext.toJsonString
//import com.shuwei.dish.match.utils.ext.toast
//import java.io.Serializable
//
//class DishSamplingFragment : Fragment() {
//
// private val TAG = "DishSamplingFragment"
//
// private lateinit var activity: DishSamplingActivity
// private lateinit var binding: FragmentDishSamplingBinding
//
// 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)
// }
// }
// }
//
// override fun onCreateView(
// inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
// ): View {
// binding = FragmentDishSamplingBinding.inflate(inflater, container, false)
// return binding.root
// }
//
// override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
// super.onViewCreated(view, savedInstanceState)
// activity = requireActivity() as DishSamplingActivity
// addViewClickListener()
// foodName = activity.foodName
// binding.etInputDish.setText(foodName)
// }
//
// @SuppressLint("NotifyDataSetChanged")
// private fun addViewClickListener() {
// binding.rvDishPartList.run {
// layoutManager = LinearLayoutManager(activity, LinearLayoutManager.VERTICAL, false)
// adapter = dishAdapter
// }
// binding.tvInputDishType.run {
// clickWithDebounce {
// BottomDialog(goodsType = 0).show(activity) { 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) {
// activity.toast("请输入食材名称")
// return@setOnClickListener
// }
// if (binding.rgSampling.checkedRadioButtonId == -1) {
// activity.toast("请选择主辅材类型")
// return@setOnClickListener
// }
// if (tempDishEntity!!.useWeight == null) {
// activity.toast("请将食材放在称上称重")
// return@setOnClickListener
// }
// tempDishEntity!!.apply {
// isSamplingPage = true
// materialType = dishMaterialType
// }
// val result = list.firstOrNull { it.goodsId == tempDishEntity!!.goodsId }
// if (result != null) {
// activity.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()}")
// activity.startActivity<SubmitDishActivity> {
// putExtra(SubmitDishActivity.GOODS_LIST, list as Serializable)
// putExtra(SubmitDishActivity.FOOD_ITEM, food as Serializable)
// }
// }
// binding.etInputDish.let { v ->
// v.addOnActionSearchListener {
// jumpSearch(v)
// }
// }
// }
//
// private fun jumpSearch(v: View) {
// activity.launch(Intent(activity, 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)
// }
//
//
// private var foodId: String? = null
// private var foodName: String? = null
//}
@@ -1,254 +1,254 @@
package com.shuwei.dish.match.ui.fragment
import android.annotation.SuppressLint
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.ItemTouchHelper
import androidx.recyclerview.widget.LinearLayoutManager
import com.shuwei.dish.match.R
import com.shuwei.dish.match.adapter.SamplingAdapter
import com.shuwei.dish.match.databinding.FragmentSamplingListBinding
import com.shuwei.dish.match.databinding.LayoutEmptyViewBinding
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.ui.DishSamplingActivity
import com.shuwei.dish.match.ui.SamplingListActivity
import com.shuwei.dish.match.ui.SubmitDishActivity
import com.shuwei.dish.match.utils.DateTimeUtil
import com.shuwei.dish.match.utils.SwipeCallback
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 java.io.Serializable
class SamplingListFragment : Fragment() {
companion object {
private const val TAG = "SamplingListFragment"
}
private lateinit var activity: SamplingListActivity
private lateinit var binding: FragmentSamplingListBinding
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(requireContext(), LinearLayoutManager.VERTICAL, false)
adapter = dishAdapter
val itemTouchHelper = ItemTouchHelper(SwipeCallback(dishAdapter) { position ->
if (list[position].isCooking.not()) {
activity.toast("只能删除烹饪中的菜品")
dishAdapter.notifyItemChanged(position)
return@SwipeCallback
}
activity.deleteCookFoodAndGoods(foodId = list[position].foodId?:"") {
if (list.size > 1) {
dishAdapter.removeAt(position)
} else {
loadEmptyView()
}
activity.toast("已删除")
}
})
itemTouchHelper.attachToRecyclerView(this)
}
}
private fun addViewListener() {
binding.btnAddSampling.setOnClickListener {
activity.startActivity<DishSamplingActivity>()
}
binding.refreshLayout.setOnRefreshListener {
pageNo = 1
getSamplingList()
}
binding.refreshLayout.setOnLoadMoreListener {
getSamplingList()
}
binding.dishRadioGroup.setOnCheckedChangeListener { group, checkedId ->
if (checkedId == R.id.rbCooking) {
refreshLocalData()
} else {
pageNo = 1
getSamplingList()
}
}
}
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
binding = FragmentSamplingListBinding.inflate(inflater, container, false)
return binding.root
}
@SuppressLint("NotifyDataSetChanged")
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
activity = requireActivity() as SamplingListActivity
initRecyclerView()
addViewListener()
refreshLocalData()
}
var pageNo = 1
private val pageSize = 30
@SuppressLint("NotifyDataSetChanged")
fun getSamplingList() {
activity.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)
}
activity.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)
activity.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(requireContext()), 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(false)
setEnableLoadMore(false)
}
}
fun refreshPage(isCooking: Boolean) {
binding.dishRadioGroup.check(
if (isCooking) R.id.rbCooking else R.id.rbFinished
)
}
@SuppressLint("NotifyDataSetChanged")
fun refreshLocalData() {
activity.showLoading()
//查询本地数据
activity.getCookFoodList { cookFoodEntities ->
activity.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)
}
}
}
}
//package com.shuwei.dish.match.ui.fragment
//
//import android.annotation.SuppressLint
//import android.os.Bundle
//import android.view.LayoutInflater
//import android.view.View
//import android.view.ViewGroup
//import androidx.fragment.app.Fragment
//import androidx.recyclerview.widget.ItemTouchHelper
//import androidx.recyclerview.widget.LinearLayoutManager
//import com.shuwei.dish.match.R
//import com.shuwei.dish.match.adapter.SamplingAdapter
//import com.shuwei.dish.match.databinding.FragmentSamplingListBinding
//import com.shuwei.dish.match.databinding.LayoutEmptyViewBinding
//
//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.ui.DishSamplingActivity
//import com.shuwei.dish.match.ui.SamplingListActivity
//import com.shuwei.dish.match.ui.SubmitDishActivity
//import com.shuwei.dish.match.utils.DateTimeUtil
//import com.shuwei.dish.match.utils.SwipeCallback
//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 java.io.Serializable
//
//class SamplingListFragment : Fragment() {
//
// companion object {
// private const val TAG = "SamplingListFragment"
// }
//
// private lateinit var activity: SamplingListActivity
// private lateinit var binding: FragmentSamplingListBinding
//
// 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(requireContext(), LinearLayoutManager.VERTICAL, false)
// adapter = dishAdapter
// val itemTouchHelper = ItemTouchHelper(SwipeCallback(dishAdapter) { position ->
// if (list[position].isCooking.not()) {
// activity.toast("只能删除烹饪中的菜品")
// dishAdapter.notifyItemChanged(position)
// return@SwipeCallback
// }
// activity.deleteCookFoodAndGoods(foodId = list[position].foodId?:"") {
// if (list.size > 1) {
// dishAdapter.removeAt(position)
// } else {
// loadEmptyView()
// }
// activity.toast("已删除")
// }
// })
// itemTouchHelper.attachToRecyclerView(this)
// }
// }
//
// private fun addViewListener() {
// binding.btnAddSampling.setOnClickListener {
// activity.startActivity<DishSamplingActivity>()
// }
// binding.refreshLayout.setOnRefreshListener {
// pageNo = 1
// getSamplingList()
// }
// binding.refreshLayout.setOnLoadMoreListener {
// getSamplingList()
// }
// binding.dishRadioGroup.setOnCheckedChangeListener { group, checkedId ->
// if (checkedId == R.id.rbCooking) {
// refreshLocalData()
// } else {
// pageNo = 1
// getSamplingList()
// }
// }
// }
//
// override fun onCreateView(
// inflater: LayoutInflater,
// container: ViewGroup?,
// savedInstanceState: Bundle?
// ): View {
// binding = FragmentSamplingListBinding.inflate(inflater, container, false)
// return binding.root
// }
//
// @SuppressLint("NotifyDataSetChanged")
// override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
// super.onViewCreated(view, savedInstanceState)
// activity = requireActivity() as SamplingListActivity
// initRecyclerView()
// addViewListener()
// refreshLocalData()
// }
//
// var pageNo = 1
// private val pageSize = 30
//
// @SuppressLint("NotifyDataSetChanged")
// fun getSamplingList() {
// activity.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)
// }
// activity.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)
// activity.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(requireContext()), 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(false)
// setEnableLoadMore(false)
// }
// }
//
// fun refreshPage(isCooking: Boolean) {
// binding.dishRadioGroup.check(
// if (isCooking) R.id.rbCooking else R.id.rbFinished
// )
// }
//
// @SuppressLint("NotifyDataSetChanged")
// fun refreshLocalData() {
// activity.showLoading()
// //查询本地数据
// activity.getCookFoodList { cookFoodEntities ->
// activity.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)
// }
// }
// }
//
//
//}
@@ -7,6 +7,7 @@ import com.chad.library.adapter4.viewholder.QuickViewHolder
import com.shuwei.dish.match.adapter.DishPartAdapter
import com.shuwei.dish.match.adapter.DishShowAdapter
import com.shuwei.dish.match.adapter.SamplingAdapter
import androidx.core.view.isEmpty
class SwipeCallback(
private val adapter: BaseQuickAdapter<*,*>,
@@ -37,14 +38,23 @@ class SwipeCallback(
var swipeFlags = ItemTouchHelper.LEFT or ItemTouchHelper.RIGHT
if (adapter is SamplingAdapter) {
if (adapter.items.isEmpty()) {
return makeMovementFlags(0, 0)
}
if (!adapter.items[position].isCooking) {
swipeFlags = 0
}
} else if (adapter is DishShowAdapter) {
if (adapter.items.isEmpty()) {
return makeMovementFlags(0, 0)
}
if (!adapter.items[position].isCooking) {
swipeFlags = 0
}
} else if (adapter is DishPartAdapter) {
if (adapter.items.isEmpty()) {
return makeMovementFlags(0, 0)
}
if (!adapter.items[position].isNewDishType) {
swipeFlags = 0
}
@@ -42,16 +42,16 @@ class AppViewModel(private val rep: AppRepository) : ViewModel() {
}
}
fun saveCookFood(cookMode: Int, entity: CookFoodEntity) {
viewModelScope.launch {
val data = rep.getCookFoodById(entity.foodId, cookMode)
if (data == null) {
rep.insertCookFood(entity)
return@launch
}
rep.updateCookFood(entity)
}
}
// fun saveCookFood(cookMode: Int, entity: CookFoodEntity) {
// viewModelScope.launch {
// val data = rep.getCookFoodById(entity.foodId, cookMode)
// if (data == null) {
// rep.insertCookFood(entity)
// return@launch
// }
// rep.updateCookFood(entity)
// }
// }
fun saveCookFoodAndGoods(
cookMode: Int,
@@ -68,7 +68,12 @@ class AppViewModel(private val rep: AppRepository) : ViewModel() {
}
//重新保存数据
rep.insertCookFood(entity)
list?.let { rep.insertGoodsList(it) }
list?.let { it ->
it.forEach { goods->
goods.id = 0
}
rep.insertGoodsList(it)
}
onFinish()
}
}
+1 -1
View File
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<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>
@@ -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"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/flContainer"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
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"
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">
<!-- <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/rbCooking"
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/rbCooking"-->
<!-- 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/rbFinished"
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>
<!-- <RadioButton-->
<!-- android:id="@+id/rbFinished"-->
<!-- 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">
<!-- <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"/>
<!-- <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.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" />
<!-- <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" />
<!-- <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.footer.ClassicsFooter-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="wrap_content" />-->
</com.scwang.smart.refresh.layout.SmartRefreshLayout>
</LinearLayout>
<!-- </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" />
<!-- <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>