refactor(viewmodel): 统一 DbViewModel 初始化并拆分 DAO 结构
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -22,6 +22,7 @@ import com.shuwei.dish.match.R
|
||||
import com.shuwei.dish.match.databinding.ActivityBaseBinding
|
||||
import com.shuwei.dish.match.dialog.Loading
|
||||
import com.shuwei.dish.match.net.NetViewModel
|
||||
import com.shuwei.dish.match.db.DbViewModel
|
||||
import com.shuwei.dish.match.ui.InitActivity
|
||||
import com.shuwei.dish.match.utils.ActivityManager
|
||||
import com.shuwei.dish.match.utils.ext.dp
|
||||
@@ -181,6 +182,7 @@ open class BaseActivity : AppCompatActivity() {
|
||||
|
||||
|
||||
val netViewModel: NetViewModel by viewModels()
|
||||
val appViewModel: DbViewModel by viewModels()
|
||||
|
||||
private var permissionCallback: ((isGranted: Boolean) -> Unit)? = null
|
||||
private var activityCallback: ((intent: Intent?) -> Unit)? = null
|
||||
|
||||
@@ -6,7 +6,9 @@ import androidx.room.Room
|
||||
import androidx.room.RoomDatabase
|
||||
import androidx.room.migration.Migration
|
||||
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
import com.shuwei.dish.match.db.dao.AppDao
|
||||
import com.shuwei.dish.match.db.dao.CookFoodDao
|
||||
import com.shuwei.dish.match.db.dao.CookFoodGoodsDao
|
||||
import com.shuwei.dish.match.db.dao.SeasoningDao
|
||||
import com.shuwei.dish.match.db.dao.SeasoningSlotDao
|
||||
import com.shuwei.dish.match.entity.CookFoodEntity
|
||||
import com.shuwei.dish.match.entity.CookFoodGoodsEntity
|
||||
@@ -27,11 +29,12 @@ import com.shuwei.dish.match.entity.SeasoningSlotEntity
|
||||
exportSchema = true
|
||||
)
|
||||
abstract class AppDatabase : RoomDatabase() {
|
||||
// abstract fun seasoningDao(): SeasoningDao
|
||||
// abstract fun cookFoodDao(): CookFoodDao
|
||||
// abstract fun cookFoodGoodsDao(): CookFoodGoodsDao
|
||||
|
||||
abstract fun appDao(): AppDao
|
||||
abstract fun cookFoodDao(): CookFoodDao
|
||||
|
||||
abstract fun cookFoodGoodsDao(): CookFoodGoodsDao
|
||||
|
||||
abstract fun seasoningDao(): SeasoningDao
|
||||
|
||||
abstract fun seasoningSlotDao(): SeasoningSlotDao
|
||||
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package com.shuwei.dish.match.db
|
||||
|
||||
import com.shuwei.dish.match.base.BaseApp
|
||||
import com.shuwei.dish.match.db.dao.AppDao
|
||||
import com.shuwei.dish.match.db.dao.SeasoningSlotDao
|
||||
import com.shuwei.dish.match.entity.CookFoodEntity
|
||||
import com.shuwei.dish.match.entity.CookFoodGoodsEntity
|
||||
import com.shuwei.dish.match.entity.SeasoningEntity
|
||||
@@ -11,101 +9,95 @@ import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
|
||||
class DbRepository(val appDao: AppDao, val seasoningSlotDao: SeasoningSlotDao) {
|
||||
class DbRepository {
|
||||
|
||||
private val db = BaseApp.instance!!.database
|
||||
|
||||
suspend fun insertCookFood(item: CookFoodEntity) = withContext(Dispatchers.IO) {
|
||||
appDao.insertCookFood(item)
|
||||
db.cookFoodDao().insertCookFood(item)
|
||||
}
|
||||
|
||||
suspend fun updateCookFood(item: CookFoodEntity) = withContext(Dispatchers.IO) {
|
||||
appDao.updateCookFood(item)
|
||||
db.cookFoodDao().updateCookFood(item)
|
||||
}
|
||||
|
||||
suspend fun getCookFoodById(foodId: String, cookMode: Int) = withContext(Dispatchers.IO) {
|
||||
appDao.getCookFoodById(BaseApp.canteenId, foodId, cookMode)
|
||||
db.cookFoodDao().getCookFoodById(BaseApp.canteenId, foodId, cookMode)
|
||||
}
|
||||
|
||||
suspend fun getCookFoodList(cookMode: Int, dinnerType: String) = withContext(Dispatchers.IO) {
|
||||
appDao.getCookFoodList(BaseApp.canteenId, cookMode, dinnerType)
|
||||
db.cookFoodDao().getCookFoodList(BaseApp.canteenId, cookMode, dinnerType)
|
||||
}
|
||||
|
||||
suspend fun countCookFood(cookMode: Int) = withContext(Dispatchers.IO) {
|
||||
appDao.countCookFood(BaseApp.canteenId, cookMode)
|
||||
db.cookFoodDao().countCookFood(BaseApp.canteenId, cookMode)
|
||||
}
|
||||
|
||||
suspend fun deleteCookFood(foodId: String, cookMode: Int) = withContext(Dispatchers.IO) {
|
||||
appDao.deleteCookFood(BaseApp.canteenId, foodId, cookMode)
|
||||
db.cookFoodDao().deleteCookFood(BaseApp.canteenId, foodId, cookMode)
|
||||
}
|
||||
|
||||
suspend fun deleteCookFoodGoodsList(pid:Long, foodId: String) = withContext(Dispatchers.IO) {
|
||||
appDao.deleteCookFoodGoodsList(pid, foodId)
|
||||
suspend fun deleteCookFoodGoodsList(pid: Long, foodId: String) = withContext(Dispatchers.IO) {
|
||||
db.cookFoodGoodsDao().deleteCookFoodGoodsList(pid, foodId)
|
||||
}
|
||||
//--------------------------------------------------------------------------------------------
|
||||
|
||||
// suspend fun insertGoods(item: CookFoodGoodsEntity) = withContext(Dispatchers.IO) {
|
||||
// appDao.insertGoods(item)
|
||||
// }
|
||||
|
||||
suspend fun insertGoodsList(items: MutableList<CookFoodGoodsEntity>) =
|
||||
withContext(Dispatchers.IO) {
|
||||
appDao.insertGoodsList(items)
|
||||
db.cookFoodGoodsDao().insertGoodsList(items)
|
||||
}
|
||||
|
||||
// suspend fun updateGoods(item: CookFoodGoodsEntity) = withContext(Dispatchers.IO) {
|
||||
// appDao.updateGoods(item)
|
||||
// }
|
||||
|
||||
suspend fun getCookFoodGoodsList(pid:Long, foodId: String) = withContext(Dispatchers.IO) {
|
||||
appDao.getCookFoodGoodsList(pid, foodId)
|
||||
suspend fun getCookFoodGoodsList(pid: Long, foodId: String) = withContext(Dispatchers.IO) {
|
||||
db.cookFoodGoodsDao().getCookFoodGoodsList(pid, foodId)
|
||||
}
|
||||
|
||||
suspend fun getCookFoodGoodsListByType(
|
||||
foodId: String,
|
||||
materialType: Int
|
||||
) = withContext(Dispatchers.IO) {
|
||||
appDao.getCookFoodGoodsListByType(foodId, materialType)
|
||||
db.cookFoodGoodsDao().getCookFoodGoodsListByType(foodId, materialType)
|
||||
}
|
||||
//--------------------------------------------------------------------------------------------
|
||||
|
||||
suspend fun getSeasoningById(id: Long) = withContext(Dispatchers.IO) {
|
||||
appDao.getSeasoningById(id)
|
||||
db.seasoningDao().getSeasoningById(id)
|
||||
}
|
||||
|
||||
suspend fun getSeasoningBySort(sort:Int) = withContext(Dispatchers.IO) {
|
||||
appDao.getSeasoningBySort(sort)
|
||||
suspend fun getSeasoningBySort(sort: Int) = withContext(Dispatchers.IO) {
|
||||
db.seasoningDao().getSeasoningBySort(sort)
|
||||
}
|
||||
|
||||
suspend fun getSeasoningByGoodsId(goodsId: Int) = withContext(Dispatchers.IO) {
|
||||
appDao.getSeasoningByGoodsId(goodsId)
|
||||
db.seasoningDao().getSeasoningByGoodsId(goodsId)
|
||||
}
|
||||
|
||||
suspend fun getAllStream() = withContext(Dispatchers.IO) {
|
||||
appDao.getAllStream()
|
||||
db.seasoningDao().getAllStream()
|
||||
}
|
||||
|
||||
suspend fun search(query: String) = withContext(Dispatchers.IO) {
|
||||
appDao.search(query)
|
||||
db.seasoningDao().search(query)
|
||||
}
|
||||
|
||||
suspend fun clearAllSeasoning() = withContext(Dispatchers.IO) {
|
||||
appDao.clearAllSeasoning()
|
||||
db.seasoningDao().clearAllSeasoning()
|
||||
}
|
||||
|
||||
suspend fun deleteSeasoningBySort(sort: Int) = withContext(Dispatchers.IO) {
|
||||
appDao.deleteSeasoningBySort(sort)
|
||||
db.seasoningDao().deleteSeasoningBySort(sort)
|
||||
}
|
||||
|
||||
suspend fun insertSeasoningList(items: MutableList<SeasoningEntity>) =
|
||||
withContext(Dispatchers.IO) {
|
||||
appDao.insertSeasoningList(items)
|
||||
db.seasoningDao().insertSeasoningList(items)
|
||||
}
|
||||
|
||||
suspend fun updateSeasoning(item: SeasoningEntity) = withContext(Dispatchers.IO) {
|
||||
appDao.updateSeasoning(item)
|
||||
db.seasoningDao().updateSeasoning(item)
|
||||
}
|
||||
|
||||
suspend fun insertSeasoning(item: SeasoningEntity) = withContext(Dispatchers.IO) {
|
||||
appDao.insertSeasoning(item)
|
||||
db.seasoningDao().insertSeasoning(item)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -114,14 +106,14 @@ class DbRepository(val appDao: AppDao, val seasoningSlotDao: SeasoningSlotDao) {
|
||||
* @return true 表示已有配置,false 表示未配置
|
||||
*/
|
||||
suspend fun hasSeasoningSlotConfig(deviceId: String) = withContext(Dispatchers.IO) {
|
||||
seasoningSlotDao.queryByDeviceId(deviceId).isNotEmpty()
|
||||
db.seasoningSlotDao().queryByDeviceId(deviceId).isNotEmpty()
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有设备的调料槽位配置
|
||||
*/
|
||||
suspend fun getAllSeasoningSlots() = withContext(Dispatchers.IO) {
|
||||
seasoningSlotDao.queryAll()
|
||||
db.seasoningSlotDao().queryAll()
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -129,21 +121,21 @@ class DbRepository(val appDao: AppDao, val seasoningSlotDao: SeasoningSlotDao) {
|
||||
* @param deviceId 目标设备 ID
|
||||
*/
|
||||
suspend fun getSeasoningSlotsByDeviceId(deviceId: String) = withContext(Dispatchers.IO) {
|
||||
seasoningSlotDao.queryByDeviceId(deviceId)
|
||||
db.seasoningSlotDao().queryByDeviceId(deviceId)
|
||||
}
|
||||
|
||||
/**
|
||||
* 插入或更新单个调料槽位配置
|
||||
*/
|
||||
suspend fun upsertSeasoningSlot(slot: SeasoningSlotEntity) = withContext(Dispatchers.IO) {
|
||||
seasoningSlotDao.upsert(slot)
|
||||
db.seasoningSlotDao().upsert(slot)
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量插入或更新调料槽位配置
|
||||
*/
|
||||
suspend fun upsertAllSeasoningSlots(slots: List<SeasoningSlotEntity>) = withContext(Dispatchers.IO) {
|
||||
seasoningSlotDao.upsertAll(slots)
|
||||
db.seasoningSlotDao().upsertAll(slots)
|
||||
}
|
||||
}
|
||||
//
|
||||
|
||||
+4
-3
@@ -1,8 +1,7 @@
|
||||
package com.shuwei.dish.match.viewmodel
|
||||
package com.shuwei.dish.match.db
|
||||
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.shuwei.dish.match.db.DbRepository
|
||||
import com.shuwei.dish.match.entity.CookFoodEntity
|
||||
import com.shuwei.dish.match.entity.CookFoodGoodsEntity
|
||||
import com.shuwei.dish.match.entity.SeasoningEntity
|
||||
@@ -15,7 +14,9 @@ import kotlinx.coroutines.sync.Mutex
|
||||
import kotlinx.coroutines.sync.withLock
|
||||
import kotlin.collections.forEach
|
||||
|
||||
class DbViewModel(private val rep: DbRepository) : ViewModel() {
|
||||
class DbViewModel : ViewModel() {
|
||||
|
||||
private val rep = DbRepository()
|
||||
|
||||
fun updateCookFood(entity: CookFoodEntity) {
|
||||
viewModelScope.launch {
|
||||
@@ -1,92 +0,0 @@
|
||||
package com.shuwei.dish.match.db.dao
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Insert
|
||||
import androidx.room.OnConflictStrategy
|
||||
import androidx.room.Query
|
||||
import androidx.room.Update
|
||||
import com.shuwei.dish.match.entity.CookFoodEntity
|
||||
import com.shuwei.dish.match.entity.CookFoodGoodsEntity
|
||||
import com.shuwei.dish.match.entity.SeasoningEntity
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
@Dao
|
||||
interface AppDao {
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun insertCookFood(item: CookFoodEntity): Long
|
||||
|
||||
@Update
|
||||
suspend fun updateCookFood(item: CookFoodEntity)
|
||||
|
||||
@Query("SELECT * FROM dm_cook_food WHERE isDel = 0 AND canteenId = :canteenId AND foodId = :foodId AND cookMode = :cookMode")
|
||||
suspend fun getCookFoodById(canteenId:String, foodId: String, cookMode: Int): CookFoodEntity?
|
||||
|
||||
@Query("SELECT * FROM dm_cook_food WHERE isDel = 0 AND canteenId = :canteenId AND cookMode = :cookMode AND dinnerType = :dinnerType ORDER BY createTime DESC")
|
||||
suspend fun getCookFoodList(canteenId:String, cookMode: Int, dinnerType:String): MutableList<CookFoodEntity>?
|
||||
|
||||
@Query("SELECT count(1) FROM dm_cook_food WHERE isDel = 0 AND canteenId = :canteenId AND cookMode = :cookMode")
|
||||
suspend fun countCookFood(canteenId:String, cookMode: Int): Int
|
||||
|
||||
@Query("DELETE FROM dm_cook_food WHERE canteenId = :canteenId AND foodId = :foodId AND cookMode = :cookMode")
|
||||
suspend fun deleteCookFood(canteenId:String, foodId: String, cookMode: Int)
|
||||
|
||||
//--------------------------------------------------------------------------------------------
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun insertGoods(item: CookFoodGoodsEntity): Long
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun insertGoodsList(items: MutableList<CookFoodGoodsEntity>): Array<Long>
|
||||
|
||||
@Update
|
||||
suspend fun updateGoods(item: CookFoodGoodsEntity)
|
||||
|
||||
@Query("SELECT * FROM dm_cook_food_goods WHERE isDel = 0 AND pid = :pid AND foodId = :foodId")
|
||||
suspend fun getCookFoodGoodsList(pid:Long, foodId: String): MutableList<CookFoodGoodsEntity>
|
||||
|
||||
@Query("SELECT * FROM dm_cook_food_goods WHERE isDel = 0 AND foodId = :foodId AND materialType = :materialType")
|
||||
suspend fun getCookFoodGoodsListByType(
|
||||
foodId: String,
|
||||
materialType: Int
|
||||
): MutableList<CookFoodGoodsEntity>
|
||||
|
||||
@Query("DELETE FROM dm_cook_food_goods WHERE pid = :pid AND foodId = :foodId")
|
||||
suspend fun deleteCookFoodGoodsList(pid:Long, foodId: String)
|
||||
|
||||
//--------------------------------------------------------------------------------------------
|
||||
|
||||
@Query("SELECT * FROM dm_seasoning WHERE isDel = 0 AND id = :id")
|
||||
suspend fun getSeasoningById(id: Long): SeasoningEntity?
|
||||
|
||||
@Query("SELECT * FROM dm_seasoning WHERE isDel = 0 AND sort = :sort")
|
||||
suspend fun getSeasoningBySort(sort: Int): MutableList<SeasoningEntity>?
|
||||
|
||||
@Query("SELECT * FROM dm_seasoning WHERE isDel = 0 AND goodsId = :goodsId")
|
||||
suspend fun getSeasoningByGoodsId(goodsId: Int): SeasoningEntity?
|
||||
|
||||
// @Query("SELECT * FROM dm_seasoning WHERE isDel = 0 AND goodsId != -1 AND goodsName != '' ORDER BY sort ASC")
|
||||
// fun getAllStream(): Flow<MutableList<SeasoningEntity>>
|
||||
|
||||
@Query("SELECT * FROM dm_seasoning WHERE isDel = 0 AND goodsId != -1 AND goodsName != '' ORDER BY sort ASC")
|
||||
fun getAllStream(): MutableList<SeasoningEntity>
|
||||
|
||||
@Query("SELECT * FROM dm_seasoning WHERE isDel = 0 AND goodsName LIKE '%' || :query || '%'")
|
||||
suspend fun search(query: String): MutableList<SeasoningEntity>
|
||||
|
||||
@Query("DELETE FROM dm_seasoning WHERE isDel = 0 AND sort = :sort")
|
||||
suspend fun deleteSeasoningBySort(sort:Int): Int
|
||||
|
||||
@Query("DELETE FROM dm_seasoning WHERE isDel = 0")
|
||||
suspend fun clearAllSeasoning(): Int
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun insertSeasoningList(items: MutableList<SeasoningEntity>): Array<Long>
|
||||
|
||||
@Update
|
||||
suspend fun updateSeasoning(item: SeasoningEntity)
|
||||
|
||||
@Insert
|
||||
suspend fun insertSeasoning(item: SeasoningEntity): Long
|
||||
//--------------------------------------------------------------------------------------------
|
||||
}
|
||||
@@ -1,20 +1,30 @@
|
||||
//package com.shuwei.dish.match.db.dao
|
||||
//
|
||||
//import androidx.room.Dao
|
||||
//import androidx.room.Query
|
||||
//import com.shuwei.dish.match.db.BaseDao
|
||||
//import com.shuwei.dish.match.entity.CookFoodEntity
|
||||
//
|
||||
//@Dao
|
||||
//interface CookFoodDao : BaseDao<CookFoodEntity> {
|
||||
//
|
||||
// @Query("SELECT * FROM dm_cook_food WHERE isDel = 0 AND foodId = :foodId AND cookMode = :cookMode")
|
||||
// suspend fun getCookFoodById(foodId: String, cookMode:Int): CookFoodEntity?
|
||||
//
|
||||
// @Query("SELECT * FROM dm_cook_food WHERE isDel = 0 AND cookMode = :cookMode")
|
||||
// suspend fun getCookFoodList(cookMode:Int): MutableList<CookFoodEntity>?
|
||||
//
|
||||
// @Query("SELECT count(1) FROM dm_cook_food WHERE isDel = 0 AND cookMode = :cookMode")
|
||||
// suspend fun countCookFood(cookMode:Int): Int
|
||||
//
|
||||
//}
|
||||
package com.shuwei.dish.match.db.dao
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Insert
|
||||
import androidx.room.OnConflictStrategy
|
||||
import androidx.room.Query
|
||||
import androidx.room.Update
|
||||
import com.shuwei.dish.match.entity.CookFoodEntity
|
||||
|
||||
@Dao
|
||||
interface CookFoodDao {
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun insertCookFood(item: CookFoodEntity): Long
|
||||
|
||||
@Update
|
||||
suspend fun updateCookFood(item: CookFoodEntity)
|
||||
|
||||
@Query("SELECT * FROM dm_cook_food WHERE isDel = 0 AND canteenId = :canteenId AND foodId = :foodId AND cookMode = :cookMode")
|
||||
suspend fun getCookFoodById(canteenId: String, foodId: String, cookMode: Int): CookFoodEntity?
|
||||
|
||||
@Query("SELECT * FROM dm_cook_food WHERE isDel = 0 AND canteenId = :canteenId AND cookMode = :cookMode AND dinnerType = :dinnerType ORDER BY createTime DESC")
|
||||
suspend fun getCookFoodList(canteenId: String, cookMode: Int, dinnerType: String): MutableList<CookFoodEntity>?
|
||||
|
||||
@Query("SELECT count(1) FROM dm_cook_food WHERE isDel = 0 AND canteenId = :canteenId AND cookMode = :cookMode")
|
||||
suspend fun countCookFood(canteenId: String, cookMode: Int): Int
|
||||
|
||||
@Query("DELETE FROM dm_cook_food WHERE canteenId = :canteenId AND foodId = :foodId AND cookMode = :cookMode")
|
||||
suspend fun deleteCookFood(canteenId: String, foodId: String, cookMode: Int)
|
||||
}
|
||||
|
||||
@@ -1,29 +1,30 @@
|
||||
//package com.shuwei.dish.match.db.dao
|
||||
//
|
||||
//import androidx.room.Dao
|
||||
//import androidx.room.Query
|
||||
//import com.shuwei.dish.match.db.BaseDao
|
||||
//import com.shuwei.dish.match.entity.CookFoodGoodsEntity
|
||||
//
|
||||
//@Dao
|
||||
//interface CookFoodGoodsDao : BaseDao<CookFoodGoodsEntity> {
|
||||
//
|
||||
// @Query("SELECT * FROM dm_cook_food_goods WHERE isDel = 0 AND foodId = :foodId")
|
||||
// suspend fun getCookFoodGoodsList(foodId: String): MutableList<CookFoodGoodsEntity>
|
||||
//
|
||||
// @Query("SELECT * FROM dm_cook_food_goods WHERE isDel = 0 AND foodId = :foodId AND materialType = :materialType")
|
||||
// suspend fun getCookFoodGoodsListByType(foodId: String, materialType:Int): MutableList<CookFoodGoodsEntity>
|
||||
//
|
||||
//// @Query(
|
||||
//// """
|
||||
//// UPDATE dm_cook_food_goods
|
||||
//// SET goodsName=:entity.goodsName, foodId=:entity.foodId, relateionType=:entity.relateionType, sort=:entity.sort
|
||||
//// allEdible=:entity.allEdible, useWeight=:entity.useWeight, isDel=:entity.isDel, createTime=:entity.createTime
|
||||
//// WHERE isDel = 0
|
||||
//// AND foodId=:entity.foodId
|
||||
//// AND goodsId=:goodsId
|
||||
//// """
|
||||
//// )
|
||||
//// fun updateByGoodsId(entity: CookFoodGoodsEntity)
|
||||
//
|
||||
//}
|
||||
package com.shuwei.dish.match.db.dao
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Insert
|
||||
import androidx.room.OnConflictStrategy
|
||||
import androidx.room.Query
|
||||
import androidx.room.Update
|
||||
import com.shuwei.dish.match.entity.CookFoodGoodsEntity
|
||||
|
||||
@Dao
|
||||
interface CookFoodGoodsDao {
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun insertGoods(item: CookFoodGoodsEntity): Long
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun insertGoodsList(items: MutableList<CookFoodGoodsEntity>): Array<Long>
|
||||
|
||||
@Update
|
||||
suspend fun updateGoods(item: CookFoodGoodsEntity)
|
||||
|
||||
@Query("SELECT * FROM dm_cook_food_goods WHERE isDel = 0 AND pid = :pid AND foodId = :foodId")
|
||||
suspend fun getCookFoodGoodsList(pid: Long, foodId: String): MutableList<CookFoodGoodsEntity>
|
||||
|
||||
@Query("SELECT * FROM dm_cook_food_goods WHERE isDel = 0 AND foodId = :foodId AND materialType = :materialType")
|
||||
suspend fun getCookFoodGoodsListByType(foodId: String, materialType: Int): MutableList<CookFoodGoodsEntity>
|
||||
|
||||
@Query("DELETE FROM dm_cook_food_goods WHERE pid = :pid AND foodId = :foodId")
|
||||
suspend fun deleteCookFoodGoodsList(pid: Long, foodId: String)
|
||||
}
|
||||
|
||||
@@ -1,25 +1,42 @@
|
||||
//package com.shuwei.dish.match.db.dao
|
||||
//
|
||||
//import androidx.room.Dao
|
||||
//import androidx.room.Query
|
||||
//import com.shuwei.dish.match.db.BaseDao
|
||||
//import com.shuwei.dish.match.entity.SeasoningEntity
|
||||
//import kotlinx.coroutines.flow.Flow
|
||||
//
|
||||
//@Dao
|
||||
//interface SeasoningDao : BaseDao<SeasoningEntity> {
|
||||
//
|
||||
//// @Query("SELECT * FROM dm_seasoning WHERE isDel = 0 AND id = :id")
|
||||
//// suspend fun getSeasoningById(id: Long): SeasoningEntity?
|
||||
////
|
||||
//// @Query("SELECT * FROM dm_seasoning WHERE isDel = 0 ORDER BY sort ASC")
|
||||
//// fun getAllStream(): Flow<MutableList<SeasoningEntity>>
|
||||
////
|
||||
//// @Query("SELECT * FROM dm_seasoning WHERE isDel = 0 AND name LIKE '%' || :query || '%'")
|
||||
//// suspend fun search(query: String): MutableList<SeasoningEntity>
|
||||
////
|
||||
//// @Query("DELETE FROM dm_seasoning WHERE rowid IN " +
|
||||
//// "(SELECT rowid FROM dm_seasoning LIMIT 1000)")
|
||||
//// suspend fun deleteBatch(): Int
|
||||
//
|
||||
//}
|
||||
package com.shuwei.dish.match.db.dao
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Insert
|
||||
import androidx.room.OnConflictStrategy
|
||||
import androidx.room.Query
|
||||
import androidx.room.Update
|
||||
import com.shuwei.dish.match.entity.SeasoningEntity
|
||||
|
||||
@Dao
|
||||
interface SeasoningDao {
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun insertSeasoning(item: SeasoningEntity): Long
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun insertSeasoningList(items: MutableList<SeasoningEntity>): Array<Long>
|
||||
|
||||
@Update
|
||||
suspend fun updateSeasoning(item: SeasoningEntity)
|
||||
|
||||
@Query("SELECT * FROM dm_seasoning WHERE isDel = 0 AND id = :id")
|
||||
suspend fun getSeasoningById(id: Long): SeasoningEntity?
|
||||
|
||||
@Query("SELECT * FROM dm_seasoning WHERE isDel = 0 AND sort = :sort")
|
||||
suspend fun getSeasoningBySort(sort: Int): MutableList<SeasoningEntity>?
|
||||
|
||||
@Query("SELECT * FROM dm_seasoning WHERE isDel = 0 AND goodsId = :goodsId")
|
||||
suspend fun getSeasoningByGoodsId(goodsId: Int): SeasoningEntity?
|
||||
|
||||
@Query("SELECT * FROM dm_seasoning WHERE isDel = 0 AND goodsId != -1 AND goodsName != '' ORDER BY sort ASC")
|
||||
fun getAllStream(): MutableList<SeasoningEntity>
|
||||
|
||||
@Query("SELECT * FROM dm_seasoning WHERE isDel = 0 AND goodsName LIKE '%' || :query || '%'")
|
||||
suspend fun search(query: String): MutableList<SeasoningEntity>
|
||||
|
||||
@Query("DELETE FROM dm_seasoning WHERE isDel = 0 AND sort = :sort")
|
||||
suspend fun deleteSeasoningBySort(sort: Int): Int
|
||||
|
||||
@Query("DELETE FROM dm_seasoning WHERE isDel = 0")
|
||||
suspend fun clearAllSeasoning(): Int
|
||||
}
|
||||
|
||||
@@ -29,8 +29,6 @@
|
||||
//import com.shuwei.dish.match.utils.ext.startActivity
|
||||
//import com.shuwei.dish.match.utils.ext.toast
|
||||
//import com.shuwei.dish.match.utils.ext.visible
|
||||
//import com.shuwei.dish.match.viewmodel.DbViewModel
|
||||
//import com.shuwei.dish.match.viewmodel.factory.AppFactory
|
||||
//import com.shuwei.dish.match.adapter.TextCellAdapter
|
||||
//import com.shuwei.dish.match.databinding.ActivityDeviceConfigBinding
|
||||
//import com.shuwei.dish.match.dialog.SeasoningSearchDialog
|
||||
|
||||
@@ -7,7 +7,6 @@ import android.util.Log
|
||||
import android.view.View
|
||||
import androidx.activity.addCallback
|
||||
import androidx.activity.viewModels
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.recyclerview.widget.ItemTouchHelper
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.shuwei.dish.match.R
|
||||
@@ -15,7 +14,6 @@ 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.ActivityDishSamplingBinding
|
||||
import com.shuwei.dish.match.db.DbRepository
|
||||
import com.shuwei.dish.match.dialog.FoodSearchDialog
|
||||
import com.shuwei.dish.match.dialog.CommonDialog
|
||||
import com.shuwei.dish.match.entity.CookFoodEntity
|
||||
@@ -33,8 +31,6 @@ 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.DbViewModel
|
||||
import com.shuwei.dish.match.viewmodel.factory.AppFactory
|
||||
import java.io.Serializable
|
||||
|
||||
class DishSamplingActivity : BaseActivity() {
|
||||
@@ -62,7 +58,6 @@ class DishSamplingActivity : BaseActivity() {
|
||||
setTitleBar()
|
||||
setHeaderBackground()
|
||||
addViewClickListener()
|
||||
initViewModel()
|
||||
foodName = intent.getStringExtra(FOOD_NAME)
|
||||
binding.etInputDish.setText(foodName)
|
||||
|
||||
@@ -97,15 +92,7 @@ class DishSamplingActivity : BaseActivity() {
|
||||
})
|
||||
}
|
||||
|
||||
private lateinit var appViewModel: DbViewModel
|
||||
|
||||
private fun initViewModel() {
|
||||
val db = BaseApp.instance!!.database
|
||||
val factory =
|
||||
AppFactory(DbRepository(db.appDao(), db.seasoningSlotDao()))
|
||||
appViewModel =
|
||||
ViewModelProvider(this, factory)[DbViewModel::class.java]
|
||||
}
|
||||
|
||||
fun getCookFoodList() {
|
||||
appViewModel.getCookFoodList(cookMode = 1)
|
||||
|
||||
@@ -3,7 +3,6 @@ package com.shuwei.dish.match.ui
|
||||
import android.annotation.SuppressLint
|
||||
import android.os.Bundle
|
||||
import androidx.activity.addCallback
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.shuwei.dish.match.R
|
||||
@@ -11,13 +10,10 @@ import com.shuwei.dish.match.adapter.HomeModeAdapter
|
||||
import com.shuwei.dish.match.base.BaseActivity
|
||||
import com.shuwei.dish.match.base.BaseApp
|
||||
import com.shuwei.dish.match.databinding.ActivityHomeBinding
|
||||
import com.shuwei.dish.match.db.DbRepository
|
||||
import com.shuwei.dish.match.entity.HomeModeBean
|
||||
import com.shuwei.dish.match.utils.SpTool
|
||||
import com.shuwei.dish.match.utils.ext.startActivity
|
||||
import com.shuwei.dish.match.utils.ext.toast
|
||||
import com.shuwei.dish.match.viewmodel.DbViewModel
|
||||
import com.shuwei.dish.match.viewmodel.factory.AppFactory
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class HomeActivity : BaseActivity() {
|
||||
@@ -34,7 +30,6 @@ class HomeActivity : BaseActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
statusBarDarkFont(enable = true)
|
||||
initViewModel()
|
||||
// // 获取 ANDROID_ID
|
||||
// val deviceId =
|
||||
// Settings.Secure.getString(contentResolver, Settings.Secure.ANDROID_ID)
|
||||
@@ -136,13 +131,7 @@ class HomeActivity : BaseActivity() {
|
||||
)
|
||||
}
|
||||
|
||||
private lateinit var appViewModel: DbViewModel
|
||||
|
||||
private fun initViewModel() {
|
||||
val db = BaseApp.instance!!.database
|
||||
val factory = AppFactory(DbRepository(db.appDao(), db.seasoningSlotDao()))
|
||||
appViewModel = ViewModelProvider(this, factory)[DbViewModel::class.java]
|
||||
}
|
||||
|
||||
private fun goSampling() {
|
||||
lifecycleScope.launch {
|
||||
|
||||
@@ -9,14 +9,12 @@ import android.view.KeyEvent
|
||||
import android.view.animation.RotateAnimation
|
||||
import androidx.activity.addCallback
|
||||
import androidx.core.graphics.toColorInt
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.shuwei.dish.match.base.BaseActivity
|
||||
import com.shuwei.dish.match.base.BaseApp
|
||||
import com.shuwei.dish.match.base.DeviceRole
|
||||
import com.shuwei.dish.match.base.GlobalData
|
||||
import com.shuwei.dish.match.databinding.ActivityInitBinding
|
||||
import com.shuwei.dish.match.db.DbRepository
|
||||
import com.shuwei.dish.match.objbox.FoodModule
|
||||
import com.shuwei.dish.match.scale.ScaleServiceManager
|
||||
import com.shuwei.dish.match.utils.AppUtil
|
||||
@@ -27,8 +25,6 @@ import com.shuwei.dish.match.utils.WeightUtil
|
||||
import com.shuwei.dish.match.utils.ext.gone
|
||||
import com.shuwei.dish.match.utils.ext.startActivity
|
||||
import com.shuwei.dish.match.utils.ext.visible
|
||||
import com.shuwei.dish.match.viewmodel.DbViewModel
|
||||
import com.shuwei.dish.match.viewmodel.factory.AppFactory
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
@@ -38,7 +34,6 @@ class InitActivity : BaseActivity() {
|
||||
}
|
||||
|
||||
private lateinit var binding: ActivityInitBinding
|
||||
private lateinit var appViewModel: DbViewModel
|
||||
private var startTime = 0L // 倒计时开始时间
|
||||
private var lastNetworkCheckTime = 0L // 上次检测网络的时间
|
||||
|
||||
@@ -59,8 +54,6 @@ class InitActivity : BaseActivity() {
|
||||
|
||||
BaseApp.canteenId = "0"
|
||||
|
||||
initViewModel()
|
||||
|
||||
WeightUtil.init()
|
||||
WeightUtil.getWeight()
|
||||
WeightUtil.startContinuousRead()
|
||||
@@ -68,11 +61,6 @@ class InitActivity : BaseActivity() {
|
||||
initViews()
|
||||
}
|
||||
|
||||
private fun initViewModel() {
|
||||
val db = BaseApp.instance!!.database
|
||||
val factory = AppFactory(DbRepository(db.appDao(), db.seasoningSlotDao()))
|
||||
appViewModel = ViewModelProvider(this, factory)[DbViewModel::class.java]
|
||||
}
|
||||
|
||||
private fun startNextPage(withDelay: Boolean = false) {
|
||||
lifecycleScope.launch {
|
||||
|
||||
@@ -26,10 +26,6 @@ import com.shuwei.dish.match.databinding.ListTypeScale18Binding
|
||||
import com.shuwei.dish.match.databinding.ListTypeScale2Binding
|
||||
import com.shuwei.dish.match.databinding.ListTypeScale22Binding
|
||||
import com.shuwei.dish.match.base.BaseApp
|
||||
import com.shuwei.dish.match.db.DbRepository
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import com.shuwei.dish.match.viewmodel.DbViewModel
|
||||
import com.shuwei.dish.match.viewmodel.factory.AppFactory
|
||||
import com.shuwei.dish.match.databinding.ListItemScale22RowBinding
|
||||
import com.shuwei.dish.match.scale.ScaleData
|
||||
import com.shuwei.dish.match.scale.ScaleDeviceConfig
|
||||
@@ -56,7 +52,6 @@ class MasterScaleActivity : BaseActivity() {
|
||||
private lateinit var binding: ActivityMasterScaleBinding
|
||||
private val size by lazy { SizeTool.getFlexLayoutSize(10.dp) }
|
||||
|
||||
private lateinit var appViewModel: DbViewModel
|
||||
private data class DeviceGroup(
|
||||
val deviceId: String,
|
||||
val ip: String,
|
||||
@@ -80,8 +75,6 @@ class MasterScaleActivity : BaseActivity() {
|
||||
binding.rvScaleList.itemAnimator = null
|
||||
binding.rvScaleList.adapter = adapter
|
||||
|
||||
val db = BaseApp.instance!!.database
|
||||
appViewModel = ViewModelProvider(this, AppFactory(DbRepository(db.appDao(), db.seasoningSlotDao())))[DbViewModel::class.java]
|
||||
loadSlotNames()
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import androidx.activity.addCallback
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.lifecycle.repeatOnLifecycle
|
||||
import androidx.recyclerview.widget.ItemTouchHelper
|
||||
@@ -17,7 +16,6 @@ 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.DbRepository
|
||||
import com.shuwei.dish.match.dialog.CommonDialog
|
||||
import com.shuwei.dish.match.entity.CookFoodEntity
|
||||
import com.shuwei.dish.match.entity.FoodRecord
|
||||
@@ -27,8 +25,6 @@ import com.shuwei.dish.match.utils.ext.gone
|
||||
import com.shuwei.dish.match.utils.ext.startActivity
|
||||
import com.shuwei.dish.match.utils.ext.toast
|
||||
import com.shuwei.dish.match.utils.ext.visible
|
||||
import com.shuwei.dish.match.viewmodel.DbViewModel
|
||||
import com.shuwei.dish.match.viewmodel.factory.AppFactory
|
||||
import java.io.Serializable
|
||||
import kotlinx.coroutines.launch
|
||||
import com.shuwei.dish.match.net.UiState
|
||||
@@ -49,7 +45,6 @@ class SamplingListActivity : BaseActivity() {
|
||||
setContentView(binding.root)
|
||||
setTitleBar()
|
||||
setHeaderBackground()
|
||||
initViewModel()
|
||||
initRecyclerView()
|
||||
addViewListener()
|
||||
initObserver()
|
||||
@@ -128,13 +123,7 @@ class SamplingListActivity : BaseActivity() {
|
||||
|
||||
}
|
||||
|
||||
private lateinit var appViewModel: DbViewModel
|
||||
|
||||
private fun initViewModel() {
|
||||
val db = BaseApp.instance!!.database
|
||||
val factory = AppFactory(DbRepository(db.appDao(), db.seasoningSlotDao()))
|
||||
appViewModel = ViewModelProvider(this, factory)[DbViewModel::class.java]
|
||||
}
|
||||
|
||||
fun getCookFoodList() {
|
||||
appViewModel.getCookFoodList(cookMode = 1)
|
||||
|
||||
@@ -3,14 +3,12 @@ package com.shuwei.dish.match.ui
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import androidx.activity.addCallback
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import kotlinx.coroutines.launch
|
||||
import com.shuwei.dish.match.R
|
||||
import com.shuwei.dish.match.base.BaseActivity
|
||||
import com.shuwei.dish.match.base.BaseApp
|
||||
import com.shuwei.dish.match.databinding.ActivitySelectDishBinding
|
||||
import com.shuwei.dish.match.db.DbRepository
|
||||
import com.shuwei.dish.match.dialog.CommonDialog
|
||||
import com.shuwei.dish.match.ui.fragment.DishListFragment
|
||||
import com.shuwei.dish.match.utils.KeyboardUtil
|
||||
@@ -19,8 +17,6 @@ import com.shuwei.dish.match.utils.ext.gone
|
||||
import com.shuwei.dish.match.utils.ext.startActivity
|
||||
import com.shuwei.dish.match.utils.ext.toast
|
||||
import com.shuwei.dish.match.utils.ext.visible
|
||||
import com.shuwei.dish.match.viewmodel.DbViewModel
|
||||
import com.shuwei.dish.match.viewmodel.factory.AppFactory
|
||||
|
||||
class SelectDishActivity : BaseActivity() {
|
||||
|
||||
@@ -32,9 +28,6 @@ class SelectDishActivity : BaseActivity() {
|
||||
|
||||
private lateinit var binding: ActivitySelectDishBinding
|
||||
|
||||
lateinit var appViewModel: DbViewModel
|
||||
private set
|
||||
|
||||
private var dinnerType: String = "1"
|
||||
|
||||
private val fragmentList = mutableListOf<DishListFragment>().apply {
|
||||
@@ -61,17 +54,11 @@ class SelectDishActivity : BaseActivity() {
|
||||
}, backAction = {
|
||||
it.gone()
|
||||
})
|
||||
initViewModel()
|
||||
addViewListener()
|
||||
loadFragment()
|
||||
onBackPressedDispatcher.addCallback(this) {}
|
||||
}
|
||||
|
||||
private fun initViewModel() {
|
||||
val db = BaseApp.instance!!.database
|
||||
val factory = AppFactory(DbRepository(db.appDao(), db.seasoningSlotDao()))
|
||||
appViewModel = ViewModelProvider(this, factory)[DbViewModel::class.java]
|
||||
}
|
||||
|
||||
fun getCookFoodList() {
|
||||
appViewModel.getCookFoodList(cookMode = 0, dinnerType = dinnerType)
|
||||
|
||||
@@ -4,17 +4,13 @@ import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import com.shuwei.dish.match.base.BaseActivity
|
||||
import com.shuwei.dish.match.base.BaseApp
|
||||
import com.shuwei.dish.match.db.DbRepository
|
||||
import com.shuwei.dish.match.ui.fragment.CollectFragment
|
||||
import com.shuwei.dish.match.ui.fragment.DeviceConfigFragment
|
||||
import com.shuwei.dish.match.ui.fragment.SeasoningConfigFragment
|
||||
import com.shuwei.dish.match.utils.ext.gone
|
||||
import com.shuwei.dish.match.utils.ext.visible
|
||||
import com.shuwei.dish.match.viewmodel.DbViewModel
|
||||
import com.shuwei.dish.match.viewmodel.factory.AppFactory
|
||||
|
||||
/**
|
||||
* 通用单 Fragment 容器 Activity
|
||||
@@ -63,15 +59,9 @@ class SingleFragmentActivity : BaseActivity() {
|
||||
lifecycleCallback = callback
|
||||
}
|
||||
|
||||
lateinit var appViewModel: DbViewModel
|
||||
private set
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
val db = BaseApp.instance!!.database
|
||||
appViewModel = ViewModelProvider(this, AppFactory(DbRepository(db.appDao(), db.seasoningSlotDao())))[DbViewModel::class.java]
|
||||
|
||||
setHeaderBackground()
|
||||
|
||||
// 解析页面类型,非法值直接关闭
|
||||
|
||||
@@ -31,10 +31,6 @@ import com.shuwei.dish.match.utils.SizeTool
|
||||
import com.shuwei.dish.match.utils.WeightUtil
|
||||
import com.shuwei.dish.match.utils.ext.dp
|
||||
import kotlinx.coroutines.launch
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import com.shuwei.dish.match.db.DbRepository
|
||||
import com.shuwei.dish.match.viewmodel.DbViewModel
|
||||
import com.shuwei.dish.match.viewmodel.factory.AppFactory
|
||||
|
||||
/**
|
||||
* 子设备专属页面(小屏幕设备使用)
|
||||
@@ -66,17 +62,12 @@ class SlaveActivity : BaseActivity() {
|
||||
private var clearHighlightRunnable: Runnable? = null
|
||||
private val size by lazy { SizeTool.getFlexLayoutSize(10.dp) }
|
||||
|
||||
private lateinit var appViewModel: DbViewModel
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
binding = ActivitySlaveBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
setHeaderBackground()
|
||||
|
||||
val db = BaseApp.instance!!.database
|
||||
appViewModel = ViewModelProvider(this, AppFactory(DbRepository(db.appDao(), db.seasoningSlotDao())))[DbViewModel::class.java]
|
||||
|
||||
binding.tvDeviceId.text = "设备:${GlobalData.deviceId}"
|
||||
binding.tvDeviceIp.text = "IP:${getLocalIpAddress()}"
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ import android.annotation.SuppressLint
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import androidx.activity.addCallback
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.lifecycle.repeatOnLifecycle
|
||||
@@ -15,7 +14,6 @@ import com.shuwei.dish.match.adapter.SeasoningWeightAdapter
|
||||
import com.shuwei.dish.match.base.BaseActivity
|
||||
import com.shuwei.dish.match.base.BaseApp
|
||||
import com.shuwei.dish.match.databinding.ActivitySubmitFoodBinding
|
||||
import com.shuwei.dish.match.db.DbRepository
|
||||
import com.shuwei.dish.match.dialog.CommonDialog
|
||||
import com.shuwei.dish.match.entity.CookFoodEntity
|
||||
import com.shuwei.dish.match.entity.CookFoodGoodsEntity
|
||||
@@ -35,8 +33,6 @@ import com.shuwei.dish.match.utils.ext.toJsonString
|
||||
import com.shuwei.dish.match.utils.ext.toType
|
||||
import com.shuwei.dish.match.utils.ext.toast
|
||||
import com.shuwei.dish.match.utils.ext.visible
|
||||
import com.shuwei.dish.match.viewmodel.DbViewModel
|
||||
import com.shuwei.dish.match.viewmodel.factory.AppFactory
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.collectLatest
|
||||
import kotlinx.coroutines.launch
|
||||
@@ -100,7 +96,6 @@ class SubmitFoodActivity : BaseActivity() {
|
||||
super.onCreate(savedInstanceState)
|
||||
binding = ActivitySubmitFoodBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
initViewModel()
|
||||
setHeaderBackground()
|
||||
intent.extras?.apply {
|
||||
food = getSerializable(FOOD_ITEM) as FoodRecord?
|
||||
@@ -406,13 +401,7 @@ class SubmitFoodActivity : BaseActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
private lateinit var appViewModel: DbViewModel
|
||||
|
||||
private fun initViewModel() {
|
||||
val db = BaseApp.instance!!.database
|
||||
val factory = AppFactory(DbRepository(db.appDao(), db.seasoningSlotDao()))
|
||||
appViewModel = ViewModelProvider(this, factory)[DbViewModel::class.java]
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
WeightUtil.removeWeightListener(TAG)
|
||||
|
||||
@@ -54,22 +54,12 @@ class DeviceConfigFragment : BaseFragment<FragmentDeviceConfigBinding>() {
|
||||
}
|
||||
|
||||
override fun initialize() {
|
||||
initViewModel()
|
||||
initUI()
|
||||
// addWeighListener()
|
||||
// addGridItemListener()
|
||||
// loadSeasoning()
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化ViewModel
|
||||
*/
|
||||
private fun initViewModel() {
|
||||
// val db = BaseApp.instance!!.database
|
||||
// val factory = AppFactory(DbRepository(db.appDao()))
|
||||
// appViewModel = ViewModelProvider(this, factory)[DbViewModel::class.java]
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化UI
|
||||
*/
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
//package com.shuwei.dish.match.viewmodel
|
||||
//
|
||||
//import androidx.lifecycle.ViewModel
|
||||
//import androidx.lifecycle.viewModelScope
|
||||
//import com.shuwei.dish.match.db.CookFoodGoodsRepository
|
||||
//import com.shuwei.dish.match.entity.CookFoodGoodsEntity
|
||||
//import kotlinx.coroutines.launch
|
||||
//
|
||||
//class CookFoodGoodsViewModel(private val rep: CookFoodGoodsRepository) : ViewModel() {
|
||||
//
|
||||
// fun getCookFoodGoodsList(
|
||||
// foodId: String,
|
||||
// action: (list: MutableList<CookFoodGoodsEntity>) -> Unit
|
||||
// ) {
|
||||
// viewModelScope.launch {
|
||||
// val list = rep.cookFoodGoodsDao.getCookFoodGoodsList(foodId)
|
||||
// action(list)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// fun saveCookFoodGoods(list: MutableList<CookFoodGoodsEntity>) {
|
||||
// viewModelScope.launch {
|
||||
// val foodId = list[0].foodId
|
||||
// val data: MutableList<CookFoodGoodsEntity>? =
|
||||
// rep.cookFoodGoodsDao.getCookFoodGoodsList(foodId!!)
|
||||
// if (data.isNullOrEmpty()) {
|
||||
// rep.cookFoodGoodsDao.insertAll(list)
|
||||
// return@launch
|
||||
// }
|
||||
// val localDbSeasoningList = rep.cookFoodGoodsDao.getCookFoodGoodsListByType(foodId, 3)
|
||||
// localDbSeasoningList.forEach {
|
||||
// it.isDel = 1
|
||||
// //更新本地调料数据为已删除的状态
|
||||
// rep.cookFoodGoodsDao.update(it)
|
||||
// }
|
||||
// //筛选出调料数据保存,主辅材不会变更不需要再次处理
|
||||
// val saveSeasoningList = list.filter { it.materialType == 3 }
|
||||
// rep.cookFoodGoodsDao.insertAll(saveSeasoningList.toMutableList())
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//}
|
||||
@@ -1,44 +0,0 @@
|
||||
//package com.shuwei.dish.match.viewmodel
|
||||
//
|
||||
//import androidx.lifecycle.ViewModel
|
||||
//import androidx.lifecycle.viewModelScope
|
||||
//import com.shuwei.dish.match.db.CookFoodRepository
|
||||
//import com.shuwei.dish.match.entity.CookFoodEntity
|
||||
//import kotlinx.coroutines.launch
|
||||
//
|
||||
//class CookFoodViewModel(private val rep: CookFoodRepository) : ViewModel() {
|
||||
//
|
||||
// fun getCookFoodById(foodId: String, cookMode: Int, action: (CookFoodEntity?) -> Unit) {
|
||||
// viewModelScope.launch {
|
||||
// val data = rep.cookFoodDao.getCookFoodById(foodId, cookMode)
|
||||
// action(data)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// fun getCookFoodList(cookMode: Int, action: (MutableList<CookFoodEntity>?) -> Unit) {
|
||||
// viewModelScope.launch {
|
||||
// val data = rep.cookFoodDao.getCookFoodList(cookMode)
|
||||
// action(data)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// fun countCookFood(cookMode: Int, action: (Int) -> Unit) {
|
||||
// viewModelScope.launch {
|
||||
// val count = rep.cookFoodDao.countCookFood(cookMode)
|
||||
// action(count)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// fun saveCookFood(cookMode: Int, entity: CookFoodEntity) {
|
||||
// viewModelScope.launch {
|
||||
// val data = rep.cookFoodDao.getCookFoodById(entity.foodId, cookMode)
|
||||
// if (data == null) {
|
||||
// rep.cookFoodDao.insert(entity)
|
||||
// return@launch
|
||||
// }
|
||||
// rep.cookFoodDao.update(entity)
|
||||
//
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//}
|
||||
@@ -1,47 +0,0 @@
|
||||
//package com.shuwei.dish.match.viewmodel
|
||||
//
|
||||
//import androidx.lifecycle.ViewModel
|
||||
//import androidx.lifecycle.viewModelScope
|
||||
//import com.shuwei.dish.match.db.SeasoningRepository
|
||||
//import com.shuwei.dish.match.entity.SeasoningEntity
|
||||
//import kotlinx.coroutines.delay
|
||||
//import kotlinx.coroutines.launch
|
||||
//
|
||||
//class DeviceSettingViewModel(private val rep: SeasoningRepository) : ViewModel() {
|
||||
// fun addSeasoning(list: MutableList<SeasoningEntity>, callback:()-> Unit) {
|
||||
// viewModelScope.launch {
|
||||
// rep.seasoningDao.deleteBatch()
|
||||
// delay(500)
|
||||
// val rows: Array<Long>? = rep.seasoningDao.insertAll(items = list)
|
||||
// if (rows.isNullOrEmpty().not()) {
|
||||
// callback()
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private var isProcessing = false
|
||||
// fun loadSeasoning(action: (list: MutableList<SeasoningEntity>) -> Unit) {
|
||||
// viewModelScope.launch {
|
||||
// if (isProcessing) return@launch
|
||||
// isProcessing = true
|
||||
// rep.seasoningDao.getAllStream().collect { list ->
|
||||
// action(list)
|
||||
// isProcessing = false
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// fun deleteAll() {
|
||||
// viewModelScope.launch {
|
||||
// rep.seasoningDao.deleteBatch()
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// fun updateAll(list: MutableList<SeasoningEntity>) {
|
||||
// viewModelScope.launch {
|
||||
// list.forEach {
|
||||
// rep.seasoningDao.update(it)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
@@ -1,24 +0,0 @@
|
||||
//package com.shuwei.dish.match.viewmodel
|
||||
//
|
||||
//import androidx.lifecycle.ViewModel
|
||||
//import androidx.lifecycle.viewModelScope
|
||||
//import com.shuwei.dish.match.db.SeasoningRepository
|
||||
//import com.shuwei.dish.match.entity.CookFoodEntity
|
||||
//import com.shuwei.dish.match.entity.SeasoningEntity
|
||||
//import kotlinx.coroutines.launch
|
||||
//
|
||||
//class SubmitDishViewModel(private val rep: SeasoningRepository) : ViewModel() {
|
||||
//
|
||||
// private var isProcessing = false
|
||||
// fun loadSeasoning(action: (list: MutableList<SeasoningEntity>) -> Unit) {
|
||||
// viewModelScope.launch {
|
||||
// if (isProcessing) return@launch
|
||||
// isProcessing = true
|
||||
// rep.seasoningDao.getAllStream().collect { list ->
|
||||
// action(list)
|
||||
// isProcessing = false
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//}
|
||||
@@ -1,44 +0,0 @@
|
||||
package com.shuwei.dish.match.viewmodel.factory
|
||||
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import com.shuwei.dish.match.db.DbRepository
|
||||
import com.shuwei.dish.match.db.dao.SeasoningSlotDao
|
||||
import com.shuwei.dish.match.viewmodel.DbViewModel
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
class AppFactory(private val repo: DbRepository) : ViewModelProvider.Factory {
|
||||
override fun <T : ViewModel> create(modelClass: Class<T>): T {
|
||||
return DbViewModel(repo) as T
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
//@Suppress("UNCHECKED_CAST")
|
||||
//class DeviceSettingFactory(private val repo: SeasoningRepository) : ViewModelProvider.Factory {
|
||||
// override fun <T : ViewModel> create(modelClass: Class<T>): T {
|
||||
// return DeviceSettingViewModel(repo) as T
|
||||
// }
|
||||
//}
|
||||
//
|
||||
////@Suppress("UNCHECKED_CAST")
|
||||
////class SubmitDishFactory(private val repo: SeasoningRepository) : ViewModelProvider.Factory {
|
||||
//// override fun <T : ViewModel> create(modelClass: Class<T>): T {
|
||||
//// return SubmitDishViewModel(repo) as T
|
||||
//// }
|
||||
////}
|
||||
//
|
||||
//@Suppress("UNCHECKED_CAST")
|
||||
//class CookFoodFactory(private val repo: CookFoodRepository) : ViewModelProvider.Factory {
|
||||
// override fun <T : ViewModel> create(modelClass: Class<T>): T {
|
||||
// return CookFoodViewModel(repo) as T
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//@Suppress("UNCHECKED_CAST")
|
||||
//class CookFoodGoodsFactory(private val repo: CookFoodGoodsRepository) : ViewModelProvider.Factory {
|
||||
// override fun <T : ViewModel> create(modelClass: Class<T>): T {
|
||||
// return CookFoodGoodsViewModel(repo) as T
|
||||
// }
|
||||
//}
|
||||
|
||||
Reference in New Issue
Block a user