Skip to content

Commit

Permalink
feat: saving user preference on emoji autosuggest based on menu
Browse files Browse the repository at this point in the history
  • Loading branch information
SaurabhJamadagni committed Jul 25, 2023
1 parent 60be461 commit d1ed519
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
19 changes: 14 additions & 5 deletions Keyboards/KeyboardsBase/KeyboardViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,9 @@ class KeyboardViewController: UIInputViewController {
}

// Disable the third auto action button if we'll have emoji suggestions.
getEmojiAutoSuggestions(for: currentPrefix)
if emojiAutosuggestIsEnabled() {
getEmojiAutoSuggestions(for: currentPrefix)
}
} else {
getDefaultAutosuggestions()
}
Expand Down Expand Up @@ -577,7 +579,9 @@ class KeyboardViewController: UIInputViewController {
}

// Disable the third auto action button if we'll have emoji suggestions.
getEmojiAutoSuggestions(for: prefix)
if emojiAutosuggestIsEnabled() {
getEmojiAutoSuggestions(for: prefix)
}
}

/// Sets up command buttons to execute autocomplete and autosuggest.
Expand Down Expand Up @@ -2008,11 +2012,8 @@ class KeyboardViewController: UIInputViewController {

func setCommaAndPeriodKeysConditionally() {
let langCode = languagesAbbrDict[controllerLanguage] ?? "unknown"

let userDefaults = UserDefaults(suiteName: "group.scribe.userDefaultsContainer")!

let dictionaryKey = langCode + "CommaAndPeriod"

let letterKeysHaveCommaPeriod = userDefaults.bool(forKey: dictionaryKey)

if letterKeysHaveCommaPeriod {
Expand All @@ -2021,6 +2022,14 @@ class KeyboardViewController: UIInputViewController {
letterKeys[3] = ["123", "selectKeyboard", "space", "return"]
}
}

func emojiAutosuggestIsEnabled() -> Bool {
let langCode = languagesAbbrDict[controllerLanguage] ?? "unknown"
let userDefaults = UserDefaults(suiteName: "group.scribe.userDefaultsContainer")!
let dictionaryKey = langCode + "EmojiAutosuggest"

return userDefaults.bool(forKey: dictionaryKey)
}

// MARK: Button Actions

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ class InfoChildTableViewCell: UITableViewCell {
case .toggleCommaAndPeriod:
let dictionaryKey = languageCode + "CommaAndPeriod"
userDefaults.setValue(toggleSwitch.isOn, forKey: dictionaryKey)
case .autosuggestEmojis: break
case .autosuggestEmojis:
let dictionaryKey = languageCode + "EmojiAutosuggest"
userDefaults.setValue(toggleSwitch.isOn, forKey: dictionaryKey)
case .none: break
}

Expand All @@ -64,7 +66,9 @@ class InfoChildTableViewCell: UITableViewCell {
case .toggleCommaAndPeriod:
let dictionaryKey = languageCode + "CommaAndPeriod"
toggleSwitch.isOn = userDefaults.bool(forKey: dictionaryKey)
case .autosuggestEmojis: break
case .autosuggestEmojis:
let dictionaryKey = languageCode + "EmojiAutosuggest"
toggleSwitch.isOn = userDefaults.bool(forKey: dictionaryKey)
case .none: break
}
}
Expand Down

0 comments on commit d1ed519

Please sign in to comment.