Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: rename RimeEvent to RimeNotification
- Loading branch information
1 parent
77996e2
commit ba27779
Showing
4 changed files
with
79 additions
and
80 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 was deleted.
Oops, something went wrong.
62 changes: 62 additions & 0 deletions
62
app/src/main/java/com/osfans/trime/core/RimeNotification.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,62 @@ | ||
package com.osfans.trime.core | ||
|
||
sealed class RimeNotification { | ||
|
||
abstract val messageType: MessageType | ||
|
||
data class SchemaNotification(val messageValue: String) : | ||
RimeNotification() { | ||
override val messageType: MessageType | ||
get() = MessageType.Schema | ||
|
||
val schemaId get() = messageValue.substringBefore('/') | ||
val schemaName get() = messageValue.substringAfter('/') | ||
|
||
override fun toString() = "SchemaEvent(schemaId=$schemaId, schemaName=$schemaName" | ||
} | ||
|
||
data class OptionNotification(val messageValue: String) : | ||
RimeNotification() { | ||
override val messageType: MessageType | ||
get() = MessageType.Option | ||
|
||
val option = messageValue.substringAfter('!') | ||
val value = !messageValue.startsWith('!') | ||
|
||
override fun toString() = "OptionNotification(option=$option, value=$value)" | ||
} | ||
|
||
data class DeployNotification(val messageValue: String) : | ||
RimeNotification() { | ||
override val messageType: MessageType | ||
get() = MessageType.Deploy | ||
|
||
val state = messageValue | ||
|
||
override fun toString() = "DeployNotification(state=$state)" | ||
} | ||
|
||
data class UnknownNotification(val messageValue: String) : | ||
RimeNotification() { | ||
override val messageType: MessageType | ||
get() = MessageType.Unknown | ||
} | ||
|
||
enum class MessageType { | ||
Schema, | ||
Option, | ||
Deploy, | ||
Unknown, | ||
} | ||
|
||
companion object RimeNotificationHandler { | ||
@JvmStatic | ||
fun create(type: String, value: String) = | ||
when (type) { | ||
"schema" -> SchemaNotification(value) | ||
"option" -> OptionNotification(value) | ||
"deploy" -> DeployNotification(value) | ||
else -> UnknownNotification(value) | ||
} | ||
} | ||
} |
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