|
@@ -1,7 +1,7 @@
|
|
|
package com.develop.main.ui
|
|
|
|
|
|
|
|
|
-import android.graphics.Rect
|
|
|
+import android.os.Bundle
|
|
|
import android.view.LayoutInflater
|
|
|
import android.view.View
|
|
|
import android.view.ViewGroup
|
|
@@ -9,19 +9,16 @@ import android.widget.RelativeLayout
|
|
|
import androidx.appcompat.widget.AppCompatTextView
|
|
|
import androidx.databinding.ViewDataBinding
|
|
|
import androidx.recyclerview.widget.RecyclerView
|
|
|
+import com.develop.base.ext.globalApp
|
|
|
import com.develop.base.ext.navigateTo
|
|
|
import com.develop.base.ext.resId2Dimension
|
|
|
import com.develop.base.ext.updateText
|
|
|
-import com.develop.base.util.GridSpaceItemDecoration
|
|
|
import com.develop.base.widgets.CommonPopupWindow
|
|
|
import com.develop.common.data_repo.db.*
|
|
|
import com.develop.common.data_repo.db.entity.DevRecipeCategory
|
|
|
import com.develop.common.databinding.FragmentCommeListBinding
|
|
|
import com.develop.common.router.Screens
|
|
|
-import com.develop.common.tag.IS_LIKE_TAG
|
|
|
-import com.develop.common.tag.NUMBER_TAG
|
|
|
-import com.develop.common.tag.RECIPES_EDITION_TAG
|
|
|
-import com.develop.common.tag.SOURCE_TAG
|
|
|
+import com.develop.common.tag.*
|
|
|
import com.develop.common.ui.CommonBVMFragment
|
|
|
import com.develop.common.widget.*
|
|
|
import com.develop.main.R
|
|
@@ -108,11 +105,7 @@ class RecipesFragment : CommonBVMFragment<FragmentCommeListBinding, HomeViewMode
|
|
|
|
|
|
override fun onResume() {
|
|
|
super.onResume()
|
|
|
- if (viewModel.recipesType == RecipesType.ONLINE) {
|
|
|
- viewModel.getOnLineCategoryList()
|
|
|
- } else {
|
|
|
- viewModel.queryRecipesCategory()
|
|
|
- }
|
|
|
+ refreshOnLineOrLocalRecipes()
|
|
|
}
|
|
|
|
|
|
private fun initView() {
|
|
@@ -137,9 +130,8 @@ class RecipesFragment : CommonBVMFragment<FragmentCommeListBinding, HomeViewMode
|
|
|
HOME_FOOD_LIST_PROVIDER -> {
|
|
|
val foodListModel = getModel<FoodListModel>()
|
|
|
val foodRecycle =
|
|
|
- findView<RecyclerView>(com.develop.common.R.id.food_recycle)
|
|
|
+ findView<RecyclerView>(R.id.food_recycle)
|
|
|
foodRecycle.apply {
|
|
|
- addItemDecoration(GridSpaceItemDecoration(4, 0, dp10))
|
|
|
grid(4)
|
|
|
setup {
|
|
|
addType<FoodContentModel>(com.develop.common.R.layout.food_content_provider)
|
|
@@ -154,14 +146,13 @@ class RecipesFragment : CommonBVMFragment<FragmentCommeListBinding, HomeViewMode
|
|
|
HOME_FUNCTION_PROVIDER -> {
|
|
|
filterSortSearchView =
|
|
|
findView<HomeFilterSortSearchView>(R.id.function_view)
|
|
|
- filterSortSearchView?.onFunctionCallback = functionCallback
|
|
|
- }
|
|
|
- HOME_BANNER_PROVIDER -> {
|
|
|
- val bannerAdapter =
|
|
|
- HomeBannerAdapter(getModel<HomeBannerListModel>().data)
|
|
|
- bannerAdapter.onBannerItemClickListener = bannerItemClickCallback
|
|
|
- findView<Banner<*, *>>(R.id.home_banner_view).adapter = bannerAdapter
|
|
|
-
|
|
|
+ filterSortSearchView?.apply {
|
|
|
+ if (!viewModel.isSearch) {
|
|
|
+ resetView()
|
|
|
+ }
|
|
|
+ hideOnlineLayout(getModel<FilterSortModel>().isOnLineState)
|
|
|
+ onFunctionCallback = functionCallback
|
|
|
+ }
|
|
|
}
|
|
|
HOME_SEARCH_PROVIDER -> {
|
|
|
findView<CommonSearchLayout>(R.id.common_search_view).apply {
|
|
@@ -185,12 +176,7 @@ class RecipesFragment : CommonBVMFragment<FragmentCommeListBinding, HomeViewMode
|
|
|
binding.page.apply {
|
|
|
setEnableRefresh(false)
|
|
|
onRefresh {
|
|
|
- if (viewModel.recipesType == RecipesType.ONLINE) {
|
|
|
- viewModel.netFoodLiveData.postValue(true)
|
|
|
- viewModel.getOnLineCategoryList()
|
|
|
- } else {
|
|
|
- viewModel.queryLocalRecipes(categoryCode)
|
|
|
- }
|
|
|
+ refreshOnLineOrLocalRecipes()
|
|
|
}
|
|
|
onLoadMore {
|
|
|
if (viewModel.recipesType == RecipesType.ONLINE) {
|
|
@@ -224,6 +210,10 @@ class RecipesFragment : CommonBVMFragment<FragmentCommeListBinding, HomeViewMode
|
|
|
}
|
|
|
|
|
|
override fun onSearchClick() {
|
|
|
+ viewModel.apply {
|
|
|
+ isSearch = true
|
|
|
+ homeOrBackLiveData.postValue(HomeOrBack.Back)
|
|
|
+ }
|
|
|
//进入搜索页
|
|
|
if (viewModel.recipesType == RecipesType.ONLINE) {
|
|
|
viewModel.getOnLineHotTags()
|
|
@@ -242,18 +232,23 @@ class RecipesFragment : CommonBVMFragment<FragmentCommeListBinding, HomeViewMode
|
|
|
}
|
|
|
|
|
|
override fun onDownloadClick() {
|
|
|
-
|
|
|
+ navigateTo(Screens.Cook.FOOD_LIST) {
|
|
|
+ val bundle = Bundle()
|
|
|
+ bundle.putString(
|
|
|
+ FOOL_LIST_TITLE, globalApp().getString(com.develop.common.R.string.download)
|
|
|
+ )
|
|
|
+ bundle.putInt(FOOD_LIST_TYPE, Downloaded)
|
|
|
+ with(bundle)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
override fun onOnlineRecipesClick() {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- override fun onBackClick() {
|
|
|
- if (viewModel.recipesType == RecipesType.ONLINE) {
|
|
|
- viewModel.getOnLineCategoryList()
|
|
|
- } else {
|
|
|
- viewModel.queryLocalRecipes(categoryCode)
|
|
|
+ viewModel.apply {
|
|
|
+ getOnLineCategoryList()
|
|
|
+ recipesType = RecipesType.ONLINE
|
|
|
+ netFoodLiveData.postValue(true)
|
|
|
+ postEmptyOnlineRecipes()
|
|
|
+ homeOrBackLiveData.postValue(HomeOrBack.Back)
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -267,9 +262,7 @@ class RecipesFragment : CommonBVMFragment<FragmentCommeListBinding, HomeViewMode
|
|
|
viewModel.getOnLineRecipeList("", currentHotWord)
|
|
|
} else {
|
|
|
viewModel.queryRecipesByHotWord(currentHotWord, CategoryType.All)
|
|
|
- filterSortSearchView?.updateHotWord(
|
|
|
- hotWord
|
|
|
- )
|
|
|
+ filterSortSearchView?.updateHotWord(hotWord)
|
|
|
}
|
|
|
|
|
|
}
|
|
@@ -290,19 +283,6 @@ class RecipesFragment : CommonBVMFragment<FragmentCommeListBinding, HomeViewMode
|
|
|
}
|
|
|
|
|
|
|
|
|
- /**banner点击回调 */
|
|
|
- private var bannerItemClickCallback = object : HomeBannerAdapter.OnBannerItemClickListener {
|
|
|
- override fun onNetRecipesClick(bannerModel: HomeBannerModel) {
|
|
|
- viewModel.apply {
|
|
|
- getOnLineCategoryList()
|
|
|
- recipesType = RecipesType.ONLINE
|
|
|
- netFoodLiveData.postValue(true)
|
|
|
- postEmptyOnlineRecipes()
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
/**绑定过滤或排序内容*/
|
|
|
private fun bindFilterSortView(
|
|
|
adapter: BindingAdapter,
|
|
@@ -341,9 +321,13 @@ class RecipesFragment : CommonBVMFragment<FragmentCommeListBinding, HomeViewMode
|
|
|
/**liveData回调*/
|
|
|
private fun initLiveDataCallback() {
|
|
|
viewModel.apply {
|
|
|
- //从网络菜谱切回本地菜谱,更新数据
|
|
|
+
|
|
|
refreshRecipesLiveData.observe(viewLifecycleOwner) {
|
|
|
- viewModel.queryRecipesCategory()
|
|
|
+ if (filterSortSearchView?.getOnlineLayoutVisible() != true) {
|
|
|
+ //从网络菜谱切回本地菜谱,更新数据
|
|
|
+ viewModel.recipesType = RecipesType.LOCAL
|
|
|
+ }
|
|
|
+ refreshOnLineOrLocalRecipes()
|
|
|
}
|
|
|
//获取本地菜谱分类回调
|
|
|
localCategoryLiveData.observe(viewLifecycleOwner) {
|
|
@@ -454,9 +438,20 @@ class RecipesFragment : CommonBVMFragment<FragmentCommeListBinding, HomeViewMode
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private fun refreshOnLineOrLocalRecipes() {
|
|
|
+ if (viewModel.recipesType == RecipesType.ONLINE) {
|
|
|
+ viewModel.apply {
|
|
|
+ postEmptyOnlineRecipes()
|
|
|
+ getOnLineCategoryList()
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ viewModel.queryRecipesCategory()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
companion object {
|
|
|
val HOME_TITLE_PROVIDER = R.layout.home_title_provider
|
|
|
- val HOME_FOOD_LIST_PROVIDER = com.develop.common.R.layout.food_grid_view
|
|
|
+ val HOME_FOOD_LIST_PROVIDER = R.layout.food_grid_view
|
|
|
val HOME_BANNER_PROVIDER = R.layout.home_banner_provider
|
|
|
val HOME_SEARCH_PROVIDER = R.layout.home_common_search_provider
|
|
|
val HOME_CATEGORY_PROVIDER = R.layout.home_category_tab_provider
|