os details are now fetched from os.json instead of hardcoded

This commit is contained in:
2026-03-10 01:57:57 +05:00
parent 5bd9ef0dcf
commit 987c928ee2
2 changed files with 130 additions and 116 deletions

View File

@@ -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/"
}
]

View File

@@ -1,5 +1,6 @@
package sh.sar.isodroid.ui.screens package sh.sar.isodroid.ui.screens
import android.content.Context
import android.content.Intent import android.content.Intent
import android.net.Uri import android.net.Uri
import androidx.compose.foundation.clickable import androidx.compose.foundation.clickable
@@ -30,6 +31,7 @@ import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.ColorFilter import androidx.compose.ui.graphics.ColorFilter
@@ -38,97 +40,40 @@ import androidx.compose.ui.unit.dp
import coil.compose.AsyncImage import coil.compose.AsyncImage
import coil.decode.SvgDecoder import coil.decode.SvgDecoder
import coil.request.ImageRequest import coil.request.ImageRequest
import org.json.JSONArray
data class OsDownload( data class OsDownload(
val name: String, val name: String,
val category: String,
val description: String, val description: String,
val url: String, val icon: String?,
val icon: String? = null val url: String
) )
private val linuxDownloads = listOf( private fun loadOsDownloads(context: Context): List<OsDownload> {
OsDownload( return try {
name = "Ubuntu", val json = context.assets.open("os.json").bufferedReader().use { it.readText() }
description = "", val jsonArray = JSONArray(json)
url = "https://ubuntu.com/download", val downloads = mutableListOf<OsDownload>()
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 val bsdDownloads = listOf( for (i in 0 until jsonArray.length()) {
OsDownload( val obj = jsonArray.getJSONObject(i)
name = "FreeBSD", downloads.add(
description = "FreeBSD is an operating system for a variety of platforms which focuses on features, speed, and stability.", OsDownload(
url = "https://www.freebsd.org/where/", name = obj.getString("name"),
icon = "freebsd.svg" category = obj.getString("category"),
), description = obj.optString("description", ""),
OsDownload( icon = if (obj.isNull("icon")) null else obj.optString("icon", null),
name = "OPNsense", url = obj.getString("url")
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" }
)
)
private val windowsDownloads = listOf( downloads.sortedBy { it.name.lowercase() }
OsDownload( } catch (e: Exception) {
name = "Windows 11", emptyList()
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
)
)
@OptIn(ExperimentalMaterial3Api::class) @OptIn(ExperimentalMaterial3Api::class)
@Composable @Composable
@@ -136,6 +81,14 @@ fun DownloadsScreen(
onNavigateBack: () -> Unit onNavigateBack: () -> Unit
) { ) {
val context = LocalContext.current 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) { fun openUrl(url: String) {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url)) val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
@@ -167,39 +120,14 @@ fun DownloadsScreen(
.padding(paddingValues) .padding(paddingValues)
.verticalScroll(rememberScrollState()) .verticalScroll(rememberScrollState())
) { ) {
// Linux groupedDownloads.forEach { (category, osList) ->
DownloadCategory( DownloadCategory(
title = "Linux", title = category,
downloads = linuxDownloads, downloads = osList,
onItemClick = { openUrl(it.url) } onItemClick = { openUrl(it.url) }
) )
Spacer(modifier = Modifier.height(16.dp))
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) }
)
Text( Text(
text = "Tap to open download page in browser", text = "Tap to open download page in browser",