Skip to content

Commit

Permalink
Initial Release
Browse files Browse the repository at this point in the history
  • Loading branch information
Wes Williams committed Jun 1, 2015
0 parents commit 254ffb7
Show file tree
Hide file tree
Showing 65 changed files with 6,569 additions and 0 deletions.
18 changes: 18 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Xcode
#
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
*.xccheckout
*.moved-aside
DerivedData
*.hmap
*.ipa
*.xcuserstate
25 changes: 25 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
LICENSE
=======

LEARNINGSTUDIO SAMPLE APPLICATION - Mobile Dashboard for iOS
--------------------------------------

Copyright (c) 2015 Pearson Education, Inc.
Created by Pearson Developer Services

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Portions of this work are reproduced from work created and
shared by Apple and used according to the terms described in
the License. Apple is not otherwise affiliated with the
development of this work.
502 changes: 502 additions & 0 deletions LSDashboard.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

202 changes: 202 additions & 0 deletions LSDashboard/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
/*
* LearningStudio Mobile Dashboard for iOS
*
* Need Help or Have Questions?
* Please use the PDN Developer Community at https://community.pdn.pearson.com
*
* @category LearningStudio Sample Application - Mobile
* @author Wes Williams <[email protected]>
* @author Pearson Developer Services Team <[email protected]>
* @copyright 2015 Pearson Education, Inc.
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache 2.0
* @version 1.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Portions of this work are reproduced from work created and
* shared by Apple and used according to the terms described in
* the License. Apple is not otherwise affiliated with the
* development of this work.
*/

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?


func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.


// We need permission to update the icon's badge
application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: UIUserNotificationType.Badge, categories: nil))

// Let background fetch fire as often as it can. We'll throttlle the API usage during the call
UIApplication.sharedApplication().setMinimumBackgroundFetchInterval(UIApplicationBackgroundFetchIntervalMinimum)

return true
}

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.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

