-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
35 changed files
with
4,326 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
Oh My Flag/Oh My Flag.xcodeproj/project.xcworkspace/contents.xcworkspacedata
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
Oh My Flag/Oh My Flag.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?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>IDEDidComputeMac32BitWarning</key> | ||
<true/> | ||
</dict> | ||
</plist> |
Binary file added
BIN
+22.9 KB
...eproj/project.xcworkspace/xcuserdata/yongfrank.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
14 changes: 14 additions & 0 deletions
14
.../Oh My Flag.xcodeproj/xcuserdata/yongfrank.xcuserdatad/xcschemes/xcschememanagement.plist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?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>Oh My Flag.xcscheme_^#shared#^_</key> | ||
<dict> | ||
<key>orderHint</key> | ||
<integer>0</integer> | ||
</dict> | ||
</dict> | ||
</dict> | ||
</plist> |
15 changes: 15 additions & 0 deletions
15
Oh My Flag/Oh My Flag/App/Assets.xcassets/AccentColor.colorset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"colors" : [ | ||
{ | ||
"color" : { | ||
"platform" : "universal", | ||
"reference" : "systemBlueColor" | ||
}, | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
Binary file added
BIN
+373 KB
Oh My Flag/Oh My Flag/App/Assets.xcassets/AppIcon.appiconset/AppIcon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions
14
Oh My Flag/Oh My Flag/App/Assets.xcassets/AppIcon.appiconset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"filename" : "AppIcon.png", | ||
"idiom" : "universal", | ||
"platform" : "ios", | ||
"size" : "1024x1024" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
// | ||
// ContentView.swift | ||
// OhMyFlag | ||
// | ||
// Created by Frank Chu on 4/10/22. | ||
// | ||
|
||
import SwiftUI | ||
//#-learning-task(Gallery) | ||
//#-learning-task(Quiz) | ||
//#-learning-task(Drawing) | ||
struct ContentView: View { | ||
@FetchRequest(sortDescriptors: []) var flagsInContentView: FetchedResults<FlagEntities> | ||
@Environment(\.managedObjectContext) var mocInContentView | ||
|
||
@State private var showWhatsNew = false | ||
|
||
// MARK: - Body | ||
|
||
var body: some View { | ||
TabView { | ||
/*#-code-walkthrough(1.1)*/ | ||
FlagGallery(showWhatsNew: $showWhatsNew) | ||
.tabItem { | ||
Label("Gallery", systemImage: "house") | ||
} | ||
/*#-code-walkthrough(1.1)*/ | ||
/*#-code-walkthrough(2.1)*/ | ||
QuizFlag() | ||
.tabItem { | ||
Label("Quiz", systemImage: "lightbulb") | ||
} | ||
/*#-code-walkthrough(2.1)*/ | ||
/*#-code-walkthrough(3.1)*/ | ||
DrawingFlag() | ||
.tabItem { | ||
Label("Drawing", systemImage: "scribble") | ||
} | ||
/*#-code-walkthrough(3.1)*/ | ||
} | ||
.sheet(isPresented: $showWhatsNew) { | ||
NewVerWhatsNew() | ||
} | ||
.onAppear() { | ||
showWhatsNew = checkForUpdate() | ||
if showWhatsNew { | ||
addTemplateFlag() | ||
} | ||
} | ||
|
||
// MARK: - | ||
|
||
// .onAppear { | ||
// UIDevice.current.setValue(UIInterfaceOrientation.portrait.rawValue, forKey: "orientation") // Forcing the rotation to portrait | ||
// AppDelegate.orientationLock = .landscape // And making sure it stays that way | ||
// }.onDisappear { | ||
// AppDelegate.orientationLock = .all // Unlocking the rotation when leaving the view | ||
// } | ||
} | ||
func addTemplateFlag() { | ||
let newFlag = FlagEntities(context: mocInContentView) | ||
newFlag.id = UUID() | ||
newFlag.emojiFlag = "🇨🇭" | ||
newFlag.nameFlag = "Switzerland" | ||
newFlag.shortIntro = "White Across in a Red Square" | ||
newFlag.detailedIntro = "Mar 12, 2020\nIn the history class, we learned about Switzerland. The history of this area is fascinating.\n\nDec 8, 2020: \nA year ago, I went to Switzerland. I hope that pandemic will end soon. I want to travel again!😭\n\nDec 9, 2019: Grindelwald First \nIt's the best time of my trip. Cable car🚠, glider, cliff🏔! \n\nDec 8, 2019: Zurich, a beautiful city in the Switzerland \n🌁 Panorama bridge Sigriswil, what a sophisticated bridge. I love the structure of this bridge!" | ||
|
||
try? mocInContentView.save() | ||
} | ||
|
||
} | ||
|
||
struct ContentView_Previews: PreviewProvider { | ||
static var previews: some View { | ||
ContentView() | ||
} | ||
} | ||
|
||
func emojiFlag(regionCode: String) -> String? { | ||
let code = regionCode.uppercased() | ||
|
||
guard Locale.isoRegionCodes.contains(code) else { | ||
return nil | ||
} | ||
|
||
var flagString = "" | ||
for s in code.unicodeScalars { | ||
guard let scalar = UnicodeScalar(127397 + s.value) else { | ||
continue | ||
} | ||
flagString.append(String(scalar)) | ||
} | ||
return flagString | ||
} | ||
|
||
func countryName(from countryCode: String) -> String { | ||
if let name = (Locale.current as NSLocale).displayName(forKey: .countryCode, value: countryCode) { | ||
// Country name was found | ||
return name | ||
} else { | ||
// Country name cannot be found | ||
return countryCode | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// | ||
// EmojiTextField.swift | ||
// OhMyFlag | ||
// | ||
// Created by Frank Chu on 4/10/22. | ||
// | ||
|
||
import SwiftUI | ||
//import Foundation | ||
|
||
// https://stackoverflow.com/questions/66397828/emoji-keyboard-swiftui | ||
class UIEmojiTextField: UITextField { | ||
|
||
override func awakeFromNib() { | ||
super.awakeFromNib() | ||
} | ||
|
||
func setEmoji() { | ||
_ = self.textInputMode | ||
} | ||
|
||
override var textInputContextIdentifier: String? { | ||
return "" | ||
} | ||
|
||
override var textInputMode: UITextInputMode? { | ||
for mode in UITextInputMode.activeInputModes { | ||
if mode.primaryLanguage == "emoji" { | ||
self.keyboardType = .default // do not remove this | ||
return mode | ||
} | ||
} | ||
return nil | ||
} | ||
} | ||
|
||
struct EmojiTextField: UIViewRepresentable { | ||
@Binding var text: String | ||
var placeholder: String = "" | ||
|
||
func makeUIView(context: Context) -> UIEmojiTextField { | ||
let emojiTextField = UIEmojiTextField() | ||
emojiTextField.placeholder = placeholder | ||
emojiTextField.text = text | ||
emojiTextField.delegate = context.coordinator | ||
return emojiTextField | ||
} | ||
|
||
func updateUIView(_ uiView: UIEmojiTextField, context: Context) { | ||
uiView.text = text | ||
} | ||
|
||
func makeCoordinator() -> Coordinator { | ||
Coordinator(parent: self) | ||
} | ||
|
||
class Coordinator: NSObject, UITextFieldDelegate { | ||
var parent: EmojiTextField | ||
|
||
init(parent: EmojiTextField) { | ||
self.parent = parent | ||
} | ||
|
||
func textFieldDidChangeSelection(_ textField: UITextField) { | ||
DispatchQueue.main.async { [weak self] in | ||
self?.parent.text = textField.text ?? "" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import SwiftUI | ||
import CoreData | ||
|
||
@objc(FlagEntities) | ||
|
||
public class FlagEntities: NSManagedObject { | ||
@NSManaged public var id: UUID | ||
@NSManaged public var emojiFlag: String | ||
@NSManaged public var nameFlag: String | ||
@NSManaged public var shortIntro: String | ||
@NSManaged public var detailedIntro: String | ||
} | ||
|
||
extension FlagEntities: Identifiable { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import SwiftUI | ||
import CoreData | ||
|
||
struct PersistenceController { | ||
static let shared = PersistenceController() | ||
|
||
static var preview: PersistenceController = { | ||
let result = PersistenceController(inMemory: true) | ||
let viewContext = result.container.viewContext | ||
for index in 0..<10 { | ||
// let newItem = Item(context: viewContext) | ||
// newItem.timestamp = Date() | ||
} | ||
do { | ||
try viewContext.save() | ||
} catch { | ||
// Replace this implementation with code to handle the error appropriately. | ||
// fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. | ||
let nsError = error as NSError | ||
fatalError("Unresolved error \(nsError), \(nsError.userInfo)") | ||
} | ||
return result | ||
}() | ||
|
||
let container: NSPersistentContainer | ||
|
||
init(inMemory: Bool = false) { | ||
let flagEntities = NSEntityDescription() | ||
flagEntities.name = "FlagEntities" | ||
flagEntities.managedObjectClassName = "FlagEntities" | ||
|
||
let idAttribute = NSAttributeDescription() | ||
idAttribute.name = "id" | ||
idAttribute.type = .uuid | ||
flagEntities.properties.append(idAttribute) | ||
|
||
let nameFlagAttribute = NSAttributeDescription() | ||
nameFlagAttribute.name = "nameFlag" | ||
nameFlagAttribute.type = .string | ||
flagEntities.properties.append(nameFlagAttribute) | ||
|
||
let emojiFlagAttribute = NSAttributeDescription() | ||
emojiFlagAttribute.name = "emojiFlag" | ||
emojiFlagAttribute.type = .string | ||
flagEntities.properties.append(emojiFlagAttribute) | ||
|
||
let shortIntroAttribute = NSAttributeDescription() | ||
shortIntroAttribute.name = "shortIntro" | ||
shortIntroAttribute.type = .string | ||
flagEntities.properties.append(shortIntroAttribute) | ||
|
||
let detailedIntroAttribute = NSAttributeDescription() | ||
detailedIntroAttribute.name = "detailedIntro" | ||
detailedIntroAttribute.type = .string | ||
flagEntities.properties.append(detailedIntroAttribute) | ||
|
||
let model = NSManagedObjectModel() | ||
model.entities = [flagEntities] | ||
|
||
|
||
container = NSPersistentContainer(name: "OhMyFlag", managedObjectModel: model) | ||
if inMemory { | ||
container.persistentStoreDescriptions.first!.url = URL(fileURLWithPath: "/dev/null") | ||
} | ||
container.loadPersistentStores(completionHandler: { (storeDescription, error) in | ||
if let error = error as NSError? { | ||
// Replace this implementation with code to handle the error appropriately. | ||
// fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. | ||
|
||
/* | ||
Typical reasons for an error here include: | ||
* The parent directory does not exist, cannot be created, or disallows writing. | ||
* The persistent store is not accessible, due to permissions or data protection when the device is locked. | ||
* The device is out of space. | ||
* The store could not be migrated to the current model version. | ||
Check the error message to determine what the actual problem was. | ||
*/ | ||
fatalError("Unresolved error \(error), \(error.userInfo)") | ||
} | ||
}) | ||
container.viewContext.automaticallyMergesChangesFromParent = true | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// | ||
// BadgeFlagView.swift | ||
// OhMyFlag | ||
// | ||
// Created by Frank Chu on 4/10/22. | ||
// | ||
|
||
import SwiftUI | ||
import CoreData | ||
|
||
struct BadgeFlagView: View { | ||
// @FetchRequest(sortDescriptors: []) var flagsBadgeView: FetchedResults<FlagEntities> | ||
// @Environment(\.managedObjectContext) var mocInBadgeFlagView | ||
let flag: FlagEntities | ||
var body: some View { | ||
|
||
VStack { | ||
Text(flag.emojiFlag) | ||
.frame(height: 96) | ||
.font(.system(size: 96)) | ||
.padding() | ||
|
||
VStack { | ||
Text(flag.nameFlag) | ||
.font(.headline) | ||
.foregroundColor(.white) | ||
|
||
Text(flag.shortIntro) | ||
.font(.caption) | ||
.foregroundColor(.white.opacity(0.5)) | ||
} | ||
.frame(maxWidth: .infinity) | ||
.padding(.vertical) | ||
.background(.lightBackground) | ||
} | ||
.clipShape(RoundedRectangle(cornerRadius: 10)) | ||
.overlay( | ||
RoundedRectangle(cornerRadius: 10) | ||
.stroke(.lightBackground) | ||
) | ||
} | ||
|
||
} | ||
|
||
//struct BadgeFlagView_Previews: PreviewProvider { | ||
// static var previews: some View { | ||
// BadgeFlagView() | ||
// } | ||
//} |
Oops, something went wrong.