Skip to content

Commit

Permalink
Merge pull request #118 from AKORA-Studios/Updated-Grade-Weight
Browse files Browse the repository at this point in the history
Updated grade weight to zhave Doublke Values
  • Loading branch information
DragonCat4012 authored Jan 6, 2025
2 parents 1899189 + 7c2fe29 commit 213c2a2
Show file tree
Hide file tree
Showing 15 changed files with 370 additions and 58 deletions.
16 changes: 11 additions & 5 deletions Calq.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
F17F4448298C4ED3000A3993 /* NewGradeScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = F17F4447298C4ED3000A3993 /* NewGradeScreen.swift */; };
F17F444A298C4EE7000A3993 /* SubjectListScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = F17F4449298C4EE7000A3993 /* SubjectListScreen.swift */; };
F17F445E298C59B3000A3993 /* ColorExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = F17F445D298C59B3000A3993 /* ColorExtension.swift */; };
F17F76FD2D2BC01B00018306 /* Mapping Model 3 to 4.xcmappingmodel in Sources */ = {isa = PBXBuildFile; fileRef = F17F76FC2D2BC01B00018306 /* Mapping Model 3 to 4.xcmappingmodel */; };
F192DD24299D10CB0077B905 /* NewSubject.swift in Sources */ = {isa = PBXBuildFile; fileRef = F192DD23299D10CB0077B905 /* NewSubject.swift */; };
F192DD25299D2CD00077B905 /* BarChart.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD8813782764D58B00EB6BD8 /* BarChart.swift */; };
F192DD28299D2DEC0077B905 /* ViewExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = F192DD27299D2DEC0077B905 /* ViewExtension.swift */; };
Expand Down Expand Up @@ -212,6 +213,8 @@
F17F4447298C4ED3000A3993 /* NewGradeScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewGradeScreen.swift; sourceTree = "<group>"; };
F17F4449298C4EE7000A3993 /* SubjectListScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SubjectListScreen.swift; sourceTree = "<group>"; };
F17F445D298C59B3000A3993 /* ColorExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ColorExtension.swift; sourceTree = "<group>"; };
F17F76FB2D2BBF9F00018306 /* Model 4.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "Model 4.xcdatamodel"; sourceTree = "<group>"; };
F17F76FC2D2BC01B00018306 /* Mapping Model 3 to 4.xcmappingmodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcmappingmodel; path = "Mapping Model 3 to 4.xcmappingmodel"; sourceTree = "<group>"; };
F192DD23299D10CB0077B905 /* NewSubject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewSubject.swift; sourceTree = "<group>"; };
F192DD27299D2DEC0077B905 /* ViewExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewExtension.swift; sourceTree = "<group>"; };
F19B10A429AF84C000B11C82 /* OverviewVM.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OverviewVM.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -418,6 +421,7 @@
F1A772332A1795C6004B8DCC /* UserSubject+CoreDataClass.swift */,
F1A772342A1795C6004B8DCC /* UserSubject+CoreDataProperties.swift */,
F1A7720E2A17947A004B8DCC /* Model.xcdatamodeld */,
F17F76FC2D2BC01B00018306 /* Mapping Model 3 to 4.xcmappingmodel */,
F11583012AA4910200122FBB /* Mapping Model 2 to 3.xcmappingmodel */,
F1AAEF282A1BC1E5000CD044 /* Mapping Model 1.xcmappingmodel */,
DD4F97522751167000D3CC57 /* CoreDataStack.swift */,
Expand Down Expand Up @@ -905,6 +909,7 @@
F1B0B16C299648C400F3D1FD /* GradeTableOverviewScreen.swift in Sources */,
F1A772082A17940B004B8DCC /* MigrationPolicy.swift in Sources */,
F1BE91C22A41DF2A00E85494 /* SubjectListVM.swift in Sources */,
F17F76FD2D2BC01B00018306 /* Mapping Model 3 to 4.xcmappingmodel in Sources */,
F1A772472A179617004B8DCC /* GradeType+CoreDataClass.swift in Sources */,
F1A7102D2A43757D00255F10 /* CardView.swift in Sources */,
F11583022AA4910200122FBB /* Mapping Model 2 to 3.xcmappingmodel in Sources */,
Expand Down Expand Up @@ -1154,15 +1159,15 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = Calq/CalqDebug.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 3;
CURRENT_PROJECT_VERSION = 0;
DEVELOPMENT_TEAM = 93TVBDWQK4;
INFOPLIST_FILE = Calq/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 3.3.7;
MARKETING_VERSION = 3.4.0;
PRODUCT_BUNDLE_IDENTIFIER = AKORA.Calq;
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
Expand All @@ -1181,15 +1186,15 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_ENTITLEMENTS = Calq/CalqRelease.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 3;
CURRENT_PROJECT_VERSION = 0;
DEVELOPMENT_TEAM = 93TVBDWQK4;
INFOPLIST_FILE = Calq/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 3.3.7;
MARKETING_VERSION = 3.4.0;
PRODUCT_BUNDLE_IDENTIFIER = AKORA.Calq;
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
Expand Down Expand Up @@ -1287,11 +1292,12 @@
F1A7720E2A17947A004B8DCC /* Model.xcdatamodeld */ = {
isa = XCVersionGroup;
children = (
F17F76FB2D2BBF9F00018306 /* Model 4.xcdatamodel */,
F11583002AA490BE00122FBB /* Model 3.xcdatamodel */,
F1A7720F2A17947A004B8DCC /* Model 2.xcdatamodel */,
F1A772102A17947A004B8DCC /* Model.xcdatamodel */,
);
currentVersion = F11583002AA490BE00122FBB /* Model 3.xcdatamodel */;
currentVersion = F17F76FB2D2BBF9F00018306 /* Model 4.xcdatamodel */;
path = Model.xcdatamodeld;
sourceTree = "<group>";
versionGroupType = wrapper.xcdatamodel;
Expand Down
65 changes: 51 additions & 14 deletions Calq/Screens/SettingsScreens/EditWeight/EditWeightScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,35 @@ struct ChangeWeightScreen: View {

var body: some View {
VStack {

HStack {
Text("EditWeigthDesc")
Image(systemName: "info.circle").onTapGesture {
vm.toggleHintText()
}
}

if vm.showHintText {
Text("EditWeigthPrimaryHint").font(.footnote)
.multilineTextAlignment(.center)
.padding(.top, 5)
Text("EditWeigthPrimaryHint")
.foregroundColor(vm.showHintText ? .labelColor : .backgroundColor)
.font(.footnote)
.multilineTextAlignment(.center)
.padding(.top, 5)

VStack {
Text("EditWeigthPickerTitle").frame(maxWidth: .infinity, alignment: .leading)
Picker("EditWeigthPickerTitle", selection: $vm.selectedStepSize) {
Text("10").tag(stepSize.tenth)
Text("1").tag(stepSize.ones)
Text("0.1").tag(stepSize.fraction)
}
.pickerStyle(.segmented)
}
.padding()

List {
exampleWeightView()

Section {
ForEach(vm.types) { type in
ForEach(vm.types.sorted(by: {$0.weigth > $1.weigth})) { type in
HStack {
HStack {
if Util.isPrimaryType(type) {
Expand All @@ -49,24 +61,24 @@ struct ChangeWeightScreen: View {
}

if let typeWeight = vm.typeArr[type] {
Text("\(typeWeight)")
Text("\(typeWeight.shorted)")
.foregroundStyle(weightColor(typeWeight))
.frame(width: 25).font(.footnote)
.frame(width: 30).font(.footnote)

TextField("", text: vm.binding(for: type.id))
.foregroundStyle(weightColor(typeWeight))
}

Spacer()

Stepper("") {
vm.increment(type)
} onDecrement: {
vm.decrement(type)
}

deleteView(type)

if vm.showHintText {
Text("\(type.id)").foregroundColor(Color.gray).frame(width: 10).font(.footnote)
}
Expand All @@ -82,7 +94,7 @@ struct ChangeWeightScreen: View {
.padding(0)

Spacer()
Text("EditWeigthSum\(vm.summedUp)")
Text("EditWeigthSum\(vm.summedUp) %")
.foregroundColor(vm.summedUp > 100 ? Color.red : Color.gray)

Button("saveDataWeight") {
Expand All @@ -105,6 +117,31 @@ struct ChangeWeightScreen: View {
}
}

func exampleWeightView() -> some View {
Section {
HStack {
Image(systemName: "star")

Text("%")
.foregroundStyle(.gray)
.frame(width: 30).font(.footnote)

Text("Name")
.foregroundStyle(.gray)

Spacer()

Stepper("") {
} onDecrement: {
}.disabled(true)

if vm.showHintText {
Text("ID").foregroundColor(Color.gray).frame(width: 10).font(.footnote)
}
}
}
}

@ViewBuilder
func deleteView(_ type: GradeType) -> some View {
if vm.types.count > 2 && vm.getGradesForType(type).isEmpty {
Expand All @@ -113,8 +150,8 @@ struct ChangeWeightScreen: View {
}
}

func weightColor(_ weight: Int16) -> Color {
return weight > 0 ? Color(uiColor: UIColor.label) : Color.red
func weightColor(_ weight: Double) -> Color {
return weight > 0.0 ? Color(uiColor: UIColor.label) : Color.red
}

func saveChanges() {
Expand Down
39 changes: 30 additions & 9 deletions Calq/Screens/SettingsScreens/EditWeight/WeightViewmodel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,14 @@ enum AlertType {
case wrongPercentage
}

enum stepSize {
case tenth
case ones
case fraction
}

class WeightViewmodel: ObservableObject {
@Published var typeArr: [GradeType: Int16] = [:]
@Published var typeArr: [GradeType: Double] = [:]
@Published var summedUp: Int = 0

@Published var selectedDelete: Int16 = 0
Expand All @@ -25,6 +31,8 @@ class WeightViewmodel: ObservableObject {

@Published var types = Util.getTypes()

@Published var selectedStepSize = stepSize.tenth

init() {
load()
reload()
Expand All @@ -47,26 +55,36 @@ class WeightViewmodel: ObservableObject {
}

func increment(_ type: GradeType) {
guard let aloha = typeArr[type] else { return }
typeArr[type]! += typeArr[type]! >= 100 ? 0 : 10
// if typeArr[type]! < 0 { typeArr[type]! = 0}
if typeArr[type] == nil { return }
typeArr[type]! += typeArr[type]! >= 100 ? 0 : getStepValue()
reload()
}

func decrement(_ type: GradeType) {
guard let _ = typeArr[type] else { return }
typeArr[type]! -= typeArr[type]! <= 0 ? 0 : 10
if typeArr[type] == nil { return }
typeArr[type]! -= typeArr[type]! <= 0 ? 0 : getStepValue()
if typeArr[type]! < 0 { typeArr[type]! = 0}
reload()
}

func getStepValue() -> Double {
switch selectedStepSize {
case .tenth:
return 10.0
case .ones:
return 1.0
case .fraction:
return 0.1
}
}

func reload() {
summedUp = Int(Array(typeArr.values).reduce(0, +))
}

func saveWeigths() {
for type in types {
if let typeWeight = typeArr[type],
if let typeWeight = typeArr[type],
let typeName = typeArrNames[type.id] {
type.weigth = typeWeight
type.name = typeName
Expand Down Expand Up @@ -98,8 +116,11 @@ class WeightViewmodel: ObservableObject {

func addWeigth() {
let newName = "Type \(typeArr.count)"
Util.addType(name: newName, weigth: 0)
load()
let newType = Util.addType(name: newName, weigth: 0)
typeArr[newType] = newType.weigth
typeArrNames[newType.id] = newType.name
types.append(newType)
objectWillChange.send()
}

func removeWeigth() {
Expand Down
12 changes: 2 additions & 10 deletions Calq/Screens/WhatsNewScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,11 @@ struct WhatsNewScreen: View {
@EnvironmentObject var vm: TabVM

let newFuncs = [
"📥 save Backup",
"🗒️ Export to PDF (experimental)",
"📄 PDF & JSON export preview",
"🌸 Fixed Missing Impact Number",
"💾 Removed common crash sources"
"⚙️ Grade weights can now also be 51.3!"
]

let newFuncsGeneral = [
"📥 Backups speichern",
"🗒️ Export zu PDF (experimentell)",
"📄 PDF & JSON Export Vorschau",
"🌸 Fehlende Zahl beim Einfluss gefixt",
"💾 Entfernen von häufige Absturzquellen"
"⚙️ Notengewichte können nurn auch 51.3 sein!"
]

let lang = Locale.preferredLanguages[0]
Expand Down
3 changes: 2 additions & 1 deletion Calq/de.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
"EditWeigthWarning %@"="Bitte ändere den Typ dieser Noten: %@";
"EditWeigthWarningTitle"="Wuah warte";
"EditWeigthNew"="Neuen Typ hinzufügen";
"EditWeigthPrimaryHint"="Tippe lang auf den Stern um den hervorgehobenen Notentypen auszuwählen";
"EditWeigthPrimaryHint"="Tippe lang auf den Stern um den hervorgehobenen Notentypen auszuwählen.\n Typen können nur gelöscht werden wenn diese von keinen Noten mehr verwendet werden.";
"EditWeigthPickerTitle"="Stufengröße";

"editSubject"="Kurs bearbeiten";
"editSubDelete"="Fach löschen";
Expand Down
3 changes: 2 additions & 1 deletion Calq/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
"EditWeigthWarning %@"="Pls change the type of the following grades to something else: %@";
"EditWeigthWarningTitle"="Wuah wait";
"EditWeigthNew"="Add new type";
"EditWeigthPrimaryHint"="Press long on the star icon to change the which grade type should be highlited";
"EditWeigthPrimaryHint"="Press long on the star icon to change the which grade type should be highlited.\nTypes can only be deleted when no grade has them assigned anymore.";
"EditWeigthPickerTitle"="Stepsize";

"editSubject"="Edit Subject";
"editSubDelete"="Delete Subject";
Expand Down
2 changes: 1 addition & 1 deletion Calq/lib/ColorExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ extension UIColor {
}

extension Color {

static let labelColor = Color(UIColor.label)
static let backgroundColor = Color(UIColor.backgroundColor)
static let cardShadow = Color(UIColor.cardShadow)

Expand Down
Loading

0 comments on commit 213c2a2

Please sign in to comment.