Skip to content

Commit

Permalink
Show InfiniTime release file sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
pipe01 committed Apr 2, 2024
1 parent 7c448ee commit f5be31f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 19 deletions.
4 changes: 1 addition & 3 deletions app/src/main/java/net/pipe01/pinepartner/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ class MainActivity : ComponentActivity() {
var showBottomBar by remember { mutableStateOf(true) }

PinePartnerTheme {
PermissionsFrame(
onGotAllPermissions = { },
) {
PermissionsFrame {
DisposableEffect(Unit) {
serviceHandle.start()

Expand Down
32 changes: 18 additions & 14 deletions app/src/main/java/net/pipe01/pinepartner/pages/devices/DFUPage.kt
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
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
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
Expand All @@ -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
Expand Down Expand Up @@ -123,6 +125,8 @@ private fun InfiniTimeReleases(
onChoseRelease: (InfiniTimeRelease) -> Unit,
onError: (PineError) -> Unit,
) {
val context = LocalContext.current

val releases = remember { mutableStateListOf<InfiniTimeRelease>() }

var showConfirmDialog by remember { mutableStateOf<InfiniTimeRelease?>(null) }
Expand All @@ -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),
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ data class InfiniTimeRelease(
val name: String,
val resourcesUri: Uri,
val firmwareUri: Uri,
val firmwareSizeBytes: Long,
)

@Serializable
Expand All @@ -24,6 +25,7 @@ private data class GitHubRelease(
@Serializable
private data class GitHubAsset(
val name: String,
val size: Long,
val browser_download_url: String,
)

Expand All @@ -38,11 +40,15 @@ suspend fun getInfiniTimeReleases(): List<InfiniTimeRelease> {
val ghReleases = json.decodeFromString<List<GitHubRelease>>(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,
)
}
}

0 comments on commit f5be31f

Please sign in to comment.