Skip to content

Commit

Permalink
Merge pull request #8 from r-token/bug/weekday-fix-and-design-updates
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
r-token committed Apr 22, 2024
2 parents d3779f2 + f173cf5 commit 4110020
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 59 deletions.
4 changes: 2 additions & 2 deletions CatchUp-SwiftUI.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 3.1.1;
MARKETING_VERSION = 3.1.2;
PRODUCT_BUNDLE_IDENTIFIER = com.tokensolutions.CatchUp;
PRODUCT_NAME = CatchUp;
SUPPORTS_MACCATALYST = NO;
Expand Down Expand Up @@ -532,7 +532,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 3.1.1;
MARKETING_VERSION = 3.1.2;
PRODUCT_BUNDLE_IDENTIFIER = com.tokensolutions.CatchUp;
PRODUCT_NAME = CatchUp;
SUPPORTS_MACCATALYST = NO;
Expand Down
42 changes: 41 additions & 1 deletion CatchUp-SwiftUI/Data/SelectedContact.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class SelectedContact {
var notification_preference_hour: Int = 0
var notification_preference_minute: Int = 0
var notification_preference_quarterly_set_time: Date = Date()
var notification_preference_weekday: Int = 0
var notification_preference_weekday: Int = 1
var notification_preference_week_of_month: Int = 0
var phone: String = ""
var picture: String = ""
Expand Down Expand Up @@ -120,6 +120,46 @@ class SelectedContact {
notification_preference == 6
}

func hasPhone() -> Bool {
phone != "" ? true : false
}

func hasSecondaryPhone() -> Bool {
secondary_phone != "" ? true : false
}

func hasEmail() -> Bool {
email != "" ? true : false
}

func hasSecondaryEmail() -> Bool {
secondary_email != "" ? true : false
}

func hasAddress() -> Bool {
address != "" ? true : false
}

func hasSecondaryAddress() -> Bool {
secondary_address != "" ? true : false
}

func hasBirthday() -> Bool {
birthday != "" ? true : false
}

func hasAnniversary() -> Bool {
anniversary != "" ? true : false
}

func hasContactInfo() -> Bool {
if hasPhone() || hasSecondaryPhone() || hasEmail() || hasSecondaryEmail() || hasAddress() || hasSecondaryAddress() || hasBirthday() || hasAnniversary() {
return true
} else {
return false
}
}

static let sampleData = SelectedContact(
address: "2190 E 11th Ave",
anniversary: "06/20/2020",
Expand Down
39 changes: 2 additions & 37 deletions CatchUp-SwiftUI/Utilities/ContactHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,43 +11,8 @@ import UIKit
import Contacts
import CoreData

// Functions for creating and updating a contact
struct ContactHelper {
// MARK: Functions for DetailScreen

static func contactHasPhone(_ contact: SelectedContact) -> Bool {
return contact.phone != "" ? true : false
}

static func contactHasSecondaryPhone(_ contact: SelectedContact) -> Bool {
return contact.secondary_phone != "" ? true : false
}

static func contactHasEmail(_ contact: SelectedContact) -> Bool {
return contact.email != "" ? true : false
}

static func contactHasSecondaryEmail(_ contact: SelectedContact) -> Bool {
return contact.secondary_email != "" ? true : false
}

static func contactHasAddress(_ contact: SelectedContact) -> Bool {
return contact.address != "" ? true : false
}

static func contactHasSecondaryAddress(_ contact: SelectedContact) -> Bool {
return contact.secondary_address != "" ? true : false
}

static func contactHasBirthday(_ contact: SelectedContact) -> Bool {
return contact.birthday != "" ? true : false
}

static func contactHasAnniversary(_ contact: SelectedContact) -> Bool {
return contact.anniversary != "" ? true : false
}

// MARK: Functions for ContactPickerViewController

static func encodeContactPicture(for contact: CNContact) -> String {
let picture: String

Expand Down Expand Up @@ -283,7 +248,7 @@ struct ContactHelper {
let notification_preference_hour = currentHour
let notification_preference_minute = currentMinute
let notification_preference_quarterly_set_time = Date()
let notification_preference_weekday = 0
let notification_preference_weekday = 1
let notification_preference_custom_year = currentYear
let notification_preference_custom_month = currentMonth
let notification_preference_custom_day = currentDay
Expand Down
12 changes: 6 additions & 6 deletions CatchUp-SwiftUI/Utilities/NotificationHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ struct NotificationHelper {
addGeneralNotification(for: contact)
}

if ContactHelper.contactHasBirthday(contact) {
if contact.hasBirthday() {
addBirthdayNotification(for: contact)
}

if ContactHelper.contactHasAnniversary(contact) {
if contact.hasAnniversary() {
addAnniversaryNotification(for: contact)
}
}
Expand Down Expand Up @@ -128,14 +128,14 @@ struct NotificationHelper {
soonestUpcomingNotificationDateString = calculateDateStringFromComponents(components)
}

if ContactHelper.contactHasBirthday(contact) && !contact.preferenceIsNever() {
if contact.hasBirthday() && !contact.preferenceIsNever() {
let birthdayDateString = calculateDateStringFromComponents(getBirthdayDateComponents(for: contact))
if birthdayDateString < soonestUpcomingNotificationDateString {
soonestUpcomingNotificationDateString = birthdayDateString
}
}

if ContactHelper.contactHasAnniversary(contact) && !contact.preferenceIsNever() {
if contact.hasAnniversary() && !contact.preferenceIsNever() {
let anniversaryDateString = calculateDateStringFromComponents(getAnniversaryDateComponents(for: contact))
if anniversaryDateString < soonestUpcomingNotificationDateString {
soonestUpcomingNotificationDateString = anniversaryDateString
Expand Down Expand Up @@ -339,11 +339,11 @@ struct NotificationHelper {
static func removeExistingNotifications(for contact: SelectedContact) {
removeGeneralNotification(for: contact)

if ContactHelper.contactHasBirthday(contact) {
if contact.hasBirthday() {
removeBirthdayNotification(for: contact)
}

if ContactHelper.contactHasAnniversary(contact) {
if contact.hasAnniversary() {
removeAnniversaryNotification(for: contact)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ struct BirthdayOrAnniversaryRow: View {
}

func dayBeforeAnniversaryString() -> String? {
if ContactHelper.contactHasAnniversary(contact) {
if contact.hasAnniversary() {
return NotificationHelper.calculateDateStringFromComponents(NotificationHelper.getAnniversaryDateComponents(for: contact))
}

Expand Down
23 changes: 15 additions & 8 deletions CatchUp-SwiftUI/Views/DetailScreen Subviews/ContactInfoView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ struct ContactInfoView: View {
}

var body: some View {
if ContactHelper.contactHasPhone(contact) {
if contact.hasPhone() {
VStack(alignment: .leading, spacing: 3) {
Text("Phone")
.font(.caption)
Expand All @@ -52,7 +52,8 @@ struct ContactInfoView: View {
.foregroundStyle(.blue)
}
}
if ContactHelper.contactHasSecondaryPhone(contact) {

if contact.hasSecondaryPhone() {
VStack(alignment: .leading, spacing: 3) {
Text("Secondary Phone")
.font(.caption)
Expand All @@ -63,7 +64,8 @@ struct ContactInfoView: View {
.foregroundStyle(.blue)
}
}
if ContactHelper.contactHasEmail(contact) {

if contact.hasEmail() {
VStack(alignment: .leading, spacing: 3) {
Text("Email")
.font(.caption)
Expand All @@ -86,7 +88,8 @@ struct ContactInfoView: View {
Button("Cancel", role: .cancel) {}
}
}
if ContactHelper.contactHasSecondaryEmail(contact) {

if contact.hasSecondaryEmail() {
VStack(alignment: .leading, spacing: 3) {
Text("Secondary Email")
.font(.caption)
Expand All @@ -99,7 +102,8 @@ struct ContactInfoView: View {
.foregroundStyle(.blue)
}
}
if ContactHelper.contactHasAddress(contact) {

if contact.hasAddress() {
VStack(alignment: .leading, spacing: 3) {
Text("Address")
.font(.caption)
Expand All @@ -109,7 +113,8 @@ struct ContactInfoView: View {
.foregroundStyle(.blue)
}
}
if ContactHelper.contactHasSecondaryAddress(contact) {

if contact.hasSecondaryAddress() {
VStack(alignment: .leading, spacing: 3) {
Text("Secondary Address")
.font(.caption)
Expand All @@ -119,7 +124,8 @@ struct ContactInfoView: View {
.foregroundStyle(.blue)
}
}
if ContactHelper.contactHasBirthday(contact) {

if contact.hasBirthday() {
VStack(alignment: .leading, spacing: 3) {
Text("Birthday")
.font(.caption)
Expand All @@ -133,7 +139,8 @@ struct ContactInfoView: View {
}
}
}
if ContactHelper.contactHasAnniversary(contact) {

if contact.hasAnniversary() {
VStack(alignment: .leading, spacing: 3) {
Text("Anniversary")
.font(.caption)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ struct NotificationPreferenceView: View {
@Environment(DataController.self) var dataController
@Environment(\.modelContext) var modelContext

@State private var initialNotificationPreference = 0
@State private var initialNotificationPreferenceWeekday = 0
@State private var initialNotificationPreference = 0 // Never
@State private var initialNotificationPreferenceWeekday = 1 // Sunday
@State private var initialNotificationPreferenceTime = Date()
@State private var initialNotificationPreferenceCustomDate = Date()

Expand Down
7 changes: 5 additions & 2 deletions CatchUp-SwiftUI/Views/DetailScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@ struct DetailScreen: View {
Section("Notification Preference") {
NotificationPreferenceView(contact: contact)
}
Section("Contact Information") {
ContactInfoView(contact: contact)

if contact.hasContactInfo() {
Section("Contact Information") {
ContactInfoView(contact: contact)
}
}

RemoveContactButton(contact: contact)
Expand Down
1 change: 1 addition & 0 deletions CatchUp-SwiftUI/Views/HomeScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ struct HomeScreen : View {
}
} else {
Text("No CatchUps yet! Tap the 'Add Contacts' button to add some.")
.foregroundStyle(.gray)
}
}
.refreshable {
Expand Down

0 comments on commit 4110020

Please sign in to comment.