Skip to content

Commit

Permalink
Merge pull request #341 from HackIllinois/dev
Browse files Browse the repository at this point in the history
2020.2.1-rc1
  • Loading branch information
redsn0w422 authored Feb 25, 2020
2 parents 048f437 + 2404103 commit 9e66254
Show file tree
Hide file tree
Showing 17 changed files with 122 additions and 61 deletions.
7 changes: 3 additions & 4 deletions HIAPI/Models/Announcement.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,23 @@ public struct AnnouncementContainer: Decodable, APIReturnable {

public struct Announcement: Codable {
internal enum CodingKeys: String, CodingKey {
case topic
case title
case body
case time
case roles = "topicName"
}

public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
self.topic = try container.decode(String.self, forKey: .topic)
self.title = try container.decode(String.self, forKey: .title)
self.body = try container.decode(String.self, forKey: .body)
let time = try container.decode(Double.self, forKey: .time)
self.time = Date(timeIntervalSince1970: time)
let role = try container.decode(String.self, forKey: .roles)
self.roles = try Roles(string: role)
}

public let topic: String
public let title: String
public let body: String
public let time: Date
public let roles: Roles
}
2 changes: 1 addition & 1 deletion HIAPI/Services/AnnouncementService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ public final class AnnouncementService: BaseService {
}

