From 8088c4a6532d9344c349536811608e030e45612e Mon Sep 17 00:00:00 2001 From: Sophia Liu Date: Sun, 18 Feb 2024 01:14:15 -0600 Subject: [PATCH 1/2] add notifications functionality --- HIAPI/Models/Notification.swift | 17 ++++++++++++ HIAPI/Services/NotificationService.swift | 22 ++++++++++++++++ HackIllinois.xcodeproj/project.pbxproj | 33 ++++++++++++++++++++++++ HackIllinois/AppDelegate.swift | 30 ++++++++++++++++++--- HackIllinois/GoogleService-Info.plist | 32 +++++++++++++++++++++++ 5 files changed, 131 insertions(+), 3 deletions(-) create mode 100644 HIAPI/Models/Notification.swift create mode 100644 HIAPI/Services/NotificationService.swift create mode 100644 HackIllinois/GoogleService-Info.plist diff --git a/HIAPI/Models/Notification.swift b/HIAPI/Models/Notification.swift new file mode 100644 index 00000000..736b8682 --- /dev/null +++ b/HIAPI/Models/Notification.swift @@ -0,0 +1,17 @@ +// +// Notification.swift +// HIAPI +// +// Created by HackIllinois on 2/18/24. +// Copyright © 2024 HackIllinois. All rights reserved. +// + +import Foundation +import APIManager + +public struct NotificationContainer: Decodable, APIReturnable { + public let success: Bool? + public let status: String? + public let error: String? +} + diff --git a/HIAPI/Services/NotificationService.swift b/HIAPI/Services/NotificationService.swift new file mode 100644 index 00000000..e7acf455 --- /dev/null +++ b/HIAPI/Services/NotificationService.swift @@ -0,0 +1,22 @@ +// +// NotificationService.swift +// HIAPI +// +// Created by HackIllinois on 2/18/24. +// Copyright © 2024 HackIllinois. All rights reserved. +// + +import Foundation +import APIManager + +public final class NotificationService: BaseService { + public override static var baseURL: String { + return super.baseURL + } + + public static func sendDeviceToken(deviceToken: String) -> APIRequest { + var body = HTTPBody() + body["deviceToken"] = deviceToken + return APIRequest(service: self, endpoint: "notification/", body: body, method: .POST) + } +} diff --git a/HackIllinois.xcodeproj/project.pbxproj b/HackIllinois.xcodeproj/project.pbxproj index f63fe346..9c8aace9 100644 --- a/HackIllinois.xcodeproj/project.pbxproj +++ b/HackIllinois.xcodeproj/project.pbxproj @@ -148,6 +148,12 @@ D1BE81172AC8FC680042C078 /* HIAPI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 95E3142A21FAD5B30092C22E /* HIAPI.framework */; }; D1BE81182AC8FC690042C078 /* HIAPI.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 95E3142A21FAD5B30092C22E /* HIAPI.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; D1C5B6582B732E44000E766D /* refresh.json in Resources */ = {isa = PBXBuildFile; fileRef = D1C5B6572B732E44000E766D /* refresh.json */; }; + D1D335172B81DEBA00BBB596 /* FirebaseMessaging in Frameworks */ = {isa = PBXBuildFile; productRef = D1D335162B81DEBA00BBB596 /* FirebaseMessaging */; }; + D1D335192B81DEF600BBB596 /* Notification.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1D335182B81DEF600BBB596 /* Notification.swift */; }; + D1D3351B2B81DF0300BBB596 /* NotificationService.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1D3351A2B81DF0300BBB596 /* NotificationService.swift */; }; + D1D3351D2B81E11500BBB596 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = D1D3351C2B81E11500BBB596 /* GoogleService-Info.plist */; }; + D1D3351E2B81E11500BBB596 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = D1D3351C2B81E11500BBB596 /* GoogleService-Info.plist */; }; + D1D3351F2B81E11500BBB596 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = D1D3351C2B81E11500BBB596 /* GoogleService-Info.plist */; }; D1F1463A2B605C57004E7FC9 /* Hack_Mushroom_Loading.json in Resources */ = {isa = PBXBuildFile; fileRef = D1F146392B605C57004E7FC9 /* Hack_Mushroom_Loading.json */; }; D3A309BC2211175200CBA351 /* PassKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D3A309BB2211175200CBA351 /* PassKit.framework */; }; D7451BD22B54BCFB00D501D0 /* URLImage in Frameworks */ = {isa = PBXBuildFile; productRef = D7451BD12B54BCFB00D501D0 /* URLImage */; }; @@ -364,6 +370,9 @@ D1BBA5672B70AB940017BD13 /* Staff.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Staff.swift; sourceTree = ""; }; D1BBA5692B70ACCC0017BD13 /* StaffService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StaffService.swift; sourceTree = ""; }; D1C5B6572B732E44000E766D /* refresh.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = refresh.json; sourceTree = ""; }; + D1D335182B81DEF600BBB596 /* Notification.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Notification.swift; sourceTree = ""; }; + D1D3351A2B81DF0300BBB596 /* NotificationService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationService.swift; sourceTree = ""; }; + D1D3351C2B81E11500BBB596 /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = ""; }; D1F146392B605C57004E7FC9 /* Hack_Mushroom_Loading.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = Hack_Mushroom_Loading.json; sourceTree = ""; }; D3A309BA221116A600CBA351 /* HackIllinois.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = HackIllinois.entitlements; sourceTree = ""; }; D3A309BB2211175200CBA351 /* PassKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = PassKit.framework; path = System/Library/Frameworks/PassKit.framework; sourceTree = SDKROOT; }; @@ -407,6 +416,7 @@ DF3706562925DE4C000B4278 /* Metal.framework in Frameworks */, DF3706542925DE47000B4278 /* libz.tbd in Frameworks */, DF3706522925DE42000B4278 /* libc++.tbd in Frameworks */, + D1D335172B81DEBA00BBB596 /* FirebaseMessaging in Frameworks */, DF3706502925DE38000B4278 /* ImageIO.framework in Frameworks */, DF37064E2925DE34000B4278 /* GLKit.framework in Frameworks */, DF37064C2925DE2F000B4278 /* CoreText.framework in Frameworks */, @@ -511,6 +521,7 @@ 957DB2E91FC2453100F8C45E /* FlowControllers */, 951827981EA35DB800049F79 /* AppDelegate.swift */, 951827991EA35DB800049F79 /* Assets.xcassets */, + D1D3351C2B81E11500BBB596 /* GoogleService-Info.plist */, 9518279E1EA35DB800049F79 /* Controllers */, 9521A6A6201912B4009059C6 /* DataSources */, 958A33E421E143BF00F34C9E /* Extensions */, @@ -728,6 +739,7 @@ 95E3146221FAF1740092C22E /* AuthService.swift */, 2FA73B4D2B58CAA0002658C0 /* ShopService.swift */, 95E3146121FAF1740092C22E /* BaseService.swift */, + D1D3351A2B81DF0300BBB596 /* NotificationService.swift */, 95B12042220BEA9D00E024BB /* CheckInService.swift */, 95E3145F21FAF1740092C22E /* EventService.swift */, D187BF5B2B78318000AD7356 /* MentorService.swift */, @@ -751,6 +763,7 @@ 95E3146821FAF1740092C22E /* Announcement.swift */, 3521FFA82207C03E00634A63 /* Attendee.swift */, 95E3146521FAF1740092C22E /* Event.swift */, + D1D335182B81DEF600BBB596 /* Notification.swift */, D1BBA5672B70AB940017BD13 /* Staff.swift */, 2FA73B4F2B58CAC3002658C0 /* Item.swift */, AC3B620D25E85CAD002386A2 /* Profile.swift */, @@ -892,6 +905,7 @@ 951E67F523C1C83B00477703 /* Keychain */, 951E67F823C1C88200477703 /* Lottie */, D7451BD12B54BCFB00D501D0 /* URLImage */, + D1D335162B81DEBA00BBB596 /* FirebaseMessaging */, ); productName = HackIllinois; productReference = 9518277F1EA35AF100049F79 /* HackIllinois.app */; @@ -982,6 +996,7 @@ 951E67F423C1C83B00477703 /* XCRemoteSwiftPackageReference "keychain" */, 951E67F723C1C88200477703 /* XCRemoteSwiftPackageReference "lottie-ios" */, D7451BD02B54BCFB00D501D0 /* XCRemoteSwiftPackageReference "url-image" */, + D1D335152B81DEBA00BBB596 /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */, ); productRefGroup = 951827801EA35AF100049F79 /* Products */; projectDirPath = ""; @@ -1007,6 +1022,7 @@ 951827B41EA35E8B00049F79 /* LaunchScreen.storyboard in Resources */, 1C7561A5278E96750004D739 /* LightVespaText.json in Resources */, D134D30F296B3F56006EA589 /* Montserrat-VariableFont_wght.ttf in Resources */, + D1D3351D2B81E11500BBB596 /* GoogleService-Info.plist in Resources */, DF37063E2925DDE7000B4278 /* GoogleMaps.bundle in Resources */, D1C5B6582B732E44000E766D /* refresh.json in Resources */, ); @@ -1016,6 +1032,7 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + D1D3351F2B81E11500BBB596 /* GoogleService-Info.plist in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1024,6 +1041,7 @@ buildActionMask = 2147483647; files = ( AC607EF0261CD6E300B88798 /* Stickers.xcassets in Resources */, + D1D3351E2B81E11500BBB596 /* GoogleService-Info.plist in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1174,6 +1192,7 @@ ACB53AEA261B8789007B1643 /* InterestService.swift in Sources */, 3C8F62D4238F9639001A5DAF /* Time.swift in Sources */, 95E3147621FAF1740092C22E /* Announcement.swift in Sources */, + D1D3351B2B81DF0300BBB596 /* NotificationService.swift in Sources */, 95E3146C21FAF1740092C22E /* UserService.swift in Sources */, 95B12043220BEA9D00E024BB /* CheckInService.swift in Sources */, 95E3147121FAF1740092C22E /* AuthService.swift in Sources */, @@ -1191,6 +1210,7 @@ 3C8F62D6238F9825001A5DAF /* TimeService.swift in Sources */, D187BF5A2B78317600AD7356 /* Mentor.swift in Sources */, 95E3145921FAD71E0092C22E /* Error.swift in Sources */, + D1D335192B81DEF600BBB596 /* Notification.swift in Sources */, 3C26401D23ADE8A5004E1DBE /* Project.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1595,6 +1615,14 @@ version = 4.0.1; }; }; + D1D335152B81DEBA00BBB596 /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */ = { + isa = XCRemoteSwiftPackageReference; + repositoryURL = "https://github.com/firebase/firebase-ios-sdk"; + requirement = { + kind = upToNextMajorVersion; + minimumVersion = 9.0.0; + }; + }; D7451BD02B54BCFB00D501D0 /* XCRemoteSwiftPackageReference "url-image" */ = { isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/dmytro-anokhin/url-image"; @@ -1621,6 +1649,11 @@ package = 951E67F723C1C88200477703 /* XCRemoteSwiftPackageReference "lottie-ios" */; productName = Lottie; }; + D1D335162B81DEBA00BBB596 /* FirebaseMessaging */ = { + isa = XCSwiftPackageProductDependency; + package = D1D335152B81DEBA00BBB596 /* XCRemoteSwiftPackageReference "firebase-ios-sdk" */; + productName = FirebaseMessaging; + }; D7451BD12B54BCFB00D501D0 /* URLImage */ = { isa = XCSwiftPackageProductDependency; package = D7451BD02B54BCFB00D501D0 /* XCRemoteSwiftPackageReference "url-image" */; diff --git a/HackIllinois/AppDelegate.swift b/HackIllinois/AppDelegate.swift index d08e9d30..0c8cc171 100644 --- a/HackIllinois/AppDelegate.swift +++ b/HackIllinois/AppDelegate.swift @@ -15,22 +15,27 @@ import CoreLocation import UserNotifications import HIAPI import GoogleMaps +import Firebase +import FirebaseMessaging @UIApplicationMain -class AppDelegate: UIResponder, UIApplicationDelegate { - +class AppDelegate: UIResponder, UIApplicationDelegate, MessagingDelegate, UNUserNotificationCenterDelegate { private var obfuscatedApiKey: [UInt8] = [92, 213, 228, 193, 244, 27, 239, 139, 188, 14, 85, 191, 47, 237, 55, 13, 85, 89, 111, 212, 35, 80, 45, 104, 189, 229, 33, 32, 70, 63, 90, 163, 173, 232, 167, 90, 203, 22, 169, 29, 156, 158, 160, 167, 98, 174, 239, 247, 118, 96, 207, 104, 180, 14, 90, 58, 61, 89, 186, 89, 7, 114, 25, 255, 141, 115, 113, 117, 78, 10, 150, 197, 161, 158, 98, 129, 87, 228] + var fcmToken: String? // Handle remote notification registration. func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) { guard let user = HIApplicationStateController.shared.user else { return } let token = deviceToken.map { String(format: "%02.2hhx", $0) }.joined() + + Messaging.messaging().apnsToken = deviceToken + Messaging.messaging().delegate = self // Send the token to notifications server - AnnouncementService.sendToken(deviceToken: token) + NotificationService.sendDeviceToken(deviceToken: fcmToken!) .onCompletion { result in do { _ = try result.get() @@ -54,6 +59,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { } func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { + FirebaseApp.configure() setupNavigationBarAppearance() setupTableViewAppearance() _ = HIThemeEngine.shared @@ -63,8 +69,26 @@ class AppDelegate: UIResponder, UIApplicationDelegate { HIApplicationStateController.shared.initalize() // Check the app version and prompt the user to update if needed checkAppVersion() + application.registerForRemoteNotifications() + Messaging.messaging().delegate = self + UNUserNotificationCenter.current().delegate = self return true } + + func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) { + // Called when the app has successfully registered with FCM and received a registration token + self.fcmToken = fcmToken + print("FCM Token: \(fcmToken)") + + } + + func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) { + // Log the notification details + print("Received notification:") + print(notification.request.content.userInfo) + + completionHandler([.alert, .sound, .badge]) + } func applicationWillResignActive(_ application: UIApplication) { // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. diff --git a/HackIllinois/GoogleService-Info.plist b/HackIllinois/GoogleService-Info.plist new file mode 100644 index 00000000..7a60ff06 --- /dev/null +++ b/HackIllinois/GoogleService-Info.plist @@ -0,0 +1,32 @@ + + + + + API_KEY + placeholder + GCM_SENDER_ID + 848675954156 + PLIST_VERSION + 1 + BUNDLE_ID + org.hackillinois.ios + PROJECT_ID + hackillinois-3787e + STORAGE_BUCKET + hackillinois-3787e.appspot.com + IS_ADS_ENABLED + + IS_ANALYTICS_ENABLED + + IS_APPINVITE_ENABLED + + IS_GCM_ENABLED + + IS_SIGNIN_ENABLED + + GOOGLE_APP_ID + 1:848675954156:ios:d43e052424b30ef97f34c9 + DATABASE_URL + https://hackillinois-3787e-default-rtdb.firebaseio.com + + From e54166f852ff70d79660ced69883232ad37907da Mon Sep 17 00:00:00 2001 From: Sophia Liu Date: Sun, 18 Feb 2024 01:41:25 -0600 Subject: [PATCH 2/2] clean up code --- HackIllinois.xcodeproj/project.pbxproj | 4 - HackIllinois/AppDelegate.swift | 2 - .../Cells/HIBubbleCell/HIShiftCell.swift | 141 ------------------ .../HIEventDetailViewController.swift | 1 - .../HIPointsShopSwiftUIView.swift | 12 +- .../ViewControllers/HIProfileCardView.swift | 3 - .../HIProfileViewController.swift | 1 - 7 files changed, 2 insertions(+), 162 deletions(-) delete mode 100644 HackIllinois/UI/TableView/Cells/HIBubbleCell/HIShiftCell.swift diff --git a/HackIllinois.xcodeproj/project.pbxproj b/HackIllinois.xcodeproj/project.pbxproj index 9c8aace9..8ce9f9bf 100644 --- a/HackIllinois.xcodeproj/project.pbxproj +++ b/HackIllinois.xcodeproj/project.pbxproj @@ -139,7 +139,6 @@ D14D3AE3295FBDA200EB7995 /* HIBannerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D14D3AE2295FBDA100EB7995 /* HIBannerViewController.swift */; }; D158EC312B5A2D440003D799 /* HIQRAttendeeScannerSelection.swift in Sources */ = {isa = PBXBuildFile; fileRef = D158EC302B5A2D440003D799 /* HIQRAttendeeScannerSelection.swift */; }; D158EC332B5A2DFE0003D799 /* HIScanPointsShopViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D158EC322B5A2DFE0003D799 /* HIScanPointsShopViewController.swift */; }; - D187BF582B781A1100AD7356 /* HIShiftCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D187BF572B781A1100AD7356 /* HIShiftCell.swift */; }; D187BF5A2B78317600AD7356 /* Mentor.swift in Sources */ = {isa = PBXBuildFile; fileRef = D187BF592B78317600AD7356 /* Mentor.swift */; }; D187BF5C2B78318000AD7356 /* MentorService.swift in Sources */ = {isa = PBXBuildFile; fileRef = D187BF5B2B78318000AD7356 /* MentorService.swift */; }; D19D4C932B794F9100376E1B /* HIScanMentorViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D19D4C922B794F9100376E1B /* HIScanMentorViewController.swift */; }; @@ -363,7 +362,6 @@ D14D3AE2295FBDA100EB7995 /* HIBannerViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HIBannerViewController.swift; sourceTree = ""; }; D158EC302B5A2D440003D799 /* HIQRAttendeeScannerSelection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HIQRAttendeeScannerSelection.swift; sourceTree = ""; }; D158EC322B5A2DFE0003D799 /* HIScanPointsShopViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HIScanPointsShopViewController.swift; sourceTree = ""; }; - D187BF572B781A1100AD7356 /* HIShiftCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HIShiftCell.swift; sourceTree = ""; }; D187BF592B78317600AD7356 /* Mentor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Mentor.swift; sourceTree = ""; }; D187BF5B2B78318000AD7356 /* MentorService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MentorService.swift; sourceTree = ""; }; D19D4C922B794F9100376E1B /* HIScanMentorViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HIScanMentorViewController.swift; sourceTree = ""; }; @@ -693,7 +691,6 @@ 95A7D282203D4F54005EAEAF /* HIAnnouncementCell.swift */, 95A7D29F203D60E9005EAEAF /* HIBubbleCell.swift */, 95A7D281203D4F54005EAEAF /* HIEventCell.swift */, - D187BF572B781A1100AD7356 /* HIShiftCell.swift */, 3CF8DB1223B419980035ECAE /* HIProjectCell.swift */, ); path = HIBubbleCell; @@ -1100,7 +1097,6 @@ E1E4A5DA291C9BF800780BA1 /* HIOnboardingView.swift in Sources */, 95A7D290203D4F54005EAEAF /* HIAnnouncementCell.swift in Sources */, 9515E43722093E1300BCAF92 /* HIEventScannerViewController.swift in Sources */, - D187BF582B781A1100AD7356 /* HIShiftCell.swift in Sources */, 95A7D28F203D4F54005EAEAF /* HIEventCell.swift in Sources */, ACAA717626017EC4000F42B0 /* HICollectionViewFlowLayout.swift in Sources */, DF5B27C5299197E80034A8B9 /* Array.swift in Sources */, diff --git a/HackIllinois/AppDelegate.swift b/HackIllinois/AppDelegate.swift index 0c8cc171..4273588a 100644 --- a/HackIllinois/AppDelegate.swift +++ b/HackIllinois/AppDelegate.swift @@ -78,13 +78,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate, MessagingDelegate, UNUser func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) { // Called when the app has successfully registered with FCM and received a registration token self.fcmToken = fcmToken - print("FCM Token: \(fcmToken)") } func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) { // Log the notification details - print("Received notification:") print(notification.request.content.userInfo) completionHandler([.alert, .sound, .badge]) diff --git a/HackIllinois/UI/TableView/Cells/HIBubbleCell/HIShiftCell.swift b/HackIllinois/UI/TableView/Cells/HIBubbleCell/HIShiftCell.swift deleted file mode 100644 index f886fd66..00000000 --- a/HackIllinois/UI/TableView/Cells/HIBubbleCell/HIShiftCell.swift +++ /dev/null @@ -1,141 +0,0 @@ -// -// HIShiftCell.swift -// HackIllinois -// -// Created by HackIllinois Team on 2/10/24. -// Copyright © 2017 HackIllinois. All rights reserved. -// This file is part of the Hackillinois iOS App. -// The Hackillinois iOS App is open source software, released under the University of -// Illinois/NCSA Open Source License. You should have received a copy of -// this license in a file with the distribution. -// - -import Foundation -import UIKit -import HIAPI - - -class HIShiftCell: HIBubbleCell { - // MARK: - Properties - var headerView = UIStackView() - var contentStackView = UIStackView() - var contentStackViewHeight = NSLayoutConstraint() - - var indexPath: IndexPath? - weak var delegate: HIEventCellDelegate? - - // MARK: - Init - override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { - super.init(style: style, reuseIdentifier: reuseIdentifier) - var headerSpacingConstant: CGFloat = 1.0 - if UIDevice.current.userInterfaceIdiom == .pad { - headerSpacingConstant = 2.0 - } - backgroundColor = UIColor.clear - // add bubble view - contentView.layer.backgroundColor = UIColor.clear.cgColor - bubbleView.addSubview(headerView) - headerView.axis = .vertical - headerView.alignment = .leading - headerView.translatesAutoresizingMaskIntoConstraints = false - headerView.leadingAnchor.constraint(equalTo: bubbleView.leadingAnchor, constant: 17 * headerSpacingConstant).isActive = true - headerView.topAnchor.constraint(equalTo: bubbleView.topAnchor, constant: 16 * headerSpacingConstant).isActive = true - - bubbleView.addSubview(contentStackView) - contentStackView.axis = .vertical - contentStackView.alignment = .leading - contentStackView.translatesAutoresizingMaskIntoConstraints = false - contentStackView.leadingAnchor.constraint(equalTo: headerView.leadingAnchor).isActive = true - contentStackView.trailingAnchor.constraint(equalTo: bubbleView.trailingAnchor, constant: -16).isActive = true - contentStackView.topAnchor.constraint(equalTo: headerView.bottomAnchor, constant: 10 * headerSpacingConstant).isActive = true - contentStackView.bottomAnchor.constraint(greaterThanOrEqualTo: bubbleView.bottomAnchor, constant: -16 * headerSpacingConstant).isActive = true - } - - required init?(coder aDecoder: NSCoder) { - fatalError("init(coder:) should not be used.") - } -} - -// MARK: - Population -extension HIShiftCell { - static func heightForCell(with event: Event, width: CGFloat) -> CGFloat { - let heightFromEventName = HILabel.heightForView(text: event.name, font: HIAppearance.Font.eventTitle!, width: width - 137) - var heightConstant: CGFloat = 1.6 - if UIDevice.current.userInterfaceIdiom == .pad { - heightConstant = 11.0 - } - let height = heightFromEventName + 160 - if UIDevice.current.userInterfaceIdiom == .pad { - return height + (22 * (heightConstant / 1.45)) - } - return height + 5 - } - static func <- (lhs: HIShiftCell, rhs: Event) { - print(rhs) - var contentStackViewHeight: CGFloat = 0.0; var eventCellSpacing: CGFloat = 8.0 - var stackViewSpacing: CGFloat = 4.7; var bubbleConstant: CGFloat = 1.0 - var locationImageView = UIImageView(image: #imageLiteral(resourceName: "LocationSign")); var timeImageView = UIImageView(image: #imageLiteral(resourceName: "Clock")) - let titleLabel = HILabel(style: .event) - titleLabel.numberOfLines = 2; titleLabel.text = rhs.name - lhs.headerView.addArrangedSubview(titleLabel) - lhs.headerView.setCustomSpacing(9, after: titleLabel) - if UIDevice.current.userInterfaceIdiom == .pad { - eventCellSpacing = 12.0; stackViewSpacing = 15.0; bubbleConstant = 2.0 - locationImageView = UIImageView(image: #imageLiteral(resourceName: "VectorPad")) - timeImageView = UIImageView(image: #imageLiteral(resourceName: "TimePad")) - lhs.headerView.setCustomSpacing(18, after: titleLabel) - } - titleLabel.constrain(width: lhs.contentView.frame.width - 120, height: (HILabel.heightForView(text: rhs.name, font: HIAppearance.Font.eventTitle!, width: lhs.contentView.frame.width - 137)) * bubbleConstant) - let upperContainerView = HIView { - lhs.contentStackView.addArrangedSubview($0) - $0.translatesAutoresizingMaskIntoConstraints = false - } - let middleContainerView = HIView { - lhs.contentStackView.addArrangedSubview($0) - $0.translatesAutoresizingMaskIntoConstraints = false - } - let timeLabel = HILabel(style: .time) - // We can check for async events by checking if the event start and end time is 1970-01-01 00:00:00 +0000 - if rhs.startTime.timeIntervalSince1970 == 0 || rhs.endTime.timeIntervalSince1970 == 0 { - timeLabel.text = HIConstants.ASYNC_EVENT_TIME_TEXT - } else { - timeLabel.text = Formatter.simpleTime.string(from: rhs.startTime) + " - " + Formatter.simpleTime.string(from: rhs.endTime) - } - upperContainerView.addSubview(timeImageView) - upperContainerView.addSubview(timeLabel) - timeLabel.leadingAnchor.constraint(equalTo: timeImageView.trailingAnchor, constant: eventCellSpacing + 1).isActive = true - timeLabel.centerYAnchor.constraint(equalTo: timeImageView.centerYAnchor).isActive = true - let locationLabel = HILabel(style: .newLocation) - if rhs.locations.count > 0 { - locationLabel.text = rhs.locations.map({ ($0 as AnyObject).name }).joined(separator: ", ") - } - middleContainerView.addSubview(locationImageView) - locationImageView.translatesAutoresizingMaskIntoConstraints = false - middleContainerView.addSubview(locationLabel) - locationImageView.centerYAnchor.constraint(equalTo: timeImageView.centerYAnchor, constant: (stackViewSpacing * 2.5) + 14).isActive = true - locationImageView.centerXAnchor.constraint(equalTo: timeImageView.centerXAnchor).isActive = true - locationLabel.leadingAnchor.constraint(equalTo: timeLabel.leadingAnchor).isActive = true - locationLabel.centerYAnchor.constraint(equalTo: locationImageView.centerYAnchor).isActive = true - let descriptionLabel = HILabel(style: .cellDescription) - descriptionLabel.numberOfLines = 2 - descriptionLabel.text = "\(rhs.info)" - lhs.contentStackView.addArrangedSubview(descriptionLabel) - contentStackViewHeight += HILabel.heightForView(text: rhs.name, font: HIAppearance.Font.eventTitle!, width: lhs.contentView.frame.width - 98) - contentStackViewHeight += timeLabel.intrinsicContentSize.height + locationLabel.intrinsicContentSize.height + 13 + 40 + 3 + 40 - } -} - -// MARK: - UITableViewCell -extension HIShiftCell { - override func prepareForReuse() { - super.prepareForReuse() - headerView.subviews.forEach {(view) in - headerView.willRemoveSubview(view) - view.removeFromSuperview() - } - contentStackView.arrangedSubviews.forEach { (view) in - contentStackView.removeArrangedSubview(view) - view.removeFromSuperview() - } - } -} diff --git a/HackIllinois/ViewControllers/HIEventDetailViewController.swift b/HackIllinois/ViewControllers/HIEventDetailViewController.swift index eedb274f..4abfa303 100644 --- a/HackIllinois/ViewControllers/HIEventDetailViewController.swift +++ b/HackIllinois/ViewControllers/HIEventDetailViewController.swift @@ -241,7 +241,6 @@ extension HIEventDetailViewController { } func setupMap() { guard let event = event else { return } - print(event.mapImageUrl) // Check if the image URL ends with "svg" and replace it with "png" var imageUrlString = event.mapImageUrl diff --git a/HackIllinois/ViewControllers/HIPointsShopSwiftUIView.swift b/HackIllinois/ViewControllers/HIPointsShopSwiftUIView.swift index 16fae7bc..e7b81e8c 100644 --- a/HackIllinois/ViewControllers/HIPointsShopSwiftUIView.swift +++ b/HackIllinois/ViewControllers/HIPointsShopSwiftUIView.swift @@ -50,8 +50,7 @@ struct HIPointShopSwiftUIView: View { .resizable() .frame(width: isIpad ? 590 : 355, height:isIpad ? 185 : 105) .offset(y: -25) - //Spacer() - //.frame(height: 10) + VStack(spacing: 0) { CustomTopTabBar(tabIndex: $tabIndex) ScrollView(showsIndicators: false) { @@ -94,7 +93,6 @@ struct HIPointShopSwiftUIView: View { } } } - //} } func getItems() { HIAPI.ShopService.getAllItems() @@ -140,7 +138,6 @@ struct PointShopItemCell: View { Rectangle() .foregroundColor(.clear) .frame(width: UIScreen.main.bounds.width > 850 ? 800 : (isIpad ? 700 : 360), height: 10) - //.frame(width: isIpad ? 600 : 360, height: 10)//TODO: Change width .background(Color(red: 0.4, green: 0.17, blue: 0.07)) .cornerRadius(1) //transparent pane @@ -148,7 +145,6 @@ struct PointShopItemCell: View { Rectangle() .fill(.white) .frame(width: UIScreen.main.bounds.width > 850 ? 790 : (isIpad ? 690 : 350), height: 157) - //.frame(width: isIpad ? 590 : 350, height: 157)//TODO: Change width .opacity(0.4) HStack { Spacer() @@ -161,7 +157,7 @@ struct PointShopItemCell: View { .frame(width: 145, height: 145) Spacer() - //bubble-thing + //bubble view VStack { HStack{ Spacer() @@ -178,8 +174,6 @@ struct PointShopItemCell: View { .frame(maxWidth: .infinity) .padding(.trailing, 20) - /*Spacer() - .frame(width:20)*/ } HStack(alignment: .center, spacing: 7) { @@ -244,13 +238,11 @@ struct TabBarButton: View { Rectangle() .fill(Color(red: 0.85, green: 0.25, blue: 0.47)) .frame(width: UIScreen.main.bounds.width > 850 ? 350 : (isIpad ? 295 : 155), height: isIpad ? 90: 50) - //.frame(width: isIpad ? 250: 155, height: isIpad ? 90: 50)//190 .cornerRadius(10, corners: [.topLeft, .topRight]) }else{ Rectangle() .fill(Color(red: 0.85, green: 0.25, blue: 0.47)) .frame(width: UIScreen.main.bounds.width > 850 ? 350 : (isIpad ? 295 : 155), height: isIpad ? 90: 50) - //.frame(width: isIpad ? 250: 155, height: isIpad ? 90: 50)//190 .cornerRadius(10, corners: [.topLeft, .topRight]) .opacity(0) } diff --git a/HackIllinois/ViewControllers/HIProfileCardView.swift b/HackIllinois/ViewControllers/HIProfileCardView.swift index d02281c0..2380e229 100644 --- a/HackIllinois/ViewControllers/HIProfileCardView.swift +++ b/HackIllinois/ViewControllers/HIProfileCardView.swift @@ -90,7 +90,6 @@ struct HIProfileCardView: View { getRank { rank in self.rank = rank } - print(rank) } } }.padding(.bottom, isIpad ? 40*padFactor : 25*phoneFactor) @@ -199,7 +198,6 @@ struct HIProfileCardView: View { let (qr, _) = try result.get() DispatchQueue.main.async { self.qrInfo = qr.qrInfo - print("qrinfo with attendee jwt", qrInfo) } } catch { print("An error has occurred \(error)") @@ -218,7 +216,6 @@ struct HIProfileCardView: View { do { let (userRanking, _) = try result.get() rank = userRanking.ranking - print("rank:", rank) completion(rank) } catch { print("An error has occurred in ranking \(error)") diff --git a/HackIllinois/ViewControllers/HIProfileViewController.swift b/HackIllinois/ViewControllers/HIProfileViewController.swift index 525ecbaf..b4fa7c37 100644 --- a/HackIllinois/ViewControllers/HIProfileViewController.swift +++ b/HackIllinois/ViewControllers/HIProfileViewController.swift @@ -91,7 +91,6 @@ extension HIProfileViewController { // print("rank \(rank)") guard let user = HIApplicationStateController.shared.user else { return } var role = "General" - print(user.roles) if user.roles.contains(.PRO) { role = "Knight" }