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

@@ -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<OsDownload> {
return try {
val json = context.assets.open("os.json").bufferedReader().use { it.readText() }
val jsonArray = JSONArray(json)
val downloads = mutableListOf<OsDownload>()
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",