Skip to content

Commit

Permalink
Merge pull request #142 from divvun/feature/user-dictionary
Browse files Browse the repository at this point in the history
Feature/user dictionary #47
  • Loading branch information
dylanhand authored Mar 10, 2020
2 parents f101bb9 + ebfceed commit 66edca2
Show file tree
Hide file tree
Showing 49 changed files with 2,505 additions and 159 deletions.
4 changes: 4 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
excluded:
- Pods
- HostingApp/Strings.swift


disabled_rules:
- todo
Expand All @@ -10,8 +12,10 @@ cyclomatic_complexity:
identifier_name:
excluded:
- i
- j
- id
- x
- y
- db

line_length: 130
289 changes: 284 additions & 5 deletions GiellaKeyboard.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@
</BuildableReference>
</MacroExpansion>
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "990440A123FC14A30063064E"
BuildableName = "HostingAppTests.xctest"
BlueprintName = "HostingAppTests"
ReferencedContainer = "container:GiellaKeyboard.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
Expand Down
10 changes: 10 additions & 0 deletions GiellaKeyboard.xcodeproj/xcshareddata/xcschemes/Keyboard.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@
</BuildableReference>
</MacroExpansion>
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "990440A123FC14A30063064E"
BuildableName = "HostingAppTests.xctest"
BlueprintName = "HostingAppTests"
ReferencedContainer = "container:GiellaKeyboard.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
Expand Down
13 changes: 4 additions & 9 deletions HostingApp/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
return true
}

func applicationWillResignActive(_: UIApplication) {}

func applicationDidEnterBackground(_: UIApplication) {}

func applicationWillEnterForeground(_: UIApplication) {}

func applicationDidBecomeActive(_: UIApplication) {}

func applicationWillTerminate(_: UIApplication) {}
func applicationWillEnterForeground(_: UIApplication) {
// I'd gladly use .NSExtensionHostWillEnterForeground but it doesn't work
NotificationCenter.default.post(Notification(name: .HostingAppWillEnterForeground))
}

