Skip to content

Commit ec7b766

Browse files
authored
Merge pull request #146 from garanj/main
Removes perceived delay on initial watch face transfers
2 parents e5eab94 + 2b316b6 commit ec7b766

File tree

12 files changed

+75
-20
lines changed

12 files changed

+75
-20
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ class FakeWatchFaceInstallationRepository : WatchFaceInstallationRepository {
7575
_watchFaceInstallationStatus.value = WatchFaceInstallationStatus.NotStarted
7676
}
7777

78+
override suspend fun prepareForTransfer() {
79+
transferId = generateTransferId()
80+
_watchFaceInstallationStatus.value = WatchFaceInstallationStatus.Preparing
81+
}
82+
7883
private fun generateTransferId() = UUID.randomUUID().toString().take(8)
7984

8085
public fun setWatchAsConnected() {

feature/results/src/androidTest/java/com/android/developers/androidify/results/ResultsScreenTest.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@ class ResultsScreenTest {
190190
val configProvider = ConfigProvider(TestRemoteConfigDataSource(false))
191191
val viewModel = ResultsViewModel(testUri, originalImageUrl = testUri, null, configProvider)
192192

193-
194193
composeTestRule.setContent {
195194
// Disable animation
196195
SharedElementContextPreview {

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import dagger.assisted.Assisted
3535
import dagger.assisted.AssistedFactory
3636
import dagger.assisted.AssistedInject
3737
import dagger.hilt.android.lifecycle.HiltViewModel
38+
import kotlinx.coroutines.Dispatchers
3839
import kotlinx.coroutines.Job
3940
import kotlinx.coroutines.flow.MutableStateFlow
4041
import kotlinx.coroutines.flow.SharingStarted.Companion.WhileSubscribed
@@ -368,10 +369,11 @@ class CustomizeExportViewModel @AssistedInject constructor(
368369

369370
fun installWatchFace() {
370371
val watchFaceToInstall = _state.value.watchFaceSelectionState.selectedWatchFace ?: return
371-
transferJob = viewModelScope.launch {
372-
val bitmap = state.value.exportImageCanvas.imageBitmap
373-
val watch = state.value.connectedWatch
374-
if (watch != null && bitmap != null) {
372+
val bitmap = state.value.exportImageCanvas.imageBitmap
373+
val watch = state.value.connectedWatch
374+
if (watch != null && bitmap != null) {
375+
transferJob = viewModelScope.launch(Dispatchers.Default) {
376+
watchfaceInstallationRepository.prepareForTransfer()
375377
val wfBitmap = imageGenerationRepository.removeBackground(bitmap)
376378
val response = watchfaceInstallationRepository
377379
.createAndTransferWatchFace(watch, watchFaceToInstall, wfBitmap)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ fun getPlaceholderBotUri(): Uri =
3232

3333
@Composable
3434
fun getPlaceholderBotBitmap(): Bitmap =
35-
ImageBitmap.imageResource(id = R.drawable.placeholderbot).asAndroidBitmap()
35+
ImageBitmap.imageResource(id = R.drawable.placeholderbot).asAndroidBitmap()
Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ import com.android.developers.androidify.theme.AndroidifyTheme
3737
import com.android.developers.androidify.watchface.WatchFaceAsset
3838

3939
@Composable
40-
fun SendingWatchFacePanel(
40+
fun TransferringWatchFacePanel(
4141
modifier: Modifier = Modifier,
42+
transferLabel: String,
4243
selectedWatchFace: WatchFaceAsset?,
4344
) {
4445
Column(
@@ -61,8 +62,8 @@ fun SendingWatchFacePanel(
6162
}
6263
Spacer(modifier = Modifier.height(24.dp))
6364
WatchFacePanelButton(
64-
modifier = modifier.padding(horizontal = 16.dp),
65-
buttonText = stringResource(R.string.sending_to_watch),
65+
modifier = Modifier.padding(horizontal = 16.dp),
66+
buttonText = transferLabel,
6667
isSending = true,
6768
colors = ButtonDefaults.buttonColors(
6869
contentColor = MaterialTheme.colorScheme.onSurface,
@@ -81,8 +82,25 @@ private fun SendingWatchFacePanelPreview() {
8182
previewPath = R.drawable.watch_face_preview,
8283
)
8384
AndroidifyTheme {
84-
SendingWatchFacePanel(
85+
TransferringWatchFacePanel(
8586
selectedWatchFace = watchFace1,
87+
transferLabel = stringResource(R.string.sending_to_watch),
88+
)
89+
}
90+
}
91+
92+
@OptIn(ExperimentalMaterial3Api::class)
93+
@Preview(showBackground = true)
94+
@Composable
95+
private fun PreparingWatchFacePanelPreview() {
96+
val watchFace1 = WatchFaceAsset(
97+
id = "watch_face_1",
98+
previewPath = R.drawable.watch_face_preview,
99+
)
100+
AndroidifyTheme {
101+
TransferringWatchFacePanel(
102+
selectedWatchFace = watchFace1,
103+
transferLabel = stringResource(R.string.preparing_to_send),
86104
)
87105
}
88106
}

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

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@ package com.android.developers.androidify.customize.watchface
1717

1818
import androidx.compose.animation.AnimatedContent
1919
import androidx.compose.animation.ContentTransform
20+
import androidx.compose.animation.EnterTransition
21+
import androidx.compose.animation.ExitTransition
2022
import androidx.compose.animation.core.tween
2123
import androidx.compose.animation.fadeIn
2224
import androidx.compose.animation.fadeOut
25+
import androidx.compose.animation.togetherWith
2326
import androidx.compose.foundation.background
2427
import androidx.compose.foundation.layout.Arrangement
2528
import androidx.compose.foundation.layout.Box
@@ -108,14 +111,21 @@ fun WatchFaceModalSheet(
108111
AnimatedContent(
109112
targetState = installationStatus,
110113
transitionSpec = {
111-
ContentTransform(
112-
targetContentEnter = fadeIn(
113-
animationSpec = tween(durationMillis = 500),
114-
),
115-
initialContentExit = fadeOut(
116-
animationSpec = tween(durationMillis = 500),
117-
),
118-
)
114+
if (
115+
initialState is WatchFaceInstallationStatus.Preparing &&
116+
targetState is WatchFaceInstallationStatus.Sending
117+
) {
118+
EnterTransition.None togetherWith ExitTransition.None
119+
} else {
120+
ContentTransform(
121+
targetContentEnter = fadeIn(
122+
animationSpec = tween(durationMillis = 500),
123+
),
124+
initialContentExit = fadeOut(
125+
animationSpec = tween(durationMillis = 500),
126+
),
127+
)
128+
}
119129
},
120130
) { installationStatus ->
121131
when (installationStatus) {
@@ -164,9 +174,17 @@ fun WatchFaceModalSheet(
164174
}
165175
}
166176

177+
is WatchFaceInstallationStatus.Preparing -> {
178+
TransferringWatchFacePanel(
179+
selectedWatchFace = watchFaceSelectionState.selectedWatchFace,
180+
transferLabel = stringResource(R.string.preparing_to_send),
181+
)
182+
}
183+
167184
is WatchFaceInstallationStatus.Sending -> {
168-
SendingWatchFacePanel(
185+
TransferringWatchFacePanel(
169186
selectedWatchFace = watchFaceSelectionState.selectedWatchFace,
187+
transferLabel = stringResource(R.string.sending_to_watch),
170188
)
171189
}
172190

feature/results/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
<item>Hey good looking!</item>
4343
</string-array>
4444
<string name="send_to_watch">Send to watch</string>
45+
<string name="preparing_to_send">Preparing…</string>
4546
<string name="sending_to_watch">Sending to watch…</string>
4647
<string name="watch_face_sent">Watch face sent</string>
4748
<string name="send_to_watch_device">%s detected.</string>

watchface/src/main/java/com/android/developers/androidify/watchface/di/WatchFaceModule.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class WatchFaceModule {
7070
remoteConfigDataSource: RemoteConfigDataSource,
7171
): WatchFaceInstallationRepository {
7272
val watchFacesEnabled = remoteConfigDataSource.watchfaceFeatureEnabled()
73-
return if (Build.VERSION.SDK_INT >= MIN_WATCH_FACE_SDK_VERSION && watchFacesEnabled) {
73+
return if (Build.VERSION.SDK_INT >= MIN_WATCH_FACE_SDK_VERSION && watchFacesEnabled || true) {
7474
supportedImpl
7575
} else {
7676
noSupportImpl

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,6 @@ class EmptyWatchFaceInstallationRepositoryImpl @Inject constructor() : WatchFace
4646
}
4747

4848
override suspend fun resetInstallationStatus() { }
49+
50+
override suspend fun prepareForTransfer() { }
4951
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ interface WatchFaceInstallationRepository {
6868
suspend fun getAvailableWatchFaces(): Result<List<WatchFaceAsset>>
6969

7070
suspend fun resetInstallationStatus()
71+
72+
suspend fun prepareForTransfer()
7173
}
7274

7375
class WatchFaceInstallationRepositoryImpl @Inject constructor(
@@ -127,4 +129,8 @@ class WatchFaceInstallationRepositoryImpl @Inject constructor(
127129
wearAssetTransmitter.resetTransferId()
128130
manualStatusUpdates.tryEmit(WatchFaceInstallationStatus.NotStarted)
129131
}
132+
133+
override suspend fun prepareForTransfer() {
134+
manualStatusUpdates.tryEmit(WatchFaceInstallationStatus.Preparing)
135+
}
130136
}

0 commit comments

Comments
 (0)