DHBW-Service-App/DHBW-Service/Views/Tabs/LecturePlanItem.swift

116 lines
3.6 KiB
Swift
Raw Permalink Normal View History

//
// LecturePlanItem.swift
// DHBW-Service
//
// Created by Patrick Müller on 01.02.21.
//
import SwiftUI
import CoreData
struct LecturePlanItem: View {
2021-02-10 19:26:53 +00:00
@State var event: RaPlaEvent
@State var isHidden = false
var body: some View {
VStack {
2021-02-07 19:39:56 +00:00
HStack {
2021-02-07 20:17:08 +00:00
Spacer()
VStack {
2021-02-10 19:26:53 +00:00
Text(event.summary!)
2021-02-07 20:17:08 +00:00
.font(.title3)
.frame(maxWidth: .infinity, alignment: .leading)
2021-02-10 19:26:53 +00:00
Text(event.descr!)
2021-02-07 19:39:56 +00:00
.bold()
2021-02-07 20:17:08 +00:00
.frame(maxWidth: .infinity, alignment: .leading)
Divider()
HStack {
VStack(alignment: .leading) {
Text("When")
Text("Where")
Text("Who")
}
VStack(alignment: .leading) {
2021-02-10 19:26:53 +00:00
Text(getDateAndTimeAsString(date: event.startDate!)
2021-02-07 20:17:08 +00:00
+ " to "
2021-02-10 19:26:53 +00:00
+ getTimeAsString(date: event.endDate!))
2021-02-07 20:17:08 +00:00
.bold()
2021-02-10 19:26:53 +00:00
Text(event.location!)
2021-02-07 20:17:08 +00:00
.bold()
Text(!event.lecturerList.isEmpty ? event.lecturerList[0].wrappedName : "")
2021-02-07 20:17:08 +00:00
.bold()
}.frame(maxWidth: .infinity, alignment: .leading)
}
Divider()
HStack {
Button(action: {
2021-02-10 19:26:53 +00:00
event.isHidden = !isHidden
2021-02-07 20:17:08 +00:00
self.isHidden = !isHidden
}){
if(self.isHidden){
Text("Show")
} else {
Text("Hide")
}
}
.padding()
.foregroundColor(.white)
.background(Color.blue)
.cornerRadius(15)
Spacer()
}
}
2021-02-07 20:17:08 +00:00
.padding()
.background(
RoundedRectangle(cornerRadius: 10)
.fill(Color.gray)
)
Spacer()
}
2021-02-07 20:17:08 +00:00
.frame(maxWidth: .infinity)
2021-02-07 19:39:56 +00:00
Spacer()
}
.onAppear{
2021-02-10 19:26:53 +00:00
self.isHidden = event.isHidden
}
.onDisappear{
PersistenceController.shared.save()
}
}
}
2021-02-07 20:17:08 +00:00
func getDateAndTimeAsString(date: Date) -> String {
2021-02-07 19:39:56 +00:00
let formatter = DateFormatter()
formatter.dateStyle = .short
2021-02-07 20:17:08 +00:00
formatter.timeStyle = .short
return formatter.string(from: date)
}
func getTimeAsString(date: Date) -> String {
let formatter = DateFormatter()
formatter.timeStyle = .short
2021-02-07 19:39:56 +00:00
return formatter.string(from: date)
}
struct LecturePlanItem_Previews: PreviewProvider {
static var previews: some View {
LecturePlanItem(event: getPreviewEvent())
.preferredColorScheme(.dark)
.previewDevice("iPhone 12")
.environmentObject(getFirstOpening())
.environment(\.managedObjectContext, PersistenceController.preview.container.viewContext)
}
static func getFirstOpening() -> LocalSettings {
let settings = LocalSettings();
settings.isFirstOpening = false;
return settings
}
2021-02-10 19:26:53 +00:00
static func getPreviewEvent() -> RaPlaEvent {
return RaPlaEvent.getSpecified(sortDescriptors: [])[0]
}
}