func parseUrl(_: URL) {
guard Bundle.main.bundleIdentifier != nil else {
Expand Down
8 changes: 6 additions & 2 deletions HostingApp/Base.lproj/Localizable.strings
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
"about" = "About the keyboard app";
"about" = "About";
"addNewKeyboard" = "Add New Keyboard…";
"allowFullAccess" = "Allow Full Access";
"attributions" = "Attributions";
"contextsFor" = "Contexts for \"%1$@\"";
"enableTapSoundsPlain" = "If you wish to enable key tap sounds, you must then tap %1$@ and toggle %2$@.";
"general" = "General";
"keyboard" = "Keyboard";
"keyboards" = "Keyboards";
"language" = "Language";
"layouts" = "Layouts";
"locale_sjd" = "Kildin Sami";
"localeSjd" = "Kildin Sami";
"noUserWords" = "No user-created words yet.";
"noUserWordsDescription" = "Words that are left uncorrected and are not in the built-in dictionary will appear here.";
"openAppPlain" = "Open the %1$@ app";
"openSettings" = "Open Settings";
"save" = "Save";
Expand All @@ -17,4 +20,5 @@
"settings" = "Settings";
"skip" = "Skip";
"tapPlain" = "Tap %1$@";
"userDictionary" = "User Dictionary";
"whenYouHaveFinished" = "When you have finished, return to this app to continue.";
25 changes: 24 additions & 1 deletion HostingApp/Controllers/HomeController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,45 @@ class HomeController: ViewController<HomeView>, HideNavBar {
navigationController?.pushViewController(TestingController(), animated: true)
}

@objc private func openSettings() {
navigationController?.pushViewController(SettingsViewController(), animated: true)
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)

contentView.configStack?.isHidden = AppDelegate.instance.isKeyboardEnabled
refreshUI()
contentView.awakeFromNib()
}

@objc private func refreshUI() {
contentView.configStack?.isHidden = AppDelegate.instance.isKeyboardEnabled
}

override func viewDidLoad() {
super.viewDidLoad()

title = Strings.localizedName

NotificationCenter.default.addObserver(self,
selector: #selector(refreshUI),
name: UIApplication.didBecomeActiveNotification,
object: nil)

contentView.langButton.addTarget(self, action: #selector(openLanguages), for: [.touchUpInside])
contentView.langButton2.addTarget(self, action: #selector(openLanguages), for: [.touchUpInside])
contentView.helpButton.addTarget(self, action: #selector(openInstructions), for: [.touchUpInside])
contentView.aboutButton.addTarget(self, action: #selector(openAbout), for: [.touchUpInside])
contentView.testingButton.addTarget(self, action: #selector(openTesting), for: [.touchUpInside])
contentView.settingsButton.addTarget(self, action: #selector(openSettings), for: [.touchUpInside])

#if ENABLE_USER_DICTIONARY
#else
contentView.settingsButton.isHidden = true
#endif
}

deinit {
NotificationCenter.default.removeObserver(self)
}
}
18 changes: 18 additions & 0 deletions HostingApp/Controllers/KeyboardLocalesViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import UIKit

class KeyboardLocalesViewController: SettingsViewController {

override var rows: [Row] {
var rows: [Row] = []

for locale in KeyboardLocale.allLocales {
let row = Row(title: locale.languageName) { () -> UIViewController in
UserDictionaryViewController(keyboardLocale: locale)
}
rows.append(row)
}

return rows
}

}
65 changes: 31 additions & 34 deletions HostingApp/Controllers/LanguagesController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,59 @@ import UIKit

class LanguagesController: UITableViewController {
let rows = Strings.supportedLocales

var selectedRow: IndexPath?

@objc private func onDoneTapped() {
if let row = selectedRow?.row {
KeyboardSettings.languageCode = rows[row].languageCode!
Strings.languageCode = KeyboardSettings.languageCode
}

navigationController?.popViewController(animated: true)
}

override func viewDidLoad() {
super.viewDidLoad()
title = Strings.language
setupNavBar()
setupTableView()
}

let selectedLocale = Locale(identifier: KeyboardSettings.languageCode)
private func setupNavBar() {
navigationItem.rightBarButtonItem = UIBarButtonItem(
title: Strings.save,
style: .done,
target: self,
action: #selector(onSaveTapped)
)
}

private func setupTableView() {
let selectedLocale = Locale(identifier: KeyboardSettings.languageCode)
if let i = rows.firstIndex(where: { $0.languageCode == selectedLocale.languageCode }) {
selectedRow = IndexPath(item: i, section: 0)
tableView.reloadData()
}

tableView.allowsSelection = true
tableView.allowsMultipleSelection = false

navigationItem.rightBarButtonItem = UIBarButtonItem(
title: Strings.save,
style: .done,
target: self,
action: #selector(onDoneTapped)
)

title = Strings.language

tableView.tableFooterView = UIView()

tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
tableView.tableFooterView = UIView()
}

override func numberOfSections(in _: UITableView) -> Int {
return 1
@objc private func onSaveTapped() {
if let row = selectedRow?.row {
KeyboardSettings.languageCode = rows[row].languageCode!
Strings.languageCode = KeyboardSettings.languageCode
}

navigationController?.popViewController(animated: true)
}

override func tableView(_: UITableView, numberOfRowsInSection _: Int) -> Int {
return rows.count
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)

cell.textLabel?.text = Strings.languageName(for: rows[indexPath.row])!
cell.accessoryType = selectedRow == indexPath ? .checkmark : .none

return cell
}

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)

Expand All @@ -62,13 +68,4 @@ class LanguagesController: UITableViewController {

selectedRow = indexPath
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)

cell.textLabel?.text = Strings.languageName(for: rows[indexPath.row])!
cell.accessoryType = selectedRow == indexPath ? .checkmark : .none

return cell
}
}
61 changes: 61 additions & 0 deletions HostingApp/Controllers/SettingsViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import UIKit

typealias ViewControllerMaker = (() -> UIViewController)?

struct Row {
let title: String
let destinationViewController: ViewControllerMaker
}

class SettingsViewController: UITableViewController {

var rows: [Row] {
let destinationViewController: ViewControllerMaker
let locales = KeyboardLocale.allLocales
if locales.count == 1 {
destinationViewController = {
UserDictionaryViewController(keyboardLocale: locales.first!)
}
} else {
destinationViewController = {
KeyboardLocalesViewController()
}
}

return [
Row(title: Strings.userDictionary, destinationViewController: destinationViewController)
]
}

init() {
super.init(style: .grouped)
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

override func viewDidLoad() {
super.viewDidLoad()
tableView.register(DisclosureCell.self)
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return rows.count
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(DisclosureCell.self)
cell.textLabel?.text = rows[indexPath.item].title
return cell
}

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let row = rows[indexPath.row]
guard let viewController = row.destinationViewController?() else {
return
}
navigationController?.pushViewController(viewController, animated: true)
}

}
Loading

0 comments on commit 66edca2

Please sign in to comment.