Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#49 4 exams #50

Merged
merged 15 commits into from
Sep 3, 2023
41 changes: 21 additions & 20 deletions AppSettings+CoreDataProperties.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// AppSettings+CoreDataProperties.swift
// Calq
//
// Created by Kiara on 19.05.23.
// Created by Kiara on 03.09.23.
//
//

Expand All @@ -17,26 +17,10 @@ extension AppSettings {
}

@NSManaged public var colorfulCharts: Bool
@NSManaged public var weightBigGrades: String
@NSManaged public var usersubjects: NSSet?
@NSManaged public var weightBigGrades: String?
@NSManaged public var hasFiveExams: Bool
@NSManaged public var gradetypes: NSSet?

}

// MARK: Generated accessors for usersubjects
extension AppSettings {

@objc(addUsersubjectsObject:)
@NSManaged public func addToUsersubjects(_ value: UserSubject)

@objc(removeUsersubjectsObject:)
@NSManaged public func removeFromUsersubjects(_ value: UserSubject)

@objc(addUsersubjects:)
@NSManaged public func addToUsersubjects(_ values: NSSet)

@objc(removeUsersubjects:)
@NSManaged public func removeFromUsersubjects(_ values: NSSet)
@NSManaged public var usersubjects: NSSet?

}

Expand All @@ -57,6 +41,23 @@ extension AppSettings {

}

// MARK: Generated accessors for usersubjects
extension AppSettings {

@objc(addUsersubjectsObject:)
@NSManaged public func addToUsersubjects(_ value: UserSubject)

@objc(removeUsersubjectsObject:)
@NSManaged public func removeFromUsersubjects(_ value: UserSubject)

@objc(addUsersubjects:)
@NSManaged public func addToUsersubjects(_ values: NSSet)

@objc(removeUsersubjects:)
@NSManaged public func removeFromUsersubjects(_ values: NSSet)

}

