8 Commits
v1.0 ... v1.1

Author SHA1 Message Date
Madeline
d87ddbcd8c Comment out toki pona word matching in english mode 2022-11-04 04:09:20 -04:00
Madeline
0fea23b057 Hide keyboard on tap, more robust search algorithm, option to search by dictionary word or definition 2022-10-28 00:52:53 -04:00
Madeline
c74a2f520c Fix json values for word "li" 2022-10-28 00:51:58 -04:00
Madeline
8dd57b6742 Version bump to 1.1 2022-10-26 16:54:30 -04:00
Madeline
e893a04e13 More robust dictionary search feature, styling tweaks for widgets 2022-10-26 15:46:50 -04:00
Madeline
5999cc3533 Refactor, decompose and add previews. Fix part of speech sheet pop over 2022-10-08 08:35:14 -04:00
Madeline
aae0b6c87e Add dictionary view and change how phrase lookup works 2022-10-08 06:36:19 -04:00
Avery Pace
b27369596f Widget alpha finish 2021-12-12 06:36:54 -05:00
28 changed files with 1094 additions and 79 deletions

View File

@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

View File

@@ -0,0 +1,98 @@
{
"images" : [
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "20x20"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "20x20"
},
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "29x29"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "29x29"
},
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "40x40"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "40x40"
},
{
"idiom" : "iphone",
"scale" : "2x",
"size" : "60x60"
},
{
"idiom" : "iphone",
"scale" : "3x",
"size" : "60x60"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "20x20"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "20x20"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "29x29"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "29x29"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "40x40"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "40x40"
},
{
"idiom" : "ipad",
"scale" : "1x",
"size" : "76x76"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "76x76"
},
{
"idiom" : "ipad",
"scale" : "2x",
"size" : "83.5x83.5"
},
{
"idiom" : "ios-marketing",
"scale" : "1x",
"size" : "1024x1024"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

View File

@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}

View File

@@ -0,0 +1,38 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0.396",
"green" : "0.263",
"red" : "0.392"
}
},
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0.702",
"green" : "0.545",
"red" : "0.698"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

View File

@@ -0,0 +1,38 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0.895",
"green" : "0.893",
"red" : "0.894"
}
},
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0.895",
"green" : "0.893",
"red" : "0.894"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

View File

@@ -0,0 +1,38 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0.927",
"green" : "0.924",
"red" : "0.919"
}
},
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0.927",
"green" : "0.924",
"red" : "0.919"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

View File

@@ -0,0 +1,38 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0.702",
"green" : "0.545",
"red" : "0.698"
}
},
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0.396",
"green" : "0.263",
"red" : "0.392"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

View File

@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSExtension</key>
<dict>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.widgetkit-extension</string>
</dict>
</dict>
</plist>

View File

@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>INEnums</key>
<array/>
<key>INIntentDefinitionModelVersion</key>
<string>1.2</string>
<key>INIntentDefinitionNamespace</key>
<string>88xZPY</string>
<key>INIntentDefinitionSystemVersion</key>
<string>20A294</string>
<key>INIntentDefinitionToolsBuildVersion</key>
<string>12A6144</string>
<key>INIntentDefinitionToolsVersion</key>
<string>12.0</string>
<key>INIntents</key>
<array>
<dict>
<key>INIntentCategory</key>
<string>information</string>
<key>INIntentDescriptionID</key>
<string>tVvJ9c</string>
<key>INIntentEligibleForWidgets</key>
<true/>
<key>INIntentIneligibleForSuggestions</key>
<true/>
<key>INIntentName</key>
<string>Configuration</string>
<key>INIntentResponse</key>
<dict>
<key>INIntentResponseCodes</key>
<array>
<dict>
<key>INIntentResponseCodeName</key>
<string>success</string>
<key>INIntentResponseCodeSuccess</key>
<true/>
</dict>
<dict>
<key>INIntentResponseCodeName</key>
<string>failure</string>
</dict>
</array>
</dict>
<key>INIntentTitle</key>
<string>Configuration</string>
<key>INIntentTitleID</key>
<string>gpCwrM</string>
<key>INIntentType</key>
<string>Custom</string>
<key>INIntentVerb</key>
<string>View</string>
</dict>
</array>
<key>INTypes</key>
<array/>
</dict>
</plist>

View File

