Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Verified Commit 3e5dfe70 authored by Fahim M. Choudhury's avatar Fahim M. Choudhury
Browse files

refactor: improve method readability in AppManagerWrapper

parent 0e1892ee
Loading
Loading
Loading
Loading
+20 −17
Original line number Diff line number Diff line
@@ -143,23 +143,26 @@ class AppManagerWrapper @Inject constructor(
        progress: DownloadProgress
    ): Int {
        val downloadIds = appInstall.downloadIdMap.keys
        var percent = 0
        if (downloadIds.isEmpty()) {
            return 0
        }

        if (downloadIds.isNotEmpty()) {
        val totalSizeBytes = progress.totalSizeBytes
            .filterKeys { downloadIds.contains(it) }
            .values
            .sum()

            if (totalSizeBytes > 0) {
        val downloadedSoFar = progress.bytesDownloadedSoFar
            .filterKeys { downloadIds.contains(it) }
            .values
            .sum()
                percent = ((downloadedSoFar / totalSizeBytes.toDouble()) * PERCENTAGE_MULTIPLIER)

        val percent = if (totalSizeBytes > 0) {
            ((downloadedSoFar / totalSizeBytes.toDouble()) * PERCENTAGE_MULTIPLIER)
                .toInt()
                .coerceIn(0, PERCENTAGE_MULTIPLIER)
            }
        } else {
            0
        }

        return percent