Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Completed #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions Lifetime.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
2AA400E31CDB825E00BF7683 /* ContactCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2AA400E21CDB825E00BF7683 /* ContactCell.swift */; };
870312411CD4EDBC00A48B90 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 8703123F1CD4EDBC00A48B90 /* LaunchScreen.storyboard */; };
870312421CD4EDBC00A48B90 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 870312401CD4EDBC00A48B90 /* Main.storyboard */; };
871045011CD4ED800091710A /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 871044F21CD4ED800091710A /* AppDelegate.swift */; };
Expand All @@ -17,6 +18,7 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
2AA400E21CDB825E00BF7683 /* ContactCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ContactCell.swift; path = Lifetime/ContactCell.swift; sourceTree = SOURCE_ROOT; };
8703123F1CD4EDBC00A48B90 /* LaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = LaunchScreen.storyboard; path = Lifetime/LaunchScreen.storyboard; sourceTree = SOURCE_ROOT; };
870312401CD4EDBC00A48B90 /* Main.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = Main.storyboard; path = Lifetime/Main.storyboard; sourceTree = SOURCE_ROOT; };
871044D91CD3C9860091710A /* Lifetime.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Lifetime.app; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -69,6 +71,7 @@
870312481CD4EECD00A48B90 /* View */ = {
isa = PBXGroup;
children = (
2AA400E21CDB825E00BF7683 /* ContactCell.swift */,
);
name = View;
sourceTree = "<group>";
Expand Down Expand Up @@ -135,6 +138,7 @@
TargetAttributes = {
871044D81CD3C9860091710A = {
CreatedOnToolsVersion = 7.3;
DevelopmentTeam = AVQEU8EC7K;
};
};
};
Expand Down Expand Up @@ -174,6 +178,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
2AA400E31CDB825E00BF7683 /* ContactCell.swift in Sources */,
8710450A1CD4ED800091710A /* Lifetime.swift in Sources */,
871045071CD4ED800091710A /* ContactDetailViewController.swift in Sources */,
871045011CD4ED800091710A /* AppDelegate.swift in Sources */,
Expand Down Expand Up @@ -274,10 +279,13 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
INFOPLIST_FILE = "$(SRCROOT)/Lifetime/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "de.uni-heidelberg.ios-dev-kurs.Life";
PRODUCT_BUNDLE_IDENTIFIER = "de.uni-heidelberg.max-simon.life";
PRODUCT_NAME = Lifetime;
PROVISIONING_PROFILE = "";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
};
name = Debug;
Expand All @@ -287,10 +295,13 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
INFOPLIST_FILE = "$(SRCROOT)/Lifetime/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "de.uni-heidelberg.ios-dev-kurs.Life";
PRODUCT_BUNDLE_IDENTIFIER = "de.uni-heidelberg.max-simon.life";
PRODUCT_NAME = Lifetime;
PROVISIONING_PROFILE = "";
};
name = Release;
};
Expand Down
38 changes: 38 additions & 0 deletions Lifetime/ContactCell.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// ContactCell.swift
// Lifetime
//
// Created by Max Simon on 05.05.16.
// Copyright © 2016 iOS Dev Kurs Universität Heidelberg. All rights reserved.
//

import UIKit
import Contacts

class ContactCell: UITableViewCell {


@IBOutlet weak var labelName: UILabel!
@IBOutlet weak var labelSeconds: UILabel!

var totalTime: Int = 0
var timer: NSTimer?

func updateSeconds() {
self.totalTime += 1
labelSeconds.text = String(self.totalTime) + "s"
}

func configureForContact(contact: CNContact) {
labelName.text = contact.givenName + " " + contact.familyName
if let timeSinceBirthday = contact.lifetimeInSeconds {
totalTime = timeSinceBirthday
timer = NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: #selector(ContactCell.updateSeconds), userInfo: nil, repeats: true)
}
else {
labelSeconds.text = ""
totalTime = 0
timer = nil
}
}
}
2 changes: 1 addition & 1 deletion Lifetime/ContactDetailViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class ContactDetailViewController: UIViewController {
lifetimeFormatter.unitsStyle = .SpellOut
lifetimeLabel.text = lifetimeFormatter.stringFromDate(birthday, toDate: NSDate())
} else {
lifetimeLabel.text = nil
lifetimeLabel.text = "Sorry, this Birthday is not set 😞"
}
}

