Skip to content

Commit

Permalink
Merge pull request #7 from fbernaly/master
Browse files Browse the repository at this point in the history
Swift 3
  • Loading branch information
misbach authored Sep 19, 2017
2 parents a2fb95d + d5f1619 commit 1538c34
Show file tree
Hide file tree
Showing 10 changed files with 825 additions and 1,002 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.git
.DS_Store
FamilySearchIosSampleApp/AppKeys.swift
FamilySearchIosSampleApp/AppKeys.swift
FamilySearchIosSampleApp.xcodeproj/project.xcworkspace/xcuserdata
FamilySearchIosSampleApp.xcodeproj/xcuserdata
14 changes: 10 additions & 4 deletions FamilySearchIosSampleApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
objects = {

/* Begin PBXBuildFile section */
0EE073E01F69D521006CD2D6 /* AppKeys.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0EE073DF1F69D521006CD2D6 /* AppKeys.swift */; };
5E7D1C301D4BFD5E00874503 /* Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7D1C2E1D4BFB7D00874503 /* Extensions.swift */; };
A00150AF1D08FF76008E53E8 /* User.swift in Sources */ = {isa = PBXBuildFile; fileRef = A00150AE1D08FF76008E53E8 /* User.swift */; };
A00BB4AB1D06628D009ADBDB /* AppKeys.swift in Sources */ = {isa = PBXBuildFile; fileRef = A00BB4AA1D06628D009ADBDB /* AppKeys.swift */; };
A00BB4B01D06741E009ADBDB /* TreeTVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = A00BB4AF1D06741E009ADBDB /* TreeTVC.swift */; };
A00FDD3D1D02755700C7384B /* Links.swift in Sources */ = {isa = PBXBuildFile; fileRef = A00FDD3C1D02755700C7384B /* Links.swift */; };
A0151B321D10FBA6008DADD8 /* MemoryCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = A0151B311D10FBA6008DADD8 /* MemoryCell.swift */; };
Expand All @@ -29,9 +29,9 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
0EE073DF1F69D521006CD2D6 /* AppKeys.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppKeys.swift; sourceTree = "<group>"; };
5E7D1C2E1D4BFB7D00874503 /* Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Extensions.swift; sourceTree = "<group>"; };
A00150AE1D08FF76008E53E8 /* User.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = User.swift; sourceTree = "<group>"; };
A00BB4AA1D06628D009ADBDB /* AppKeys.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppKeys.swift; sourceTree = "<group>"; };
A00BB4AF1D06741E009ADBDB /* TreeTVC.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TreeTVC.swift; sourceTree = "<group>"; };
A00FDD3C1D02755700C7384B /* Links.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Links.swift; sourceTree = "<group>"; };
A0151B311D10FBA6008DADD8 /* MemoryCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MemoryCell.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -103,7 +103,6 @@
A01D9FD51D023344005473BD /* Main.storyboard */,
A01D9FDA1D023344005473BD /* LaunchScreen.storyboard */,
A01D9FDD1D023344005473BD /* Info.plist */,
A00BB4AA1D06628D009ADBDB /* AppKeys.swift */,
A05168E31D09EDDA005E7EE9 /* Localizable.strings */,
);
path = FamilySearchIosSampleApp;
Expand Down Expand Up @@ -134,6 +133,7 @@
children = (
A0D6047E1D03D99A00F2A83D /* Utilities.swift */,
A03BAE501D106A91002572BA /* WaitingView.swift */,
0EE073DF1F69D521006CD2D6 /* AppKeys.swift */,
);
name = Utils;
sourceTree = "<group>";
Expand Down Expand Up @@ -170,6 +170,8 @@
TargetAttributes = {
A01D9FCD1D023344005473BD = {
CreatedOnToolsVersion = 7.3.1;
DevelopmentTeam = E75E2R8ZH4;
LastSwiftMigration = 0830;
};
};
};
Expand Down Expand Up @@ -213,10 +215,10 @@
A01D9FD41D023344005473BD /* LoginVC.swift in Sources */,
A01B4FBC1D0CFB3600E90D6D /* MemoriesVC.swift in Sources */,
A0151B321D10FBA6008DADD8 /* MemoryCell.swift in Sources */,
0EE073E01F69D521006CD2D6 /* AppKeys.swift in Sources */,
A00FDD3D1D02755700C7384B /* Links.swift in Sources */,
A0D6047F1D03D99A00F2A83D /* Utilities.swift in Sources */,
A0296F111D0A688A00FAE4E0 /* PersonCell.swift in Sources */,
A00BB4AB1D06628D009ADBDB /* AppKeys.swift in Sources */,
A00BB4B01D06741E009ADBDB /* TreeTVC.swift in Sources */,
A01D9FD21D023344005473BD /* AppDelegate.swift in Sources */,
A03BAE511D106A91002572BA /* WaitingView.swift in Sources */,
Expand Down Expand Up @@ -339,23 +341,27 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = E75E2R8ZH4;
INFOPLIST_FILE = FamilySearchIosSampleApp/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.FamilySearch.IosSampleApp;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
A01D9FE21D023344005473BD /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = E75E2R8ZH4;
INFOPLIST_FILE = FamilySearchIosSampleApp/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.FamilySearch.IosSampleApp;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand Down
248 changes: 102 additions & 146 deletions FamilySearchIosSampleApp/AncestorDetails.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,156 +11,112 @@ import UIKit

