Skip to content

Commit

Permalink
[ci skip] Fix Android in-app update
Browse files Browse the repository at this point in the history
  • Loading branch information
DRSchlaubi committed Oct 21, 2023
1 parent 61485ae commit ff99cd5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
2 changes: 1 addition & 1 deletion app/android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ android {
applicationId = "dev.schlaubi.tonbrett.android"
minSdk = 26
targetSdk = sdkInt
versionCode = System.getenv("GITHUB_RUN_NUMBER")?.toIntOrNull()?.plus(931663) ?: 931663
versionCode = System.getenv("GITHUB_RUN_NUMBER")?.toIntOrNull()?.plus(931663) ?: 931665
versionName = rootProject.version.toString()
}

Expand Down
23 changes: 10 additions & 13 deletions app/android/src/main/java/UpdateAwareAppScope.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
Expand All @@ -38,6 +39,7 @@ import com.google.android.play.core.ktx.requestCompleteUpdate
import com.google.android.play.core.ktx.requestUpdateFlow
import com.google.android.play.core.ktx.totalBytesToDownload
import dev.schlaubi.tonbrett.app.ColorScheme
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.launch
import java.text.NumberFormat

Expand All @@ -47,24 +49,19 @@ fun UpdateAwareAppScope(activity: Activity, content: @Composable () -> Unit) {
val scope = rememberCoroutineScope()
val appUpdateManager =
remember(context) { AppUpdateManagerFactory.create(context.applicationContext) }
var progress by remember(appUpdateManager) { mutableStateOf<AppUpdateResult?>(null) }

if (progress == null) {
LaunchedEffect(appUpdateManager) {
try {
appUpdateManager.requestUpdateFlow().collect {
progress = it
}
} catch (e: Throwable) {
Log.w("Tonbrett", "Could not load Update info", e)
}
}
val progressFlow = remember(appUpdateManager) {
appUpdateManager.requestUpdateFlow()
.catch { emit(AppUpdateResult.NotAvailable) }
}

val progress: AppUpdateResult? by progressFlow.collectAsState(initial = null)
var failed by remember(appUpdateManager) { mutableStateOf(false) }

Box(Modifier.fillMaxSize()) {
content()

if (failed) return

Column(
verticalArrangement = Arrangement.Bottom,
horizontalAlignment = Alignment.CenterHorizontally,
Expand Down Expand Up @@ -95,7 +92,7 @@ fun UpdateAwareAppScope(activity: Activity, content: @Composable () -> Unit) {
val installState = currentProgress.installState
when (installState.installStatus) {
InstallStatus.CANCELED, InstallStatus.INSTALLED, InstallStatus.FAILED -> {
progress = AppUpdateResult.NotAvailable
failed = true
}

InstallStatus.DOWNLOADING -> {
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ plugins {

allprojects {
group = "dev.schlaubi.tonbrett"
version = "1.14.39"
version = "1.15.0"

repositories {
mavenCentral()
Expand Down

0 comments on commit ff99cd5

Please sign in to comment.