Expand Down
37 changes: 36 additions & 1 deletion Lifetime/ContactListViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class ContactListViewController: UITableViewController {
private var contacts: [CNContact] = [] {
didSet {
tableView.reloadData()
print(contacts.count)
}
}

Expand Down Expand Up @@ -60,6 +61,7 @@ class ContactListViewController: UITableViewController {

override func viewDidLoad() {
super.viewDidLoad()
//self.tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "ContactCell")
tableView.tableHeaderView = searchController.searchBar
}

Expand All @@ -68,20 +70,53 @@ class ContactListViewController: UITableViewController {

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
switch segue.identifier! {
case "showInText":
guard let indexPath = (self.view as! UITableView).indexPathForSelectedRow else { return }
segue.destinationViewController.title = contacts[indexPath.row].givenName + " " + contacts[indexPath.row].familyName
(segue.destinationViewController as! ContactDetailViewController).contact = contacts[indexPath.row]
break

// TODO: prepare segue.destinationViewController for each identifier

default:
break
}
}


@IBAction func unwindToRoot(segue: UIStoryboardSegue) {
// nothing to do
}

}


// MARK: - Table View Datasource

// TODO: implement UITableViewDatasource protocol
extension ContactListViewController {
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return contacts.count
}


override func tableView(tableView: (UITableView!), cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let contact = contacts[indexPath.row]
let cell = tableView.dequeueReusableCellWithIdentifier("ContactCell", forIndexPath: indexPath) as! ContactCell
// Weiterlaufen verhindern
if let timerOldCell = cell.timer {
timerOldCell.invalidate()
}
cell.configureForContact(contact)
cell.selectionStyle = .Default
cell.accessoryType = .DisclosureIndicator

return cell

}
}


// MARK: - Search Results Updating
Expand Down
6 changes: 3 additions & 3 deletions Lifetime/LaunchScreen.storyboard
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="8150" systemVersion="15A204g" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" initialViewController="01J-lp-oVM">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10116" systemVersion="15E65" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" initialViewController="01J-lp-oVM">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8122"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
</dependencies>
<scenes>
<!--View Controller-->
Expand All @@ -15,7 +16,6 @@
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<animations/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
</view>
</viewController>
Expand Down
7 changes: 7 additions & 0 deletions Lifetime/Lifetime.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,11 @@ extension CNContact {
return NSDate().timeIntervalSinceDate(birthday)
}

