Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions app/src/main/java/com/osfans/trime/data/theme/ColorManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,22 @@ object ColorManager {
var activeColorScheme: ColorScheme
get() = _activeColorScheme
set(value) {
if (_activeColorScheme == value) return
if (this::_activeColorScheme.isInitialized && _activeColorScheme == value) return
_activeColorScheme = value
lightModeColorScheme =
runCatching {
_activeColorScheme.values["light_scheme"]?.let { colorScheme(it) }
}.getOrNull()
darkModeColorScheme =
runCatching {
_activeColorScheme.values["dark_scheme"]?.let { colorScheme(it) }
}.getOrNull()
fireChange()
}

private val lightModeColorScheme: ColorScheme? =
runCatching {
_activeColorScheme.values["light_scheme"]?.let { colorScheme(it) }
}.getOrNull()
private var lightModeColorScheme: ColorScheme? = null

private val darkModeColorScheme: ColorScheme? =
runCatching {
_activeColorScheme.values["dark_scheme"]?.let { colorScheme(it) }
}.getOrNull()
private var darkModeColorScheme: ColorScheme? = null

private val defaultFallbackColors =
mapOf(
Expand Down Expand Up @@ -124,7 +126,7 @@ object ColorManager {

fun init(configuration: Configuration) {
isNightMode = configuration.isNightMode()
_activeColorScheme = evaluateActiveColorScheme()
activeColorScheme = evaluateActiveColorScheme()
}

fun onSystemNightModeChange(isNight: Boolean) {
Expand All @@ -145,7 +147,7 @@ object ColorManager {
freeCaches()
this.theme = theme
val newScheme = evaluateActiveColorScheme()
_activeColorScheme = newScheme
activeColorScheme = newScheme
normalModeColor = newScheme.id
}

Expand Down
2 changes: 0 additions & 2 deletions app/src/main/java/com/osfans/trime/ime/keyboard/Keyboard.kt
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ class Keyboard(
/** Keyboard default ascii mode */
var asciiMode = false
private set
var currentAsciiMode = false
var resetAsciiMode = true
private set

Expand Down Expand Up @@ -161,7 +160,6 @@ class Keyboard(

mLabelTransform = obtainString(keyboardConfig, "label_transform", "none")
asciiMode = obtainInt(keyboardConfig, "ascii_mode", 1) == 1
currentAsciiMode = asciiMode
if (!asciiMode) asciiKeyboard = obtainString(keyboardConfig, "ascii_keyboard", "")
resetAsciiMode = obtainBoolean(keyboardConfig, "reset_ascii_mode", true)
landscapeKeyboard = obtainString(keyboardConfig, "landscape_keyboard", "")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ class KeyboardWindow(
if (it.isLock) lastLockKeyboardId = target
dispatchCapsState(it::setShifted)
val isAsciiMode = rime.run { statusCached }.isAsciiMode
if (isAsciiMode != it.currentAsciiMode) {
service.postRimeJob { setRuntimeOption("ascii_mode", it.currentAsciiMode) }
if (isAsciiMode != it.asciiMode) {
service.postRimeJob { setRuntimeOption("ascii_mode", it.asciiMode) }
}
// TODO:为避免过量重构,这里暂时将 currentKeyboard 同步到 KeyboardSwitcher
KeyboardSwitcher.currentKeyboard = it
Expand Down Expand Up @@ -154,8 +154,11 @@ class KeyboardWindow(
".last" -> lastKeyboardId
".last_lock" -> lastLockKeyboardId
".ascii" -> {
val ascii = currentKeyboard?.asciiKeyboard
if (!ascii.isNullOrEmpty() && presetKeyboardIds.contains(ascii)) ascii else currentKeyboardId
var ascii = currentKeyboard?.asciiKeyboard
if (ascii.isNullOrEmpty()) {
ascii = lastLockKeyboardId
}
if (presetKeyboardIds.contains(ascii)) ascii else currentKeyboardId
}
else -> {
id.ifEmpty {
Expand Down Expand Up @@ -267,7 +270,6 @@ class KeyboardWindow(

override fun onRimeOptionUpdated(value: RimeMessage.OptionMessage.Data) {
when (val opt = value.option) {
"ascii_mode" -> currentKeyboard?.currentAsciiMode = value.value
"_hide_key_hint" -> currentKeyboardView?.showKeyHint = !value.value
"_hide_key_symbol" -> currentKeyboardView?.showKeySymbol = !value.value
else -> {
Expand Down
Loading