Skip to content

Commit

Permalink
Merge pull request #91 from HackIllinois/dev
Browse files Browse the repository at this point in the history
HI 2018 App v1.0.4 build(1)
  • Loading branch information
rauhul authored Feb 20, 2018
2 parents 49e2737 + 619410d commit 02a1c33
Show file tree
Hide file tree
Showing 6 changed files with 238 additions and 7 deletions.
4 changes: 4 additions & 0 deletions HackIllinois.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
0A360882203539FF001F5F85 /* HIAdminEventViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A360881203539FF001F5F85 /* HIAdminEventViewController.swift */; };
35240BD1201408DB00E0C0D8 /* HICountdownViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 35240BD0201408DB00E0C0D8 /* HICountdownViewController.swift */; };
356B219D202A5786007113D6 /* countdown-24.json in Resources */ = {isa = PBXBuildFile; fileRef = 356B219B202A5786007113D6 /* countdown-24.json */; };
356B219E202A5786007113D6 /* countdown-60.json in Resources */ = {isa = PBXBuildFile; fileRef = 356B219C202A5786007113D6 /* countdown-60.json */; };
Expand Down Expand Up @@ -100,6 +101,7 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
0A360881203539FF001F5F85 /* HIAdminEventViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HIAdminEventViewController.swift; sourceTree = "<group>"; };
35240BD0201408DB00E0C0D8 /* HICountdownViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HICountdownViewController.swift; sourceTree = "<group>"; };
356B219B202A5786007113D6 /* countdown-24.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "countdown-24.json"; sourceTree = "<group>"; };
356B219C202A5786007113D6 /* countdown-60.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "countdown-60.json"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -373,6 +375,7 @@
957DB2E41FC2435100F8C45E /* ViewControllers */ = {
isa = PBXGroup;
children = (
0A360881203539FF001F5F85 /* HIAdminEventViewController.swift */,
958C863A2033C94800803F81 /* HIAdminAnnouncementViewController.swift */,
956F41E01FC7577500557DC7 /* HIAnnouncementsViewController.swift */,
95C3BE2F2008B99C0008ED79 /* HIBaseViewController.swift */,
Expand Down Expand Up @@ -666,6 +669,7 @@
9510F6A31FCB7D6E007D19DB /* Location+CoreDataClass.swift in Sources */,
9510F6A01FCB7D6E007D19DB /* Announcement+CoreDataClass.swift in Sources */,
95DE24DC1FC3ADBE000F599D /* HIAnnouncementService.swift in Sources */,
0A360882203539FF001F5F85 /* HIAdminEventViewController.swift in Sources */,
9521A6AC201917B6009059C6 /* HIAPIAnnouncement.swift in Sources */,
95F0AE91201B087F005968BC /* HIEventDetailLocationCell.swift in Sources */,
95DC43EA202A38EB007E9B1A /* HIEmptyTableBackgroundView.swift in Sources */,
Expand Down
7 changes: 7 additions & 0 deletions HackIllinois/APIService/HITrackingService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,11 @@ final class HITrackingService: HIBaseService {
return APIRequest<HIAPISuccessContainer>(service: self, endpoint: "/\(id)", method: .GET)
}

static func create(name: String, duration: Int) -> APIRequest<HIAPISuccessContainer> {
var eventDict = [String: Any]()
eventDict["name"] = name
eventDict["duration"] = duration * 60 // user inputs minutes but API wants seconds
return APIRequest<HIAPISuccessContainer>(service: self, endpoint: "", body: eventDict, method: .POST)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
//
// HIAdminEventViewController.swift
// HackIllinois
//
// Created by Kevin Rajan on 2/14/18.
// Copyright © 2018 HackIllinois. All rights reserved.
//

import Foundation
import UIKit
import CoreData

enum HIAdminEventViewControllerStyle {
case currentlyCreatingEvent
case readyToCreateEvent
}

class HIAdminEventViewController: HIBaseViewController {
// MARK: - Properties
var activityIndicator = UIActivityIndicatorView()
var titleTextField = UITextField()
var durationTextField = UITextField()
var createEventButton = UIButton()
}

// MARK: - Actions
extension HIAdminEventViewController {
@objc func didSelectCreateEvent(_ sender: UIButton) {
guard let title = titleTextField.text,
let durationText = durationTextField.text,
title != "", durationText != "",
let duration = Int(durationText)
else { return }

let message = "Create a new tracked event \"\(title)\" for \(duration) minutes?"
let confirmAlertController = UIAlertController(title: "Confirm Tracked Event", message: message, preferredStyle: .alert)
confirmAlertController.addAction(
UIAlertAction(title: "Yes", style: .default) { _ in
self.stylizeFor(.currentlyCreatingEvent)
HITrackingService.create(name: title, duration: duration)
.onCompletion { result in
let alertTitle: String
var alertMessage: String?
var shouldExitOnCompletion = false

switch result {
case .success(let successContainer):

if let error = successContainer.error {
alertTitle = error.title
alertMessage = error.message
} else {
alertTitle = "Tracked Event Created"
shouldExitOnCompletion = true
}

case .cancellation:
alertTitle = "Cancelled"

case .failure(let error):
alertTitle = "Error"
alertMessage = error.localizedDescription
}
let alert = UIAlertController(title: alertTitle, message: alertMessage, preferredStyle: .alert)
alert.addAction(
UIAlertAction(title: "OK", style: .default) { [weak self] _ in
if shouldExitOnCompletion {
self?.navigationController?.popViewController(animated: true)
}
}
)
DispatchQueue.main.async { [weak self] in
self?.stylizeFor(.readyToCreateEvent)
self?.titleTextField.text = ""
self?.durationTextField.text = ""
self?.present(alert, animated: true, completion: nil)
}
}
.authorization(HIApplicationStateController.shared.user)
.perform()
}
)
confirmAlertController.addAction(UIAlertAction(title: "No", style: .cancel, handler: nil))
self.present(confirmAlertController, animated: true, completion: nil)
}
}

// MARK: - UIViewController
extension HIAdminEventViewController {
override func loadView() {
super.loadView()

// Title TextField
titleTextField.placeholder = "TITLE"
titleTextField.textColor = HIApplication.Color.darkIndigo
titleTextField.font = UIFont.systemFont(ofSize: 13, weight: .medium)
titleTextField.tintColor = HIApplication.Color.hotPink
titleTextField.autocapitalizationType = .sentences
titleTextField.autocorrectionType = .yes
titleTextField.delegate = self
titleTextField.enablesReturnKeyAutomatically = true
titleTextField.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(titleTextField)
titleTextField.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 24).isActive = true
titleTextField.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor, constant: 30).isActive = true
titleTextField.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor, constant: -30).isActive = true
titleTextField.heightAnchor.constraint(equalToConstant: 44).isActive = true

// Seperator View
let separatorView = UILabel()
separatorView.backgroundColor = HIApplication.Color.hotPink
separatorView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(separatorView)
separatorView.topAnchor.constraint(equalTo: titleTextField.bottomAnchor).isActive = true
separatorView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor, constant: 30).isActive = true
separatorView.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor, constant: -30).isActive = true
separatorView.heightAnchor.constraint(equalToConstant: 1).isActive = true

