使用新方式实现调料页面,优化涉及页面
This commit is contained in:
@@ -161,9 +161,9 @@ class AppViewModel(private val rep: AppRepository) : ViewModel() {
|
||||
}
|
||||
}
|
||||
|
||||
fun deleteEmptySeasoning() {
|
||||
fun deleteSeasoningBySort(sort: Int) {
|
||||
viewModelScope.launch {
|
||||
rep.deleteEmptySeasoning()
|
||||
rep.deleteSeasoningBySort(sort)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,23 +174,30 @@ class AppViewModel(private val rep: AppRepository) : ViewModel() {
|
||||
}
|
||||
}
|
||||
|
||||
fun updateAll(list: MutableList<SeasoningEntity>) {
|
||||
viewModelScope.launch {
|
||||
list.forEach {
|
||||
rep.updateSeasoning(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
// fun updateAll(list: MutableList<SeasoningEntity>) {
|
||||
// viewModelScope.launch {
|
||||
// list.forEach {
|
||||
// rep.updateSeasoning(it)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
fun saveSeasoning(entity: SeasoningEntity, block: () -> Unit) {
|
||||
viewModelScope.launch {
|
||||
val seasoning = rep.getSeasoningBySort(entity.sort)
|
||||
if (seasoning == null) {
|
||||
rep.insertSeasoning(entity)
|
||||
val list = rep.getSeasoningBySort(entity.sort)
|
||||
val size = list?.size?:0
|
||||
if (size == 1) {
|
||||
rep.updateSeasoning(entity.also { it.id = list!![0].id })
|
||||
block()
|
||||
return@launch
|
||||
}
|
||||
rep.updateSeasoning(entity.also { it.id = seasoning.id })
|
||||
if (size > 1) {
|
||||
list?.forEach {
|
||||
rep.deleteSeasoningBySort(it.sort)
|
||||
}
|
||||
}
|
||||
entity.id = 0
|
||||
rep.insertSeasoning(entity)
|
||||
block()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user