class AncestorDetails : UIViewController
{
@IBOutlet weak var ancestorImageView: UIImageView!
@IBOutlet weak var ancestorNameLabel: UILabel!
@IBOutlet weak var ancestorBirthLabelTitle: UILabel!
@IBOutlet weak var ancestorBirthLabelValue: UILabel!
@IBOutlet weak var ancestorDeathLabelTitle: UILabel!
@IBOutlet weak var ancestorDeathLabelValue: UILabel!
@IBOutlet weak var ancestorImageIndicator: UIActivityIndicatorView!
@IBOutlet weak var ancestorDataIndicator: UIActivityIndicatorView!
@IBOutlet weak var ancestorImageView: UIImageView!
@IBOutlet weak var ancestorNameLabel: UILabel!
@IBOutlet weak var ancestorBirthLabelTitle: UILabel!
@IBOutlet weak var ancestorBirthLabelValue: UILabel!
@IBOutlet weak var ancestorDeathLabelTitle: UILabel!
@IBOutlet weak var ancestorDeathLabelValue: UILabel!
@IBOutlet weak var ancestorImageIndicator: UIActivityIndicatorView!
@IBOutlet weak var ancestorDataIndicator: UIActivityIndicatorView!

var person : Person?

override func viewDidLoad() {
self.navigationItem.title = NSLocalizedString("ancestorDetailsTitle", comment: "Word Ancestor")

var person : Person?
// hide data labels until the data gets downloaded
self.ancestorBirthLabelTitle.isHidden = true
self.ancestorBirthLabelValue.isHidden = true
self.ancestorDeathLabelTitle.isHidden = true
self.ancestorDeathLabelValue.isHidden = true

override func viewDidLoad() {
self.navigationItem.title = NSLocalizedString("ancestorDetailsTitle", comment: "Word Ancestor")

// hide data labels until the data gets downloaded
self.ancestorBirthLabelTitle.hidden = true
self.ancestorBirthLabelValue.hidden = true
self.ancestorDeathLabelTitle.hidden = true
self.ancestorDeathLabelValue.hidden = true

// get the access token from NSUserDefaults
let preferences = NSUserDefaults.standardUserDefaults()
let accessToken = preferences.stringForKey(Utilities.KEY_ACCESS_TOKEN)

Utilities.getImageFromUrl(person!.personLinkHref!, accessToken: accessToken!) { (data, response, error) in
dispatch_async(dispatch_get_main_queue()) { [weak self] () -> Void in
self?.ancestorImageView.image = UIImage(data: data!)
self?.ancestorImageIndicator.hidesWhenStopped = true
self?.ancestorImageIndicator.stopAnimating()
}
}

// set labels
self.ancestorNameLabel.text = person?.displayName

// download data from Person.personLinkHref
getAncestorDetailsData(person?.personLinkHref,
accessToken: accessToken!,
completionAncestorDetails: { [weak self] (personDetails, errorResponse) -> Void in
if (errorResponse == nil)
{
dispatch_async(dispatch_get_main_queue(),{
self?.ancestorImageIndicator.hidesWhenStopped = true
self?.ancestorDataIndicator.stopAnimating()
self?.ancestorDataIndicator.hidden = true

// birth data
self?.ancestorBirthLabelTitle.text = NSLocalizedString("ancestorDetailsBirth", comment: "Birth:")
self?.ancestorBirthLabelTitle.hidden = false
self?.ancestorBirthLabelValue.text = personDetails?.personBirthDate
self?.ancestorBirthLabelValue.hidden = false

// death data
if (personDetails?.personDeathDate != nil)
{
self?.ancestorDeathLabelTitle.text = NSLocalizedString("ancestorDetailsDeath", comment: "Death:")
self?.ancestorDeathLabelTitle.hidden = false
self?.ancestorDeathLabelValue.text = personDetails?.personDeathDate
self?.ancestorDeathLabelValue.hidden = false
}
})
}
})
// get the access token from UserDefaults
let preferences = UserDefaults.standard
let accessToken = preferences.string(forKey: Utilities.KEY_ACCESS_TOKEN)

Utilities.getImageFromUrl(person!.personLinkHref!, accessToken: accessToken!) { (data, response, error) in
DispatchQueue.main.async { [weak self] () -> Void in
self?.ancestorImageView.image = UIImage(data: data!)
self?.ancestorImageIndicator.hidesWhenStopped = true
self?.ancestorImageIndicator.stopAnimating()
}
}

func getAncestorDetailsData(personUrlString:String?,
accessToken:String,
completionAncestorDetails:(responseDetails: PersonDetails?, reponseError:NSError?) -> ())
{

guard let personUrlString = personUrlString, ancestorDetailsUrl = NSURL(string: personUrlString) else {
return
// set labels
self.ancestorNameLabel.text = person?.displayName

// download data from Person.personLinkHref
getAncestorDetailsData(person?.personLinkHref,
accessToken: accessToken!,
completionAncestorDetails: { [weak self] (personDetails, errorResponse) -> Void in
if (errorResponse == nil)
{
DispatchQueue.main.async(execute: {
self?.ancestorImageIndicator.hidesWhenStopped = true
self?.ancestorDataIndicator.stopAnimating()
self?.ancestorDataIndicator.isHidden = true

// birth data
self?.ancestorBirthLabelTitle.text = NSLocalizedString("ancestorDetailsBirth", comment: "Birth:")
self?.ancestorBirthLabelTitle.isHidden = false
self?.ancestorBirthLabelValue.text = personDetails?.personBirthDate
self?.ancestorBirthLabelValue.isHidden = false

// death data
if (personDetails?.personDeathDate != nil)
{
self?.ancestorDeathLabelTitle.text = NSLocalizedString("ancestorDetailsDeath", comment: "Death:")
self?.ancestorDeathLabelTitle.isHidden = false
self?.ancestorDeathLabelValue.text = personDetails?.personDeathDate
self?.ancestorDeathLabelValue.isHidden = false
}
})
}
})
}

func getAncestorDetailsData(_ personUrlString:String?,
accessToken:String,
completionAncestorDetails:@escaping (_ responseDetails: PersonDetails?, _ reponseError: Error?) -> ())
{

guard let personUrlString = personUrlString, let ancestorDetailsUrl = URL(string: personUrlString) else {
return
}

let configuration = URLSessionConfiguration.default
let headers: [AnyHashable: Any] = ["Accept":"application/json", "Authorization":"Bearer " + accessToken]
configuration.httpAdditionalHeaders = headers
let session = URLSession(configuration: configuration)
let ancestorDetailDataTask = session.dataTask(with: ancestorDetailsUrl, completionHandler: { (ancestorData, ancestorResponse, ancestorError) in
if (ancestorError == nil)
{
do
{
guard let ancestryDataJson = try JSONSerialization.jsonObject(with: ancestorData!, options: .allowFragments) as? [String : Any],
let persons = ancestryDataJson["persons"] as? [[String:AnyObject]],
let person = persons.first,
let display = person["display"] as? [String: Any],
let birthDate = display["birthDate"] as? String,
let deathDate = display["deathDate"] as? String else {
return
}
print("ancestryDataJson = \(ancestryDataJson)")

let personDetails = PersonDetails()
personDetails.personBirthDate = birthDate
personDetails.personDeathDate = deathDate

completionAncestorDetails(personDetails, nil)
}

let configuration = NSURLSessionConfiguration.defaultSessionConfiguration();
let headers: [NSObject : AnyObject] = ["Accept":"application/json", "Authorization":"Bearer " + accessToken];
configuration.HTTPAdditionalHeaders = headers;
let session = NSURLSession(configuration: configuration)
let ancestorDetailDataTask = session.dataTaskWithURL(ancestorDetailsUrl) { (ancestorData, ancestorResponse, ancestorError) in
if (ancestorError == nil)
{
do
{
let ancestryDataJson = try NSJSONSerialization.JSONObjectWithData(ancestorData!, options: .AllowFragments);
// print("ancestryDataJson = \(ancestryDataJson)")

let persons = ancestryDataJson["persons"] as? [[String:AnyObject]]
let person = persons!.first

let display = person!["display"] as? NSDictionary

let birthDate = display!["birthDate"] as? String
let deathDate = display!["deathDate"] as? String

let personDetails = PersonDetails()
personDetails.personBirthDate = birthDate
personDetails.personDeathDate = deathDate

completionAncestorDetails(responseDetails: personDetails, reponseError: nil)
}
catch
{
completionAncestorDetails(responseDetails: nil, reponseError: ancestorError)
}
}
catch
{
completionAncestorDetails(nil, ancestorError)
}

ancestorDetailDataTask.resume()
}
}
})

ancestorDetailDataTask.resume()
}
}











































Loading

0 comments on commit 1538c34

Please sign in to comment.