var lifetimeInSeconds: Int? {
guard let birthdate = self.birthday, birthdayAsNSObject = NSCalendar.currentCalendar().dateFromComponents(birthdate) else {
return nil
}
let totalTime = NSDate().timeIntervalSinceDate(birthdayAsNSObject)
return Int(totalTime)
}
}
64 changes: 58 additions & 6 deletions Lifetime/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</objects>
<point key="canvasLocation" x="-38" y="-630"/>
</scene>
<!--Contact Detail-->
<!--Contact Detail View Controller-->
<scene sceneID="yUG-lL-AsK">
<objects>
<viewController automaticallyAdjustsScrollViewInsets="NO" id="JEX-9P-axG" customClass="ContactDetailViewController" customModule="Lifetime" customModuleProvider="target" sceneMemberID="viewController">
Expand All @@ -33,23 +33,35 @@
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<stackView opaque="NO" contentMode="scaleToFill" misplaced="YES" axis="vertical" spacing="8" translatesAutoresizingMaskIntoConstraints="NO" id="KK4-Wj-Xu5">
<rect key="frame" x="20" y="79" width="560" height="60"/>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" spacing="8" translatesAutoresizingMaskIntoConstraints="NO" id="KK4-Wj-Xu5">
<rect key="frame" x="20" y="79" width="560" height="61"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" misplaced="YES" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="uhI-5r-oSa">
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="uhI-5r-oSa">
<rect key="frame" x="0.0" y="0.0" width="560" height="20"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleHeadline"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" misplaced="YES" text="Lifetime" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="pm4-Q2-Ezn">
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Lifetime" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="pm4-Q2-Ezn">
<rect key="frame" x="0.0" y="28" width="560" height="33"/>
<fontDescription key="fontDescription" style="UICTFontTextStyleTitle1"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</stackView>
<navigationBar contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="oCK-cx-ZLA">
<rect key="frame" x="0.0" y="8" width="600" height="44"/>
<items>
<navigationItem id="hKq-MU-Gff">
<barButtonItem key="leftBarButtonItem" title="Cool Story, Bro!" id="c3k-U9-ODu">
<connections>
<segue destination="r0D-lI-8Iv" kind="unwind" unwindAction="unwindToRoot:" id="6EN-dZ-lYQ"/>
</connections>
</barButtonItem>
</navigationItem>
</items>
</navigationBar>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<constraints>
Expand All @@ -60,13 +72,14 @@
</constraints>
</view>
<toolbarItems/>
<navigationItem key="navigationItem" title="Contact Detail" id="mOI-FS-AaM"/>
<simulatedToolbarMetrics key="simulatedBottomBarMetrics"/>
<connections>
<outlet property="lifetimeLabel" destination="pm4-Q2-Ezn" id="EvT-zo-cQu"/>
<outlet property="lifetimeTitleLabel" destination="uhI-5r-oSa" id="eNr-Zy-7Rg"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="FJe-Yq-33r" sceneMemberID="firstResponder"/>
<exit id="r0D-lI-8Iv" userLabel="Exit" sceneMemberID="exit"/>
</objects>
<point key="canvasLocation" x="1427" y="-630"/>
</scene>
Expand All @@ -78,6 +91,45 @@
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" restorationIdentifier="ContactCell" selectionStyle="default" indentationWidth="10" reuseIdentifier="ContactCell" id="ixk-nP-hvA" customClass="ContactCell" customModule="Lifetime" customModuleProvider="target">
<rect key="frame" x="0.0" y="86" width="600" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="ixk-nP-hvA" id="t2A-7L-o8e">
<rect key="frame" x="0.0" y="0.0" width="600" height="43"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" misplaced="YES" text="Name" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="0tO-Sz-Fi2">
<rect key="frame" x="20" y="11" width="45" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" misplaced="YES" text="Seconds" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="vU3-Nd-n5t">
<rect key="frame" x="478" y="11" width="67" height="21"/>
<constraints>
<constraint firstAttribute="width" constant="100" id="hfh-YP-YVc"/>
</constraints>
<fontDescription key="fontDescription" type="system" pointSize="15"/>
<color key="textColor" red="0.41522823952879584" green="0.41522823952879584" blue="0.41522823952879584" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<constraints>
<constraint firstItem="0tO-Sz-Fi2" firstAttribute="centerY" secondItem="t2A-7L-o8e" secondAttribute="centerY" id="C8d-CJ-1qg"/>
<constraint firstAttribute="trailingMargin" secondItem="vU3-Nd-n5t" secondAttribute="trailing" constant="10" id="Jhr-9G-pHf"/>
<constraint firstItem="vU3-Nd-n5t" firstAttribute="leading" secondItem="0tO-Sz-Fi2" secondAttribute="trailing" constant="20" id="RX9-7I-rEH"/>
<constraint firstItem="vU3-Nd-n5t" firstAttribute="centerY" secondItem="t2A-7L-o8e" secondAttribute="centerY" id="Znx-Ks-ZXh"/>
<constraint firstItem="0tO-Sz-Fi2" firstAttribute="leading" secondItem="t2A-7L-o8e" secondAttribute="leadingMargin" constant="15" id="kZH-KM-jt5"/>
</constraints>
</tableViewCellContentView>
<connections>
<outlet property="labelName" destination="0tO-Sz-Fi2" id="odl-8N-8eD"/>
<outlet property="labelSeconds" destination="vU3-Nd-n5t" id="rQv-mt-D16"/>
<segue destination="JEX-9P-axG" kind="show" identifier="showInText" action="showDetailViewController:sender:" id="5SR-VG-NmC"/>
</connections>
</tableViewCell>
</prototypes>
<sections/>
<connections>
<outlet property="dataSource" destination="7bK-jq-Zjz" id="Gho-Na-rnu"/>
Expand Down