Adding date of next theory phase start to home screen

- Also some UI stuff, documentation and removal of unused CoreData entities
This commit is contained in:
Patrick Müller 2021-02-04 23:12:24 +01:00 committed by Patrick Müller
parent c8a6ba8008
commit 64bd6bf434
3 changed files with 45 additions and 9 deletions

View File

@ -1,8 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="17709" systemVersion="20D62" minimumToolsVersion="Automatic" sourceLanguage="Swift" usedWithCloudKit="YES" userDefinedModelVersionIdentifier=""> <model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="17709" systemVersion="20D62" minimumToolsVersion="Automatic" sourceLanguage="Swift" usedWithCloudKit="YES" userDefinedModelVersionIdentifier="">
<entity name="Item" representedClassName="Item" syncable="YES" codeGenerationType="class">
<attribute name="timestamp" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
</entity>
<entity name="RaPlaEvent" representedClassName="RaPlaEvent" syncable="YES" codeGenerationType="class"> <entity name="RaPlaEvent" representedClassName="RaPlaEvent" syncable="YES" codeGenerationType="class">
<attribute name="category" optional="YES" attributeType="String"/> <attribute name="category" optional="YES" attributeType="String"/>
<attribute name="descr" optional="YES" attributeType="String"/> <attribute name="descr" optional="YES" attributeType="String"/>
@ -19,7 +16,6 @@
<attribute name="name" optional="YES" attributeType="String"/> <attribute name="name" optional="YES" attributeType="String"/>
</entity> </entity>
<elements> <elements>
<element name="Item" positionX="-63" positionY="-18" width="128" height="44"/>
<element name="RaPlaEvent" positionX="-63" positionY="9" width="128" height="149"/> <element name="RaPlaEvent" positionX="-63" positionY="9" width="128" height="149"/>
<element name="User" positionX="-63" positionY="-9" width="128" height="74"/> <element name="User" positionX="-63" positionY="-9" width="128" height="74"/>
</elements> </elements>

View File

