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 c8587e7b..8842130f 100644 --- a/src/main/kotlin/com/looker/droidify/ui/fragments/InstalledFragment.kt +++ b/src/main/kotlin/com/looker/droidify/ui/fragments/InstalledFragment.kt @@ -6,7 +6,9 @@ import android.view.View import android.view.ViewGroup import androidx.appcompat.widget.SearchView import androidx.compose.foundation.isSystemInDarkTheme -import androidx.compose.material.Scaffold +import androidx.compose.material.ExperimentalMaterialApi +import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.material3.Scaffold import com.google.android.material.composethemeadapter.MdcTheme import com.looker.droidify.R import com.looker.droidify.content.Preferences @@ -45,28 +47,7 @@ class InstalledFragment : MainNavFragmentX() { } viewModel.installed.observe(viewLifecycleOwner) {} 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.sortedBy(Product::label), repositories, - onUserClick = { item -> - AppSheetX(item.packageName) - .showNow(parentFragmentManager, "Product ${item.packageName}") - }, - onFavouriteClick = {}, - onInstallClick = { - mainActivityX.syncConnection.binder?.installApps(listOf(it)) - } - ) - } - } - } + redrawPage(it) } viewModel.secondaryProducts.observe(viewLifecycleOwner) { binding.updatedBar.visibility = if (it.isNotEmpty()) View.VISIBLE else View.GONE @@ -129,4 +110,30 @@ class InstalledFragment : MainNavFragmentX() { } } } + + @OptIn(ExperimentalMaterialApi::class, ExperimentalMaterial3Api::class) + private fun redrawPage(products: List?) { + 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?.sortedBy(Product::label), repositories, + onUserClick = { item -> + AppSheetX(item.packageName) + .showNow(parentFragmentManager, "Product ${item.packageName}") + }, + onFavouriteClick = {}, + onInstallClick = { + mainActivityX.syncConnection.binder?.installApps(listOf(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 a17cd09c..85e26028 100644 --- a/src/main/kotlin/com/looker/droidify/ui/fragments/LatestFragment.kt +++ b/src/main/kotlin/com/looker/droidify/ui/fragments/LatestFragment.kt @@ -6,10 +6,13 @@ import android.view.View import android.view.ViewGroup import androidx.appcompat.widget.SearchView import androidx.compose.foundation.isSystemInDarkTheme -import androidx.compose.material.Scaffold +import androidx.compose.material.ExperimentalMaterialApi +import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.material3.Scaffold import com.google.android.material.composethemeadapter.MdcTheme import com.looker.droidify.R import com.looker.droidify.content.Preferences +import com.looker.droidify.database.entity.Product import com.looker.droidify.database.entity.Repository import com.looker.droidify.databinding.FragmentLatestXBinding import com.looker.droidify.ui.compose.ProductsHorizontalRecycler @@ -45,28 +48,7 @@ class LatestFragment : MainNavFragmentX() { } viewModel.installed.observe(viewLifecycleOwner) {} 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.secondaryProducts.observe(viewLifecycleOwner) { binding.secondaryComposeRecycler.setContent { @@ -106,4 +88,30 @@ class LatestFragment : MainNavFragmentX() { } } } + + @OptIn(ExperimentalMaterialApi::class, ExperimentalMaterial3Api::class) + private fun redrawPage(products: List?) { + 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)) + } + ) + } + } + } + } }