mirror of
https://github.com/Aviortheking/Neo-Store.git
synced 2025-04-23 19:32:16 +00:00
Update: Migrate Latest to use Compose solely
This commit is contained in:
parent
467ee02cde
commit
123adea168
@ -27,16 +27,18 @@ import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.livedata.observeAsState
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.ComposeView
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
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.FragmentComposeBinding
|
||||
import com.looker.droidify.service.SyncService
|
||||
import com.looker.droidify.ui.activities.PrefsActivityX
|
||||
import com.looker.droidify.ui.compose.ProductsHorizontalRecycler
|
||||
@ -49,9 +51,6 @@ import com.looker.droidify.utility.isDarkTheme
|
||||
|
||||
class LatestFragment : MainNavFragmentX() {
|
||||
|
||||
private lateinit var binding: FragmentComposeBinding
|
||||
|
||||
// TODO replace the source with one that get a certain amount of updated apps
|
||||
override val primarySource = Source.UPDATED
|
||||
override val secondarySource = Source.NEW
|
||||
|
||||
@ -63,9 +62,9 @@ class LatestFragment : MainNavFragmentX() {
|
||||
savedInstanceState: Bundle?,
|
||||
): View {
|
||||
super.onCreate(savedInstanceState)
|
||||
binding = FragmentComposeBinding.inflate(inflater, container, false)
|
||||
binding.lifecycleOwner = this
|
||||
return binding.root
|
||||
return ComposeView(requireContext()).apply {
|
||||
setContent { LatestPage() }
|
||||
}
|
||||
}
|
||||
|
||||
override fun setupLayout() {
|
||||
@ -76,17 +75,15 @@ class LatestFragment : MainNavFragmentX() {
|
||||
// Avoid the compiler using the same class as observer
|
||||
Log.d(this::class.java.canonicalName, this.toString())
|
||||
}
|
||||
viewModel.primaryProducts.observe(viewLifecycleOwner) {
|
||||
redrawPage(it, viewModel.secondaryProducts.value)
|
||||
}
|
||||
viewModel.secondaryProducts.observe(viewLifecycleOwner) {
|
||||
redrawPage(viewModel.primaryProducts.value, it)
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalMaterialApi::class, ExperimentalMaterial3Api::class)
|
||||
private fun redrawPage(primaryList: List<Product>?, secondaryList: List<Product>?) {
|
||||
binding.composeView.setContent {
|
||||
@Composable
|
||||
private fun LatestPage() {
|
||||
val primaryList by viewModel.primaryProducts.observeAsState(null)
|
||||
val secondaryList by viewModel.secondaryProducts.observeAsState(null)
|
||||
val searchQuery by viewModel.searchQuery.observeAsState("")
|
||||
|
||||
AppTheme(
|
||||
darkTheme = when (Preferences[Preferences.Key.Theme]) {
|
||||
is Preferences.Theme.System -> isSystemInDarkTheme()
|
||||
@ -99,12 +96,12 @@ class LatestFragment : MainNavFragmentX() {
|
||||
topBar = {
|
||||
TopBar(title = stringResource(id = R.string.application_name)) {
|
||||
ExpandableSearchAction(
|
||||
query = viewModel.searchQuery.value.orEmpty(),
|
||||
query = searchQuery.orEmpty(),
|
||||
onClose = {
|
||||
viewModel.searchQuery.value = ""
|
||||
viewModel.setSearchQuery("")
|
||||
},
|
||||
onQueryChanged = { query ->
|
||||
if (isResumed && query != viewModel.searchQuery.value)
|
||||
if (isResumed && query != searchQuery)
|
||||
viewModel.setSearchQuery(query)
|
||||
}
|
||||
)
|
||||
@ -173,5 +170,4 @@ class LatestFragment : MainNavFragmentX() {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user