优化
This commit is contained in:
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user