diff --git a/JCAlerts.xcodeproj/project.pbxproj b/JCAlerts.xcodeproj/project.pbxproj index 609c6a9..1cbcf73 100644 --- a/JCAlerts.xcodeproj/project.pbxproj +++ b/JCAlerts.xcodeproj/project.pbxproj @@ -62,7 +62,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 */; }; @@ -115,7 +115,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 = ""; }; @@ -279,7 +279,7 @@ children = ( D24211B32AED548E005BD72C /* FCMTopicService.swift */, D2984CC92B08436A007B199C /* CloudFirestoreService.swift */, - D2E412DE2B26B7FD003EC53F /* UserService.swift */, + D2E412DE2B26B7FD003EC53F /* UserSettingService.swift */, ); path = services; sourceTree = ""; @@ -461,7 +461,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 */, @@ -650,7 +650,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; @@ -683,7 +683,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/controllers/NotificationDetailViewController.swift b/JCAlerts/controllers/NotificationDetailViewController.swift index ce0f360..464938b 100644 --- a/JCAlerts/controllers/NotificationDetailViewController.swift +++ b/JCAlerts/controllers/NotificationDetailViewController.swift @@ -14,6 +14,7 @@ class NotificationDetailViewController: UIViewController { @IBOutlet weak var topicNameLabel: UILabel! @IBOutlet weak var messageView: UITextView! @IBOutlet weak var timestampLabel: UILabel! + @IBOutlet weak var fontSizeStepper: UIStepper! var notificationPayload: NotificationPayload! @@ -29,6 +30,11 @@ class NotificationDetailViewController: UIViewController { messageView.text = notificationPayload.message } messageView.layer.cornerRadius = 15 + let fontSize = UserSettingService.instance.getTextViewFontSize() + messageView.font = .systemFont(ofSize: CGFloat(fontSize)) + fontSizeStepper.minimumValue = 12 + fontSizeStepper.maximumValue = 30 + fontSizeStepper.value = Double(fontSize) topicNameLabel.text = notificationPayload.topic.getTopicName() let timestamp = notificationPayload.timestamp timestampLabel.text = formatTimestamp(timestamp: timestamp) @@ -54,6 +60,18 @@ class NotificationDetailViewController: UIViewController { performSegue(withIdentifier: K.Segues.notificationDetailToComments, sender: notificationPayload) } + @IBAction func stepperTapped(_ sender: UIStepper) { + let oldFontSize = UserSettingService.instance.getTextViewFontSize() + if Double(oldFontSize) < fontSizeStepper.value { + UserSettingService.instance.increaseTextViewFontSize() + } else { + UserSettingService.instance.decreaseTextViewFontSize() + } + + let newFontSize = UserSettingService.instance.getTextViewFontSize() + messageView.font = .systemFont(ofSize: CGFloat(newFontSize)) + } + override func prepare(for segue: UIStoryboardSegue, sender: Any?) { if segue.identifier == K.Segues.notificationDetailToComments { let vc = segue.destination as! NotificationCommentsViewController diff --git a/JCAlerts/controllers/PushNotificationDisplayViewController.swift b/JCAlerts/controllers/PushNotificationDisplayViewController.swift index cad2184..d6182ec 100644 --- a/JCAlerts/controllers/PushNotificationDisplayViewController.swift +++ b/JCAlerts/controllers/PushNotificationDisplayViewController.swift @@ -9,6 +9,8 @@ import UIKit class PushNotificationDisplayViewController: UIViewController { + @IBOutlet weak var fontSizeStepper: UIStepper! + static let nib = UINib(nibName: "PushNotificationDisplayViewController", bundle: nil) static let identifier = K.Nibs.Views.notificationDisplayView @@ -25,6 +27,11 @@ class PushNotificationDisplayViewController: UIViewController { title = "Notification Detail" textView.text = "Loading..." textView.layer.cornerRadius = 15 + let fontSize = UserSettingService.instance.getTextViewFontSize() + textView.font = .systemFont(ofSize: CGFloat(fontSize)) + fontSizeStepper.minimumValue = 12 + fontSizeStepper.maximumValue = 30 + fontSizeStepper.value = Double(fontSize) self.view.backgroundColor = UIColor(named: K.Colors.backgroundColor) cloudFirestoreService.delegate = self @@ -35,6 +42,18 @@ class PushNotificationDisplayViewController: UIViewController { } } + @IBAction func stepperTapped(_ sender: UIStepper) { + let oldFontSize = UserSettingService.instance.getTextViewFontSize() + if Double(oldFontSize) < fontSizeStepper.value { + UserSettingService.instance.increaseTextViewFontSize() + } else { + UserSettingService.instance.decreaseTextViewFontSize() + } + + let newFontSize = UserSettingService.instance.getTextViewFontSize() + textView.font = .systemFont(ofSize: CGFloat(newFontSize)) + } + @IBAction func doneTapped(_ sender: UIBarButtonItem) { self.dismiss(animated: true) } diff --git a/JCAlerts/delegates/AppDelegate.swift b/JCAlerts/delegates/AppDelegate.swift index 66ad02e..4704b5e 100644 --- a/JCAlerts/delegates/AppDelegate.swift +++ b/JCAlerts/delegates/AppDelegate.swift @@ -131,24 +131,22 @@ extension AppDelegate: UNUserNotificationCenterDelegate { -> 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 @@ - - - + + - + +