From 7dddc1ab4f4d1cd21b7b70c8de74c1b9481d369f Mon Sep 17 00:00:00 2001 From: John Choi Date: Fri, 29 Dec 2023 00:48:40 -0500 Subject: [PATCH 1/2] Added font stepper for two views --- JCAlerts.xcodeproj/project.pbxproj | 12 ++-- .../xcshareddata/xcschemes/JCAlerts.xcscheme | 2 +- .../NotificationDetailViewController.swift | 18 ++++++ ...ushNotificationDisplayViewController.swift | 19 ++++++ JCAlerts/delegates/AppDelegate.swift | 20 +++--- JCAlerts/services/CloudFirestoreService.swift | 7 ++- JCAlerts/services/UserService.swift | 31 ---------- JCAlerts/services/UserSettingService.swift | 62 +++++++++++++++++++ .../storyboards/Base.lproj/Main.storyboard | 38 ++++++++---- .../PushNotificationDisplayViewController.xib | 51 +++++++++++---- 10 files changed, 184 insertions(+), 76 deletions(-) delete mode 100644 JCAlerts/services/UserService.swift create mode 100644 JCAlerts/services/UserSettingService.swift diff --git a/JCAlerts.xcodeproj/project.pbxproj b/JCAlerts.xcodeproj/project.pbxproj index acfd22d..011ea65 100644 --- a/JCAlerts.xcodeproj/project.pbxproj +++ b/JCAlerts.xcodeproj/project.pbxproj @@ -61,7 +61,7 @@ D2C660E52AD2073E00CB52BE /* FirebaseMessaging in Frameworks */ = {isa = PBXBuildFile; productRef = D2C660E42AD2073E00CB52BE /* FirebaseMessaging */; }; D2C660EC2ADA881800CB52BE /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = D2C660EB2ADA881800CB52BE /* GoogleService-Info.plist */; }; D2E412DD2B26B3E9003EC53F /* NotificationComment.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2E412DC2B26B3E9003EC53F /* NotificationComment.swift */; }; - D2E412DF2B26B7FD003EC53F /* UserService.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2E412DE2B26B7FD003EC53F /* UserService.swift */; }; + D2E412DF2B26B7FD003EC53F /* UserSettingService.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2E412DE2B26B7FD003EC53F /* UserSettingService.swift */; }; D2E412E12B26DF28003EC53F /* NotificationCommentsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2E412E02B26DF28003EC53F /* NotificationCommentsViewController.swift */; }; D2E412E42B26E2A8003EC53F /* IQKeyboardManagerSwift in Frameworks */ = {isa = PBXBuildFile; productRef = D2E412E32B26E2A8003EC53F /* IQKeyboardManagerSwift */; }; D2E412E72B26E3BD003EC53F /* NotificationCommentTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2E412E52B26E3BD003EC53F /* NotificationCommentTableViewCell.swift */; }; @@ -113,7 +113,7 @@ D2C660EA2AD2FFEC00CB52BE /* JCAlerts.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = JCAlerts.entitlements; sourceTree = ""; }; D2C660EB2ADA881800CB52BE /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = ""; }; D2E412DC2B26B3E9003EC53F /* NotificationComment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationComment.swift; sourceTree = ""; }; - D2E412DE2B26B7FD003EC53F /* UserService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserService.swift; sourceTree = ""; }; + D2E412DE2B26B7FD003EC53F /* UserSettingService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserSettingService.swift; sourceTree = ""; }; D2E412E02B26DF28003EC53F /* NotificationCommentsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationCommentsViewController.swift; sourceTree = ""; }; D2E412E52B26E3BD003EC53F /* NotificationCommentTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationCommentTableViewCell.swift; sourceTree = ""; }; D2E412E62B26E3BD003EC53F /* NotificationCommentTableViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = NotificationCommentTableViewCell.xib; sourceTree = ""; }; @@ -276,7 +276,7 @@ children = ( D24211B32AED548E005BD72C /* FCMTopicService.swift */, D2984CC92B08436A007B199C /* CloudFirestoreService.swift */, - D2E412DE2B26B7FD003EC53F /* UserService.swift */, + D2E412DE2B26B7FD003EC53F /* UserSettingService.swift */, ); path = services; sourceTree = ""; @@ -458,7 +458,7 @@ files = ( D26F6C542AD1FADF00AC1D6F /* AlertsViewController.swift in Sources */, D26F6C5A2AD1FADF00AC1D6F /* JCAlerts.xcdatamodeld in Sources */, - D2E412DF2B26B7FD003EC53F /* UserService.swift in Sources */, + D2E412DF2B26B7FD003EC53F /* UserSettingService.swift in Sources */, D24211A82AEB5567005BD72C /* SettingsTableViewCell.swift in Sources */, D2153F772B32B33600F405C8 /* UIExt.swift in Sources */, D2984CD12B084A37007B199C /* NotificationPayload.swift in Sources */, @@ -646,7 +646,7 @@ ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_ENTITLEMENTS = JCAlerts/JCAlerts.entitlements; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 2023122801; + CURRENT_PROJECT_VERSION = 2023122901; DEVELOPMENT_TEAM = 2JDGUK4DRH; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = JCAlerts/Info.plist; @@ -679,7 +679,7 @@ ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_ENTITLEMENTS = JCAlerts/JCAlerts.entitlements; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 2023122801; + CURRENT_PROJECT_VERSION = 2023122901; DEVELOPMENT_TEAM = 2JDGUK4DRH; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = JCAlerts/Info.plist; diff --git a/JCAlerts.xcodeproj/xcshareddata/xcschemes/JCAlerts.xcscheme b/JCAlerts.xcodeproj/xcshareddata/xcschemes/JCAlerts.xcscheme index 0b6ad65..a436e14 100644 --- a/JCAlerts.xcodeproj/xcshareddata/xcschemes/JCAlerts.xcscheme +++ b/JCAlerts.xcodeproj/xcshareddata/xcschemes/JCAlerts.xcscheme @@ -30,7 +30,7 @@ shouldAutocreateTestPlan = "YES"> UNNotificationPresentationOptions { let userInfo = notification.request.content.userInfo log.info("Notification Payload: \(userInfo)") - -#if !DEBUG - // check if notification is a test notification - let isTestMessage = Bool(userInfo["test-notification"] as! String)! - if isTestMessage { - return [] - } -#endif - // With swizzling disabled you must let Messaging know about the message, for Analytics // Messaging.messaging().appDidReceiveMessage(userInfo) - let notificationTopic = userInfo["notification-topic"] as! String if !FCMTopicService.instance.topicIsSubscribed(topic: notificationTopic) { return [] } + + // NOTE: comment this block for development - #if !DEBUG does not work at the moment + // check if notification is a test notification + let isTestMessage = Bool(userInfo["test-notification"] as! String)! + if isTestMessage { + return [] + } + // Change this to your preferred presentation option - return [[.banner, .sound]] + return [.banner, .sound] } func userNotificationCenter(_ center: UNUserNotificationCenter, diff --git a/JCAlerts/services/CloudFirestoreService.swift b/JCAlerts/services/CloudFirestoreService.swift index 8de3eeb..6bd639f 100644 --- a/JCAlerts/services/CloudFirestoreService.swift +++ b/JCAlerts/services/CloudFirestoreService.swift @@ -19,7 +19,7 @@ class CloudFirestoreService: ObservableObject { private let logger = os.Logger() - private let userService = UserService.instance + private let userService = UserSettingService.instance var delegate: CloudFirestoreDelegate? @@ -73,12 +73,13 @@ class CloudFirestoreService: ObservableObject { let payload = NotificationPayload(id: UUID(), notificationTitle: notificationTitle, notificationSubtitle: notificationSubtitle, notificationId: notificationId, message: message, timestamp: timestamp.utcTimestampToDate(), topic: topic, isHtml: isHtml, isTestMessage: isTestMessage) -#if !DEBUG + + // NOTE: comment this block for development - #if !DEBUG does not work at the moment // if on prod, ignore test messages if payload.isTestMessage { continue } -#endif + notifications.append(payload) notificationDict[notificationId] = payload } diff --git a/JCAlerts/services/UserService.swift b/JCAlerts/services/UserService.swift deleted file mode 100644 index baffeb8..0000000 --- a/JCAlerts/services/UserService.swift +++ /dev/null @@ -1,31 +0,0 @@ -// -// FirebaseService.swift -// JCAlerts -// -// Created by John Choi on 12/10/23. -// - -import Foundation - -class UserService { - static let instance = UserService() - - private var currentUsername: String - - private init() { - // check if UserDefaults has username defined - let userDefaults = UserDefaults.standard - if let username = userDefaults.string(forKey: "currentUsername") { - currentUsername = username - } else { - // generate username - let uuid = UUID().uuidString - currentUsername = uuid - userDefaults.setValue(uuid, forKey: "currentUsername") - } - } - - func getCurrentUsername() -> String { - return currentUsername - } -} diff --git a/JCAlerts/services/UserSettingService.swift b/JCAlerts/services/UserSettingService.swift new file mode 100644 index 0000000..98f6ab1 --- /dev/null +++ b/JCAlerts/services/UserSettingService.swift @@ -0,0 +1,62 @@ +// +// FirebaseService.swift +// JCAlerts +// +// Created by John Choi on 12/10/23. +// + +import Foundation + +class UserSettingService { + static let instance = UserSettingService() + + let userDefaults = UserDefaults.standard + + private var currentUsername: String + + private var textViewFontSize: Int + + private init() { + // check if UserDefaults has username defined + if let username = userDefaults.string(forKey: "currentUsername") { + currentUsername = username + } else { + // generate username + let uuid = UUID().uuidString + currentUsername = uuid + userDefaults.setValue(uuid, forKey: "currentUsername") + } + + // check if UserDefaults has textViewFontSize defined + if userDefaults.integer(forKey: "textViewFontSize") != 0 { + textViewFontSize = userDefaults.integer(forKey: "textViewFontSize") + } else { + textViewFontSize = 14 + userDefaults.setValue(textViewFontSize, forKey: "textViewFontSize") + } + } + + func getTextViewFontSize() -> Int { + return textViewFontSize + } + + func decreaseTextViewFontSize() { + if textViewFontSize <= 12 { + return + } + textViewFontSize -= 1 + userDefaults.setValue(textViewFontSize, forKey: "textViewFontSize") + } + + func increaseTextViewFontSize() { + if textViewFontSize >= 30 { + return + } + textViewFontSize += 1 + userDefaults.setValue(textViewFontSize, forKey: "textViewFontSize") + } + + func getCurrentUsername() -> String { + return currentUsername + } +} diff --git a/JCAlerts/storyboards/Base.lproj/Main.storyboard b/JCAlerts/storyboards/Base.lproj/Main.storyboard index 76b75e1..512ed2b 100644 --- a/JCAlerts/storyboards/Base.lproj/Main.storyboard +++ b/JCAlerts/storyboards/Base.lproj/Main.storyboard @@ -64,7 +64,7 @@ - + @@ -83,7 +83,7 @@ - + @@ -106,7 +106,7 @@ - + - + + + + + + + + + + - + + - - + @@ -176,6 +187,7 @@ + @@ -310,7 +322,7 @@ - + diff --git a/JCAlerts/storyboards/PushNotificationDisplayViewController.xib b/JCAlerts/storyboards/PushNotificationDisplayViewController.xib index f525cc2..2bff846 100644 --- a/JCAlerts/storyboards/PushNotificationDisplayViewController.xib +++ b/JCAlerts/storyboards/PushNotificationDisplayViewController.xib @@ -10,6 +10,7 @@ + @@ -19,13 +20,41 @@ - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -42,13 +71,13 @@ - - - + + - + + From cd583e26422f8f7dae5921e6478063703fee3f4c Mon Sep 17 00:00:00 2001 From: John Choi Date: Fri, 29 Dec 2023 00:50:08 -0500 Subject: [PATCH 2/2] Reverting scheme --- JCAlerts.xcodeproj/xcshareddata/xcschemes/JCAlerts.xcscheme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/JCAlerts.xcodeproj/xcshareddata/xcschemes/JCAlerts.xcscheme b/JCAlerts.xcodeproj/xcshareddata/xcschemes/JCAlerts.xcscheme index a436e14..0b6ad65 100644 --- a/JCAlerts.xcodeproj/xcshareddata/xcschemes/JCAlerts.xcscheme +++ b/JCAlerts.xcodeproj/xcshareddata/xcschemes/JCAlerts.xcscheme @@ -30,7 +30,7 @@ shouldAutocreateTestPlan = "YES">