Skip to content

Commit bfa6c4a

Browse files
authored
Merge pull request #6 from r-token/more-preference-options
Fixed annual preference bug
2 parents 1a037a6 + 8caee17 commit bfa6c4a

File tree

3 files changed

+27
-33
lines changed

3 files changed

+27
-33
lines changed

CatchUp-SwiftUI/Utilities/Conversions.swift

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -274,14 +274,7 @@ struct Converter {
274274
var day: String
275275
var year: String
276276

277-
var monthPreference: Int = 0
278-
if contact.preferenceIsCustom() {
279-
monthPreference = contact.notification_preference_custom_month
280-
} else if contact.preferenceIsAnnually() {
281-
monthPreference = contact.notification_preference_custom_month+1
282-
}
283-
284-
switch monthPreference {
277+
switch contact.notification_preference_custom_month {
285278
case 1:
286279
month = "January"
287280
break

CatchUp-SwiftUI/Utilities/NotificationHelper.swift

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -103,22 +103,22 @@ struct NotificationHelper {
103103
} else if contact.preferenceIsWeekly() || contact.preferenceIsMonthly() {
104104
components.hour = contact.notification_preference_hour
105105
components.minute = contact.notification_preference_minute
106-
components.weekday = contact.notification_preference_weekday + 1
106+
components.weekday = contact.notification_preference_weekday+1
107107
if contact.notification_preference_week_of_month != 0 {
108-
components.weekOfMonth = contact.notification_preference_week_of_month + 1
108+
components.weekOfMonth = contact.notification_preference_week_of_month+1
109109
}
110110
} else if contact.preferenceIsQuarterly() {
111-
print("Quarterly is handled separately by UNTimeIntervalNotificationTrigger")
111+
print("Quarterly is handled separately by UNTimeIntervalNotificationTrigger. Fallthrough.")
112112
} else if contact.preferenceIsAnnually() || contact.preferenceIsCustom() {
113-
components.hour = contact.notification_preference_hour
114113
components.minute = contact.notification_preference_minute
114+
components.hour = contact.notification_preference_hour
115+
components.day = contact.notification_preference_custom_day
116+
components.month = contact.notification_preference_custom_month
115117
if contact.preferenceIsAnnually() {
116-
components.month = contact.notification_preference_custom_month + 1
118+
components.year = nil
117119
} else if contact.preferenceIsCustom() {
118-
components.month = contact.notification_preference_custom_month
120+
components.year = contact.notification_preference_custom_year
119121
}
120-
components.day = contact.notification_preference_custom_day
121-
components.year = contact.notification_preference_custom_year
122122
}
123123

124124
var soonestUpcomingNotificationDateString = ""
@@ -163,12 +163,12 @@ struct NotificationHelper {
163163
dateComponents.weekOfMonth = contact.notification_preference_week_of_month
164164
} else if contact.preferenceIsAnnually() || contact.preferenceIsCustom() {
165165
if contact.preferenceIsAnnually() {
166-
dateComponents.month = contact.notification_preference_custom_month+1
166+
dateComponents.year = nil
167167
} else if contact.preferenceIsCustom() {
168-
dateComponents.month = contact.notification_preference_custom_month
168+
dateComponents.year = contact.notification_preference_custom_year
169169
}
170+
dateComponents.month = contact.notification_preference_custom_month
170171
dateComponents.day = contact.notification_preference_custom_day
171-
dateComponents.year = contact.notification_preference_custom_year
172172
dateComponents.hour = contact.notification_preference_hour
173173
dateComponents.minute = contact.notification_preference_minute
174174
}
@@ -399,20 +399,16 @@ struct NotificationHelper {
399399
return formattedDate
400400
}
401401

402-
// print("returning Unknown")
403402
return "Unknown"
404403
}
405404

406405
static func setYearPreference(for contact: SelectedContact) {
407406
var contactDateComponents = NotificationHelper.getNotificationDateComponents(for: contact)
408407
contactDateComponents.year = Calendar.current.component(.year, from: Date())
409408
if let nextNotificationDate = Calendar.current.date(from: contactDateComponents) {
410-
print("nextNotificationDate for bee: \(nextNotificationDate)")
411409
if nextNotificationDate < Date() {
412-
print("\(Date()) for bee is greater than \(nextNotificationDate)")
413-
contact.notification_preference_custom_year = Calendar.current.component(.year, from: Date()) + 1
410+
contact.notification_preference_custom_year = Calendar.current.component(.year, from: Date())+1
414411
} else {
415-
print("\(Date()) for bee is less than \(nextNotificationDate)")
416412
contact.notification_preference_custom_year = Calendar.current.component(.year, from: Date())
417413
}
418414
print("set \(contact.name)'s year preference to \(contact.notification_preference_custom_year)")

CatchUp-SwiftUI/Views/DetailScreen Subviews/NotificationPreferenceView.swift

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ struct NotificationPreferenceView: View {
5252
// Month Picker
5353
Picker(selection: $contact.notification_preference_custom_month, label: Text("What month?")) {
5454
ForEach(0..<monthOptions.count, id: \.self) { index in
55-
Text(monthOptions[index].rawValue).tag(index)
55+
Text(monthOptions[index].rawValue).tag(index+1)
5656
}
5757
}
5858

@@ -134,9 +134,14 @@ struct NotificationPreferenceView: View {
134134
print("notificationPreferenceTime changed")
135135
let calendar = Calendar.current
136136
let components = calendar.dateComponents([.hour, .minute], from : newTime)
137-
NotificationHelper.updateNotificationTime(for: contact, hour: components.hour!, minute: components.minute!)
138-
139-
resetNotificationsForContact()
137+
138+
if let hour = components.hour, let minute = components.minute {
139+
NotificationHelper.setYearPreference(for: contact)
140+
NotificationHelper.updateNotificationTime(for: contact, hour: hour, minute: minute)
141+
resetNotificationsForContact()
142+
} else {
143+
notificationPreferenceTime = initialTime
144+
}
140145
}
141146
}
142147

@@ -175,16 +180,16 @@ struct NotificationPreferenceView: View {
175180
let calendar = Calendar.current
176181
let timeComponents = DateComponents(
177182
calendar: calendar,
178-
hour: Int(contact.notification_preference_hour),
179-
minute: Int(contact.notification_preference_minute)
183+
hour: contact.notification_preference_hour,
184+
minute: contact.notification_preference_minute
180185
)
181186
let time = Calendar.current.date(from: timeComponents)
182187

183188
let customDateComponents = DateComponents(
184189
calendar: calendar,
185-
year: Int(contact.notification_preference_custom_year),
186-
month: Int(contact.notification_preference_custom_month),
187-
day: Int(contact.notification_preference_custom_day)
190+
year: contact.notification_preference_custom_year,
191+
month: contact.notification_preference_custom_month,
192+
day: contact.notification_preference_custom_day
188193
)
189194
let customDate = Calendar.current.date(from: customDateComponents)
190195

0 commit comments

Comments
 (0)