func applicationDidEnterBackground(application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

func applicationWillEnterForeground(application: UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

func applicationDidBecomeActive(application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.

var badgeNumber = UIApplication.sharedApplication().applicationIconBadgeNumber
if badgeNumber > 0 {
if LearningStudio.api.restoreCredentials() {
LearningStudio.api.getMe({ (error) -> Void in
if error == nil {
dispatch_async(dispatch_get_main_queue()) {
LearningStudio.api.proceedWithRefresh()
}
}
})
}
UIApplication.sharedApplication().applicationIconBadgeNumber = 0
}
}

func applicationWillTerminate(application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.


// called by simulator despite comment in applicationDidEnterBackground
LearningStudio.api.removeUserDataArchive()
}



func application(application: UIApplication,
performFetchWithCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {

// going to check for new activity if login is possible
if LearningStudio.api.restoreCredentials() {
// going to make 3 calls, and will respond when all have completed
// Should have plenty of time, so no need to ask for extra time
let dataParts = 3 // happenings, events, announcements
var partsSearched = 0
var partsFound = 0

// last time we checked is stored as a user default
// this is set during first login and everytime data is refreshed
var lastActivityTime = NSUserDefaults.standardUserDefaults().objectForKey(LearningStudio.api.defaultLastActivityTimeKey) as? String

// this current time will replace the lastActivityTime if this succeeds
var dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = LearningStudio.api.normalDateFormat
dateFormatter.timeZone = NSTimeZone(name: LearningStudio.api.defaultTimeZone)
var now = NSDate()
let thisActivityTime = dateFormatter.stringFromDate(now)

// just exit if lastActivityDate is missing or not as expected
if lastActivityTime == nil || dateFormatter.dateFromString(lastActivityTime!) == nil {
NSUserDefaults.standardUserDefaults().setValue(thisActivityTime, forKey: LearningStudio.api.defaultLastActivityTimeKey)
completionHandler(UIBackgroundFetchResult.NoData)
return
}

// There's no need to check more than once an hour.
// Otherwise, background fetch might be unnecessarily querying
var hourAgoTime = dateFormatter.stringFromDate(now.dateByAddingTimeInterval(-1 * 60 * 60))
if hourAgoTime.compare(lastActivityTime!) == NSComparisonResult.OrderedAscending {
completionHandler(UIBackgroundFetchResult.NoData)
return
}

// can't respond until all are done...
// and doing them in parallel should be faster than chaining them
// this is the logic for the time when all of them are complete
var whenDone = { () -> Void in
NSUserDefaults.standardUserDefaults().setValue(thisActivityTime, forKey: LearningStudio.api.defaultLastActivityTimeKey)
if partsFound > 0 {
UIApplication.sharedApplication().applicationIconBadgeNumber += partsFound
completionHandler(UIBackgroundFetchResult.NewData)
}
else {
completionHandler(UIBackgroundFetchResult.NoData)
}
}

// what's been done
LearningStudio.api.getHappeningsSince(lastActivityTime!, callback: { (data, error) -> Void in

if data != nil {
var happenings = data as! [AnyObject]

if happenings.count > 0 {
partsFound += happenings.count
}
}

// check if this is the last one
if ++partsSearched == dataParts {
whenDone()
}
})
// what's coming due
LearningStudio.api.getEventsSince(lastActivityTime!, callback: { (data, error) -> Void in

if data != nil {
var activities = data as! [AnyObject]

if activities.count > 0 {
partsFound += activities.count
}
}

// check if this is the last one
if ++partsSearched == dataParts {
whenDone()
}
})
// what's been announced
LearningStudio.api.getAnnouncementsSince(lastActivityTime!, callback: { (data, error) -> Void in

if data != nil {
var announcements = data as! [AnyObject]

if announcements.count > 0 {
partsFound += announcements.count
}
}

// check if this is the last one
if ++partsSearched == dataParts {
whenDone()
}
})

}
else {
completionHandler(UIBackgroundFetchResult.NoData);
}

}
}

49 changes: 49 additions & 0 deletions LSDashboard/Base.lproj/LaunchScreen.xib
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="7702" systemVersion="14C109" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7701"/>
<capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<view contentMode="scaleToFill" id="iN0-l3-epB">
<rect key="frame" x="0.0" y="0.0" width="480" height="480"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text=" Copyright (c) 2015 Pearson Developer Network. All rights reserved." textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="9" translatesAutoresizingMaskIntoConstraints="NO" id="8ie-xW-0ye">
<rect key="frame" x="20" y="439" width="441" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="LearningStudio Demo" textAlignment="center" lineBreakMode="middleTruncation" baselineAdjustment="alignBaselines" minimumFontSize="18" translatesAutoresizingMaskIntoConstraints="NO" id="kId-c2-rCX">
<rect key="frame" x="20" y="59" width="441" height="43"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="36"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="LSDemo" translatesAutoresizingMaskIntoConstraints="NO" id="0TZ-FF-w79">
<rect key="frame" x="179" y="162" width="150" height="150"/>
</imageView>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="kId-c2-rCX" firstAttribute="centerY" secondItem="iN0-l3-epB" secondAttribute="bottom" multiplier="1/3" constant="-79.5" id="5cJ-9S-tgC"/>
<constraint firstAttribute="centerX" secondItem="0TZ-FF-w79" secondAttribute="centerX" constant="-14" id="EPI-Q6-FYV"/>
<constraint firstAttribute="centerX" secondItem="kId-c2-rCX" secondAttribute="centerX" id="Koa-jz-hwk"/>
<constraint firstAttribute="bottom" secondItem="8ie-xW-0ye" secondAttribute="bottom" constant="20" id="Kzo-t9-V3l"/>
<constraint firstItem="8ie-xW-0ye" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" constant="20" symbolic="YES" id="MfP-vx-nX0"/>
<constraint firstAttribute="centerX" secondItem="8ie-xW-0ye" secondAttribute="centerX" id="ZEH-qu-HZ9"/>
<constraint firstAttribute="centerY" secondItem="0TZ-FF-w79" secondAttribute="centerY" constant="3.5" id="ZlP-Qo-dnV"/>
<constraint firstItem="kId-c2-rCX" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" constant="20" symbolic="YES" id="fvb-Df-36g"/>
</constraints>
<nil key="simulatedStatusBarMetrics"/>
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
<point key="canvasLocation" x="548" y="455"/>
</view>
</objects>
<resources>
<image name="LSDemo" width="150" height="150"/>
</resources>
</document>
Loading

0 comments on commit 254ffb7

Please sign in to comment.