This repository has been archived by the owner on Apr 24, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from boswelja/incoming-messages-flow
Replace message listener with a Flow
- Loading branch information
Showing
18 changed files
with
138 additions
and
271 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
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
38 changes: 38 additions & 0 deletions
38
core/src/main/kotlin/com/boswelja/watchconnection/core/Message.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,38 @@ | ||
package com.boswelja.watchconnection.core | ||
|
||
import java.util.UUID | ||
|
||
/** | ||
* A data class containing information about a received message. | ||
* @param sourceWatchId The [Watch.id] of the watch that sent the message. | ||
* @param message The message itself. | ||
* @param data Any data that may have been included with the message, or null if there is none. | ||
*/ | ||
data class Message( | ||
val sourceWatchId: UUID, | ||
val message: String, | ||
val data: ByteArray? | ||
) { | ||
override fun equals(other: Any?): Boolean { | ||
if (this === other) return true | ||
if (javaClass != other?.javaClass) return false | ||
|
||
other as Message | ||
|
||
if (sourceWatchId != other.sourceWatchId) return false | ||
if (message != other.message) return false | ||
if (data != null) { | ||
if (other.data == null) return false | ||
if (!data.contentEquals(other.data)) return false | ||
} else if (other.data != null) return false | ||
|
||
return true | ||
} | ||
|
||
override fun hashCode(): Int { | ||
var result = sourceWatchId.hashCode() | ||
result = 31 * result + message.hashCode() | ||
result = 31 * result + (data?.contentHashCode() ?: 0) | ||
return result | ||
} | ||
} |
17 changes: 0 additions & 17 deletions
17
core/src/main/kotlin/com/boswelja/watchconnection/core/MessageListener.kt
This file was deleted.
Oops, something went wrong.
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
5 changes: 1 addition & 4 deletions
5
test/src/test/kotlin/com/boswelja/watchconnection/core/ConcreteMessageReceiver.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,14 +1,11 @@ | ||
package com.boswelja.watchconnection.core | ||
|
||
import android.content.Context | ||
import java.util.UUID | ||
|
||
class ConcreteMessageReceiver : MessageReceiver() { | ||
|
||
override suspend fun onMessageReceived( | ||
context: Context, | ||
sourceWatchId: UUID, | ||
message: String, | ||
data: ByteArray? | ||
message: Message | ||
) { } | ||
} |
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
Oops, something went wrong.