1+ package com.android.developers.testing.repository
2+
3+ import android.graphics.Bitmap
4+ import com.android.developers.androidify.watchface.WatchFaceAsset
5+ import com.android.developers.androidify.watchface.transfer.WatchFaceInstallationRepository
6+ import com.android.developers.androidify.wear.common.ConnectedWatch
7+ import com.android.developers.androidify.wear.common.WatchFaceActivationStrategy
8+ import com.android.developers.androidify.wear.common.WatchFaceInstallError
9+ import com.android.developers.androidify.wear.common.WatchFaceInstallationStatus
10+ import kotlinx.coroutines.delay
11+ import kotlinx.coroutines.flow.MutableStateFlow
12+ import kotlinx.coroutines.flow.asStateFlow
13+ import java.util.UUID
14+
15+ class FakeWatchFaceInstallationRepository : WatchFaceInstallationRepository {
16+ private val watch = ConnectedWatch (
17+ nodeId = " 1234" ,
18+ displayName = " Pixel Watch" ,
19+ hasAndroidify = true ,
20+ )
21+
22+ private val watchFaceAsset = WatchFaceAsset (
23+ id = " watch_face_1" ,
24+ previewPath = com.android.developers.androidify.results.R .drawable.watch_face_preview,
25+ )
26+
27+ private var transferId = generateTransferId()
28+
29+ private val _connectedWatch = MutableStateFlow <ConnectedWatch ?>(null )
30+ override val connectedWatch = _connectedWatch .asStateFlow()
31+
32+ private val _watchFaceInstallationStatus =
33+ MutableStateFlow <WatchFaceInstallationStatus >(WatchFaceInstallationStatus .NotStarted )
34+ override val watchFaceInstallationUpdates = _watchFaceInstallationStatus .asStateFlow()
35+
36+ override suspend fun createAndTransferWatchFace (
37+ connectedWatch : ConnectedWatch ,
38+ watchFace : WatchFaceAsset ,
39+ bitmap : Bitmap ,
40+ ): WatchFaceInstallError {
41+ transferId = generateTransferId()
42+ delay(5_000 )
43+ _watchFaceInstallationStatus .value = WatchFaceInstallationStatus .Complete (
44+ success = true ,
45+ otherNodeId = " 5678" ,
46+ transferId = transferId,
47+ activationStrategy = WatchFaceActivationStrategy .NO_ACTION_NEEDED ,
48+ validationToken = " 1234abcd" ,
49+ installError = WatchFaceInstallError .NO_ERROR ,
50+ )
51+ return WatchFaceInstallError .NO_ERROR
52+ }
53+
54+ override suspend fun getAvailableWatchFaces (): Result <List <WatchFaceAsset >> {
55+ return Result .success(listOf (watchFaceAsset))
56+ }
57+
58+ override suspend fun resetInstallationStatus () {
59+ transferId = generateTransferId()
60+ _watchFaceInstallationStatus .value = WatchFaceInstallationStatus .NotStarted
61+ }
62+
63+ private fun generateTransferId () = UUID .randomUUID().toString().take(8 )
64+
65+ public fun setWatchAsConnected () {
66+ _connectedWatch .value = watch
67+ }
68+ }
0 commit comments