diff --git a/src/main/kotlin/com/looker/droidify/ui/fragments/ExploreFragment.kt b/src/main/kotlin/com/looker/droidify/ui/fragments/ExploreFragment.kt index 67d6f378..4f2bbe12 100644 --- a/src/main/kotlin/com/looker/droidify/ui/fragments/ExploreFragment.kt +++ b/src/main/kotlin/com/looker/droidify/ui/fragments/ExploreFragment.kt @@ -46,7 +46,15 @@ class ExploreFragment : MainNavFragmentX() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) + viewModel.db.repositoryDao.allFlowable + .observeOn(Schedulers.io()) + .flatMapSingle { list -> RxUtils.querySingle { list.mapNotNull { it.trueData } } } + .map { list -> list.asSequence().map { Pair(it.id, it) }.toMap() } + .observeOn(AndroidSchedulers.mainThread()) + .subscribe { repositories = it } + } + override fun setupAdapters() { appsItemAdapter = PagedModelAdapter(PRODUCT_ASYNC_DIFFER_CONFIG) { it.data_item?.let { item -> VAppItem(item, repositories[it.repository_id]) } } @@ -57,14 +65,9 @@ class ExploreFragment : MainNavFragmentX() { setHasFixedSize(true) adapter = appsFastAdapter } + } - viewModel.db.repositoryDao.allFlowable - .observeOn(Schedulers.io()) - .flatMapSingle { list -> RxUtils.querySingle { list.mapNotNull { it.trueData } } } - .map { list -> list.asSequence().map { Pair(it.id, it) }.toMap() } - .observeOn(AndroidSchedulers.mainThread()) - .subscribe { repositories = it } - + override fun setupLayout() { viewModel.productsList.observe(requireActivity()) { appsItemAdapter.submitList(it) } diff --git a/src/main/kotlin/com/looker/droidify/ui/fragments/InstalledFragment.kt b/src/main/kotlin/com/looker/droidify/ui/fragments/InstalledFragment.kt index 3bca294b..a6f6fbcd 100644 --- a/src/main/kotlin/com/looker/droidify/ui/fragments/InstalledFragment.kt +++ b/src/main/kotlin/com/looker/droidify/ui/fragments/InstalledFragment.kt @@ -50,7 +50,15 @@ class InstalledFragment : MainNavFragmentX() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) + viewModel.db.repositoryDao.allFlowable + .observeOn(Schedulers.io()) + .flatMapSingle { list -> RxUtils.querySingle { list.mapNotNull { it.trueData } } } + .map { list -> list.asSequence().map { Pair(it.id, it) }.toMap() } + .observeOn(AndroidSchedulers.mainThread()) + .subscribe { repositories = it } + } + override fun setupAdapters() { installedItemAdapter = PagedModelAdapter(PRODUCT_ASYNC_DIFFER_CONFIG) { it.data_item?.let { item -> VAppItem(item, repositories[it.repository_id]) } } @@ -70,15 +78,18 @@ class InstalledFragment : MainNavFragmentX() { layoutManager = LinearLayoutManager(requireContext(), RecyclerView.HORIZONTAL, false) adapter = updatedFastAdapter } + } - viewModel.db.repositoryDao.allFlowable - .observeOn(Schedulers.io()) - .flatMapSingle { list -> RxUtils.querySingle { list.mapNotNull { it.trueData } } } - .map { list -> list.asSequence().map { Pair(it.id, it) }.toMap() } - .observeOn(AndroidSchedulers.mainThread()) - .subscribe { repositories = it } + override fun setupLayout() { + binding.buttonUpdated.setOnClickListener { + binding.updatedRecycler.apply { + visibility = if (visibility == View.VISIBLE) View.GONE else View.VISIBLE + } + } viewModel.productsList.observe(requireActivity()) { + binding.updatedBar.visibility = + if (it.any { item -> item.data_item?.canUpdate == true }) View.VISIBLE else View.GONE updatedItemAdapter.submitList(it) installedItemAdapter.submitList(it) } diff --git a/src/main/kotlin/com/looker/droidify/ui/fragments/LatestFragment.kt b/src/main/kotlin/com/looker/droidify/ui/fragments/LatestFragment.kt index ead3304d..7ae7ef95 100644 --- a/src/main/kotlin/com/looker/droidify/ui/fragments/LatestFragment.kt +++ b/src/main/kotlin/com/looker/droidify/ui/fragments/LatestFragment.kt @@ -51,7 +51,15 @@ class LatestFragment : MainNavFragmentX() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) + viewModel.db.repositoryDao.allFlowable + .observeOn(Schedulers.io()) + .flatMapSingle { list -> RxUtils.querySingle { list.mapNotNull { it.trueData } } } + .map { list -> list.asSequence().map { Pair(it.id, it) }.toMap() } + .observeOn(AndroidSchedulers.mainThread()) + .subscribe { repositories = it } + } + override fun setupAdapters() { updatedItemAdapter = PagedModelAdapter(PRODUCT_ASYNC_DIFFER_CONFIG) { it.data_item?.let { item -> VAppItem(item, repositories[it.repository_id]) } } @@ -71,14 +79,9 @@ class LatestFragment : MainNavFragmentX() { layoutManager = LinearLayoutManager(requireContext(), RecyclerView.HORIZONTAL, false) adapter = newFastAdapter } + } - viewModel.db.repositoryDao.allFlowable - .observeOn(Schedulers.io()) - .flatMapSingle { list -> RxUtils.querySingle { list.mapNotNull { it.trueData } } } - .map { list -> list.asSequence().map { Pair(it.id, it) }.toMap() } - .observeOn(AndroidSchedulers.mainThread()) - .subscribe { repositories = it } - + override fun setupLayout() { viewModel.productsList.observe(requireActivity()) { newItemAdapter.submitList(it) updatedItemAdapter.submitList(it) diff --git a/src/main/kotlin/com/looker/droidify/ui/fragments/MainNavFragmentX.kt b/src/main/kotlin/com/looker/droidify/ui/fragments/MainNavFragmentX.kt index eb0e5349..d025bc99 100644 --- a/src/main/kotlin/com/looker/droidify/ui/fragments/MainNavFragmentX.kt +++ b/src/main/kotlin/com/looker/droidify/ui/fragments/MainNavFragmentX.kt @@ -1,5 +1,7 @@ package com.looker.droidify.ui.fragments +import android.os.Bundle +import android.view.View import androidx.fragment.app.Fragment import com.looker.droidify.R import com.looker.droidify.entity.ProductItem @@ -37,6 +39,15 @@ abstract class MainNavFragmentX : Fragment() { } } } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + setupAdapters() + setupLayout() + } + + abstract fun setupAdapters() + abstract fun setupLayout() } enum class Source(val sections: Boolean, val order: Boolean) {