diff --git a/app/src/main/java/net/pipe01/pinepartner/MainActivity.kt b/app/src/main/java/net/pipe01/pinepartner/MainActivity.kt index 6480af6..e0c63cf 100644 --- a/app/src/main/java/net/pipe01/pinepartner/MainActivity.kt +++ b/app/src/main/java/net/pipe01/pinepartner/MainActivity.kt @@ -43,9 +43,7 @@ class MainActivity : ComponentActivity() { var showBottomBar by remember { mutableStateOf(true) } PinePartnerTheme { - PermissionsFrame( - onGotAllPermissions = { }, - ) { + PermissionsFrame { DisposableEffect(Unit) { serviceHandle.start() diff --git a/app/src/main/java/net/pipe01/pinepartner/pages/devices/DFUPage.kt b/app/src/main/java/net/pipe01/pinepartner/pages/devices/DFUPage.kt index 6a5f4f2..51b5ceb 100644 --- a/app/src/main/java/net/pipe01/pinepartner/pages/devices/DFUPage.kt +++ b/app/src/main/java/net/pipe01/pinepartner/pages/devices/DFUPage.kt @@ -1,6 +1,7 @@ package net.pipe01.pinepartner.pages.devices import android.net.Uri +import android.text.format.Formatter import android.util.Log import androidx.activity.compose.BackHandler import androidx.activity.compose.rememberLauncherForActivityResult @@ -8,7 +9,6 @@ import androidx.activity.result.contract.ActivityResultContracts import androidx.compose.foundation.clickable import androidx.compose.foundation.gestures.Orientation import androidx.compose.foundation.gestures.scrollable -import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxWidth @@ -30,6 +30,8 @@ import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.alpha +import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import kotlinx.coroutines.delay @@ -123,6 +125,8 @@ private fun InfiniTimeReleases( onChoseRelease: (InfiniTimeRelease) -> Unit, onError: (PineError) -> Unit, ) { + val context = LocalContext.current + val releases = remember { mutableStateListOf() } var showConfirmDialog by remember { mutableStateOf(null) } @@ -148,19 +152,19 @@ private fun InfiniTimeReleases( } LoadingStandIn(isLoading = releases.isEmpty()) { - if (releases.isEmpty()) { - Text("Loading releases...") - } else { - Column { - releases.forEach { - Box( - modifier = Modifier - .fillMaxWidth() - .clickable { showConfirmDialog = it } - .padding(16.dp), - ) { - Text(it.name) - } + Column { + releases.forEach { + Column( + modifier = Modifier + .fillMaxWidth() + .clickable { showConfirmDialog = it } + .padding(8.dp), + ) { + Text(text = it.name) + Text( + modifier = Modifier.alpha(0.6f), + text = Formatter.formatFileSize(context, it.firmwareSizeBytes), + ) } } } diff --git a/app/src/main/java/net/pipe01/pinepartner/utils/InfiniTimeReleases.kt b/app/src/main/java/net/pipe01/pinepartner/utils/InfiniTimeReleases.kt index bf891ac..fb87a32 100644 --- a/app/src/main/java/net/pipe01/pinepartner/utils/InfiniTimeReleases.kt +++ b/app/src/main/java/net/pipe01/pinepartner/utils/InfiniTimeReleases.kt @@ -12,6 +12,7 @@ data class InfiniTimeRelease( val name: String, val resourcesUri: Uri, val firmwareUri: Uri, + val firmwareSizeBytes: Long, ) @Serializable @@ -24,6 +25,7 @@ private data class GitHubRelease( @Serializable private data class GitHubAsset( val name: String, + val size: Long, val browser_download_url: String, ) @@ -38,11 +40,15 @@ suspend fun getInfiniTimeReleases(): List { val ghReleases = json.decodeFromString>(resp) return ghReleases.mapNotNull { + val resources = it.assets.firstOrNull { it.name.startsWith("infinitime-resources-") } ?: return@mapNotNull null + val firmware = it.assets.firstOrNull { it.name.startsWith("pinetime-mcuboot-app-dfu-") } ?: return@mapNotNull null + InfiniTimeRelease( version = it.tag_name, name = it.name.trim(), - resourcesUri = Uri.parse(it.assets.firstOrNull { it.name.startsWith("infinitime-resources-") }?.browser_download_url ?: return@mapNotNull null), - firmwareUri = Uri.parse(it.assets.firstOrNull { it.name.startsWith("pinetime-mcuboot-app-dfu-") }?.browser_download_url ?: return@mapNotNull null), + resourcesUri = Uri.parse(resources.browser_download_url), + firmwareUri = Uri.parse(firmware.browser_download_url), + firmwareSizeBytes = firmware.size, ) } }