extension AppSettings : Identifiable {

}
14 changes: 13 additions & 1 deletion Calq.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
F10E74F32A41E6C1004C7863 /* WhatsNewScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = F10E74F22A41E6C1004C7863 /* WhatsNewScreen.swift */; };
F1138E5129958878008E7FD8 /* DocumentPicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1138E5029958878008E7FD8 /* DocumentPicker.swift */; };
F1138E5529959677008E7FD8 /* GradeListScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1138E5429959677008E7FD8 /* GradeListScreen.swift */; };
F11583022AA4910200122FBB /* Mapping Model 2 to 3.xcmappingmodel in Sources */ = {isa = PBXBuildFile; fileRef = F11583012AA4910200122FBB /* Mapping Model 2 to 3.xcmappingmodel */; };
F11583042AA4AB3500122FBB /* Models.swift in Sources */ = {isa = PBXBuildFile; fileRef = F11583032AA4AB3500122FBB /* Models.swift */; };
F11583052AA4AC8200122FBB /* Models.swift in Sources */ = {isa = PBXBuildFile; fileRef = F11583032AA4AB3500122FBB /* Models.swift */; };
F14140462A47639E007E4648 /* TabViewVM.swift in Sources */ = {isa = PBXBuildFile; fileRef = F14140452A47639E007E4648 /* TabViewVM.swift */; };
F14140482A476408007E4648 /* AppStoreRating.swift in Sources */ = {isa = PBXBuildFile; fileRef = F14140472A476408007E4648 /* AppStoreRating.swift */; };
F17F443D298C4DA7000A3993 /* CalqApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = F17F443C298C4DA7000A3993 /* CalqApp.swift */; };
Expand Down Expand Up @@ -157,6 +160,9 @@
F10E74F22A41E6C1004C7863 /* WhatsNewScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WhatsNewScreen.swift; sourceTree = "<group>"; };
F1138E5029958878008E7FD8 /* DocumentPicker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DocumentPicker.swift; sourceTree = "<group>"; };
F1138E5429959677008E7FD8 /* GradeListScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GradeListScreen.swift; sourceTree = "<group>"; };
F11583002AA490BE00122FBB /* Model 3.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "Model 3.xcdatamodel"; sourceTree = "<group>"; };
F11583012AA4910200122FBB /* Mapping Model 2 to 3.xcmappingmodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcmappingmodel; path = "Mapping Model 2 to 3.xcmappingmodel"; sourceTree = "<group>"; };
F11583032AA4AB3500122FBB /* Models.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Models.swift; sourceTree = "<group>"; };
F14140452A47639E007E4648 /* TabViewVM.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabViewVM.swift; sourceTree = "<group>"; };
F14140472A476408007E4648 /* AppStoreRating.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppStoreRating.swift; sourceTree = "<group>"; };
F17F443C298C4DA7000A3993 /* CalqApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CalqApp.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -336,6 +342,7 @@
F1A772332A1795C6004B8DCC /* UserSubject+CoreDataClass.swift */,
F1A772342A1795C6004B8DCC /* UserSubject+CoreDataProperties.swift */,
F1A7720E2A17947A004B8DCC /* Model.xcdatamodeld */,
F11583012AA4910200122FBB /* Mapping Model 2 to 3.xcmappingmodel */,
F1AAEF282A1BC1E5000CD044 /* Mapping Model 1.xcmappingmodel */,
DD4F97522751167000D3CC57 /* CoreDataStack.swift */,
F1A772072A17940B004B8DCC /* MigrationPolicy.swift */,
Expand Down Expand Up @@ -449,6 +456,7 @@
DD81F6822759091600B4A43B /* JSONUtil.swift */,
F1D29E782A17B8AF0001D469 /* ExportJSON.swift */,
F1D29E7A2A17B8D90001D469 /* LoadJSON.swift */,
F11583032AA4AB3500122FBB /* Models.swift */,
);
path = JSON;
sourceTree = "<group>";
Expand Down Expand Up @@ -640,6 +648,7 @@
F1A772442A1795C6004B8DCC /* UserSubject+CoreDataProperties.swift in Sources */,
F1A7724B2A179753004B8DCC /* Model.xcdatamodeld in Sources */,
F192DD25299D2CD00077B905 /* BarChart.swift in Sources */,
F11583052AA4AC8200122FBB /* Models.swift in Sources */,
F1A7723A2A1795C6004B8DCC /* AppSettings+CoreDataClass.swift in Sources */,
F1C04B5229BA376800DAC128 /* MediumBarChart.swift in Sources */,
F1D29E7C2A17BCC90001D469 /* ExportJSON.swift in Sources */,
Expand Down Expand Up @@ -673,6 +682,7 @@
F1B0B1682996489900F3D1FD /* EditGradeScreen.swift in Sources */,
F10D66B2298D57BD00993237 /* BlockView.swift in Sources */,
F1A772412A1795C6004B8DCC /* UserSubject+CoreDataClass.swift in Sources */,
F11583042AA4AB3500122FBB /* Models.swift in Sources */,
F1D3433D29C37024002ED7DE /* SettingsVM.swift in Sources */,
F1A59A3E2A6347880039C95E /* ToastView.swift in Sources */,
F10D66B4298D66C200993237 /* ExamVM.swift in Sources */,
Expand Down Expand Up @@ -712,6 +722,7 @@
F1BE91C22A41DF2A00E85494 /* SubjectListVM.swift in Sources */,
F1A772472A179617004B8DCC /* GradeType+CoreDataClass.swift in Sources */,
F1A7102D2A43757D00255F10 /* CardView.swift in Sources */,
F11583022AA4910200122FBB /* Mapping Model 2 to 3.xcmappingmodel in Sources */,
F1D29E792A17B8AF0001D469 /* ExportJSON.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -1076,10 +1087,11 @@
F1A7720E2A17947A004B8DCC /* Model.xcdatamodeld */ = {
isa = XCVersionGroup;
children = (
F11583002AA490BE00122FBB /* Model 3.xcdatamodel */,
F1A7720F2A17947A004B8DCC /* Model 2.xcdatamodel */,
F1A772102A17947A004B8DCC /* Model.xcdatamodel */,
);
currentVersion = F1A7720F2A17947A004B8DCC /* Model 2.xcdatamodel */;
currentVersion = F11583002AA490BE00122FBB /* Model 3.xcdatamodel */;
path = Model.xcdatamodeld;
sourceTree = "<group>";
versionGroupType = wrapper.xcdatamodel;
Expand Down
14 changes: 6 additions & 8 deletions Calq/Screens/ExamScreen/ExamScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ struct ExamScreen: View {
.padding(.top, 10)

CardContainer {
let exams = vm.hasFiveExams ? 5 : 4
VStack {
ForEach(1...5, id: \.self) { i in
ForEach(1...exams, id: \.self) { i in
ExamView(subject: getExam(i), type: i)
.environmentObject(vm)
}
Expand All @@ -35,8 +36,8 @@ struct ExamScreen: View {
Spacer()

}.onAppear(perform: vm.updateViews)
.padding()
.navigationTitle("ExamViewTitle")
.padding()
.navigationTitle("ExamViewTitle")
}
}
}
Expand All @@ -60,9 +61,7 @@ struct ExamView: View {

var body: some View {
VStack {
ZStack {
Menu {
if !vm.options.isEmpty {
Section {
ForEach(vm.options) {sub in
Button(sub.name) {
Expand All @@ -74,12 +73,11 @@ struct ExamView: View {
}
}

if subject != nil {
if subject != nil && !vm.options.isEmpty {
Section {
deleteExamButton()
}
}
}
} label: {
Button {
} label: {
Expand All @@ -90,7 +88,7 @@ struct ExamView: View {
}
}.buttonStyle(MenuPickerButton(color: getSubjectColor(subject), active: subject != nil))
}
}

HStack {
Text(String(Int(sliderValue.rounded())))
Slider(value: $sliderValue, in: 0...15, onEditingChanged: { _ in
Expand Down
13 changes: 6 additions & 7 deletions Calq/Screens/ExamScreen/ExamVM.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@ import Foundation

class ExamViewModel: ObservableObject {
@Published var subjects: [UserSubject] = []
@Published var options: [UserSubject] = []
@Published var options: [UserSubject] = Util.getAllSubjects().filter {$0.examtype == 0}

@Published var points1 = generateBlockOne()
@Published var points2 = generateBlockTwo()
@Published var maxpoints = generatePossibleBlockOne()

@Published var hasFiveExams = Util.getSettings().hasFiveExams

func updateViews() {
self.objectWillChange.send()
subjects = Util.getAllSubjects()
options = subjects.filter {$0.examtype == 0}

hasFiveExams = Util.getSettings().hasFiveExams
updateBlocks()
}

Expand All @@ -41,10 +43,6 @@ func getExam(_ type: Int) -> UserSubject? {
return subjects.filter {$0.examtype == Int16(type)}.first
}

func getExamOptions(_ subjects: [UserSubject]) -> [UserSubject] {
return subjects.filter {$0.examtype == 0}
}

func resetExams() {
let subjects = Util.getAllSubjects()
subjects.forEach { sub in
Expand Down Expand Up @@ -108,7 +106,8 @@ func generateBlockTwo() -> Int {
var sum: Double = 0

for sub in subjects {
sum += Double(Int(sub.exampoints) * 4)
let multiplier = Util.getSettings().hasFiveExams ? 4 : 5
sum += Double(Int(sub.exampoints) * multiplier)
}

return Int(sum)
Expand Down
69 changes: 43 additions & 26 deletions Calq/Screens/OverviewScreen/OverviewScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,52 @@ struct OverviewScreen: View {
@ObservedObject var vm: OverViewViewModel

var body: some View {

NavigationView {
ScrollView(showsIndicators: false) {
VStack {
CardContainer {
BarChart(values: $vm.subjectValues, heigth: 200, average: vm.generalAverage, round: true)
}

CardContainer {
LineChartView()
}

CardContainer {
VStack(alignment: .leading, spacing: 5) {
Text("OverViewHalfyearChartTitle")
BarChart(values: $vm.halfyears, heigth: 150)
}
}

CardContainer {
CircleViews()
}

if #available(iOS 15.0, *) {
NavigationView {
ScrollView(showsIndicators: false) {
scrollViewBody()
}
}.padding(.horizontal)
.padding(.horizontal)
.navigationTitle("OverViewTitle")
.onAppear {
vm.updateViews()
.onAppear(perform: vm.updateViews)
}
.refreshable {
vm.updateViews()
}

} else {
NavigationView {
ScrollView(showsIndicators: false) {
scrollViewBody()
}
.padding(.horizontal)
.navigationTitle("OverViewTitle")
.onAppear(perform: vm.updateViews)
}
}
}

func scrollViewBody() -> some View {
VStack {
CardContainer {
BarChart(values: $vm.subjectValues, heigth: 200, average: vm.generalAverage, round: true)
}

CardContainer {
LineChartView()
}

CardContainer {
VStack(alignment: .leading, spacing: 5) {
Text("OverViewHalfyearChartTitle")
BarChart(values: $vm.halfyears, heigth: 150)
}
}

CardContainer {
CircleViews()
}

}
}

Expand Down
19 changes: 15 additions & 4 deletions Calq/Screens/SettingsScreens/SettingsScreen/SettingsScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ struct SettingsScreen: View {
.alert(isPresented: $vm.deleteAlert) {
settingsAlert()
}
.onAppear {
vm.subjects = Util.getAllSubjects()
}
.onAppear(perform: vm.onAppear)
}

func settingsAlert() -> Alert {
Expand Down Expand Up @@ -89,10 +87,23 @@ struct SettingsScreen: View {
}
})

HStack {
SettingsIcon(color: Color(hexString: "5856d6"), icon: "numbersign", text: "settingsExamCount") {}
Spacer()
Picker("", selection: $vm.hasFiveExams) {
Text("4").tag(4)
Text("5").tag(5)
}.pickerStyle(.segmented)
.onChange(of: vm.hasFiveExams) { _ in
vm.updateExamSettings()
}
.frame(width: 70)
}

HStack {
SettingsIcon(color: Color.accentColor, icon: "chart.bar.fill", text: "settingsRainbow") {}
Toggle(isOn: $vm.settings.colorfulCharts) {}.onChange(of: vm.settings.colorfulCharts) { _ in
vm.reloadAndSave()
vm.updateColorfulCharts()
}.toggleStyle(SwitchToggleStyle(tint: .accentColor))
}

Expand Down
22 changes: 19 additions & 3 deletions Calq/Screens/SettingsScreens/SettingsScreen/SettingsVM.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class SettingsViewModel: ObservableObject {
@Published var subjects: [UserSubject] = Util.getAllSubjects()
@Published var selectedSubjet: UserSubject?

@Published var hasFiveExams = Util.getSettings().hasFiveExams ? 5 : 4

// sheet presnet stuff
@Published var editSubjectPresented = false
@Published var weightSheetPresented = false
Expand All @@ -36,10 +38,8 @@ class SettingsViewModel: ObservableObject {
@Published var importeJsonURL: URL = URL(fileURLWithPath: "")

func reloadAndSave() {
settings.colorfulCharts = Util.getSettings().colorfulCharts
saveCoreData()
subjects = Util.getAllSubjects()
settings = Util.getSettings()
saveCoreData()
}

func deleteData() {
Expand All @@ -62,4 +62,20 @@ class SettingsViewModel: ObservableObject {
deleteAlert = false
reloadAndSave()
}

func updateColorfulCharts() {
settings.colorfulCharts = Util.getSettings().colorfulCharts
saveCoreData()
}

func updateExamSettings() {
settings.hasFiveExams = hasFiveExams == 5
saveCoreData()
}

func onAppear() {
subjects = Util.getAllSubjects()
settings = Util.getSettings()
hasFiveExams = settings.hasFiveExams ? 5 : 4
}
}
1 change: 1 addition & 0 deletions Calq/de.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"settingsImport"= "Noten importieren";
"settingsExport"= "Noten exportieren";
"settingsRainbow"= "Regenbogen";
"settingsExamCount"= "Anzahl Abiturprüfungen";
"settingsWeight"= "Wertung ändern";
"settingsLoadDemo"= "Demo Daten laden";
"settingsDelete"= "Daten löschen";
Expand Down
Loading