Skip to content

Commit

Permalink
Use boolean setting to set key width only if wanted
Browse files Browse the repository at this point in the history
  • Loading branch information
Zwyx committed Feb 14, 2024
1 parent 20499ac commit 53c01b1
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 59 deletions.
27 changes: 18 additions & 9 deletions app/src/main/java/com/dessalines/thumbkey/db/AppDb.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.util.concurrent.Executors

const val DEFAULT_KEY_HEIGHT = 64
const val DEFAULT_KEY_WIDTH = 64
const val DEFAULT_KEY_SIZE = 64
const val DEFAULT_ANIMATION_SPEED = 250
const val DEFAULT_ANIMATION_HELPER_SPEED = 250
const val DEFAULT_POSITION = 0
Expand Down Expand Up @@ -58,13 +57,13 @@ const val DEFAULT_KEY_RADIUS = 0
data class AppSettings(
@PrimaryKey(autoGenerate = true) val id: Int,
@ColumnInfo(
name = "key_height",
defaultValue = DEFAULT_KEY_HEIGHT.toString(),
name = "key_size",
defaultValue = DEFAULT_KEY_SIZE.toString(),
)
val keyHeight: Int,
val keySize: Int,
@ColumnInfo(
name = "key_width",
defaultValue = DEFAULT_KEY_WIDTH.toString(),
defaultValue = "0",
)
val keyWidth: Int,
@ColumnInfo(
Expand Down Expand Up @@ -220,9 +219,9 @@ data class LayoutsUpdate(
data class LookAndFeelUpdate(
val id: Int,
@ColumnInfo(
name = "key_height",
name = "key_size",
)
val keyHeight: Int,
val keySize: Int,
@ColumnInfo(
name = "key_width",
)
Expand Down Expand Up @@ -504,8 +503,17 @@ val MIGRATION_12_13 =
}
}

val MIGRATION_13_14 =
object : Migration(13, 14) {
override fun migrate(db: SupportSQLiteDatabase) {
db.execSQL(
"alter table AppSettings add column key_width INTEGER NOT NULL default 0",
)
}
}

@Database(
version = 13,
version = 14,
entities = [AppSettings::class],
exportSchema = true,
)
Expand Down Expand Up @@ -540,6 +548,7 @@ abstract class AppDB : RoomDatabase() {
MIGRATION_10_11,
MIGRATION_11_12,
MIGRATION_12_13,
MIGRATION_13_14,
)
// Necessary because it can't insert data on creation
.addCallback(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ fun KeyboardKey(
val keyHeight = legendHeight + (keyPadding * 2.0) + (keyBorderWidth * 2.0)
val keyWidth = legendWidth + (keyPadding * 2.0) + (keyBorderWidth * 2.0)
val keySize = (keyHeight + keyWidth) / 2.0
val legendSize = (legendHeight + legendWidth) / 2
val legendPadding = 4.dp + keyBorderWidth.dp

val haptic = LocalHapticFeedback.current
Expand Down Expand Up @@ -519,7 +520,7 @@ fun KeyboardKey(
),
) {
key.swipes?.get(SwipeDirection.TOP_LEFT)?.let {
KeyText(it, (legendWidth - keyBorderWidth).dp, hideLetters, hideSymbols, capsLock)
KeyText(it, (legendSize - keyBorderWidth).dp, hideLetters, hideSymbols, capsLock)
}
}
Box(
Expand All @@ -530,7 +531,7 @@ fun KeyboardKey(
.padding(vertical = yPadding),
) {
key.swipes?.get(SwipeDirection.TOP)?.let {
KeyText(it, (legendWidth - keyBorderWidth).dp, hideLetters, hideSymbols, capsLock)
KeyText(it, (legendSize - keyBorderWidth).dp, hideLetters, hideSymbols, capsLock)
}
}
Box(
Expand All @@ -544,7 +545,7 @@ fun KeyboardKey(
),
) {
key.swipes?.get(SwipeDirection.TOP_RIGHT)?.let {
KeyText(it, (legendWidth - keyBorderWidth).dp, hideLetters, hideSymbols, capsLock)
KeyText(it, (legendSize - keyBorderWidth).dp, hideLetters, hideSymbols, capsLock)
}
}
Box(
Expand All @@ -555,7 +556,7 @@ fun KeyboardKey(
.padding(horizontal = legendPadding),
) {
key.swipes?.get(SwipeDirection.LEFT)?.let {
KeyText(it, (legendWidth - keyBorderWidth).dp, hideLetters, hideSymbols, capsLock)
KeyText(it, (legendSize - keyBorderWidth).dp, hideLetters, hideSymbols, capsLock)
}
}
Box(
Expand All @@ -565,7 +566,7 @@ fun KeyboardKey(
.fillMaxSize()
.padding(legendPadding),
) {
KeyText(key.center, (legendWidth - keyBorderWidth).dp, hideLetters, hideSymbols, capsLock)
KeyText(key.center, (legendSize - keyBorderWidth).dp, hideLetters, hideSymbols, capsLock)
}

Box(
Expand All @@ -576,7 +577,7 @@ fun KeyboardKey(
.padding(horizontal = legendPadding),
) {
key.swipes?.get(SwipeDirection.RIGHT)?.let {
KeyText(it, (legendWidth - keyBorderWidth).dp, hideLetters, hideSymbols, capsLock)
KeyText(it, (legendSize - keyBorderWidth).dp, hideLetters, hideSymbols, capsLock)
}
}
Box(
Expand All @@ -590,7 +591,7 @@ fun KeyboardKey(
),
) {
key.swipes?.get(SwipeDirection.BOTTOM_LEFT)?.let {
KeyText(it, (legendWidth - keyBorderWidth).dp, hideLetters, hideSymbols, capsLock)
KeyText(it, (legendSize - keyBorderWidth).dp, hideLetters, hideSymbols, capsLock)
}
}
Box(
Expand All @@ -601,7 +602,7 @@ fun KeyboardKey(
.padding(vertical = yPadding),
) {
key.swipes?.get(SwipeDirection.BOTTOM)?.let {
KeyText(it, (legendWidth - keyBorderWidth).dp, hideLetters, hideSymbols, capsLock)
KeyText(it, (legendSize - keyBorderWidth).dp, hideLetters, hideSymbols, capsLock)
}
}
Box(
Expand All @@ -615,7 +616,7 @@ fun KeyboardKey(
),
) {
key.swipes?.get(SwipeDirection.BOTTOM_RIGHT)?.let {
KeyText(it, (legendWidth - keyBorderWidth).dp, hideLetters, hideSymbols, capsLock)
KeyText(it, (legendSize - keyBorderWidth).dp, hideLetters, hideSymbols, capsLock)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@ import com.dessalines.thumbkey.db.DEFAULT_HIDE_LETTERS
import com.dessalines.thumbkey.db.DEFAULT_HIDE_SYMBOLS
import com.dessalines.thumbkey.db.DEFAULT_KEYBOARD_LAYOUT
import com.dessalines.thumbkey.db.DEFAULT_KEY_BORDER_WIDTH
import com.dessalines.thumbkey.db.DEFAULT_KEY_HEIGHT
import com.dessalines.thumbkey.db.DEFAULT_KEY_PADDING
import com.dessalines.thumbkey.db.DEFAULT_KEY_RADIUS
import com.dessalines.thumbkey.db.DEFAULT_KEY_WIDTH
import com.dessalines.thumbkey.db.DEFAULT_KEY_SIZE
import com.dessalines.thumbkey.db.DEFAULT_MIN_SWIPE_LENGTH
import com.dessalines.thumbkey.db.DEFAULT_POSITION
import com.dessalines.thumbkey.db.DEFAULT_PUSHUP_SIZE
Expand Down Expand Up @@ -131,8 +130,8 @@ fun KeyboardScreen(
val backdropColor = MaterialTheme.colorScheme.background
val backdropPadding = 6.dp
val keyPadding = settings?.keyPadding ?: DEFAULT_KEY_PADDING
val legendHeight = settings?.keyHeight ?: DEFAULT_KEY_HEIGHT
val legendWidth = settings?.keyWidth ?: DEFAULT_KEY_WIDTH
val legendHeight = settings?.keySize ?: DEFAULT_KEY_SIZE
val legendWidth = (if ((settings?.keyWidth ?: 0) > 0) settings?.keyWidth else legendHeight) ?: legendHeight
val keyRadius = settings?.keyRadius ?: DEFAULT_KEY_RADIUS

val keyBorderWidthFloat = keyBorderWidth / 10.0f
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,9 @@ import com.dessalines.thumbkey.db.DEFAULT_HIDE_SYMBOLS
import com.dessalines.thumbkey.db.DEFAULT_KEYBOARD_LAYOUT
import com.dessalines.thumbkey.db.DEFAULT_KEY_BORDERS
import com.dessalines.thumbkey.db.DEFAULT_KEY_BORDER_WIDTH
import com.dessalines.thumbkey.db.DEFAULT_KEY_HEIGHT
import com.dessalines.thumbkey.db.DEFAULT_KEY_PADDING
import com.dessalines.thumbkey.db.DEFAULT_KEY_RADIUS
import com.dessalines.thumbkey.db.DEFAULT_KEY_WIDTH
import com.dessalines.thumbkey.db.DEFAULT_KEY_SIZE
import com.dessalines.thumbkey.db.DEFAULT_MIN_SWIPE_LENGTH
import com.dessalines.thumbkey.db.DEFAULT_POSITION
import com.dessalines.thumbkey.db.DEFAULT_PUSHUP_SIZE
Expand Down Expand Up @@ -278,8 +277,8 @@ private fun resetAppSettingsToDefault(
hideLetters = DEFAULT_HIDE_LETTERS,
hideSymbols = DEFAULT_HIDE_SYMBOLS,
keyBorders = DEFAULT_KEY_BORDERS,
keyHeight = DEFAULT_KEY_HEIGHT,
keyWidth = DEFAULT_KEY_WIDTH,
keySize = DEFAULT_KEY_SIZE,
keyWidth = 0,
spacebarMultiTaps = DEFAULT_SPACEBAR_MULTITAPS,
theme = DEFAULT_THEME,
themeColor = DEFAULT_THEME_COLOR,
Expand Down
Loading

0 comments on commit 53c01b1

Please sign in to comment.