diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 98a5c1f71..a65cfbf55 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -183,7 +183,6 @@ dependencies { implementation(libs.androidx.core.ktx) implementation(libs.androidx.browser) implementation(libs.androidx.lifecycle.viewmodel.ktx) - implementation(libs.androidx.lifecycle.process) implementation(libs.androidx.lifecycle.navigation3) implementation(libs.androidx.preference.ktx) implementation(libs.androidx.swiperefreshlayout) diff --git a/app/src/main/java/com/aurora/store/compose/composables/DownloadComposable.kt b/app/src/main/java/com/aurora/store/compose/composables/DownloadComposable.kt index 0174995a3..fba19cf53 100644 --- a/app/src/main/java/com/aurora/store/compose/composables/DownloadComposable.kt +++ b/app/src/main/java/com/aurora/store/compose/composables/DownloadComposable.kt @@ -5,6 +5,7 @@ package com.aurora.store.compose.composables +import android.text.format.Formatter import androidx.compose.foundation.combinedClickable import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column @@ -37,7 +38,6 @@ import com.aurora.store.R import com.aurora.store.compose.preview.AppPreviewProvider import com.aurora.store.compose.preview.coilPreviewProvider import com.aurora.store.data.room.download.Download -import com.aurora.store.util.CommonUtil.getDownloadSpeedString import com.aurora.store.util.CommonUtil.getETAString /** @@ -107,7 +107,7 @@ fun DownloadComposable( style = MaterialTheme.typography.bodySmall ) Text( - text = getDownloadSpeedString(LocalContext.current, download.speed), + text = "${Formatter.formatShortFileSize(LocalContext.current, download.speed)}/s", style = MaterialTheme.typography.bodySmall ) } diff --git a/app/src/main/java/com/aurora/store/compose/ui/details/components/AppDetails.kt b/app/src/main/java/com/aurora/store/compose/ui/details/components/AppDetails.kt index 343547d3a..cab626cdd 100644 --- a/app/src/main/java/com/aurora/store/compose/ui/details/components/AppDetails.kt +++ b/app/src/main/java/com/aurora/store/compose/ui/details/components/AppDetails.kt @@ -5,6 +5,7 @@ package com.aurora.store.compose.ui.details.components +import android.text.format.Formatter import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column @@ -92,7 +93,7 @@ fun AppDetails( ) Text( text = if (inProgress) { - CommonUtil.getDownloadSpeedString(context, speed) + + "${Formatter.formatShortFileSize(context, speed)}/s" + ", " + CommonUtil.getETAString(context, timeRemaining) } else { "" diff --git a/app/src/main/java/com/aurora/store/util/CommonUtil.kt b/app/src/main/java/com/aurora/store/util/CommonUtil.kt index 2845df5b8..64e64d6cd 100644 --- a/app/src/main/java/com/aurora/store/util/CommonUtil.kt +++ b/app/src/main/java/com/aurora/store/util/CommonUtil.kt @@ -21,11 +21,8 @@ package com.aurora.store.util import android.content.Context import android.util.Log -import androidx.lifecycle.Lifecycle -import androidx.lifecycle.ProcessLifecycleOwner import com.aurora.store.R import com.aurora.store.data.model.ProxyInfo -import java.text.DecimalFormat import java.util.Locale import kotlin.math.ln import kotlin.math.pow @@ -109,40 +106,6 @@ object CommonUtil { ) } - fun humanReadableByteValue(bytes: Long, si: Boolean): String { - val unit = if (si) 1000 else 1024 - if (bytes < unit) return "$bytes B" - val exp = (ln(bytes.toDouble()) / ln(unit.toDouble())).toInt() - val pre = (if (si) "kMGTPE" else "KMGTPE")[exp - 1].toString() + if (si) "" else "i" - return String.format( - Locale.getDefault(), "%.1f %sB", - bytes / unit.toDouble().pow(exp.toDouble()), - pre - ) - } - - fun getDownloadSpeedString(context: Context, downloadedBytesPerSecond: Long): String { - if (downloadedBytesPerSecond < 0) { - return context.getString(R.string.download_speed_estimating) - } - val kb = downloadedBytesPerSecond.toDouble() / 1000.toDouble() - val mb = kb / 1000.toDouble() - val decimalFormat = DecimalFormat(".##") - return when { - mb >= 1 -> { - context.getString(R.string.download_speed_mb, decimalFormat.format(mb)) - } - - kb >= 1 -> { - context.getString(R.string.download_speed_kb, decimalFormat.format(kb)) - } - - else -> { - context.getString(R.string.download_speed_bytes, downloadedBytesPerSecond) - } - } - } - fun cleanupInstallationSessions(context: Context) { val packageInstaller = context.packageManager.packageInstaller for (sessionInfo in packageInstaller.mySessions) { @@ -180,8 +143,4 @@ object CommonUtil { else -> null } } - - fun inForeground(): Boolean { - return ProcessLifecycleOwner.get().lifecycle.currentState.isAtLeast(Lifecycle.State.CREATED) - } } diff --git a/app/src/main/java/com/aurora/store/view/epoxy/views/DownloadView.kt b/app/src/main/java/com/aurora/store/view/epoxy/views/DownloadView.kt index 100a46b96..5feb39c02 100644 --- a/app/src/main/java/com/aurora/store/view/epoxy/views/DownloadView.kt +++ b/app/src/main/java/com/aurora/store/view/epoxy/views/DownloadView.kt @@ -20,6 +20,7 @@ package com.aurora.store.view.epoxy.views import android.content.Context +import android.text.format.Formatter import android.util.AttributeSet import coil3.load import coil3.request.placeholder @@ -32,7 +33,6 @@ import com.aurora.store.R import com.aurora.store.data.model.DownloadStatus import com.aurora.store.data.room.download.Download import com.aurora.store.databinding.ViewDownloadBinding -import com.aurora.store.util.CommonUtil.getDownloadSpeedString import com.aurora.store.util.CommonUtil.getETAString @ModelView( @@ -61,10 +61,7 @@ class DownloadView @JvmOverloads constructor( binding.txtProgress.text = ("${download.progress}%") binding.txtEta.text = getETAString(context, download.timeRemaining) - binding.txtSpeed.text = getDownloadSpeedString( - context, - download.speed - ) + binding.txtSpeed.text = "${Formatter.formatShortFileSize(context, download.speed)}/s" when (download.downloadStatus) { DownloadStatus.DOWNLOADING, DownloadStatus.QUEUED -> { diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index b3210ce30..c9498ef1c 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -63,7 +63,6 @@ androidx-adaptive-navigation = { module = "androidx.compose.material3.adaptive:a androidx-espresso-core = { module = "androidx.test.espresso:espresso-core", version.ref = "espresso" } androidx-hilt-navigation = { module = "androidx.hilt:hilt-navigation-compose", version.ref = "androidx-hilt" } androidx-junit = { module = "androidx.test.ext:junit-ktx", version.ref = "androidx-junit" } -androidx-lifecycle-process = { module = "androidx.lifecycle:lifecycle-process", version.ref = "lifecycle" } androidx-lifecycle-viewmodel-ktx = { module = "androidx.lifecycle:lifecycle-viewmodel-ktx", version.ref = "lifecycle" } androidx-lifecycle-navigation3 = { module = "androidx.lifecycle:lifecycle-viewmodel-navigation3", version.ref = "lifecycle-navigation3" } androidx-material3 = { group = "androidx.compose.material3", name = "material3", version.ref = "composeMaterial" }