diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 6faca4d95..d317d8683 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -121,4 +121,6 @@ dependencies { testImplementation(libs.androidx.junit) androidTestImplementation(libs.androidx.junit) + + implementation(libs.app.update) } diff --git a/app/src/main/java/team/aliens/dms/android/app/MainActivity.kt b/app/src/main/java/team/aliens/dms/android/app/MainActivity.kt index 06dd942d5..90d69ce6d 100644 --- a/app/src/main/java/team/aliens/dms/android/app/MainActivity.kt +++ b/app/src/main/java/team/aliens/dms/android/app/MainActivity.kt @@ -8,6 +8,9 @@ import androidx.compose.material3.windowsizeclass.ExperimentalMaterial3WindowSiz import androidx.compose.material3.windowsizeclass.calculateWindowSizeClass import androidx.core.view.WindowCompat import com.google.accompanist.adaptive.calculateDisplayFeatures +import com.google.android.play.core.appupdate.AppUpdateManagerFactory +import com.google.android.play.core.install.model.AppUpdateType +import com.google.android.play.core.install.model.UpdateAvailability import dagger.hilt.android.AndroidEntryPoint import kotlinx.coroutines.flow.StateFlow import team.aliens.dms.android.core.designsystem.DmsTheme @@ -30,6 +33,7 @@ class MainActivity : ComponentActivity() { WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, ) + checkAppUpdate() setContent { val windowSizeClass = calculateWindowSizeClass(activity = this) val displayFeatures = calculateDisplayFeatures(activity = this) @@ -43,4 +47,23 @@ class MainActivity : ComponentActivity() { } } } + + private fun checkAppUpdate() { + val appUpdateManager = AppUpdateManagerFactory.create(this) + val appUpdateInfoTask = appUpdateManager.appUpdateInfo + + appUpdateInfoTask.addOnSuccessListener { appUpdateInfo -> + val isUpdateAvailable = + appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE + + if (isUpdateAvailable && appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.IMMEDIATE)) { + appUpdateManager.startUpdateFlowForResult( + appUpdateInfo, + AppUpdateType.IMMEDIATE, + this, + 0, + ) + } + } + } } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 3863c9049..1d7124e6f 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -4,6 +4,7 @@ accompanist = "0.34.0" androidx-window = "1.3.0-alpha02" activity = "1.8.2" appcompat = "1.6.1" +appUpdate = "2.1.0" core = "1.12.0" datastorePreferences = "1.0.0" espresso = "3.5.1" @@ -58,6 +59,7 @@ androidx-compose-material = { group = "androidx.compose.material3", name = "mate androidx-compose-material-window = { group = "androidx.compose.material3", name = "material3-window-size-class-android", version.ref = "materialCompose" } androidx-navigation-compose = { module = "androidx.navigation:navigation-compose", version.ref = "navigation" } androidx-hilt-navigation-compose = { module = "androidx.hilt:hilt-navigation-compose", version.ref = "hiltNavigation" } +app-update = { module = "com.google.android.play:app-update-ktx", version.ref = "appUpdate" } composeDestinations = { group = "io.github.raamcosta.compose-destinations", name = "animations-core", version.ref = "composeDestination" } composeDestinations-ksp = { group = "io.github.raamcosta.compose-destinations", name = "ksp", version.ref = "composeDestination" } javax-inject = { module = "javax.inject:javax.inject", version.ref = "javaxInject" }