@@ -0,0 +1,97 @@
//
// Toki_Trainer_Widgets.swift
// Toki Trainer Widgets
//
// Created by Avery Ada Pace on 12/3/21.
//
import WidgetKit
import SwiftUI
import Intents
struct Provider: IntentTimelineProvider {
var tokiJSONLoader = TokiJSONLoader()
var tokiDictionary: [TokiDictEntry]
init() {
tokiDictionary = tokiJSONLoader.loadDictionary()!
}
func getRandomEntry(configuration: ConfigurationIntent) -> DefinitionEntry {
let randomDictionary = tokiDictionary.shuffled()
let entry = DefinitionEntry(date: Date(), configuration: configuration, word: randomDictionary.first!.word, definition: randomDictionary.first!.definitions[0].definition)
return entry
}
func placeholder(in context: Context) -> DefinitionEntry {
getRandomEntry(configuration: ConfigurationIntent())
}
func getSnapshot(for configuration: ConfigurationIntent, in context: Context, completion: @escaping (DefinitionEntry) -> ()) {
let entry = getRandomEntry(configuration: configuration)
completion(entry)
}
func getTimeline(for configuration: ConfigurationIntent, in context: Context, completion: @escaping (Timeline<Entry>) -> ()) {
var entries: [DefinitionEntry] = []
for _ in 0...5 {
entries.append(getRandomEntry(configuration: configuration))
}
let timeline = Timeline(entries: entries, policy: .atEnd)
completion(timeline)
}
}
struct DefinitionEntry: TimelineEntry {
let date: Date
let configuration: ConfigurationIntent
let word: String
let definition: String
}
struct Toki_Trainer_WidgetsEntryView : View {
var entry: Provider.Entry
var body: some View {
ZStack {
Color("LightPurple")
VStack(alignment: .leading) {
Text(entry.word)
.foregroundColor(Color("FontColorTitle"))
.font(.title)
.frame(maxWidth: .infinity, alignment: .topLeading)
.padding(8)
Text(entry.definition)
.foregroundColor(Color("FontColorSubtitle"))
.frame(maxWidth: .infinity, alignment: .leading)
.padding(8)
}
}
}
}
@main
struct Toki_Trainer_Widgets: Widget {
let kind: String = "Toki_Trainer_Widgets"
var body: some WidgetConfiguration {
IntentConfiguration(kind: kind, intent: ConfigurationIntent.self, provider: Provider()) { entry in
Toki_Trainer_WidgetsEntryView(entry: entry)
}
.configurationDisplayName("Toki Pona Random Word")
.description("Gives you a random word of the moment.")
.supportedFamilies([.systemSmall, .systemMedium])
}
}
struct Toki_Trainer_Widgets_Previews: PreviewProvider {
static var tokiDictionary: [TokiDictEntry] = TokiJSONLoader().loadDictionary()!.shuffled()
static var previews: some View {
Toki_Trainer_WidgetsEntryView(entry: DefinitionEntry(date: Date(), configuration: ConfigurationIntent(), word: tokiDictionary.first!.word, definition: tokiDictionary.first!.definitions[0].definition))
.previewContext(WidgetPreviewContext(family: .systemSmall))
}
}

View File

