From 25a3c2691ffe77e40a8e818f1b6ffb826379afab Mon Sep 17 00:00:00 2001 From: machiav3lli Date: Sat, 8 Oct 2022 01:50:07 +0200 Subject: [PATCH] Clean up --- src/main/AndroidManifest.xml | 63 ++--- .../fdroid/ui/pages/ExplorePage.kt | 137 +++++------ .../fdroid/ui/pages/InstalledPage.kt | 227 +++++++++--------- .../machiav3lli/fdroid/ui/pages/LatestPage.kt | 137 +++++------ .../fdroid/ui/pages/PrefsOtherPage.kt | 1 - 5 files changed, 266 insertions(+), 299 deletions(-) diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml index d8e24755..1200e266 100644 --- a/src/main/AndroidManifest.xml +++ b/src/main/AndroidManifest.xml @@ -1,30 +1,31 @@ + xmlns:tools="http://schemas.android.com/tools"> - + + android:name=".MainApplication" + android:allowBackup="false" + android:icon="${appIcon}" + android:label="@string/application_name" + android:roundIcon="${appIconRound}" + android:supportsRtl="true" android:theme="@style/Theme.Main.Amoled" + tools:ignore="GoogleAppIndexingWarning"> + android:name=".MainApplication$BootReceiver" + android:exported="true"> @@ -33,10 +34,10 @@ + android:name=".ui.activities.MainActivityX" + android:exported="true" + android:launchMode="singleTask" + android:windowSoftInputMode="adjustResize"> @@ -59,8 +60,8 @@ + android:host="details" + android:scheme="market" /> @@ -82,29 +83,29 @@ + android:name=".ui.activities.PrefsActivityX" + android:exported="true" + android:launchMode="singleTask" + android:windowSoftInputMode="adjustResize" /> + android:name=".service.SyncService$Job" + android:exported="true" + android:permission="android.permission.BIND_JOB_SERVICE" /> + android:name=".installer.InstallerService" + android:exported="false" /> + android:name=".content.Cache$Provider" + android:authorities="${applicationId}.provider.cache" + android:exported="false" + android:grantUriPermissions="true" /> diff --git a/src/main/kotlin/com/machiav3lli/fdroid/ui/pages/ExplorePage.kt b/src/main/kotlin/com/machiav3lli/fdroid/ui/pages/ExplorePage.kt index d76a0d15..6766beaf 100644 --- a/src/main/kotlin/com/machiav3lli/fdroid/ui/pages/ExplorePage.kt +++ b/src/main/kotlin/com/machiav3lli/fdroid/ui/pages/ExplorePage.kt @@ -1,7 +1,6 @@ package com.machiav3lli.fdroid.ui.pages import androidx.compose.foundation.background -import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer @@ -35,10 +34,8 @@ import com.machiav3lli.fdroid.ui.compose.ProductsVerticalRecycler import com.machiav3lli.fdroid.ui.compose.components.CategoryChip import com.machiav3lli.fdroid.ui.compose.icons.Phosphor import com.machiav3lli.fdroid.ui.compose.icons.phosphor.FunnelSimple -import com.machiav3lli.fdroid.ui.compose.theme.AppTheme import com.machiav3lli.fdroid.ui.navigation.NavItem import com.machiav3lli.fdroid.ui.viewmodels.MainNavFragmentViewModelX -import com.machiav3lli.fdroid.utility.isDarkTheme import com.machiav3lli.fdroid.utility.onLaunchClick import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers @@ -78,83 +75,75 @@ fun ExplorePage(viewModel: MainNavFragmentViewModelX) { } } - AppTheme( - darkTheme = when (Preferences[Preferences.Key.Theme]) { - is Preferences.Theme.System -> isSystemInDarkTheme() - is Preferences.Theme.SystemBlack -> isSystemInDarkTheme() - else -> isDarkTheme - } + Column( + Modifier + .background(MaterialTheme.colorScheme.background) + .fillMaxSize() ) { - Column( - Modifier - .background(MaterialTheme.colorScheme.background) - .fillMaxSize() + Row( + modifier = Modifier.padding(horizontal = 6.dp), + verticalAlignment = Alignment.CenterVertically, ) { - Row( - modifier = Modifier.padding(horizontal = 6.dp), - verticalAlignment = Alignment.CenterVertically, - ) { - var favoriteFilter by remember { - mutableStateOf(false) - } - - SuggestionChip( - shape = MaterialTheme.shapes.medium, - colors = SuggestionChipDefaults.suggestionChipColors( - containerColor = MaterialTheme.colorScheme.surface, - labelColor = MaterialTheme.colorScheme.onSurface, - ), - onClick = { - mainActivityX.navigateSortFilter(NavItem.Explore.destination) - }, - icon = { - Icon( - modifier = Modifier.size(18.dp), - imageVector = Phosphor.FunnelSimple, - contentDescription = stringResource(id = R.string.sort_filter) - ) - }, - label = { - Text(text = stringResource(id = R.string.sort_filter)) - } - ) - Spacer(modifier = Modifier.weight(1f)) - CategoryChip( - category = stringResource(id = R.string.favorite_applications), - isSelected = favoriteFilter, - onSelected = { - favoriteFilter = !favoriteFilter - viewModel.sections.postValue( - if (it) Section.FAVORITE - else Section.All - ) - } - ) + var favoriteFilter by remember { + mutableStateOf(false) } - ProductsVerticalRecycler( - productsList = products, - repositories = repositoriesMap, - favorites = favorites, - modifier = Modifier - .fillMaxWidth() - .weight(1f), - onUserClick = { item -> - mainActivityX.navigateProduct(item.packageName) + + SuggestionChip( + shape = MaterialTheme.shapes.medium, + colors = SuggestionChipDefaults.suggestionChipColors( + containerColor = MaterialTheme.colorScheme.surface, + labelColor = MaterialTheme.colorScheme.onSurface, + ), + onClick = { + mainActivityX.navigateSortFilter(NavItem.Explore.destination) }, - onFavouriteClick = { item -> - viewModel.setFavorite( - item.packageName, - !favorites.contains(item.packageName) + icon = { + Icon( + modifier = Modifier.size(18.dp), + imageVector = Phosphor.FunnelSimple, + contentDescription = stringResource(id = R.string.sort_filter) ) }, - getInstalled = { installedList?.get(it.packageName) } - ) { item -> - val installed = installedList?.get(item.packageName) - if (installed != null && installed.launcherActivities.isNotEmpty()) - context.onLaunchClick(installed, mainActivityX.supportFragmentManager) - else - mainActivityX.syncConnection.binder?.installApps(listOf(item)) - } + label = { + Text(text = stringResource(id = R.string.sort_filter)) + } + ) + Spacer(modifier = Modifier.weight(1f)) + CategoryChip( + category = stringResource(id = R.string.favorite_applications), + isSelected = favoriteFilter, + onSelected = { + favoriteFilter = !favoriteFilter + viewModel.sections.postValue( + if (it) Section.FAVORITE + else Section.All + ) + } + ) + } + ProductsVerticalRecycler( + productsList = products, + repositories = repositoriesMap, + favorites = favorites, + modifier = Modifier + .fillMaxWidth() + .weight(1f), + onUserClick = { item -> + mainActivityX.navigateProduct(item.packageName) + }, + onFavouriteClick = { item -> + viewModel.setFavorite( + item.packageName, + !favorites.contains(item.packageName) + ) + }, + getInstalled = { installedList?.get(it.packageName) } + ) { item -> + val installed = installedList?.get(item.packageName) + if (installed != null && installed.launcherActivities.isNotEmpty()) + context.onLaunchClick(installed, mainActivityX.supportFragmentManager) + else + mainActivityX.syncConnection.binder?.installApps(listOf(item)) } } } diff --git a/src/main/kotlin/com/machiav3lli/fdroid/ui/pages/InstalledPage.kt b/src/main/kotlin/com/machiav3lli/fdroid/ui/pages/InstalledPage.kt index f46220b0..233796fe 100644 --- a/src/main/kotlin/com/machiav3lli/fdroid/ui/pages/InstalledPage.kt +++ b/src/main/kotlin/com/machiav3lli/fdroid/ui/pages/InstalledPage.kt @@ -2,7 +2,6 @@ package com.machiav3lli.fdroid.ui.pages import androidx.compose.animation.AnimatedVisibility import androidx.compose.foundation.background -import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer @@ -43,10 +42,8 @@ import com.machiav3lli.fdroid.ui.compose.icons.phosphor.CaretDown import com.machiav3lli.fdroid.ui.compose.icons.phosphor.CaretUp import com.machiav3lli.fdroid.ui.compose.icons.phosphor.Download import com.machiav3lli.fdroid.ui.compose.icons.phosphor.FunnelSimple -import com.machiav3lli.fdroid.ui.compose.theme.AppTheme import com.machiav3lli.fdroid.ui.navigation.NavItem import com.machiav3lli.fdroid.ui.viewmodels.MainNavFragmentViewModelX -import com.machiav3lli.fdroid.utility.isDarkTheme import com.machiav3lli.fdroid.utility.onLaunchClick import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers @@ -87,133 +84,125 @@ fun InstalledPage(viewModel: MainNavFragmentViewModelX) { } } - AppTheme( - darkTheme = when (Preferences[Preferences.Key.Theme]) { - is Preferences.Theme.System -> isSystemInDarkTheme() - is Preferences.Theme.SystemBlack -> isSystemInDarkTheme() - else -> isDarkTheme - } - ) { - var updatesVisible by remember(secondaryList) { mutableStateOf(true) } + var updatesVisible by remember(secondaryList) { mutableStateOf(true) } - Column( - Modifier - .background(MaterialTheme.colorScheme.background) - .fillMaxSize() - ) { - AnimatedVisibility(visible = secondaryList.orEmpty().isNotEmpty()) { - Column { - Row( - modifier = Modifier.padding(horizontal = 8.dp, vertical = 4.dp), - verticalAlignment = Alignment.CenterVertically + Column( + Modifier + .background(MaterialTheme.colorScheme.background) + .fillMaxSize() + ) { + AnimatedVisibility(visible = secondaryList.orEmpty().isNotEmpty()) { + Column { + Row( + modifier = Modifier.padding(horizontal = 8.dp, vertical = 4.dp), + verticalAlignment = Alignment.CenterVertically + ) { + ElevatedButton( + colors = ButtonDefaults.elevatedButtonColors( + contentColor = MaterialTheme.colorScheme.primary + ), + onClick = { updatesVisible = !updatesVisible } ) { - ElevatedButton( - colors = ButtonDefaults.elevatedButtonColors( - contentColor = MaterialTheme.colorScheme.primary - ), - onClick = { updatesVisible = !updatesVisible } - ) { - Text( - modifier = Modifier.padding(start = 4.dp), - text = stringResource(id = R.string.updates), - textAlign = TextAlign.Center, - style = MaterialTheme.typography.titleSmall - ) - Spacer(modifier = Modifier.width(8.dp)) - Icon( - modifier = Modifier.size(18.dp), - imageVector = if (updatesVisible) Phosphor.CaretUp else Phosphor.CaretDown, - contentDescription = stringResource(id = R.string.updates) - ) - } - Spacer(modifier = Modifier.weight(1f)) - SuggestionChip( - shape = MaterialTheme.shapes.medium, - colors = SuggestionChipDefaults.suggestionChipColors( - containerColor = MaterialTheme.colorScheme.surface, - labelColor = MaterialTheme.colorScheme.onSurface, - ), - onClick = { - secondaryList?.let { - mainActivityX.syncConnection.binder?.updateApps( - it.map( - Product::toItem - ) - ) - } - }, - icon = { - Icon( - modifier = Modifier.size(18.dp), - imageVector = Phosphor.Download, - contentDescription = stringResource(id = R.string.update_all) - ) - }, - label = { - Text(text = stringResource(id = R.string.update_all)) - } + Text( + modifier = Modifier.padding(start = 4.dp), + text = stringResource(id = R.string.updates), + textAlign = TextAlign.Center, + style = MaterialTheme.typography.titleSmall + ) + Spacer(modifier = Modifier.width(8.dp)) + Icon( + modifier = Modifier.size(18.dp), + imageVector = if (updatesVisible) Phosphor.CaretUp else Phosphor.CaretDown, + contentDescription = stringResource(id = R.string.updates) ) } - AnimatedVisibility(visible = updatesVisible) { - ProductsHorizontalRecycler(secondaryList, repositoriesMap) { item -> - mainActivityX.navigateProduct(item.packageName) + Spacer(modifier = Modifier.weight(1f)) + SuggestionChip( + shape = MaterialTheme.shapes.medium, + colors = SuggestionChipDefaults.suggestionChipColors( + containerColor = MaterialTheme.colorScheme.surface, + labelColor = MaterialTheme.colorScheme.onSurface, + ), + onClick = { + secondaryList?.let { + mainActivityX.syncConnection.binder?.updateApps( + it.map( + Product::toItem + ) + ) + } + }, + icon = { + Icon( + modifier = Modifier.size(18.dp), + imageVector = Phosphor.Download, + contentDescription = stringResource(id = R.string.update_all) + ) + }, + label = { + Text(text = stringResource(id = R.string.update_all)) } + ) + } + AnimatedVisibility(visible = updatesVisible) { + ProductsHorizontalRecycler(secondaryList, repositoriesMap) { item -> + mainActivityX.navigateProduct(item.packageName) } } } - Row( - modifier = Modifier.padding(horizontal = 8.dp, vertical = 4.dp), - verticalAlignment = Alignment.CenterVertically - ) { - Text( - text = stringResource(id = R.string.installed_applications), - modifier = Modifier.weight(1f), - ) - SuggestionChip( - shape = MaterialTheme.shapes.medium, - colors = SuggestionChipDefaults.suggestionChipColors( - containerColor = MaterialTheme.colorScheme.surface, - labelColor = MaterialTheme.colorScheme.onSurface, - ), - onClick = { - mainActivityX.navigateSortFilter(NavItem.Installed.destination) - }, - icon = { - Icon( - modifier = Modifier.size(18.dp), - imageVector = Phosphor.FunnelSimple, - contentDescription = stringResource(id = R.string.sort_filter) - ) - }, - label = { - Text(text = stringResource(id = R.string.sort_filter)) - } - ) - } - ProductsVerticalRecycler( - productsList = primaryList?.sortedBy { it.label.lowercase() }, - repositories = repositoriesMap, - favorites = favorites, - modifier = Modifier - .fillMaxWidth() - .weight(1f), - onUserClick = { item -> - mainActivityX.navigateProduct(item.packageName) + } + Row( + modifier = Modifier.padding(horizontal = 8.dp, vertical = 4.dp), + verticalAlignment = Alignment.CenterVertically + ) { + Text( + text = stringResource(id = R.string.installed_applications), + modifier = Modifier.weight(1f), + ) + SuggestionChip( + shape = MaterialTheme.shapes.medium, + colors = SuggestionChipDefaults.suggestionChipColors( + containerColor = MaterialTheme.colorScheme.surface, + labelColor = MaterialTheme.colorScheme.onSurface, + ), + onClick = { + mainActivityX.navigateSortFilter(NavItem.Installed.destination) }, - onFavouriteClick = { item -> - viewModel.setFavorite( - item.packageName, - !favorites.contains(item.packageName) + icon = { + Icon( + modifier = Modifier.size(18.dp), + imageVector = Phosphor.FunnelSimple, + contentDescription = stringResource(id = R.string.sort_filter) ) }, - getInstalled = { installedList?.get(it.packageName) } - ) { item -> - val installed = installedList?.get(item.packageName) - if (installed != null && installed.launcherActivities.isNotEmpty()) - context.onLaunchClick(installed, mainActivityX.supportFragmentManager) - else - mainActivityX.syncConnection.binder?.installApps(listOf(item)) - } + label = { + Text(text = stringResource(id = R.string.sort_filter)) + } + ) + } + ProductsVerticalRecycler( + productsList = primaryList?.sortedBy { it.label.lowercase() }, + repositories = repositoriesMap, + favorites = favorites, + modifier = Modifier + .fillMaxWidth() + .weight(1f), + onUserClick = { item -> + mainActivityX.navigateProduct(item.packageName) + }, + onFavouriteClick = { item -> + viewModel.setFavorite( + item.packageName, + !favorites.contains(item.packageName) + ) + }, + getInstalled = { installedList?.get(it.packageName) } + ) { item -> + val installed = installedList?.get(item.packageName) + if (installed != null && installed.launcherActivities.isNotEmpty()) + context.onLaunchClick(installed, mainActivityX.supportFragmentManager) + else + mainActivityX.syncConnection.binder?.installApps(listOf(item)) } } } diff --git a/src/main/kotlin/com/machiav3lli/fdroid/ui/pages/LatestPage.kt b/src/main/kotlin/com/machiav3lli/fdroid/ui/pages/LatestPage.kt index c126bf75..e645c588 100644 --- a/src/main/kotlin/com/machiav3lli/fdroid/ui/pages/LatestPage.kt +++ b/src/main/kotlin/com/machiav3lli/fdroid/ui/pages/LatestPage.kt @@ -1,7 +1,6 @@ package com.machiav3lli.fdroid.ui.pages import androidx.compose.foundation.background -import androidx.compose.foundation.isSystemInDarkTheme import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.padding @@ -32,10 +31,8 @@ import com.machiav3lli.fdroid.ui.compose.ProductsHorizontalRecycler import com.machiav3lli.fdroid.ui.compose.components.ProductsListItem import com.machiav3lli.fdroid.ui.compose.icons.Phosphor import com.machiav3lli.fdroid.ui.compose.icons.phosphor.FunnelSimple -import com.machiav3lli.fdroid.ui.compose.theme.AppTheme import com.machiav3lli.fdroid.ui.navigation.NavItem import com.machiav3lli.fdroid.ui.viewmodels.MainNavFragmentViewModelX -import com.machiav3lli.fdroid.utility.isDarkTheme import com.machiav3lli.fdroid.utility.onLaunchClick import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers @@ -77,85 +74,77 @@ fun LatestPage(viewModel: MainNavFragmentViewModelX) { } } - AppTheme( - darkTheme = when (Preferences[Preferences.Key.Theme]) { - is Preferences.Theme.System -> isSystemInDarkTheme() - is Preferences.Theme.SystemBlack -> isSystemInDarkTheme() - else -> isDarkTheme - } + LazyColumn( + Modifier + .background(MaterialTheme.colorScheme.background) + .fillMaxSize(), ) { - LazyColumn( - Modifier - .background(MaterialTheme.colorScheme.background) - .fillMaxSize(), - ) { - item { + item { + Text( + text = stringResource(id = R.string.new_applications), + modifier = Modifier.padding(8.dp) + ) + ProductsHorizontalRecycler(secondaryList, repositoriesMap) { item -> + mainActivityX.navigateProduct(item.packageName) + } + } + item { + 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, repositoriesMap) { item -> - mainActivityX.navigateProduct(item.packageName) - } - } - item { - 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), - ) - SuggestionChip( - shape = MaterialTheme.shapes.medium, - colors = SuggestionChipDefaults.suggestionChipColors( - containerColor = MaterialTheme.colorScheme.surface, - labelColor = MaterialTheme.colorScheme.onSurface, - ), - onClick = { - mainActivityX.navigateSortFilter(NavItem.Latest.destination) - }, - icon = { - Icon( - modifier = Modifier.size(18.dp), - imageVector = Phosphor.FunnelSimple, - contentDescription = stringResource(id = R.string.sort_filter) - ) - }, - label = { - Text(text = stringResource(id = R.string.sort_filter)) - } - ) - } - } - items( - items = primaryList?.map { it.toItem() } ?: emptyList(), - ) { item -> - ProductsListItem( - item = item, - repo = repositoriesMap[item.repositoryId], - isFavorite = favorites.contains(item.packageName), - onUserClick = { mainActivityX.navigateProduct(it.packageName) }, - onFavouriteClick = { - viewModel.setFavorite( - it.packageName, - !favorites.contains(it.packageName) + SuggestionChip( + shape = MaterialTheme.shapes.medium, + colors = SuggestionChipDefaults.suggestionChipColors( + containerColor = MaterialTheme.colorScheme.surface, + labelColor = MaterialTheme.colorScheme.onSurface, + ), + onClick = { + mainActivityX.navigateSortFilter(NavItem.Latest.destination) + }, + icon = { + Icon( + modifier = Modifier.size(18.dp), + imageVector = Phosphor.FunnelSimple, + contentDescription = stringResource(id = R.string.sort_filter) ) }, - installed = installedList?.get(item.packageName), - onActionClick = { - val installed = installedList?.get(it.packageName) - if (installed != null && installed.launcherActivities.isNotEmpty()) - context.onLaunchClick( - installed, - mainActivityX.supportFragmentManager - ) - else - mainActivityX.syncConnection.binder?.installApps(listOf(it)) + label = { + Text(text = stringResource(id = R.string.sort_filter)) } ) } } + items( + items = primaryList?.map { it.toItem() } ?: emptyList(), + ) { item -> + ProductsListItem( + item = item, + repo = repositoriesMap[item.repositoryId], + isFavorite = favorites.contains(item.packageName), + onUserClick = { mainActivityX.navigateProduct(it.packageName) }, + onFavouriteClick = { + viewModel.setFavorite( + it.packageName, + !favorites.contains(it.packageName) + ) + }, + installed = installedList?.get(item.packageName), + onActionClick = { + val installed = installedList?.get(it.packageName) + if (installed != null && installed.launcherActivities.isNotEmpty()) + context.onLaunchClick( + installed, + mainActivityX.supportFragmentManager + ) + else + mainActivityX.syncConnection.binder?.installApps(listOf(it)) + } + ) + } } } diff --git a/src/main/kotlin/com/machiav3lli/fdroid/ui/pages/PrefsOtherPage.kt b/src/main/kotlin/com/machiav3lli/fdroid/ui/pages/PrefsOtherPage.kt index d1ae4fc7..ba224ca5 100644 --- a/src/main/kotlin/com/machiav3lli/fdroid/ui/pages/PrefsOtherPage.kt +++ b/src/main/kotlin/com/machiav3lli/fdroid/ui/pages/PrefsOtherPage.kt @@ -41,7 +41,6 @@ fun PrefsOtherPage() { Preferences.Key.ProxyHost, Preferences.Key.ProxyPort, ) - val infoPrefs = emptyList>() Scaffold( modifier = Modifier.fillMaxSize()