mirror of
https://github.com/Aviortheking/Neo-Store.git
synced 2025-04-23 11:22:12 +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,100 +75,97 @@ 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 {
|
||||
AppTheme(
|
||||
darkTheme = when (Preferences[Preferences.Key.Theme]) {
|
||||
is Preferences.Theme.System -> isSystemInDarkTheme()
|
||||
is Preferences.Theme.AmoledSystem -> isSystemInDarkTheme()
|
||||
else -> isDarkTheme
|
||||
}
|
||||
) {
|
||||
Scaffold(
|
||||
// TODO add the topBar to the activity instead of the fragments
|
||||
topBar = {
|
||||
TopBar(title = stringResource(id = R.string.application_name)) {
|
||||
ExpandableSearchAction(
|
||||
query = viewModel.searchQuery.value.orEmpty(),
|
||||
onClose = {
|
||||
viewModel.searchQuery.value = ""
|
||||
},
|
||||
onQueryChanged = { query ->
|
||||
if (isResumed && query != viewModel.searchQuery.value)
|
||||
viewModel.setSearchQuery(query)
|
||||
}
|
||||
)
|
||||
TopBarAction(icon = Icons.Rounded.Sync) {
|
||||
mainActivityX.syncConnection.binder?.sync(SyncService.SyncRequest.MANUAL)
|
||||
}
|
||||
TopBarAction(icon = Icons.Rounded.Settings) {
|
||||
startActivity(Intent(context, PrefsActivityX::class.java))
|
||||
@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()
|
||||
is Preferences.Theme.AmoledSystem -> isSystemInDarkTheme()
|
||||
else -> isDarkTheme
|
||||
}
|
||||
) {
|
||||
Scaffold(
|
||||
// TODO add the topBar to the activity instead of the fragments
|
||||
topBar = {
|
||||
TopBar(title = stringResource(id = R.string.application_name)) {
|
||||
ExpandableSearchAction(
|
||||
query = searchQuery.orEmpty(),
|
||||
onClose = {
|
||||
viewModel.setSearchQuery("")
|
||||
},
|
||||
onQueryChanged = { query ->
|
||||
if (isResumed && query != searchQuery)
|
||||
viewModel.setSearchQuery(query)
|
||||
}
|
||||
)
|
||||
TopBarAction(icon = Icons.Rounded.Sync) {
|
||||
mainActivityX.syncConnection.binder?.sync(SyncService.SyncRequest.MANUAL)
|
||||
}
|
||||
TopBarAction(icon = Icons.Rounded.Settings) {
|
||||
startActivity(Intent(context, PrefsActivityX::class.java))
|
||||
}
|
||||
}
|
||||
) { padding ->
|
||||
Column(
|
||||
Modifier
|
||||
.padding(padding)
|
||||
.background(MaterialTheme.colorScheme.background)
|
||||
.fillMaxSize()
|
||||
}
|
||||
) { padding ->
|
||||
Column(
|
||||
Modifier
|
||||
.padding(padding)
|
||||
.background(MaterialTheme.colorScheme.background)
|
||||
.fillMaxSize()
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(id = R.string.new_applications),
|
||||
modifier = Modifier.padding(8.dp)
|
||||
)
|
||||
ProductsHorizontalRecycler(secondaryList, repositories) { item ->
|
||||
AppSheetX(item.packageName)
|
||||
.showNow(parentFragmentManager, "Product ${item.packageName}")
|
||||
}
|
||||
Row(
|
||||
modifier = Modifier.padding(horizontal = 8.dp, vertical = 4.dp),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(id = R.string.new_applications),
|
||||
modifier = Modifier.padding(8.dp)
|
||||
text = stringResource(id = R.string.recently_updated),
|
||||
modifier = Modifier.weight(1f),
|
||||
)
|
||||
ProductsHorizontalRecycler(secondaryList, repositories) { item ->
|
||||
Chip(
|
||||
shape = MaterialTheme.shapes.medium,
|
||||
colors = ChipDefaults.chipColors(
|
||||
backgroundColor = MaterialTheme.colorScheme.surface,
|
||||
contentColor = MaterialTheme.colorScheme.onSurface,
|
||||
),
|
||||
onClick = { } // TODO add sort & filter
|
||||
) {
|
||||
Icon(
|
||||
modifier = Modifier.size(18.dp),
|
||||
painter = painterResource(id = R.drawable.ic_sort),
|
||||
contentDescription = stringResource(id = R.string.sort_filter)
|
||||
)
|
||||
Spacer(modifier = Modifier.width(8.dp))
|
||||
Text(text = stringResource(id = R.string.sort_filter))
|
||||
}
|
||||
}
|
||||
ProductsVerticalRecycler(primaryList, repositories,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.weight(1f),
|
||||
onUserClick = { item ->
|
||||
AppSheetX(item.packageName)
|
||||
.showNow(parentFragmentManager, "Product ${item.packageName}")
|
||||
},
|
||||
onFavouriteClick = {},
|
||||
onInstallClick = {
|
||||
mainActivityX.syncConnection.binder?.installApps(listOf(it))
|
||||
}
|
||||
Row(
|
||||
modifier = Modifier.padding(horizontal = 8.dp, vertical = 4.dp),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(id = R.string.recently_updated),
|
||||
modifier = Modifier.weight(1f),
|
||||
)
|
||||
Chip(
|
||||
shape = MaterialTheme.shapes.medium,
|
||||
colors = ChipDefaults.chipColors(
|
||||
backgroundColor = MaterialTheme.colorScheme.surface,
|
||||
contentColor = MaterialTheme.colorScheme.onSurface,
|
||||
),
|
||||
onClick = { } // TODO add sort & filter
|
||||
) {
|
||||
Icon(
|
||||
modifier = Modifier.size(18.dp),
|
||||
painter = painterResource(id = R.drawable.ic_sort),
|
||||
contentDescription = stringResource(id = R.string.sort_filter)
|
||||
)
|
||||
Spacer(modifier = Modifier.width(8.dp))
|
||||
Text(text = stringResource(id = R.string.sort_filter))
|
||||
}
|
||||
}
|
||||
ProductsVerticalRecycler(primaryList, repositories,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.weight(1f),
|
||||
onUserClick = { item ->
|
||||
AppSheetX(item.packageName)
|
||||
.showNow(parentFragmentManager, "Product ${item.packageName}")
|
||||
},
|
||||
onFavouriteClick = {},
|
||||
onInstallClick = {
|
||||
mainActivityX.syncConnection.binder?.installApps(listOf(it))
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user