// Description TextField
durationTextField.placeholder = "DURATION (MINUTES)"
durationTextField.textColor = HIApplication.Color.darkIndigo
durationTextField.font = UIFont.systemFont(ofSize: 13, weight: .medium)
durationTextField.tintColor = HIApplication.Color.hotPink
durationTextField.backgroundColor = UIColor.clear
durationTextField.keyboardType = .numberPad
durationTextField.autocorrectionType = .yes
durationTextField.delegate = self
durationTextField.enablesReturnKeyAutomatically = true
durationTextField.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(durationTextField)
durationTextField.topAnchor.constraint(equalTo: separatorView.bottomAnchor, constant: 0).isActive = true
durationTextField.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 30).isActive = true
durationTextField.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -30).isActive = true
durationTextField.heightAnchor.constraint(equalToConstant: 44).isActive = true

// Create Event Button
createEventButton.backgroundColor = HIApplication.Color.lightPeriwinkle
createEventButton.layer.cornerRadius = 8
createEventButton.setTitle("Create Tracked Event", for: .normal)
createEventButton.setTitleColor(HIApplication.Color.darkIndigo, for: .normal)
createEventButton.titleLabel?.font = UIFont.systemFont(ofSize: 15)
createEventButton.addTarget(self, action: #selector(didSelectCreateEvent(_:)), for: .touchUpInside)
createEventButton.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(createEventButton)
createEventButton.topAnchor.constraint(equalTo: durationTextField.bottomAnchor, constant: 44).isActive = true
createEventButton.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor, constant: 12).isActive = true
createEventButton.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor, constant: -12).isActive = true
createEventButton.heightAnchor.constraint(equalToConstant: 50).isActive = true

// Activity Indicator
activityIndicator.tintColor = HIApplication.Color.hotPink
activityIndicator.stopAnimating()
activityIndicator.hidesWhenStopped = true
activityIndicator.translatesAutoresizingMaskIntoConstraints = false
createEventButton.addSubview(activityIndicator)
activityIndicator.centerXAnchor.constraint(equalTo: createEventButton.centerXAnchor).isActive = true
activityIndicator.centerYAnchor.constraint(equalTo: createEventButton.centerYAnchor).isActive = true
}
}

// MARK: - Responder Chain
extension HIAdminEventViewController {
override func nextReponder(current: UIResponder) -> UIResponder? {
switch current {
case titleTextField:
return durationTextField
case durationTextField:
return nil
default:
return nil
}
}
override func actionForFinalResponder() {
didSelectCreateEvent(createEventButton)
}
}

// MARK: - UINavigationItem Setup
extension HIAdminEventViewController {
@objc dynamic override func setupNavigationItem() {
super.setupNavigationItem()
title = "CREATE TRACKED EVENT"
}
}

// MARK: - Styling
extension HIAdminEventViewController {
func stylizeFor(_ style: HIAdminEventViewControllerStyle) {
switch style {
case .currentlyCreatingEvent:
createEventButton.isEnabled = false
createEventButton.setTitle(nil, for: .normal)
createEventButton.backgroundColor = UIColor.gray
activityIndicator.startAnimating()

case .readyToCreateEvent:
createEventButton.isEnabled = true
createEventButton.setTitle("Create Tracked Event", for: .normal)
createEventButton.backgroundColor = HIApplication.Color.lightPeriwinkle
activityIndicator.stopAnimating()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class HIScannerViewController: HIBaseViewController {
var respondingToQRCodeFound = true

var lookingUpUserAlertController: UIAlertController?
var adminEventViewController = HIAdminEventViewController()
}

// MARK: - UIViewController
Expand All @@ -44,6 +45,15 @@ extension HIScannerViewController {
}
}
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
var rightNavigationItem: UIBarButtonItem?
if HIApplicationStateController.shared.user?.permissions == .admin {
rightNavigationItem = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(presentAdminEventViewController))
}
navigationItem.rightBarButtonItem = rightNavigationItem
}

override func viewDidDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
Expand All @@ -59,6 +69,13 @@ extension HIScannerViewController {
}
}

// MARK: - Actions
extension HIScannerViewController {
@objc func presentAdminEventViewController() {
navigationController?.pushViewController(adminEventViewController, animated: true)
}
}

// MARK: - UINavigationItem Setup
extension HIScannerViewController {
@objc dynamic override func setupNavigationItem() {
Expand Down
8 changes: 4 additions & 4 deletions HackIllinois/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>ITSAppUsesNonExemptEncryption</key>
<false/>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
Expand All @@ -17,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0.3</string>
<string>1.0.4</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
Expand All @@ -32,7 +30,9 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>2</string>
<string>1</string>
<key>ITSAppUsesNonExemptEncryption</key>
<false/>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSCameraUsageDescription</key>
Expand Down
6 changes: 3 additions & 3 deletions Stickers/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleDisplayName</key>
<string>Hackillinois</string>
<string>HackIllinois</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
Expand All @@ -17,9 +17,9 @@
<key>CFBundlePackageType</key>
<string>XPC!</string>
<key>CFBundleShortVersionString</key>
<string>1.0.3</string>
<string>1.0.4</string>
<key>CFBundleVersion</key>
<string>2</string>
<string>1</string>
<key>NSExtension</key>
<dict>
<key>NSExtensionPointIdentifier</key>
Expand Down

0 comments on commit 02a1c33

Please sign in to comment.