Update: Wire ComposeView in the MainNav fragments

This commit is contained in:
machiav3lli 2022-02-18 00:02:45 +01:00
parent a91020e885
commit 19bb3bf4ae
3 changed files with 127 additions and 16 deletions

View File

@ -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}")
}
}
}
}
}
}
}
}

View File

@ -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}")
}
}
}
}
}
}
}
}

View File

@ -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}")
}
}
}
}
}
}
}
}