public static func getAllAnnouncements() -> APIRequest<AnnouncementContainer> {
return APIRequest<AnnouncementContainer>(service: self, endpoint: "all/", method: .GET)
return APIRequest<AnnouncementContainer>(service: self, endpoint: "topic/all/", method: .GET)
}
}
24 changes: 12 additions & 12 deletions HackIllinois.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -932,12 +932,12 @@
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_IDENTITY = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 7;
CURRENT_PROJECT_VERSION = 3;
DEVELOPMENT_TEAM = 8VNQTQM2L6;
GCC_C_LANGUAGE_STANDARD = gnu11;
INFOPLIST_FILE = Stickers/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MARKETING_VERSION = 2020.2;
MARKETING_VERSION = 2020.2.1;
PRODUCT_BUNDLE_IDENTIFIER = org.hackillinois.ios.stickers;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
Expand All @@ -953,12 +953,12 @@
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_IDENTITY = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 7;
CURRENT_PROJECT_VERSION = 3;
DEVELOPMENT_TEAM = 8VNQTQM2L6;
GCC_C_LANGUAGE_STANDARD = gnu11;
INFOPLIST_FILE = Stickers/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MARKETING_VERSION = 2020.2;
MARKETING_VERSION = 2020.2.1;
PRODUCT_BUNDLE_IDENTIFIER = org.hackillinois.ios.stickers;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
Expand Down Expand Up @@ -1085,14 +1085,14 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = HackIllinois/HackIllinois.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer";
CURRENT_PROJECT_VERSION = 7;
CURRENT_PROJECT_VERSION = 3;
DEVELOPMENT_TEAM = 8VNQTQM2L6;
INFOPLIST_FILE = HackIllinois/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 2020.2;
MARKETING_VERSION = 2020.2.1;
OTHER_SWIFT_FLAGS = "$(inherited) \"-D\" \"COCOAPODS\" -Xfrontend -warn-long-expression-type-checking=150";
PRODUCT_BUNDLE_IDENTIFIER = org.hackillinois.ios;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -1108,14 +1108,14 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = HackIllinois/HackIllinois.entitlements;
CODE_SIGN_IDENTITY = "iPhone Developer";
CURRENT_PROJECT_VERSION = 7;
CURRENT_PROJECT_VERSION = 3;
DEVELOPMENT_TEAM = 8VNQTQM2L6;
INFOPLIST_FILE = HackIllinois/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 2020.2;
MARKETING_VERSION = 2020.2.1;
PRODUCT_BUNDLE_IDENTIFIER = org.hackillinois.ios;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
Expand All @@ -1132,7 +1132,7 @@
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_IDENTITY = "";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 7;
CURRENT_PROJECT_VERSION = 3;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = 8VNQTQM2L6;
DYLIB_COMPATIBILITY_VERSION = 1;
Expand All @@ -1146,7 +1146,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 2020.2;
MARKETING_VERSION = 2020.2.1;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = org.hackillinois.HIAPI;
Expand All @@ -1169,7 +1169,7 @@
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_IDENTITY = "";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 7;
CURRENT_PROJECT_VERSION = 3;
DEFINES_MODULE = YES;
DEVELOPMENT_TEAM = 8VNQTQM2L6;
DYLIB_COMPATIBILITY_VERSION = 1;
Expand All @@ -1183,7 +1183,7 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 2020.2;
MARKETING_VERSION = 2020.2.1;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = org.hackillinois.HIAPI;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions HackIllinois/Assets.xcassets/Bell.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "Bell@1x.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "Bell@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "Bell@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
},
"properties" : {
"template-rendering-intent" : "template"
}
}
19 changes: 9 additions & 10 deletions HackIllinois/DataSources/HIAnnouncementDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,18 @@ final class HIAnnouncementDataSource {
coreDataAnnouncementsToUpdate.forEach { (coreDataAnnouncement, apiAnnouncement) in
// Update CoreData Announcement.
coreDataAnnouncement.title = apiAnnouncement.title
coreDataAnnouncement.info = apiAnnouncement.body
coreDataAnnouncement.body = apiAnnouncement.body
coreDataAnnouncement.time = apiAnnouncement.time
coreDataAnnouncement.roles = Int32(apiAnnouncement.roles.rawValue)
coreDataAnnouncement.topic = apiAnnouncement.topic
}

apiAnnouncementsToInsert.forEach { apiAnnouncement in
// Create CoreData announcement.
let coreDataAnnouncement = Announcement(context: context)
coreDataAnnouncement.time = apiAnnouncement.time
coreDataAnnouncement.info = apiAnnouncement.body
coreDataAnnouncement.title = apiAnnouncement.title
coreDataAnnouncement.roles = Int32(apiAnnouncement.roles.rawValue)
coreDataAnnouncement.body = apiAnnouncement.body
coreDataAnnouncement.time = apiAnnouncement.time
coreDataAnnouncement.topic = apiAnnouncement.topic
}

// 10) Save changes, call completion handler, unlock refresh
Expand Down Expand Up @@ -104,9 +104,8 @@ final class HIAnnouncementDataSource {
let title = data["title"] as? String,
let body = data["body"] as? String,
let seconds = data["time"] as? TimeInterval,
let topicName = data["topicName"] as? String,
let roles = try? HIAPI.Roles(string: topicName) else { return }
let time = Date(timeIntervalSince1970: seconds)
let topic = data["topic"] as? String else { return }
let time = Date(timeIntervalSince1970: seconds)

HICoreDataController.shared.performBackgroundTask { context -> Void in
do {
Expand All @@ -118,9 +117,9 @@ final class HIAnnouncementDataSource {
// 2) Update the announcement if it exists, otherwise create it.
let coreDataAnnouncement = coreDataAnnouncements.first ?? Announcement(context: context)
coreDataAnnouncement.title = title
coreDataAnnouncement.info = body
coreDataAnnouncement.body = body
coreDataAnnouncement.time = time
coreDataAnnouncement.roles = Int32(roles.rawValue)
coreDataAnnouncement.topic = topic

// 3) Save changes, call completion handler.
try context.save()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ extension Announcement {
return NSFetchRequest<Announcement>(entityName: "Announcement")
}

@NSManaged public var info: String
@NSManaged public var topic: String
@NSManaged public var body: String
@NSManaged public var time: Date
@NSManaged public var title: String
@NSManaged public var roles: Int32

}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="15702" systemVersion="19C57" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="15702" systemVersion="19D76" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
<entity name="Announcement" representedClassName="Announcement" syncable="YES">
<attribute name="info" attributeType="String"/>
<attribute name="roles" optional="YES" attributeType="Integer 32" defaultValueString="0" usesScalarValueType="YES"/>
<attribute name="body" attributeType="String"/>
<attribute name="time" attributeType="Date" usesScalarValueType="NO"/>
<attribute name="title" attributeType="String"/>
<attribute name="topic" optional="YES" attributeType="String"/>
<uniquenessConstraints>
<uniquenessConstraint>
<constraint value="time"/>
Expand Down Expand Up @@ -55,7 +55,7 @@
</uniquenessConstraints>
</entity>
<elements>
<element name="Announcement" positionX="-63" positionY="72" width="128" height="105"/>
<element name="Announcement" positionX="-63" positionY="72" width="128" height="103"/>
<element name="Event" positionX="-54" positionY="36" width="128" height="178"/>
<element name="Location" positionX="-54" positionY="108" width="128" height="103"/>
<element name="Project" positionX="-45" positionY="108" width="128" height="163"/>
Expand Down
6 changes: 6 additions & 0 deletions HackIllinois/UI/HIButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,9 @@ class HIButton: UIButton {
}
}
}

extension HIButton {
func toBarButtonItem() -> UIBarButtonItem? {
return UIBarButtonItem(customView: self)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class HIAnnouncementCell: HIBubbleCell {
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)

backgroundColor = UIColor.clear
contentView.layer.backgroundColor = UIColor.clear.cgColor
bubbleView.addSubview(titleLabel)
titleLabel.topAnchor.constraint(equalTo: bubbleView.topAnchor, constant: 10).isActive = true
titleLabel.leadingAnchor.constraint(equalTo: bubbleView.leadingAnchor, constant: 23).isActive = true
Expand Down Expand Up @@ -54,7 +56,7 @@ extension HIAnnouncementCell {
static func <- (lhs: HIAnnouncementCell, rhs: Announcement) {
lhs.titleLabel.text = rhs.title
lhs.timeLabel.text = Date.humanReadableTimeSince(rhs.time)
lhs.infoLabel.text = rhs.info
lhs.infoLabel.text = rhs.body
}
}

Expand Down
48 changes: 30 additions & 18 deletions HackIllinois/ViewControllers/HIAnnouncementsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,40 @@ class HIAnnouncementsViewController: HIBaseViewController {
}()

var adminAnnouncementViewController = HIAdminAnnouncementViewController()
private let closeButton = HIButton {
$0.tintHIColor = \.baseText
$0.backgroundHIColor = \.clear
$0.activeImage = #imageLiteral(resourceName: "MenuClose")
$0.baseImage = #imageLiteral(resourceName: "MenuClose")
}
private let titleLabel = HILabel(style: .detailTitle) {
$0.translatesAutoresizingMaskIntoConstraints = false
$0.textColor <- \.baseText
$0.font = HIAppearance.Font.detailTitle
}
}

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

view.addSubview(closeButton)
closeButton.addTarget(self, action: #selector(didSelectCloseButton(_:)), for: .touchUpInside)
closeButton.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 15).isActive = true
closeButton.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor, constant: 15).isActive = true
closeButton.constrain(height: 20)

view.addSubview(titleLabel)
titleLabel.leadingAnchor.constraint(equalTo: closeButton.leadingAnchor).isActive = true
titleLabel.topAnchor.constraint(equalTo: closeButton.topAnchor, constant: 35).isActive = true

let tableView = HITableView()
view.addSubview(tableView)
tableView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor).isActive = true
tableView.topAnchor.constraint(equalTo: titleLabel.bottomAnchor, constant: 15).isActive = true
tableView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor).isActive = true
tableView.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
tableView.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor).isActive = true
tableView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor, constant: -6).isActive = true
tableView.estimatedRowHeight = 100
tableView.rowHeight = UITableView.automaticDimension
self.tableView = tableView
Expand All @@ -67,22 +88,16 @@ extension HIAnnouncementsViewController {

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
titleLabel.text = "ANNOUNCEMENTS"
HIAnnouncementDataSource.refresh()

NotificationCenter.default.addObserver(self, selector: #selector(viewWillEnterForeground), name: UIApplication.willEnterForegroundNotification, object: nil)

var rightNavigationItem: UIBarButtonItem?
if HIApplicationStateController.shared.user?.roles.contains(.admin) == true {
rightNavigationItem = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(presentAdminAnnouncementViewController))
}
navigationItem.rightBarButtonItem = rightNavigationItem
}

