Skip to content

Commit 4110020

Browse files
authored
Merge pull request #8 from r-token/bug/weekday-fix-and-design-updates
- Default `weekday` to 1 (Sunday) instead of 0 (Unknown) when adding a contact - Only show the 'Contact Info' section on the detail screen if there is actually any contact info - Change the 'No CatchUps yet' text to gray - Code cleanup
2 parents d3779f2 + f173cf5 commit 4110020

File tree

9 files changed

+75
-59
lines changed

9 files changed

+75
-59
lines changed

CatchUp-SwiftUI.xcodeproj/project.pbxproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@
504504
"$(inherited)",
505505
"@executable_path/Frameworks",
506506
);
507-
MARKETING_VERSION = 3.1.1;
507+
MARKETING_VERSION = 3.1.2;
508508
PRODUCT_BUNDLE_IDENTIFIER = com.tokensolutions.CatchUp;
509509
PRODUCT_NAME = CatchUp;
510510
SUPPORTS_MACCATALYST = NO;
@@ -532,7 +532,7 @@
532532
"$(inherited)",
533533
"@executable_path/Frameworks",
534534
);
535-
MARKETING_VERSION = 3.1.1;
535+
MARKETING_VERSION = 3.1.2;
536536
PRODUCT_BUNDLE_IDENTIFIER = com.tokensolutions.CatchUp;
537537
PRODUCT_NAME = CatchUp;
538538
SUPPORTS_MACCATALYST = NO;

CatchUp-SwiftUI/Data/SelectedContact.swift

