Add WordView, fix some functions, add basic implementation of AnkiView
This commit is contained in:
@@ -11,6 +11,7 @@
|
|||||||
6C8185002B88C9660033CF46 /* WordAXModelView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C8184FF2B88C9660033CF46 /* WordAXModelView.swift */; };
|
6C8185002B88C9660033CF46 /* WordAXModelView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C8184FF2B88C9660033CF46 /* WordAXModelView.swift */; };
|
||||||
6C8185022B88C9FB0033CF46 /* SettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C8185012B88C9FB0033CF46 /* SettingsView.swift */; };
|
6C8185022B88C9FB0033CF46 /* SettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C8185012B88C9FB0033CF46 /* SettingsView.swift */; };
|
||||||
6C8185042B88CA210033CF46 /* AnkiView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C8185032B88CA210033CF46 /* AnkiView.swift */; };
|
6C8185042B88CA210033CF46 /* AnkiView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C8185032B88CA210033CF46 /* AnkiView.swift */; };
|
||||||
|
6C8185062B8A537F0033CF46 /* WordView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C8185052B8A537F0033CF46 /* WordView.swift */; };
|
||||||
6CF439522B83541D004C3543 /* WordAXApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CF439512B83541D004C3543 /* WordAXApp.swift */; };
|
6CF439522B83541D004C3543 /* WordAXApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CF439512B83541D004C3543 /* WordAXApp.swift */; };
|
||||||
6CF439542B83541D004C3543 /* MainView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CF439532B83541D004C3543 /* MainView.swift */; };
|
6CF439542B83541D004C3543 /* MainView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CF439532B83541D004C3543 /* MainView.swift */; };
|
||||||
6CF439562B83541E004C3543 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 6CF439552B83541E004C3543 /* Assets.xcassets */; };
|
6CF439562B83541E004C3543 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 6CF439552B83541E004C3543 /* Assets.xcassets */; };
|
||||||
@@ -22,6 +23,7 @@
|
|||||||
6C8184FF2B88C9660033CF46 /* WordAXModelView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WordAXModelView.swift; sourceTree = "<group>"; };
|
6C8184FF2B88C9660033CF46 /* WordAXModelView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WordAXModelView.swift; sourceTree = "<group>"; };
|
||||||
6C8185012B88C9FB0033CF46 /* SettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsView.swift; sourceTree = "<group>"; };
|
6C8185012B88C9FB0033CF46 /* SettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsView.swift; sourceTree = "<group>"; };
|
||||||
6C8185032B88CA210033CF46 /* AnkiView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnkiView.swift; sourceTree = "<group>"; };
|
6C8185032B88CA210033CF46 /* AnkiView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnkiView.swift; sourceTree = "<group>"; };
|
||||||
|
6C8185052B8A537F0033CF46 /* WordView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WordView.swift; sourceTree = "<group>"; };
|
||||||
6CF4394E2B83541D004C3543 /* WordAX.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = WordAX.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
6CF4394E2B83541D004C3543 /* WordAX.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = WordAX.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||||
6CF439512B83541D004C3543 /* WordAXApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WordAXApp.swift; sourceTree = "<group>"; };
|
6CF439512B83541D004C3543 /* WordAXApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WordAXApp.swift; sourceTree = "<group>"; };
|
||||||
6CF439532B83541D004C3543 /* MainView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainView.swift; sourceTree = "<group>"; };
|
6CF439532B83541D004C3543 /* MainView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainView.swift; sourceTree = "<group>"; };
|
||||||
@@ -63,6 +65,7 @@
|
|||||||
6CF439532B83541D004C3543 /* MainView.swift */,
|
6CF439532B83541D004C3543 /* MainView.swift */,
|
||||||
6C8185012B88C9FB0033CF46 /* SettingsView.swift */,
|
6C8185012B88C9FB0033CF46 /* SettingsView.swift */,
|
||||||
6C8185032B88CA210033CF46 /* AnkiView.swift */,
|
6C8185032B88CA210033CF46 /* AnkiView.swift */,
|
||||||
|
6C8185052B8A537F0033CF46 /* WordView.swift */,
|
||||||
6C8184FD2B88C9580033CF46 /* WordAX.swift */,
|
6C8184FD2B88C9580033CF46 /* WordAX.swift */,
|
||||||
6C8184FF2B88C9660033CF46 /* WordAXModelView.swift */,
|
6C8184FF2B88C9660033CF46 /* WordAXModelView.swift */,
|
||||||
6CF439552B83541E004C3543 /* Assets.xcassets */,
|
6CF439552B83541E004C3543 /* Assets.xcassets */,
|
||||||
@@ -151,6 +154,7 @@
|
|||||||
files = (
|
files = (
|
||||||
6C8185022B88C9FB0033CF46 /* SettingsView.swift in Sources */,
|
6C8185022B88C9FB0033CF46 /* SettingsView.swift in Sources */,
|
||||||
6CF439542B83541D004C3543 /* MainView.swift in Sources */,
|
6CF439542B83541D004C3543 /* MainView.swift in Sources */,
|
||||||
|
6C8185062B8A537F0033CF46 /* WordView.swift in Sources */,
|
||||||
6C8185002B88C9660033CF46 /* WordAXModelView.swift in Sources */,
|
6C8185002B88C9660033CF46 /* WordAXModelView.swift in Sources */,
|
||||||
6C8185042B88CA210033CF46 /* AnkiView.swift in Sources */,
|
6C8185042B88CA210033CF46 /* AnkiView.swift in Sources */,
|
||||||
6CF439522B83541D004C3543 /* WordAXApp.swift in Sources */,
|
6CF439522B83541D004C3543 /* WordAXApp.swift in Sources */,
|
||||||
|
|||||||
@@ -9,8 +9,15 @@ import SwiftUI
|
|||||||
|
|
||||||
struct AnkiView: View {
|
struct AnkiView: View {
|
||||||
@EnvironmentObject var model: WordAXModelView
|
@EnvironmentObject var model: WordAXModelView
|
||||||
|
var word: WordAX.Word? {
|
||||||
|
model.getWordToDisplay()
|
||||||
|
}
|
||||||
var body: some View {
|
var body: some View {
|
||||||
Text("This is Anki View")
|
if word != nil {
|
||||||
|
WordView(word: word!)
|
||||||
|
} else {
|
||||||
|
Text("There is no word to display, come back later")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ struct WordAX {
|
|||||||
var description: String
|
var description: String
|
||||||
var shown: Bool
|
var shown: Bool
|
||||||
var nextSpacedRepetitionMilestone: SpacedRepetitionMilestoneEnum?
|
var nextSpacedRepetitionMilestone: SpacedRepetitionMilestoneEnum?
|
||||||
var displayOn: Date?
|
var lastSeenOn: Date?
|
||||||
}
|
}
|
||||||
enum FrequencyEnum: Int {
|
enum FrequencyEnum: Int {
|
||||||
case Daily = 1
|
case Daily = 1
|
||||||
@@ -35,11 +35,21 @@ struct WordAX {
|
|||||||
static var allCasesSorted: [SpacedRepetitionMilestoneEnum] {
|
static var allCasesSorted: [SpacedRepetitionMilestoneEnum] {
|
||||||
allCases.sorted {$0.rawValue < $1.rawValue }
|
allCases.sorted {$0.rawValue < $1.rawValue }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getNext() -> SpacedRepetitionMilestoneEnum? {
|
||||||
|
let sorted = WordAX.SpacedRepetitionMilestoneEnum.allCasesSorted
|
||||||
|
let milestoneIndex = sorted.firstIndex(where: {$0.rawValue == self.rawValue})!
|
||||||
|
if milestoneIndex < WordAX.SpacedRepetitionMilestoneEnum.allCasesSorted.count {
|
||||||
|
return sorted[milestoneIndex + 1]
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Settings {
|
struct Settings {
|
||||||
var frequency: FrequencyEnum = .Daily
|
var frequency: FrequencyEnum = .Daily
|
||||||
var lastShownNew: Date?
|
var lastShownNew: Date?
|
||||||
|
var dateFormatter: DateFormatter
|
||||||
}
|
}
|
||||||
|
|
||||||
private mutating func setNextSpacedRepetitionMilestone(word: Word) {
|
private mutating func setNextSpacedRepetitionMilestone(word: Word) {
|
||||||
@@ -59,8 +69,10 @@ struct WordAX {
|
|||||||
|
|
||||||
init() {
|
init() {
|
||||||
self.words = []
|
self.words = []
|
||||||
self.settings = Settings()
|
let dateFormatter = DateFormatter()
|
||||||
self.words.append(Word(id: 0, name: "Magnificent", description: "When something is awesome", shown: false))
|
dateFormatter.dateFormat = "dd/mm/YYYY"
|
||||||
|
self.settings = Settings(dateFormatter: dateFormatter)
|
||||||
|
self.words.append(Word(id: 0, name: "Magnificent", description: "When something is awesome. Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.", shown: false))
|
||||||
self.words.append(Word(id: 1, name: "Mesmerising", description: "When something is beautiful", shown: false))
|
self.words.append(Word(id: 1, name: "Mesmerising", description: "When something is beautiful", shown: false))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,12 +14,17 @@ class WordAXModelView: ObservableObject {
|
|||||||
model = WordAX()
|
model = WordAX()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public func getDateFormatter() -> DateFormatter {
|
||||||
|
model.settings.dateFormatter
|
||||||
|
}
|
||||||
|
|
||||||
public func getWordToDisplay() -> Word? {
|
public func getWordToDisplay() -> Word? {
|
||||||
let words = model.words
|
let words = model.words
|
||||||
|
|
||||||
if words.count > 0 {
|
if words.count > 0 {
|
||||||
// if today is the date they're supposed to be shown
|
// if today is the date they're supposed to be shown
|
||||||
let displayToday = words.filter({ $0.displayOn != nil && $0.displayOn!.isToday()})
|
|
||||||
|
let displayToday = words.filter({ $0.lastSeenOn != nil && $0.lastSeenOn!.add})
|
||||||
if displayToday.count > 0 {
|
if displayToday.count > 0 {
|
||||||
return displayToday.first!
|
return displayToday.first!
|
||||||
}
|
}
|
||||||
@@ -33,7 +38,7 @@ class WordAXModelView: ObservableObject {
|
|||||||
let settings = model.settings
|
let settings = model.settings
|
||||||
if shownWords.count == 0 ||
|
if shownWords.count == 0 ||
|
||||||
settings.lastShownNew == nil ||
|
settings.lastShownNew == nil ||
|
||||||
settings.lastShownNew!.addingTimeInterval(TimeInterval(settings.frequency.rawValue * 24 * 60 * 60)).isAfterToday() {
|
settings.lastShownNew!.addFrequency(frequency: settings.frequency).isAfterToday() {
|
||||||
return words.first!
|
return words.first!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -63,6 +68,10 @@ extension Date {
|
|||||||
return selfDate.year! > paramDate.year! || selfDate.month! > paramDate.month! || selfDate.day! > paramDate.day!
|
return selfDate.year! > paramDate.year! || selfDate.month! > paramDate.month! || selfDate.day! > paramDate.day!
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func addFrequency(frequency: WordAX.FrequencyEnum) -> Date {
|
||||||
|
self.addingTimeInterval(TimeInterval(frequency.rawValue * 24 * 60 * 60))
|
||||||
|
}
|
||||||
|
|
||||||
func isAfterToday() -> Bool {
|
func isAfterToday() -> Bool {
|
||||||
self.isAfter(Date())
|
self.isAfter(Date())
|
||||||
}
|
}
|
||||||
|
|||||||
40
WordAX/WordView.swift
Normal file
40
WordAX/WordView.swift
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
//
|
||||||
|
// WordView.swift
|
||||||
|
// WordAX
|
||||||
|
//
|
||||||
|
// Created by Oliver Hnát on 24.02.2024.
|
||||||
|
//
|
||||||
|
|
||||||
|
import SwiftUI
|
||||||
|
import UIKit
|
||||||
|
|
||||||
|
struct WordView: View {
|
||||||
|
var word: WordAX.Word
|
||||||
|
var showDescription: Bool = true
|
||||||
|
@EnvironmentObject var model: WordAXModelView
|
||||||
|
@Environment(\.colorScheme) var colorScheme
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
VStack {
|
||||||
|
Text(word.name)
|
||||||
|
.font(.title)
|
||||||
|
.bold()
|
||||||
|
if word.shown && word.lastSeenOn != nil {
|
||||||
|
Text(model.getDateFormatter().string(from: word.lastSeenOn!))
|
||||||
|
}
|
||||||
|
if showDescription {
|
||||||
|
Divider()
|
||||||
|
.background(colorScheme == .light ? Color.black : Color.white)
|
||||||
|
.padding(.horizontal)
|
||||||
|
Text(word.description)
|
||||||
|
.multilineTextAlignment(.center)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding([.horizontal, .top])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#Preview {
|
||||||
|
WordView(word: WordAXModelView().getWordToDisplay()!)
|
||||||
|
.environmentObject(WordAXModelView())
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user