@ -45,7 +45,7 @@ class UtilityFunctions {
} }
public class func deleteAllData() -> Bool { public class func deleteAllData() -> Bool {
let entities = ["User", "Item"] let entities = ["User", "RaPlaEvent"]
var allSuccessful = true var allSuccessful = true
for entityName in entities { for entityName in entities {

View File

@ -32,6 +32,10 @@ struct HomeView: View {
Text("director".localized(tableName: "General", plural: false) + ": ") Text("director".localized(tableName: "General", plural: false) + ": ")
Text(self.director) Text(self.director)
} }
HStack {
Text("Next Theory Phase: ")
Text(getNextTheoryPhaseStartDate())
}
// Upcoming events section // Upcoming events section
HStack { HStack {
@ -52,9 +56,9 @@ struct HomeView: View {
} }
} }
.padding() .padding()
.overlay( .background(
RoundedRectangle(cornerRadius: 10) RoundedRectangle(cornerRadius: 10)
.stroke(Color.blue, lineWidth: 4) .fill(Color.gray)
) )
VStack { VStack {
@ -72,9 +76,9 @@ struct HomeView: View {
} }
} }
.padding() .padding()
.overlay( .background(
RoundedRectangle(cornerRadius: 10) RoundedRectangle(cornerRadius: 10)
.stroke(Color.blue, lineWidth: 4) .fill(Color.gray)
) )
Spacer() Spacer()
@ -99,6 +103,10 @@ struct HomeView: View {
} }
} }
.padding() .padding()
.background(
RoundedRectangle(cornerRadius: 10)
.fill(Color.gray)
)
.overlay( .overlay(
RoundedRectangle(cornerRadius: 10) RoundedRectangle(cornerRadius: 10)
.stroke(Color.red, lineWidth: 4) .stroke(Color.red, lineWidth: 4)
@ -118,6 +126,7 @@ struct HomeView: View {
} }
extension HomeView{ extension HomeView{
// Read required data from CoreData and save it to the appropriate variables
func readFromCoreData() { func readFromCoreData() {
let fetchedData = UtilityFunctions.getCoreDataObject(entity: "User") let fetchedData = UtilityFunctions.getCoreDataObject(entity: "User")
@ -129,6 +138,8 @@ extension HomeView{
} }
} }
// Get 0...2 of todays lectures from RaPla
// Returns a list of RaPlaEvent NSManagedObjects
func getTodaysEvents() -> [NSManagedObject] { func getTodaysEvents() -> [NSManagedObject] {
let searchPredicate = NSPredicate(format: "(category == 'Lehrveranstaltung')") let searchPredicate = NSPredicate(format: "(category == 'Lehrveranstaltung')")
let hiddenPredicate = NSPredicate(format: "isHidden == NO") let hiddenPredicate = NSPredicate(format: "isHidden == NO")
@ -143,6 +154,8 @@ extension HomeView{
} }
} }
// Get 0...2 of tomorrows lectures from RaPla
// Returns a list of RaPlaEvent NSManagedObjects
func getTomorrowsEvents() -> [NSManagedObject] { func getTomorrowsEvents() -> [NSManagedObject] {
let searchPredicate = NSPredicate(format: "(category == 'Lehrveranstaltung')") let searchPredicate = NSPredicate(format: "(category == 'Lehrveranstaltung')")
let hiddenPredicate = NSPredicate(format: "isHidden == NO") let hiddenPredicate = NSPredicate(format: "isHidden == NO")
@ -157,6 +170,8 @@ extension HomeView{
} }
} }
// Get 0...2 of upcoming exams from RaPla
// Returns a list of RaPlaEvent NSManagedObjects
func getUpcomingExams() -> [NSManagedObject] { func getUpcomingExams() -> [NSManagedObject] {
let searchPredicate = NSPredicate(format: "category == %@", "Prüfung") let searchPredicate = NSPredicate(format: "category == %@", "Prüfung")
let hiddenPredicate = NSPredicate(format: "isHidden == NO") let hiddenPredicate = NSPredicate(format: "isHidden == NO")
@ -171,6 +186,7 @@ extension HomeView{
} }
} }
// Get the required NSPredicates to fetch only RaPla events with a start date that is today
func getDayPredicates(today: Bool = false, tomorrow: Bool = false) -> [NSPredicate] { func getDayPredicates(today: Bool = false, tomorrow: Bool = false) -> [NSPredicate] {
var calendar = Calendar.current var calendar = Calendar.current
calendar.timeZone = NSTimeZone.local calendar.timeZone = NSTimeZone.local
@ -192,6 +208,30 @@ extension HomeView{
return [fromPredicate, toPredicate] return [fromPredicate, toPredicate]
} }
// Get the formatted date when the next theory phase starts
func getNextTheoryPhaseStartDate() -> String {
var calendar = Calendar.current
calendar.timeZone = NSTimeZone.local
let categoryPredicate = NSPredicate(format: "category == %@", "Sonstiger Termin")
let datePredicate = NSPredicate(format: "startDate >= %@", calendar.startOfDay(for: Date()) as NSDate)
let titlePredicate = NSPredicate(format: "summary CONTAINS[cd] %@", "beginn")
let compoundPredicate = NSCompoundPredicate(andPredicateWithSubpredicates: [categoryPredicate, datePredicate, titlePredicate])
let sectionSortDescriptor = NSSortDescriptor(key: "startDate", ascending: true)
let sortDescriptors = [sectionSortDescriptor]
let events = UtilityFunctions.getCoreDataObject(entity: "RaPlaEvent", sortDescriptors: sortDescriptors, searchPredicate: compoundPredicate)
if(!events.isEmpty) {
let date = events[0].value(forKey: "startDate") as! Date
let formatter = DateFormatter()
formatter.dateStyle = .short
return formatter.string(from: date)
} else {
return "N/A"
}
}
} }
struct HomeView_Previews: PreviewProvider { struct HomeView_Previews: PreviewProvider {