Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jiachenyee committed May 27, 2020
2 parents de33bd4 + 5177fec commit e620efb
Show file tree
Hide file tree
Showing 11 changed files with 93 additions and 36 deletions.
4 changes: 4 additions & 0 deletions Announcer/Announcement VC/AnnouncementSearchBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ extension AnnouncementsViewController: UISearchBarDelegate {
// When text changes, update search results with searchText
// Seach results automatically reloads when value changed
func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
// Handling when posts are missing because reloading
if posts == nil { return }

// It takes a bit to search so just run it in the background
DispatchQueue.global(qos: .background).async {
// Set color of labels
// Update labels/textview with data
Expand Down
19 changes: 15 additions & 4 deletions Announcer/Announcement VC/AnnouncementsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -168,17 +168,28 @@ class AnnouncementsViewController: UIViewController {
}

func addItemsToCoreSpotlight() {

/// So that it does not crash when `posts` gets forced unwrapped
if posts == nil {
return
}

/// `posts` converted to `CSSearchableItems`
let items: [CSSearchableItem] = posts.map({ post in
let attributeSet = CSSearchableItemAttributeSet(itemContentType: kUTTypeText as String)
attributeSet.title = post.title
attributeSet.contentDescription = post.content.condenseLinebreaks().htmlToString

return CSSearchableItem(uniqueIdentifier: "\(post.title)",
domainIdentifier: Bundle.main.bundleIdentifier!,
attributeSet: attributeSet)

let item = CSSearchableItem(uniqueIdentifier: "\(post.title)", domainIdentifier: Bundle.main.bundleIdentifier!, attributeSet: attributeSet)

item.expirationDate = Date.distantFuture

return item
})

// Index the items
CSSearchableIndex.default().indexSearchableItems(items) { error in
// Make sure there is no error indexing everything
if let error = error {
print("Indexing error: \(error.localizedDescription)")
} else {
Expand Down
8 changes: 4 additions & 4 deletions Announcer/Storyboards/Base.lproj/LaunchScreen.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
</connections>
</button>
</subviews>
<color key="backgroundColor" name="Background"/>
<color key="backgroundColor" name="background"/>
<constraints>
<constraint firstItem="D4Z-nc-8jB" firstAttribute="leading" secondItem="KG6-NR-CWo" secondAttribute="trailing" constant="20" id="AVU-0V-KN0"/>
<constraint firstItem="mcM-rT-ziF" firstAttribute="centerY" secondItem="la3-eh-nni" secondAttribute="centerY" id="Cdc-Zc-Y5Z"/>
Expand Down Expand Up @@ -89,11 +89,11 @@
<resources>
<image name="arrow.clockwise" catalog="system" width="115" height="128"/>
<image name="line.horizontal.3.decrease.circle.fill" catalog="system" width="128" height="121"/>
<namedColor name="Background">
<color red="0.96078431372549022" green="0.95686274509803926" blue="0.96470588235294119" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</namedColor>
<namedColor name="Global Tint">
<color red="0.66274509803921566" green="0.66274509803921566" blue="0.66274509803921566" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</namedColor>
<namedColor name="background">
<color red="0.96078431372549022" green="0.95686274509803926" blue="0.96470588235294119" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</namedColor>
</resources>
</document>
8 changes: 4 additions & 4 deletions Announcer/Storyboards/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
</searchBar>
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" keyboardDismissMode="onDrag" dataMode="prototypes" style="grouped" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="18" sectionFooterHeight="18" translatesAutoresizingMaskIntoConstraints="NO" id="Fjh-xs-KYN">
<rect key="frame" x="0.0" y="195.5" width="414" height="700.5"/>
<color key="backgroundColor" name="Background"/>
<color key="backgroundColor" name="background"/>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" reuseIdentifier="announcements" id="Lbq-1h-jZ4" customClass="AnnouncementTableViewCell" customModule="SST_Announcer" customModuleProvider="target">
<rect key="frame" x="0.0" y="55.5" width="414" height="91.5"/>
Expand Down Expand Up @@ -72,7 +72,7 @@
</constraints>
</imageView>
</subviews>
<color key="backgroundColor" name="Background"/>
<color key="backgroundColor" name="background"/>
<constraints>
<constraint firstItem="Ghj-WG-ybC" firstAttribute="top" secondItem="pa4-Xa-zA5" secondAttribute="bottom" constant="8" id="8Op-vH-qy1"/>
<constraint firstItem="Ghj-WG-ybC" firstAttribute="leading" secondItem="ny6-0q-uie" secondAttribute="leadingMargin" id="CW8-AT-kh7"/>
Expand Down Expand Up @@ -138,7 +138,7 @@
<rect key="frame" x="368.5" y="108" width="23.5" height="20"/>
</activityIndicatorView>
</subviews>
<color key="backgroundColor" name="Background"/>
<color key="backgroundColor" name="background"/>
<color key="tintColor" name="Grey 1"/>
<constraints>
<constraint firstItem="EzQ-w5-066" firstAttribute="leading" secondItem="Fdc-31-Cyo" secondAttribute="trailing" constant="20" id="6Ih-kc-aLi"/>
Expand Down Expand Up @@ -199,7 +199,7 @@
<image name="arrow.clockwise" catalog="system" width="115" height="128"/>
<image name="line.horizontal.3.decrease.circle.fill" catalog="system" width="128" height="121"/>
<image name="pin.fill" catalog="system" width="119" height="128"/>
<namedColor name="Background">
<namedColor name="background">
<color red="0.96078431372549022" green="0.95686274509803926" blue="0.96470588235294119" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</namedColor>
<namedColor name="Grey 1">
Expand Down
4 changes: 2 additions & 2 deletions Announcer/Storyboards/Content.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@
</connections>
</button>
</subviews>
<color key="backgroundColor" name="Background"/>
<color key="backgroundColor" name="background"/>
<color key="tintColor" name="Grey 1"/>
<constraints>
<constraint firstItem="rvY-1i-u3H" firstAttribute="bottom" secondItem="ZgU-FN-WM7" secondAttribute="bottom" constant="-16" id="6T1-we-frQ"/>
Expand Down Expand Up @@ -414,7 +414,7 @@
<image name="square.and.arrow.up" catalog="system" width="115" height="128"/>
<image name="tag.fill" catalog="system" width="128" height="116"/>
<image name="textformat.size" catalog="system" width="128" height="82"/>
<namedColor name="Background">
<namedColor name="background">
<color red="0.96078431372549022" green="0.95686274509803926" blue="0.96470588235294119" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</namedColor>
<namedColor name="Grey 1">
Expand Down
6 changes: 3 additions & 3 deletions Announcer/Storyboards/Filter.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="none" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" id="6lQ-wG-dRr">
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" name="Background"/>
<color key="backgroundColor" name="background"/>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" reuseIdentifier="labelCell" id="3ab-Oz-2nr" customClass="FilterTableViewCell" customModule="SST_Announcer" customModuleProvider="target">
<rect key="frame" x="0.0" y="28" width="414" height="74.5"/>
Expand Down Expand Up @@ -42,7 +42,7 @@
</constraints>
</view>
</subviews>
<color key="backgroundColor" name="Background"/>
<color key="backgroundColor" name="background"/>
<constraints>
<constraint firstItem="Mfa-Cg-r04" firstAttribute="bottom" secondItem="68J-Og-8DK" secondAttribute="bottomMargin" id="V0F-Qh-VC9"/>
<constraint firstItem="Mfa-Cg-r04" firstAttribute="top" secondItem="68J-Og-8DK" secondAttribute="topMargin" id="bjh-UV-mYT"/>
Expand Down Expand Up @@ -98,7 +98,7 @@
<color key="tintColor" name="Grey 1"/>
<resources>
<image name="arrow.uturn.left" catalog="system" width="128" height="112"/>
<namedColor name="Background">
<namedColor name="background">
<color red="0.96078431372549022" green="0.95686274509803926" blue="0.96470588235294119" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</namedColor>
<namedColor name="Grey 1">
Expand Down
31 changes: 25 additions & 6 deletions Announcer/Support Files/Delegates/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
center.requestAuthorization(options: options) {
(granted, error) in
if !granted {
// User did not give us notification access :(
print("Something went wrong")
print("noooo i demand notifications!!!!!")
}
Expand Down Expand Up @@ -66,12 +67,32 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
// Start background task
scheduleBackgroundTaskIfNeeded()

// Set project version
let versionNumber = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as! String
UserDefaults.standard.set(versionNumber, forKey: "versionNumber")

// Set project build
let buildNumber = Bundle.main.infoDictionary?["CFBundleVersion"] as! String
UserDefaults.standard.set(buildNumber, forKey: "buildNumber")

return true
}

// Testing if background task works
// Run this below in debugger
// e -l objc -- (void)[[BGTaskScheduler sharedScheduler] _simulateLaunchForTaskWithIdentifier:@"sg.edu.sst.panziyue.Announcer.new-announcement"]
/**
Schedules the new announcement background task
The identifier is `sg.edu.sst.panziyue.Announcer.new-announcement`
---
# Debugging Background Tasks
Running this line in the debugger to instantly manually background refresh. Background refresh takes a while so this is the easier way to do it and test it out.
[Developer Article](https://developer.apple.com/documentation/backgroundtasks/starting_and_terminating_tasks_during_development)
```
e -l objc -- (void)[[BGTaskScheduler sharedScheduler] _simulateLaunchForTaskWithIdentifier:@"sg.edu.sst.panziyue.Announcer.new-announcement"]
```
*/
func scheduleBackgroundTaskIfNeeded() {
let taskRequest = BGProcessingTaskRequest(identifier: AppDelegate.backgroundTaskIdentifier)
taskRequest.requiresNetworkConnectivity = true
Expand Down Expand Up @@ -131,9 +152,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
}

// Calls when user opens app from a notification
func userNotificationCenter(_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void) {
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {

openPost(with: response.notification)

Expand Down
5 changes: 2 additions & 3 deletions Announcer/Support Files/Globals.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ import SafariServices
- important: Ensure that the URL is set to the correct blog before production.
# Production Blog URL
http://studentsblog.sst.edu.sg
[http://studentsblog.sst.edu.sg](http://studentsblog.sst.edu.sg)
# Development Blog URL
https://testannouncer.blogspot.com
[https://testannouncer.blogspot.com](https://testannouncer.blogspot.com)
This constant stores the URL for the blog linked to the RSS feed.
*/
Expand Down Expand Up @@ -428,7 +428,6 @@ func launchPost(withTitle postTitle: String) {

if let post = post {
// Handles when post is found

announcementVC.receivePost(with: post)

} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,6 @@ SOFTWARE.</string>
<dict>
<key>Type</key>
<string>PSGroupSpecifier</string>
<key>Title</key>
<string>Generated by Cocoapods - https://cocoapods.org</string>
</dict>
</array>
</dict>
Expand Down
26 changes: 26 additions & 0 deletions Announcer/Support Files/Settings.bundle/Root.plist
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,32 @@
<string>Root</string>
<key>PreferenceSpecifiers</key>
<array>
<dict>
<key>Type</key>
<string>PSGroupSpecifier</string>
<key>Title</key>
<string>App Information</string>
</dict>
<dict>
<key>Type</key>
<string>PSTitleValueSpecifier</string>
<key>Title</key>
<string>Version</string>
<key>Key</key>
<string>versionNumber</string>
<key>DefaultValue</key>
<string>0</string>
</dict>
<dict>
<key>Type</key>
<string>PSTitleValueSpecifier</string>
<key>Title</key>
<string>Build</string>
<key>Key</key>
<string>buildNumber</string>
<key>DefaultValue</key>
<string>0</string>
</dict>
<dict>
<key>Type</key>
<string>PSChildPaneSpecifier</string>
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SST Announcer (iOS)
[![Language](http://img.shields.io/badge/swift-5-orange.svg?style=flat)](https://developer.apple.com/swift)
[![Xcode](http://img.shields.io/badge/xcode-11.4-red.svg?style=flat)](https://developer.apple.com/xcode)
[![Xcode](http://img.shields.io/badge/xcode-11.5-red.svg?style=flat)](https://developer.apple.com/xcode)
[![Cocoapods](http://img.shields.io/badge/pod-v1.8.4-darkgray.svg?style=flat)](https://cocoapods.org/)

[![iOS](http://img.shields.io/badge/platform-iOS%2013-blue.svg?style=flat)](https://developer.apple.com/iphone/index.action)
Expand Down Expand Up @@ -79,10 +79,10 @@ These colors are used for different parts of the app such as backgrounds and lab

|Color Name |Identifier|Light Theme|Dark Theme |
|-----------|----------|-----------|-----------|
|Background |`background`|![](https://via.placeholder.com/15/F5F4F6/F5F4F6) - #F5F4F6|![](https://via.placeholder.com/15/060400/060400) - #060400|
|Global Tint|`Global Tint`|![](https://via.placeholder.com/15/A9A9A9/A9A9A9) - #A9A9A9|![](https://via.placeholder.com/15/A9A9A9/A9A9A9) - #A9A9A9|
|Grey 1 |`Grey 1`|![](https://via.placeholder.com/15/434343/434343) - #434343|![](https://via.placeholder.com/15/B8BABB/B8BABB) - #B8BABB|
|Grey 2 |`Grey 2`|![](https://via.placeholder.com/15/DCDADB/DCDADB) - #DCDADB|![](https://via.placeholder.com/15/252628/252628) - #252628|
|Background |`"background"`|![](https://via.placeholder.com/15/F5F4F6/F5F4F6) - #F5F4F6|![](https://via.placeholder.com/15/060400/060400) - #060400|
|Global Tint|`"Global Tint"`|![](https://via.placeholder.com/15/A9A9A9/A9A9A9) - #A9A9A9|![](https://via.placeholder.com/15/A9A9A9/A9A9A9) - #A9A9A9|
|Grey 1 |`"Grey 1"`|![](https://via.placeholder.com/15/434343/434343) - #434343|![](https://via.placeholder.com/15/B8BABB/B8BABB) - #B8BABB|
|Grey 2 |`"Grey 2"`|![](https://via.placeholder.com/15/DCDADB/DCDADB) - #DCDADB|![](https://via.placeholder.com/15/252628/252628) - #252628|

### Apple Colors
These colors are the ones as part of Apple's [UIColor Human Interface Guidelines](https://developer.apple.com/design/human-interface-guidelines/ios/visual-design/color/)
Expand All @@ -97,6 +97,6 @@ These colors are used for loading content using KALoader

|Color Name |Identifier|Light Theme|Dark Theme |
|-----------|----------|-----------|-----------|
|First Load Color|`First Load Color`|![](https://via.placeholder.com/15/DEDEDE/DEDEDE) - #DEDEDE|![](https://via.placeholder.com/15/202020/202020) - #202020|
|Second Load Color|`Second Load Color`|![](https://via.placeholder.com/15/DDDDDD/DDDDDD) - #DDDDDD|![](https://via.placeholder.com/15/212121/212121) - #212121|
|Back Gray Color |`Back Gray Color`|![](https://via.placeholder.com/15/F6F6F6/F6F6F6) - #F6F6F6|![](https://via.placeholder.com/15/080808/080808) - #080808|
|First Load Color|`"First Load Color"`|![](https://via.placeholder.com/15/DEDEDE/DEDEDE) - #DEDEDE|![](https://via.placeholder.com/15/202020/202020) - #202020|
|Second Load Color|`"Second Load Color"`|![](https://via.placeholder.com/15/DDDDDD/DDDDDD) - #DDDDDD|![](https://via.placeholder.com/15/212121/212121) - #212121|
|Back Gray Color |`"Back Gray Color"`|![](https://via.placeholder.com/15/F6F6F6/F6F6F6) - #F6F6F6|![](https://via.placeholder.com/15/080808/080808) - #080808|

0 comments on commit e620efb

Please sign in to comment.