Skip to content

Commit 2ede715

Browse files
committed
Addresses comments
1 parent 88b3e8f commit 2ede715

File tree

7 files changed

+28
-16
lines changed

7 files changed

+28
-16
lines changed

core/testing/src/main/java/com/android/developers/testing/repository/FakeWatchFaceInstallationRepository.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ class FakeWatchFaceInstallationRepository : WatchFaceInstallationRepository {
8080
_watchFaceInstallationStatus.value = WatchFaceInstallationStatus.Preparing
8181
}
8282

83+
override suspend fun installAndroidify(nodeId: String) { }
84+
8385
private fun generateTransferId() = UUID.randomUUID().toString().take(8)
8486

8587
public fun setWatchAsConnected() {

feature/results/src/main/java/com/android/developers/androidify/customize/CustomizeExportScreen.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ fun CustomizeAndExportScreen(
131131
viewModel.installWatchFace()
132132
},
133133
onInstallAndroidifyClicked = {
134-
viewModel.installAndroidifyOnWatch()
134+
viewModel.launchPlayInstallOnWatch()
135135
},
136136
onResetWatchFaceSend = {
137137
viewModel.resetWatchFaceSend()
@@ -154,7 +154,7 @@ private fun CustomizeExportContents(
154154
onToolSelected: (CustomizeTool) -> Unit,
155155
onSelectedToolStateChanged: (ToolState) -> Unit,
156156
onInstallWatchFaceClicked: () -> Unit,
157-
onInstallAndroidifyClicked: () -> Unit,
157+
onInstallAndroidifyClicked: suspend () -> Boolean,
158158
onResetWatchFaceSend: () -> Unit,
159159
layoutType: CustomizeExportLayoutType,
160160
snackbarHostState: SnackbarHostState,
@@ -606,7 +606,7 @@ fun CustomizeExportPreview() {
606606
layoutType = CustomizeExportLayoutType.Compact,
607607
onSelectedToolStateChanged = {},
608608
onInstallWatchFaceClicked = {},
609-
onInstallAndroidifyClicked = {},
609+
onInstallAndroidifyClicked = { true },
610610
onResetWatchFaceSend = {},
611611
loadWatchFaces = {},
612612
onWatchFaceSelect = {},
@@ -648,7 +648,7 @@ fun CustomizeExportPreviewLarge() {
648648
layoutType = CustomizeExportLayoutType.Medium,
649649
onSelectedToolStateChanged = {},
650650
onInstallWatchFaceClicked = {},
651-
onInstallAndroidifyClicked = {},
651+
onInstallAndroidifyClicked = { true },
652652
onResetWatchFaceSend = {},
653653
loadWatchFaces = {},
654654
onWatchFaceSelect = {},

feature/results/src/main/java/com/android/developers/androidify/customize/CustomizeExportViewModel.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,13 +368,17 @@ class CustomizeExportViewModel @AssistedInject constructor(
368368
}
369369
}
370370

371-
fun installAndroidifyOnWatch() {
372-
viewModelScope.launch {
371+
suspend fun launchPlayInstallOnWatch(): Boolean {
372+
try {
373373
val watch = state.value.connectedWatch
374374
watch?.let {
375375
watchfaceInstallationRepository.installAndroidify(application.applicationContext, it.nodeId)
376376
}
377+
return true
378+
} catch (e: Exception) {
379+
Timber.e(e, "Failed to open Play Store on watch")
377380
}
381+
return false
378382
}
379383

380384
fun installWatchFace() {

feature/results/src/main/java/com/android/developers/androidify/customize/watchface/InstallAndroidifyPanel.kt

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import androidx.compose.runtime.Composable
3030
import androidx.compose.runtime.getValue
3131
import androidx.compose.runtime.mutableStateOf
3232
import androidx.compose.runtime.remember
33+
import androidx.compose.runtime.rememberCoroutineScope
3334
import androidx.compose.runtime.setValue
3435
import androidx.compose.ui.Alignment
3536
import androidx.compose.ui.Modifier
@@ -40,10 +41,11 @@ import androidx.compose.ui.unit.dp
4041
import com.android.developers.androidify.results.R
4142
import com.android.developers.androidify.theme.AndroidifyTheme
4243
import com.android.developers.androidify.watchface.WatchFaceAsset
44+
import kotlinx.coroutines.launch
4345

4446
@Composable
4547
fun InstallAndroidifyPanel(
46-
onInstallClick: () -> Unit,
48+
onInstallClick: suspend () -> Boolean,
4749
modifier: Modifier = Modifier,
4850
) {
4951
val context = LocalContext.current
@@ -86,14 +88,19 @@ fun InstallAndroidifyPanel(
8688
contentColor = MaterialTheme.colorScheme.surface,
8789
containerColor = MaterialTheme.colorScheme.onSurface,
8890
)
91+
val scope = rememberCoroutineScope()
8992
WatchFacePanelButton(
9093
modifier = modifier.padding(horizontal = 16.dp),
9194
buttonText = buttonText,
9295
iconResId = R.drawable.watch_arrow_24,
9396
onClick = {
9497
if (!isPlayLaunched) {
95-
isPlayLaunched = true
96-
onInstallClick()
98+
scope.launch {
99+
val launchResult = onInstallClick()
100+
if (launchResult) {
101+
isPlayLaunched = true
102+
}
103+
}
97104
}
98105
},
99106
colors = if (isPlayLaunched) {
@@ -111,6 +118,6 @@ fun InstallAndroidifyPanel(
111118
@Composable
112119
private fun InstallAndroidifyPanelPreview() {
113120
AndroidifyTheme {
114-
InstallAndroidifyPanel({})
121+
InstallAndroidifyPanel({ true })
115122
}
116123
}

feature/results/src/main/java/com/android/developers/androidify/customize/watchface/WatchFaceModalSheet.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ import com.android.developers.androidify.wear.common.WatchFaceInstallationStatus
6464
fun WatchFaceModalSheet(
6565
connectedWatch: ConnectedWatch,
6666
onWatchFaceInstallClick: (String) -> Unit,
67-
onAndroidifyInstallClick: () -> Unit,
67+
onAndroidifyInstallClick: suspend () -> Boolean,
6868
installationStatus: WatchFaceInstallationStatus,
6969
sheetState: SheetState,
7070
watchFaceSelectionState: WatchFaceSelectionState,
@@ -246,7 +246,7 @@ private fun WatchFaceModalSheetPreview() {
246246
onLoad = {},
247247
onDismiss = {},
248248
onWatchFaceInstallClick = {},
249-
onAndroidifyInstallClick = {},
249+
onAndroidifyInstallClick = { true },
250250
sheetState = sheetState,
251251
)
252252
}

watchface/src/main/java/com/android/developers/androidify/watchface/transfer/EmptyWatchFaceInstallationRepository.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
package com.android.developers.androidify.watchface.transfer
1717

18-
import android.content.Context
1918
import android.graphics.Bitmap
2019
import com.android.developers.androidify.watchface.WatchFaceAsset
2120
import com.android.developers.androidify.wear.common.ConnectedWatch
@@ -50,5 +49,5 @@ class EmptyWatchFaceInstallationRepositoryImpl @Inject constructor() : WatchFace
5049

5150
override suspend fun prepareForTransfer() { }
5251

53-
override suspend fun installAndroidify(context: Context, nodeId: String) { }
52+
override suspend fun installAndroidify(nodeId: String) { }
5453
}

watchface/src/main/java/com/android/developers/androidify/watchface/transfer/WatchFaceInstallationRepository.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ interface WatchFaceInstallationRepository {
7676

7777
suspend fun prepareForTransfer()
7878

79-
suspend fun installAndroidify(context: Context, nodeId: String)
79+
suspend fun installAndroidify(nodeId: String)
8080
}
8181

8282
class WatchFaceInstallationRepositoryImpl @Inject constructor(
@@ -141,7 +141,7 @@ class WatchFaceInstallationRepositoryImpl @Inject constructor(
141141
manualStatusUpdates.tryEmit(WatchFaceInstallationStatus.Preparing)
142142
}
143143

144-
override suspend fun installAndroidify(context: Context, nodeId: String) {
144+
override suspend fun installAndroidify(nodeId: String) {
145145
val backgroundExecutor = Dispatchers.IO.asExecutor()
146146
val remoteActivityHelper = RemoteActivityHelper(context, backgroundExecutor)
147147

0 commit comments

Comments
 (0)