mirror of
https://github.com/Mueller-Patrick/DHBW-Service-App.git
synced 2026-05-26 12:38:05 +00:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 590e89fb1a | |||
| 543bd190eb | |||
| f6e1d979fd |
@@ -7,6 +7,7 @@
|
||||
objects = {
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
42560FA0264AB7E40062053B /* ColorExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 42560F9F264AB7E40062053B /* ColorExtension.swift */; };
|
||||
CD17FAD025C9F93B0088D700 /* HomeView.strings in Resources */ = {isa = PBXBuildFile; fileRef = CD17FAD225C9F93B0088D700 /* HomeView.strings */; };
|
||||
CD2FC0C525A869FE00963178 /* dhbw-standard-icon@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = CD2FC0C025A869FE00963178 /* dhbw-standard-icon@2x.png */; };
|
||||
CD2FC0C625A869FE00963178 /* dhbw-standard-icon@3x.png in Resources */ = {isa = PBXBuildFile; fileRef = CD2FC0C125A869FE00963178 /* dhbw-standard-icon@3x.png */; };
|
||||
@@ -27,6 +28,7 @@
|
||||
CD9FABA3258EC60600D6D0C5 /* DHBW_ServiceUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD9FABA2258EC60600D6D0C5 /* DHBW_ServiceUITests.swift */; };
|
||||
CDA1CBAE25D4591000DB2AE5 /* User+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDA1CBA825D4591000DB2AE5 /* User+CoreDataProperties.swift */; };
|
||||
CDA1CBB025D4591000DB2AE5 /* Lecturer+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDA1CBAA25D4591000DB2AE5 /* Lecturer+CoreDataProperties.swift */; };
|
||||
CDB1E947261DDA0200EDE9EB /* DateExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDB1E946261DDA0200EDE9EB /* DateExtension.swift */; };
|
||||
CDCD721A25912E1200FBF2F5 /* HomeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDCD721925912E1200FBF2F5 /* HomeView.swift */; };
|
||||
CDCD72242591316500FBF2F5 /* LocalSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDCD72232591316500FBF2F5 /* LocalSettings.swift */; };
|
||||
CDCD7230259135C500FBF2F5 /* FirstOpeningSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = CDCD722F259135C500FBF2F5 /* FirstOpeningSettings.swift */; };
|
||||
@@ -60,6 +62,7 @@
|
||||
/* End PBXContainerItemProxy section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
42560F9F264AB7E40062053B /* ColorExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ColorExtension.swift; sourceTree = "<group>"; };
|
||||
CD17FAD125C9F93B0088D700 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/HomeView.strings; sourceTree = "<group>"; };
|
||||
CD17FAD625C9F9440088D700 /* de */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = de; path = de.lproj/HomeView.strings; sourceTree = "<group>"; };
|
||||
CD2FC0C025A869FE00963178 /* dhbw-standard-icon@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "dhbw-standard-icon@2x.png"; sourceTree = "<group>"; };
|
||||
@@ -70,7 +73,6 @@
|
||||
CD730A34259A860E00E0BB69 /* SettingsAcknowledgements.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsAcknowledgements.swift; sourceTree = "<group>"; };
|
||||
CD8555BD25C47AE500C4ACD6 /* RaPlaFetcher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RaPlaFetcher.swift; sourceTree = "<group>"; };
|
||||
CD8555C225C47B5300C4ACD6 /* ApiService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApiService.swift; sourceTree = "<group>"; };
|
||||
CD9E3F0A25DC3C9A00C77D10 /* DHBW-Service.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = "DHBW-Service.entitlements"; sourceTree = "<group>"; };
|
||||
CD9E3F0E25DC466100C77D10 /* SettingsPushNotifications.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsPushNotifications.swift; sourceTree = "<group>"; };
|
||||
CD9FAB7D258EC60200D6D0C5 /* DHBW-Service.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "DHBW-Service.app"; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
CD9FAB80258EC60200D6D0C5 /* DHBW_ServiceApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DHBW_ServiceApp.swift; sourceTree = "<group>"; };
|
||||
@@ -88,6 +90,7 @@
|
||||
CD9FABA4258EC60600D6D0C5 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
CDA1CBA825D4591000DB2AE5 /* User+CoreDataProperties.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = "User+CoreDataProperties.swift"; path = "DHBW-Service/CoreData/Models/User+CoreDataProperties.swift"; sourceTree = SOURCE_ROOT; };
|
||||
CDA1CBAA25D4591000DB2AE5 /* Lecturer+CoreDataProperties.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = "Lecturer+CoreDataProperties.swift"; path = "DHBW-Service/CoreData/Models/Lecturer+CoreDataProperties.swift"; sourceTree = SOURCE_ROOT; };
|
||||
CDB1E946261DDA0200EDE9EB /* DateExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DateExtension.swift; sourceTree = "<group>"; };
|
||||
CDCD721925912E1200FBF2F5 /* HomeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeView.swift; sourceTree = "<group>"; };
|
||||
CDCD72232591316500FBF2F5 /* LocalSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocalSettings.swift; sourceTree = "<group>"; };
|
||||
CDCD722F259135C500FBF2F5 /* FirstOpeningSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FirstOpeningSettings.swift; sourceTree = "<group>"; };
|
||||
@@ -210,7 +213,6 @@
|
||||
CD9FAB7F258EC60200D6D0C5 /* DHBW-Service */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
CD9E3F0A25DC3C9A00C77D10 /* DHBW-Service.entitlements */,
|
||||
CDCD720F25912D3C00FBF2F5 /* App */,
|
||||
CDCD721025912D4900FBF2F5 /* Views */,
|
||||
CDDCF4792591FE410027CDC5 /* Utility */,
|
||||
@@ -321,6 +323,8 @@
|
||||
CDDCF47A2591FE550027CDC5 /* UtilityFunctions.swift */,
|
||||
CD8555BD25C47AE500C4ACD6 /* RaPlaFetcher.swift */,
|
||||
CD8555C225C47B5300C4ACD6 /* ApiService.swift */,
|
||||
CDB1E946261DDA0200EDE9EB /* DateExtension.swift */,
|
||||
42560F9F264AB7E40062053B /* ColorExtension.swift */,
|
||||
);
|
||||
path = Utility;
|
||||
sourceTree = "<group>";
|
||||
@@ -476,6 +480,7 @@
|
||||
CDDCF4842592028A0027CDC5 /* Localizer.swift in Sources */,
|
||||
CDD970DF25D453D90061755E /* Lecturer+CoreDataClass.swift in Sources */,
|
||||
CDCD7230259135C500FBF2F5 /* FirstOpeningSettings.swift in Sources */,
|
||||
42560FA0264AB7E40062053B /* ColorExtension.swift in Sources */,
|
||||
CDA1CBB025D4591000DB2AE5 /* Lecturer+CoreDataProperties.swift in Sources */,
|
||||
CD9FAB8A258EC60600D6D0C5 /* Persistence.swift in Sources */,
|
||||
CD730A35259A860E00E0BB69 /* SettingsAcknowledgements.swift in Sources */,
|
||||
@@ -487,6 +492,7 @@
|
||||
CD8555BE25C47AE500C4ACD6 /* RaPlaFetcher.swift in Sources */,
|
||||
CDEA70C025C85999001CFE28 /* LecturePlanItem.swift in Sources */,
|
||||
CD8555C325C47B5300C4ACD6 /* ApiService.swift in Sources */,
|
||||
CDB1E947261DDA0200EDE9EB /* DateExtension.swift in Sources */,
|
||||
CD9FAB8D258EC60600D6D0C5 /* DHBW_Service.xcdatamodeld in Sources */,
|
||||
CDCD721A25912E1200FBF2F5 /* HomeView.swift in Sources */,
|
||||
CDD39B4B259A64150078D05F /* SettingsMain.swift in Sources */,
|
||||
@@ -683,9 +689,8 @@
|
||||
buildSettings = {
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
|
||||
CODE_SIGN_ENTITLEMENTS = "DHBW-Service/DHBW-Service.entitlements";
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CURRENT_PROJECT_VERSION = 1.0.1;
|
||||
CURRENT_PROJECT_VERSION = 1.0.2;
|
||||
DEVELOPMENT_ASSET_PATHS = "\"DHBW-Service/Preview Content\"";
|
||||
DEVELOPMENT_TEAM = HS7KNT4MZ2;
|
||||
ENABLE_PREVIEWS = YES;
|
||||
@@ -707,9 +712,8 @@
|
||||
buildSettings = {
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
|
||||
CODE_SIGN_ENTITLEMENTS = "DHBW-Service/DHBW-Service.entitlements";
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CURRENT_PROJECT_VERSION = 1.0.1;
|
||||
CURRENT_PROJECT_VERSION = 1.0.2;
|
||||
DEVELOPMENT_ASSET_PATHS = "\"DHBW-Service/Preview Content\"";
|
||||
DEVELOPMENT_TEAM = HS7KNT4MZ2;
|
||||
ENABLE_PREVIEWS = YES;
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
//
|
||||
// ColorExtension.swift
|
||||
// DHBW-Service
|
||||
//
|
||||
// Created by Lisa Kletsko on 11.05.21.
|
||||
//
|
||||
import SwiftUI
|
||||
import Foundation
|
||||
extension Color {
|
||||
// For Darkmode
|
||||
static let darkModeDarkColor = Color(red: 16 / 255, green: 32 / 255, blue: 39 / 255)
|
||||
static let darkModePrimaryColor = Color(red: 55 / 255, green: 71 / 255, blue: 79 / 255)
|
||||
static let darkModeLightColor = Color(red: 98 / 255, green: 114 / 255, blue: 123 / 255)
|
||||
// For Lightmode
|
||||
static let lightkModeDarkColor = Color(red: 174 / 255, green: 174 / 255, blue: 174 / 255)
|
||||
static let lightModePrimaryColor = Color(red: 224 / 255, green: 224 / 255, blue: 224 / 255)
|
||||
static let lightModeLightColor = Color(red: 255 / 255, green: 255 / 255, blue: 255 / 255)
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
//
|
||||
// DateExtension.swift
|
||||
// DHBW-Service
|
||||
//
|
||||
// Created by Patrick Müller on 07.04.21.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
extension Date {
|
||||
func get(_ components: Calendar.Component..., calendar: Calendar = Calendar.current) -> DateComponents {
|
||||
return calendar.dateComponents(Set(components), from: self)
|
||||
}
|
||||
|
||||
func get(_ component: Calendar.Component, calendar: Calendar = Calendar.current) -> Int {
|
||||
return calendar.component(component, from: self)
|
||||
}
|
||||
}
|
||||
@@ -264,6 +264,8 @@ class RaPlaFetcher {
|
||||
print("Found unknown frequency: " + event.frequency)
|
||||
}
|
||||
|
||||
// (offsetAmount * iteration) because for the 1st event, we dont want to add an offset, and
|
||||
// for every event after that we want to add e.g. 1 week, 2 weeks, 3 weeks etc.
|
||||
let startDate = Calendar.current.date(byAdding: offsetType, value: (offsetAmount * iteration), to: event.startDate)!
|
||||
let endDate = Calendar.current.date(byAdding: offsetType, value: (offsetAmount * iteration), to: event.endDate)!
|
||||
|
||||
@@ -288,8 +290,6 @@ class RaPlaFetcher {
|
||||
}
|
||||
|
||||
// Populate fields
|
||||
// (offsetAmount * iteration) because for the 1st event, we dont want to add an offset, and
|
||||
// for every event after that we want to add e.g. 1 week, 2 weeks, 3 weeks etc.
|
||||
evt.startDate = startDate
|
||||
evt.endDate = endDate
|
||||
evt.summary = event.summary
|
||||
@@ -298,6 +298,8 @@ class RaPlaFetcher {
|
||||
evt.category = event.category
|
||||
evt.uid = newUID
|
||||
for lecturer in event.lecturers {
|
||||
// TODO: Delete all old lecturer objects
|
||||
|
||||
let lect = Lecturer(context: PersistenceController.shared.context)
|
||||
lect.name = lecturer.name
|
||||
lect.email = lecturer.email
|
||||
|
||||
@@ -33,7 +33,7 @@ struct HomeView: View {
|
||||
.padding()
|
||||
.background(
|
||||
RoundedRectangle(cornerRadius: 10)
|
||||
.fill(Color.gray)
|
||||
.fill(Color.darkModePrimaryColor)
|
||||
)
|
||||
Spacer()
|
||||
}
|
||||
@@ -41,7 +41,8 @@ struct HomeView: View {
|
||||
Spacer()
|
||||
VStack {
|
||||
Text("information".localized(tableName: "HomeView", plural: false))
|
||||
.font(.title3)
|
||||
.font(.headline)
|
||||
.fontWeight(.semibold)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
HStack {
|
||||
VStack(alignment: .leading) {
|
||||
@@ -59,7 +60,7 @@ struct HomeView: View {
|
||||
.padding()
|
||||
.background(
|
||||
RoundedRectangle(cornerRadius: 10)
|
||||
.fill(Color.gray)
|
||||
.fill(Color.darkModePrimaryColor)
|
||||
)
|
||||
Spacer()
|
||||
}
|
||||
@@ -228,7 +229,8 @@ struct UpcomingLecturesBlock: View {
|
||||
var body: some View {
|
||||
VStack {
|
||||
Text(titleKey.localized(tableName: "HomeView"))
|
||||
.font(.title)
|
||||
.font(.title2)
|
||||
.fontWeight(.semibold)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
VStack {
|
||||
if(!eventsList.isEmpty){
|
||||
@@ -245,7 +247,7 @@ struct UpcomingLecturesBlock: View {
|
||||
.padding()
|
||||
.background(
|
||||
RoundedRectangle(cornerRadius: 10)
|
||||
.fill(Color.gray)
|
||||
.fill(Color.darkModePrimaryColor)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -274,11 +276,11 @@ struct UpcomingExamsBlock: View {
|
||||
.padding()
|
||||
.background(
|
||||
RoundedRectangle(cornerRadius: 10)
|
||||
.fill(Color.gray)
|
||||
.fill(Color.darkModePrimaryColor)
|
||||
)
|
||||
.overlay(
|
||||
RoundedRectangle(cornerRadius: 10)
|
||||
.stroke(Color.red, lineWidth: 4)
|
||||
.stroke(Color("AccentColor"), lineWidth: 4)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +46,6 @@ struct LecturePlanItem: View {
|
||||
Button(action: {
|
||||
event.isHidden = !isHidden
|
||||
self.isHidden = !isHidden
|
||||
PersistenceController.shared.save()
|
||||
}){
|
||||
if(self.isHidden){
|
||||
Text("Show")
|
||||
@@ -74,6 +73,9 @@ struct LecturePlanItem: View {
|
||||
.onAppear{
|
||||
self.isHidden = event.isHidden
|
||||
}
|
||||
.onDisappear{
|
||||
PersistenceController.shared.save()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,39 +7,32 @@
|
||||
|
||||
import SwiftUI
|
||||
import CoreData
|
||||
import Combine
|
||||
|
||||
struct LecturePlanList: View {
|
||||
@State private var events: [RaPlaEvent] = []
|
||||
@State private var daysWithEvents: [Date:[RaPlaEvent]] = [:]
|
||||
@State private var sortingAscending = true
|
||||
|
||||
|
||||
var body: some View {
|
||||
NavigationView() {
|
||||
List {
|
||||
ForEach(events, id: \.self) { event in
|
||||
NavigationLink(destination: LecturePlanItem(event: event)){
|
||||
ScrollView(.vertical) {
|
||||
ScrollViewReader { scrollView in
|
||||
// Button("Jump to today") {
|
||||
// withAnimation(){
|
||||
// scrollView.scrollTo(8, anchor: .center)
|
||||
// }
|
||||
// }
|
||||
// .padding()
|
||||
|
||||
ForEach(daysWithEvents.sorted(by: {$0.key < $1.key}), id: \.key) { key, value in
|
||||
HStack {
|
||||
Text(formatDate(date: event.startDate!))
|
||||
.foregroundColor(getEventForegroundColor(for: event))
|
||||
Text(event.summary!)
|
||||
.foregroundColor(getEventForegroundColor(for: event))
|
||||
|
||||
Spacer()
|
||||
|
||||
if(event.isHidden) {
|
||||
Image(systemName: "eye.slash")
|
||||
.foregroundColor(.red)
|
||||
} else {
|
||||
Image(systemName: "eye")
|
||||
}
|
||||
DayWithEventsBlock(date: key, eventsList: value, parent: self)
|
||||
Spacer()
|
||||
}
|
||||
}
|
||||
// When an event gets updated from child view, reload it here as this will not trigger the onAppear() function
|
||||
.onReceive(event.objectWillChange, perform: { _ in
|
||||
let sectionSortDescriptor = NSSortDescriptor(key: "startDate", ascending: true)
|
||||
let sortDescriptors = [sectionSortDescriptor]
|
||||
self.events = []
|
||||
self.events = RaPlaEvent.getSpecified(sortDescriptors: sortDescriptors)
|
||||
})
|
||||
}
|
||||
}
|
||||
.navigationBarTitle(Text("Lectures"))
|
||||
@@ -58,10 +51,8 @@ struct LecturePlanList: View {
|
||||
}
|
||||
.navigationViewStyle(StackNavigationViewStyle())
|
||||
.onAppear{
|
||||
let sectionSortDescriptor = NSSortDescriptor(key: "startDate", ascending: true)
|
||||
let sortDescriptors = [sectionSortDescriptor]
|
||||
self.events = []
|
||||
self.events = RaPlaEvent.getSpecified(sortDescriptors: sortDescriptors)
|
||||
self.getRaPlaEvents()
|
||||
self.findNextDay()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -83,13 +74,22 @@ struct LecturePlanList_Previews: PreviewProvider {
|
||||
}
|
||||
|
||||
extension LecturePlanList {
|
||||
private func formatDate(date: Date) -> String {
|
||||
public func formatDate(date: Date) -> String {
|
||||
let formatter = DateFormatter()
|
||||
formatter.dateStyle = .short
|
||||
return formatter.string(from: date)
|
||||
}
|
||||
|
||||
private func getEventForegroundColor(for event: RaPlaEvent) -> Color {
|
||||
public func formatTime(date: Date) -> String {
|
||||
let formatter = DateFormatter()
|
||||
formatter.timeStyle = .short
|
||||
return formatter.string(from: date)
|
||||
}
|
||||
|
||||
/**
|
||||
Get the correct foreground color for the given event, e.g. primary for normal events and red for exams.
|
||||
*/
|
||||
public func getEventForegroundColor(for event: RaPlaEvent) -> Color {
|
||||
var textColor: Color = .primary
|
||||
if(event.category! == "Prüfung") {
|
||||
textColor = Color.red
|
||||
@@ -99,4 +99,136 @@ extension LecturePlanList {
|
||||
|
||||
return textColor
|
||||
}
|
||||
|
||||
/**
|
||||
DEPRECATED, used to find the element in the list of days that represents the next day
|
||||
*/
|
||||
public func findNextDay() {
|
||||
// As this list is already sorted ascending, we can just return the first event with a start date that is in the future
|
||||
let sortedEvents = self.events.sorted(by: { $0.startDate! < $1.startDate! })
|
||||
for event in sortedEvents {
|
||||
if(event.startDate! > Date()) {
|
||||
//self.focusedEvent = event
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Loads required data from CoreData
|
||||
*/
|
||||
public func getRaPlaEvents() {
|
||||
let sectionSortDescriptor = NSSortDescriptor(key: "startDate", ascending: true)
|
||||
let sortDescriptors = [sectionSortDescriptor]
|
||||
|
||||
var calendar = Calendar.current
|
||||
calendar.timeZone = NSTimeZone.local
|
||||
let dateFrom = calendar.startOfDay(for: Date())
|
||||
let fromPredicate = NSPredicate(format: "startDate >= %@", dateFrom as NSDate)
|
||||
|
||||
self.events = []
|
||||
self.daysWithEvents = [:]
|
||||
|
||||
self.events = RaPlaEvent.getSpecified(sortDescriptors: sortDescriptors, searchPredicate: fromPredicate)
|
||||
|
||||
// Also write events to daysWithEvents map
|
||||
for event in self.events {
|
||||
let components = event.startDate!.get(.day, .month, .year)
|
||||
let day = String(components.day!); let month = String(components.month!); let year = String(components.year!)
|
||||
|
||||
let dateFormatter = DateFormatter()
|
||||
dateFormatter.dateFormat = "yyyy-MM-dd"
|
||||
let dayOnly = dateFormatter.date(from: String(year + "-" + month + "-" + day))!
|
||||
|
||||
var eventsList = daysWithEvents[dayOnly]
|
||||
if(eventsList == nil) {
|
||||
eventsList = []
|
||||
}
|
||||
eventsList!.append(event)
|
||||
self.daysWithEvents[dayOnly] = eventsList
|
||||
}
|
||||
}
|
||||
|
||||
public func updateDay(day: Date, events: [RaPlaEvent]) {
|
||||
self.daysWithEvents[day] = events
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Each of these represents one day block in the view
|
||||
*/
|
||||
struct DayWithEventsBlock: View {
|
||||
@State var date: Date
|
||||
@State var eventsList: [RaPlaEvent]
|
||||
@State var parent: LecturePlanList
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
Text(String(date.get(.day)) + "." + String(date.get(.month)) + "." + String(date.get(.year)))
|
||||
.font(.title)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
|
||||
VStack {
|
||||
if(!eventsList.isEmpty){
|
||||
ForEach(eventsList, id: \.self) { event in
|
||||
var visibleIconGroup = Group {
|
||||
Button(action: {
|
||||
event.isHidden.toggle()
|
||||
}){
|
||||
if(event.isHidden) {
|
||||
Image(systemName: "eye.slash")
|
||||
.foregroundColor(.red)
|
||||
} else {
|
||||
Image(systemName: "eye")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NavigationLink(destination: LecturePlanItem(event: event)) {
|
||||
HStack {
|
||||
Text(parent.formatTime(date: event.startDate!))
|
||||
.foregroundColor(parent.getEventForegroundColor(for: event))
|
||||
Text(event.summary!)
|
||||
.foregroundColor(parent.getEventForegroundColor(for: event))
|
||||
|
||||
Spacer()
|
||||
|
||||
visibleIconGroup
|
||||
}
|
||||
.padding()
|
||||
.background(
|
||||
RoundedRectangle(cornerRadius: 10)
|
||||
.fill(Color(#colorLiteral(red: 0.2549019754, green: 0.2745098174, blue: 0.3019607961, alpha: 1)))
|
||||
)
|
||||
}
|
||||
// When an event gets updated from child view, reload it here as this will not trigger the onAppear() function
|
||||
.onReceive(event.objectWillChange, perform: { _ in
|
||||
print("receiving event: \(event.isHidden)")
|
||||
visibleIconGroup = Group {
|
||||
Button(action: {
|
||||
event.isHidden.toggle()
|
||||
}){
|
||||
if(event.isHidden) {
|
||||
Image(systemName: "eye.slash")
|
||||
.foregroundColor(.red)
|
||||
} else {
|
||||
Image(systemName: "eye")
|
||||
}
|
||||
}
|
||||
}
|
||||
// parent.updateDay(day: self.date, events: self.eventsList)
|
||||
})
|
||||
}
|
||||
} else {
|
||||
Text("noLectures".localized(tableName: "HomeView"))
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding()
|
||||
.background(
|
||||
RoundedRectangle(cornerRadius: 10)
|
||||
.fill(Color.gray)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user