|
@@ -32,7 +32,10 @@ import com.develop.main.R
|
|
|
import com.develop.main.databinding.ItemFilterAndSortViewBinding
|
|
|
import com.develop.main.viewmodel.HomeViewModel
|
|
|
import com.drake.brv.BindingAdapter
|
|
|
+import com.drake.brv.listener.OnMultiStateListener
|
|
|
import com.drake.brv.utils.*
|
|
|
+import com.scwang.smart.refresh.layout.api.RefreshLayout
|
|
|
+import com.scwang.smart.refresh.layout.listener.OnMultiListener
|
|
|
import org.greenrobot.eventbus.EventBus
|
|
|
import org.greenrobot.eventbus.Subscribe
|
|
|
|
|
@@ -49,7 +52,7 @@ class RecipesFragment : CommonBVMFragment<FragmentCommeListBinding, HomeViewMode
|
|
|
private var currentHotWord = ""
|
|
|
private var categoryCode: String = ""
|
|
|
|
|
|
- private val loadingDialog by lazy {
|
|
|
+ private val loadingDialog by lazy {
|
|
|
LoadingDialog()
|
|
|
}
|
|
|
private var isRefresh = false
|
|
@@ -129,7 +132,6 @@ class RecipesFragment : CommonBVMFragment<FragmentCommeListBinding, HomeViewMode
|
|
|
|
|
|
binding.rv.apply {
|
|
|
setHasFixedSize(true)
|
|
|
- isNestedScrollingEnabled = false
|
|
|
linear()
|
|
|
setup {
|
|
|
addType<String>(HOME_TITLE_PROVIDER)
|
|
@@ -142,23 +144,27 @@ class RecipesFragment : CommonBVMFragment<FragmentCommeListBinding, HomeViewMode
|
|
|
onBind {
|
|
|
when (itemViewType) {
|
|
|
HOME_TITLE_PROVIDER -> {
|
|
|
- findView<AppCompatTextView>(R.id.tv_food_category_name).updateText(
|
|
|
- getModel()
|
|
|
- )
|
|
|
+ if (!viewModel.isSearch) {
|
|
|
+ findView<AppCompatTextView>(R.id.tv_food_category_name).updateText(
|
|
|
+ getModel()
|
|
|
+ )
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
HOME_FOOD_LIST_PROVIDER -> {
|
|
|
val foodListModel = getModel<FoodListModel>()
|
|
|
|
|
|
- if(foodRecycle == null){
|
|
|
- foodRecycle = findView<RecyclerView>(R.id.food_recycle)
|
|
|
- foodRecycle!!.grid(4)
|
|
|
- foodRecycle!!.setup {
|
|
|
- addType<FoodContentModel>(com.develop.common.R.layout.food_content_provider)
|
|
|
- onBind {
|
|
|
- findView<FoodContentView>(com.develop.common.R.id.food_content_view).setFoodContent(
|
|
|
- getModel()
|
|
|
- )
|
|
|
- } }
|
|
|
+ if (foodRecycle == null) {
|
|
|
+ foodRecycle = findView<RecyclerView>(R.id.food_recycle)
|
|
|
+ foodRecycle!!.grid(4)
|
|
|
+ foodRecycle!!.setup {
|
|
|
+ addType<FoodContentModel>(com.develop.common.R.layout.food_content_provider)
|
|
|
+ onBind {
|
|
|
+ findView<FoodContentView>(com.develop.common.R.id.food_content_view).setFoodContent(
|
|
|
+ getModel()
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
@@ -166,6 +172,7 @@ class RecipesFragment : CommonBVMFragment<FragmentCommeListBinding, HomeViewMode
|
|
|
|
|
|
|
|
|
}
|
|
|
+
|
|
|
HOME_FUNCTION_PROVIDER -> {
|
|
|
filterSortSearchView =
|
|
|
findView<HomeFilterSortSearchView>(R.id.function_view)
|
|
@@ -177,12 +184,14 @@ class RecipesFragment : CommonBVMFragment<FragmentCommeListBinding, HomeViewMode
|
|
|
onFunctionCallback = functionCallback
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
HOME_SEARCH_PROVIDER -> {
|
|
|
findView<CommonSearchLayout>(R.id.common_search_view).apply {
|
|
|
updateData(getModel())
|
|
|
onHotWordsSelectedListener = hotWordsSelectedCallback
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
HOME_CATEGORY_PROVIDER -> {
|
|
|
findView<CategoryTabViewLayout>(R.id.category_tab_view).apply {
|
|
|
val model = getModel<CategoryModel>()
|
|
@@ -253,7 +262,7 @@ class RecipesFragment : CommonBVMFragment<FragmentCommeListBinding, HomeViewMode
|
|
|
|
|
|
override fun onInputSearch(searchContent: String) {
|
|
|
currentHotWord = searchContent
|
|
|
- loadingDialog.showDialog(childFragmentManager,"loadingDialog")
|
|
|
+ loadingDialog.showDialog(childFragmentManager, "loadingDialog")
|
|
|
if (viewModel.recipesType == RecipesType.ONLINE) {
|
|
|
viewModel.getOnLineRecipeList("", currentHotWord)
|
|
|
} else {
|
|
@@ -274,7 +283,7 @@ class RecipesFragment : CommonBVMFragment<FragmentCommeListBinding, HomeViewMode
|
|
|
|
|
|
override fun onOnlineRecipesClick() {
|
|
|
viewModel.apply {
|
|
|
- loadingDialog.showDialog(childFragmentManager,"loadingDialog")
|
|
|
+ loadingDialog.showDialog(childFragmentManager, "loadingDialog")
|
|
|
getOnLineCategoryList()
|
|
|
recipesType = RecipesType.ONLINE
|
|
|
netFoodLiveData.postValue(true)
|
|
@@ -288,7 +297,7 @@ class RecipesFragment : CommonBVMFragment<FragmentCommeListBinding, HomeViewMode
|
|
|
private var hotWordsSelectedCallback = object : CommonSearchLayout.OnHotWordsSelectedListener {
|
|
|
override fun onHotWordsSelected(hotWord: String) {
|
|
|
currentHotWord = hotWord
|
|
|
- loadingDialog.showDialog(childFragmentManager,"loadingDialog")
|
|
|
+ loadingDialog.showDialog(childFragmentManager, "loadingDialog")
|
|
|
if (viewModel.recipesType == RecipesType.ONLINE) {
|
|
|
viewModel.getOnLineRecipeList("", currentHotWord)
|
|
|
} else {
|
|
@@ -304,7 +313,7 @@ class RecipesFragment : CommonBVMFragment<FragmentCommeListBinding, HomeViewMode
|
|
|
private var categoryTabSelectedCallback =
|
|
|
object : CategoryTabViewLayout.OnCategoryTabSelectedListener {
|
|
|
override fun onCurrentSelected(categoryType: CategoryType) {
|
|
|
- loadingDialog.showDialog(childFragmentManager,"loadingDialog")
|
|
|
+ loadingDialog.showDialog(childFragmentManager, "loadingDialog")
|
|
|
if (viewModel.recipesType == RecipesType.ONLINE) {
|
|
|
viewModel.getOnLineRecipeList("", currentHotWord)
|
|
|
} else {
|
|
@@ -389,9 +398,12 @@ class RecipesFragment : CommonBVMFragment<FragmentCommeListBinding, HomeViewMode
|
|
|
|
|
|
//获取对应分类菜谱回调
|
|
|
localRecipesLiveData.observe(viewLifecycleOwner) {
|
|
|
- loadingDialog.removeSelf()
|
|
|
binding.page.apply {
|
|
|
- finishLoadMore(true)
|
|
|
+ if (isRefresh){
|
|
|
+ finishRefresh()
|
|
|
+ } else {
|
|
|
+ finishLoadMore(true)
|
|
|
+ }
|
|
|
}
|
|
|
binding.rv.apply {
|
|
|
models = it
|
|
@@ -399,13 +411,17 @@ class RecipesFragment : CommonBVMFragment<FragmentCommeListBinding, HomeViewMode
|
|
|
scrollToPosition(0)
|
|
|
}
|
|
|
}
|
|
|
+ loadingDialog.removeSelf()
|
|
|
}
|
|
|
|
|
|
//获取线上菜谱列表回调
|
|
|
onLineRecipesLiveData.observe(viewLifecycleOwner) {
|
|
|
- loadingDialog.removeSelf()
|
|
|
binding.page.apply {
|
|
|
- finishLoadMore(true)
|
|
|
+ if (isRefresh){
|
|
|
+ finishRefresh()
|
|
|
+ } else {
|
|
|
+ finishLoadMore(true)
|
|
|
+ }
|
|
|
}
|
|
|
binding.rv.apply {
|
|
|
models = it
|
|
@@ -413,6 +429,7 @@ class RecipesFragment : CommonBVMFragment<FragmentCommeListBinding, HomeViewMode
|
|
|
scrollToPosition(0)
|
|
|
}
|
|
|
}
|
|
|
+ loadingDialog.removeSelf()
|
|
|
}
|
|
|
|
|
|
//获取线上分类回调
|
|
@@ -436,11 +453,15 @@ class RecipesFragment : CommonBVMFragment<FragmentCommeListBinding, HomeViewMode
|
|
|
|
|
|
//搜索回调
|
|
|
hotWordSearchRecipesLiveData.observe(viewLifecycleOwner) {
|
|
|
- loadingDialog.removeSelf()
|
|
|
binding.page.apply {
|
|
|
- finishLoadMore(0)
|
|
|
+ if (isRefresh){
|
|
|
+ finishRefresh()
|
|
|
+ } else {
|
|
|
+ finishLoadMore(true)
|
|
|
+ }
|
|
|
}
|
|
|
binding.rv.models = it
|
|
|
+ loadingDialog.removeSelf()
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -448,7 +469,7 @@ class RecipesFragment : CommonBVMFragment<FragmentCommeListBinding, HomeViewMode
|
|
|
|
|
|
/**更新分类名称并获取对应数据*/
|
|
|
private fun updateCategoryName(devRecipeCategory: DevRecipeCategory) {
|
|
|
- loadingDialog.showDialog(childFragmentManager,"loadingDialog")
|
|
|
+ loadingDialog.showDialog(childFragmentManager, "loadingDialog")
|
|
|
viewModel.currCategoryName = devRecipeCategory.name ?: ""
|
|
|
filterSortSearchView?.updateFilterName(
|
|
|
viewModel.currCategoryName
|
|
@@ -466,23 +487,27 @@ class RecipesFragment : CommonBVMFragment<FragmentCommeListBinding, HomeViewMode
|
|
|
|
|
|
/**更新分类排序并获取对应数据*/
|
|
|
private fun updateSortName(pos: Int, needRefresh: Boolean = true) {
|
|
|
- loadingDialog.showDialog(childFragmentManager,"loadingDialog")
|
|
|
+ loadingDialog.showDialog(childFragmentManager, "loadingDialog")
|
|
|
filterSortSearchView?.updateSortName(
|
|
|
sortDataList[pos].name
|
|
|
)
|
|
|
viewModel.sortedType = when (pos) {
|
|
|
- 3 -> {
|
|
|
+ 1 -> {
|
|
|
SortedType.Popular
|
|
|
}
|
|
|
- 1 -> {
|
|
|
+
|
|
|
+ 2 -> {
|
|
|
SortedType.Newest
|
|
|
}
|
|
|
- 2 -> {
|
|
|
+
|
|
|
+ 3 -> {
|
|
|
SortedType.Score
|
|
|
}
|
|
|
+
|
|
|
0 -> {
|
|
|
SortedType.A2Z
|
|
|
}
|
|
|
+
|
|
|
else -> {
|
|
|
SortedType.A2Z
|
|
|
}
|