Skip to content

Commit

Permalink
Merge pull request #58 from johnchoi96/feature/52-font-size
Browse files Browse the repository at this point in the history
Added font stepper for two views
  • Loading branch information
johnchoi96 authored Dec 29, 2023
2 parents bdf4360 + cd583e2 commit c8574b6
Show file tree
Hide file tree
Showing 9 changed files with 183 additions and 75 deletions.
12 changes: 6 additions & 6 deletions JCAlerts.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -115,7 +115,7 @@
D2C660EA2AD2FFEC00CB52BE /* JCAlerts.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = JCAlerts.entitlements; sourceTree = "<group>"; };
D2C660EB2ADA881800CB52BE /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = "<group>"; };
D2E412DC2B26B3E9003EC53F /* NotificationComment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationComment.swift; sourceTree = "<group>"; };
D2E412DE2B26B7FD003EC53F /* UserService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserService.swift; sourceTree = "<group>"; };
D2E412DE2B26B7FD003EC53F /* UserSettingService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserSettingService.swift; sourceTree = "<group>"; };
D2E412E02B26DF28003EC53F /* NotificationCommentsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationCommentsViewController.swift; sourceTree = "<group>"; };
D2E412E52B26E3BD003EC53F /* NotificationCommentTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationCommentTableViewCell.swift; sourceTree = "<group>"; };
D2E412E62B26E3BD003EC53F /* NotificationCommentTableViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = NotificationCommentTableViewCell.xib; sourceTree = "<group>"; };
Expand Down Expand Up @@ -279,7 +279,7 @@
children = (
D24211B32AED548E005BD72C /* FCMTopicService.swift */,
D2984CC92B08436A007B199C /* CloudFirestoreService.swift */,
D2E412DE2B26B7FD003EC53F /* UserService.swift */,
D2E412DE2B26B7FD003EC53F /* UserSettingService.swift */,
);
path = services;
sourceTree = "<group>";
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
18 changes: 18 additions & 0 deletions JCAlerts/controllers/NotificationDetailViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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!

Expand All @@ -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)
Expand All @@ -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
Expand Down
19 changes: 19 additions & 0 deletions JCAlerts/controllers/PushNotificationDisplayViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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)
}
Expand Down
20 changes: 9 additions & 11 deletions JCAlerts/delegates/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 4 additions & 3 deletions JCAlerts/services/CloudFirestoreService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Expand Down Expand Up @@ -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
}
Expand Down
31 changes: 0 additions & 31 deletions JCAlerts/services/UserService.swift

This file was deleted.

62 changes: 62 additions & 0 deletions JCAlerts/services/UserSettingService.swift
Original file line number Diff line number Diff line change
@@ -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
}
}
Loading

0 comments on commit c8574b6

Please sign in to comment.