|
@@ -4,10 +4,24 @@ package com.develop.food.base.data
|
|
|
import android.content.res.Resources
|
|
|
import com.develop.base.R
|
|
|
import com.develop.common.utils.ConfigUtils
|
|
|
-import com.develop.food.base.data.model.*
|
|
|
+import com.develop.food.base.data.model.CommonSearchItem
|
|
|
+import com.develop.food.base.data.model.CommonSearchModel
|
|
|
+import com.develop.food.base.data.model.FilterSortModel
|
|
|
+import com.develop.food.base.data.model.FoodContentModel
|
|
|
+import com.develop.food.base.data.model.HomeBannerListModel
|
|
|
+import com.develop.food.base.data.model.HomeBannerModel
|
|
|
+import com.develop.food.base.data.model.LanguageModel
|
|
|
+import com.develop.food.base.data.model.ModelsModel
|
|
|
+import com.develop.food.base.data.model.NewsModel
|
|
|
+import com.develop.food.base.data.model.SettingModel
|
|
|
import com.develop.food.base.repo.entity.DevRecipe
|
|
|
import com.develop.food.base.repo.entity.UserFavoriteRecipes
|
|
|
-import java.util.Collections
|
|
|
+import com.develop.food.base.utils.MmkvUtils
|
|
|
+import com.google.gson.Gson
|
|
|
+import com.google.gson.reflect.TypeToken
|
|
|
+import java.lang.reflect.Type
|
|
|
+import java.util.*
|
|
|
+import kotlin.Comparator
|
|
|
|
|
|
object DataFactory {
|
|
|
|
|
@@ -17,21 +31,18 @@ object DataFactory {
|
|
|
val languageList = mutableListOf<LanguageModel>()
|
|
|
// val strList = mutableListOf<String>(
|
|
|
// resource.getString(R.string.english),
|
|
|
-// resource.getString(R.string.pl),
|
|
|
//// resource.getString(R.string.chinese),
|
|
|
//// resource.getString(R.string.france),
|
|
|
//// resource.getString(R.string.japan)
|
|
|
// )
|
|
|
// val iconList = mutableListOf<Int>(
|
|
|
// R.drawable.ic_english,
|
|
|
-// R.drawable.ic_pl,
|
|
|
//// R.drawable.ic_chinese,
|
|
|
//// R.drawable.ic_france,
|
|
|
//// R.drawable.ic_japan
|
|
|
// )
|
|
|
// val typeList = mutableListOf<LanguageType>(
|
|
|
// LanguageType.English,
|
|
|
-// LanguageType.PL,
|
|
|
//// LanguageType.Chinese,
|
|
|
//// LanguageType.France,
|
|
|
//// LanguageType.Japan
|
|
@@ -48,7 +59,6 @@ object DataFactory {
|
|
|
return ConfigUtils.loadLangConfig()?.langs?.filter { it.show == true } ?: Collections.emptyList();
|
|
|
}
|
|
|
|
|
|
-
|
|
|
fun genNetRecipesData(
|
|
|
categoryName: String,
|
|
|
recipesList: MutableList<DevRecipe>,
|
|
@@ -322,13 +332,27 @@ object DataFactory {
|
|
|
fun genTestSearchDataList(): MutableList<Any> {
|
|
|
val result = mutableListOf<Any>()
|
|
|
result.add(FilterSortModel(""))
|
|
|
- val searchNameList =
|
|
|
- mutableListOf("Guacamole", "Aioli", "Popular", "Chinese food", "Healthy")
|
|
|
- val searchModelList = mutableListOf<CommonSearchItem>()
|
|
|
- searchNameList.forEach {
|
|
|
- searchModelList.add(CommonSearchItem(it))
|
|
|
+ var historyDataList: MutableList<CommonSearchItem> = mutableListOf()
|
|
|
+ val hotWordJson = MmkvUtils.getString("CommonWords") ?: ""
|
|
|
+ if (hotWordJson.isNotEmpty()) {
|
|
|
+ val type: Type = object : TypeToken<List<CommonSearchItem>>() {}.type
|
|
|
+ historyDataList = Gson().fromJson(hotWordJson, type)
|
|
|
}
|
|
|
- result.add(CommonSearchModel(searchModelList))
|
|
|
+ historyDataList.sortWith(Comparator { t, t2 ->
|
|
|
+ if (t.count > (t2.count ?: 0)) {
|
|
|
+ return@Comparator -1
|
|
|
+ } else if ((t.count ?: 0) == (t2.count ?: 0)) {
|
|
|
+ return@Comparator 0
|
|
|
+ } else {
|
|
|
+ return@Comparator 1
|
|
|
+ }
|
|
|
+ })
|
|
|
+ val searchModel = if (historyDataList.size > 12) {
|
|
|
+ CommonSearchModel(historyDataList.subList(0, 12))
|
|
|
+ } else {
|
|
|
+ CommonSearchModel(historyDataList)
|
|
|
+ }
|
|
|
+ result.add(searchModel)
|
|
|
return result
|
|
|
}
|
|
|
|
|
@@ -337,7 +361,7 @@ object DataFactory {
|
|
|
result.add(FilterSortModel(""))
|
|
|
val searchModelList = mutableListOf<CommonSearchItem>()
|
|
|
hotTags.forEach {
|
|
|
- searchModelList.add(CommonSearchItem(it))
|
|
|
+ searchModelList.add(CommonSearchItem(it,1))
|
|
|
}
|
|
|
result.add(CommonSearchModel(searchModelList))
|
|
|
return result
|
|
@@ -418,4 +442,16 @@ enum class SortedType {
|
|
|
Popular,
|
|
|
Newest,
|
|
|
Score
|
|
|
-}
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+fun getHistoryWords(): MutableList<String> {
|
|
|
+ var historyDataList: MutableList<String> = mutableListOf()
|
|
|
+ val hotWordJson = MmkvUtils.getString("HistoryWords") ?: ""
|
|
|
+ if (hotWordJson.isNotEmpty()) {
|
|
|
+ val type: Type = object : TypeToken<List<String>>() {}.type
|
|
|
+ historyDataList = Gson().fromJson(hotWordJson, type)
|
|
|
+ }
|
|
|
+ return historyDataList
|
|
|
+}
|