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.MaterialTheme
|
||||||
import androidx.compose.material3.Scaffold
|
import androidx.compose.material3.Scaffold
|
||||||
import androidx.compose.material3.Text
|
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.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.platform.ComposeView
|
||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import com.looker.droidify.R
|
import com.looker.droidify.R
|
||||||
import com.looker.droidify.content.Preferences
|
import com.looker.droidify.content.Preferences
|
||||||
import com.looker.droidify.database.entity.Product
|
|
||||||
import com.looker.droidify.database.entity.Repository
|
import com.looker.droidify.database.entity.Repository
|
||||||
import com.looker.droidify.databinding.FragmentComposeBinding
|
|
||||||
import com.looker.droidify.service.SyncService
|
import com.looker.droidify.service.SyncService
|
||||||
import com.looker.droidify.ui.activities.PrefsActivityX
|
import com.looker.droidify.ui.activities.PrefsActivityX
|
||||||
import com.looker.droidify.ui.compose.ProductsHorizontalRecycler
|
import com.looker.droidify.ui.compose.ProductsHorizontalRecycler
|
||||||
@ -49,9 +51,6 @@ import com.looker.droidify.utility.isDarkTheme
|
|||||||
|
|
||||||
class LatestFragment : MainNavFragmentX() {
|
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 primarySource = Source.UPDATED
|
||||||
override val secondarySource = Source.NEW
|
override val secondarySource = Source.NEW
|
||||||
|
|
||||||
@ -63,9 +62,9 @@ class LatestFragment : MainNavFragmentX() {
|
|||||||
savedInstanceState: Bundle?,
|
savedInstanceState: Bundle?,
|
||||||
): View {
|
): View {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
binding = FragmentComposeBinding.inflate(inflater, container, false)
|
return ComposeView(requireContext()).apply {
|
||||||
binding.lifecycleOwner = this
|
setContent { LatestPage() }
|
||||||
return binding.root
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setupLayout() {
|
override fun setupLayout() {
|
||||||
@ -76,100 +75,97 @@ class LatestFragment : MainNavFragmentX() {
|
|||||||
// Avoid the compiler using the same class as observer
|
// Avoid the compiler using the same class as observer
|
||||||
Log.d(this::class.java.canonicalName, this.toString())
|
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)
|
@OptIn(ExperimentalMaterialApi::class, ExperimentalMaterial3Api::class)
|
||||||
private fun redrawPage(primaryList: List<Product>?, secondaryList: List<Product>?) {
|
@Composable
|
||||||
binding.composeView.setContent {
|
private fun LatestPage() {
|
||||||
AppTheme(
|
val primaryList by viewModel.primaryProducts.observeAsState(null)
|
||||||
darkTheme = when (Preferences[Preferences.Key.Theme]) {
|
val secondaryList by viewModel.secondaryProducts.observeAsState(null)
|
||||||
is Preferences.Theme.System -> isSystemInDarkTheme()
|
val searchQuery by viewModel.searchQuery.observeAsState("")
|
||||||
is Preferences.Theme.AmoledSystem -> isSystemInDarkTheme()
|
|
||||||
else -> isDarkTheme
|
AppTheme(
|
||||||
}
|
darkTheme = when (Preferences[Preferences.Key.Theme]) {
|
||||||
) {
|
is Preferences.Theme.System -> isSystemInDarkTheme()
|
||||||
Scaffold(
|
is Preferences.Theme.AmoledSystem -> isSystemInDarkTheme()
|
||||||
// TODO add the topBar to the activity instead of the fragments
|
else -> isDarkTheme
|
||||||
topBar = {
|
}
|
||||||
TopBar(title = stringResource(id = R.string.application_name)) {
|
) {
|
||||||
ExpandableSearchAction(
|
Scaffold(
|
||||||
query = viewModel.searchQuery.value.orEmpty(),
|
// TODO add the topBar to the activity instead of the fragments
|
||||||
onClose = {
|
topBar = {
|
||||||
viewModel.searchQuery.value = ""
|
TopBar(title = stringResource(id = R.string.application_name)) {
|
||||||
},
|
ExpandableSearchAction(
|
||||||
onQueryChanged = { query ->
|
query = searchQuery.orEmpty(),
|
||||||
if (isResumed && query != viewModel.searchQuery.value)
|
onClose = {
|
||||||
viewModel.setSearchQuery(query)
|
viewModel.setSearchQuery("")
|
||||||
}
|
},
|
||||||
)
|
onQueryChanged = { query ->
|
||||||
TopBarAction(icon = Icons.Rounded.Sync) {
|
if (isResumed && query != searchQuery)
|
||||||
mainActivityX.syncConnection.binder?.sync(SyncService.SyncRequest.MANUAL)
|
viewModel.setSearchQuery(query)
|
||||||
}
|
|
||||||
TopBarAction(icon = Icons.Rounded.Settings) {
|
|
||||||
startActivity(Intent(context, PrefsActivityX::class.java))
|
|
||||||
}
|
}
|
||||||
|
)
|
||||||
|
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(
|
) { padding ->
|
||||||
Modifier
|
Column(
|
||||||
.padding(padding)
|
Modifier
|
||||||
.background(MaterialTheme.colorScheme.background)
|
.padding(padding)
|
||||||
.fillMaxSize()
|
.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(
|
||||||
text = stringResource(id = R.string.new_applications),
|
text = stringResource(id = R.string.recently_updated),
|
||||||
modifier = Modifier.padding(8.dp)
|
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)
|
AppSheetX(item.packageName)
|
||||||
.showNow(parentFragmentManager, "Product ${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