switch type to long

This commit is contained in:
Ax333l 2024-12-19 20:52:49 +01:00
parent 829f093afe
commit 543f9fe7e4
No known key found for this signature in database
GPG Key ID: D2B4D85271127D23
5 changed files with 10 additions and 14 deletions

View File

@ -40,7 +40,7 @@ class DownloadedAppRepository(
data: Parcelable,
expectedPackageName: String,
expectedVersion: String?,
onDownload: suspend (downloadProgress: Pair<Double, Double?>) -> Unit,
onDownload: suspend (downloadProgress: Pair<Long, Long?>) -> Unit,
): File {
// Converted integers cannot contain / or .. unlike the package name or version, so they are safer to use here.
val relativePath = File(generateUid().toString())
@ -90,7 +90,7 @@ class DownloadedAppRepository(
}
.conflate()
.flowOn(Dispatchers.IO)
.collect { (downloaded, size) -> onDownload(downloaded.megaBytes to size.megaBytes) }
.collect { (downloaded, size) -> onDownload(downloaded to size) }
if (downloadedBytes.get() < 1) error("Downloader did not download anything.")
val pkgInfo =
@ -130,8 +130,4 @@ class DownloadedAppRepository(
dao.delete(downloadedApps)
}
private companion object {
val Long.megaBytes get() = toDouble() / 1_000_000
}
}

View File

@ -74,7 +74,7 @@ class PatcherWorker(
val selectedPatches: PatchSelection,
val options: Options,
val logger: Logger,
val downloadProgress: MutableStateFlow<Pair<Double, Double?>?>,
val downloadProgress: MutableStateFlow<Pair<Long, Long?>?>,
val patchesProgress: MutableStateFlow<Pair<Int, Int>>,
val handleStartActivityRequest: suspend (LoadedDownloaderPlugin, Intent) -> ActivityResult,
val setInputFile: (File) -> Unit,

View File

@ -135,7 +135,7 @@ fun SubStep(
name: String,
state: State,
message: String? = null,
downloadProgress: Pair<Double, Double?>? = null
downloadProgress: Pair<Long, Long?>? = null
) {
var messageExpanded by rememberSaveable { mutableStateOf(true) }
@ -181,7 +181,7 @@ fun SubStep(
} else {
downloadProgress?.let { (current, total) ->
Text(
if (total != null) "${current.formatted}/${total.formatted} MB" else "${current.formatted} MB",
if (total != null) "${current.megaBytes}/${total.megaBytes} MB" else "${current.megaBytes} MB",
style = MaterialTheme.typography.labelSmall
)
}
@ -200,7 +200,7 @@ fun SubStep(
}
@Composable
fun StepIcon(state: State, progress: Pair<Double, Double?>? = null, size: Dp) {
fun StepIcon(state: State, progress: Pair<Long, Long?>? = null, size: Dp) {
val strokeWidth = Dp(floor(size.value / 10) + 1)
when (state) {
@ -245,4 +245,4 @@ fun StepIcon(state: State, progress: Pair<Double, Double?>? = null, size: Dp) {
}
}
private val Double.formatted get() = "%.1f".format(locale = Locale.ROOT, this)
private val Long.megaBytes get() = "%.1f".format(locale = Locale.ROOT, toDouble() / 1_000_000)

View File

@ -19,5 +19,5 @@ data class Step(
val category: StepCategory,
val state: State = State.WAITING,
val message: String? = null,
val downloadProgress: StateFlow<Pair<Double, Double?>?>? = null
val downloadProgress: StateFlow<Pair<Long, Long?>?>? = null
)

View File

@ -125,7 +125,7 @@ class PatcherViewModel(
}
val patchesProgress = MutableStateFlow(Pair(0, input.selectedPatches.values.sumOf { it.size }))
private val downloadProgress = MutableStateFlow<Pair<Double, Double?>?>(null)
private val downloadProgress = MutableStateFlow<Pair<Long, Long?>?>(null)
val steps = generateSteps(
app,
input.selectedApp,
@ -447,7 +447,7 @@ class PatcherViewModel(
fun generateSteps(
context: Context,
selectedApp: SelectedApp,
downloadProgress: StateFlow<Pair<Double, Double?>?>? = null
downloadProgress: StateFlow<Pair<Long, Long?>?>? = null
): List<Step> {
val needsDownload =
selectedApp is SelectedApp.Download || selectedApp is SelectedApp.Search