From 987c928ee272b1423208de36f59bede2cb064179 Mon Sep 17 00:00:00 2001 From: Shihaam Abdul Rahman Date: Tue, 10 Mar 2026 01:57:57 +0500 Subject: [PATCH] os details are now fetched from os.json instead of hardcoded --- app/src/main/assets/os.json | 86 ++++++++++ .../isodroid/ui/screens/DownloadsScreen.kt | 160 +++++------------- 2 files changed, 130 insertions(+), 116 deletions(-) create mode 100644 app/src/main/assets/os.json diff --git a/app/src/main/assets/os.json b/app/src/main/assets/os.json new file mode 100644 index 0000000..1c4d1ca --- /dev/null +++ b/app/src/main/assets/os.json @@ -0,0 +1,86 @@ +[ + { + "name": "Arch Linux", + "category": "Linux", + "description": "A simple, lightweight distribution", + "icon": "archlinux.svg", + "url": "https://archlinux.org/download/" + }, + { + "name": "Debian", + "category": "Linux", + "description": "Debian is a complete Free Operating System!", + "icon": "debian.svg", + "url": "https://www.debian.org/download" + }, + { + "name": "Fedora", + "category": "Linux", + "description": "The Fedora Project is a community of people working together to build a free and open source software platform and to collaborate on and share user-focused solutions built on that platform.", + "icon": "fedora.svg", + "url": "https://www.fedoraproject.org/" + }, + { + "name": "Linux Mint", + "category": "Linux", + "description": "Linux Mint is an operating system for desktop and laptop computers. It is designed to work 'out of the box' and comes fully equipped with the apps most people need.", + "icon": "linuxmint.svg", + "url": "https://linuxmint.com/download.php" + }, + { + "name": "NixOS", + "category": "Linux", + "description": "Declarative builds and deployments.", + "icon": "nixos.svg", + "url": "https://nixos.org/download/#nixos-iso" + }, + { + "name": "Pop!_OS", + "category": "Linux", + "description": "Unleash your potential on a Linux operating system made to be productive and personal.", + "icon": "popos.svg", + "url": "https://system76.com/pop/download/" + }, + { + "name": "Tails", + "category": "Linux", + "description": "Tails is a portable operating system that protects against surveillance and censorship.", + "icon": "tails.svg", + "url": "https://tails.net/install/download/index.en.html" + }, + { + "name": "Ubuntu", + "category": "Linux", + "description": "", + "icon": "ubuntu.svg", + "url": "https://ubuntu.com/download" + }, + { + "name": "FreeBSD", + "category": "BSD", + "description": "FreeBSD is an operating system for a variety of platforms which focuses on features, speed, and stability.", + "icon": "freebsd.svg", + "url": "https://www.freebsd.org/where/" + }, + { + "name": "OPNsense", + "category": "BSD", + "description": "OPNsense® is an open source, feature rich firewall and routing platform, offering cutting-edge network protection.", + "icon": "opnsense.svg", + "url": "https://opnsense.org/download/" + }, + { + "name": "Windows 11", + "category": "Windows", + "description": "", + "icon": null, + "url": "https://www.microsoft.com/en-us/software-download/windows11" + }, + { + "name": "Hiren's BootCD PE", + "category": "Recovery", + "description": "Hiren's BootCD PE (Preinstallation Environment) is a restored edition of Hiren's BootCD based on Windows PE", + "icon": null, + "url": "https://www.hirensbootcd.org/download/" + } +] diff --git a/app/src/main/java/sh/sar/isodroid/ui/screens/DownloadsScreen.kt b/app/src/main/java/sh/sar/isodroid/ui/screens/DownloadsScreen.kt index 4656b20..ebab9be 100644 --- a/app/src/main/java/sh/sar/isodroid/ui/screens/DownloadsScreen.kt +++ b/app/src/main/java/sh/sar/isodroid/ui/screens/DownloadsScreen.kt @@ -1,5 +1,6 @@ package sh.sar.isodroid.ui.screens +import android.content.Context import android.content.Intent import android.net.Uri import androidx.compose.foundation.clickable @@ -30,6 +31,7 @@ import androidx.compose.material3.Text import androidx.compose.material3.TopAppBar import androidx.compose.material3.TopAppBarDefaults import androidx.compose.runtime.Composable +import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.ColorFilter @@ -38,97 +40,40 @@ import androidx.compose.ui.unit.dp import coil.compose.AsyncImage import coil.decode.SvgDecoder import coil.request.ImageRequest +import org.json.JSONArray data class OsDownload( val name: String, + val category: String, val description: String, - val url: String, - val icon: String? = null + val icon: String?, + val url: String ) -private val linuxDownloads = listOf( - OsDownload( - name = "Ubuntu", - description = "", - url = "https://ubuntu.com/download", - icon = "ubuntu.svg" - ), - OsDownload( - name = "Debian", - description = "Debian is a complete Free Operating System!", - url = "https://www.debian.org/download", - icon = "debian.svg" - ), - OsDownload( - name = "Arch Linux", - description = "A simple, lightweight distribution", - url = "https://archlinux.org/download/", - icon = "archlinux.svg" - ), - OsDownload( - name = "NixOS", - description = "Declarative builds and deployments.", - url = "https://nixos.org/download/#nixos-iso", - icon = "nixos.svg" - ), - OsDownload( - name = "Linux Mint", - description = "Linux Mint is an operating system for desktop and laptop computers. It is designed to work 'out of the box' and comes fully equipped with the apps most people need.", - url = "https://linuxmint.com/download.php", - icon = "linuxmint.svg" - ), - OsDownload( - name = "Fedora", - description = "The Fedora Project is a community of people working together to build a free and open source software platform and to collaborate on and share user-focused solutions built on that platform.", - url = "https://www.fedoraproject.org/", - icon = "fedora.svg" - ), - OsDownload( - name = "Tails", - description = "Tails is a portable operating system that protects against surveillance and censorship.", - url = "https://tails.net/install/download/index.en.html", - icon = "tails.svg" - ), - OsDownload( - name = "Pop!_OS", - description = "Unleash your potential on a Linux operating system made to be productive and personal.", - url = "https://system76.com/pop/download/", - icon = "popos.svg" - ) -) +private fun loadOsDownloads(context: Context): List { + return try { + val json = context.assets.open("os.json").bufferedReader().use { it.readText() } + val jsonArray = JSONArray(json) + val downloads = mutableListOf() -private val bsdDownloads = listOf( - OsDownload( - name = "FreeBSD", - description = "FreeBSD is an operating system for a variety of platforms which focuses on features, speed, and stability.", - url = "https://www.freebsd.org/where/", - icon = "freebsd.svg" - ), - OsDownload( - name = "OPNsense", - description = "OPNsense® is an open source, feature rich firewall and routing platform, offering cutting-edge network protection.", - url = "https://opnsense.org/download/", - icon = "opnsense.svg" - ) -) + for (i in 0 until jsonArray.length()) { + val obj = jsonArray.getJSONObject(i) + downloads.add( + OsDownload( + name = obj.getString("name"), + category = obj.getString("category"), + description = obj.optString("description", ""), + icon = if (obj.isNull("icon")) null else obj.optString("icon", null), + url = obj.getString("url") + ) + ) + } -private val windowsDownloads = listOf( - OsDownload( - name = "Windows 11", - description = "", - url = "https://www.microsoft.com/en-us/software-download/windows11", - icon = null - ) -) - -private val recoveryDownloads = listOf( - OsDownload( - name = "Hiren's BootCD PE", - description = "Hiren's BootCD PE (Preinstallation Environment) is a restored edition of Hiren's BootCD based on Windows PE", - url = "https://www.hirensbootcd.org/download/", - icon = null - ) -) + downloads.sortedBy { it.name.lowercase() } + } catch (e: Exception) { + emptyList() + } +} @OptIn(ExperimentalMaterial3Api::class) @Composable @@ -136,6 +81,14 @@ fun DownloadsScreen( onNavigateBack: () -> Unit ) { val context = LocalContext.current + val downloads = remember { loadOsDownloads(context) } + + // Group by category and maintain order: Linux, BSD, Windows, Recovery + val categoryOrder = listOf("Linux", "BSD", "Windows", "Recovery") + val groupedDownloads = remember(downloads) { + downloads.groupBy { it.category } + .toSortedMap(compareBy { categoryOrder.indexOf(it).takeIf { i -> i >= 0 } ?: Int.MAX_VALUE }) + } fun openUrl(url: String) { val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url)) @@ -167,39 +120,14 @@ fun DownloadsScreen( .padding(paddingValues) .verticalScroll(rememberScrollState()) ) { - // Linux - DownloadCategory( - title = "Linux", - downloads = linuxDownloads, - onItemClick = { openUrl(it.url) } - ) - - Spacer(modifier = Modifier.height(16.dp)) - - // BSD - DownloadCategory( - title = "BSD", - downloads = bsdDownloads, - onItemClick = { openUrl(it.url) } - ) - - Spacer(modifier = Modifier.height(16.dp)) - - // Windows - DownloadCategory( - title = "Windows", - downloads = windowsDownloads, - onItemClick = { openUrl(it.url) } - ) - - Spacer(modifier = Modifier.height(16.dp)) - - // Recovery - DownloadCategory( - title = "Recovery", - downloads = recoveryDownloads, - onItemClick = { openUrl(it.url) } - ) + groupedDownloads.forEach { (category, osList) -> + DownloadCategory( + title = category, + downloads = osList, + onItemClick = { openUrl(it.url) } + ) + Spacer(modifier = Modifier.height(16.dp)) + } Text( text = "Tap to open download page in browser",