优化
This commit is contained in:
@@ -138,16 +138,20 @@ class DeviceConfigActivity : BaseActivity() {
|
||||
}
|
||||
|
||||
private fun addWeighListener() {
|
||||
WeightUtil.addWeightListener { address, state, weight ->
|
||||
// Log.d(TAG, "addWeighListener: address=$address,stat=$state,weight=$weight")
|
||||
WeightUtil.addWeightListener(onConnect = { state ->
|
||||
binding.viewPoint.setBackgroundResource(
|
||||
if (state) R.drawable.bg_circle_green else R.drawable.bg_circle_red
|
||||
)
|
||||
}, getWeight = { address, state, weight ->
|
||||
Log.d(TAG, "addWeighListener: address=$address,stat=$state,weight=$weight")
|
||||
weightArray.put(address, weight)
|
||||
val item = seasoningItems.firstOrNull { address == addressArray[it.sort]}
|
||||
val item = seasoningItems.firstOrNull { address == addressArray[it.sort] }
|
||||
item?.let {
|
||||
it.useWeight = weight.toDouble()
|
||||
updateGridData(it)
|
||||
}
|
||||
//setGridData(seasoningItems)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private var seasoningItems = mutableListOf<SeasoningEntity>()
|
||||
@@ -229,15 +233,15 @@ class DeviceConfigActivity : BaseActivity() {
|
||||
list.forEach { entity ->
|
||||
val tag = entity.sort.toString()
|
||||
val frameLayout = gridLayout.findViewWithTag<FrameLayout>(tag)
|
||||
TextCellAdapter.loadLayout(frameLayout , entity)
|
||||
TextCellAdapter.loadLayout(frameLayout, entity)
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateGridData(entity:SeasoningEntity) {
|
||||
private fun updateGridData(entity: SeasoningEntity) {
|
||||
val gridLayout = binding.include.root
|
||||
val tag = entity.sort.toString()
|
||||
val frameLayout = gridLayout.findViewWithTag<FrameLayout>(tag)
|
||||
TextCellAdapter.loadLayout(frameLayout , entity)
|
||||
TextCellAdapter.loadLayout(frameLayout, entity)
|
||||
}
|
||||
|
||||
private fun clickGridItem(sort: Int, entity: SeasoningEntity) {
|
||||
|
||||
@@ -76,7 +76,7 @@ class InitActivity : BaseActivity() {
|
||||
|
||||
initViewModel()
|
||||
WeightUtil.init()
|
||||
WeightUtil.connect {}
|
||||
// WeightUtil.connect {}
|
||||
WeightUtil.getWeight()
|
||||
WeightUtil.startContinuousRead()
|
||||
HttpUtil.getAppToken()
|
||||
|
||||
@@ -165,42 +165,24 @@ class DishListFragment : BaseFragment<FragmentDishListBinding>() {
|
||||
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("暂未搜索到相关菜品信息")
|
||||
loadDishList(it)
|
||||
}, doFailure = { code, msg ->
|
||||
try {
|
||||
if (isAdded.not()) {
|
||||
return@get
|
||||
}
|
||||
binding.refreshLayout.run {
|
||||
setEnableRefresh(true)
|
||||
}
|
||||
toast(msg)
|
||||
finishRefresh()
|
||||
if (pageNo == 1) {
|
||||
loadEmptyView()
|
||||
}
|
||||
return@get
|
||||
activity.delayDismissLoading()
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
val records = recordBean.records
|
||||
if (pageNo == 1) {
|
||||
list.clear()
|
||||
}
|
||||
list.addAll(records!!)
|
||||
dishAdapter.notifyDataSetChanged()
|
||||
val isLoadMoreEnable = records.size >= pageSize
|
||||
binding.refreshLayout.setEnableLoadMore(isLoadMoreEnable)
|
||||
if (isLoadMoreEnable) {
|
||||
pageNo++
|
||||
}
|
||||
refreshLocalData(list)
|
||||
}, doFailure = { code, msg ->
|
||||
binding.refreshLayout.run {
|
||||
setEnableRefresh(true)
|
||||
}
|
||||
toast(msg)
|
||||
finishRefresh()
|
||||
if (pageNo == 1) {
|
||||
loadEmptyView()
|
||||
}
|
||||
activity.delayDismissLoading()
|
||||
})
|
||||
}
|
||||
|
||||
@@ -269,5 +251,41 @@ class DishListFragment : BaseFragment<FragmentDishListBinding>() {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
private fun loadDishList(data: Any) {
|
||||
try {
|
||||
if (isAdded.not()) {
|
||||
return
|
||||
}
|
||||
binding.refreshLayout.run {
|
||||
setEnableRefresh(true)
|
||||
}
|
||||
activity.delayDismissLoading()
|
||||
finishRefresh()
|
||||
val json = data.toJsonString()
|
||||
val recordBean: FoodRecordBean? = json.toObject<FoodRecordBean>()
|
||||
if (recordBean == null || recordBean.records.isNullOrEmpty()) {
|
||||
//toast("暂未搜索到相关菜品信息")
|
||||
if (pageNo == 1) {
|
||||
loadEmptyView()
|
||||
}
|
||||
return
|
||||
}
|
||||
val records = recordBean.records
|
||||
if (pageNo == 1) {
|
||||
list.clear()
|
||||
}
|
||||
list.addAll(records!!)
|
||||
dishAdapter.notifyDataSetChanged()
|
||||
val isLoadMoreEnable = records.size >= pageSize
|
||||
binding.refreshLayout.setEnableLoadMore(isLoadMoreEnable)
|
||||
if (isLoadMoreEnable) {
|
||||
pageNo++
|
||||
}
|
||||
refreshLocalData(list)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user