appstore: fix padding, installed icons, source inference, user apps only, remove favorites
- Commit
536e40b1247366e333766adcb924c809a35c6556- Author
- Vayun Mathur <[email protected]>
- When
- 2026-07-31 16:20 UTC (4 months ago)
- Parents
9398491
Diff
appstore/src/main/java/com/vayunmathur/appstore/MainActivity.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/MainActivity.kt b/appstore/src/main/java/com/vayunmathur/appstore/MainActivity.ktindex f8464f0c52..73bd984a43 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/MainActivity.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/MainActivity.kt@@ -20,7 +20,6 @@ import com.vayunmathur.appstore.data.AppDatabase import com.vayunmathur.appstore.data.DB_NAME import com.vayunmathur.appstore.data.UnifiedApp import com.vayunmathur.appstore.ui.AppDetailPage-import com.vayunmathur.appstore.ui.FavoritesPage import com.vayunmathur.appstore.ui.InstalledPage import com.vayunmathur.appstore.ui.ReposPage import com.vayunmathur.appstore.ui.UpdatesPage@@ -29,12 +28,9 @@ import com.vayunmathur.appstore.util.AppStoreViewModelFactory import com.vayunmathur.library.room.buildDatabase import com.vayunmathur.library.ui.DynamicTheme import com.vayunmathur.library.ui.IconDownload-import com.vayunmathur.library.ui.IconFavorite import com.vayunmathur.library.ui.IconHome import com.vayunmathur.library.ui.IconSettings import com.vayunmathur.library.ui.IconPackage-import com.vayunmathur.library.ui.IconStar-import com.vayunmathur.library.ui.IconHistory import com.vayunmathur.library.util.BottomBarItem import com.vayunmathur.library.util.BottomNavBar import com.vayunmathur.library.util.MainNavigation@@ -56,7 +52,7 @@ class MainActivity : ComponentActivity() { enableEdgeToEdge() lifecycleScope.launch(Dispatchers.IO) {- val db = buildDatabase<AppDatabase>(dbName = DB_NAME)+ val db = buildDatabase<AppDatabase>(dbName = DB_NAME, migrations = AppDatabase.migrations) val factory = AppStoreViewModelFactory(applicationContext, db) withContext(Dispatchers.Main) { factoryState = factory@@ -72,7 +68,6 @@ class MainActivity : ComponentActivity() { Box(Modifier.fillMaxSize()) } else { val vm: AppStoreViewModel = viewModel(factory = factoryState!!)- // handle deep link pkg after vm ready LaunchedEffect(externalPkg) { externalPkg?.let { pkg -> val cached = vm.cachedApps.value.find { it.packageName == pkg }@@ -121,10 +116,8 @@ class MainActivity : ComponentActivity() { @Serializable sealed interface Route : NavKey { @Serializable data object Browse : Route- @Serializable data object Search : Route @Serializable data object Installed : Route @Serializable data object Updates : Route- @Serializable data object Favorites : Route @Serializable data object Repos : Route @Serializable data object Detail : Route }@@ -139,7 +132,6 @@ private fun AppRoot( val backStack = rememberNavBackStack<Route>(initial) val current = backStack.last() - // If an app is selected and we are not already on Detail, push Detail LaunchedEffect(selected) { if (selected != null && current !is Route.Detail) { backStack.add(Route.Detail)@@ -156,7 +148,6 @@ private fun AppRoot( BottomBarItem("Browse", Route.Browse) { IconHome() }, BottomBarItem("Installed", Route.Installed) { IconPackage() }, BottomBarItem("Updates", Route.Updates) { IconDownload() },- BottomBarItem("Favorites", Route.Favorites) { IconStar() }, BottomBarItem("Repos", Route.Repos) { IconSettings() }, ), current@@ -182,12 +173,6 @@ private fun AppRoot( backStack.add(Route.Detail) }) }- entry<Route.Favorites> {- FavoritesPage(viewModel = viewModel, onAppClick = { app ->- viewModel.selectApp(app)- backStack.add(Route.Detail)- })- } entry<Route.Repos> { ReposPage(viewModel = viewModel) }
appstore/src/main/java/com/vayunmathur/appstore/data/AppDatabase.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/data/AppDatabase.kt b/appstore/src/main/java/com/vayunmathur/appstore/data/AppDatabase.ktindex fa93e51821..8f52c118e5 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/data/AppDatabase.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/data/AppDatabase.kt@@ -8,6 +8,8 @@ import androidx.room.PrimaryKey import androidx.room.Query import androidx.room.RoomDatabase import androidx.room.Upsert+import androidx.room.migration.Migration+import androidx.sqlite.db.SupportSQLiteDatabase import kotlinx.coroutines.flow.Flow const val DB_NAME = "appstore-db"@@ -30,7 +32,7 @@ data class CachedAppEntity( val description: String, val iconUrl: String?, val author: String?,- val categories: String, // json joined+ val categories: String, // comma joined val versionName: String?, val versionCode: Long, val sizeBytes: Long,@@ -39,12 +41,6 @@ data class CachedAppEntity( val lastUpdated: Long ) -@Entity-data class FavoriteEntity(- @PrimaryKey val packageName: String,- val addedAt: Long = System.currentTimeMillis()-)- @Dao interface RepoDao { @Query("SELECT * FROM RepoEntity ORDER BY name ASC")@@ -87,28 +83,22 @@ interface CachedAppDao { suspend fun clearAll() } -@Dao-interface FavoriteDao {- @Query("SELECT * FROM FavoriteEntity ORDER BY addedAt DESC")- fun allFlow(): Flow<List<FavoriteEntity>>-- @Query("SELECT EXISTS(SELECT 1 FROM FavoriteEntity WHERE packageName = :pkg)")- fun isFavFlow(pkg: String): Flow<Boolean>-- @Upsert- suspend fun upsert(fav: FavoriteEntity)-- @Query("DELETE FROM FavoriteEntity WHERE packageName = :pkg")- suspend fun deleteByPackage(pkg: String)-}- @Database(- entities = [RepoEntity::class, CachedAppEntity::class, FavoriteEntity::class],- version = 1,+ entities = [RepoEntity::class, CachedAppEntity::class],+ version = 2, exportSchema = false ) abstract class AppDatabase : RoomDatabase() { abstract fun repoDao(): RepoDao abstract fun cachedAppDao(): CachedAppDao- abstract fun favoriteDao(): FavoriteDao++ companion object {+ val migrations = listOf(+ object : Migration(1, 2) {+ override fun migrate(db: SupportSQLiteDatabase) {+ db.execSQL("DROP TABLE IF EXISTS FavoriteEntity")+ }+ }+ )+ } }
appstore/src/main/java/com/vayunmathur/appstore/data/AppModels.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/data/AppModels.kt b/appstore/src/main/java/com/vayunmathur/appstore/data/AppModels.ktindex 41df61f2db..226720977f 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/data/AppModels.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/data/AppModels.kt@@ -4,16 +4,7 @@ import kotlinx.serialization.Serializable enum class AppSource { FDROID,- PLAYSTORE,- UNKNOWN-}--enum class InstallStatus {- NOT_INSTALLED,- INSTALLED,- UPDATE_AVAILABLE,- DOWNLOADING,- INSTALLING+ PLAYSTORE } @Serializable@@ -40,7 +31,7 @@ data class UnifiedApp( val lastUpdated: Long = 0L, val antiFeatures: List<String> = emptyList(), val isFree: Boolean = true,- val repoUrl: String? = null // for F-Droid+ val repoUrl: String? = null ) data class InstalledInfo(@@ -48,17 +39,9 @@ data class InstalledInfo( val name: String, val versionName: String?, val versionCode: Long,- val icon: android.graphics.drawable.Drawable? = null, val isSystem: Boolean = false ) -data class SearchResult(- val fdroidApps: List<UnifiedApp> = emptyList(),- val playApps: List<UnifiedApp> = emptyList()-) {- val combined: List<UnifiedApp> get() = fdroidApps + playApps-}- object DefaultRepos { const val FDROID_MAIN = "https://f-droid.org/repo" const val FDROID_ARCHIVE = "https://f-droid.org/archive"
appstore/src/main/java/com/vayunmathur/appstore/ui/AppDetailPage.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/ui/AppDetailPage.kt b/appstore/src/main/java/com/vayunmathur/appstore/ui/AppDetailPage.ktindex 221ae35fda..c375df1e38 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/ui/AppDetailPage.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/ui/AppDetailPage.kt@@ -1,5 +1,7 @@ package com.vayunmathur.appstore.ui +import android.graphics.drawable.Drawable+import androidx.compose.foundation.Image import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row@@ -16,12 +18,15 @@ import androidx.compose.foundation.verticalScroll import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue+import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip+import androidx.compose.ui.graphics.asImageBitmap import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.dp+import androidx.core.graphics.drawable.toBitmap import coil.compose.AsyncImage import com.vayunmathur.appstore.data.AppSource import com.vayunmathur.appstore.util.AppStoreViewModel@@ -31,12 +36,8 @@ import com.vayunmathur.library.ui.FilledTonalButton import com.vayunmathur.library.ui.HorizontalDivider import com.vayunmathur.library.ui.IconBack import com.vayunmathur.library.ui.IconDownload-import com.vayunmathur.library.ui.IconFavorite import com.vayunmathur.library.ui.IconGlobe-import com.vayunmathur.library.ui.IconLink import com.vayunmathur.library.ui.IconShoppingCart-import com.vayunmathur.library.ui.IconStar-import com.vayunmathur.library.ui.IconStarBorder import com.vayunmathur.library.ui.IconButton import com.vayunmathur.library.ui.MaterialTheme import com.vayunmathur.library.ui.OutlinedButton@@ -51,25 +52,18 @@ fun AppDetailPage( val app by viewModel.selectedApp.collectAsState() val current = app ?: return val installed by viewModel.installedApps.collectAsState()- val favorites by viewModel.favorites.collectAsState() val isInstalled = installed.any { it.packageName == current.packageName } val installedInfo = installed.find { it.packageName == current.packageName }- val isFav = favorites.any { it.packageName == current.packageName } val progressMap by viewModel.downloadProgress.collectAsState() val progress = progressMap[current.packageName]+ val icons by viewModel.installedIcons.collectAsState()+ val installedIcon = icons[current.packageName] Scaffold( topBar = { CenterAlignedTopAppBar( title = { Text(current.name) },- navigationIcon = {- IconButton(onClick = onBack) { IconBack() }- },- actions = {- IconButton(onClick = { viewModel.toggleFavorite(current.packageName) }) {- if (isFav) IconFavorite() else IconStarBorder()- }- }+ navigationIcon = { IconButton(onClick = onBack) { IconBack() } } ) } ) { padding ->@@ -78,12 +72,33 @@ fun AppDetailPage( verticalArrangement = Arrangement.spacedBy(12.dp) ) { Row(verticalAlignment = Alignment.CenterVertically) {- AsyncImage(- model = current.iconUrl,- contentDescription = null,- modifier = Modifier.size(72.dp).clip(RoundedCornerShape(16.dp)),- contentScale = ContentScale.Crop- )+ if (installedIcon != null) {+ val bitmap = remember(installedIcon) {+ try { installedIcon.toBitmap(width = 144, height = 144).asImageBitmap() } catch (_: Exception) { null }+ }+ if (bitmap != null) {+ Image(+ bitmap = bitmap,+ contentDescription = null,+ modifier = Modifier.size(72.dp).clip(RoundedCornerShape(16.dp)),+ contentScale = ContentScale.Crop+ )+ } else {+ AsyncImage(+ model = current.iconUrl,+ contentDescription = null,+ modifier = Modifier.size(72.dp).clip(RoundedCornerShape(16.dp)),+ contentScale = ContentScale.Crop+ )+ }+ } else {+ AsyncImage(+ model = current.iconUrl,+ contentDescription = null,+ modifier = Modifier.size(72.dp).clip(RoundedCornerShape(16.dp)),+ contentScale = ContentScale.Crop+ )+ } Spacer(Modifier.width(16.dp)) Column(Modifier.weight(1f)) { Text(current.name, style = MaterialTheme.typography.headlineSmall, fontWeight = FontWeight.Bold)@@ -134,9 +149,7 @@ fun AppDetailPage( if (current.source == AppSource.FDROID || current.website != null) { OutlinedButton(onClick = { viewModel.openInBrowser(current.website ?: current.sourceCode ?: "")- }) {- IconGlobe()- }+ }) { IconGlobe() } } }
appstore/src/main/java/com/vayunmathur/appstore/ui/BrowsePage.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/ui/BrowsePage.kt b/appstore/src/main/java/com/vayunmathur/appstore/ui/BrowsePage.ktindex b4c876fe2e..941529e073 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/ui/BrowsePage.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/ui/BrowsePage.kt@@ -1,5 +1,7 @@ package com.vayunmathur.appstore.ui +import android.graphics.drawable.Drawable+import androidx.compose.foundation.Image import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer@@ -10,13 +12,17 @@ import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.width import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.runtime.Composable+import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip+import androidx.compose.ui.graphics.asImageBitmap import androidx.compose.ui.layout.ContentScale+import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp+import androidx.core.graphics.drawable.toBitmap import coil.compose.AsyncImage import com.vayunmathur.appstore.data.AppSource import com.vayunmathur.appstore.data.UnifiedApp@@ -31,6 +37,7 @@ fun AppRow( app: UnifiedApp, isInstalled: Boolean, progress: Float?,+ installedIcon: Drawable? = null, onClick: () -> Unit ) { Card(@@ -40,12 +47,34 @@ fun AppRow( ) { Column(Modifier.padding(12.dp)) { Row(Modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically) {- AsyncImage(- model = app.iconUrl,- contentDescription = null,- modifier = Modifier.size(48.dp).clip(RoundedCornerShape(12.dp)),- contentScale = ContentScale.Crop- )+ // Use installed drawable if available, else remote icon via coil+ if (installedIcon != null) {+ val bitmap = remember(installedIcon) {+ try { installedIcon.toBitmap(width = 96, height = 96).asImageBitmap() } catch (_: Exception) { null }+ }+ if (bitmap != null) {+ Image(+ bitmap = bitmap,+ contentDescription = null,+ modifier = Modifier.size(48.dp).clip(RoundedCornerShape(12.dp)),+ contentScale = ContentScale.Crop+ )+ } else {+ AsyncImage(+ model = app.iconUrl,+ contentDescription = null,+ modifier = Modifier.size(48.dp).clip(RoundedCornerShape(12.dp)),+ contentScale = ContentScale.Crop+ )+ }+ } else {+ AsyncImage(+ model = app.iconUrl,+ contentDescription = null,+ modifier = Modifier.size(48.dp).clip(RoundedCornerShape(12.dp)),+ contentScale = ContentScale.Crop+ )+ } Spacer(Modifier.width(12.dp)) Column(Modifier.weight(1f)) { Row(verticalAlignment = Alignment.CenterVertically) {@@ -91,13 +120,11 @@ fun AppRow( fun SourceBadge(source: AppSource) { val label = when (source) { AppSource.FDROID -> "F-Droid"- AppSource.PLAYSTORE -> "Play"- AppSource.UNKNOWN -> "?"+ AppSource.PLAYSTORE -> "Play Store" } val color = when (source) { AppSource.FDROID -> MaterialTheme.colorScheme.primaryContainer AppSource.PLAYSTORE -> MaterialTheme.colorScheme.secondaryContainer- AppSource.UNKNOWN -> MaterialTheme.colorScheme.surface } Card(colors = CardDefaults.cardColors(containerColor = color)) { Text(label, style = MaterialTheme.typography.labelSmall, modifier = Modifier.padding(horizontal = 6.dp, vertical = 2.dp))
appstore/src/main/java/com/vayunmathur/appstore/ui/InstalledPage.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/ui/InstalledPage.kt b/appstore/src/main/java/com/vayunmathur/appstore/ui/InstalledPage.ktindex 8305dfe132..3a5865dcb2 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/ui/InstalledPage.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/ui/InstalledPage.kt@@ -3,23 +3,18 @@ package com.vayunmathur.appstore.ui import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.PaddingValues-import androidx.compose.foundation.layout.Row-import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxSize-import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding-import androidx.compose.foundation.layout.width import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue-import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp+import com.vayunmathur.appstore.data.AppSource import com.vayunmathur.appstore.data.UnifiedApp import com.vayunmathur.appstore.util.AppStoreViewModel-import com.vayunmathur.library.ui.Card import com.vayunmathur.library.ui.MaterialTheme import com.vayunmathur.library.ui.Text @@ -30,31 +25,43 @@ fun InstalledPage( ) { val installed by viewModel.installedApps.collectAsState() val cached by viewModel.cachedApps.collectAsState()- val favorites by viewModel.favorites.collectAsState()+ val icons by viewModel.installedIcons.collectAsState() - // Map installed to UnifiedApp for unified UI, using cached info when available val apps = installed.map { inst -> val cachedApp = cached.find { it.packageName == inst.packageName } UnifiedApp( packageName = inst.packageName,- source = com.vayunmathur.appstore.data.AppSource.UNKNOWN,+ source = if (cachedApp != null) AppSource.FDROID else AppSource.PLAYSTORE, name = inst.name,+ summary = cachedApp?.summary ?: inst.versionName ?: "",+ description = cachedApp?.description ?: "",+ iconUrl = cachedApp?.iconUrl,+ author = cachedApp?.author, versionName = inst.versionName, versionCode = inst.versionCode,- iconUrl = cachedApp?.iconUrl+ apkUrl = cachedApp?.apkUrl,+ repoUrl = cachedApp?.repoUrl ) } - LazyColumn(- modifier = Modifier.fillMaxSize(),- contentPadding = PaddingValues(12.dp),- verticalArrangement = Arrangement.spacedBy(8.dp)- ) {- item {- Text("${installed.size} installed apps", style = MaterialTheme.typography.labelMedium, modifier = Modifier.padding(4.dp))- }- items(apps, key = { it.packageName }) { app ->- AppRow(app = app, isInstalled = true, progress = null, onClick = { onAppClick(app) })+ Column(Modifier.fillMaxSize()) {+ LazyColumn(+ modifier = Modifier.fillMaxSize(),+ contentPadding = PaddingValues(top = 24.dp, start = 12.dp, end = 12.dp, bottom = 12.dp),+ verticalArrangement = Arrangement.spacedBy(8.dp)+ ) {+ item {+ Text("${installed.size} installed apps", style = MaterialTheme.typography.titleSmall, modifier = Modifier.padding(4.dp))+ }+ items(apps, key = { it.packageName }) { app ->+ AppRow(+ app = app,+ isInstalled = true,+ progress = null,+ installedIcon = icons[app.packageName],+ onClick = { onAppClick(app) }+ )+ } } } }@@ -64,17 +71,19 @@ fun UpdatesPage(viewModel: AppStoreViewModel, onAppClick: (UnifiedApp) -> Unit) val installed by viewModel.installedApps.collectAsState() val cached by viewModel.cachedApps.collectAsState() val progressMap by viewModel.downloadProgress.collectAsState()+ val icons by viewModel.installedIcons.collectAsState() val updates = cached.mapNotNull { cachedEntity -> val inst = installed.find { it.packageName == cachedEntity.packageName } ?: return@mapNotNull null if (cachedEntity.versionCode > inst.versionCode) {- com.vayunmathur.appstore.data.UnifiedApp(+ UnifiedApp( packageName = cachedEntity.packageName,- source = try { com.vayunmathur.appstore.data.AppSource.valueOf(cachedEntity.source) } catch (_: Exception) { com.vayunmathur.appstore.data.AppSource.FDROID },+ source = AppSource.FDROID, name = cachedEntity.name, summary = cachedEntity.summary, description = cachedEntity.description, iconUrl = cachedEntity.iconUrl,+ author = cachedEntity.author, versionName = cachedEntity.versionName, versionCode = cachedEntity.versionCode, sizeBytes = cachedEntity.sizeBytes,@@ -84,58 +93,29 @@ fun UpdatesPage(viewModel: AppStoreViewModel, onAppClick: (UnifiedApp) -> Unit) } else null } - LazyColumn(- modifier = Modifier.fillMaxSize(),- contentPadding = PaddingValues(12.dp),- verticalArrangement = Arrangement.spacedBy(8.dp)- ) {- if (updates.isEmpty()) {- item {- Text("All apps up to date", style = MaterialTheme.typography.bodyMedium, modifier = Modifier.padding(16.dp))- }- } else {- item {- Text("${updates.size} updates available", style = MaterialTheme.typography.labelMedium, modifier = Modifier.padding(4.dp))- }- items(updates, key = { it.packageName }) { app ->- AppRow(app = app, isInstalled = true, progress = progressMap[app.packageName], onClick = { onAppClick(app) })- }- }- }-}--@Composable-fun FavoritesPage(viewModel: AppStoreViewModel, onAppClick: (UnifiedApp) -> Unit) {- val favorites by viewModel.favorites.collectAsState()- val cached by viewModel.cachedApps.collectAsState()- val installed by viewModel.installedApps.collectAsState()-- val apps = favorites.mapNotNull { fav ->- cached.find { it.packageName == fav.packageName }?.let { c ->- com.vayunmathur.appstore.data.UnifiedApp(- packageName = c.packageName,- source = try { com.vayunmathur.appstore.data.AppSource.valueOf(c.source) } catch (_: Exception) { com.vayunmathur.appstore.data.AppSource.FDROID },- name = c.name,- summary = c.summary,- iconUrl = c.iconUrl,- versionName = c.versionName,- versionCode = c.versionCode,- apkUrl = c.apkUrl- )- }- }-- LazyColumn(- modifier = Modifier.fillMaxSize(),- contentPadding = PaddingValues(12.dp),- verticalArrangement = Arrangement.spacedBy(8.dp)- ) {- if (apps.isEmpty()) {- item { Text("No favorites yet", style = MaterialTheme.typography.bodyMedium, modifier = Modifier.padding(16.dp)) }- } else {- items(apps, key = { it.packageName }) { app ->- val isInstalled = installed.any { it.packageName == app.packageName }- AppRow(app = app, isInstalled = isInstalled, progress = null, onClick = { onAppClick(app) })+ Column(Modifier.fillMaxSize()) {+ LazyColumn(+ modifier = Modifier.fillMaxSize(),+ contentPadding = PaddingValues(top = 24.dp, start = 12.dp, end = 12.dp, bottom = 12.dp),+ verticalArrangement = Arrangement.spacedBy(8.dp)+ ) {+ if (updates.isEmpty()) {+ item {+ Text("All apps up to date", style = MaterialTheme.typography.bodyMedium, modifier = Modifier.padding(16.dp))+ }+ } else {+ item {+ Text("${updates.size} updates available", style = MaterialTheme.typography.titleSmall, modifier = Modifier.padding(4.dp))+ }+ items(updates, key = { it.packageName }) { app ->+ AppRow(+ app = app,+ isInstalled = true,+ progress = progressMap[app.packageName],+ installedIcon = icons[app.packageName],+ onClick = { onAppClick(app) }+ )+ } } } }
appstore/src/main/java/com/vayunmathur/appstore/ui/ReposPage.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/ui/ReposPage.kt b/appstore/src/main/java/com/vayunmathur/appstore/ui/ReposPage.ktindex b91459ffd2..26c7a5655a 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/ui/ReposPage.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/ui/ReposPage.kt@@ -35,6 +35,7 @@ import com.vayunmathur.library.ui.Switch import com.vayunmathur.library.ui.Text import com.vayunmathur.library.ui.TextButton import com.vayunmathur.library.ui.IconButton+import com.vayunmathur.library.ui.TopAppBar @Composable fun ReposPage(viewModel: AppStoreViewModel) {@@ -45,10 +46,9 @@ fun ReposPage(viewModel: AppStoreViewModel) { var newName by remember { mutableStateOf("") } Scaffold(+ topBar = { TopAppBar(title = { Text("Repositories") }) }, floatingActionButton = {- FloatingActionButton(onClick = { showAdd = true }) {- IconAdd()- }+ FloatingActionButton(onClick = { showAdd = true }) { IconAdd() } } ) { padding -> LazyColumn(@@ -60,7 +60,7 @@ fun ReposPage(viewModel: AppStoreViewModel) { Text("F-Droid Repositories", style = MaterialTheme.typography.titleMedium) Spacer(Modifier.height(4.dp)) Text(- "Add F-Droid compatible repos. Play Store listings are always enabled and searched live.",+ "Add F-Droid compatible repos. Apps available on F-Droid are marked F-Droid, others Play Store.", style = MaterialTheme.typography.bodySmall ) }@@ -86,9 +86,7 @@ fun ReposPage(viewModel: AppStoreViewModel) { } } Switch(checked = repo.enabled, onCheckedChange = { viewModel.toggleRepo(repo.url) })- IconButton(onClick = { viewModel.deleteRepo(repo.url) }) {- IconDelete()- }+ IconButton(onClick = { viewModel.deleteRepo(repo.url) }) { IconDelete() } } } }
appstore/src/main/java/com/vayunmathur/appstore/ui/SearchAndBrowsePage.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/ui/SearchAndBrowsePage.kt b/appstore/src/main/java/com/vayunmathur/appstore/ui/SearchAndBrowsePage.ktindex 5df8e078ae..bf01492059 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/ui/SearchAndBrowsePage.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/ui/SearchAndBrowsePage.kt@@ -27,7 +27,11 @@ import com.vayunmathur.library.ui.IconSearch import com.vayunmathur.library.ui.IconButton import com.vayunmathur.library.ui.MaterialTheme import com.vayunmathur.library.ui.OutlinedTextField+import com.vayunmathur.library.ui.Scaffold import com.vayunmathur.library.ui.Text+import com.vayunmathur.library.ui.TopAppBar+import com.vayunmathur.library.util.NavBackStack+import com.vayunmathur.appstore.Route @Composable fun SearchAndBrowsePage(@@ -40,60 +44,74 @@ fun SearchAndBrowsePage( val isSyncing by viewModel.isSyncing.collectAsState() val syncMsg by viewModel.syncMessage.collectAsState() val progressMap by viewModel.downloadProgress.collectAsState()+ val icons by viewModel.installedIcons.collectAsState() - Column(Modifier.fillMaxSize()) {- OutlinedTextField(- value = query,- onValueChange = { viewModel.setSearch(it) },- modifier = Modifier.fillMaxWidth().padding(12.dp),- placeholder = { Text("Search F-Droid & Play Store") },- leadingIcon = { IconSearch() },- trailingIcon = {- if (query.isNotBlank()) {- IconButton(onClick = { viewModel.setSearch("") }) {- IconClose()+ Scaffold(+ topBar = {+ TopAppBar(title = { Text("App Store") })+ }+ ) { padding ->+ Column(Modifier.fillMaxSize().padding(padding)) {+ OutlinedTextField(+ value = query,+ onValueChange = { viewModel.setSearch(it) },+ modifier = Modifier.fillMaxWidth().padding(horizontal = 12.dp, vertical = 8.dp),+ placeholder = { Text("Search F-Droid & Play Store") },+ leadingIcon = { IconSearch() },+ trailingIcon = {+ if (query.isNotBlank()) {+ IconButton(onClick = { viewModel.setSearch("") }) { IconClose() } }- }- },- singleLine = true- )+ },+ singleLine = true+ ) - if (syncMsg.isNotBlank()) {- Row(Modifier.fillMaxWidth().padding(horizontal = 16.dp, vertical = 4.dp), verticalAlignment = Alignment.CenterVertically) {- if (isSyncing) {- CircularProgressIndicator(Modifier.size(16.dp))- Spacer(Modifier.width(8.dp))+ if (syncMsg.isNotBlank()) {+ Row(+ Modifier.fillMaxWidth().padding(horizontal = 16.dp, vertical = 4.dp),+ verticalAlignment = Alignment.CenterVertically+ ) {+ if (isSyncing) {+ CircularProgressIndicator(Modifier.size(16.dp))+ Spacer(Modifier.width(8.dp))+ }+ Text(syncMsg, style = MaterialTheme.typography.labelSmall) }- Text(syncMsg, style = MaterialTheme.typography.labelSmall) }- } - LazyColumn(- modifier = Modifier.fillMaxSize(),- contentPadding = PaddingValues(12.dp),- verticalArrangement = Arrangement.spacedBy(8.dp)- ) {- if (apps.isEmpty() && query.isNotBlank()) {- item {- Box(Modifier.fillMaxWidth().padding(32.dp), contentAlignment = Alignment.Center) {- Text("No results for \"$query\"", style = MaterialTheme.typography.bodyMedium)+ LazyColumn(+ modifier = Modifier.fillMaxSize(),+ contentPadding = PaddingValues(12.dp),+ verticalArrangement = Arrangement.spacedBy(8.dp)+ ) {+ if (apps.isEmpty() && query.isNotBlank()) {+ item {+ Box(Modifier.fillMaxWidth().padding(32.dp), contentAlignment = Alignment.Center) {+ Text("No results for \"$query\"", style = MaterialTheme.typography.bodyMedium)+ } }- }- } else if (apps.isEmpty()) {- item {- Box(Modifier.fillMaxWidth().padding(32.dp), contentAlignment = Alignment.Center) {- Column(horizontalAlignment = Alignment.CenterHorizontally) {- Text("Welcome to App Store", style = MaterialTheme.typography.titleMedium)- Text("Combines F-Droid repos with Play Store listings", style = MaterialTheme.typography.bodySmall)- Text("Tap Sync in Repos to fetch F-Droid apps, or search for Play apps", style = MaterialTheme.typography.bodySmall)+ } else if (apps.isEmpty()) {+ item {+ Box(Modifier.fillMaxWidth().padding(32.dp), contentAlignment = Alignment.Center) {+ Column(horizontalAlignment = Alignment.CenterHorizontally) {+ Text("Welcome to App Store", style = MaterialTheme.typography.titleMedium)+ Text("Combines F-Droid repos with Play Store listings", style = MaterialTheme.typography.bodySmall)+ Text("Tap Sync in Repos to fetch F-Droid apps, or search for Play apps", style = MaterialTheme.typography.bodySmall)+ } } }- }- } else {- items(apps, key = { it.packageName + it.source.name }) { app ->- val isInstalled = installed.any { it.packageName == app.packageName }- val progress = progressMap[app.packageName]- AppRow(app = app, isInstalled = isInstalled, progress = progress, onClick = { onAppClick(app) })+ } else {+ items(apps, key = { it.packageName + it.source.name }) { app ->+ val isInstalled = installed.any { it.packageName == app.packageName }+ val progress = progressMap[app.packageName]+ AppRow(+ app = app,+ isInstalled = isInstalled,+ progress = progress,+ installedIcon = if (isInstalled) icons[app.packageName] else null,+ onClick = { onAppClick(app) }+ )+ } } } }
appstore/src/main/java/com/vayunmathur/appstore/util/AppStoreViewModel.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/util/AppStoreViewModel.kt b/appstore/src/main/java/com/vayunmathur/appstore/util/AppStoreViewModel.ktindex 0b73afcdd0..e626f13464 100644--- a/appstore/src/main/java/com/vayunmathur/appstore/util/AppStoreViewModel.kt+++ b/appstore/src/main/java/com/vayunmathur/appstore/util/AppStoreViewModel.kt@@ -4,6 +4,7 @@ import android.content.Context import android.content.Intent import android.content.pm.ApplicationInfo import android.content.pm.PackageManager+import android.graphics.drawable.Drawable import android.net.Uri import android.os.Build import androidx.core.content.FileProvider@@ -15,19 +16,16 @@ import com.vayunmathur.appstore.data.AppSource import com.vayunmathur.appstore.data.CachedAppEntity import com.vayunmathur.appstore.data.DefaultRepos import com.vayunmathur.appstore.data.FDroidRepository-import com.vayunmathur.appstore.data.FavoriteEntity import com.vayunmathur.appstore.data.InstalledInfo import com.vayunmathur.appstore.data.PlayStoreDataSource import com.vayunmathur.appstore.data.RepoEntity import com.vayunmathur.appstore.data.UnifiedApp-import com.vayunmathur.library.room.buildDatabase import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Job import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.combine-import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.launch import kotlinx.coroutines.withContext@@ -61,7 +59,10 @@ class AppStoreViewModel( private val _installedApps = MutableStateFlow<List<InstalledInfo>>(emptyList()) val installedApps: StateFlow<List<InstalledInfo>> = _installedApps - private val _activeRepo = MutableStateFlow<String?>(null) // filter+ private val _installedIcons = MutableStateFlow<Map<String, Drawable>>(emptyMap())+ val installedIcons: StateFlow<Map<String, Drawable>> = _installedIcons++ private val _activeRepo = MutableStateFlow<String?>(null) val repos = db.repoDao().allFlow() .stateIn(viewModelScope, SharingStarted.Eagerly, emptyList())@@ -69,29 +70,40 @@ class AppStoreViewModel( val cachedApps = db.cachedAppDao().allFlow() .stateIn(viewModelScope, SharingStarted.Eagerly, emptyList()) - val favorites = db.favoriteDao().allFlow()- .stateIn(viewModelScope, SharingStarted.Eagerly, emptyList())- val combinedBrowse: StateFlow<List<UnifiedApp>> = combine( cachedApps, _playSearchResults, _topCharts, _searchQuery, _activeRepo ) { cached, playSearch, topCharts, query, activeRepo ->- val fdroid = cached.map { it.toUnifiedApp() }- .let { list -> if (activeRepo != null) list.filter { it.repoUrl == activeRepo || activeRepo == "all" } else list }+ val fdroidAll = cached.map { it.toUnifiedApp() }+ val fdroid = if (activeRepo != null) fdroidAll.filter { it.repoUrl == activeRepo || activeRepo == "all" } else fdroidAll+ // Infer overlay: if package exists in any F-Droid repo, force FDROID source; otherwise PLAYSTORE+ val fdroidPkgs = fdroidAll.map { it.packageName }.toSet()+ val infPlaySearch = playSearch.map { it.copy(source = inferSource(it.packageName, fdroidPkgs)) }+ val infTop = topCharts.map { it.copy(source = inferSource(it.packageName, fdroidPkgs)) } if (query.isBlank()) {- // Browse mode: F-Droid cached + top Play charts- val all = fdroid + if (playSearch.isEmpty()) topCharts else playSearch+ val all = fdroid + (if (infPlaySearch.isEmpty()) infTop else infPlaySearch) all.distinctBy { it.packageName }.sortedBy { it.name.lowercase() } } else { val q = query.lowercase() val filteredFdroid = fdroid.filter { it.name.lowercase().contains(q) || it.packageName.lowercase().contains(q) || it.summary.lowercase().contains(q) }- val combined = (filteredFdroid + playSearch).distinctBy { it.packageName }+ val combined = (filteredFdroid + infPlaySearch).distinctBy { it.packageName }.map {+ it.copy(source = inferSource(it.packageName, fdroidPkgs))+ } combined.sortedBy { it.name.lowercase() } } }.stateIn(viewModelScope, SharingStarted.Eagerly, emptyList()) + private fun inferSource(pkg: String, fdroidPkgs: Set<String>): AppSource {+ return if (fdroidPkgs.contains(pkg)) AppSource.FDROID else AppSource.PLAYSTORE+ }++ fun inferSourceForInstalled(pkg: String): AppSource {+ val fdroidPkgs = cachedApps.value.map { it.packageName }.toSet()+ return inferSource(pkg, fdroidPkgs)+ }+ var searchJob: Job? = null var topJob: Job? = null @@ -130,7 +142,7 @@ class AppStoreViewModel( return } searchJob = viewModelScope.launch {- kotlinx.coroutines.delay(400) // debounce+ kotlinx.coroutines.delay(400) _syncMessage.value = "Searching Play Store..." val play = PlayStoreDataSource.search(q) _playSearchResults.value = play@@ -170,7 +182,10 @@ class AppStoreViewModel( fun refreshInstalled() { viewModelScope.launch(Dispatchers.IO) { val pm = context.packageManager- val installed = pm.getInstalledApplications(PackageManager.MATCH_ALL).mapNotNull { ai ->+ // Only user apps: exclude system partition apps+ val allApps = pm.getInstalledApplications(PackageManager.MATCH_ALL)+ val userApps = allApps.filter { (it.flags and ApplicationInfo.FLAG_SYSTEM) == 0 }+ val installed = userApps.mapNotNull { ai -> try { val pi = pm.getPackageInfo(ai.packageName, 0) InstalledInfo(@@ -178,21 +193,31 @@ class AppStoreViewModel( name = pm.getApplicationLabel(ai).toString(), versionName = pi.versionName, versionCode = if (Build.VERSION.SDK_INT >= 28) pi.longVersionCode else pi.versionCode.toLong(),- isSystem = (ai.flags and ApplicationInfo.FLAG_SYSTEM) != 0+ isSystem = false ) } catch (_: Exception) { null } }.sortedBy { it.name.lowercase() }++ val icons = userApps.mapNotNull { ai ->+ try { ai.packageName to pm.getApplicationIcon(ai.packageName) } catch (_: Exception) { null }+ }.toMap()+ _installedApps.value = installed+ _installedIcons.value = icons } } fun selectApp(app: UnifiedApp) {- _selectedApp.value = app- // If Play Store app with no details yet, fetch them- if (app.source == AppSource.PLAYSTORE && app.description.isBlank()) {+ // Re-infer source based on F-Droid cache at selection time too+ val fdroidPkgs = cachedApps.value.map { it.packageName }.toSet()+ val inferred = app.copy(source = inferSource(app.packageName, fdroidPkgs))+ _selectedApp.value = inferred+ if (inferred.source == AppSource.PLAYSTORE && inferred.description.isBlank()) { viewModelScope.launch {- val details = PlayStoreDataSource.appDetails(app.packageName)- if (details != null) _selectedApp.value = details+ val details = PlayStoreDataSource.appDetails(inferred.packageName)+ if (details != null) {+ _selectedApp.value = details.copy(source = inferSource(details.packageName, fdroidPkgs))+ } } } }@@ -212,20 +237,13 @@ class AppStoreViewModel( } fun openInBrowser(url: String) {+ if (url.isBlank()) return try { val i = Intent(Intent.ACTION_VIEW, Uri.parse(url)).apply { addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) } context.startActivity(i) } catch (_: Exception) { } } - fun toggleFavorite(pkg: String) {- viewModelScope.launch {- val isFav = db.favoriteDao().isFavFlow(pkg).first()- if (isFav) db.favoriteDao().deleteByPackage(pkg)- else db.favoriteDao().upsert(FavoriteEntity(pkg))- }- }- fun addRepo(url: String, name: String) { viewModelScope.launch { val cleanUrl = url.trim().trimEnd('/')@@ -248,11 +266,15 @@ class AppStoreViewModel( } fun downloadAndInstall(app: UnifiedApp) {- if (app.source == AppSource.PLAYSTORE) {+ // Inferred source decides: FDROID = direct APK, PLAYSTORE = market intent+ val fdroidPkgs = cachedApps.value.map { it.packageName }.toSet()+ val src = inferSource(app.packageName, fdroidPkgs)+ if (src == AppSource.PLAYSTORE) { openInPlayStore(app.packageName) return }- val apkUrl = app.apkUrl ?: return+ // Resolve APK from F-Droid cache if current listing lacks it+ val apkUrl = app.apkUrl ?: cachedApps.value.find { it.packageName == app.packageName }?.apkUrl ?: return viewModelScope.launch(Dispatchers.IO) { try { _downloadProgress.value = _downloadProgress.value + (app.packageName to 0.01f)@@ -277,9 +299,7 @@ class AppStoreViewModel( } } _downloadProgress.value = _downloadProgress.value - app.packageName- withContext(Dispatchers.Main) {- installApk(file)- }+ withContext(Dispatchers.Main) { installApk(file) } } catch (e: Exception) { _downloadProgress.value = _downloadProgress.value - app.packageName _syncMessage.value = "Download failed: ${e.message}"@@ -300,10 +320,6 @@ class AppStoreViewModel( } } - fun isAppInstalled(pkg: String): Boolean = _installedApps.value.any { it.packageName == pkg }-- fun getInstalledVersion(pkg: String): InstalledInfo? = _installedApps.value.find { it.packageName == pkg }- fun setActiveRepoFilter(repoUrl: String?) { _activeRepo.value = repoUrl }