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

View File

@@ -8,6 +8,7 @@ package com.aurora.store.viewmodel.details
import android.content.Context import android.content.Context
import android.util.Log import android.util.Log
import androidx.core.content.pm.PackageInfoCompat
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import com.aurora.Constants import com.aurora.Constants
@@ -135,7 +136,18 @@ class AppDetailsViewModel @Inject constructor(
private val defaultAppState: AppState private val defaultAppState: AppState
get() = when { 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 else -> if (isArchived) AppState.Archived else AppState.Unavailable
} }