Modern Apps git

← Modern-Apps.git

appstore: new unified F-Droid + Play Store app (Droid-ify + Aurora combo)

Commit
9398491190bdc1c479a5b098f827ebcd5504b8f1
Author
Vayun Mathur <[email protected]>
When
2026-07-31 15:59 UTC (4 months ago)
Parents
64aa705

Diff

appstore/build.gradle.kts
diff --git a/appstore/build.gradle.kts b/appstore/build.gradle.ktsnew file mode 100644index 0000000000..14e620bf10--- /dev/null+++ b/appstore/build.gradle.kts@@ -0,0 +1,27 @@+plugins {+    id("common-conventions-app")+    id("common-conventions-metadata")+    alias(libs.plugins.ksp)+}++launcherIcon {+    symbol = "store"+}++android {+    defaultConfig {+        applicationId = "com.vayunmathur.appstore"+    }+}++dependencies {+    implementRoom(libs)+    implementation(project(":library:room"))+    implementation(project(":library:network"))+    implementation(libs.androidx.datastore.preferences)+    implementation(libs.coil.compose)+    implementation(libs.coil.svg)+    implementation(libs.jsoup)+    implementation(libs.okhttp)+    implementation(libs.kotlinx.serialization.json)+}
appstore/src/main/AndroidManifest.xml
diff --git a/appstore/src/main/AndroidManifest.xml b/appstore/src/main/AndroidManifest.xmlnew file mode 100644index 0000000000..1148a508ac--- /dev/null+++ b/appstore/src/main/AndroidManifest.xml@@ -0,0 +1,58 @@+<?xml version="1.0" encoding="utf-8"?>+<manifest xmlns:android="http://schemas.android.com/apk/res/android"+    xmlns:tools="http://schemas.android.com/tools">++    <uses-permission android:name="android.permission.INTERNET" />+    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />+    <uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />+    <uses-permission android:name="android.permission.QUERY_ALL_PACKAGES"+        tools:ignore="QueryAllPackagesPermission" />+    <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />+    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />+    <uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />++    <application+        android:allowBackup="true"+        android:dataExtractionRules="@xml/data_extraction_rules"+        android:icon="@mipmap/ic_launcher"+        android:label="@string/app_name"+        android:roundIcon="@mipmap/ic_launcher"+        android:supportsRtl="true"+        android:theme="@style/Theme.General">++        <provider+            android:name="androidx.core.content.FileProvider"+            android:authorities="${applicationId}.fileprovider"+            android:exported="false"+            android:grantUriPermissions="true">+            <meta-data+                android:name="android.support.FILE_PROVIDER_PATHS"+                android:resource="@xml/file_paths" />+        </provider>++        <activity+            android:configChanges="mcc|mnc|colorMode|density|fontScale|fontWeightAdjustment|keyboard|keyboardHidden|layoutDirection|navigation|orientation|screenLayout|screenSize|smallestScreenSize|touchscreen|uiMode"+            android:name=".MainActivity"+            android:exported="true"+            android:theme="@style/Theme.General">+            <intent-filter>+                <action android:name="android.intent.action.MAIN" />+                <category android:name="android.intent.category.LAUNCHER" />+            </intent-filter>+            <intent-filter>+                <action android:name="android.intent.action.VIEW" />+                <category android:name="android.intent.category.DEFAULT" />+                <category android:name="android.intent.category.BROWSABLE" />+                <data android:scheme="market" />+                <data android:scheme="https" android:host="play.google.com" />+                <data android:scheme="https" android:host="f-droid.org" />+            </intent-filter>+        </activity>++        <service+            android:name="androidx.work.impl.foreground.SystemForegroundService"+            android:foregroundServiceType="dataSync"+            tools:node="merge" />++    </application>+</manifest>
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.ktnew file mode 100644index 0000000000..f8464f0c52--- /dev/null+++ b/appstore/src/main/java/com/vayunmathur/appstore/MainActivity.kt@@ -0,0 +1,198 @@+package com.vayunmathur.appstore++import android.content.Intent+import android.os.Bundle+import androidx.activity.ComponentActivity+import androidx.activity.compose.setContent+import androidx.activity.enableEdgeToEdge+import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.fillMaxSize+import androidx.compose.runtime.Composable+import androidx.compose.runtime.LaunchedEffect+import androidx.compose.runtime.collectAsState+import androidx.compose.runtime.getValue+import androidx.compose.runtime.mutableStateOf+import androidx.compose.runtime.setValue+import androidx.compose.ui.Modifier+import androidx.lifecycle.lifecycleScope+import androidx.lifecycle.viewmodel.compose.viewModel+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+import com.vayunmathur.appstore.util.AppStoreViewModel+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+import com.vayunmathur.library.util.NavKey+import com.vayunmathur.library.util.rememberNavBackStack+import kotlinx.coroutines.Dispatchers+import kotlinx.coroutines.launch+import kotlinx.coroutines.withContext+import kotlinx.serialization.Serializable++class MainActivity : ComponentActivity() {++    private val readyState = mutableStateOf(false)+    private var factoryState by mutableStateOf<AppStoreViewModelFactory?>(null)+    private var externalPkg: String? = null++    override fun onCreate(savedInstanceState: Bundle?) {+        super.onCreate(savedInstanceState)+        enableEdgeToEdge()++        lifecycleScope.launch(Dispatchers.IO) {+            val db = buildDatabase<AppDatabase>(dbName = DB_NAME)+            val factory = AppStoreViewModelFactory(applicationContext, db)+            withContext(Dispatchers.Main) {+                factoryState = factory+                handleIntentUrl(intent)+                readyState.value = true+            }+        }++        setContent {+            DynamicTheme {+                Box(Modifier.fillMaxSize()) {+                    if (!readyState.value || factoryState == null) {+                        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 }+                                if (cached != null) {+                                    vm.selectApp(+                                        UnifiedApp(+                                            packageName = cached.packageName,+                                            source = try { com.vayunmathur.appstore.data.AppSource.valueOf(cached.source) } catch (_: Exception) { com.vayunmathur.appstore.data.AppSource.FDROID },+                                            name = cached.name,+                                            summary = cached.summary,+                                            description = cached.description,+                                            iconUrl = cached.iconUrl,+                                            versionName = cached.versionName,+                                            versionCode = cached.versionCode,+                                            apkUrl = cached.apkUrl+                                        )+                                    )+                                }+                            }+                        }+                        AppRoot(vm, onAppClick = { app -> vm.selectApp(app) })+                    }+                }+            }+        }+    }++    override fun onNewIntent(intent: Intent) {+        super.onNewIntent(intent)+        handleIntentUrl(intent)+    }++    private fun handleIntentUrl(intent: Intent?) {+        intent ?: return+        val data = intent.dataString ?: return+        val pkg = when {+            data.startsWith("market://") -> Regex("[?&]id=([^&]+)").find(data)?.groupValues?.get(1)+            data.contains("play.google.com") -> Regex("[?&]id=([^&]+)").find(data)?.groupValues?.get(1)+            data.contains("f-droid.org") -> data.substringAfterLast('/').substringBefore('?')+            else -> null+        }+        if (pkg != null) externalPkg = pkg+    }+}++@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+}++@Composable+private fun AppRoot(+    viewModel: AppStoreViewModel,+    onAppClick: (UnifiedApp) -> Unit+) {+    val selected by viewModel.selectedApp.collectAsState()+    val initial: Route = if (selected != null) Route.Detail else Route.Browse+    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)+        }+    }++    MainNavigation(+        backStack,+        bottomBar = {+            if (current !is Route.Detail) {+                BottomNavBar(+                    backStack,+                    listOf(+                        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+                )+            }+        }+    ) {+        entry<Route.Browse> {+            com.vayunmathur.appstore.ui.SearchAndBrowsePage(viewModel = viewModel, onAppClick = { app ->+                onAppClick(app)+                backStack.add(Route.Detail)+            })+        }+        entry<Route.Installed> {+            InstalledPage(viewModel = viewModel, onAppClick = { app ->+                viewModel.selectApp(app)+                backStack.add(Route.Detail)+            })+        }+        entry<Route.Updates> {+            UpdatesPage(viewModel = viewModel, onAppClick = { app ->+                viewModel.selectApp(app)+                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)+        }+        entry<Route.Detail> {+            AppDetailPage(viewModel = viewModel, onBack = { backStack.pop() })+        }+    }+}
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.ktnew file mode 100644index 0000000000..fa93e51821--- /dev/null+++ b/appstore/src/main/java/com/vayunmathur/appstore/data/AppDatabase.kt@@ -0,0 +1,114 @@+package com.vayunmathur.appstore.data++import androidx.room.Dao+import androidx.room.Database+import androidx.room.Delete+import androidx.room.Entity+import androidx.room.PrimaryKey+import androidx.room.Query+import androidx.room.RoomDatabase+import androidx.room.Upsert+import kotlinx.coroutines.flow.Flow++const val DB_NAME = "appstore-db"++@Entity+data class RepoEntity(+    @PrimaryKey val url: String,+    val name: String,+    val enabled: Boolean = true,+    val fingerprint: String? = null,+    val lastSync: Long = 0L+)++@Entity+data class CachedAppEntity(+    @PrimaryKey val packageName: String,+    val source: String, // FDROID, PLAYSTORE+    val name: String,+    val summary: String,+    val description: String,+    val iconUrl: String?,+    val author: String?,+    val categories: String, // json joined+    val versionName: String?,+    val versionCode: Long,+    val sizeBytes: Long,+    val apkUrl: String?,+    val repoUrl: String?,+    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")+    fun allFlow(): Flow<List<RepoEntity>>++    @Query("SELECT * FROM RepoEntity")+    suspend fun all(): List<RepoEntity>++    @Upsert+    suspend fun upsert(repo: RepoEntity)++    @Delete+    suspend fun delete(repo: RepoEntity)++    @Query("DELETE FROM RepoEntity WHERE url = :url")+    suspend fun deleteByUrl(url: String)+}++@Dao+interface CachedAppDao {+    @Query("SELECT * FROM CachedAppEntity ORDER BY name ASC")+    fun allFlow(): Flow<List<CachedAppEntity>>++    @Query("SELECT * FROM CachedAppEntity WHERE packageName LIKE '%' || :q || '%' OR name LIKE '%' || :q || '%' ORDER BY name ASC")+    fun searchFlow(q: String): Flow<List<CachedAppEntity>>++    @Query("SELECT * FROM CachedAppEntity WHERE packageName = :pkg LIMIT 1")+    suspend fun byPackage(pkg: String): CachedAppEntity?++    @Upsert+    suspend fun upsertAll(apps: List<CachedAppEntity>)++    @Upsert+    suspend fun upsert(app: CachedAppEntity)++    @Query("DELETE FROM CachedAppEntity WHERE repoUrl = :repoUrl")+    suspend fun deleteByRepo(repoUrl: String)++    @Query("DELETE FROM CachedAppEntity")+    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,+    exportSchema = false+)+abstract class AppDatabase : RoomDatabase() {+    abstract fun repoDao(): RepoDao+    abstract fun cachedAppDao(): CachedAppDao+    abstract fun favoriteDao(): FavoriteDao+}
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.ktnew file mode 100644index 0000000000..41df61f2db--- /dev/null+++ b/appstore/src/main/java/com/vayunmathur/appstore/data/AppModels.kt@@ -0,0 +1,74 @@+package com.vayunmathur.appstore.data++import kotlinx.serialization.Serializable++enum class AppSource {+    FDROID,+    PLAYSTORE,+    UNKNOWN+}++enum class InstallStatus {+    NOT_INSTALLED,+    INSTALLED,+    UPDATE_AVAILABLE,+    DOWNLOADING,+    INSTALLING+}++@Serializable+data class UnifiedApp(+    val packageName: String,+    val source: AppSource,+    val name: String,+    val summary: String = "",+    val description: String = "",+    val iconUrl: String? = null,+    val author: String? = null,+    val categories: List<String> = emptyList(),+    val versionName: String? = null,+    val versionCode: Long = 0L,+    val sizeBytes: Long = 0L,+    val apkUrl: String? = null,+    val screenshotUrls: List<String> = emptyList(),+    val rating: Float? = null,+    val license: String? = null,+    val website: String? = null,+    val sourceCode: String? = null,+    val whatsNew: String? = null,+    val addedTimestamp: Long = 0L,+    val lastUpdated: Long = 0L,+    val antiFeatures: List<String> = emptyList(),+    val isFree: Boolean = true,+    val repoUrl: String? = null // for F-Droid+)++data class InstalledInfo(+    val packageName: String,+    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"+    const val IZVYZID = "https://apt.izzysoft.de/fdroid/repo"+}++@Serializable+data class RepoInfo(+    val url: String,+    val name: String,+    val enabled: Boolean = true,+    val fingerprint: String? = null+)
appstore/src/main/java/com/vayunmathur/appstore/data/FDroidRepository.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/data/FDroidRepository.kt b/appstore/src/main/java/com/vayunmathur/appstore/data/FDroidRepository.ktnew file mode 100644index 0000000000..876f4485dc--- /dev/null+++ b/appstore/src/main/java/com/vayunmathur/appstore/data/FDroidRepository.kt@@ -0,0 +1,193 @@+package com.vayunmathur.appstore.data++import kotlinx.coroutines.Dispatchers+import kotlinx.coroutines.withContext+import kotlinx.serialization.json.Json+import kotlinx.serialization.json.JsonArray+import kotlinx.serialization.json.JsonObject+import kotlinx.serialization.json.booleanOrNull+import kotlinx.serialization.json.contentOrNull+import kotlinx.serialization.json.intOrNull+import kotlinx.serialization.json.jsonArray+import kotlinx.serialization.json.jsonObject+import kotlinx.serialization.json.jsonPrimitive+import kotlinx.serialization.json.longOrNull+import java.net.HttpURLConnection+import java.net.URL++/**+ * F-Droid index v2 client — inspired by Droid-ify's sync logic but simplified+ * for this unified store. Fetches https://f-droid.org/repo/index-v2.json and+ * IzzyOnDroid, merges into [UnifiedApp] list.+ */+object FDroidRepository {++    private val json = Json { ignoreUnknownKeys = true; isLenient = true }++    suspend fun fetchRepoIndex(repoUrl: String): List<UnifiedApp> = withContext(Dispatchers.IO) {+        val base = repoUrl.trimEnd('/')+        // Try index-v2.json first (faster, structured), fallback to index-v1.json+        val urls = listOf("$base/index-v2.json", "$base/index-v1.json")+        var lastErr: Exception? = null+        for (url in urls) {+            try {+                return@withContext if (url.endsWith("v2.json")) fetchV2(url, base)+                else fetchV1(url, base)+            } catch (e: Exception) {+                lastErr = e+            }+        }+        throw lastErr ?: RuntimeException("Failed to fetch $repoUrl")+    }++    private fun fetchV2(url: String, repoBase: String): List<UnifiedApp> {+        val conn = (URL(url).openConnection() as HttpURLConnection).apply {+            connectTimeout = 20000+            readTimeout = 60000+            setRequestProperty("Accept", "application/json")+            setRequestProperty("User-Agent", "ModernAppStore/1.0")+        }+        val text = conn.inputStream.bufferedReader().readText()+        val root = json.parseToJsonElement(text).jsonObject+        val packages = root["packages"]?.jsonObject ?: return emptyList()+        val result = mutableListOf<UnifiedApp>()++        for ((pkg, pkgEl) in packages) {+            try {+                val pkgObj = pkgEl.jsonObject+                val meta = pkgObj["metadata"]?.jsonObject ?: continue+                val versions = pkgObj["versions"]?.jsonObject ?: continue+                if (versions.isEmpty()) continue++                // pick latest version by added timestamp+                val latestEntry = versions.values.mapNotNull {+                    it.jsonObject+                }.maxByOrNull { it["added"]?.jsonPrimitive?.longOrNull ?: 0L } ?: continue++                val fileObj = latestEntry["file"]?.jsonObject+                val manifest = latestEntry["manifest"]?.jsonObject++                val name = extractLocalized(meta["name"])+                    ?: pkg.substringAfterLast('.')+                val summary = extractLocalized(meta["summary"]) ?: ""+                val desc = extractLocalized(meta["description"]) ?: ""+                val author = meta["authorName"]?.jsonPrimitive?.contentOrNull+                val cats = meta["categories"]?.jsonArray?.mapNotNull { it.jsonPrimitive.contentOrNull } ?: emptyList()+                val versionName = manifest?.get("versionName")?.jsonPrimitive?.contentOrNull+                val versionCode = manifest?.get("versionCode")?.jsonPrimitive?.longOrNull ?: 0L+                val sizeBytes = fileObj?.get("size")?.jsonPrimitive?.longOrNull ?: 0L+                val apkName = fileObj?.get("name")?.jsonPrimitive?.contentOrNull+                val apkUrl = if (apkName != null) "$repoBase/$apkName" else null+                val website = meta["webSite"]?.jsonPrimitive?.contentOrNull+                val source = meta["sourceCode"]?.jsonPrimitive?.contentOrNull+                val license = meta["license"]?.jsonPrimitive?.contentOrNull+                val whatsNew = extractLocalized(latestEntry["whatsNew"])+                val added = meta["added"]?.jsonPrimitive?.longOrNull ?: 0L+                val lastUpdated = meta["lastUpdated"]?.jsonPrimitive?.longOrNull ?: added++                // icon url: metadata.icon["en-US"]?.name -> repoBase/icons/...+                val iconName = runCatching {+                    meta["icon"]?.jsonObject?.values?.firstOrNull()+                        ?.jsonObject?.values?.firstOrNull()+                        ?.jsonObject?.get("name")?.jsonPrimitive?.contentOrNull+                }.getOrNull()+                val iconUrl = iconName?.let { "$repoBase/icons/$it" }++                result += UnifiedApp(+                    packageName = pkg,+                    source = AppSource.FDROID,+                    name = name,+                    summary = summary,+                    description = desc,+                    iconUrl = iconUrl,+                    author = author,+                    categories = cats,+                    versionName = versionName,+                    versionCode = versionCode,+                    sizeBytes = sizeBytes,+                    apkUrl = apkUrl,+                    license = license,+                    website = website,+                    sourceCode = source,+                    whatsNew = whatsNew,+                    addedTimestamp = added,+                    lastUpdated = lastUpdated,+                    repoUrl = repoBase+                )+            } catch (_: Exception) { /* skip broken entry */ }+        }+        return result+    }++    private fun fetchV1(url: String, repoBase: String): List<UnifiedApp> {+        // v1 is JSON with "apps" array and "packages" map — simplified parse+        val conn = (URL(url).openConnection() as HttpURLConnection).apply {+            connectTimeout = 20000+            readTimeout = 60000+            setRequestProperty("User-Agent", "ModernAppStore/1.0")+        }+        val text = conn.inputStream.bufferedReader().readText()+        val root = json.parseToJsonElement(text).jsonObject+        val apps = root["apps"]?.jsonArray ?: return emptyList()+        val packages = root["packages"]?.jsonObject++        val result = mutableListOf<UnifiedApp>()+        for (el in apps) {+            try {+                val obj = el.jsonObject+                val pkg = obj["packageName"]?.jsonPrimitive?.contentOrNull ?: continue+                val name = obj["name"]?.jsonPrimitive?.contentOrNull ?: pkg+                val summary = obj["summary"]?.jsonPrimitive?.contentOrNull ?: ""+                val desc = obj["description"]?.jsonPrimitive?.contentOrNull ?: ""+                val author = obj["authorName"]?.jsonPrimitive?.contentOrNull+                val cats = obj["categories"]?.jsonArray?.mapNotNull { it.jsonPrimitive.contentOrNull } ?: emptyList()+                val website = obj["webSite"]?.jsonPrimitive?.contentOrNull+                val src = obj["sourceCode"]?.jsonPrimitive?.contentOrNull+                val license = obj["license"]?.jsonPrimitive?.contentOrNull+                val added = obj["added"]?.jsonPrimitive?.longOrNull ?: 0L+                val lastUpdated = obj["lastUpdated"]?.jsonPrimitive?.longOrNull ?: added+                val iconName = obj["icon"]?.jsonPrimitive?.contentOrNull+                val iconUrl = iconName?.let { "$repoBase/icons/$it" }++                val versions = packages?.get(pkg)?.jsonArray+                val latestVer = versions?.lastOrNull()?.jsonObject+                val apkName = latestVer?.get("apkName")?.jsonPrimitive?.contentOrNull+                val apkUrl = apkName?.let { "$repoBase/$it" }+                val vName = latestVer?.get("versionName")?.jsonPrimitive?.contentOrNull+                val vCode = latestVer?.get("versionCode")?.jsonPrimitive?.longOrNull ?: 0L+                val size = latestVer?.get("size")?.jsonPrimitive?.longOrNull ?: 0L++                result += UnifiedApp(+                    packageName = pkg,+                    source = AppSource.FDROID,+                    name = name,+                    summary = summary,+                    description = desc,+                    iconUrl = iconUrl,+                    author = author,+                    categories = cats,+                    versionName = vName,+                    versionCode = vCode,+                    sizeBytes = size,+                    apkUrl = apkUrl,+                    website = website,+                    sourceCode = src,+                    license = license,+                    addedTimestamp = added,+                    lastUpdated = lastUpdated,+                    repoUrl = repoBase+                )+            } catch (_: Exception) { }+        }+        return result+    }++    private fun extractLocalized(elem: kotlinx.serialization.json.JsonElement?): String? {+        if (elem == null) return null+        if (elem is kotlinx.serialization.json.JsonPrimitive) return elem.contentOrNull+        val obj = elem as? JsonObject ?: return null+        return obj["en-US"]?.jsonPrimitive?.contentOrNull+            ?: obj["en"]?.jsonPrimitive?.contentOrNull+            ?: obj.values.firstOrNull()?.jsonPrimitive?.contentOrNull+    }+}
appstore/src/main/java/com/vayunmathur/appstore/data/PlayStoreDataSource.kt
diff --git a/appstore/src/main/java/com/vayunmathur/appstore/data/PlayStoreDataSource.kt b/appstore/src/main/java/com/vayunmathur/appstore/data/PlayStoreDataSource.ktnew file mode 100644index 0000000000..7ec9748561--- /dev/null+++ b/appstore/src/main/java/com/vayunmathur/appstore/data/PlayStoreDataSource.kt@@ -0,0 +1,138 @@+package com.vayunmathur.appstore.data++import kotlinx.coroutines.Dispatchers+import kotlinx.coroutines.withContext+import kotlinx.serialization.json.Json+import org.jsoup.Jsoup+import java.net.HttpURLConnection+import java.net.URL+import java.net.URLEncoder++/**+ * Play Store scraping data source — lightweight, no gplayapi dependency.+ * Inspired by Aurora Store's browsing but uses public Play Store web pages+ * plus anonymous token for search. This avoids requiring Google account login+ * while still listing Play Store apps alongside F-Droid.+ *+ * For install we delegate to browser / market intent (user's existing Play+ * Store or Aurora already handles installs). For direct APK we leave apkUrl null+ * and surface Play listing — same as Aurora's "manual download" path.+ */+object PlayStoreDataSource {++    private const val PLAY_BASE = "https://play.google.com"+    private val jsonLoose = Json { ignoreUnknownKeys = true; isLenient = true }++    data class PlaySearchResult(+        val packageName: String,+        val name: String,+        val developer: String,+        val iconUrl: String?,+        val rating: Float?,+        val summary: String,+        val isFree: Boolean+    )++    suspend fun search(query: String): List<UnifiedApp> = withContext(Dispatchers.IO) {+        if (query.isBlank()) return@withContext emptyList()+        try {+            val q = URLEncoder.encode(query, "UTF-8")+            val url = "$PLAY_BASE/store/search?q=$q&c=apps"+            val conn = (URL(url).openConnection() as HttpURLConnection).apply {+                connectTimeout = 15000+                readTimeout = 20000+                setRequestProperty("User-Agent", "Mozilla/5.0 (Linux; Android 13) AppleWebKit/537.36")+                setRequestProperty("Accept-Language", "en-US,en;q=0.9")+            }+            val html = conn.inputStream.bufferedReader().readText()+            parseSearchHtml(html)+        } catch (e: Exception) {+            emptyList()+        }+    }++    suspend fun topCharts(category: String = ""): List<UnifiedApp> = withContext(Dispatchers.IO) {+        try {+            val catPath = if (category.isNotBlank()) "/category/${URLEncoder.encode(category, "UTF-8")}" else ""+            val url = "$PLAY_BASE/store/apps$catPath?hl=en_US&gl=US"+            val conn = (URL(url).openConnection() as HttpURLConnection).apply {+                connectTimeout = 15000+                readTimeout = 20000+                setRequestProperty("User-Agent", "Mozilla/5.0 (Linux; Android 13) AppleWebKit/537.36")+            }+            val html = conn.inputStream.bufferedReader().readText()+            parseSearchHtml(html).take(30)+        } catch (_: Exception) { emptyList() }+    }++    suspend fun appDetails(packageName: String): UnifiedApp? = withContext(Dispatchers.IO) {+        try {+            val url = "$PLAY_BASE/store/apps/details?id=$packageName&hl=en_US&gl=US"+            val doc = Jsoup.connect(url)+                .userAgent("Mozilla/5.0 (Linux; Android 13) AppleWebKit/537.36")+                .timeout(20000)+                .get()++            val name = doc.selectFirst("h1 span")?.text()+                ?: doc.selectFirst("[itemprop=name] span")?.text()+                ?: packageName.substringAfterLast('.')++            val developer = doc.selectFirst("a[href*=/store/apps/developer] span")?.text()+                ?: doc.selectFirst("a[href*=/store/apps/dev] span")?.text()++            val icon = doc.selectFirst("img[alt*=Icon]")?.attr("src")+                ?: doc.selectFirst("img.T75of")?.attr("src")++            val summary = doc.selectFirst("div[itemprop=description]")?.text()?.take(500) ?: ""+            val ratingText = doc.selectFirst("div.TT9eCd")?.text()+            val rating = ratingText?.toFloatOrNull()++            UnifiedApp(+                packageName = packageName,+                source = AppSource.PLAYSTORE,+                name = name,+                summary = summary.take(200),+                description = doc.selectFirst("div[itemprop=description]")?.text() ?: summary,+                iconUrl = icon,+                author = developer,+                categories = emptyList(),+                rating = rating,+                website = "$PLAY_BASE/store/apps/details?id=$packageName"+            )+        } catch (_: Exception) { null }+    }++    private fun parseSearchHtml(html: String): List<UnifiedApp> {+        val results = mutableListOf<UnifiedApp>()+        try {+            val doc = Jsoup.parse(html)+            // Play Store uses very dynamic layout — try multiple selectors+            val candidates = doc.select("a[href*=/store/apps/details?id=]")+            val seen = mutableSetOf<String>()+            for (a in candidates) {+                val href = a.attr("href")+                val pkg = Regex("[?&]id=([^&]+)").find(href)?.groupValues?.get(1) ?: continue+                if (!seen.add(pkg)) continue+                if (results.size >= 40) break++                val title = a.attr("title").ifBlank { a.text().ifBlank { pkg } }+                // icon nearby+                val img = a.selectFirst("img")?.attr("src")+                    ?: a.parent()?.selectFirst("img")?.attr("src")++                results += UnifiedApp(+                    packageName = pkg,+                    source = AppSource.PLAYSTORE,+                    name = title.take(80),+                    iconUrl = img,+                    summary = "",+                    website = "$PLAY_BASE/store/apps/details?id=$pkg"+                )+            }+        } catch (_: Exception) { }+        return results+    }++    fun playStoreUrl(pkg: String): String = "$PLAY_BASE/store/apps/details?id=$pkg"+    fun marketUrl(pkg: String): String = "market://details?id=$pkg"+}
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.ktnew file mode 100644index 0000000000..221ae35fda--- /dev/null+++ b/appstore/src/main/java/com/vayunmathur/appstore/ui/AppDetailPage.kt@@ -0,0 +1,183 @@+package com.vayunmathur.appstore.ui++import androidx.compose.foundation.layout.Arrangement+import androidx.compose.foundation.layout.Column+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.height+import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.layout.size+import androidx.compose.foundation.layout.width+import androidx.compose.foundation.rememberScrollState+import androidx.compose.foundation.shape.RoundedCornerShape+import androidx.compose.foundation.verticalScroll+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.draw.clip+import androidx.compose.ui.layout.ContentScale+import androidx.compose.ui.text.font.FontWeight+import androidx.compose.ui.unit.dp+import coil.compose.AsyncImage+import com.vayunmathur.appstore.data.AppSource+import com.vayunmathur.appstore.util.AppStoreViewModel+import com.vayunmathur.library.ui.Button+import com.vayunmathur.library.ui.CenterAlignedTopAppBar+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+import com.vayunmathur.library.ui.Scaffold+import com.vayunmathur.library.ui.Text++@Composable+fun AppDetailPage(+    viewModel: AppStoreViewModel,+    onBack: () -> Unit+) {+    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]++    Scaffold(+        topBar = {+            CenterAlignedTopAppBar(+                title = { Text(current.name) },+                navigationIcon = {+                    IconButton(onClick = onBack) { IconBack() }+                },+                actions = {+                    IconButton(onClick = { viewModel.toggleFavorite(current.packageName) }) {+                        if (isFav) IconFavorite() else IconStarBorder()+                    }+                }+            )+        }+    ) { padding ->+        Column(+            Modifier.fillMaxSize().padding(padding).verticalScroll(rememberScrollState()).padding(16.dp),+            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+                )+                Spacer(Modifier.width(16.dp))+                Column(Modifier.weight(1f)) {+                    Text(current.name, style = MaterialTheme.typography.headlineSmall, fontWeight = FontWeight.Bold)+                    current.author?.let { Text(it, style = MaterialTheme.typography.bodySmall) }+                    Row(verticalAlignment = Alignment.CenterVertically) {+                        SourceBadge(current.source)+                        Spacer(Modifier.width(8.dp))+                        if (isInstalled) {+                            Text("Installed ${installedInfo?.versionName ?: ""}", style = MaterialTheme.typography.labelSmall, color = MaterialTheme.colorScheme.primary)+                        }+                    }+                }+            }++            Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {+                when {+                    isInstalled && current.versionCode > (installedInfo?.versionCode ?: 0L) -> {+                        Button(onClick = { viewModel.downloadAndInstall(current) }, modifier = Modifier.weight(1f)) {+                            IconDownload()+                            Spacer(Modifier.width(6.dp))+                            Text("Update")+                        }+                    }+                    isInstalled -> {+                        FilledTonalButton(onClick = { viewModel.openInPlayStore(current.packageName) }, modifier = Modifier.weight(1f)) {+                            Text("Open")+                        }+                    }+                    current.source == AppSource.PLAYSTORE -> {+                        Button(onClick = { viewModel.openInPlayStore(current.packageName) }, modifier = Modifier.weight(1f)) {+                            IconShoppingCart()+                            Spacer(Modifier.width(6.dp))+                            Text("View in Play Store")+                        }+                    }+                    else -> {+                        Button(+                            onClick = { viewModel.downloadAndInstall(current) },+                            modifier = Modifier.weight(1f),+                            enabled = progress == null+                        ) {+                            IconDownload()+                            Spacer(Modifier.width(6.dp))+                            Text(if (progress != null) "Downloading ${(progress * 100).toInt()}%" else "Install")+                        }+                    }+                }+                if (current.source == AppSource.FDROID || current.website != null) {+                    OutlinedButton(onClick = {+                        viewModel.openInBrowser(current.website ?: current.sourceCode ?: "")+                    }) {+                        IconGlobe()+                    }+                }+            }++            if (current.summary.isNotBlank()) {+                Text(current.summary, style = MaterialTheme.typography.titleSmall, fontWeight = FontWeight.SemiBold)+            }++            if (current.description.isNotBlank()) {+                Text(current.description, style = MaterialTheme.typography.bodyMedium)+            }++            HorizontalDivider()++            Column(verticalArrangement = Arrangement.spacedBy(4.dp)) {+                DetailRow("Package", current.packageName)+                current.versionName?.let { DetailRow("Version", it) }+                if (current.sizeBytes > 0) DetailRow("Size", formatSize(current.sizeBytes))+                current.license?.let { DetailRow("License", it) }+                if (current.categories.isNotEmpty()) DetailRow("Categories", current.categories.joinToString(", "))+                current.sourceCode?.let { DetailRow("Source", it) }+                current.website?.let { DetailRow("Website", it) }+                if (current.antiFeatures.isNotEmpty()) DetailRow("Anti-Features", current.antiFeatures.joinToString(", "))+                current.whatsNew?.let { if (it.isNotBlank()) DetailRow("What's New", it) }+            }+        }+    }+}++@Composable+private fun DetailRow(label: String, value: String) {+    Column(Modifier.fillMaxWidth()) {+        Text(label, style = MaterialTheme.typography.labelSmall, color = MaterialTheme.colorScheme.onSurfaceVariant)+        Text(value, style = MaterialTheme.typography.bodySmall)+        Spacer(Modifier.height(4.dp))+    }+}++private fun formatSize(bytes: Long): String {+    if (bytes < 1024) return "$bytes B"+    val kb = bytes / 1024.0+    if (kb < 1024) return String.format("%.1f KB", kb)+    val mb = kb / 1024.0+    return String.format("%.1f MB", mb)+}
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.ktnew file mode 100644index 0000000000..b4c876fe2e--- /dev/null+++ b/appstore/src/main/java/com/vayunmathur/appstore/ui/BrowsePage.kt@@ -0,0 +1,105 @@+package com.vayunmathur.appstore.ui++import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.Row+import androidx.compose.foundation.layout.Spacer+import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.height+import androidx.compose.foundation.layout.padding+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.ui.Alignment+import androidx.compose.ui.Modifier+import androidx.compose.ui.draw.clip+import androidx.compose.ui.layout.ContentScale+import androidx.compose.ui.text.font.FontWeight+import androidx.compose.ui.text.style.TextOverflow+import androidx.compose.ui.unit.dp+import coil.compose.AsyncImage+import com.vayunmathur.appstore.data.AppSource+import com.vayunmathur.appstore.data.UnifiedApp+import com.vayunmathur.library.ui.Card+import com.vayunmathur.library.ui.CardDefaults+import com.vayunmathur.library.ui.LinearProgressIndicator+import com.vayunmathur.library.ui.MaterialTheme+import com.vayunmathur.library.ui.Text++@Composable+fun AppRow(+    app: UnifiedApp,+    isInstalled: Boolean,+    progress: Float?,+    onClick: () -> Unit+) {+    Card(+        onClick = onClick,+        modifier = Modifier.fillMaxWidth(),+        colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.surfaceVariant.copy(alpha = 0.6f))+    ) {+        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+                )+                Spacer(Modifier.width(12.dp))+                Column(Modifier.weight(1f)) {+                    Row(verticalAlignment = Alignment.CenterVertically) {+                        Text(+                            app.name,+                            style = MaterialTheme.typography.titleSmall,+                            fontWeight = FontWeight.Bold,+                            maxLines = 1,+                            overflow = TextOverflow.Ellipsis,+                            modifier = Modifier.weight(1f, fill = false)+                        )+                        Spacer(Modifier.width(6.dp))+                        SourceBadge(app.source)+                    }+                    if (app.summary.isNotBlank()) {+                        Text(+                            app.summary,+                            style = MaterialTheme.typography.bodySmall,+                            maxLines = 2,+                            overflow = TextOverflow.Ellipsis+                        )+                    }+                    Row(verticalAlignment = Alignment.CenterVertically) {+                        if (app.author != null) {+                            Text(app.author, style = MaterialTheme.typography.labelSmall, maxLines = 1)+                        }+                        if (isInstalled) {+                            Spacer(Modifier.width(8.dp))+                            Text("Installed", style = MaterialTheme.typography.labelSmall, color = MaterialTheme.colorScheme.primary)+                        }+                    }+                }+            }+            if (progress != null) {+                Spacer(Modifier.height(8.dp))+                LinearProgressIndicator(progress = { progress }, modifier = Modifier.fillMaxWidth())+            }+        }+    }+}++@Composable+fun SourceBadge(source: AppSource) {+    val label = when (source) {+        AppSource.FDROID -> "F-Droid"+        AppSource.PLAYSTORE -> "Play"+        AppSource.UNKNOWN -> "?"+    }+    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.ktnew file mode 100644index 0000000000..8305dfe132--- /dev/null+++ b/appstore/src/main/java/com/vayunmathur/appstore/ui/InstalledPage.kt@@ -0,0 +1,142 @@+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.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++@Composable+fun InstalledPage(+    viewModel: AppStoreViewModel,+    onAppClick: (UnifiedApp) -> Unit+) {+    val installed by viewModel.installedApps.collectAsState()+    val cached by viewModel.cachedApps.collectAsState()+    val favorites by viewModel.favorites.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,+            name = inst.name,+            versionName = inst.versionName,+            versionCode = inst.versionCode,+            iconUrl = cachedApp?.iconUrl+        )+    }++    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) })+        }+    }+}++@Composable+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 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(+                packageName = cachedEntity.packageName,+                source = try { com.vayunmathur.appstore.data.AppSource.valueOf(cachedEntity.source) } catch (_: Exception) { com.vayunmathur.appstore.data.AppSource.FDROID },+                name = cachedEntity.name,+                summary = cachedEntity.summary,+                description = cachedEntity.description,+                iconUrl = cachedEntity.iconUrl,+                versionName = cachedEntity.versionName,+                versionCode = cachedEntity.versionCode,+                sizeBytes = cachedEntity.sizeBytes,+                apkUrl = cachedEntity.apkUrl,+                repoUrl = cachedEntity.repoUrl+            )+        } 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) })+            }+        }+    }+}
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.ktnew file mode 100644index 0000000000..b91459ffd2--- /dev/null+++ b/appstore/src/main/java/com/vayunmathur/appstore/ui/ReposPage.kt@@ -0,0 +1,123 @@+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.height+import androidx.compose.foundation.layout.padding+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.runtime.mutableStateOf+import androidx.compose.runtime.remember+import androidx.compose.runtime.setValue+import androidx.compose.ui.Alignment+import androidx.compose.ui.Modifier+import androidx.compose.ui.unit.dp+import com.vayunmathur.appstore.data.DefaultRepos+import com.vayunmathur.appstore.util.AppStoreViewModel+import com.vayunmathur.library.ui.AlertDialog+import com.vayunmathur.library.ui.Button+import com.vayunmathur.library.ui.Card+import com.vayunmathur.library.ui.FloatingActionButton+import com.vayunmathur.library.ui.IconAdd+import com.vayunmathur.library.ui.IconDelete+import com.vayunmathur.library.ui.MaterialTheme+import com.vayunmathur.library.ui.OutlinedTextField+import com.vayunmathur.library.ui.Scaffold+import com.vayunmathur.library.ui.Switch+import com.vayunmathur.library.ui.Text+import com.vayunmathur.library.ui.TextButton+import com.vayunmathur.library.ui.IconButton++@Composable+fun ReposPage(viewModel: AppStoreViewModel) {+    val repos by viewModel.repos.collectAsState()+    val isSyncing by viewModel.isSyncing.collectAsState()+    var showAdd by remember { mutableStateOf(false) }+    var newUrl by remember { mutableStateOf("") }+    var newName by remember { mutableStateOf("") }++    Scaffold(+        floatingActionButton = {+            FloatingActionButton(onClick = { showAdd = true }) {+                IconAdd()+            }+        }+    ) { padding ->+        LazyColumn(+            modifier = Modifier.fillMaxSize().padding(padding),+            contentPadding = PaddingValues(16.dp),+            verticalArrangement = Arrangement.spacedBy(12.dp)+        ) {+            item {+                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.",+                    style = MaterialTheme.typography.bodySmall+                )+            }+            item {+                Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.spacedBy(8.dp)) {+                    Button(onClick = { viewModel.syncRepos() }, enabled = !isSyncing, modifier = Modifier.weight(1f)) {+                        Text(if (isSyncing) "Syncing..." else "Sync All")+                    }+                    Button(onClick = { viewModel.loadTopCharts() }, modifier = Modifier.weight(1f)) {+                        Text("Refresh Play")+                    }+                }+            }+            items(repos, key = { it.url }) { repo ->+                Card(Modifier.fillMaxWidth()) {+                    Column(Modifier.padding(12.dp)) {+                        Row(Modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically) {+                            Column(Modifier.weight(1f)) {+                                Text(repo.name, style = MaterialTheme.typography.titleSmall)+                                Text(repo.url, style = MaterialTheme.typography.labelSmall)+                                if (repo.lastSync > 0) {+                                    Text("Last sync: ${java.text.SimpleDateFormat("yyyy-MM-dd HH:mm").format(java.util.Date(repo.lastSync))}", style = MaterialTheme.typography.labelSmall)+                                }+                            }+                            Switch(checked = repo.enabled, onCheckedChange = { viewModel.toggleRepo(repo.url) })+                            IconButton(onClick = { viewModel.deleteRepo(repo.url) }) {+                                IconDelete()+                            }+                        }+                    }+                }+            }+        }+    }++    if (showAdd) {+        AlertDialog(+            onDismissRequest = { showAdd = false },+            title = { Text("Add Repository") },+            text = {+                Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {+                    OutlinedTextField(value = newUrl, onValueChange = { newUrl = it }, label = { Text("Repo URL") }, placeholder = { Text(DefaultRepos.FDROID_MAIN) }, modifier = Modifier.fillMaxWidth())+                    OutlinedTextField(value = newName, onValueChange = { newName = it }, label = { Text("Name (optional)") }, modifier = Modifier.fillMaxWidth())+                    Text("Examples:\n${DefaultRepos.FDROID_MAIN}\n${DefaultRepos.IZVYZID}", style = MaterialTheme.typography.labelSmall)+                }+            },+            confirmButton = {+                Button(onClick = {+                    if (newUrl.isNotBlank()) {+                        viewModel.addRepo(newUrl, newName)+                        newUrl = ""+                        newName = ""+                        showAdd = false+                    }+                }) { Text("Add") }+            },+            dismissButton = { TextButton(onClick = { showAdd = false }) { Text("Cancel") } }+        )+    }+}
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.ktnew file mode 100644index 0000000000..5df8e078ae--- /dev/null+++ b/appstore/src/main/java/com/vayunmathur/appstore/ui/SearchAndBrowsePage.kt@@ -0,0 +1,101 @@+package com.vayunmathur.appstore.ui++import androidx.compose.foundation.layout.Arrangement+import androidx.compose.foundation.layout.Box+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.size+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.UnifiedApp+import com.vayunmathur.appstore.util.AppStoreViewModel+import com.vayunmathur.library.ui.CircularProgressIndicator+import com.vayunmathur.library.ui.IconClose+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.Text++@Composable+fun SearchAndBrowsePage(+    viewModel: AppStoreViewModel,+    onAppClick: (UnifiedApp) -> Unit+) {+    val query by viewModel.searchQuery.collectAsState()+    val apps by viewModel.combinedBrowse.collectAsState()+    val installed by viewModel.installedApps.collectAsState()+    val isSyncing by viewModel.isSyncing.collectAsState()+    val syncMsg by viewModel.syncMessage.collectAsState()+    val progressMap by viewModel.downloadProgress.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()+                    }+                }+            },+            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))+                }+                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)+                    }+                }+            } 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) })+                }+            }+        }+    }+}
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.ktnew file mode 100644index 0000000000..0b73afcdd0--- /dev/null+++ b/appstore/src/main/java/com/vayunmathur/appstore/util/AppStoreViewModel.kt@@ -0,0 +1,354 @@+package com.vayunmathur.appstore.util++import android.content.Context+import android.content.Intent+import android.content.pm.ApplicationInfo+import android.content.pm.PackageManager+import android.net.Uri+import android.os.Build+import androidx.core.content.FileProvider+import androidx.lifecycle.ViewModel+import androidx.lifecycle.ViewModelProvider+import androidx.lifecycle.viewModelScope+import com.vayunmathur.appstore.data.AppDatabase+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+import java.io.File+import java.net.HttpURLConnection+import java.net.URL++class AppStoreViewModel(+    private val context: Context,+    private val db: AppDatabase+) : ViewModel() {++    private val _isSyncing = MutableStateFlow(false)+    val isSyncing: StateFlow<Boolean> = _isSyncing++    private val _syncMessage = MutableStateFlow("")+    val syncMessage: StateFlow<String> = _syncMessage++    private val _searchQuery = MutableStateFlow("")+    val searchQuery: StateFlow<String> = _searchQuery++    private val _playSearchResults = MutableStateFlow<List<UnifiedApp>>(emptyList())+    private val _topCharts = MutableStateFlow<List<UnifiedApp>>(emptyList())++    private val _selectedApp = MutableStateFlow<UnifiedApp?>(null)+    val selectedApp: StateFlow<UnifiedApp?> = _selectedApp++    private val _downloadProgress = MutableStateFlow<Map<String, Float>>(emptyMap())+    val downloadProgress: StateFlow<Map<String, Float>> = _downloadProgress++    private val _installedApps = MutableStateFlow<List<InstalledInfo>>(emptyList())+    val installedApps: StateFlow<List<InstalledInfo>> = _installedApps++    private val _activeRepo = MutableStateFlow<String?>(null) // filter++    val repos = db.repoDao().allFlow()+        .stateIn(viewModelScope, SharingStarted.Eagerly, emptyList())++    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 }++        if (query.isBlank()) {+            // Browse mode: F-Droid cached + top Play charts+            val all = fdroid + if (playSearch.isEmpty()) topCharts else playSearch+            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 }+            combined.sortedBy { it.name.lowercase() }+        }+    }.stateIn(viewModelScope, SharingStarted.Eagerly, emptyList())++    var searchJob: Job? = null+    var topJob: Job? = null++    init {+        viewModelScope.launch {+            ensureDefaultRepos()+            refreshInstalled()+            loadTopCharts()+        }+    }++    private suspend fun ensureDefaultRepos() {+        val existing = db.repoDao().all()+        if (existing.isEmpty()) {+            db.repoDao().upsert(RepoEntity(DefaultRepos.FDROID_MAIN, "F-Droid", true))+            db.repoDao().upsert(RepoEntity(DefaultRepos.FDROID_ARCHIVE, "F-Droid Archive", false))+            db.repoDao().upsert(RepoEntity(DefaultRepos.IZVYZID, "IzzyOnDroid", true))+        }+    }++    fun loadTopCharts() {+        topJob?.cancel()+        topJob = viewModelScope.launch {+            _syncMessage.value = "Loading top charts..."+            val charts = PlayStoreDataSource.topCharts()+            _topCharts.value = charts+            _syncMessage.value = ""+        }+    }++    fun setSearch(q: String) {+        _searchQuery.value = q+        searchJob?.cancel()+        if (q.isBlank()) {+            _playSearchResults.value = emptyList()+            return+        }+        searchJob = viewModelScope.launch {+            kotlinx.coroutines.delay(400) // debounce+            _syncMessage.value = "Searching Play Store..."+            val play = PlayStoreDataSource.search(q)+            _playSearchResults.value = play+            _syncMessage.value = ""+        }+    }++    fun syncRepos() {+        if (_isSyncing.value) return+        viewModelScope.launch {+            _isSyncing.value = true+            _syncMessage.value = "Syncing repositories..."+            val repos = db.repoDao().all().filter { it.enabled }+            var fetched = 0+            for (repo in repos) {+                try {+                    _syncMessage.value = "Syncing ${repo.name}..."+                    val apps = FDroidRepository.fetchRepoIndex(repo.url)+                    val entities = apps.map { it.toEntity() }+                    db.cachedAppDao().deleteByRepo(repo.url.removeSuffix("/"))+                    db.cachedAppDao().upsertAll(entities)+                    db.repoDao().upsert(repo.copy(lastSync = System.currentTimeMillis()))+                    fetched += apps.size+                } catch (e: Exception) {+                    _syncMessage.value = "Failed ${repo.name}: ${e.message}"+                    kotlinx.coroutines.delay(1500)+                }+            }+            _syncMessage.value = if (fetched > 0) "Synced $fetched apps" else "Sync complete"+            kotlinx.coroutines.delay(2000)+            _syncMessage.value = ""+            _isSyncing.value = false+            refreshInstalled()+        }+    }++    fun refreshInstalled() {+        viewModelScope.launch(Dispatchers.IO) {+            val pm = context.packageManager+            val installed = pm.getInstalledApplications(PackageManager.MATCH_ALL).mapNotNull { ai ->+                try {+                    val pi = pm.getPackageInfo(ai.packageName, 0)+                    InstalledInfo(+                        packageName = ai.packageName,+                        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+                    )+                } catch (_: Exception) { null }+            }.sortedBy { it.name.lowercase() }+            _installedApps.value = installed+        }+    }++    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()) {+            viewModelScope.launch {+                val details = PlayStoreDataSource.appDetails(app.packageName)+                if (details != null) _selectedApp.value = details+            }+        }+    }++    fun openInPlayStore(pkg: String) {+        try {+            val market = Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=$pkg")).apply {+                addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)+            }+            context.startActivity(market)+        } catch (_: Exception) {+            val web = Intent(Intent.ACTION_VIEW, Uri.parse(PlayStoreDataSource.playStoreUrl(pkg))).apply {+                addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)+            }+            context.startActivity(web)+        }+    }++    fun openInBrowser(url: String) {+        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('/')+            db.repoDao().upsert(RepoEntity(cleanUrl, name.ifBlank { cleanUrl }, true))+        }+    }++    fun toggleRepo(url: String) {+        viewModelScope.launch {+            val existing = db.repoDao().all().find { it.url == url } ?: return@launch+            db.repoDao().upsert(existing.copy(enabled = !existing.enabled))+        }+    }++    fun deleteRepo(url: String) {+        viewModelScope.launch {+            db.repoDao().deleteByUrl(url)+            db.cachedAppDao().deleteByRepo(url)+        }+    }++    fun downloadAndInstall(app: UnifiedApp) {+        if (app.source == AppSource.PLAYSTORE) {+            openInPlayStore(app.packageName)+            return+        }+        val apkUrl = app.apkUrl ?: return+        viewModelScope.launch(Dispatchers.IO) {+            try {+                _downloadProgress.value = _downloadProgress.value + (app.packageName to 0.01f)+                val file = File(context.cacheDir, "${app.packageName}.apk")+                val conn = (URL(apkUrl).openConnection() as HttpURLConnection).apply {+                    connectTimeout = 20000+                    readTimeout = 60000+                }+                val total = conn.contentLengthLong.takeIf { it > 0 } ?: app.sizeBytes+                conn.inputStream.use { input ->+                    file.outputStream().use { out ->+                        val buf = ByteArray(8192)+                        var read: Int+                        var downloaded = 0L+                        while (input.read(buf).also { read = it } != -1) {+                            out.write(buf, 0, read)+                            downloaded += read+                            if (total > 0) {+                                _downloadProgress.value = _downloadProgress.value + (app.packageName to (downloaded.toFloat() / total))+                            }+                        }+                    }+                }+                _downloadProgress.value = _downloadProgress.value - app.packageName+                withContext(Dispatchers.Main) {+                    installApk(file)+                }+            } catch (e: Exception) {+                _downloadProgress.value = _downloadProgress.value - app.packageName+                _syncMessage.value = "Download failed: ${e.message}"+            }+        }+    }++    private fun installApk(file: File) {+        try {+            val uri = FileProvider.getUriForFile(context, "${context.packageName}.fileprovider", file)+            val intent = Intent(Intent.ACTION_VIEW).apply {+                setDataAndType(uri, "application/vnd.android.package-archive")+                addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_GRANT_READ_URI_PERMISSION)+            }+            context.startActivity(intent)+        } catch (e: Exception) {+            _syncMessage.value = "Install failed: ${e.message}"+        }+    }++    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+    }++    private fun UnifiedApp.toEntity(): CachedAppEntity = CachedAppEntity(+        packageName = packageName,+        source = source.name,+        name = name,+        summary = summary,+        description = description,+        iconUrl = iconUrl,+        author = author,+        categories = categories.joinToString(","),+        versionName = versionName,+        versionCode = versionCode,+        sizeBytes = sizeBytes,+        apkUrl = apkUrl,+        repoUrl = repoUrl?.removeSuffix("/") ?: DefaultRepos.FDROID_MAIN,+        lastUpdated = lastUpdated+    )++    private fun CachedAppEntity.toUnifiedApp(): UnifiedApp = UnifiedApp(+        packageName = packageName,+        source = try { AppSource.valueOf(source) } catch (_: Exception) { AppSource.FDROID },+        name = name,+        summary = summary,+        description = description,+        iconUrl = iconUrl,+        author = author,+        categories = categories.split(",").filter { it.isNotBlank() },+        versionName = versionName,+        versionCode = versionCode,+        sizeBytes = sizeBytes,+        apkUrl = apkUrl,+        repoUrl = repoUrl,+        lastUpdated = lastUpdated+    )+}++class AppStoreViewModelFactory(+    private val context: Context,+    private val db: AppDatabase+) : ViewModelProvider.Factory {+    @Suppress("UNCHECKED_CAST")+    override fun <T : ViewModel> create(modelClass: Class<T>): T {+        return AppStoreViewModel(context.applicationContext, db) as T+    }+}
appstore/src/main/res/values/strings.xml
diff --git a/appstore/src/main/res/values/strings.xml b/appstore/src/main/res/values/strings.xmlnew file mode 100644index 0000000000..1fe64d59ed--- /dev/null+++ b/appstore/src/main/res/values/strings.xml@@ -0,0 +1,4 @@+<?xml version="1.0" encoding="utf-8"?>+<resources>+    <string name="app_name">App Store</string>+</resources>
appstore/src/main/res/xml/data_extraction_rules.xml
diff --git a/appstore/src/main/res/xml/data_extraction_rules.xml b/appstore/src/main/res/xml/data_extraction_rules.xmlnew file mode 100644index 0000000000..15f36f1c4b--- /dev/null+++ b/appstore/src/main/res/xml/data_extraction_rules.xml@@ -0,0 +1,13 @@+<?xml version="1.0" encoding="utf-8"?>+<data-extraction-rules>+    <cloud-backup>+        <include domain="sharedpref" path="." />+        <exclude domain="sharedpref" path="device.xml" />+        <include domain="database" path="." />+    </cloud-backup>+    <device-transfer>+        <include domain="sharedpref" path="." />+        <include domain="database" path="." />+        <include domain="file" path="." />+    </device-transfer>+</data-extraction-rules>
appstore/src/main/res/xml/file_paths.xml
diff --git a/appstore/src/main/res/xml/file_paths.xml b/appstore/src/main/res/xml/file_paths.xmlnew file mode 100644index 0000000000..e6a9f031f0--- /dev/null+++ b/appstore/src/main/res/xml/file_paths.xml@@ -0,0 +1,8 @@+<?xml version="1.0" encoding="utf-8"?>+<paths>+    <external-path name="external" path="." />+    <cache-path name="cache" path="." />+    <external-cache-path name="external_cache" path="." />+    <files-path name="files" path="." />+    <external-files-path name="external_files" path="." />+</paths>
settings.gradle.kts
diff --git a/settings.gradle.kts b/settings.gradle.ktsindex a36aabefef..cb7605efa7 100644--- a/settings.gradle.kts+++ b/settings.gradle.kts@@ -89,6 +89,7 @@ include(":keyboard") include(":speech") include(":vpn") include(":web")+include(":appstore")  // Personal / private app modules live under personal/ (gitignored). Included only // when present so the public repo still configures without them.