Skip to content

Commit

Permalink
Quick UI Fixes (#579)
Browse files Browse the repository at this point in the history
* fixed staff shifts ui and made home button press easier

* add zoom in on map

* Added pan gesture to map view

* fixed points shop lag by preloading items

* make sure quantity of coins and items reloads

* fix mentorId not being passed in

* bump app version

* updated to quest complete
  • Loading branch information
s0phialiu authored Feb 20, 2024
1 parent caa19ac commit 737821d
Show file tree
Hide file tree
Showing 15 changed files with 371 additions and 57 deletions.
2 changes: 1 addition & 1 deletion HIAPI/Models/Item.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public struct ItemContainer: Decodable, APIReturnable {
}
}

public struct Item: Codable {
public struct Item: Codable, Hashable {
internal enum CodingKeys: String, CodingKey {
case name
case price
Expand Down
1 change: 1 addition & 0 deletions HIAPI/Models/Mentor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ import APIManager

public struct MentorAttendanceContainer: Codable, APIReturnable {
public let status: String?
public let points: Int?
}
2 changes: 1 addition & 1 deletion HIAPI/Services/MentorService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public final class MentorService: BaseService {
var headers = HTTPHeaders()
headers["Authorization"] = userToken
var body = HTTPBody()
body["mentorId"] = userToken
body["mentorId"] = mentorId
return APIRequest<MentorAttendanceContainer>(service: self, endpoint: "attendance/", body: body, headers: headers, method: .POST)
}

Expand Down
8 changes: 6 additions & 2 deletions HackIllinois.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@
D1BBA56A2B70ACCC0017BD13 /* StaffService.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1BBA5692B70ACCC0017BD13 /* StaffService.swift */; };
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, ); }; };
D1C268022B8470200001876B /* HIShiftDetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1C268012B8470200001876B /* HIShiftDetailViewController.swift */; };
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 */; };
Expand Down Expand Up @@ -367,6 +368,7 @@
D19D4C922B794F9100376E1B /* HIScanMentorViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HIScanMentorViewController.swift; sourceTree = "<group>"; };
D1BBA5672B70AB940017BD13 /* Staff.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Staff.swift; sourceTree = "<group>"; };
D1BBA5692B70ACCC0017BD13 /* StaffService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StaffService.swift; sourceTree = "<group>"; };
D1C268012B8470200001876B /* HIShiftDetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HIShiftDetailViewController.swift; sourceTree = "<group>"; };
D1C5B6572B732E44000E766D /* refresh.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = refresh.json; sourceTree = "<group>"; };
D1D335182B81DEF600BBB596 /* Notification.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Notification.swift; sourceTree = "<group>"; };
D1D3351A2B81DF0300BBB596 /* NotificationService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationService.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -611,6 +613,7 @@
95CCEA1E203D6B3600E3E28C /* HINavigationController.swift */,
2FF0F9312B58D5A200017D08 /* HIPointsShopSwiftUIView.swift */,
95C18DC820096539004784B5 /* HIScheduleViewController.swift */,
D1C268012B8470200001876B /* HIShiftDetailViewController.swift */,
98CA2A3D25C899CF003E842A /* HIProfileViewController.swift */,
2FF0F92F2B58D56700017D08 /* HIPointsShopViewController.swift */,
E170038929679D08009B99A8 /* HIProfileCardView.swift */,
Expand Down Expand Up @@ -1140,6 +1143,7 @@
AC5E9FE326195CCF00674FCF /* HIEventType.swift in Sources */,
AC3B621425E86053002386A2 /* Profile+CoreDataProperties.swift in Sources */,
9564E02F2218CE6F003A8EEB /* HIMapsDataSource.swift in Sources */,
D1C268022B8470200001876B /* HIShiftDetailViewController.swift in Sources */,
E1BF5E7A298B462F00A98390 /* HIStaffButtonView.swift in Sources */,
953199C91FC25CA0009F2AA1 /* HICoreDataController.swift in Sources */,
95A7D28D203D4F54005EAEAF /* Identifiable.swift in Sources */,
Expand Down Expand Up @@ -1371,7 +1375,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 2024.1.5;
MARKETING_VERSION = 2024.2.0;
ONLY_ACTIVE_ARCH = YES;
OTHER_SWIFT_FLAGS = "$(inherited) \"-D\" \"COCOAPODS\" -Xfrontend -warn-long-expression-type-checking=150";
PRODUCT_BUNDLE_IDENTIFIER = org.hackillinois.ios;
Expand Down Expand Up @@ -1403,7 +1407,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 2024.1.5;
MARKETING_VERSION = 2024.2.0;
ONLY_ACTIVE_ARCH = YES;
PRODUCT_BUNDLE_IDENTIFIER = org.hackillinois.ios;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down
2 changes: 2 additions & 0 deletions HackIllinois/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate, MessagingDelegate, UNUser
HIApplicationStateController.shared.initalize()
// Check the app version and prompt the user to update if needed
checkAppVersion()
// Preload point shop items
PointShopManager.shared.preloadItems()
application.registerForRemoteNotifications()
Messaging.messaging().delegate = self
UNUserNotificationCenter.current().delegate = self
Expand Down
6 changes: 3 additions & 3 deletions HackIllinois/UI/HIAppearance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,7 @@ struct HIAppearance: Equatable {
private static var statusBarBlack: UIStatusBarStyle {
if #available(iOS 13.0, *) {
return .lightContent
} else {
return .lightContent
}
} else { return .lightContent }
}

