Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code cleanup: Getting rid of null asserts. #491

Merged
merged 2 commits into from
Oct 14, 2023
Merged
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
37 changes: 21 additions & 16 deletions app/src/main/java/com/dessalines/thumbkey/ComposeKeyboardView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,29 +36,34 @@ class ComposeKeyboardView(
onSwitchLanguage = {
ctx.lifecycleScope.launch {
// Cycle to the next keyboard
val s = settingsState.value!!
val layouts = keyboardLayoutsSetFromString(s.keyboardLayouts).toList()
val currentLayout = s.keyboardLayout
val index = layouts.indexOf(currentLayout)
val nextIndex = (index + 1).mod(layouts.size)
val nextLayout = layouts.getOrNull(nextIndex)
nextLayout?.let { layout ->
val s2 = s.copy(keyboardLayout = layout)
settingsRepo.update(s2)
val state = settingsState.value
state?.let { s ->

val layouts = keyboardLayoutsSetFromString(s.keyboardLayouts).toList()
val currentLayout = s.keyboardLayout
val index = layouts.indexOf(currentLayout)
val nextIndex = (index + 1).mod(layouts.size)
val nextLayout = layouts.getOrNull(nextIndex)
nextLayout?.let { layout ->
val s2 = s.copy(keyboardLayout = layout)
settingsRepo.update(s2)

// Display the new layout's name on the screen
val layoutName = KeyboardLayout.entries.find { it.index == nextLayout }?.keyboardDefinition!!.title
Toast.makeText(context, "$layoutName", Toast.LENGTH_SHORT).show()
// Display the new layout's name on the screen
val layoutName = KeyboardLayout.entries.find { it.index == nextLayout }?.keyboardDefinition?.title
Toast.makeText(context, layoutName, Toast.LENGTH_SHORT).show()
}
}
}
},
onSwitchPosition = {
ctx.lifecycleScope.launch {
// Cycle to the next position
val s = settingsState.value!!
val nextPosition = (s.position + 1).mod(3)
val s2 = s.copy(position = nextPosition)
settingsRepo.update(s2)
val state = settingsState.value
state?.let { s ->
val nextPosition = (s.position + 1).mod(3)
val s2 = s.copy(position = nextPosition)
settingsRepo.update(s2)
}
}
},
)
Expand Down