2021-02-01 22:17:15 +00:00
|
|
|
//
|
|
|
|
// LecturePlanItem.swift
|
|
|
|
// DHBW-Service
|
|
|
|
//
|
|
|
|
// Created by Patrick Müller on 01.02.21.
|
|
|
|
//
|
|
|
|
|
|
|
|
import SwiftUI
|
|
|
|
import CoreData
|
|
|
|
|
|
|
|
struct LecturePlanItem: View {
|
|
|
|
@State var event: NSManagedObject
|
|
|
|
@State var isHidden = false
|
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
VStack {
|
2021-02-07 19:39:56 +00:00
|
|
|
VStack {
|
|
|
|
Text(event.value(forKey: "summary") as! String)
|
|
|
|
.font(.title3)
|
|
|
|
.frame(maxWidth: .infinity, alignment: .leading)
|
|
|
|
HStack {
|
|
|
|
VStack(alignment: .leading) {
|
|
|
|
Text("When")
|
|
|
|
Text("Where")
|
|
|
|
}
|
|
|
|
VStack(alignment: .leading) {
|
|
|
|
Text(getDateAsString(date: event.value(forKey: "startDate") as! Date) )
|
|
|
|
.bold()
|
|
|
|
Text(event.value(forKey: "location") as! String)
|
|
|
|
.bold()
|
|
|
|
}.frame(maxWidth: .infinity, alignment: .leading)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.padding()
|
|
|
|
.background(
|
|
|
|
RoundedRectangle(cornerRadius: 10)
|
|
|
|
.fill(Color.gray)
|
|
|
|
)
|
|
|
|
Spacer()
|
2021-02-01 22:17:15 +00:00
|
|
|
Text(event.value(forKey: "summary") as! String)
|
|
|
|
Button(action: {
|
|
|
|
event.setValue(!isHidden, forKey: "isHidden")
|
|
|
|
self.isHidden = !isHidden
|
|
|
|
PersistenceController.shared.save()
|
|
|
|
}){
|
|
|
|
if(self.isHidden){
|
|
|
|
Text("Show")
|
|
|
|
} else {
|
|
|
|
Text("Hide")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.padding()
|
|
|
|
.foregroundColor(.white)
|
|
|
|
.background(Color.blue)
|
|
|
|
.cornerRadius(15)
|
2021-02-07 19:39:56 +00:00
|
|
|
Spacer()
|
2021-02-01 22:17:15 +00:00
|
|
|
}
|
|
|
|
.onAppear{
|
|
|
|
self.isHidden = event.value(forKey: "isHidden") as! Bool
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-07 19:39:56 +00:00
|
|
|
func getDateAsString(date: Date) -> String {
|
|
|
|
let formatter = DateFormatter()
|
|
|
|
formatter.dateStyle = .short
|
|
|
|
return formatter.string(from: date)
|
|
|
|
}
|
|
|
|
|
2021-02-01 22:17:15 +00:00
|
|
|
struct LecturePlanItem_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
|
|
|
LecturePlanItem(event: getPreviewEvent())
|
|
|
|
.preferredColorScheme(.dark)
|
2021-02-07 14:51:01 +00:00
|
|
|
.previewDevice("iPhone 12")
|
2021-02-01 22:17:15 +00:00
|
|
|
.environmentObject(getFirstOpening())
|
|
|
|
.environment(\.managedObjectContext, PersistenceController.preview.container.viewContext)
|
|
|
|
}
|
|
|
|
|
|
|
|
static func getFirstOpening() -> LocalSettings {
|
|
|
|
let settings = LocalSettings();
|
|
|
|
settings.isFirstOpening = false;
|
|
|
|
return settings
|
|
|
|
}
|
|
|
|
|
|
|
|
static func getPreviewEvent() -> NSManagedObject {
|
|
|
|
return UtilityFunctions.getCoreDataObject(entity: "RaPlaEvent", sortDescriptors: [])[0]
|
|
|
|
}
|
|
|
|
}
|