From 19bb3bf4ae035838c4e6f21eb21d4ba97e3086fb Mon Sep 17 00:00:00 2001 From: machiav3lli Date: Fri, 18 Feb 2022 00:02:45 +0100 Subject: [PATCH] Update: Wire ComposeView in the MainNav fragments --- .../droidify/ui/fragments/ExploreFragment.kt | 32 +++++++++- .../ui/fragments/InstalledFragment.kt | 58 ++++++++++++++++--- .../droidify/ui/fragments/LatestFragment.kt | 53 +++++++++++++++-- 3 files changed, 127 insertions(+), 16 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 441dd6e9..516283b3 100644 --- a/src/main/kotlin/com/looker/droidify/ui/fragments/ExploreFragment.kt +++ b/src/main/kotlin/com/looker/droidify/ui/fragments/ExploreFragment.kt @@ -4,10 +4,18 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import androidx.recyclerview.widget.LinearLayoutManager -import com.looker.droidify.database.entity.Product +import androidx.compose.foundation.isSystemInDarkTheme +import androidx.compose.material.Scaffold +import com.google.android.material.chip.Chip +import com.looker.droidify.R +import com.looker.droidify.content.Preferences import com.looker.droidify.database.entity.Repository import com.looker.droidify.databinding.FragmentExploreXBinding +import com.looker.droidify.entity.Section +import com.looker.droidify.ui.compose.ProductsVerticalRecycler +import com.looker.droidify.ui.compose.theme.AppTheme +import com.looker.droidify.utility.isDarkTheme + // TODO add chips bar to navigate categories class ExploreFragment : MainNavFragmentX() { @@ -37,5 +45,25 @@ class ExploreFragment : MainNavFragmentX() { viewModel.repositories.observe(viewLifecycleOwner) { 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) { + it.let { + AppSheetX(it.packageName) + .showNow(parentFragmentManager, "Product ${it.packageName}") + } + } + } + } + } + } } } 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 50fcad88..eebedfa1 100644 --- a/src/main/kotlin/com/looker/droidify/ui/fragments/InstalledFragment.kt +++ b/src/main/kotlin/com/looker/droidify/ui/fragments/InstalledFragment.kt @@ -4,9 +4,16 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import com.looker.droidify.database.entity.Product +import androidx.compose.foundation.isSystemInDarkTheme +import androidx.compose.material.Scaffold +import com.google.android.material.composethemeadapter.MdcTheme +import com.looker.droidify.content.Preferences import com.looker.droidify.database.entity.Repository import com.looker.droidify.databinding.FragmentInstalledXBinding +import com.looker.droidify.ui.compose.ProductsHorizontalRecycler +import com.looker.droidify.ui.compose.ProductsVerticalRecycler +import com.looker.droidify.ui.compose.theme.AppTheme +import com.looker.droidify.utility.isDarkTheme class InstalledFragment : MainNavFragmentX() { @@ -32,16 +39,49 @@ class InstalledFragment : MainNavFragmentX() { } override fun setupLayout() { - binding.buttonUpdated.setOnClickListener { - } - - viewModel.primaryProducts.observe(viewLifecycleOwner) { - } - viewModel.secondaryProducts.observe(viewLifecycleOwner) { - binding.updatedBar.visibility = if (it.isNotEmpty()) View.VISIBLE else View.GONE - } viewModel.repositories.observe(viewLifecycleOwner) { 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) { + it.let { + AppSheetX(it.packageName) + .showNow(parentFragmentManager, "Product ${it.packageName}") + } + } + } + } + } + } + viewModel.secondaryProducts.observe(viewLifecycleOwner) { + binding.updatedBar.visibility = if (it.isNotEmpty()) View.VISIBLE else View.GONE + binding.secondaryComposeRecycler.setContent { + AppTheme( + darkTheme = when (Preferences[Preferences.Key.Theme]) { + is Preferences.Theme.System -> isSystemInDarkTheme() + is Preferences.Theme.AmoledSystem -> isSystemInDarkTheme() + else -> isDarkTheme + } + ) { + MdcTheme { + ProductsHorizontalRecycler(it, repositories) { item -> + item.let { + AppSheetX(it.packageName) + .showNow(parentFragmentManager, "Product ${it.packageName}") + } + } + } + } + } + } } } 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 ecaf1856..9bf23900 100644 --- a/src/main/kotlin/com/looker/droidify/ui/fragments/LatestFragment.kt +++ b/src/main/kotlin/com/looker/droidify/ui/fragments/LatestFragment.kt @@ -4,9 +4,16 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import com.looker.droidify.database.entity.Product +import androidx.compose.foundation.isSystemInDarkTheme +import androidx.compose.material.Scaffold +import com.google.android.material.composethemeadapter.MdcTheme +import com.looker.droidify.content.Preferences import com.looker.droidify.database.entity.Repository import com.looker.droidify.databinding.FragmentLatestXBinding +import com.looker.droidify.ui.compose.ProductsHorizontalRecycler +import com.looker.droidify.ui.compose.ProductsVerticalRecycler +import com.looker.droidify.ui.compose.theme.AppTheme +import com.looker.droidify.utility.isDarkTheme class LatestFragment : MainNavFragmentX() { @@ -33,12 +40,48 @@ class LatestFragment : MainNavFragmentX() { } override fun setupLayout() { - viewModel.primaryProducts.observe(viewLifecycleOwner) { - } - viewModel.secondaryProducts.observe(viewLifecycleOwner) { - } viewModel.repositories.observe(viewLifecycleOwner) { 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) { + it.let { + AppSheetX(it.packageName) + .showNow(parentFragmentManager, "Product ${it.packageName}") + } + } + } + } + } + } + viewModel.secondaryProducts.observe(viewLifecycleOwner) { + binding.secondaryComposeRecycler.setContent { + AppTheme( + darkTheme = when (Preferences[Preferences.Key.Theme]) { + is Preferences.Theme.System -> isSystemInDarkTheme() + is Preferences.Theme.AmoledSystem -> isSystemInDarkTheme() + else -> isDarkTheme + } + ) { + MdcTheme { + ProductsHorizontalRecycler(it, repositories) { + it.let { + AppSheetX(it.packageName) + .showNow(parentFragmentManager, "Product ${it.packageName}") + } + } + } + } + } + } } }