From efc352c08f942628f5be107ee1d44d018f0afcec Mon Sep 17 00:00:00 2001 From: machiav3lli Date: Mon, 11 Apr 2022 00:19:28 +0200 Subject: [PATCH] Update: Abstract redraw page of Explore --- .../droidify/ui/fragments/ExploreFragment.kt | 49 ++++++++++--------- 1 file changed, 27 insertions(+), 22 deletions(-) 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 ee6ed117..f6f55883 100644 --- a/src/main/kotlin/com/looker/droidify/ui/fragments/ExploreFragment.kt +++ b/src/main/kotlin/com/looker/droidify/ui/fragments/ExploreFragment.kt @@ -12,6 +12,7 @@ import com.google.android.material.chip.Chip import com.looker.droidify.R import com.looker.droidify.content.Preferences import com.looker.droidify.database.entity.Category +import com.looker.droidify.database.entity.Product import com.looker.droidify.database.entity.Repository import com.looker.droidify.databinding.FragmentExploreXBinding import com.looker.droidify.entity.Section @@ -48,28 +49,7 @@ class ExploreFragment : MainNavFragmentX() { repositories = it.associateBy { repo -> repo.id } } viewModel.primaryProducts.observe(viewLifecycleOwner) { - binding.primaryComposeRecycler.setContent { - AppTheme( - darkTheme = when (Preferences[Preferences.Key.Theme]) { - is Preferences.Theme.System -> isSystemInDarkTheme() - is Preferences.Theme.AmoledSystem -> isSystemInDarkTheme() - else -> isDarkTheme - } - ) { - Scaffold { _ -> - ProductsVerticalRecycler(it, repositories, - onUserClick = { item -> - AppSheetX(item.packageName) - .showNow(parentFragmentManager, "Product ${item.packageName}") - }, - onFavouriteClick = {}, - onInstallClick = { - mainActivityX.syncConnection.binder?.installApps(listOf(it)) - } - ) - } - } - } + redrawPage(it) } viewModel.categories.observe(viewLifecycleOwner) { binding.categories.apply { @@ -122,4 +102,29 @@ class ExploreFragment : MainNavFragmentX() { } } } + + private fun redrawPage(products: List?, categories: List = emptyList()) { + binding.primaryComposeRecycler.setContent { + AppTheme( + darkTheme = when (Preferences[Preferences.Key.Theme]) { + is Preferences.Theme.System -> isSystemInDarkTheme() + is Preferences.Theme.AmoledSystem -> isSystemInDarkTheme() + else -> isDarkTheme + } + ) { + Scaffold { _ -> + ProductsVerticalRecycler(products, repositories, + onUserClick = { item -> + AppSheetX(item.packageName) + .showNow(parentFragmentManager, "Product ${item.packageName}") + }, + onFavouriteClick = {}, + onInstallClick = { + mainActivityX.syncConnection.binder?.installApps(listOf(it)) + } + ) + } + } + } + } }