123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810 |
- package com.develop.step.viewmodel
- import androidx.lifecycle.LiveData
- import androidx.lifecycle.MutableLiveData
- import androidx.lifecycle.scopeNetLife
- import com.blankj.utilcode.util.FileUtils
- import com.blankj.utilcode.util.GsonUtils
- import com.blankj.utilcode.util.ToastUtils
- import com.blankj.utilcode.util.ZipUtils
- import com.develop.base.ext.getNewTuya
- import com.develop.base.ext.getSN
- import com.develop.base.ext.globalApp
- import com.develop.base.mvvm.BaseViewModel
- import com.develop.base.util.FileKit
- import com.develop.base.util.MMkvUtils
- import com.develop.base.util.ThreadUtils
- import com.develop.common.data_repo.FoodDataProvider
- import com.develop.common.data_repo.db.entity.DevAccessory
- import com.develop.common.data_repo.db.entity.DevRecipe
- import com.develop.common.data_repo.db.entity.DevRecipeCategory
- import com.develop.common.data_repo.db.entity.DevRecipeCookingStep
- import com.develop.common.data_repo.db.entity.DevRecipeFood
- import com.develop.common.data_repo.db.entity.DevRecipeNutrition
- import com.develop.common.data_repo.db.entity.DevRecipePortionSize
- import com.develop.common.data_repo.db.entity.UserOnLineRecipes
- import com.develop.common.data_repo.net.Api
- import com.develop.common.data_repo.net.model.response.RecipeDataConfig
- import com.develop.common.data_repo.net.model.response.RecipeDetailResult
- import com.develop.common.tag.CURRENT_LANGUAGE
- import com.develop.common.tag.CURRENT_USER_ID
- import com.develop.common.tuya_bean.RecipesBean
- import com.develop.common.utils.CommonUtils
- import com.develop.common.utils.Resource
- import com.develop.step.TuyaCookStepType
- import com.develop.step.ui.recipes_detail.model.CookDetailInfo
- import com.drake.net.Get
- import com.drake.net.component.Progress
- import com.drake.net.interfaces.ProgressListener
- import com.google.gson.Gson
- import java.io.File
- class CookDetailViewModel : BaseViewModel() {
- var sn = getSN()
- var recipeLiveData = MutableLiveData<CookDetailInfo>()
- private val errorLiveData = MutableLiveData<Int>()
- val starCountLiveData = MutableLiveData<Int>()
- val downloadResource = MutableLiveData<Resource<Int>>()
- var portionSizeLiveData = MutableLiveData<DevRecipePortionSize>()
- var addLikeLiveData = MutableLiveData<Boolean>()
- var deleteLikeLiveData = MutableLiveData<Boolean>()
- var onfialLiveData = MutableLiveData<String>()
- var likeTypeLiveData = MutableLiveData<Boolean>()
- var stepLiveDataString = MutableLiveData<String>()
- var recipeNumber: String? = null
- private var mRecipeUrl: String? = null
- var tuyaRecipe = ""
- //是否线上菜谱
- var isRemote = false
- var isTuyaStep = false
- /**
- * 数据源: 食谱编号
- * 关联数据: [DevRecipe] 食谱基本数据
- * [DevRecipeAccessory] 食谱需要的配件
- * [DevAccessory] 单个配件数据
- * [DevRecipeFood] 食谱原料数据
- * [DevRecipeNutrition] 食谱营养数据
- * [DevRecipePortionSize] 食谱原料用量
- */
- fun queryRecipe(number: String, remote: Boolean, recipesEdition: String) {
- if (getNewTuya()) {
- var lang = MMkvUtils.getString(CURRENT_LANGUAGE) ?: "en"
- var map = HashMap<String, Any>()
- map["lang"] = lang
- map["menuId"] = number
- var gson = Gson()
- var json = gson.toJson(map)
- CommonUtils.getTuyaBean<RecipesBean>("tuya.device.menu.get", "1.0",
- json, RecipesBean::class.java, object : CommonUtils.TuyaHttp<RecipesBean> {
- override fun bean(t: RecipesBean) {
- //处理涂鸦步骤
- isTuyaStep = true
- //通知收藏结果
- likeTypeLiveData.postValue(t.isStar)
- var devRecipeCookingStep = mutableListOf<DevRecipeCookingStep>()
- //步骤
- devRecipeCookingStep.addAll(getListStep(t.cookStepInfoVOList, number, lang))
- //食谱
- val detailInfo = getTuyaRecipes(t, number, lang)
- tuyaRecipe = GsonUtils.toJson(detailInfo.recipe)
- stepLiveDataString.postValue(GsonUtils.toJson(devRecipeCookingStep))
- portionSizeLiveData.postValue(detailInfo.portionSize.firstOrNull())
- recipeLiveData.postValue(detailInfo)
- }
- override fun fail() {
- onfialLiveData.postValue("")
- }
- },0)
- } else {
- isRemote = remote
- this.recipeNumber = number
- if (remote) {
- scopeNetLife {
- Get<RecipeDetailResult>(Api.GET_RECIPES_DETAIL) {
- addQuery("recipeNumber", number)
- // addQuery("recipeEditon", recipesEdition)
- addQuery("lang", MMkvUtils.getString(CURRENT_LANGUAGE) ?: "EN")
- }.await().apply {
- mRecipeUrl = recipeUrl
- val detailInfo = CookDetailInfo(
- devRecipe,
- devAccessorys,
- devRecipeFoods,
- devRecipeNutritions,
- devRecipePortionSizes
- )
- portionSizeLiveData.postValue(detailInfo.portionSize.firstOrNull())
- recipeLiveData.postValue(detailInfo)
- }
- }.catch {
- ToastUtils.showShort(it.message)
- }
- if (FoodDataProvider.isResourceDownload(number)) {
- downloadResource.value = Resource(100, Resource.Status.SUCCESS)
- }
- } else {
- FoodDataProvider.getDatabase().runInTransaction {
- val recipeDao = FoodDataProvider.getDatabase().recipeDao()
- val recipeBean = recipeDao.queryRecipe(number)
- if (recipeBean == null) {
- // show toast
- errorLiveData.postValue(ERR_NO_RECIPE_MATCH)
- return@runInTransaction
- }
- val includeAccessory = mutableListOf<DevAccessory>()
- val accessoryIds = recipeDao.queryAccessoryIds(number)
- for (accessoryId in accessoryIds) {
- val accessory = recipeDao.queryAccessory(accessoryId.accessoryNumber ?: "")
- if (accessory != null) {
- includeAccessory.add(accessory)
- }
- }
- val includeMaterial = recipeDao.queryFood(number)
- val includeNutrition = recipeDao.queryNutrition(number)
- val includePortionSize = recipeDao.queryPortionSize(number)
- val detailInfo = CookDetailInfo(
- recipeBean,
- includeAccessory,
- includeMaterial,
- includeNutrition,
- includePortionSize
- )
- portionSizeLiveData.postValue(detailInfo.portionSize.firstOrNull())
- recipeLiveData.postValue(detailInfo)
- }
- }
- }
- }
- //涂鸦转换步骤
- fun getListStep(
- listStep: List<RecipesBean.CookStepInfoVOListBean>,
- number: String,
- langs: String
- ): MutableList<DevRecipeCookingStep> {
- var devStepList = mutableListOf<DevRecipeCookingStep>()
- listStep.forEach {
- //判断有没有 有cookArgs是模式 ,没有就是描述
- var code = it.menuId + it.id
- var wordMode = ""
- var makeMode = ""
- var direction = "0"
- var description = ""
- var autoStart = "manual"
- var minute = 0
- var second = 0
- var rotateSpeed = 0
- var temperature = 0
- var updateTime = 0L
- var createTime = 0L
- var lang = ""
- var audioFileCode = ""
- var audioFilePath = ""
- var photoVideoFileCode = ""
- var photoVideoFilePath = ""
- var numbers = ""
- if (it.cookArgs == null) {
- wordMode = "DESCRIPTION"
- } else {
- it.cookArgs.forEach { cookArgs ->
- when (cookArgs.dpCode) {
- TuyaCookStepType.DIRECTION_OTHER->{
- if (cookArgs.dpValue == "true") {
- direction = "0"
- } else {
- direction = "1"
- }
- }
- TuyaCookStepType.DIRECTION -> {
- if (cookArgs.dpValue == "true") {
- direction = "0"
- } else {
- direction = "1"
- }
- }
- TuyaCookStepType.GEAR_OTHER -> {
- rotateSpeed = cookArgs.dpValue.toInt()
- }
- TuyaCookStepType.GEAR -> {
- rotateSpeed = cookArgs.dpValue.toInt()
- }
- TuyaCookStepType.TEMPERATURE_OTHER -> {
- temperature = cookArgs.dpValue.toInt()
- }
- TuyaCookStepType.TEMPERATURE -> {
- temperature = cookArgs.dpValue.toInt()
- }
- TuyaCookStepType.TIME_OTHER -> {
- var time = cookArgs.dpValue.toInt()
- val minutes: Int = time / 60 // 计算分钟
- val seconds: Int = time % 60
- minute = minutes
- second = seconds
- }
- TuyaCookStepType.TIME -> {
- var time = cookArgs.dpValue.toInt()
- val minutes: Int = time / 60 // 计算分钟
- val seconds: Int = time % 60
- minute = minutes
- second = seconds
- }
- TuyaCookStepType.MODE -> {
- when (cookArgs.dpValue) {
- TuyaCookStepType.DP_DIY -> {
- wordMode = TuyaCookStepType.ADAPTED_COOKING
- }
- TuyaCookStepType.DP_KNEAD -> {
- wordMode = TuyaCookStepType.KNEAD_TOUGH
- }
- TuyaCookStepType.DP_STEAM -> {
- wordMode = TuyaCookStepType.STEAM
- }
- TuyaCookStepType.DP_BOIL_WATER -> {
- wordMode = TuyaCookStepType.BOIL_WATER
- }
- TuyaCookStepType.DP_SOUS_VIDE -> {
- wordMode = TuyaCookStepType.SOVS_VIDE
- }
- TuyaCookStepType.DP_FOOD_PROCESSOR -> {
- wordMode = TuyaCookStepType.FOOD_PROCESSOR
- }
- TuyaCookStepType.DP_RICE -> {
- wordMode = TuyaCookStepType.COOK_RICE
- }
- TuyaCookStepType.DP_CHOP -> {
- wordMode = TuyaCookStepType.CHOP
- }
- TuyaCookStepType.DP_PULSE -> {
- wordMode = TuyaCookStepType.TURBO
- }
- TuyaCookStepType.DP_SMOOTHIE -> {
- wordMode = TuyaCookStepType.SMOOTHIE
- }
- TuyaCookStepType.DP_AUTO_CLEAN -> {
- wordMode = TuyaCookStepType.AUTO_CLEAN
- }
- TuyaCookStepType.DP_WEIGHT -> {
- wordMode = TuyaCookStepType.WIGHT
- }
- TuyaCookStepType.DP_DICE -> {
- wordMode = TuyaCookStepType.DICING
- }
- TuyaCookStepType.DP_CITRUS_FRUITS -> {
- wordMode = TuyaCookStepType.CITRUS_JUICER
- }
- TuyaCookStepType.DP_PEELING -> {
- wordMode = TuyaCookStepType.POTATO_PEELER
- }
- TuyaCookStepType.DP_PREHEATING -> {
- wordMode = TuyaCookStepType.SPECIAL_DIY_MODE
- }
- TuyaCookStepType.DP_TNTERMITTENT_STIR -> {
- wordMode = TuyaCookStepType.BROWN
- }
- TuyaCookStepType.DP_WARNING -> {
- wordMode = TuyaCookStepType.WARNING
- }
- }
- }
- }
- }
- }
- numbers = it.step.toString()
- if (it.langInfos == null) {
- description = ""
- lang = langs
- } else {
- it.langInfos.forEach { langInfosBean ->
- //由于客户涂鸦步骤没有文字,会打空格,估这里去除空格做判断
- if (langInfosBean.desc.trim() == "") {
- description = ""
- } else {
- description = langInfosBean.desc
- }
- lang = langInfosBean.lang
- }
- }
- /**
- * val code: String,
- * val recipeNumber: String?,
- * val number: String?,
- * val workMode: String?,
- * val photoVideoFileCode: String?,
- * val photoVideoFilePath: String?,
- * val audioFileCode: String?,
- * val audioFilePath: String?,
- * val makeMode: String?,
- * val autoStart: String?,
- * val temperature: Int?,
- * val rotateDirection: String?,
- * val rotateSpeed: Int?,
- * val minute: Int?,
- * val second: Int?,
- * val description: String?,
- * val lang: String?,
- * val updateTime: Long?,
- * val createTime: Long?
- *
- * **/
- var dev = DevRecipeCookingStep(
- code.toString(),
- number,
- numbers,
- wordMode,
- photoVideoFileCode,
- photoVideoFilePath,
- audioFileCode,
- audioFilePath,
- makeMode,
- autoStart,
- temperature,
- direction,
- rotateSpeed,
- minute,
- second,
- description,
- lang,
- updateTime,
- createTime
- )
- devStepList.add(dev)
- }
- return devStepList
- }
- //涂鸦转换食谱
- fun getTuyaRecipes(t: RecipesBean, number: String, lang: String): CookDetailInfo {
- var cookTime = t.cookTime
- var makeHours = cookTime / 3600;
- var makeMinutes = (cookTime % 3600) / 60;
- var userNum = t.pv ?: 0
- var desc = ""
- //步骤描述,食谱详情的第二个按钮
- if (t.menuStepInfoVOList != null) {
- val descBuilder = StringBuilder()
- t.menuStepInfoVOList.forEach {
- it.langInfos.let { itlang ->
- itlang.forEach { langinfo ->
- descBuilder.append(langinfo.desc)
- descBuilder.append("\n")
- }
- }
- }
- desc = descBuilder.toString()
- }
- var devRecipe = DevRecipe(
- t.id.toString(),
- t.id.toString(),
- "1.0",
- lang,
- "",
- t.mainImg,
- 0,
- 0,
- makeHours,
- makeMinutes,
- 0,
- 0,
- number,
- t.easyLevelDesc,
- "",
- t.name,
- desc,
- 0.0,
- userNum.toLong(),
- t.gmtModified,
- t.gmtCreate,
- "",
- ""
- )
- val includeAccessory = mutableListOf<DevAccessory>()
- var devRecipeFoodList = mutableListOf<DevRecipeFood>()
- var devRecipeNutritionList = mutableListOf<DevRecipeNutrition>()
- val includePortionSize = mutableListOf<DevRecipePortionSize>()
- //不add进去,那边会报错,直接随便新增一个
- includePortionSize.add(
- DevRecipePortionSize(
- "321654897",
- "2212zxc",
- "1542sqsc",
- "11wwss",
- lang,
- 1,
- 1
- )
- )
- var i = 1
- if (t.foodInfoVOList != null) {
- t.foodInfoVOList.forEach {
- var amout = 0.0
- var unit = ""
- if (it.menuFoodRelationVO.amount == "0") {
- amout = it.menuFoodRelationVO.secAmount.toDouble()
- if (it.menuFoodRelationVO.secUnitDesc == null) {
- unit = "g"
- } else {
- unit = it.menuFoodRelationVO.secUnitDesc
- }
- } else {
- amout = it.menuFoodRelationVO.amount.toDouble()
- unit = "g"
- }
- devRecipeFoodList.add(
- DevRecipeFood(
- it.id.toString(),
- it.menuFoodRelationVO.foodId.toString(),
- amout,
- it.menuFoodRelationVO.menuId.toString(),
- lang,
- unit,
- it.name,
- "",
- it.gmtModified,
- it.gmtCreate
- )
- )
- it.foodNutritionVOList.forEach { food ->
- devRecipeNutritionList.add(
- DevRecipeNutrition(
- food.id.toString(),
- number,
- i.toString(),
- food.value.toDouble(),
- "g",
- "",
- lang,
- it.gmtModified,
- it.gmtCreate
- )
- )
- i++
- }
- }
- }
- //处理配件
- //先查询数据库的配件信息
- t.desc.let {
- var accessoryList = FoodDataProvider.getDatabase().recipeDao().queryAccessoryList(lang)
- var strs = it
- if (!strs.contains("#")){
- return@let
- }
- // 使用 \n 字符切割字符串
- val parts = strs.split("\n")
- parts.let {string->
- string.forEach { str ->
- val (number, name) = str.split("#")
- //赛选
- includeAccessory.add(
- DevAccessory(
- "$number#$name", number, lang, name,"$name#$number",
- "",0, 0
- )
- )
- }
- }
- }
- return CookDetailInfo(
- devRecipe,
- includeAccessory,
- devRecipeFoodList,
- devRecipeNutritionList,
- includePortionSize
- )
- }
- fun addLikeRecipes(number: String) {
- var map = HashMap<String, Any>()
- map["menuId"] = number
- var gson = Gson()
- var json = gson.toJson(map)
- CommonUtils.getTuyaLike("tuya.device.menu.star.add", "1.0",
- json, object : CommonUtils.TuyaBooleanHttp {
- override fun bean(t: Boolean) {
- addLikeLiveData.postValue(t)
- }
- override fun fail() {
- onfialLiveData.postValue("")
- }
- })
- }
- fun deleteLikeRecipes(number: String) {
- var map = HashMap<String, Any>()
- map["menuId"] = number
- var gson = Gson()
- var json = gson.toJson(map)
- CommonUtils.getTuyaLike("tuya.device.menu.star.delete", "1.0",
- json, object : CommonUtils.TuyaBooleanHttp {
- override fun bean(t: Boolean) {
- deleteLikeLiveData.postValue(t)
- }
- override fun fail() {
- onfialLiveData.postValue("")
- }
- })
- }
- //涂鸦配件图片
- fun tuyaAccessoryPhoto(number: String?) :Int{
- var photo = when(number){
- "1"->{
- com.develop.common.R.drawable.tuya_accessory_1
- }
- "2"->{
- com.develop.common.R.drawable.tuya_accessory_2
- }
- "3"->{
- com.develop.common.R.drawable.tuya_accessory_3
- }
- "4"->{
- com.develop.common.R.drawable.tuya_accessory_4
- }
- "5"->{
- com.develop.common.R.drawable.tuya_accessory_5
- }
- "6"->{
- com.develop.common.R.drawable.tuya_accessory_6
- }
- "7"->{
- com.develop.common.R.drawable.tuya_accessory_7
- }
- "8"->{
- com.develop.common.R.drawable.tuya_accessory_8
- }
- "9"->{
- com.develop.common.R.drawable.tuya_accessory_9
- }
- "10"->{
- com.develop.common.R.drawable.tuya_accessory_10
- }
- else->{
- com.develop.common.R.drawable.tuya_accessory_1
- }
- }
- return photo
- }
- fun getRecipeLiveData(): LiveData<CookDetailInfo> {
- return recipeLiveData
- }
- fun getErrorCodeLiveData(): LiveData<Int> {
- return errorLiveData
- }
- fun getStarCount(recipesId: String) {
- FoodDataProvider.getUserDatabase().runInTransaction {
- val userTag = FoodDataProvider.getUserDatabase().userInfoDao().queryUserTag(
- CURRENT_USER_ID, recipesId
- )
- userTag?.apply {
- starCountLiveData.postValue(starCount)
- }
- }
- }
- fun isDownloading(): Boolean {
- return downloadResource.value?.status == Resource.Status.LOADING
- }
- fun isDownloadSuccess(): Boolean {
- return downloadResource.value?.status == Resource.Status.SUCCESS
- }
- fun getDownloadState(): LiveData<Resource<Int>> {
- return downloadResource
- }
- fun downloadRecipe() {
- if (mRecipeUrl.isNullOrEmpty()) {
- downloadResource.value = Resource(0, Resource.Status.FAILURE)
- return
- }
- downloadResource.value = Resource(0, Resource.Status.LOADING)
- val downloadDir = globalApp().externalCacheDir.toString()
- val downloadName = System.nanoTime().toString()
- scopeNetLife {
- mRecipeUrl?.apply {
- val result = Get<File>(this) {
- setDownloadFileName(downloadName)
- setDownloadDir(downloadDir)
- addDownloadListener(object : ProgressListener() {
- override fun onProgress(p: Progress) {
- ThreadUtils.runOnMainThread {
- downloadResource.value =
- Resource(p.progress(), Resource.Status.LOADING)
- }
- }
- })
- }.await()
- if (!result.exists()) {
- ThreadUtils.runOnMainThread {
- downloadResource.value = Resource(0, Resource.Status.FAILURE)
- }
- } else {
- prepareResource(result)
- }
- }
- }.catch {
- ThreadUtils.runOnMainThread {
- downloadResource.value = Resource(0, Resource.Status.FAILURE)
- }
- }
- }
- private fun prepareResource(file: File) {
- try {
- val dst = ZipUtils.unzipFile(file, FoodDataProvider.getExtRecipeResourceDir())
- FileUtils.delete(file)
- if (dst.isNullOrEmpty()) {
- ThreadUtils.runOnMainThread {
- downloadResource.value = Resource(0, Resource.Status.FAILURE)
- }
- return
- }
- val jsonFile = FoodDataProvider.getResourceConfigJsonPath(recipeNumber!!)
- if (!jsonFile.exists()) {
- ThreadUtils.runOnMainThread {
- downloadResource.value = Resource(0, Resource.Status.FAILURE)
- }
- return
- }
- val jsonContent = FileKit.readFileToStringB(jsonFile)
- val contentData = GsonUtils.fromJson(jsonContent, RecipeDataConfig::class.java)
- // contentData.resetAllCodes()
- FoodDataProvider.getDatabase().runInTransaction {
- FoodDataProvider.getDatabase().recipeDao().apply {
- val categorys = queryAllCategory()
- val categoryMap = HashMap<String, DevRecipeCategory>()
- for (category in categorys) {
- categoryMap[category.number + ":" + category.lang] = category
- }
- for (devRecipeCategory in contentData.devRecipeCategorys) {
- if (categoryMap.containsKey(devRecipeCategory.number + ":" + devRecipeCategory.lang)) {
- devRecipeCategory.code =
- categoryMap[devRecipeCategory.number + ":" + devRecipeCategory.lang]?.code.toString()
- }
- }
- /**
- * 如果本地食谱存在的情况下
- * 下载在线食谱,需要删除本地食谱
- * **/
- contentData.devRecipes.forEach {
- var number = it.number ?: ""
- var lang = it.lang ?: "EN"
- deleteNumAndLangRecipe(number, lang)
- }
- //删除步骤 和其他一些
- recipeNumber?.let {
- deleteDevRecipeAccessorys(it)
- deleteDevRecipeCookingSteps(it)
- deleteDevRecipeFoods(it)
- deleteDevRecipeNutritions(it)
- deleteDevRecipeRelTags(it)
- deleteDevRecipePortionSizes(it)
- }
- // deleteRecipe(recipeNumber)
- insertDevAccessorys(contentData.devAccessorys)
- insertHotTags(contentData.devHotTags)
- insertDevPortraits(contentData.devPortraits)
- insertDevRecipeAccessorys(contentData.devRecipeAccessorys)
- insertDevRecipeCategorys(contentData.devRecipeCategorys)
- insertDevRecipeCookingSteps(contentData.devRecipeCookingSteps)
- insertDevRecipeFoods(contentData.devRecipeFoods)
- insertDevRecipeNutritions(contentData.devRecipeNutritions)
- insertDevRecipePortionSizes(contentData.devRecipePortionSizes)
- insertDevRecipeRelTags(contentData.devRecipeRelTags)
- insertDevRecipeTags(contentData.devRecipeTags)
- insertDevRecipes(contentData.devRecipes)
- }
- ThreadUtils.runOnMainThread {
- downloadResource.value = Resource(100, Resource.Status.SUCCESS)
- }
- }
- FoodDataProvider.getUserDatabase().runInTransaction {
- contentData.devRecipes.getOrNull(0)?.also {
- FoodDataProvider.getUserDatabase().userInfoDao().insertOnlineRecipe(
- UserOnLineRecipes(CURRENT_USER_ID, it.number ?: "")
- )
- }
- }
- } catch (e: Exception) {
- e.printStackTrace()
- ThreadUtils.runOnMainThread {
- downloadResource.value = Resource(0, Resource.Status.FAILURE)
- }
- }
- }
- companion object {
- const val ERR_NO_RECIPE_MATCH = -1
- }
- }
|