Skip to content

Commit c7ea3c5

Browse files
committed
Fixed a quarterly bug; Added time picker to 'Custom' notification preference
1 parent 82631f2 commit c7ea3c5

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

CatchUp-SwiftUI/Utilities/Conversions.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,15 @@ struct Converter {
273273
var month: String
274274
var day: String
275275
var year: String
276-
277-
switch contact.notification_preference_custom_month+1 {
276+
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 {
278285
case 1:
279286
month = "January"
280287
break

CatchUp-SwiftUI/Utilities/NotificationHelper.swift

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ struct NotificationHelper {
4747
let identifier = UUID()
4848
let dateComponents = getNotificationDateComponents(for: contact)
4949

50-
scheduleNotification(for: contact, dateComponents: dateComponents, identifier: identifier, content: notificationContent)
50+
scheduleNotification(for: contact, isBirthdayOrAnniversary: false, dateComponents: dateComponents, identifier: identifier, content: notificationContent)
5151
}
5252

5353
static func addBirthdayNotification(for contact: SelectedContact) {
@@ -60,7 +60,7 @@ struct NotificationHelper {
6060
let birthdayIdentifier = UUID()
6161
let birthdayDateComponents = getBirthdayDateComponents(for: contact)
6262

63-
scheduleNotification(for: contact, dateComponents: birthdayDateComponents, identifier: birthdayIdentifier, content: birthdayNotificationContent)
63+
scheduleNotification(for: contact, isBirthdayOrAnniversary: true, dateComponents: birthdayDateComponents, identifier: birthdayIdentifier, content: birthdayNotificationContent)
6464
}
6565

6666
static func addAnniversaryNotification(for contact: SelectedContact) {
@@ -73,7 +73,7 @@ struct NotificationHelper {
7373
let anniversaryIdentifier = UUID()
7474
let anniversaryDateComponents = getAnniversaryDateComponents(for: contact)
7575

76-
scheduleNotification(for: contact, dateComponents: anniversaryDateComponents, identifier: anniversaryIdentifier, content: anniversaryNotificationContent)
76+
scheduleNotification(for: contact, isBirthdayOrAnniversary: true, dateComponents: anniversaryDateComponents, identifier: anniversaryIdentifier, content: anniversaryNotificationContent)
7777
}
7878

7979
static func checkNotificationAuthorizationStatusAndAddRequest(action: @escaping() -> Void) {
@@ -112,7 +112,11 @@ struct NotificationHelper {
112112
} else if contact.preferenceIsAnnually() || contact.preferenceIsCustom() {
113113
components.hour = contact.notification_preference_hour
114114
components.minute = contact.notification_preference_minute
115-
components.month = contact.notification_preference_custom_month + 1
115+
if contact.preferenceIsAnnually() {
116+
components.month = contact.notification_preference_custom_month + 1
117+
} else if contact.preferenceIsCustom() {
118+
components.month = contact.notification_preference_custom_month
119+
}
116120
components.day = contact.notification_preference_custom_day
117121
components.year = contact.notification_preference_custom_year
118122
}
@@ -158,7 +162,11 @@ struct NotificationHelper {
158162
dateComponents.weekday = contact.notification_preference_weekday+1
159163
dateComponents.weekOfMonth = contact.notification_preference_week_of_month
160164
} else if contact.preferenceIsAnnually() || contact.preferenceIsCustom() {
161-
dateComponents.month = contact.notification_preference_custom_month+1
165+
if contact.preferenceIsAnnually() {
166+
dateComponents.month = contact.notification_preference_custom_month+1
167+
} else if contact.preferenceIsCustom() {
168+
dateComponents.month = contact.notification_preference_custom_month
169+
}
162170
dateComponents.day = contact.notification_preference_custom_day
163171
dateComponents.year = contact.notification_preference_custom_year
164172
dateComponents.hour = contact.notification_preference_hour
@@ -216,13 +224,13 @@ struct NotificationHelper {
216224
return anniversaryDateComponents
217225
}
218226

219-
static func scheduleNotification(for contact: SelectedContact, dateComponents: DateComponents, identifier: UUID, content: UNMutableNotificationContent) {
227+
static func scheduleNotification(for contact: SelectedContact, isBirthdayOrAnniversary: Bool, dateComponents: DateComponents, identifier: UUID, content: UNMutableNotificationContent) {
220228
var calendarTrigger: UNCalendarNotificationTrigger?
221229
var timeIntervalTrigger: UNTimeIntervalNotificationTrigger?
222230
var request: UNNotificationRequest
223231

224232
// quarterly notifications are handled by UNTimeIntervalNotificationTrigger instead of UNCalendarNotificationTrigger, so we handle them separately
225-
if contact.preferenceIsQuarterly() {
233+
if contact.preferenceIsQuarterly() && !isBirthdayOrAnniversary {
226234
let oneDay: Double = 86400 // seconds
227235
// set a recurring time interval for every 90 days
228236
timeIntervalTrigger = UNTimeIntervalNotificationTrigger(timeInterval: (oneDay*90), repeats: true)

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ struct NotificationPreferenceView: View {
7878
)
7979
.labelsHidden()
8080
}
81+
82+
TimePickerRow(notificationPreferenceTime: $notificationPreferenceTime)
8183
}
8284
}
8385
.onAppear {

0 commit comments

Comments
 (0)