mirror of
https://github.com/Mueller-Patrick/DHBW-Service-App.git
synced 2024-11-25 02:23:56 +00:00
116 lines
3.6 KiB
Swift
116 lines
3.6 KiB
Swift
//
|
|
// LecturePlanItem.swift
|
|
// DHBW-Service
|
|
//
|
|
// Created by Patrick Müller on 01.02.21.
|
|
//
|
|
|
|
import SwiftUI
|
|
import CoreData
|
|
|
|
struct LecturePlanItem: View {
|
|
@State var event: RaPlaEvent
|
|
@State var isHidden = false
|
|
|
|
var body: some View {
|
|
VStack {
|
|
HStack {
|
|
Spacer()
|
|
VStack {
|
|
Text(event.summary!)
|
|
.font(.title3)
|
|
.frame(maxWidth: .infinity, alignment: .leading)
|
|
Text(event.descr!)
|
|
.bold()
|
|
.frame(maxWidth: .infinity, alignment: .leading)
|
|
Divider()
|
|
HStack {
|
|
VStack(alignment: .leading) {
|
|
Text("When")
|
|
Text("Where")
|
|
Text("Who")
|
|
}
|
|
VStack(alignment: .leading) {
|
|
Text(getDateAndTimeAsString(date: event.startDate!)
|
|
+ " to "
|
|
+ getTimeAsString(date: event.endDate!))
|
|
.bold()
|
|
Text(event.location!)
|
|
.bold()
|
|
Text(!event.lecturerList.isEmpty ? event.lecturerList[0].wrappedName : "")
|
|
.bold()
|
|
}.frame(maxWidth: .infinity, alignment: .leading)
|
|
}
|
|
Divider()
|
|
HStack {
|
|
Button(action: {
|
|
event.isHidden = !isHidden
|
|
self.isHidden = !isHidden
|
|
}){
|
|
if(self.isHidden){
|
|
Text("Show")
|
|
} else {
|
|
Text("Hide")
|
|
}
|
|
}
|
|
.padding()
|
|
.foregroundColor(.primary)
|
|
.background(Color.blue)
|
|
.cornerRadius(15)
|
|
Spacer()
|
|
}
|
|
}
|
|
.padding()
|
|
.background(
|
|
RoundedRectangle(cornerRadius: 10)
|
|
.fill(Color.primaryColor)
|
|
)
|
|
Spacer()
|
|
}
|
|
.frame(maxWidth: .infinity)
|
|
Spacer()
|
|
}
|
|
.onAppear{
|
|
self.isHidden = event.isHidden
|
|
}
|
|
.onDisappear{
|
|
PersistenceController.shared.save()
|
|
}
|
|
}
|
|
}
|
|
|
|
func getDateAndTimeAsString(date: Date) -> String {
|
|
let formatter = DateFormatter()
|
|
formatter.dateStyle = .short
|
|
formatter.timeStyle = .short
|
|
|
|
return formatter.string(from: date)
|
|
}
|
|
|
|
func getTimeAsString(date: Date) -> String {
|
|
let formatter = DateFormatter()
|
|
formatter.timeStyle = .short
|
|
|
|
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
|
|
}
|
|
|
|
static func getPreviewEvent() -> RaPlaEvent {
|
|
return RaPlaEvent.getSpecified(sortDescriptors: [])[0]
|
|
}
|
|
}
|