From d609bde82e999405946bd09b84f0b56ad8029d7c Mon Sep 17 00:00:00 2001 From: lvmeng <848755140@qq.com> Date: Thu, 14 Aug 2025 14:26:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/shuwei/dish/match/http/UrlConfig.kt | 3 +- .../dish/match/ui/DishSamplingActivity.kt | 184 ++++++- .../com/shuwei/dish/match/ui/HomeActivity.kt | 4 +- .../dish/match/ui/SamplingListActivity.kt | 295 +++++++++- .../match/ui/fragment/DishListFragment.kt | 10 + .../match/ui/fragment/DishSamplingFragment.kt | 374 ++++++------- .../match/ui/fragment/SamplingListFragment.kt | 508 +++++++++--------- .../shuwei/dish/match/utils/SwipeCallback.kt | 10 + .../dish/match/viewmodel/AppViewModel.kt | 27 +- app/src/main/res/color/breakfast_font.xml | 2 +- .../res/layout/activity_dish_sampling.xml | 281 ++++++++++ app/src/main/res/layout/activity_sampling.xml | 106 +++- .../res/layout/fragment_sampling_list.xml | 166 +++--- 13 files changed, 1380 insertions(+), 590 deletions(-) create mode 100644 app/src/main/res/layout/activity_dish_sampling.xml diff --git a/app/src/main/java/com/shuwei/dish/match/http/UrlConfig.kt b/app/src/main/java/com/shuwei/dish/match/http/UrlConfig.kt index 755b9be..65c8f0e 100644 --- a/app/src/main/java/com/shuwei/dish/match/http/UrlConfig.kt +++ b/app/src/main/java/com/shuwei/dish/match/http/UrlConfig.kt @@ -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" diff --git a/app/src/main/java/com/shuwei/dish/match/ui/DishSamplingActivity.kt b/app/src/main/java/com/shuwei/dish/match/ui/DishSamplingActivity.kt index ba1612f..f9793c5 100644 --- a/app/src/main/java/com/shuwei/dish/match/ui/DishSamplingActivity.kt +++ b/app/src/main/java/com/shuwei/dish/match/ui/DishSamplingActivity.kt @@ -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 = 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 { + 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) + } } \ No newline at end of file diff --git a/app/src/main/java/com/shuwei/dish/match/ui/HomeActivity.kt b/app/src/main/java/com/shuwei/dish/match/ui/HomeActivity.kt index 2a46941..bcfdacc 100644 --- a/app/src/main/java/com/shuwei/dish/match/ui/HomeActivity.kt +++ b/app/src/main/java/com/shuwei/dish/match/ui/HomeActivity.kt @@ -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) diff --git a/app/src/main/java/com/shuwei/dish/match/ui/SamplingListActivity.kt b/app/src/main/java/com/shuwei/dish/match/ui/SamplingListActivity.kt index 69cde07..1081365 100644 --- a/app/src/main/java/com/shuwei/dish/match/ui/SamplingListActivity.kt +++ b/app/src/main/java/com/shuwei/dish/match/ui/SamplingListActivity.kt @@ -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 = 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 { + putExtra( + SubmitDishActivity.FOOD_ITEM, + item as Serializable + ) + } + return@setOnItemClickListener + } + context.startActivity { + 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() + } + 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() + 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() + + 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() + } + } + } \ No newline at end of file diff --git a/app/src/main/java/com/shuwei/dish/match/ui/fragment/DishListFragment.kt b/app/src/main/java/com/shuwei/dish/match/ui/fragment/DishListFragment.kt index ee60de9..86da59d 100644 --- a/app/src/main/java/com/shuwei/dish/match/ui/fragment/DishListFragment.kt +++ b/app/src/main/java/com/shuwei/dish/match/ui/fragment/DishListFragment.kt @@ -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) diff --git a/app/src/main/java/com/shuwei/dish/match/ui/fragment/DishSamplingFragment.kt b/app/src/main/java/com/shuwei/dish/match/ui/fragment/DishSamplingFragment.kt index a19fa65..7cc2e77 100644 --- a/app/src/main/java/com/shuwei/dish/match/ui/fragment/DishSamplingFragment.kt +++ b/app/src/main/java/com/shuwei/dish/match/ui/fragment/DishSamplingFragment.kt @@ -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 = 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 { - 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 -} \ No newline at end of file +//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 = 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 { +// 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 +//} \ No newline at end of file diff --git a/app/src/main/java/com/shuwei/dish/match/ui/fragment/SamplingListFragment.kt b/app/src/main/java/com/shuwei/dish/match/ui/fragment/SamplingListFragment.kt index 69d22bf..015da62 100644 --- a/app/src/main/java/com/shuwei/dish/match/ui/fragment/SamplingListFragment.kt +++ b/app/src/main/java/com/shuwei/dish/match/ui/fragment/SamplingListFragment.kt @@ -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 = 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 { - putExtra( - SubmitDishActivity.FOOD_ITEM, - item as Serializable - ) - } - return@setOnItemClickListener - } - context.startActivity { - 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() - } - 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() - 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() - - 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) - } - } - } - - -} \ No newline at end of file +//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 = 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 { +// putExtra( +// SubmitDishActivity.FOOD_ITEM, +// item as Serializable +// ) +// } +// return@setOnItemClickListener +// } +// context.startActivity { +// 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() +// } +// 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() +// 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() +// +// 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) +// } +// } +// } +// +// +//} \ No newline at end of file diff --git a/app/src/main/java/com/shuwei/dish/match/utils/SwipeCallback.kt b/app/src/main/java/com/shuwei/dish/match/utils/SwipeCallback.kt index cb1c384..cf67f0b 100644 --- a/app/src/main/java/com/shuwei/dish/match/utils/SwipeCallback.kt +++ b/app/src/main/java/com/shuwei/dish/match/utils/SwipeCallback.kt @@ -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 } diff --git a/app/src/main/java/com/shuwei/dish/match/viewmodel/AppViewModel.kt b/app/src/main/java/com/shuwei/dish/match/viewmodel/AppViewModel.kt index d7eff06..2e14ce0 100644 --- a/app/src/main/java/com/shuwei/dish/match/viewmodel/AppViewModel.kt +++ b/app/src/main/java/com/shuwei/dish/match/viewmodel/AppViewModel.kt @@ -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() } } diff --git a/app/src/main/res/color/breakfast_font.xml b/app/src/main/res/color/breakfast_font.xml index 197f200..5726826 100644 --- a/app/src/main/res/color/breakfast_font.xml +++ b/app/src/main/res/color/breakfast_font.xml @@ -1,5 +1,5 @@ - + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_dish_sampling.xml b/app/src/main/res/layout/activity_dish_sampling.xml new file mode 100644 index 0000000..390c42a --- /dev/null +++ b/app/src/main/res/layout/activity_dish_sampling.xml @@ -0,0 +1,281 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_sampling.xml b/app/src/main/res/layout/activity_sampling.xml index cac23c6..53ddbb9 100644 --- a/app/src/main/res/layout/activity_sampling.xml +++ b/app/src/main/res/layout/activity_sampling.xml @@ -1,5 +1,105 @@ - \ No newline at end of file + android:layout_height="match_parent" + android:orientation="vertical" + tools:background="@drawable/bg_other_page"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_sampling_list.xml b/app/src/main/res/layout/fragment_sampling_list.xml index 3871be0..9dab987 100644 --- a/app/src/main/res/layout/fragment_sampling_list.xml +++ b/app/src/main/res/layout/fragment_sampling_list.xml @@ -6,100 +6,100 @@ android:orientation="vertical" tools:background="@drawable/bg_other_page"> - + + + + + + - + + + + + + + + + + + + + + - - + + + + + + + + + + + + + + + + - + + + + + + + + + - + + + + + + + - + + + + + + - + + + - + + + + + + - + + + - - + + - + + + + + + + + + + + \ No newline at end of file