@@ -15,6 +15,19 @@
7E28111C273302860063DC78 /* toki-partsofspeech.json in Resources */ = {isa = PBXBuildFile; fileRef = 7E28111A273302860063DC78 /* toki-partsofspeech.json */; };
7E28111D273302860063DC78 /* toki-dictionary.json in Resources */ = {isa = PBXBuildFile; fileRef = 7E28111B273302860063DC78 /* toki-dictionary.json */; };
7E28112227330DD30063DC78 /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7E28112127330DD20063DC78 /* Constants.swift */; };
7E449775275AA0600016B6DC /* WidgetKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7E449774275AA0600016B6DC /* WidgetKit.framework */; };
7E449777275AA0600016B6DC /* SwiftUI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7E449776275AA0600016B6DC /* SwiftUI.framework */; };
7E44977A275AA0600016B6DC /* Toki_Trainer_Widgets.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7E449779275AA0600016B6DC /* Toki_Trainer_Widgets.swift */; };
7E44977D275AA0620016B6DC /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 7E44977C275AA0620016B6DC /* Assets.xcassets */; };
7E44977F275AA0620016B6DC /* Toki_Trainer_Widgets.intentdefinition in Sources */ = {isa = PBXBuildFile; fileRef = 7E44977B275AA0600016B6DC /* Toki_Trainer_Widgets.intentdefinition */; };
7E449780275AA0620016B6DC /* Toki_Trainer_Widgets.intentdefinition in Sources */ = {isa = PBXBuildFile; fileRef = 7E44977B275AA0600016B6DC /* Toki_Trainer_Widgets.intentdefinition */; };
7E449783275AA0620016B6DC /* Toki Trainer WidgetsExtension.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = 7E449772275AA0600016B6DC /* Toki Trainer WidgetsExtension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
7E449788275ABF5C0016B6DC /* TokiJSONLoader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7E2811152733027F0063DC78 /* TokiJSONLoader.swift */; };
7E449789275ABF5C0016B6DC /* TokiLesson.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7E716B3D273986E5009E2CF6 /* TokiLesson.swift */; };
7E44978A275ABF5C0016B6DC /* TokiPartOfSpeech.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7E2811162733027F0063DC78 /* TokiPartOfSpeech.swift */; };
7E44978B275ABF5C0016B6DC /* TokiDictionary.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7E2811142733027F0063DC78 /* TokiDictionary.swift */; };
7E44978C275ABF690016B6DC /* TokiDictionaryViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7E20D6002734466800D75B9A /* TokiDictionaryViewModel.swift */; };
7E44978D275AC4AE0016B6DC /* toki-dictionary.json in Resources */ = {isa = PBXBuildFile; fileRef = 7E28111B273302860063DC78 /* toki-dictionary.json */; };
7E716B3E273986E5009E2CF6 /* TokiLesson.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7E716B3D273986E5009E2CF6 /* TokiLesson.swift */; };
7E716B4227398CDF009E2CF6 /* FlashCardLessonsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7E716B4127398CDF009E2CF6 /* FlashCardLessonsView.swift */; };
7E716B4427398D3D009E2CF6 /* FlashCardLessonsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7E716B4327398D3D009E2CF6 /* FlashCardLessonsViewModel.swift */; };
@@ -29,8 +42,37 @@
7E943A2D273211C300E7DDF4 /* Toki_Trainer.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 7E943A2B273211C300E7DDF4 /* Toki_Trainer.xcdatamodeld */; };
7EBAE6AA273D65FD00BCFA09 /* toki-lessons.json in Resources */ = {isa = PBXBuildFile; fileRef = 7EBAE6A9273D65FD00BCFA09 /* toki-lessons.json */; };
7EF546162737B8FB00537AE6 /* FlashCardResultsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7EF546152737B8FA00537AE6 /* FlashCardResultsView.swift */; };
E1A8B364290B905600B53385 /* ViewExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1A8B363290B905600B53385 /* ViewExtensions.swift */; };
E1D79AE328EC396200A104BF /* DictionaryView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1D79AE228EC396200A104BF /* DictionaryView.swift */; };
E1D79AE528F1914600A104BF /* TranslatorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1D79AE428F1914600A104BF /* TranslatorView.swift */; };
E1D79AE728F1925400A104BF /* TokiWordsListEntryView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1D79AE628F1925400A104BF /* TokiWordsListEntryView.swift */; };
E1D79AEB28F194EF00A104BF /* LanguageDirectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1D79AEA28F194EF00A104BF /* LanguageDirectionView.swift */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
7E449781275AA0620016B6DC /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = 7E943A15273211C200E7DDF4 /* Project object */;
proxyType = 1;
remoteGlobalIDString = 7E449771275AA0600016B6DC;
remoteInfo = "Toki Trainer WidgetsExtension";
};
/* End PBXContainerItemProxy section */
/* Begin PBXCopyFilesBuildPhase section */
7E449784275AA0620016B6DC /* Embed App Extensions */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 13;
files = (
7E449783275AA0620016B6DC /* Toki Trainer WidgetsExtension.appex in Embed App Extensions */,
);
name = "Embed App Extensions";
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
7E20D5FE2733AFE700D75B9A /* PartsOfSpeechView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PartsOfSpeechView.swift; sourceTree = "<group>"; };
7E20D6002734466800D75B9A /* TokiDictionaryViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TokiDictionaryViewModel.swift; sourceTree = "<group>"; };
@@ -40,6 +82,14 @@
7E28111A273302860063DC78 /* toki-partsofspeech.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "toki-partsofspeech.json"; sourceTree = "<group>"; };
7E28111B273302860063DC78 /* toki-dictionary.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "toki-dictionary.json"; sourceTree = "<group>"; };
7E28112127330DD20063DC78 /* Constants.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Constants.swift; sourceTree = "<group>"; };
7E449772275AA0600016B6DC /* Toki Trainer WidgetsExtension.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = "Toki Trainer WidgetsExtension.appex"; sourceTree = BUILT_PRODUCTS_DIR; };
7E449774275AA0600016B6DC /* WidgetKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WidgetKit.framework; path = System/Library/Frameworks/WidgetKit.framework; sourceTree = SDKROOT; };
7E449776275AA0600016B6DC /* SwiftUI.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SwiftUI.framework; path = System/Library/Frameworks/SwiftUI.framework; sourceTree = SDKROOT; };
7E449779275AA0600016B6DC /* Toki_Trainer_Widgets.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Toki_Trainer_Widgets.swift; sourceTree = "<group>"; };
7E44977B275AA0600016B6DC /* Toki_Trainer_Widgets.intentdefinition */ = {isa = PBXFileReference; lastKnownFileType = file.intentdefinition; path = Toki_Trainer_Widgets.intentdefinition; sourceTree = "<group>"; };
7E44977C275AA0620016B6DC /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
7E44977E275AA0620016B6DC /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
7E44978E275C495E0016B6DC /* Toki Trainer.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = "Toki Trainer.entitlements"; sourceTree = "<group>"; };
7E716B3D273986E5009E2CF6 /* TokiLesson.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TokiLesson.swift; sourceTree = "<group>"; };
7E716B4127398CDF009E2CF6 /* FlashCardLessonsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlashCardLessonsView.swift; sourceTree = "<group>"; };
7E716B4327398D3D009E2CF6 /* FlashCardLessonsViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlashCardLessonsViewModel.swift; sourceTree = "<group>"; };
@@ -55,9 +105,23 @@
7E943A2C273211C300E7DDF4 /* Toki_Trainer.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = Toki_Trainer.xcdatamodel; sourceTree = "<group>"; };
7EBAE6A9273D65FD00BCFA09 /* toki-lessons.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "toki-lessons.json"; sourceTree = "<group>"; };
7EF546152737B8FA00537AE6 /* FlashCardResultsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlashCardResultsView.swift; sourceTree = "<group>"; };
E1A8B363290B905600B53385 /* ViewExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewExtensions.swift; sourceTree = "<group>"; };
E1D79AE228EC396200A104BF /* DictionaryView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DictionaryView.swift; sourceTree = "<group>"; };
E1D79AE428F1914600A104BF /* TranslatorView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TranslatorView.swift; sourceTree = "<group>"; };
E1D79AE628F1925400A104BF /* TokiWordsListEntryView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TokiWordsListEntryView.swift; sourceTree = "<group>"; };
E1D79AEA28F194EF00A104BF /* LanguageDirectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LanguageDirectionView.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
7E44976F275AA0600016B6DC /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
7E449777275AA0600016B6DC /* SwiftUI.framework in Frameworks */,
7E449775275AA0600016B6DC /* WidgetKit.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
7E943A1A273211C200E7DDF4 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
@@ -82,9 +146,9 @@
7E2811122733024F0063DC78 /* Views */ = {
isa = PBXGroup;
children = (
E1D79AE828F1947F00A104BF /* WordListViews */,
7E943A20273211C200E7DDF4 /* Toki_TrainerApp.swift */,
7E943A22273211C200E7DDF4 /* ContentView.swift */,
7E20D5FE2733AFE700D75B9A /* PartsOfSpeechView.swift */,
7E71E6EC2735D70C007CFF72 /* FlashCardView.swift */,
7EF546152737B8FA00537AE6 /* FlashCardResultsView.swift */,
7E716B4127398CDF009E2CF6 /* FlashCardLessonsView.swift */,
@@ -113,10 +177,32 @@
path = "JSON Data";
sourceTree = "<group>";
};
7E449773275AA0600016B6DC /* Frameworks */ = {
isa = PBXGroup;
children = (
7E449774275AA0600016B6DC /* WidgetKit.framework */,
7E449776275AA0600016B6DC /* SwiftUI.framework */,
);
name = Frameworks;
sourceTree = "<group>";
};
7E449778275AA0600016B6DC /* Toki Trainer Widgets */ = {
isa = PBXGroup;
children = (
7E449779275AA0600016B6DC /* Toki_Trainer_Widgets.swift */,
7E44977B275AA0600016B6DC /* Toki_Trainer_Widgets.intentdefinition */,
7E44977C275AA0620016B6DC /* Assets.xcassets */,
7E44977E275AA0620016B6DC /* Info.plist */,
);
path = "Toki Trainer Widgets";
sourceTree = "<group>";
};
7E943A14273211C200E7DDF4 = {
isa = PBXGroup;
children = (
7E943A1F273211C200E7DDF4 /* Toki Trainer */,
7E449778275AA0600016B6DC /* Toki Trainer Widgets */,
7E449773275AA0600016B6DC /* Frameworks */,
7E943A1E273211C200E7DDF4 /* Products */,
);
sourceTree = "<group>";
@@ -125,6 +211,7 @@
isa = PBXGroup;
children = (
7E943A1D273211C200E7DDF4 /* Toki Trainer.app */,
7E449772275AA0600016B6DC /* Toki Trainer WidgetsExtension.appex */,
);
name = Products;
sourceTree = "<group>";
@@ -132,6 +219,8 @@
7E943A1F273211C200E7DDF4 /* Toki Trainer */ = {
isa = PBXGroup;
children = (
E1A8B362290B903B00B53385 /* Extensions */,
7E44978E275C495E0016B6DC /* Toki Trainer.entitlements */,
7E28111E273302890063DC78 /* JSON Data */,
7E281113273302530063DC78 /* ViewModels */,
7E2811122733024F0063DC78 /* Views */,
@@ -153,9 +242,54 @@
path = "Preview Content";
sourceTree = "<group>";
};
E1A8B362290B903B00B53385 /* Extensions */ = {
isa = PBXGroup;
children = (
E1A8B363290B905600B53385 /* ViewExtensions.swift */,
);
path = Extensions;
sourceTree = "<group>";
};
E1D79AE828F1947F00A104BF /* WordListViews */ = {
isa = PBXGroup;
children = (
E1D79AE928F1949900A104BF /* SharedViews */,
E1D79AE228EC396200A104BF /* DictionaryView.swift */,
E1D79AE428F1914600A104BF /* TranslatorView.swift */,
);
path = WordListViews;
sourceTree = "<group>";
};
E1D79AE928F1949900A104BF /* SharedViews */ = {
isa = PBXGroup;
children = (
E1D79AE628F1925400A104BF /* TokiWordsListEntryView.swift */,
7E20D5FE2733AFE700D75B9A /* PartsOfSpeechView.swift */,
E1D79AEA28F194EF00A104BF /* LanguageDirectionView.swift */,
);
path = SharedViews;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
7E449771275AA0600016B6DC /* Toki Trainer WidgetsExtension */ = {
isa = PBXNativeTarget;
buildConfigurationList = 7E449787275AA0620016B6DC /* Build configuration list for PBXNativeTarget "Toki Trainer WidgetsExtension" */;
buildPhases = (
7E44976E275AA0600016B6DC /* Sources */,
7E44976F275AA0600016B6DC /* Frameworks */,
7E449770275AA0600016B6DC /* Resources */,
);
buildRules = (
);
dependencies = (
);
name = "Toki Trainer WidgetsExtension";
productName = "Toki Trainer WidgetsExtension";
productReference = 7E449772275AA0600016B6DC /* Toki Trainer WidgetsExtension.appex */;
productType = "com.apple.product-type.app-extension";
};
7E943A1C273211C200E7DDF4 /* Toki Trainer */ = {
isa = PBXNativeTarget;
buildConfigurationList = 7E943A30273211C300E7DDF4 /* Build configuration list for PBXNativeTarget "Toki Trainer" */;
@@ -163,10 +297,12 @@
7E943A19273211C200E7DDF4 /* Sources */,
7E943A1A273211C200E7DDF4 /* Frameworks */,
7E943A1B273211C200E7DDF4 /* Resources */,
7E449784275AA0620016B6DC /* Embed App Extensions */,
);
buildRules = (
);
dependencies = (
7E449782275AA0620016B6DC /* PBXTargetDependency */,
);
name = "Toki Trainer";
productName = "Toki Trainer";
@@ -183,6 +319,9 @@
LastSwiftUpdateCheck = 1310;
LastUpgradeCheck = 1310;
TargetAttributes = {
7E449771275AA0600016B6DC = {
CreatedOnToolsVersion = 13.1;
};
7E943A1C273211C200E7DDF4 = {
CreatedOnToolsVersion = 13.1;
};
@@ -202,11 +341,21 @@
projectRoot = "";
targets = (
7E943A1C273211C200E7DDF4 /* Toki Trainer */,
7E449771275AA0600016B6DC /* Toki Trainer WidgetsExtension */,
);
};
/* End PBXProject section */
/* Begin PBXResourcesBuildPhase section */
7E449770275AA0600016B6DC /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
7E44978D275AC4AE0016B6DC /* toki-dictionary.json in Resources */,
7E44977D275AA0620016B6DC /* Assets.xcassets in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
7E943A1B273211C200E7DDF4 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
@@ -222,6 +371,20 @@
/* End PBXResourcesBuildPhase section */
/* Begin PBXSourcesBuildPhase section */
7E44976E275AA0600016B6DC /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
7E44977A275AA0600016B6DC /* Toki_Trainer_Widgets.swift in Sources */,
7E44977F275AA0620016B6DC /* Toki_Trainer_Widgets.intentdefinition in Sources */,
7E449789275ABF5C0016B6DC /* TokiLesson.swift in Sources */,
7E449788275ABF5C0016B6DC /* TokiJSONLoader.swift in Sources */,
7E44978C275ABF690016B6DC /* TokiDictionaryViewModel.swift in Sources */,
7E44978B275ABF5C0016B6DC /* TokiDictionary.swift in Sources */,
7E44978A275ABF5C0016B6DC /* TokiPartOfSpeech.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
7E943A19273211C200E7DDF4 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
@@ -230,13 +393,19 @@
7E943A2A273211C300E7DDF4 /* Persistence.swift in Sources */,
7E20D5FF2733AFE700D75B9A /* PartsOfSpeechView.swift in Sources */,
7E71E6F12736DAE4007CFF72 /* FlashCardsViewModel.swift in Sources */,
E1D79AEB28F194EF00A104BF /* LanguageDirectionView.swift in Sources */,
E1D79AE528F1914600A104BF /* TranslatorView.swift in Sources */,
7E20D6012734466800D75B9A /* TokiDictionaryViewModel.swift in Sources */,
7E716B4427398D3D009E2CF6 /* FlashCardLessonsViewModel.swift in Sources */,
7E2811192733027F0063DC78 /* TokiPartOfSpeech.swift in Sources */,
7E449780275AA0620016B6DC /* Toki_Trainer_Widgets.intentdefinition in Sources */,
E1D79AE328EC396200A104BF /* DictionaryView.swift in Sources */,
7E943A23273211C200E7DDF4 /* ContentView.swift in Sources */,
7EF546162737B8FB00537AE6 /* FlashCardResultsView.swift in Sources */,
7E716B4227398CDF009E2CF6 /* FlashCardLessonsView.swift in Sources */,
7E2811172733027F0063DC78 /* TokiDictionary.swift in Sources */,
E1D79AE728F1925400A104BF /* TokiWordsListEntryView.swift in Sources */,
E1A8B364290B905600B53385 /* ViewExtensions.swift in Sources */,
7E71E6ED2735D70C007CFF72 /* FlashCardView.swift in Sources */,
7E943A21273211C200E7DDF4 /* Toki_TrainerApp.swift in Sources */,
7E716B462739B968009E2CF6 /* FlashCardLessonResultsView.swift in Sources */,
@@ -248,7 +417,69 @@
};
/* End PBXSourcesBuildPhase section */
/* Begin PBXTargetDependency section */
7E449782275AA0620016B6DC /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
target = 7E449771275AA0600016B6DC /* Toki Trainer WidgetsExtension */;
targetProxy = 7E449781275AA0620016B6DC /* PBXContainerItemProxy */;
};
/* End PBXTargetDependency section */
/* Begin XCBuildConfiguration section */
7E449785275AA0620016B6DC /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
ASSETCATALOG_COMPILER_WIDGET_BACKGROUND_COLOR_NAME = WidgetBackground;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 3;
DEVELOPMENT_TEAM = W9ASV855X5;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = "Toki Trainer Widgets/Info.plist";
INFOPLIST_KEY_CFBundleDisplayName = "Toki Trainer Widgets";
INFOPLIST_KEY_NSHumanReadableCopyright = "";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
"@executable_path/../../Frameworks",
);
MARKETING_VERSION = 1.1;
PRODUCT_BUNDLE_IDENTIFIER = "info.maddie.Toki-Trainer.Toki-Trainer-Widgets";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
};
7E449786275AA0620016B6DC /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
ASSETCATALOG_COMPILER_WIDGET_BACKGROUND_COLOR_NAME = WidgetBackground;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 3;
DEVELOPMENT_TEAM = W9ASV855X5;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = "Toki Trainer Widgets/Info.plist";
INFOPLIST_KEY_CFBundleDisplayName = "Toki Trainer Widgets";
INFOPLIST_KEY_NSHumanReadableCopyright = "";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
"@executable_path/../../Frameworks",
);
MARKETING_VERSION = 1.1;
PRODUCT_BUNDLE_IDENTIFIER = "info.maddie.Toki-Trainer.Toki-Trainer-Widgets";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
};
7E943A2E273211C300E7DDF4 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
@@ -368,10 +599,12 @@
7E943A31273211C300E7DDF4 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = "Toki Trainer/Toki Trainer.entitlements";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
CURRENT_PROJECT_VERSION = 3;
DEVELOPMENT_ASSET_PATHS = "\"Toki Trainer/Preview Content\"";
DEVELOPMENT_TEAM = W9ASV855X5;
ENABLE_PREVIEWS = YES;
@@ -385,7 +618,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0;
MARKETING_VERSION = 1.1;
PRODUCT_BUNDLE_IDENTIFIER = "info.maddie.Toki-Trainer";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
@@ -397,10 +630,12 @@
7E943A32273211C300E7DDF4 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = "Toki Trainer/Toki Trainer.entitlements";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
CURRENT_PROJECT_VERSION = 3;
DEVELOPMENT_ASSET_PATHS = "\"Toki Trainer/Preview Content\"";
DEVELOPMENT_TEAM = W9ASV855X5;
ENABLE_PREVIEWS = YES;
@@ -414,7 +649,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0;
MARKETING_VERSION = 1.1;
PRODUCT_BUNDLE_IDENTIFIER = "info.maddie.Toki-Trainer";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
@@ -426,6 +661,15 @@
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
7E449787275AA0620016B6DC /* Build configuration list for PBXNativeTarget "Toki Trainer WidgetsExtension" */ = {
isa = XCConfigurationList;
buildConfigurations = (
7E449785275AA0620016B6DC /* Debug */,
7E449786275AA0620016B6DC /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
7E943A18273211C200E7DDF4 /* Build configuration list for PBXProject "Toki Trainer" */ = {
isa = XCConfigurationList;
buildConfigurations = (

View File

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array/>
</plist>

View File

@@ -4,6 +4,11 @@
<dict>
<key>SchemeUserState</key>
<dict>
<key>Toki Trainer WidgetsExtension.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>1</integer>
</dict>
<key>Toki Trainer.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
uuid = "67504E59-573C-478E-8136-93CA344B943E"
type = "1"
version = "2.0">
</Bucket>

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>Toki Trainer WidgetsExtension.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>1</integer>
</dict>
<key>Toki Trainer.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
</dict>
</plist>

View File

@@ -0,0 +1,15 @@
//
// ViewExtensions.swift
// Toki Trainer
//
// Created by maddiefuzz on 10/28/22.
//
import SwiftUI
extension View {
func hideKeyboard() {
let resign = #selector(UIResponder.resignFirstResponder)
UIApplication.shared.sendAction(resign, to: nil, from: nil, for: nil)
}
}

View File

@@ -578,7 +578,7 @@
"definitions": [
{
"pos": "sep",
"definition": "\\\"(between any subject except mi and sina and its verb\": null, \" also used to introduce a new verb for the same subject)\\\""
"definition": "(between any subject except mi and sina and its verb, also used to introduce a new verb for the same subject)"
}
]
},
@@ -1748,4 +1748,4 @@
}
]
}
]
]