fileprivate static let day = HIAppearance(
Expand Down Expand Up @@ -401,6 +399,8 @@ struct HIAppearance: Equatable {

// Font for Staff QR code selection
static let QRSelection = UIFont(name: "MontserratRoman-Bold", size: 24)
static let smallEvent = UIFont(name: "MontserratRoman-SemiBold", size: 15)
static let smallEventPad = UIFont(name: "MontserratRoman-SemiBold", size: 30)
}
}

Expand Down
10 changes: 10 additions & 0 deletions HackIllinois/UI/HILabel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class HILabel: UILabel {
enum Style {
case location
case event
case smallEvent
case eventTime
case eventType
case sponsor
Expand Down Expand Up @@ -104,6 +105,15 @@ class HILabel: UILabel {
font = HIAppearance.Font.eventTitle
}

case .smallEvent:
textHIColor = \.baseText
backgroundHIColor = \.clear
if UIDevice.current.userInterfaceIdiom == .pad {
font = HIAppearance.Font.smallEventPad
} else {
font = HIAppearance.Font.smallEvent
}

case .eventTime:
textHIColor = \.baseText
backgroundHIColor = \.clear
Expand Down
6 changes: 3 additions & 3 deletions HackIllinois/ViewControllers/HICountdownViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ extension HICountdownViewController {
countdownStackView.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
countdownStackView.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
countdownStackView.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true
let daysContent = containerView(with: "DAYS", and: days)
let daysContent = containerView(with: daysRemaining == 1 ? "DAY" : "DAYS", and: days)
countdownStackView.addArrangedSubview(daysContent)
let hoursContent = containerView(with: "HOURS", and: hours)
let hoursContent = containerView(with: hoursRemaining == 1 ? "HOUR" : "HOURS", and: hours)
countdownStackView.addArrangedSubview(hoursContent)
let minutesContent = containerView(with: "MINUTES", and: minutes)
let minutesContent = containerView(with: minutesRemaining == 1 ? "MINUTE" : "MINUTES", and: minutes)
countdownStackView.addArrangedSubview(minutesContent)
var countdownSpacingConstant: CGFloat = 8
if UIDevice.current.userInterfaceIdiom == .pad {
Expand Down
100 changes: 90 additions & 10 deletions HackIllinois/ViewControllers/HIEventDetailViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import HIAPI
import APIManager
import GoogleMaps

class HIEventDetailViewController: HIBaseViewController {
class HIEventDetailViewController: HIBaseViewController, UIGestureRecognizerDelegate {
// MARK: - Properties
var event: Event?

Expand Down Expand Up @@ -72,8 +72,19 @@ class HIEventDetailViewController: HIBaseViewController {
$0.activeImage = #imageLiteral(resourceName: "MenuClose")
$0.baseImage = #imageLiteral(resourceName: "MenuClose")
}
private let mapContainer = HIView {
$0.layer.cornerRadius = 12
$0.layer.borderColor = #colorLiteral(red: 0.9254901961, green: 0.8235294118, blue: 0.8235294118, alpha: 1)
$0.layer.borderWidth = 4.0
$0.layer.masksToBounds = true
$0.layer.backgroundColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)
$0.translatesAutoresizingMaskIntoConstraints = false
$0.backgroundHIColor = \.white
}

private var mapView: UIImageView = UIImageView()
var isZooming = false
var originalImageCenter:CGPoint?

// MARK: Constraints
private var descriptionLabelHeight = NSLayoutConstraint()
Expand Down Expand Up @@ -260,24 +271,93 @@ extension HIEventDetailViewController {
DispatchQueue.main.async {
self.mapView.image = UIImage(data: data)
self.mapView.backgroundColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)
self.mapView.layer.borderColor = #colorLiteral(red: 0.9254901961, green: 0.8235294118, blue: 0.8235294118, alpha: 1)
self.mapView.layer.borderWidth = 4.0
}
}
}
task.resume()
}

eventDetailContainer.addSubview(mapView)
mapView.translatesAutoresizingMaskIntoConstraints = false
mapView.leadingAnchor.constraint(equalTo: eventDetailContainer.leadingAnchor).isActive = true
mapView.trailingAnchor.constraint(equalTo: eventDetailContainer.trailingAnchor).isActive = true
mapView.topAnchor.constraint(equalTo: locationImageView.bottomAnchor, constant: 15).isActive = true
eventDetailContainer.addSubview(mapContainer)
mapContainer.translatesAutoresizingMaskIntoConstraints = false
mapContainer.leadingAnchor.constraint(equalTo: eventDetailContainer.leadingAnchor).isActive = true
mapContainer.trailingAnchor.constraint(equalTo: eventDetailContainer.trailingAnchor).isActive = true
mapContainer.topAnchor.constraint(equalTo: locationImageView.bottomAnchor, constant: 15).isActive = true
let mapHeight: CGFloat = UIDevice.current.userInterfaceIdiom == .pad ? 450 : 250
mapView.constrain(height: mapHeight)
mapContainer.constrain(height: mapHeight)

mapContainer.addSubview(mapView)
mapView.translatesAutoresizingMaskIntoConstraints = false
mapView.leadingAnchor.constraint(equalTo: mapContainer.leadingAnchor).isActive = true
mapView.trailingAnchor.constraint(equalTo: mapContainer.trailingAnchor).isActive = true
mapView.topAnchor.constraint(equalTo: mapContainer.topAnchor).isActive = true
mapView.bottomAnchor.constraint(equalTo: mapContainer.bottomAnchor).isActive = true
mapView.layer.cornerRadius = 20
mapView.isUserInteractionEnabled = true

// Add pinch gesture recognizer
let pinchGesture = UIPinchGestureRecognizer(target: self, action: #selector(handlePinch(_:)))
mapView.addGestureRecognizer(pinchGesture)

// Add pan gesture recognizer
let pan = UIPanGestureRecognizer(target: self, action: #selector(self.pan(sender:)))
pan.delegate = self
self.mapView.addGestureRecognizer(pan)
}

@objc func pan(sender: UIPanGestureRecognizer) {
if self.isZooming && sender.state == .began {
self.originalImageCenter = sender.view?.center
} else if self.isZooming && sender.state == .changed {
let translation = sender.translation(in: self.mapView)
if let view = sender.view {
view.center = CGPoint(x: view.center.x + translation.x,
y: view.center.y + translation.y)
}
sender.setTranslation(CGPoint.zero, in: self.mapView.superview)
}
}

@objc func handlePinch(_ gesture: UIPinchGestureRecognizer) {
guard let view = gesture.view else {return}
self.originalImageCenter = gesture.view?.center
switch gesture.state {
case .began:
let currentScale = self.mapView.frame.size.width / self.mapView.bounds.size.width
let newScale = currentScale * gesture.scale
if newScale > 1 {
self.isZooming = true
}
case .changed:
let pinchCenter = CGPoint(x: gesture.location(in: view).x - view.bounds.midX,
y: gesture.location(in: view).y - view.bounds.midY)
let transform = view.transform.translatedBy(x: pinchCenter.x, y: pinchCenter.y)
.scaledBy(x: gesture.scale, y: gesture.scale)
.translatedBy(x: -pinchCenter.x, y: -pinchCenter.y)
let currentScale = self.mapView.frame.size.width / self.mapView.bounds.size.width
var newScale = currentScale*gesture.scale
if newScale < 1 {
newScale = 1
let transform = CGAffineTransform(scaleX: newScale, y: newScale)
self.mapView.transform = transform
gesture.scale = 1
} else {
view.transform = transform
gesture.scale = 1
}
case .ended:
guard let center = self.originalImageCenter else {return}
UIView.animate(withDuration: 0.3, animations: {
// Reset the transform to the original size
view.center = center
view.transform = .identity
view.layer.anchorPoint = CGPoint(x: 0.5, y: 0.5) // Reset anchor point to center
}, completion: { _ in
self.isZooming = false
})
default:
break
}
}

func setupCloseButton() {
view.addSubview(closeButton)
closeButton.addTarget(self, action: #selector(didSelectCloseButton(_:)), for: .touchUpInside)
Expand Down
7 changes: 4 additions & 3 deletions HackIllinois/ViewControllers/HIHomeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class HIHomeViewController: HIEventListViewController {
(HITimeDataSource.shared.eventTimes.checkInStart, "HACKILLINOIS BEGINS IN"),
(HITimeDataSource.shared.eventTimes.hackStart, "HACKING BEGINS IN"),
(HITimeDataSource.shared.eventTimes.hackEnd, "HACKING ENDS IN"),
(HITimeDataSource.shared.eventTimes.eventEnd, "HACKILLINOIS ENDS IN")
(HITimeDataSource.shared.eventTimes.eventEnd, "QUEST COMPLETE")
]

var transparentImageView: UIImageView!
Expand Down Expand Up @@ -87,6 +87,7 @@ extension HIHomeViewController {

func layoutLegendButton() {
view.addSubview(legendButton)
legendButton.isUserInteractionEnabled = true

let buttonSize: CGFloat = UIDevice.current.userInterfaceIdiom != .pad ? 30 : 50
let padding: CGFloat = UIDevice.current.userInterfaceIdiom != .pad ? 16 : 50
Expand All @@ -95,7 +96,7 @@ extension HIHomeViewController {
legendButton.translatesAutoresizingMaskIntoConstraints = false

// Increase the hit target area by adding padding
legendButton.topAnchor.constraint(equalTo: bannerFrameView.topAnchor, constant: -5).isActive = true
legendButton.topAnchor.constraint(equalTo: bannerFrameView.topAnchor, constant: (UIDevice.current.userInterfaceIdiom == .pad) ? 0 : -10).isActive = true
legendButton.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor, constant: -padding).isActive = true

legendButton.addTarget(self, action: #selector(didSelectLegendButton(_:)), for: .touchUpInside)
Expand Down Expand Up @@ -250,7 +251,7 @@ extension HIHomeViewController: HICountdownViewControllerDelegate {
} else {
// Displays after the event ends
// super.setCustomTitle(customTitle: "MEMORIES MADE")
bannerViewController.updateLabel(with: "MEMORIES MADE")
bannerViewController.updateLabel(with: "QUEST COMPLETE")
}
countdownDataStoreIndex += 1
}
Expand Down
37 changes: 29 additions & 8 deletions HackIllinois/ViewControllers/HIPointsShopSwiftUIView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,30 @@ import Foundation
import SwiftUI
import HIAPI

class PointShopManager {
static let shared = PointShopManager()

var items: [Item] = []

private init() {
// Private initializer to enforce singleton pattern
}

func preloadItems() {
// Fetch and populate items
HIAPI.ShopService.getAllItems()
.onCompletion { result in
do {
let (containedItem, _) = try result.get()
self.items = containedItem.items
} catch {
print("Failed to preload point shop items with the error: \(error)")
}
}
.launch()
}
}

struct HIPointShopSwiftUIView: View {
@State var items=[] as [Item]
@State private var profile = HIProfile()
Expand Down Expand Up @@ -56,10 +80,8 @@ struct HIPointShopSwiftUIView: View {
ScrollView(showsIndicators: false) {
if tabIndex == 0 {
VStack(spacing: 0) {
ForEach(0 ..< items.count, id: \.self) {value in
if (items[value].isRaffle==false) {
PointShopItemCell(item: items[value])
}
ForEach(PointShopManager.shared.items.filter { !$0.isRaffle }, id: \.self) { item in
PointShopItemCell(item: item)
}
Rectangle()
.foregroundColor(.clear)
Expand All @@ -69,15 +91,14 @@ struct HIPointShopSwiftUIView: View {
}
.onAppear {
getItems()
PointShopManager.shared.preloadItems()
getCoins{coins in
self.coins=coins}
}
} else {
VStack(spacing: 0) {
ForEach(0 ..< items.count, id: \.self) {value in
if (items[value].isRaffle==true) {
PointShopItemCell(item: items[value])
}
ForEach(PointShopManager.shared.items.filter { $0.isRaffle }, id: \.self) { item in
PointShopItemCell(item: item)
}
Rectangle()
.foregroundColor(.clear)
Expand Down
Loading

0 comments on commit 737821d

Please sign in to comment.