-
-
Notifications
You must be signed in to change notification settings - Fork 367
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: handle rime option in sub input components ...
... via newly implemented InputBroadcast(Receiver).
- Loading branch information
1 parent
f767aec
commit ad10afc
Showing
7 changed files
with
87 additions
and
18 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
7 changes: 7 additions & 0 deletions
7
app/src/main/java/com/osfans/trime/ime/broadcast/InputBroadcastReceiver.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 com.osfans.trime.ime.broadcast | ||
|
||
import com.osfans.trime.core.RimeNotification.OptionNotification | ||
|
||
interface InputBroadcastReceiver { | ||
fun onRimeOptionUpdated(value: OptionNotification.Value) {} | ||
} |
30 changes: 30 additions & 0 deletions
30
app/src/main/java/com/osfans/trime/ime/broadcast/InputBroadcaster.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,30 @@ | ||
package com.osfans.trime.ime.broadcast | ||
|
||
import com.osfans.trime.core.RimeNotification.OptionNotification | ||
import com.osfans.trime.ime.dependency.InputScope | ||
import java.util.concurrent.ConcurrentLinkedQueue | ||
|
||
@InputScope | ||
class InputBroadcaster : InputBroadcastReceiver { | ||
private val receivers = ConcurrentLinkedQueue<InputBroadcastReceiver>() | ||
|
||
fun <T> addReceiver(receiver: T) { | ||
if (receiver is InputBroadcastReceiver && receiver !is InputBroadcaster) { | ||
receivers.add(receiver) | ||
} | ||
} | ||
|
||
fun <T> removeReceiver(receiver: T) { | ||
if (receiver is InputBroadcastReceiver && receiver !is InputBroadcaster) { | ||
receivers.remove(receiver) | ||
} | ||
} | ||
|
||
fun clear() { | ||
receivers.clear() | ||
} | ||
|
||
override fun onRimeOptionUpdated(value: OptionNotification.Value) { | ||
receivers.forEach { it.onRimeOptionUpdated(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
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