+41-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class SelectedContact {
2828
var notification_preference_hour: Int = 0
2929
var notification_preference_minute: Int = 0
3030
var notification_preference_quarterly_set_time: Date = Date()
31-
var notification_preference_weekday: Int = 0
31+
var notification_preference_weekday: Int = 1
3232
var notification_preference_week_of_month: Int = 0
3333
var phone: String = ""
3434
var picture: String = ""
@@ -120,6 +120,46 @@ class SelectedContact {
120120
notification_preference == 6
121121
}
122122

123+
func hasPhone() -> Bool {
124+
phone != "" ? true : false
125+
}
126+
127+
func hasSecondaryPhone() -> Bool {
128+
secondary_phone != "" ? true : false
129+
}
130+
131+
func hasEmail() -> Bool {
132+
email != "" ? true : false
133+
}
134+
135+
func hasSecondaryEmail() -> Bool {
136+
secondary_email != "" ? true : false
137+
}
138+
139+
func hasAddress() -> Bool {
140+
address != "" ? true : false
141+
}
142+
143+
func hasSecondaryAddress() -> Bool {
144+
secondary_address != "" ? true : false
145+
}
146+
147+
func hasBirthday() -> Bool {
148+
birthday != "" ? true : false
149+
}
150+
151+
func hasAnniversary() -> Bool {
152+
anniversary != "" ? true : false
153+
}
154+
155+
func hasContactInfo() -> Bool {
156+
if hasPhone() || hasSecondaryPhone() || hasEmail() || hasSecondaryEmail() || hasAddress() || hasSecondaryAddress() || hasBirthday() || hasAnniversary() {
157+
return true
158+
} else {
159+
return false
160+
}
161+
}
162+
123163
static let sampleData = SelectedContact(
124164
address: "2190 E 11th Ave",
125165
anniversary: "06/20/2020",

CatchUp-SwiftUI/Utilities/ContactHelper.swift

+2-37
Original file line numberDiff line numberDiff line change
@@ -11,43 +11,8 @@ import UIKit
1111
import Contacts
1212
import CoreData
1313

14+
// Functions for creating and updating a contact
1415
struct ContactHelper {
15-
// MARK: Functions for DetailScreen
16-
17-
static func contactHasPhone(_ contact: SelectedContact) -> Bool {
18-
return contact.phone != "" ? true : false
19-
}
20-
21-
static func contactHasSecondaryPhone(_ contact: SelectedContact) -> Bool {
22-
return contact.secondary_phone != "" ? true : false
23-
}
24-
25-
static func contactHasEmail(_ contact: SelectedContact) -> Bool {
26-
return contact.email != "" ? true : false
27-
}
28-
29-
static func contactHasSecondaryEmail(_ contact: SelectedContact) -> Bool {
30-
return contact.secondary_email != "" ? true : false
31-
}
32-
33-
static func contactHasAddress(_ contact: SelectedContact) -> Bool {
34-
return contact.address != "" ? true : false
35-
}
36-
37-
static func contactHasSecondaryAddress(_ contact: SelectedContact) -> Bool {
38-
return contact.secondary_address != "" ? true : false
39-
}
40-
41-
static func contactHasBirthday(_ contact: SelectedContact) -> Bool {
42-
return contact.birthday != "" ? true : false
43-
}
44-
45-
static func contactHasAnniversary(_ contact: SelectedContact) -> Bool {
46-
return contact.anniversary != "" ? true : false
47-
}
48-
49-
// MARK: Functions for ContactPickerViewController
50-
5116
static func encodeContactPicture(for contact: CNContact) -> String {
5217
let picture: String
5318

@@ -283,7 +248,7 @@ struct ContactHelper {
283248
let notification_preference_hour = currentHour
284249
let notification_preference_minute = currentMinute
285250
let notification_preference_quarterly_set_time = Date()
286-
let notification_preference_weekday = 0
251+
let notification_preference_weekday = 1
287252
let notification_preference_custom_year = currentYear
288253
let notification_preference_custom_month = currentMonth
289254
let notification_preference_custom_day = currentDay

CatchUp-SwiftUI/Utilities/NotificationHelper.swift

+6-6
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ struct NotificationHelper {
2121
addGeneralNotification(for: contact)
2222
}
2323

24-
if ContactHelper.contactHasBirthday(contact) {
24+
if contact.hasBirthday() {
2525
addBirthdayNotification(for: contact)
2626
}
2727

28-
if ContactHelper.contactHasAnniversary(contact) {
28+
if contact.hasAnniversary() {
2929
addAnniversaryNotification(for: contact)
3030
}
3131
}
@@ -128,14 +128,14 @@ struct NotificationHelper {
128128
soonestUpcomingNotificationDateString = calculateDateStringFromComponents(components)
129129
}
130130

131-
if ContactHelper.contactHasBirthday(contact) && !contact.preferenceIsNever() {
131+
if contact.hasBirthday() && !contact.preferenceIsNever() {
132132
let birthdayDateString = calculateDateStringFromComponents(getBirthdayDateComponents(for: contact))
133133
if birthdayDateString < soonestUpcomingNotificationDateString {
134134
soonestUpcomingNotificationDateString = birthdayDateString
135135
}
136136
}
137137

138-
if ContactHelper.contactHasAnniversary(contact) && !contact.preferenceIsNever() {
138+
if contact.hasAnniversary() && !contact.preferenceIsNever() {
139139
let anniversaryDateString = calculateDateStringFromComponents(getAnniversaryDateComponents(for: contact))
140140
if anniversaryDateString < soonestUpcomingNotificationDateString {
141141
soonestUpcomingNotificationDateString = anniversaryDateString
@@ -339,11 +339,11 @@ struct NotificationHelper {
339339
static func removeExistingNotifications(for contact: SelectedContact) {
340340
removeGeneralNotification(for: contact)
341341

342-
if ContactHelper.contactHasBirthday(contact) {
342+
if contact.hasBirthday() {
343343
removeBirthdayNotification(for: contact)
344344
}
345345

346-
if ContactHelper.contactHasAnniversary(contact) {
346+
if contact.hasAnniversary() {
347347
removeAnniversaryNotification(for: contact)
348348
}
349349
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ struct BirthdayOrAnniversaryRow: View {
3737
}
3838

3939
func dayBeforeAnniversaryString() -> String? {
40-
if ContactHelper.contactHasAnniversary(contact) {
40+
if contact.hasAnniversary() {
4141
return NotificationHelper.calculateDateStringFromComponents(NotificationHelper.getAnniversaryDateComponents(for: contact))
4242
}
4343

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

+15-8
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ struct ContactInfoView: View {
4141
}
4242

4343
var body: some View {
44-
if ContactHelper.contactHasPhone(contact) {
44+
if contact.hasPhone() {
4545
VStack(alignment: .leading, spacing: 3) {
4646
Text("Phone")
4747
.font(.caption)
@@ -52,7 +52,8 @@ struct ContactInfoView: View {
5252
.foregroundStyle(.blue)
5353
}
5454
}
55-
if ContactHelper.contactHasSecondaryPhone(contact) {
55+
56+
if contact.hasSecondaryPhone() {
5657
VStack(alignment: .leading, spacing: 3) {
5758
Text("Secondary Phone")
5859
.font(.caption)
@@ -63,7 +64,8 @@ struct ContactInfoView: View {
6364
.foregroundStyle(.blue)
6465
}
6566
}
66-
if ContactHelper.contactHasEmail(contact) {
67+
68+
if contact.hasEmail() {
6769
VStack(alignment: .leading, spacing: 3) {
6870
Text("Email")
6971
.font(.caption)
@@ -86,7 +88,8 @@ struct ContactInfoView: View {
8688
Button("Cancel", role: .cancel) {}
8789
}
8890
}
89-
if ContactHelper.contactHasSecondaryEmail(contact) {
91+
92+
if contact.hasSecondaryEmail() {
9093
VStack(alignment: .leading, spacing: 3) {
9194
Text("Secondary Email")
9295
.font(.caption)
@@ -99,7 +102,8 @@ struct ContactInfoView: View {
99102
.foregroundStyle(.blue)
100103
}
101104
}
102-
if ContactHelper.contactHasAddress(contact) {
105+
106+
if contact.hasAddress() {
103107
VStack(alignment: .leading, spacing: 3) {
104108
Text("Address")
105109
.font(.caption)
@@ -109,7 +113,8 @@ struct ContactInfoView: View {
109113
.foregroundStyle(.blue)
110114
}
111115
}
112-
if ContactHelper.contactHasSecondaryAddress(contact) {
116+
117+
if contact.hasSecondaryAddress() {
113118
VStack(alignment: .leading, spacing: 3) {
114119
Text("Secondary Address")
115120
.font(.caption)
@@ -119,7 +124,8 @@ struct ContactInfoView: View {
119124
.foregroundStyle(.blue)
120125
}
121126
}
122-
if ContactHelper.contactHasBirthday(contact) {
127+
128+
if contact.hasBirthday() {
123129
VStack(alignment: .leading, spacing: 3) {
124130
Text("Birthday")
125131
.font(.caption)
@@ -133,7 +139,8 @@ struct ContactInfoView: View {
133139
}
134140
}
135141
}
136-
if ContactHelper.contactHasAnniversary(contact) {
142+
143+
if contact.hasAnniversary() {
137144
VStack(alignment: .leading, spacing: 3) {
138145
Text("Anniversary")
139146
.font(.caption)

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ struct NotificationPreferenceView: View {
1212
@Environment(DataController.self) var dataController
1313
@Environment(\.modelContext) var modelContext
1414

15-
@State private var initialNotificationPreference = 0
16-
@State private var initialNotificationPreferenceWeekday = 0
15+
@State private var initialNotificationPreference = 0 // Never
16+
@State private var initialNotificationPreferenceWeekday = 1 // Sunday
1717
@State private var initialNotificationPreferenceTime = Date()
1818
@State private var initialNotificationPreferenceCustomDate = Date()
1919

CatchUp-SwiftUI/Views/DetailScreen.swift

+5-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,11 @@ struct DetailScreen: View {
3737
Section("Notification Preference") {
3838
NotificationPreferenceView(contact: contact)
3939
}
40-
Section("Contact Information") {
41-
ContactInfoView(contact: contact)
40+
41+
if contact.hasContactInfo() {
42+
Section("Contact Information") {
43+
ContactInfoView(contact: contact)
44+
}
4245
}
4346

4447
RemoveContactButton(contact: contact)

CatchUp-SwiftUI/Views/HomeScreen.swift

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ struct HomeScreen : View {
6161
}
6262
} else {
6363
Text("No CatchUps yet! Tap the 'Add Contacts' button to add some.")
64+
.foregroundStyle(.gray)
6465
}
6566
}
6667
.refreshable {

0 commit comments

Comments
 (0)