-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Send a signal to the watch to sync bookmarks (#296)
- Loading branch information
Showing
12 changed files
with
94 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
shared/data/src/androidMain/kotlin/fr/androidmakers/store/wear/WearMessagingImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package fr.androidmakers.store.wear | ||
|
||
import android.content.Context | ||
import android.util.Log | ||
import com.google.android.gms.wearable.Wearable | ||
import kotlinx.coroutines.tasks.await | ||
|
||
class WearMessagingImpl(context: Context) : WearMessaging { | ||
companion object { | ||
const val MESSAGE_SYNC_BOOKMARKS = "syncBookmarks" | ||
} | ||
|
||
private val nodeClient = Wearable.getNodeClient(context) | ||
private val messageClient = Wearable.getMessageClient(context) | ||
|
||
override suspend fun sendSyncBookmarksMessage() { | ||
try { | ||
val allNodeIds = nodeClient.connectedNodes.await().map { it.id } | ||
for (nodeId in allNodeIds) { | ||
messageClient.sendMessage(nodeId, MESSAGE_SYNC_BOOKMARKS, null).await() | ||
} | ||
} catch (t: Throwable) { | ||
Log.w("WearMessagingImpl", "Error sending message", t) | ||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
shared/data/src/commonMain/kotlin/fr/androidmakers/store/wear/WearMessaging.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package fr.androidmakers.store.wear | ||
|
||
interface WearMessaging { | ||
suspend fun sendSyncBookmarksMessage() | ||
} |
9 changes: 9 additions & 0 deletions
9
shared/data/src/commonMain/kotlin/fr/androidmakers/store/wear/WearMessagingRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package fr.androidmakers.store.wear | ||
|
||
import fr.androidmakers.domain.repo.MessagingRepository | ||
|
||
class WearMessagingRepository(private val wearMessaging: WearMessaging) : MessagingRepository { | ||
override suspend fun sendSyncBookmarksMessage() { | ||
wearMessaging.sendSyncBookmarksMessage() | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
shared/data/src/iosMain/kotlin/fr/androidmakers/store/wear/WearMessagingImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package fr.androidmakers.store.wear | ||
|
||
class WearMessagingImpl : WearMessaging { | ||
override suspend fun sendSyncBookmarksMessage() { | ||
// No-op on iOS | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 6 additions & 3 deletions
9
...ain/src/commonMain/kotlin/fr/androidmakers/domain/interactor/SetSessionBookmarkUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,21 @@ | ||
package fr.androidmakers.domain.interactor | ||
|
||
import fr.androidmakers.domain.repo.BookmarksRepository | ||
import fr.androidmakers.domain.repo.MessagingRepository | ||
import fr.androidmakers.domain.repo.SessionsRepository | ||
import fr.androidmakers.domain.repo.UserRepository | ||
|
||
class SetSessionBookmarkUseCase( | ||
private val userRepository: UserRepository, | ||
private val sessionsRepository: SessionsRepository, | ||
private val bookmarksRepository: BookmarksRepository | ||
private val userRepository: UserRepository, | ||
private val sessionsRepository: SessionsRepository, | ||
private val bookmarksRepository: BookmarksRepository, | ||
private val messagingRepository: MessagingRepository, | ||
) { | ||
suspend operator fun invoke(sessionId: String, isBookmark: Boolean) { | ||
bookmarksRepository.setBookmarked(sessionId, isBookmark) | ||
userRepository.getUser()?.id?.let { token -> | ||
sessionsRepository.setBookmark(token, sessionId, isBookmark) | ||
} | ||
messagingRepository.sendSyncBookmarksMessage() | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
shared/domain/src/commonMain/kotlin/fr/androidmakers/domain/repo/MessagingRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package fr.androidmakers.domain.repo | ||
|
||
interface MessagingRepository { | ||
suspend fun sendSyncBookmarksMessage() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters