RaPla parser is now aware of recurring events

- Also some small improvements and basic implementation of Notifications
This commit is contained in:
2021-04-07 13:26:37 +02:00
committed by Patrick Müller
parent 805495fb81
commit 02cd3a0db9
10 changed files with 359 additions and 56 deletions
@@ -11,8 +11,10 @@ import CoreData
struct FirstOpeningSettings: View {
@EnvironmentObject var settings: LocalSettings
@State private var name = ""
@State private var dhbwLocation = ""
@State private var course = ""
@State private var director = ""
@State private var raplaLink = ""
@State private var invalidInputName = false
@State private var invalidInputCourse = false
@@ -28,10 +30,18 @@ struct FirstOpeningSettings: View {
.frame(minWidth: 200, idealWidth: nil, maxWidth: 500, minHeight: nil, idealHeight: nil, maxHeight: nil, alignment: .center)
.padding(.horizontal)
Picker(selection: self.$dhbwLocation, label: Text("Location")){
Text("Karlsruhe")
Text("Mannheim")
Text("Stuttgart")
Text("Mosbach")
}.frame(maxWidth: 500, alignment: .center)
.pickerStyle(SegmentedPickerStyle())
TextField("course".localized(tableName: "General"), text: self.$course)
.overlay(RoundedRectangle(cornerRadius: 10).stroke(invalidInputCourse ? Color.red : Color.secondary, lineWidth: 1))
.onChange(of: course, perform: { value in
self.setDirector()
self.setCourseInfo()
self.course = self.course.uppercased()
})
.foregroundColor(invalidInputCourse ? .red : .primary)
@@ -65,11 +75,13 @@ struct FirstOpeningSettings: View {
}
extension FirstOpeningSettings{
func setDirector() {
if (course == "TINF19B4") {
director = "Jörn Eisenbiegler"
} else {
director = ""
func setCourseInfo() {
// TODO: Replace this with some database query or stuff like this to load actual data
switch course {
case "TINF19B4":
director = "Jörn Eisenbiegler"
default:
director = ""
}
}
@@ -20,6 +20,11 @@ struct SettingsMain: View {
label: {
Text("Acknowledgements")
})
NavigationLink(
destination: SettingsPushNotifications(),
label: {
Text("Push Notifications")
})
Button(action: {
self.showLogoutConfirmationAlert = true
}, label: {
@@ -0,0 +1,72 @@
//
// SettingsPushNotifications.swift
// DHBW-Service
//
// Created by Patrick Müller on 16.02.21.
//
import SwiftUI
struct SettingsPushNotifications: View {
@State private var notificationsEnabled = false
var body: some View {
VStack {
Toggle(isOn: $notificationsEnabled) {
Text("Receive push notifications")
}
.frame(maxWidth: 500, alignment: .center)
Button(action: {
scheduleTestNotification()
}){
Text("Test Notification")
}
}
.onChange(of: notificationsEnabled) { newVal in
if(newVal) {
enablePushService()
}
}
}
}
extension SettingsPushNotifications {
private func enablePushService() {
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound]) { (allowed, error) in
//This callback does not trigger on main loop be careful
if allowed {
print("Allowed")
// Get token
DispatchQueue.main.async {
UIApplication.shared.registerForRemoteNotifications()
}
} else {
print("Error")
}
}
}
private func scheduleTestNotification() {
let content = UNMutableNotificationContent()
content.title = "Upcoming Exam"
content.subtitle = "Your exam in theoretical computer science 3 is one week from now."
content.sound = UNNotificationSound.default
// show this notification five seconds from now
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 10, repeats: false)
// choose a random identifier
let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: trigger)
// add our notification request
UNUserNotificationCenter.current().add(request)
}
}
struct SettingsPushNotifications_Previews: PreviewProvider {
static var previews: some View {
SettingsPushNotifications()
}
}