View File

@@ -94,7 +94,7 @@
"definitions": [
{
"pos": "sep",
"definition": "\\\"(between any subject except mi and sina and its verb\": null, \" also used to introduce a new verb for the same subject)\\\""
"definition": "(between any subject except mi and sina and its verb, also used to introduce a new verb for the same subject)"
}
]
}
@@ -1711,4 +1711,4 @@
}
]
}
]
]

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.application-groups</key>
<array>
<string>group.info.maddie.tokitrainer</string>
</array>
</dict>
</plist>

View File

@@ -17,6 +17,8 @@ class TokiDictionaryViewModel: ObservableObject {
@Published var dictionary: [TokiDictEntry] = []
@Published var partsOfSpeech: [TokiPartOfSpeech] = []
@Published var translatedDictionary: [TokiSubWordListEntry] = []
init() {
if let safeDictionary = jsonLoader.loadDictionary() {
dictionary = safeDictionary
@@ -30,18 +32,75 @@ class TokiDictionaryViewModel: ObservableObject {
func filterDictionary(_ input: String) {
dictionary = []
if(input.isEmpty) {
dictionary = fullDictionary
} else {
let capturePattern = #"(\w+)"#
let captures = self.searchStringForRegex(string: input, regex: capturePattern)
for capture in captures {
print(capture)
for value in fullDictionary {
if value.word == capture {
dictionary.append(value)
for value in fullDictionary {
if value.word.hasPrefix(input) {
dictionary.append(value)
}
}
}
func filterDictionaryEnglishMode(_ input: String) {
dictionary = []
for value in fullDictionary {
var entryMatch = false
// Check if word matches toki pona form, even partially
// Commented out because toki words shouldn't be matched in english mode
// if value.word.hasPrefix(input) {
// entryMatch = true
// }
// Check if any part of the word definitions match in English, even partially, but
// only by prefix (if one of the definition words matches the beginning of the word with
// the search term)
for definition in value.definitions {
let capturePattern = #"(\w+)"#
let captures = self.searchStringForRegex(string: definition.definition, regex: capturePattern)
for capture in captures {
if capture.hasPrefix(input) {
entryMatch = true
}
}
// Commented out, less strict matching that will match on any substring match
// if definition.definition.contains(input) {
// entryMatch = true
// }
}
// Add to dictionary
if entryMatch == true {
dictionary.append(value)
}
}
}
func translatePhrase(_ input: String) {
dictionary = []
translatedDictionary = []
if input.isEmpty {
dictionary = fullDictionary
translatedDictionary.append(TokiSubWordListEntry("Dictionary"))
}
let capturePattern = #"(\w+)"#
let captures = self.searchStringForRegex(string: input, regex: capturePattern)
for capture in captures {
let translatedWord = TokiSubWordListEntry(capture)
translatedDictionary.append(translatedWord)
for value in fullDictionary {
if value.word == capture {
dictionary.append(value)
translatedWord.subDictionary.removeAll()
translatedWord.subDictionary.append(value)
break
} else if value.word.hasPrefix(capture) {
dictionary.append(value)
translatedWord.subDictionary.append(value)
}
}
}
}
@@ -58,3 +117,12 @@ class TokiDictionaryViewModel: ObservableObject {
}
}
}
class TokiSubWordListEntry: Identifiable {
let header: String
var subDictionary: [TokiDictEntry] = []
init(_ header: String) {
self.header = header
}
}

View File

@@ -15,10 +15,13 @@ extension String: Identifiable {
struct ContentView: View {
@Environment(\.managedObjectContext) private var viewContext
@State private var tokiInput: String = ""
var body: some View {
TabView {
DictionaryView()
.tabItem {
Image(systemName: "book")
Text("Dictionary")
}
TranslatorView()
.tabItem {
Image(systemName: "message")
@@ -29,11 +32,6 @@ struct ContentView: View {
Image(systemName: "character.textbox")
Text("Flash Cards")
}
// FlashCardResultsView()
// .tabItem {
// Image(systemName: "number.circle")
// Text("Flash Card Results")
// }
}
}
@@ -42,54 +40,6 @@ struct ContentView: View {
}
}
struct TranslatorView: View {
@ObservedObject var tokiDictViewModel = TokiDictionaryViewModel()
@State private var selectedPartOfSpeech: String?
@State private var tokiInput: String = ""
var body: some View {
VStack {
TextField("Enter Toki Pona Word or Phrase", text: $tokiInput)
.multilineTextAlignment(.center)
.textInputAutocapitalization(.never)
.disableAutocorrection(true)
.padding(8)
.onSubmit {
tokiDictViewModel.filterDictionary(tokiInput)
}
List(tokiDictViewModel.dictionary, id: \.word) { entry in
VStack(alignment: .leading) {
Text(entry.word)
.font(.title)
ForEach(entry.definitions, id: \.pos) { definition in
HStack(alignment: .top) {
Button(action: {
self.selectedPartOfSpeech = String(definition.pos)
}) {
Text(definition.pos)
.frame(width: 45, height: 22, alignment: .center)
.foregroundColor(.black)
.background(Color(K.posColors[definition.pos]!))
.cornerRadius(5.0)
.padding(4)
}
.buttonStyle(BorderlessButtonStyle())
Text(definition.definition)
.fixedSize(horizontal: false, vertical: true)
.padding(4)
}
}
}
}
.sheet(item: $selectedPartOfSpeech) { selectedPOS in
PartsOfSpeechView(selectedPartOfSpeech: selectedPOS, partsOfSpeech: tokiDictViewModel.partsOfSpeech)
}
.onChange(of: tokiInput) { newValue in
tokiDictViewModel.filterDictionary(newValue)
}
}
}
}
struct ContentView_Previews: PreviewProvider {

View File

@@ -157,7 +157,7 @@ struct FlashCardStack: View {
var cardInDatabase = false
for answer in flashCardAnswers {
if answer.word == shuffledDictionary[currentFlashCard].word {
print("word in database: \(answer.word)")
print("word in database: \(answer.word ?? "nil")")
print("tries: \(answer.triesCount)")
print("correct`: \(answer.correctCount)")
cardInDatabase = true

View File

@@ -0,0 +1,79 @@
//
// DictionaryView.swift
// Toki Trainer
//
// Created by maddiefuzz on 10/4/22.
//
import SwiftUI
enum SearchMode {
case Dictionary
case Definitions
}
struct DictionaryView: View {
@ObservedObject var tokiDictViewModel = TokiDictionaryViewModel()
@State private var tokiInput: String = ""
@State private var selectedPartOfSpeech: String?
@State var searchMode: SearchMode = .Dictionary
@FocusState private var searchInputIsForuced: Bool
var body: some View {
VStack {
TextField("Search", text: $tokiInput)
.multilineTextAlignment(.center)
.textInputAutocapitalization(.never)
.disableAutocorrection(true)
.padding(8)
.onSubmit {
filterByInput()
//tokiDictViewModel.filterDictionaryEnglishMode(tokiInput)
}
Picker("Language", selection: $searchMode) {
Text("Dictionary").tag(SearchMode.Dictionary)
Text("Definitions").tag(SearchMode.Definitions)
}
.pickerStyle(SegmentedPickerStyle())
.onTapGesture {
if self.searchMode == SearchMode.Dictionary {
self.searchMode = SearchMode.Definitions
} else {
self.searchMode = SearchMode.Dictionary
}
filterByInput()
}
List(tokiDictViewModel.dictionary, id: \.word) { entry in
TokiWordsListEntryView(entry: entry, selectedPartOfSpeech: $selectedPartOfSpeech)
}
.sheet(item: $selectedPartOfSpeech) { selectedPOS in
PartsOfSpeechView(selectedPartOfSpeech: selectedPOS)
}
.onChange(of: tokiInput) { newValue in
filterByInput()
//tokiDictViewModel.filterDictionaryEnglishMode(newValue)
}
}
.onTapGesture {
hideKeyboard()
}
}
func filterByInput() {
if self.searchMode == SearchMode.Dictionary {
tokiDictViewModel.filterDictionary(tokiInput)
} else {
tokiDictViewModel.filterDictionaryEnglishMode(tokiInput)
}
}
}
struct DictionaryView_Previews: PreviewProvider {
static var previews: some View {
DictionaryView().previewLayout(.sizeThatFits).environment(\.managedObjectContext, PersistenceController.preview.container.viewContext)
}
}

View File

@@ -0,0 +1,53 @@
//
// LanguageDirectionView.swift
// Toki Trainer
//
// Created by maddiefuzz on 10/8/22.
//
import SwiftUI
struct LanguageDirectionView: View {
private var fromText: String = ""
private var toText: String = ""
private var fromColor: Color = .black
private var toColor: Color = .black
init(from: String, to: String, fromColor: Color, toColor: Color) {
self.fromText = from
self.toText = to
self.fromColor = fromColor
self.toColor = toColor
}
var body: some View {
HStack {
Text(fromText)
.bold()
.multilineTextAlignment(.center)
.foregroundColor(.white)
.frame(width: 100)
.background(fromColor)
.border(fromColor)
.cornerRadius(5)
Image(systemName: "chevron.right")
Text(toText)
.bold()
.multilineTextAlignment(.center)
.foregroundColor(.white)
.frame(width: 100)
.background(toColor)
.border(toColor)
.cornerRadius(5)
}
.padding(.top, 4)
}
}
struct LanguageDirectionView_Previews: PreviewProvider {
static var previews: some View {
LanguageDirectionView(from: "English", to: "Toki Pona", fromColor: .blue, toColor: .cyan)
.previewLayout(.fixed(width: 260, height: 40))
}
}

View File

@@ -12,8 +12,6 @@ struct PartsOfSpeechView: View {
@ObservedObject var tokiDictViewModel = TokiDictionaryViewModel()
var partsOfSpeech: [TokiPartOfSpeech]
var body: some View {
VStack {
Text("Parts of Speech")
@@ -42,8 +40,8 @@ struct PartsOfSpeechView: View {
struct PartsOfSpeechView_Previews: PreviewProvider {
static var previews: some View {
PartsOfSpeechView(selectedPartOfSpeech: "sep", partsOfSpeech: [TokiPartOfSpeech(pos: "sep", definition: "test")])
PartsOfSpeechView(selectedPartOfSpeech: "sep")
.preferredColorScheme(.dark)
PartsOfSpeechView(selectedPartOfSpeech: "sep", partsOfSpeech: [TokiPartOfSpeech(pos: "sep", definition: "test")])
PartsOfSpeechView(selectedPartOfSpeech: "sep")
}
}

View File

@@ -0,0 +1,47 @@
//
// TokiWordsListEntryView.swift
// Toki Trainer
//
// Created by maddiefuzz on 10/8/22.
//
import SwiftUI
struct TokiWordsListEntryView: View {
@State var entry: TokiDictEntry
@Binding var selectedPartOfSpeech: String?
var body: some View {
VStack(alignment: .leading) {
Text(entry.word)
.font(.title)
ForEach(entry.definitions, id: \.pos) { definition in
HStack(alignment: .top) {
Button(action: {
self.selectedPartOfSpeech = String(definition.pos)
}) {
Text(definition.pos)
.frame(width: 45, height: 22, alignment: .center)
.foregroundColor(.black)
.background(Color(K.posColors[definition.pos]!))
.cornerRadius(5.0)
.padding(4)
}
.buttonStyle(BorderlessButtonStyle())
Text(definition.definition)
.fixedSize(horizontal: false, vertical: true)
.padding(4)
}
}
}
}
}
struct TokiWordsListEntryView_Previews: PreviewProvider {
static var entry = TokiDictionaryViewModel().dictionary[5]
static var previews: some View {
TokiWordsListEntryView(entry: entry, selectedPartOfSpeech: .constant("n"))
.previewLayout(.sizeThatFits)
}
}

View File

@@ -0,0 +1,71 @@
//
// TranslatorView.swift
// Toki Trainer
//
// Created by maddiefuzz on 10/8/22.
//
import SwiftUI
struct TranslatorView: View {
@ObservedObject var tokiDictViewModel = TokiDictionaryViewModel()
@State private var selectedPartOfSpeech: String?
@State private var tokiInput: String = ""
@State private var translateToTokiPona: Bool = false
var body: some View {
VStack {
// Button(action: changeTranslationDirection) {
// #warning("This needs to actually switch how the lookup happens")
// if translateToTokiPona == true {
// LanguageDirectionView(from: "English", to: "Toki Pona", fromColor: .blue, toColor: .cyan)
// } else {
// LanguageDirectionView(from: "Toki Pona", to: "English", fromColor: .cyan, toColor: .blue)
// }
// }
TextField("Enter Toki Pona Word or Phrase", text: $tokiInput)
.multilineTextAlignment(.center)
.textInputAutocapitalization(.never)
.disableAutocorrection(true)
.padding(8)
.onSubmit {
tokiDictViewModel.translatePhrase(tokiInput)
}
if tokiInput.count == 0 {
List(tokiDictViewModel.dictionary, id: \.word) { entry in
TokiWordsListEntryView(entry: entry, selectedPartOfSpeech: $selectedPartOfSpeech)
}
} else {
List(tokiDictViewModel.translatedDictionary, id: \.header) { section in
Section {
ForEach(section.subDictionary, id: \.word) { entry in
TokiWordsListEntryView(entry: entry, selectedPartOfSpeech: $selectedPartOfSpeech)
}
} header: {
Text(section.header)
}
}
}
}
.sheet(item: $selectedPartOfSpeech) { selectedPOS in
PartsOfSpeechView(selectedPartOfSpeech: selectedPOS)
}
.onChange(of: tokiInput) { newValue in
tokiDictViewModel.translatePhrase(newValue)
}
.onTapGesture {
hideKeyboard()
}
}
func changeTranslationDirection() {
translateToTokiPona.toggle()
}
}
struct TranslatorView_Previews: PreviewProvider {
static var previews: some View {
TranslatorView().previewLayout(.sizeThatFits).environment(\.managedObjectContext, PersistenceController.preview.container.viewContext)
}
}