Skip to content

Commit c7ef9a2

Browse files
Download from API (#593)
* fix duplicated download screen in nav stack * fix: reset to Installation tab's root when app is reopened * init add contracts and update query nouns * "Noun annotation: update queryNounForm based on gender contract" * Restore DACommandVariables.swift * Plural command: update query for plural command and add plural annotation * Noun annotation: fix multiple annotation case * Preposition annotation: update queryPrepForm and add conversion preposition to abbreviation * Conjugate: use dynamic conjugation and declension * Declension: move declension contract to main contract file * Conjugation and declension: add function documentation and fix comments * Add YAML version of data contracts * Minor fix in comment in contracts * feat: change to using YAML contract * feat: API call and write into sqlite db * feat: initialize download button state * feat: All languages button download state and handle click * feat: initialize button states on "Check for new data" * feat: remove built in database and read from new downloaded one * add comments for new functions --------- Co-authored-by: Andrew Tavis McAllister <andrew.t.mcallister@gmail.com>
1 parent fca0281 commit c7ef9a2

18 files changed

Lines changed: 653 additions & 230 deletions
-11.2 MB
Binary file not shown.
-2.27 MB
Binary file not shown.
-4.73 MB
Binary file not shown.
-2.54 MB
Binary file not shown.
-4.08 MB
Binary file not shown.
-472 KB
Binary file not shown.
-8.32 MB
Binary file not shown.
-5.02 MB
Binary file not shown.

Keyboards/DataManager/LanguageDBManager.swift

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class LanguageDBManager {
1616
if translate {
1717
database = openDBQueue("TranslationData")
1818
} else {
19-
database = openDBQueue("\(getControllerLanguageAbbr().uppercased())LanguageData")
19+
database = openDownloadedDBQueue("\(getControllerLanguageAbbr().uppercased())LanguageData")
2020
}
2121
}
2222

@@ -42,6 +42,21 @@ class LanguageDBManager {
4242
}
4343
}
4444

45+
/// Opens a connection to the downloaded language database for the current language.
46+
private func openDownloadedDBQueue(_ dbName: String) -> DatabaseQueue? {
47+
let fileManager = FileManager.default
48+
guard let containerURL = fileManager.containerURL(forSecurityApplicationGroupIdentifier: "group.be.scri.userDefaultsContainer") else {
49+
print("App group container not found")
50+
return nil
51+
}
52+
let dbPath = containerURL.appendingPathComponent("\(dbName).sqlite").path
53+
guard fileManager.fileExists(atPath: dbPath) else {
54+
print("\(dbName).sqlite not found in app group container")
55+
return nil
56+
}
57+
return try? DatabaseQueue(path: dbPath)
58+
}
59+
4560
/// Loads a JSON file that contains grammatical information into a dictionary.
4661
///
4762
/// - Parameters

Keyboards/KeyboardsBase/KeyboardViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ class KeyboardViewController: UIInputViewController {
457457
// Get options for completion that start with the current prefix and are not just one letter.
458458
let completionOptions = LanguageDBManager.shared.queryAutocompletions(word: currentPrefix)
459459

460-
if !completionOptions[0].isEmpty {
460+
if !completionOptions.isEmpty && !completionOptions[0].isEmpty {
461461
if completionOptions.count <= 3 {
462462
for i in 0 ..< completionOptions.count {
463463
if shiftButtonState == .shift {

0 commit comments

Comments
 (0)