diff --git a/Lifetime.xcodeproj/project.pbxproj b/Lifetime.xcodeproj/project.pbxproj index 31853da..23ac415 100644 --- a/Lifetime.xcodeproj/project.pbxproj +++ b/Lifetime.xcodeproj/project.pbxproj @@ -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 */; }; @@ -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; }; @@ -69,6 +71,7 @@ 870312481CD4EECD00A48B90 /* View */ = { isa = PBXGroup; children = ( + 2AA400E21CDB825E00BF7683 /* ContactCell.swift */, ); name = View; sourceTree = ""; @@ -135,6 +138,7 @@ TargetAttributes = { 871044D81CD3C9860091710A = { CreatedOnToolsVersion = 7.3; + DevelopmentTeam = AVQEU8EC7K; }; }; }; @@ -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 */, @@ -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; @@ -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; }; diff --git a/Lifetime/ContactCell.swift b/Lifetime/ContactCell.swift new file mode 100644 index 0000000..a7797cb --- /dev/null +++ b/Lifetime/ContactCell.swift @@ -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 + } + } +} diff --git a/Lifetime/ContactDetailViewController.swift b/Lifetime/ContactDetailViewController.swift index 8035e55..33aa5fc 100644 --- a/Lifetime/ContactDetailViewController.swift +++ b/Lifetime/ContactDetailViewController.swift @@ -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 😞" } } diff --git a/Lifetime/ContactListViewController.swift b/Lifetime/ContactListViewController.swift index 7056454..2e8efc6 100644 --- a/Lifetime/ContactListViewController.swift +++ b/Lifetime/ContactListViewController.swift @@ -25,6 +25,7 @@ class ContactListViewController: UITableViewController { private var contacts: [CNContact] = [] { didSet { tableView.reloadData() + print(contacts.count) } } @@ -60,6 +61,7 @@ class ContactListViewController: UITableViewController { override func viewDidLoad() { super.viewDidLoad() + //self.tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "ContactCell") tableView.tableHeaderView = searchController.searchBar } @@ -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 diff --git a/Lifetime/LaunchScreen.storyboard b/Lifetime/LaunchScreen.storyboard index 2e721e1..323bd43 100644 --- a/Lifetime/LaunchScreen.storyboard +++ b/Lifetime/LaunchScreen.storyboard @@ -1,7 +1,8 @@ - + - + + @@ -15,7 +16,6 @@ - diff --git a/Lifetime/Lifetime.swift b/Lifetime/Lifetime.swift index 75a7858..8c9b7f7 100644 --- a/Lifetime/Lifetime.swift +++ b/Lifetime/Lifetime.swift @@ -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) + } } diff --git a/Lifetime/Main.storyboard b/Lifetime/Main.storyboard index f56967f..a689734 100644 --- a/Lifetime/Main.storyboard +++ b/Lifetime/Main.storyboard @@ -21,7 +21,7 @@ - + @@ -33,16 +33,16 @@ - - + + - + + + + + + + + + + + + @@ -60,13 +72,14 @@ - + + @@ -78,6 +91,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + +