compose: details: Show local app version name and code when installed and not updateable

Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
Aayush Gupta
2025-09-08 15:08:24 +08:00
parent 8547ff64ce
commit 52d6c9ce56
4 changed files with 31 additions and 21 deletions

View File

@@ -322,12 +322,8 @@ private fun ScreenContentApp(
) {
Details(
app = app,
inProgress = state.inProgress(),
progress = state.progress(),
onNavigateToDetailsDevProfile = { showExtraPane(Screen.DevProfile(it)) },
isUpdatable = state is AppState.Updatable,
speed = if (state is AppState.Downloading) state.speed else 0,
timeRemaining = if (state is AppState.Downloading) state.timeRemaining else 0
state = state,
onNavigateToDetailsDevProfile = { showExtraPane(Screen.DevProfile(it)) }
)
SetupActions()

View File

@@ -30,6 +30,7 @@ import com.aurora.store.R
import com.aurora.store.compose.composables.app.AnimatedAppIconComposable
import com.aurora.store.compose.preview.AppPreviewProvider
import com.aurora.store.compose.preview.coilPreviewProvider
import com.aurora.store.data.model.AppState
import com.aurora.store.util.CommonUtil
import com.aurora.store.util.PackageUtil
@@ -37,29 +38,25 @@ import com.aurora.store.util.PackageUtil
* Composable to display basic app details, supposed to be used as a part
* of the Column with proper vertical arrangement spacing in the AppDetailsScreen.
* @param app App to show details about
* @param progress Ongoing progress percentage out of 100, for e.g. 50.0
* @param inProgress Whether there is some ongoing progress related to the app
* @param state State of the app
* @param onNavigateToDetailsDevProfile Callback when the developer name is tapped
* @param isUpdatable Whether the app has a valid update available
*/
@Composable
fun Details(
app: App,
progress: Float = 0F,
inProgress: Boolean = false,
state: AppState = AppState.Unavailable,
onNavigateToDetailsDevProfile: (developerName: String) -> Unit = {},
isUpdatable: Boolean = false,
speed: Long = 0,
timeRemaining: Long = 0
) {
val context = LocalContext.current
val speed = if (state is AppState.Downloading) state.speed else 0
val timeRemaining = if (state is AppState.Downloading) state.timeRemaining else 0
Row(modifier = Modifier.fillMaxWidth()) {
AnimatedAppIconComposable(
modifier = Modifier.requiredSize(dimensionResource(R.dimen.icon_size_large)),
iconUrl = app.iconArtwork.url,
inProgress = inProgress,
progress = progress
inProgress = state.inProgress(),
progress = state.progress()
)
Column(modifier = Modifier.padding(horizontal = dimensionResource(R.dimen.margin_small))) {
Text(
@@ -78,13 +75,14 @@ fun Details(
color = MaterialTheme.colorScheme.primary
)
Text(
text = when {
inProgress -> {
text = when (state) {
is AppState.Installing,
is AppState.Downloading -> {
"${Formatter.formatShortFileSize(context, speed)}/s" +
", " + CommonUtil.getETAString(context, timeRemaining)
}
isUpdatable -> {
is AppState.Updatable -> {
stringResource(
R.string.version_update,
PackageUtil.getInstalledVersionName(context, app.packageName),
@@ -94,6 +92,10 @@ fun Details(
)
}
is AppState.Installed -> {
stringResource(R.string.version, state.versionName, state.versionCode)
}
else -> {
stringResource(R.string.version, app.versionName, app.versionCode)
}

View File

@@ -57,7 +57,7 @@ sealed class AppState {
data class Installing(val progress: Float) : AppState()
data class Error(val message: String?) : AppState()
data object Installed : AppState()
data class Installed(val versionName: String, val versionCode: Long) : AppState()
data object Archived : AppState()
data object Updatable : AppState()
data object Unavailable : AppState()

View File

@@ -8,6 +8,7 @@ package com.aurora.store.viewmodel.details
import android.content.Context
import android.util.Log
import androidx.core.content.pm.PackageInfoCompat
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.aurora.Constants
@@ -135,7 +136,18 @@ class AppDetailsViewModel @Inject constructor(
private val defaultAppState: AppState
get() = when {
isInstalled -> if (hasValidUpdate) AppState.Updatable else AppState.Installed
isInstalled -> {
if (hasValidUpdate) {
AppState.Updatable
} else {
val info = PackageUtil.getPackageInfo(context, app.value!!.packageName)
AppState.Installed(
versionName = info.versionName ?: String(),
versionCode = PackageInfoCompat.getLongVersionCode(info)
)
}
}
else -> if (isArchived) AppState.Archived else AppState.Unavailable
}