diff --git a/sample/app/src/main/kotlin/app/cash/boxapp/install/Module.kt b/sample/app/src/main/kotlin/app/cash/boxapp/install/Module.kt
index 92931fc..c60b617 100644
--- a/sample/app/src/main/kotlin/app/cash/boxapp/install/Module.kt
+++ b/sample/app/src/main/kotlin/app/cash/boxapp/install/Module.kt
@@ -16,5 +16,6 @@
package app.cash.boxapp.install
internal enum class Module(val id: String) {
+ BigBox("bigboxfeature"),
ExtraBigBox("extrabigboxfeature"),
}
diff --git a/sample/app/src/main/kotlin/app/cash/boxapp/install/SplitInstallHelper.kt b/sample/app/src/main/kotlin/app/cash/boxapp/install/SplitInstallHelper.kt
index 1cb62d6..f7e626f 100644
--- a/sample/app/src/main/kotlin/app/cash/boxapp/install/SplitInstallHelper.kt
+++ b/sample/app/src/main/kotlin/app/cash/boxapp/install/SplitInstallHelper.kt
@@ -19,6 +19,7 @@ import android.content.Context
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.platform.LocalContext
+import com.google.android.play.core.ktx.requestDeferredUninstall
import com.google.android.play.core.ktx.requestInstall
import com.google.android.play.core.ktx.status
import com.google.android.play.core.splitinstall.SplitInstallManager
@@ -62,4 +63,8 @@ internal class SplitInstallHelper(
suspend fun requestInstall(module: Module) {
splitInstallManager.requestInstall(modules = listOf(module.id))
}
+
+ suspend fun requestUninstall(module: Module) {
+ splitInstallManager.requestDeferredUninstall(moduleNames = listOf(module.id))
+ }
}
diff --git a/sample/app/src/main/kotlin/app/cash/boxapp/ui/HomeScreen.kt b/sample/app/src/main/kotlin/app/cash/boxapp/ui/HomeScreen.kt
index 558d11f..4e5a177 100644
--- a/sample/app/src/main/kotlin/app/cash/boxapp/ui/HomeScreen.kt
+++ b/sample/app/src/main/kotlin/app/cash/boxapp/ui/HomeScreen.kt
@@ -18,10 +18,11 @@ package app.cash.boxapp.ui
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
-import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
+import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
+import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material.Button
@@ -37,6 +38,7 @@ import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.font.FontWeight
@@ -63,8 +65,8 @@ internal fun HomeScreen() {
Column(
modifier = Modifier
- .padding(10.dp)
- .background(color = Color(196, 255, 233)),
+ .background(color = Color(196, 255, 233))
+ .padding(10.dp),
) {
// The "My Boxes" tab.
Row(modifier = Modifier.weight(1f)) {
@@ -78,35 +80,82 @@ internal fun HomeScreen() {
}
}
- Box(modifier = Modifier.fillMaxWidth(), contentAlignment = Alignment.Center) {
- Button(
- onClick = {
- scope.launch { installHelper.requestInstall(Module.ExtraBigBox) }
+ Column(modifier = Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally) {
+ InstallButton(
+ text = buildAnnotatedString {
+ append("Install ")
+ withStyle(SpanStyle(fontWeight = FontWeight.Black)) {
+ append("EXTRA")
+ }
+ append(" Big Box")
},
- colors = ButtonDefaults.buttonColors(Color(0, 222, 133)),
+ isLoading = isSplitInstalling,
) {
- Row(
- verticalAlignment = Alignment.CenterVertically,
- horizontalArrangement = Arrangement.spacedBy(8.dp),
- ) {
- Text(
- text = buildAnnotatedString {
- append("Install ")
- withStyle(SpanStyle(fontWeight = FontWeight.Black)) {
- append("EXTRA")
- }
- append(" Big Box")
- },
- )
- AnimatedVisibility(visible = isSplitInstalling) {
- CircularProgressIndicator(
- modifier = Modifier.size(16.dp),
- color = MaterialTheme.colors.onBackground,
- strokeWidth = 2.dp,
- )
+ scope.launch { installHelper.requestInstall(Module.ExtraBigBox) }
+ }
+ UninstallButton(
+ onClick = {
+ scope.launch { installHelper.requestUninstall(Module.ExtraBigBox) }
+ },
+ text = buildAnnotatedString {
+ append("Uninstall ")
+ withStyle(SpanStyle(fontWeight = FontWeight.Black)) {
+ append("EXTRA")
}
- }
+ append(" Big Box")
+ },
+ )
+
+ Spacer(modifier = Modifier.height(16.dp))
+
+ InstallButton(
+ text = buildAnnotatedString {
+ append("Install Big Box")
+ },
+ isLoading = isSplitInstalling,
+ ) {
+ scope.launch { installHelper.requestInstall(Module.BigBox) }
+ }
+ UninstallButton(
+ onClick = {
+ scope.launch { installHelper.requestUninstall(Module.BigBox) }
+ },
+ text = buildAnnotatedString {
+ append("Uninstall Big Box")
+ },
+ )
+ }
+ }
+}
+
+@Composable
+private fun InstallButton(text: AnnotatedString, isLoading: Boolean, onClick: () -> Unit) {
+ Button(
+ onClick = onClick,
+ colors = ButtonDefaults.buttonColors(Color(0, 222, 133)),
+ ) {
+ Row(
+ verticalAlignment = Alignment.CenterVertically,
+ horizontalArrangement = Arrangement.spacedBy(8.dp),
+ ) {
+ Text(text = text)
+ AnimatedVisibility(visible = isLoading) {
+ CircularProgressIndicator(
+ modifier = Modifier.size(16.dp),
+ color = MaterialTheme.colors.onBackground,
+ strokeWidth = 2.dp,
+ )
}
}
}
}
+
+@Composable
+private fun UninstallButton(text: AnnotatedString, onClick: () -> Unit) {
+ Button(
+ onClick = onClick,
+ colors = ButtonDefaults.buttonColors(Color(234, 67, 67)),
+ ) {
+ Text(text = text)
+ }
+}
diff --git a/sample/bigboxfeature/src/main/AndroidManifest.xml b/sample/bigboxfeature/src/main/AndroidManifest.xml
index feedb15..0b88bb2 100644
--- a/sample/bigboxfeature/src/main/AndroidManifest.xml
+++ b/sample/bigboxfeature/src/main/AndroidManifest.xml
@@ -7,6 +7,6 @@
-
+
\ No newline at end of file