Adding preview content, improvements to RaPla stuff

- Now updating locally stored events instead of deleting them and creating completely new events
- Added text color in the list view to distinguish exams from lectures
This commit is contained in:
2021-01-31 19:49:52 +01:00
committed by Patrick Müller
parent 95f06cc87d
commit fdbd88ce01
4 changed files with 103 additions and 26 deletions
+40 -5
View File
@@ -10,13 +10,28 @@ import CoreData
struct LecturePlanList: View {
@State private var events: [NSManagedObject] = []
@State private var sortingAscending = true
var body: some View {
List {
ForEach(events, id: \.self) { event in
HStack {
Text(formatDate(date: event.value(forKeyPath: "startDate") as! Date))
Text(event.value(forKeyPath: "summary") as! String)
VStack {
Button(action: {
// This is obviously bullshit, but it could be used to sort afer summary or smth like that
self.sortingAscending = !self.sortingAscending
let sectionSortDescriptor = NSSortDescriptor(key: "startDate", ascending: sortingAscending)
let sortDescriptors = [sectionSortDescriptor]
self.events = UtilityFunctions.getCoreDataObject(entity: "RaPlaEvent", sortDescriptors: sortDescriptors)
}){
Text("Switch order")
}
List {
ForEach(events, id: \.self) { event in
HStack {
Text(formatDate(date: event.value(forKeyPath: "startDate") as! Date))
.foregroundColor(getEventForegroundColor(for: event))
Text(event.value(forKeyPath: "summary") as! String)
.foregroundColor(getEventForegroundColor(for: event))
}
}
}
}.onAppear{
@@ -30,6 +45,15 @@ struct LecturePlanList: View {
struct LecturePlanList_Previews: PreviewProvider {
static var previews: some View {
LecturePlanList()
.preferredColorScheme(.dark)
.environmentObject(getFirstOpening())
.environment(\.managedObjectContext, PersistenceController.preview.container.viewContext)
}
static func getFirstOpening() -> LocalSettings {
let settings = LocalSettings();
settings.isFirstOpening = false;
return settings
}
}
@@ -39,4 +63,15 @@ extension LecturePlanList {
formatter.dateStyle = .short
return formatter.string(from: date)
}
private func getEventForegroundColor(for event: NSManagedObject) -> Color {
var textColor: Color = .primary
if(event.value(forKeyPath: "category") as! String == "Prüfung") {
textColor = Color.red
} else {
textColor = Color.primary
}
return textColor
}
}