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

make "hide letters" only hide letters, add new toggle "hide symbols" (fixes #299) #370

Merged
merged 7 commits into from
Sep 1, 2023

Conversation

nejni-marji
Copy link
Contributor

I think this PR is set up correctly this time, and I already figured out how to use the linter, so it should be pretty much good.

@nejni-marji
Copy link
Contributor Author

nejni-marji commented Aug 30, 2023

Okay, I have no idea what I've done wrong here, ugh. I don't know why the CI is upset about this.

edit: I guess it's fine now?

app/src/main/java/com/dessalines/thumbkey/db/AppDb.kt Outdated Show resolved Hide resolved
@@ -363,7 +364,12 @@ fun KeyText(key: KeyC, keySize: Dp, hideLetters: Boolean, capsLock: Boolean) {
}
is KeyDisplay.TextDisplay -> {
// Only hide the letters for text, not symbols
if (!hideLetters) {
val showKey = if (!display.text.any { !it.isLetter() }) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's going on here?

This isn't going to work for things like multiple letter keys, etc. You're going to need to add a KeyType enum {Letter, Symbol} to each key, probably with a default of KeyType.Letter, and alter every keyboard to set that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm using isLetter() on every character in the string. For example: "a" is a letter, "abc" is a letter, and "?" is a symbol, but "a?" is also a symbol. My assumption is that anything that is purely letter-characters is probably basically a letter.

Copy link
Owner

@dessalines dessalines Aug 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, but I'd move the isLetter check above, and have this do a simple if (!hideLetters && !isMadeOfLetters)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because I made hiding symbols a separate toggle, I found that I have to use the isLetter check to determine which of hideLetters and hideSymbols to apply. I tried a bunch of logic like what you're describing in a python script and none of my attempts correctly resolved every possibility.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So you haven't tested this code in thumbkey?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, .com is hidden with hideSymbols. I'm not sure if I necessarily intended that when I initially wrote it, but in a way it feels like the behaviour you would expect? Obviously, this is a particular edge case that could go either way, and it's a reason to potentially explicitly label each key as a symbol or not a symbol, but I think it's probably fine.

Copy link
Contributor Author

@nejni-marji nejni-marji Aug 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bad news: it does cause issues with the Greek keyboard, because combining accents are not letters:

display = KeyDisplay.TextDisplay("Ϋ́"),
action = KeyAction.CommitText("Ϋ́"),

display = KeyDisplay.TextDisplay("Ϊ́"),
action = KeyAction.CommitText("Ϊ́"),

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hrm... Could you check if there exists any other kotlin / java function would work? Might be something better than isLetter

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If not, even if imperfect, this would probably still be better than just hiding everything as it currently does.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no better single function to my knowledge. It's possible to compare the character's Unicode category, and check if it's one of the 3 "mark" categories. I'm not 100% what all is in the mark categories overall, but punctuation and other special symbols generally shouldn't be.

Copy link
Owner

@dessalines dessalines left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually DB migrations are still broken.

val MIGRATION_7_8 = object : Migration(7, 8) {
override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL(
"alter table AppSettings add column hide_symbols BOOLEAN NOT NULL default $DEFAULT_HIDE_SYMBOLS",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whew, good thing I tested this, because it breaks existing installations. This needed to be an INTEGER, not a boolean. I'm fixing it now.

@dessalines
Copy link
Owner

Okay I fixed this up. In the future please actually test this. If you did so, you'd see that it would cause an immediate crash on startup, because sqlite doesn't have a boolean type.

@@ -363,7 +364,15 @@ fun KeyText(key: KeyC, keySize: Dp, hideLetters: Boolean, capsLock: Boolean) {
}
is KeyDisplay.TextDisplay -> {
// Only hide the letters for text, not symbols
if (!hideLetters) {
val containsLetters = display.text.any { it.isLetter() }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed this to be clearer, and not use a triple negative

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This actually changes the logic, but after thinking it over, I do agree that this is probably the better of the two choices here anyway.

@dessalines dessalines enabled auto-merge (squash) September 1, 2023 13:42
@dessalines dessalines merged commit b2be8ee into dessalines:main Sep 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants