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

feat: saving user preference on emoji autosuggest based on menu #347

Merged
merged 4 commits into from
Jul 30, 2023
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
3 changes: 3 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ Thank you in advance for your contributions!

# Data edits [`⇧`](#contents)

> [!NOTE]\
> Please see the [Wikidata and Scribe Guide](https://github.com/scribe-org/Organization/blob/main/WIKIDATAGUIDE.md) for an overview of [Wikidata](https://www.wikidata.org/) and how Scribe uses it.

Scribe does not accept direct edits to the grammar JSON files as they are sourced from [Wikidata](https://www.wikidata.org/). Edits can be discussed and the [Scribe-Data](https://github.com/scribe-org/Scribe-Data) queries will be changed and ran before an update. If there is a problem with one of the files, then the fix should be made on [Wikidata](https://www.wikidata.org/) and not on Scribe. Feel free to let us know that edits have been made by [opening a data issue](https://github.com/scribe-org/Scribe-iOS/issues/new?assignees=&labels=data&template=data_wikidata.yml) or contacting us in the [issues for Scribe-Data](https://github.com/scribe-org/Scribe-Data/issues) and we'll be happy to integrate them!

<a id="localization"></a>
Expand Down
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
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
[![license](https://img.shields.io/github/license/scribe-org/Scribe-iOS.svg?label=%20)](https://github.com/scribe-org/Scribe-iOS/blob/main/LICENSE.txt)
[![coc](https://img.shields.io/badge/Contributor%20Covenant-ff69b4.svg)](https://github.com/scribe-org/Scribe-iOS/blob/main/.github/CODE_OF_CONDUCT.md)
[![mastodon](https://img.shields.io/badge/Mastodon-6364FF.svg?logo=mastodon&logoColor=ffffff)](https://wikis.world/@scribe)
[![twitter](https://img.shields.io/badge/Twitter-1DA1F2.svg?logo=twitter&logoColor=ffffff)](https://twitter.com/scribe_org)
[![matrix](https://img.shields.io/badge/Matrix-000000.svg?logo=matrix&logoColor=ffffff)](https://matrix.to/#/#scribe_community:matrix.org)

<a href='https://apps.apple.com/app/scribe-language-keyboards/id1596613886'><img alt='Available on the App Store' src='https://raw.githubusercontent.com/scribe-org/Scribe-iOS/main/.github/resources/images/app_store_badge.png' height='60px'/></a>
Expand Down Expand Up @@ -122,6 +121,9 @@ The Scribe road map can be followed in the organization's [project board](https:

### Data Edits [`⇧`](#contents)

> [!NOTE]\
> Please see the [Wikidata and Scribe Guide](https://github.com/scribe-org/Organization/blob/main/WIKIDATAGUIDE.md) for an overview of [Wikidata](https://www.wikidata.org/) and how Scribe uses it.

Scribe does not accept direct edits to the grammar JSON files as they are sourced from [Wikidata](https://www.wikidata.org/). Edits can be discussed and the [Scribe-Data](https://github.com/scribe-org/Scribe-Data) queries will be changed and ran before an update. If there is a problem with one of the files, then the fix should be made on [Wikidata](https://www.wikidata.org/) and not on Scribe. Feel free to let us know that edits have been made by [opening a data issue](https://github.com/scribe-org/Scribe-iOS/issues/new?assignees=&labels=data&template=data_wikidata.yml) or contacting us in the [issues for Scribe-Data](https://github.com/scribe-org/Scribe-Data/issues) and we'll be happy to integrate them!

### Designs [`⇧`](#contents)
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 @@ -63,8 +65,20 @@ class InfoChildTableViewCell: UITableViewCell {
switch togglePurpose {
case .toggleCommaAndPeriod:
let dictionaryKey = languageCode + "CommaAndPeriod"
toggleSwitch.isOn = userDefaults.bool(forKey: dictionaryKey)
case .autosuggestEmojis: break
if let toggleValue = userDefaults.object(forKey: dictionaryKey) as? Bool {
toggleSwitch.isOn = toggleValue
} else {
/// Default value
toggleSwitch.isOn = false
}
case .autosuggestEmojis:
let dictionaryKey = languageCode + "EmojiAutosuggest"
if let toggleValue = userDefaults.object(forKey: dictionaryKey) as? Bool {
toggleSwitch.isOn = toggleValue
} else {
/// Default value
toggleSwitch.isOn = true
}
case .none: break
}
}
Expand Down