Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,8 @@ dependencies {
// JavaSteam
val localBuild = false // Change to 'true' needed when building JavaSteam manually
if (localBuild) {
implementation(files("../../JavaSteam/build/libs/javasteam-1.8.0.1-22-SNAPSHOT.jar"))
implementation(files("../../JavaSteam/javasteam-depotdownloader/build/libs/javasteam-depotdownloader-1.8.0.1-22-SNAPSHOT.jar"))
implementation(files("../../JavaSteam/build/libs/javasteam-1.8.0.1-24-SNAPSHOT.jar"))
implementation(files("../../JavaSteam/javasteam-depotdownloader/build/libs/javasteam-depotdownloader-1.8.0.1-24-SNAPSHOT.jar"))
implementation(libs.bundles.javasteam.dev)
} else {
implementation(libs.javasteam) {
Expand Down
53 changes: 53 additions & 0 deletions app/src/main/java/app/gamenative/service/SteamService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import android.net.NetworkCapabilities
import android.net.NetworkRequest
import android.os.IBinder
import android.util.Base64
import app.gamenative.ui.data.Achievement
import app.gamenative.ui.util.GameInviteNotificationManager
import app.gamenative.ui.util.SnackbarManager
import app.gamenative.service.callback.GameInviteCallback
Expand Down Expand Up @@ -164,6 +165,7 @@ import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
import kotlinx.coroutines.TimeoutCancellationException
import kotlinx.coroutines.withTimeout
import timber.log.Timber
import app.gamenative.data.DownloadingAppInfo
Expand Down Expand Up @@ -3090,6 +3092,57 @@ class SteamService : Service(), IChallengeUrlChanged {
}
}

suspend fun fetchAchievementsForDisplay(appId: Int): List<Achievement>? {
Comment thread
VinceBT marked this conversation as resolved.
if (!isConnected) return null
return try {
withTimeout(15_000) {
val steamUser = instance?._steamUser ?: return@withTimeout null
val userStats = instance?._steamUserStats?.getUserStats(appId, steamUser.steamID!!)?.await() ?: return@withTimeout null
// Failed fetch (e.g. transient CM error): return null so the caller can retry.
if (userStats.result != EResult.OK) return@withTimeout null
val baseIconUrl = SteamUtils.getBaseAchievementIconUrl(appId)
val appLanguage = SteamUtils.steamLanguageForAppLocale()
val localized = userStats.getExpandedAchievements(appLanguage)
// Parse the English schema lazily: only achievements missing a localized name or
// description need it, so fully-localized games never pay for the extra parse.
val englishByName by lazy {
if (appLanguage == "english") {
emptyMap()
} else {
userStats.getExpandedAchievements("english").associateBy { it.name }
}
}
localized.map { block ->
fun english() = englishByName[block.name]
Achievement(
displayName = block.displayName?.takeIf { it.isNotBlank() }
?: english()?.displayName?.takeIf { it.isNotBlank() }
?: block.name ?: "",
name = block.name,
isUnlocked = block.isUnlocked,
description = block.description?.takeIf { it.isNotBlank() }
?: english()?.description?.takeIf { it.isNotBlank() }
?: "",
unlockTimestamp = block.unlockTimestamp,
hidden = block.hidden,
icon = if (!block.icon.isNullOrEmpty()) "$baseIconUrl${block.icon}" else "",
iconGray = if (!block.iconGray.isNullOrEmpty()) "$baseIconUrl${block.iconGray}" else null,
progressCurrent = block.progressCurrent,
progressMax = block.progressMax,
)
}
}
} catch (e: TimeoutCancellationException) {
Timber.w("fetchAchievementsForDisplay timed out for appId=$appId")
null
} catch (e: CancellationException) {
throw e
} catch (e: Exception) {
Timber.e(e, "fetchAchievementsForDisplay failed for appId=$appId")
null
}
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
}
Comment thread
VinceBT marked this conversation as resolved.

Comment thread
coderabbitai[bot] marked this conversation as resolved.
suspend fun generateAchievements(appId: Int, configDirectory: String) {
val steamUser = instance!!._steamUser!!
val userStats = instance?._steamUserStats!!.getUserStats(appId, steamUser.steamID!!).await()
Expand Down
139 changes: 139 additions & 0 deletions app/src/main/java/app/gamenative/ui/component/InfoCard.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
@file:OptIn(ExperimentalFoundationApi::class)

package app.gamenative.ui.component

import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.focusable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.interaction.collectIsFocusedAsState
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.relocation.BringIntoViewRequester
import androidx.compose.foundation.relocation.bringIntoViewRequester
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.KeyboardArrowRight
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp

/**
* Labelled card showing [label] over either a [value] string or arbitrary [content].
* [focusableForNavigation] makes it a D-pad focus stop; [onClick] makes it clickable. Either adds the [focusRing].
*/
@Composable
fun InfoCard(
label: String,
modifier: Modifier = Modifier,
value: String? = null,
statusColor: Color? = null,
isCompact: Boolean = false,
focusableForNavigation: Boolean = false,
onClick: (() -> Unit)? = null,
content: (@Composable ColumnScope.() -> Unit)? = null,
) {
val shape = RoundedCornerShape(16.dp)
val interactionSource = remember { MutableInteractionSource() }
val isFocused by interactionSource.collectIsFocusedAsState()
val bringIntoViewRequester = remember { BringIntoViewRequester() }

LaunchedEffect(isFocused) {
if (isFocused) bringIntoViewRequester.bringIntoView()
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

val interactive = when {
// No ripple; the focusRing shows focus and a ripple would bleed past the rounded shape.
onClick != null -> Modifier.clickable(
interactionSource = interactionSource,
indication = null,
onClick = onClick,
)
focusableForNavigation -> Modifier.focusable(interactionSource = interactionSource)
else -> Modifier
}

Surface(
modifier = modifier
.bringIntoViewRequester(bringIntoViewRequester)
.then(interactive)
.focusRing(interactionSource, shape),
shape = shape,
color = MaterialTheme.colorScheme.surfaceContainerHigh,
shadowElevation = 2.dp,
) {
Column(
modifier = Modifier.padding(if (isCompact) 14.dp else 18.dp),
) {
Row(verticalAlignment = Alignment.CenterVertically) {
// Only constrain the label when the chevron shares the row; otherwise let it wrap.
val hasChevron = onClick != null
Text(
text = label,
style = MaterialTheme.typography.labelMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant,
fontWeight = FontWeight.Medium,
maxLines = if (hasChevron) 1 else Int.MAX_VALUE,
overflow = if (hasChevron) TextOverflow.Ellipsis else TextOverflow.Clip,
modifier = if (hasChevron) Modifier.weight(1f, fill = false) else Modifier,
)
// Chevron hints the card is tappable.
if (onClick != null) {
Spacer(modifier = Modifier.width(2.dp))
Icon(
imageVector = Icons.AutoMirrored.Filled.KeyboardArrowRight,
contentDescription = null,
tint = MaterialTheme.colorScheme.onSurfaceVariant,
modifier = Modifier.size(16.dp),
)
}
}
Spacer(modifier = Modifier.height(6.dp))
if (content != null) {
content()
} else if (value != null) {
Row(verticalAlignment = Alignment.CenterVertically) {
if (statusColor != null) {
Box(
modifier = Modifier
.size(10.dp)
.background(statusColor, CircleShape),
)
Spacer(modifier = Modifier.width(10.dp))
}
Text(
text = value,
style = if (isCompact) {
MaterialTheme.typography.bodyLarge.copy(fontWeight = FontWeight.SemiBold)
} else {
MaterialTheme.typography.titleMedium.copy(fontWeight = FontWeight.SemiBold)
},
color = if (statusColor != null) statusColor else MaterialTheme.colorScheme.onSurface,
maxLines = 2,
overflow = TextOverflow.Ellipsis,
)
}
}
}
}
}
28 changes: 28 additions & 0 deletions app/src/main/java/app/gamenative/ui/data/Achievement.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package app.gamenative.ui.data

data class Achievement(
val displayName: String,
val name: String?,
val isUnlocked: Boolean,
val description: String,
val unlockTimestamp: Int,
val hidden: Boolean,
val icon: String,
val iconGray: String?,
val progressCurrent: Float? = null,
val progressMax: Float? = null,
){
/** True when this achievement tracks partial progress (e.g. 45 / 100). */
val hasProgress: Boolean
get() = progressMax != null && progressMax > 0f

/** (date, time-of-day) of the unlock, both localized; null if never unlocked. */
fun getFormattedUnlockDateTime(): Pair<String, String>? {
if (unlockTimestamp == 0) return null
val locale = java.util.Locale.getDefault()
val millis = java.util.Date(unlockTimestamp * 1000L)
val date = java.text.DateFormat.getDateInstance(java.text.DateFormat.MEDIUM, locale).format(millis)
val time = java.text.DateFormat.getTimeInstance(java.text.DateFormat.SHORT, locale).format(millis)
return date to time
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package app.gamenative.ui.data

/**
* Bundles the download/install flags passed to AppScreenContent. Grouping them keeps the composable's
* parameter count low enough to avoid the ART verifier rejecting the generated method (VerifyError).
*/
data class DownloadDisplayDetails(
val isInstalled: Boolean,
val isValidToDownload: Boolean,
val isDownloading: Boolean,
val downloadProgress: Float,
val hasPartialDownload: Boolean,
val isUpdatePending: Boolean,
val hasLeftoverInstall: Boolean = false,
)
Loading
Loading