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

Add more actions for changing keyboard position #1117

Merged
merged 1 commit into from
Oct 17, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import androidx.lifecycle.lifecycleScope
import com.dessalines.thumbkey.db.AppSettingsRepository
import com.dessalines.thumbkey.ui.components.keyboard.KeyboardScreen
import com.dessalines.thumbkey.ui.theme.ThumbkeyTheme
import com.dessalines.thumbkey.utils.KeyboardPosition
import com.dessalines.thumbkey.utils.keyboardLayoutsSetFromDbIndexString
import kotlinx.coroutines.launch

Expand Down Expand Up @@ -59,12 +60,11 @@ class ComposeKeyboardView(
}
}
},
onSwitchPosition = {
onChangePosition = { f ->
ctx.lifecycleScope.launch {
// Cycle to the next position
val state = settingsState.value
state?.let { s ->
val nextPosition = (s.position + 1).mod(3)
val nextPosition = f(KeyboardPosition.entries[s.position]).ordinal
val s2 = s.copy(position = nextPosition)
settingsRepo.update(s2)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ fun specialActionKeyItem(center: KeyC) =
right =
KeyC(
display = KeyDisplay.IconDisplay(Icons.Outlined.LinearScale),
action = SwitchPosition,
action = MoveKeyboard.CycleRight,
color = MUTED,
),
)
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/dessalines/thumbkey/keyboards/T9.kt
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ val KB_T9_MAIN =
bottomRight =
KeyC(
display = KeyDisplay.TextDisplay("↔"),
action = SwitchPosition,
action = MoveKeyboard.CycleRight,
color = MUTED,
),
backgroundColor = SURFACE_VARIANT,
Expand Down Expand Up @@ -554,7 +554,7 @@ val KB_T9_SHIFTED =
bottomRight =
KeyC(
display = KeyDisplay.TextDisplay("↔"),
action = SwitchPosition,
action = MoveKeyboard.CycleRight,
color = MUTED,
),
backgroundColor = SURFACE_VARIANT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import com.dessalines.thumbkey.utils.KeyC
import com.dessalines.thumbkey.utils.KeyDisplay
import com.dessalines.thumbkey.utils.KeyItemC
import com.dessalines.thumbkey.utils.KeyboardDefinitionSettings
import com.dessalines.thumbkey.utils.KeyboardPosition
import com.dessalines.thumbkey.utils.Selection
import com.dessalines.thumbkey.utils.SlideType
import com.dessalines.thumbkey.utils.SwipeDirection
Expand Down Expand Up @@ -118,7 +119,7 @@ fun KeyboardKey(
onToggleCapsLock: () -> Unit,
onAutoCapitalize: (enable: Boolean) -> Unit,
onSwitchLanguage: () -> Unit,
onSwitchPosition: () -> Unit,
onChangePosition: ((old: KeyboardPosition) -> KeyboardPosition) -> Unit,
oppositeCaseKey: KeyItemC? = null,
numericKey: KeyItemC? = null,
dragReturnEnabled: Boolean,
Expand Down Expand Up @@ -235,7 +236,7 @@ fun KeyboardKey(
onToggleCapsLock = onToggleCapsLock,
onAutoCapitalize = onAutoCapitalize,
onSwitchLanguage = onSwitchLanguage,
onSwitchPosition = onSwitchPosition,
onChangePosition = onChangePosition,
)
doneKeyAction(scope, action, isDragged, releasedKey, animationHelperSpeed)
},
Expand All @@ -252,7 +253,7 @@ fun KeyboardKey(
onToggleCapsLock = onToggleCapsLock,
onAutoCapitalize = onAutoCapitalize,
onSwitchLanguage = onSwitchLanguage,
onSwitchPosition = onSwitchPosition,
onChangePosition = onChangePosition,
)
doneKeyAction(scope, action, isDragged, releasedKey, animationHelperSpeed)
if (vibrateOnTap) {
Expand Down Expand Up @@ -501,7 +502,7 @@ fun KeyboardKey(
onToggleCapsLock = onToggleCapsLock,
onAutoCapitalize = onAutoCapitalize,
onSwitchLanguage = onSwitchLanguage,
onSwitchPosition = onSwitchPosition,
onChangePosition = onChangePosition,
)
doneKeyAction(
scope,
Expand Down Expand Up @@ -533,7 +534,7 @@ fun KeyboardKey(
onToggleCapsLock = onToggleCapsLock,
onAutoCapitalize = onAutoCapitalize,
onSwitchLanguage = onSwitchLanguage,
onSwitchPosition = onSwitchPosition,
onChangePosition = onChangePosition,
onToggleEmojiMode = onToggleEmojiMode,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ import kotlin.time.TimeMark
fun KeyboardScreen(
settings: AppSettings?,
onSwitchLanguage: () -> Unit,
onSwitchPosition: () -> Unit,
onChangePosition: ((old: KeyboardPosition) -> KeyboardPosition) -> Unit,
) {
val ctx = LocalContext.current as IMEService

Expand Down Expand Up @@ -310,7 +310,7 @@ fun KeyboardScreen(
}
},
onSwitchLanguage = onSwitchLanguage,
onSwitchPosition = onSwitchPosition,
onChangePosition = onChangePosition,
dragReturnEnabled = dragReturnEnabled,
circularDragEnabled = circularDragEnabled,
clockwiseDragAction = clockwiseDragAction,
Expand Down Expand Up @@ -445,7 +445,7 @@ fun KeyboardScreen(
}
},
onSwitchLanguage = onSwitchLanguage,
onSwitchPosition = onSwitchPosition,
onChangePosition = onChangePosition,
oppositeCaseKey =
when (mode) {
KeyboardMode.MAIN -> keyboardDefinition.modes.shifted
Expand Down
16 changes: 14 additions & 2 deletions app/src/main/java/com/dessalines/thumbkey/utils/Types.kt
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,20 @@ sealed class KeyAction {
val text: String,
) : KeyAction()

sealed class MoveKeyboard : KeyAction() {
class ToPosition(
val position: KeyboardPosition,
) : KeyAction()

data object Left : KeyAction()

data object Right : KeyAction()

data object CycleLeft : KeyAction()

data object CycleRight : KeyAction()
}

data object DeleteWordBeforeCursor : KeyAction()

data object DeleteWordAfterCursor : KeyAction()
Expand All @@ -174,8 +188,6 @@ sealed class KeyAction {

data object SwitchLanguage : KeyAction()

data object SwitchPosition : KeyAction()

data object SwitchIME : KeyAction()

data object SwitchIMEVoice : KeyAction()
Expand Down
35 changes: 33 additions & 2 deletions app/src/main/java/com/dessalines/thumbkey/utils/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ fun performKeyAction(
onToggleCapsLock: () -> Unit,
onAutoCapitalize: (enable: Boolean) -> Unit,
onSwitchLanguage: () -> Unit,
onSwitchPosition: () -> Unit,
onChangePosition: ((old: KeyboardPosition) -> KeyboardPosition) -> Unit,
) {
when (action) {
is KeyAction.CommitText -> {
Expand Down Expand Up @@ -945,8 +945,39 @@ fun performKeyAction(
)
}

is KeyAction.MoveKeyboard.ToPosition -> onChangePosition { action.position }
KeyAction.MoveKeyboard.Left ->
onChangePosition {
when (it) {
KeyboardPosition.Right -> KeyboardPosition.Center
else -> KeyboardPosition.Left
}
}
KeyAction.MoveKeyboard.Right ->
onChangePosition {
when (it) {
KeyboardPosition.Left -> KeyboardPosition.Center
else -> KeyboardPosition.Right
}
}
KeyAction.MoveKeyboard.CycleLeft ->
onChangePosition {
when (it) {
KeyboardPosition.Right -> KeyboardPosition.Center
KeyboardPosition.Center -> KeyboardPosition.Left
KeyboardPosition.Left -> KeyboardPosition.Right
}
}
KeyAction.MoveKeyboard.CycleRight ->
onChangePosition {
when (it) {
KeyboardPosition.Left -> KeyboardPosition.Center
KeyboardPosition.Center -> KeyboardPosition.Right
KeyboardPosition.Right -> KeyboardPosition.Left
}
}

KeyAction.SwitchLanguage -> onSwitchLanguage()
KeyAction.SwitchPosition -> onSwitchPosition()
KeyAction.SwitchIME -> {
val imeManager =
ime.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
Expand Down