override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
NotificationCenter.default.removeObserver(self)
}

@objc func viewWillEnterForeground() {
try? fetchedResultsController.performFetch()
HIAnnouncementDataSource.refresh()
Expand All @@ -95,10 +110,15 @@ extension HIAnnouncementsViewController {
navigationController?.pushViewController(adminAnnouncementViewController, animated: true)
}

@objc func didSelectCloseButton(_ sender: HIButton) {
self.dismiss(animated: true, completion: nil)
}

func currentPredicate() -> NSPredicate {
let roles = HIApplicationStateController.shared.user?.roles ?? .null
return NSPredicate(format: "(\(roles.rawValue) & roles) > 0")
return NSPredicate(format: "(\(roles.rawValue)) > 0")
}

}

// MARK: - UITableView Setup
Expand All @@ -109,14 +129,6 @@ extension HIAnnouncementsViewController {
}
}

// MARK: - UINavigationItem Setup
extension HIAnnouncementsViewController {
@objc dynamic override func setupNavigationItem() {
super.setupNavigationItem()
title = "ANNOUNCEMENTS"
}
}

// MARK: - UITableViewDataSource
extension HIAnnouncementsViewController {
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
Expand Down
8 changes: 8 additions & 0 deletions HackIllinois/ViewControllers/HIBaseViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,14 @@ extension HIBaseViewController: NSFetchedResultsControllerDelegate {
case .delete:
guard let deleteIndexPath = indexPath else { return }
tableView?.deleteRows(at: [deleteIndexPath], with: .fade)
if let tableView = tableView {
DispatchQueue.main.async {
UIView.setAnimationsEnabled(false)
UIView.animate(withDuration: 0.0, animations: tableView.reloadData) { _ in
UIView.setAnimationsEnabled(true)
}
}
}
case .update:
guard let updateIndexPath = indexPath else { return }
tableView?.reloadRows(at: [updateIndexPath], with: .fade)
Expand Down
Loading

0 comments on commit 9e66254

Please sign in to comment.