制作模式、采样模式数据保存支持多食堂模式,制作模式查询菜品列表和搜索菜品增加餐次字段,设置页面增加隐藏默认数据导入功能
This commit is contained in:
@@ -7,27 +7,30 @@ import android.text.style.AbsoluteSizeSpan
|
||||
import android.text.style.ForegroundColorSpan
|
||||
import android.text.style.LineHeightSpan
|
||||
import android.text.style.StyleSpan
|
||||
import android.util.Log
|
||||
import androidx.core.graphics.toColorInt
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import com.shuwei.dish.match.R
|
||||
import com.shuwei.dish.match.adapter.SeasoningCellTool
|
||||
import com.shuwei.dish.match.adapter.TextCellAdapter
|
||||
import com.shuwei.dish.match.base.BaseActivity
|
||||
import com.shuwei.dish.match.base.BaseApp
|
||||
import com.shuwei.dish.match.databinding.ActivityDeviceSettingBinding
|
||||
import com.shuwei.dish.match.databinding.LayoutFoodRemindBinding
|
||||
import com.shuwei.dish.match.db.AppRepository
|
||||
|
||||
import com.shuwei.dish.match.dialog.CommonDialog
|
||||
import com.shuwei.dish.match.entity.SeasoningEntity
|
||||
import com.shuwei.dish.match.entity.ResetReasoningRecord
|
||||
import com.shuwei.dish.match.utils.DataUtil
|
||||
import com.shuwei.dish.match.utils.JsonAssetsLoader
|
||||
import com.shuwei.dish.match.utils.MultiClickDetector
|
||||
import com.shuwei.dish.match.utils.WeightUtil
|
||||
import com.shuwei.dish.match.utils.ext.appendText
|
||||
import com.shuwei.dish.match.utils.ext.buildSpannableString
|
||||
import com.shuwei.dish.match.utils.ext.dp
|
||||
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 com.shuwei.dish.match.R
|
||||
|
||||
class DeviceSettingActivity : BaseActivity() {
|
||||
|
||||
@@ -53,8 +56,6 @@ class DeviceSettingActivity : BaseActivity() {
|
||||
|
||||
private lateinit var appViewModel: AppViewModel
|
||||
|
||||
// public lateinit var list: MutableList<SeasoningEntity>
|
||||
|
||||
private var cookMode: Int = 0
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
@@ -68,10 +69,20 @@ class DeviceSettingActivity : BaseActivity() {
|
||||
it.visible()
|
||||
}, titleAction = {
|
||||
it.text = "设备配置"
|
||||
}, rightIconActon = {
|
||||
it.visible()
|
||||
it.alpha = 0.0F
|
||||
it.setImageResource(R.drawable.ic_setting)
|
||||
it.setOnClickListener {
|
||||
// appViewModel.clearAllSeasoning{
|
||||
// loadSeasoning()
|
||||
// }
|
||||
detector.setOnDelayedMultiClickListener(it) {
|
||||
defaultDataSettingDialog()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
addListener()
|
||||
|
||||
loadQualitySpan(isEnable = false)
|
||||
when (cookMode) {
|
||||
1 -> {
|
||||
@@ -80,12 +91,14 @@ class DeviceSettingActivity : BaseActivity() {
|
||||
loadCookSpan(isClicked = true)
|
||||
loadSamplingSpan()
|
||||
}
|
||||
|
||||
2 -> {
|
||||
binding.rbModeCook.isChecked = false
|
||||
binding.rbModeSampling.isChecked = true
|
||||
loadCookSpan()
|
||||
loadSamplingSpan(isClicked = true)
|
||||
}
|
||||
|
||||
else -> 0
|
||||
}
|
||||
|
||||
@@ -107,6 +120,40 @@ class DeviceSettingActivity : BaseActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
val detector = MultiClickDetector(targetCount = 10, intervalMs = 800)
|
||||
|
||||
private fun defaultDataSettingDialog() {
|
||||
val remindBinding = LayoutFoodRemindBinding.inflate(layoutInflater)
|
||||
remindBinding.tvDialogTitle.text = "温馨提示"
|
||||
remindBinding.tvDialogContent.text = "您好,使用默认配置作为您的调料数据,则已有配置将被清除,确认吗?"
|
||||
CommonDialog(this).apply {
|
||||
messageView = remindBinding.root
|
||||
leftText = "取消"
|
||||
rightText = "确认"
|
||||
onLeftClick = { dismiss() }
|
||||
onRightClick = {
|
||||
dismiss()
|
||||
resetList()
|
||||
}
|
||||
onDismiss = { hideStatusBar() }
|
||||
}.show()
|
||||
}
|
||||
|
||||
private fun resetList() {
|
||||
runCatching {
|
||||
val record = JsonAssetsLoader.parseJsonFromAssets<ResetReasoningRecord>(this,"default_seasoning_list.json")
|
||||
val addressArray = DataUtil.getWeighAddressArray()
|
||||
val weightArray = WeightUtil.weightArray
|
||||
appViewModel.clearAllSeasoning {
|
||||
record?.list?.forEach { entity ->
|
||||
entity.useWeight = weightArray[addressArray[entity.sort]].toDouble()
|
||||
appViewModel.saveSeasoning(entity){}
|
||||
}
|
||||
loadSeasoning()
|
||||
}
|
||||
}.onFailure { it.printStackTrace() }
|
||||
}
|
||||
|
||||
private fun initViewModel() {
|
||||
val db = BaseApp.instance!!.database
|
||||
val factory =
|
||||
@@ -117,6 +164,10 @@ class DeviceSettingActivity : BaseActivity() {
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
loadSeasoning()
|
||||
}
|
||||
|
||||
private fun loadSeasoning() {
|
||||
appViewModel.loadSeasoning { it ->
|
||||
SeasoningCellTool.loadData(
|
||||
activity = this,
|
||||
@@ -125,79 +176,9 @@ class DeviceSettingActivity : BaseActivity() {
|
||||
tvCell = binding.tvRightBottomCell,
|
||||
pageType = 1
|
||||
)
|
||||
// (binding.rvSeasoning.adapter as TextCellAdapter).let { adapter ->
|
||||
// list = adapter.list
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
// private var isCookMode: Boolean = true
|
||||
|
||||
private fun addListener() {
|
||||
// binding.modeRadioGroup.setOnCheckedChangeListener { _, checkedId ->
|
||||
// when (checkedId) {
|
||||
// R.id.rbModeCook -> {
|
||||
// isCookMode = true
|
||||
// loadCookSpan(isClicked = true)
|
||||
// loadSamplingSpan()
|
||||
// loadQualitySpan(isEnable = false)
|
||||
// }
|
||||
//
|
||||
// R.id.rbModeSampling -> {
|
||||
// isCookMode = false
|
||||
// loadCookSpan()
|
||||
// loadSamplingSpan(isClicked = true)
|
||||
// loadQualitySpan(isEnable = false)
|
||||
// }
|
||||
//
|
||||
// R.id.rbModeQuality -> {
|
||||
// loadCookSpan()
|
||||
// loadSamplingSpan()
|
||||
// loadQualitySpan(isEnable = false)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// binding.btnCancel.setOnClickListener { finish() }
|
||||
// binding.btnConfirm.setOnClickListener { confirmSetting() }
|
||||
|
||||
}
|
||||
|
||||
private fun confirmSetting() {
|
||||
// runCatching {
|
||||
// showLoading()
|
||||
//// list.forEachIndexed { index, entity ->
|
||||
//// entity.sort = index
|
||||
//// }
|
||||
//// val list2 = mutableListOf<SeasoningEntity>()
|
||||
//// list2.addAll(list)
|
||||
//// val array = arrayOf(10, 11, 13)
|
||||
//// list.forEachIndexed { index, entity ->
|
||||
//// if (entity.sort == 14 && array.contains(index)) {
|
||||
//// list2.remove(entity)
|
||||
//// }
|
||||
//// }
|
||||
// Log.d(TAG, "addListener->Click: ${list.toJsonString()}")
|
||||
//
|
||||
// appViewModel.addSeasoning(list) {
|
||||
// dismissLoading()
|
||||
// if (isCookMode) {
|
||||
// startActivity<SelectDishActivity> { }
|
||||
// } else {
|
||||
// startActivity<SamplingListActivity> { }
|
||||
// }
|
||||
//// val activityStack = ActivityManager.getActivityStack()
|
||||
//// activityStack.forEach {
|
||||
//// if (it !is SelectDishActivity && it !is SamplingListActivity) {
|
||||
//// it.finish()
|
||||
//// }
|
||||
//// }
|
||||
// }
|
||||
// }.onFailure {
|
||||
// it.printStackTrace()
|
||||
// toast("数据提交失败")
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
private fun loadQualitySpan(isClicked: Boolean = false, isEnable: Boolean = true) {
|
||||
binding.rbModeQuality.text =
|
||||
@@ -257,7 +238,7 @@ class DeviceSettingActivity : BaseActivity() {
|
||||
}
|
||||
|
||||
fun saveSeasoning(entity: SeasoningEntity) {
|
||||
appViewModel.saveSeasoning(entity){
|
||||
appViewModel.saveSeasoning(entity) {
|
||||
toast("保存成功")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,19 +33,22 @@ class FoodSearchActivity : BaseActivity() {
|
||||
const val PAGE_TYPE = "pageType"
|
||||
const val FOOD_ID = "foodId"
|
||||
const val FOOD_NAME = "foodName"
|
||||
const val DINNER_TYPE = "dinnerType"
|
||||
}
|
||||
|
||||
private lateinit var binding: ActivityFoodSearchBinding
|
||||
|
||||
private var list: MutableList<FoodRecord> = mutableListOf()
|
||||
private var pageType = 0
|
||||
private var dinnerType = "0"
|
||||
private val recordAdapter by lazy {
|
||||
FoodRecordAdapter(list).apply {
|
||||
isStateViewEnable = true
|
||||
setOnItemClickListener { adapter, view, position ->
|
||||
if (pageType == 1) {
|
||||
val jumpItem = list[position].also { it.dinnerType = dinnerType }
|
||||
startActivity<PrepareCookActivity> {
|
||||
putExtra(PrepareCookActivity.FOOD_ITEM, list[position] as Serializable)
|
||||
putExtra(PrepareCookActivity.FOOD_ITEM, jumpItem as Serializable)
|
||||
}
|
||||
return@setOnItemClickListener
|
||||
}
|
||||
@@ -65,6 +68,7 @@ class FoodSearchActivity : BaseActivity() {
|
||||
binding = ActivityFoodSearchBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
pageType = intent.getIntExtra(PAGE_TYPE, 0)
|
||||
dinnerType = intent.getStringExtra(DINNER_TYPE)?:"0"
|
||||
setHeaderBackground()
|
||||
foodName = intent.getStringExtra(FOOD_NAME)
|
||||
binding.etInputDish.setText(foodName)
|
||||
@@ -131,16 +135,26 @@ class FoodSearchActivity : BaseActivity() {
|
||||
|
||||
private var pageNo = 1
|
||||
private var pageSize = 100
|
||||
|
||||
fun getDinnerTypeText(): String {
|
||||
return when (dinnerType) {
|
||||
"1" -> "早餐"
|
||||
"2" -> "午餐"
|
||||
"3" -> "晚餐"
|
||||
else -> "早餐"
|
||||
}
|
||||
}
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
private fun queryListInfo(input: String) {
|
||||
showLoading()
|
||||
val map = mapOf(
|
||||
val map = mutableMapOf(
|
||||
"foodName" to input.trim(),
|
||||
"pageNo" to "$pageNo",
|
||||
"pageSize" to "$pageSize",
|
||||
"canteenId" to BaseApp.canteenId
|
||||
)
|
||||
if (dinnerType.toInt() > 0) {
|
||||
map["dinnerType"] = getDinnerTypeText()
|
||||
}
|
||||
val sb = StringBuilder(UrlConfig.QUERY_FOOD_LIST).apply {
|
||||
append("?")
|
||||
map.forEach { (key, value) -> append("$key=$value&") }
|
||||
|
||||
@@ -68,7 +68,7 @@ class HomeActivity : BaseActivity() {
|
||||
// appViewModel.updateGoods(it)
|
||||
// }
|
||||
// }
|
||||
// appViewModel.deleteAll()
|
||||
// appViewModel.clearAllSeasoning()
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.shuwei.dish.match.utils.SwipeCallback
|
||||
import com.shuwei.dish.match.utils.WeightUtil
|
||||
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.toObject
|
||||
import com.shuwei.dish.match.utils.ext.toast
|
||||
@@ -147,11 +148,10 @@ class PrepareCookActivity : BaseActivity() {
|
||||
return
|
||||
}
|
||||
Log.d(TAG, "goToSubmit: goodsList:${goodsList?.toJsonString()}")
|
||||
startActivity(
|
||||
Intent(this, SubmitDishActivity::class.java)
|
||||
.putExtra(SubmitDishActivity.GOODS_LIST, goodsList as Serializable)
|
||||
.putExtra(SubmitDishActivity.FOOD_ITEM, food as Serializable)
|
||||
)
|
||||
startActivity<SubmitDishActivity> {
|
||||
putExtra(SubmitDishActivity.GOODS_LIST, goodsList as Serializable)
|
||||
putExtra(SubmitDishActivity.FOOD_ITEM, food as Serializable)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getGoodsList() {
|
||||
|
||||
@@ -4,6 +4,7 @@ import android.annotation.SuppressLint
|
||||
import android.app.Dialog
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import com.shuwei.dish.match.R
|
||||
import com.shuwei.dish.match.base.BaseActivity
|
||||
@@ -25,10 +26,20 @@ class SelectDishActivity : BaseActivity() {
|
||||
|
||||
companion object {
|
||||
const val IS_COOKING = "isCooking"
|
||||
const val DINNER_TYPE = "dinnerType"
|
||||
}
|
||||
|
||||
private lateinit var binding: ActivitySelectDishBinding
|
||||
private var dishListFragment: DishListFragment? = null
|
||||
|
||||
private lateinit var appViewModel: AppViewModel
|
||||
|
||||
private var dinnerType: String = "1"
|
||||
|
||||
private val fragmentList = mutableListOf<DishListFragment>().apply {
|
||||
add(DishListFragment.instance("1"))
|
||||
add(DishListFragment.instance("2"))
|
||||
add(DishListFragment.instance("3"))
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
@@ -55,10 +66,6 @@ class SelectDishActivity : BaseActivity() {
|
||||
loadFragment()
|
||||
}
|
||||
|
||||
private lateinit var appViewModel: AppViewModel
|
||||
|
||||
var dinnerType: String = "早餐"
|
||||
|
||||
private fun initViewModel() {
|
||||
val db = BaseApp.instance!!.database
|
||||
val factory =
|
||||
@@ -68,24 +75,19 @@ class SelectDishActivity : BaseActivity() {
|
||||
}
|
||||
|
||||
fun getCookFoodList(action: (MutableList<CookFoodEntity>?) -> Unit) {
|
||||
appViewModel.getCookFoodList(cookMode = 0) { action(it) }
|
||||
appViewModel.getCookFoodList(cookMode = 0, dinnerType = dinnerType) { action(it) }
|
||||
}
|
||||
|
||||
fun addViewListener() {
|
||||
binding.dishRadioGroup.setOnCheckedChangeListener { _, checkedId ->
|
||||
dinnerType = when (checkedId) {
|
||||
R.id.rbBreakfast -> "早餐"
|
||||
R.id.rbLunch -> "午餐"
|
||||
R.id.rbDinner -> "晚餐"
|
||||
else -> ""
|
||||
}
|
||||
dishListFragment?.getDishList(1, false)
|
||||
dinnerType = when (checkedId) {
|
||||
R.id.rbBreakfast -> "1"
|
||||
R.id.rbLunch -> "2"
|
||||
R.id.rbDinner -> "3"
|
||||
else -> "1"
|
||||
}
|
||||
loadFragment()
|
||||
}
|
||||
// binding.llSearchBar.setOnClickListener {
|
||||
// startActivity<FoodSearchActivity> {
|
||||
// putExtra(FoodSearchActivity.PAGE_TYPE, 1)
|
||||
// }
|
||||
// }
|
||||
binding.etInputDish.addOnActionSearchListener {
|
||||
jumpSearch()
|
||||
}
|
||||
@@ -102,18 +104,26 @@ class SelectDishActivity : BaseActivity() {
|
||||
}
|
||||
startActivity<FoodSearchActivity> {
|
||||
putExtra(FoodSearchActivity.PAGE_TYPE, 1)
|
||||
putExtra(FoodSearchActivity.DINNER_TYPE, dinnerType)
|
||||
putExtra(FoodSearchActivity.FOOD_NAME, searchText)
|
||||
}
|
||||
KeyboardUtil.hideKeyboard(this, binding.etInputDish)
|
||||
}
|
||||
|
||||
private fun loadFragment() {
|
||||
DishListFragment.instance().let {
|
||||
dishListFragment = it
|
||||
supportFragmentManager.beginTransaction().apply {
|
||||
replace(R.id.flSubPage, it)
|
||||
commit()
|
||||
runCatching {
|
||||
fragmentList[dinnerType.toInt() - 1].let {
|
||||
supportFragmentManager.beginTransaction().apply {
|
||||
if (fragmentList.contains(it)) {
|
||||
replace(R.id.flSubPage, it)
|
||||
} else {
|
||||
add(R.id.flSubPage, it)
|
||||
}
|
||||
commit()
|
||||
}
|
||||
}
|
||||
}.onFailure {
|
||||
it.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,8 +133,20 @@ class SelectDishActivity : BaseActivity() {
|
||||
|
||||
override fun onNewIntent(intent: Intent?) {
|
||||
super.onNewIntent(intent)
|
||||
val isCooking = intent?.getBooleanExtra(IS_COOKING, false) ?: false
|
||||
dishListFragment?.getDishList(1, isCooking)
|
||||
runCatching {
|
||||
val isCooking = intent?.getBooleanExtra(IS_COOKING, false) ?: false
|
||||
val lastDinnerType = intent?.getStringExtra(DINNER_TYPE) ?: "0"
|
||||
if (lastDinnerType == "1" || lastDinnerType == "2" || lastDinnerType == "3") {
|
||||
fragmentList[lastDinnerType.toInt() - 1].getDishList(1, lastDinnerType)
|
||||
}
|
||||
when(lastDinnerType) {
|
||||
"1"->binding.dishRadioGroup.check(R.id.rbBreakfast)
|
||||
"2"->binding.dishRadioGroup.check(R.id.rbLunch)
|
||||
"3"->binding.dishRadioGroup.check(R.id.rbDinner)
|
||||
}
|
||||
}.onFailure {
|
||||
it.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated("Deprecated in Java")
|
||||
|
||||
@@ -57,6 +57,7 @@ class SubmitDishActivity : BaseActivity() {
|
||||
foodId = it.foodId ?: ""
|
||||
foodName = it.foodName
|
||||
cookMode = it.cookMode
|
||||
dinnerType = it.dinnerType
|
||||
}
|
||||
canteenId = BaseApp.canteenId
|
||||
}
|
||||
@@ -96,7 +97,7 @@ class SubmitDishActivity : BaseActivity() {
|
||||
}
|
||||
|
||||
private fun loadSeasoningFromLocal() {
|
||||
appViewModel.getCookFoodGoodsList(food?.foodId!!) { it ->
|
||||
appViewModel.getCookFoodGoodsList(foodId = food!!.foodId!!, cookMode = food!!.cookMode) { it ->
|
||||
goodsList = mutableListOf()
|
||||
//设置主辅材数据
|
||||
goodsList?.addAll(it.filter { goods -> goods.materialType != 3 })
|
||||
@@ -174,12 +175,12 @@ class SubmitDishActivity : BaseActivity() {
|
||||
// return@addWeightListener
|
||||
// }
|
||||
val firstWeight = firstGoodsArray.get(address, null)
|
||||
if (firstWeight != weight) {
|
||||
Log.d(
|
||||
TAG,
|
||||
"addViewListener: state=$state,address=$address,weight=$weight,firstWeight=$firstWeight"
|
||||
)
|
||||
}
|
||||
// if (firstWeight != weight) {
|
||||
// Log.d(
|
||||
// TAG,
|
||||
// "addViewListener: state=$state,address=$address,weight=$weight,firstWeight=$firstWeight"
|
||||
// )
|
||||
// }
|
||||
if (firstWeight == null) {
|
||||
//未设置数据
|
||||
firstGoodsArray.put(address, weight)
|
||||
@@ -273,7 +274,14 @@ class SubmitDishActivity : BaseActivity() {
|
||||
val typeToken = object : TypeToken<List<CookFoodGoodsEntity>>() {}
|
||||
val tempSeasoningList = seasoningJson.toType(typeToken = typeToken)
|
||||
goodsList?.addAll(tempSeasoningList)
|
||||
|
||||
cookFoodEntity.let {
|
||||
it.dinnerType = when (it.dinnerType) {
|
||||
"早餐" -> "1"
|
||||
"午餐" -> "2"
|
||||
"晚餐" -> "3"
|
||||
else -> it.dinnerType
|
||||
}
|
||||
}
|
||||
val isSamplingData = food!!.cookMode == 1
|
||||
if (isSamplingData) {
|
||||
//生成临时foodId,解决采样模式没有foodId,无法关联数据的问题
|
||||
@@ -325,7 +333,16 @@ class SubmitDishActivity : BaseActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
cookFoodEntity.stFoodInfoConstituteList = this@SubmitDishActivity.goodsList
|
||||
cookFoodEntity.let {
|
||||
it.stFoodInfoConstituteList = this@SubmitDishActivity.goodsList
|
||||
it.dinnerType = when(it.dinnerType) {
|
||||
"1" -> "早餐"
|
||||
"2" -> "午餐"
|
||||
"3" -> "晚餐"
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
val isSamplingData = food!!.cookMode == 1
|
||||
if (isSamplingData) {
|
||||
//采样模式没有foodId
|
||||
@@ -373,6 +390,7 @@ class SubmitDishActivity : BaseActivity() {
|
||||
}
|
||||
startActivity<SelectDishActivity> {
|
||||
putExtra(SelectDishActivity.IS_COOKING, isCooking)
|
||||
putExtra(SelectDishActivity.DINNER_TYPE, food?.dinnerType)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import android.view.ViewGroup
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.recyclerview.widget.ItemTouchHelper
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.chad.library.adapter4.util.setOnDebouncedItemClick
|
||||
import com.shuwei.dish.match.adapter.DishShowAdapter
|
||||
import com.shuwei.dish.match.base.BaseApp
|
||||
import com.shuwei.dish.match.databinding.FragmentDishListBinding
|
||||
@@ -32,27 +33,29 @@ class DishListFragment : Fragment() {
|
||||
companion object {
|
||||
private const val TAG = "DishListFragment"
|
||||
|
||||
// const val DINNER_TYPE = "dinnerType"
|
||||
public fun instance(): DishListFragment {
|
||||
const val DINNER_TYPE = "dinnerType"
|
||||
public fun instance(dinnerType: String): DishListFragment {
|
||||
return DishListFragment().apply {
|
||||
// arguments = Bundle().apply {
|
||||
// putInt(DINNER_TYPE, type)
|
||||
// }
|
||||
arguments = Bundle().apply {
|
||||
putString(DINNER_TYPE, dinnerType)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// private var dinnerType = ""
|
||||
private var pageNo = 1
|
||||
private val pageSize = 30
|
||||
|
||||
private lateinit var activity: SelectDishActivity
|
||||
|
||||
private lateinit var binding: FragmentDishListBinding
|
||||
|
||||
private var dinnerType = "0"
|
||||
|
||||
private var list: MutableList<FoodRecord> = mutableListOf()
|
||||
private val dishAdapter by lazy {
|
||||
DishShowAdapter(list = list).apply {
|
||||
isStateViewEnable = true
|
||||
setOnItemClickListener { adapter, view, position ->
|
||||
setOnDebouncedItemClick { adapter, view, position ->
|
||||
val item = list[position]
|
||||
if (item.isCooking) {
|
||||
//烹饪中,跳到称熟重页面
|
||||
@@ -62,8 +65,9 @@ class DishListFragment : Fragment() {
|
||||
item as Serializable
|
||||
)
|
||||
}
|
||||
return@setOnItemClickListener
|
||||
return@setOnDebouncedItemClick
|
||||
}
|
||||
item.dinnerType = dinnerType
|
||||
context.startActivity<PrepareCookActivity> {
|
||||
putExtra(
|
||||
SubmitDishActivity.FOOD_ITEM,
|
||||
@@ -75,8 +79,6 @@ class DishListFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
|
||||
private lateinit var binding: FragmentDishListBinding
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
@@ -89,7 +91,7 @@ class DishListFragment : Fragment() {
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
activity = requireActivity() as SelectDishActivity
|
||||
//toast("type=$type")
|
||||
dinnerType = arguments?.getString(DINNER_TYPE, "0")?:"0"
|
||||
binding.rvDishList.run {
|
||||
layoutManager =
|
||||
LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false)
|
||||
@@ -127,19 +129,28 @@ class DishListFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun getDishList(pageNo: Int, isCooking: Boolean) {
|
||||
fun getDishList(pageNo: Int, dinnerType: String) {
|
||||
this.pageNo = pageNo
|
||||
this.dinnerType = dinnerType
|
||||
getDishList()
|
||||
}
|
||||
|
||||
fun getDinnerTypeText(): String {
|
||||
return when (dinnerType) {
|
||||
"1" -> "早餐"
|
||||
"2" -> "午餐"
|
||||
"3" -> "晚餐"
|
||||
else -> "早餐"
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
@Suppress("unchecked_cast")
|
||||
fun getDishList() {
|
||||
activity.showLoading()
|
||||
val map = mapOf(
|
||||
// "foodName" to input,
|
||||
"dinnerType" to activity.dinnerType,
|
||||
"dinnerType" to getDinnerTypeText(),
|
||||
"pageNo" to "$pageNo",
|
||||
"pageSize" to "$pageSize",
|
||||
"canteenId" to BaseApp.canteenId
|
||||
@@ -231,6 +242,7 @@ class DishListFragment : Fragment() {
|
||||
if (food != null) {
|
||||
food.isCooking = true
|
||||
food.sort = index
|
||||
food.dinnerType = entity.dinnerType?:"0"
|
||||
tempList.add(food)
|
||||
} else {
|
||||
//当前查询到的list不包括本地数据id,可能数据在很多页以后了,暂时只能直接构造数据
|
||||
@@ -239,6 +251,7 @@ class DishListFragment : Fragment() {
|
||||
foodId = entity.foodId,
|
||||
foodName = entity.foodName,
|
||||
sort = index,
|
||||
dinnerType = entity.dinnerType?:"0",
|
||||
isCooking = true
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user