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

use SafariViewController for creating new goals #119

Merged
merged 1 commit into from
Aug 4, 2020
Merged
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
4 changes: 0 additions & 4 deletions BeeSwift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@
A1E618E41E7934C700D8ED93 /* HealthKitConfigTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = A1E618E31E7934C700D8ED93 /* HealthKitConfigTableViewCell.swift */; };
A1E619001E86980900D8ED93 /* HealthKitConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = A1E618FF1E86980900D8ED93 /* HealthKitConfig.swift */; };
A1EA154D1B01E6EC0052A6E6 /* DatapointTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = A1EA154C1B01E6EC0052A6E6 /* DatapointTableViewCell.swift */; };
A1EFB5401F0F2E57005C75AE /* CreateGoalViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A1EFB53F1F0F2E57005C75AE /* CreateGoalViewController.swift */; };
A1F8F07B232C05410060B83E /* JSONGoal.swift in Sources */ = {isa = PBXBuildFile; fileRef = A1F8F07A232C05410060B83E /* JSONGoal.swift */; };
A1F9D1EA211B9B7600E2BC93 /* EditDatapointViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A1F9D1E9211B9B7600E2BC93 /* EditDatapointViewController.swift */; };
A1FF19141DE8EEA900FD0527 /* NewGoalCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = A1FF19131DE8EEA900FD0527 /* NewGoalCollectionViewCell.swift */; };
Expand Down Expand Up @@ -182,7 +181,6 @@
A1E618E31E7934C700D8ED93 /* HealthKitConfigTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HealthKitConfigTableViewCell.swift; sourceTree = "<group>"; };
A1E618FF1E86980900D8ED93 /* HealthKitConfig.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HealthKitConfig.swift; sourceTree = "<group>"; };
A1EA154C1B01E6EC0052A6E6 /* DatapointTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatapointTableViewCell.swift; sourceTree = "<group>"; };
A1EFB53F1F0F2E57005C75AE /* CreateGoalViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CreateGoalViewController.swift; sourceTree = "<group>"; };
A1F8F07A232C05410060B83E /* JSONGoal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JSONGoal.swift; sourceTree = "<group>"; };
A1F9D1E9211B9B7600E2BC93 /* EditDatapointViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditDatapointViewController.swift; sourceTree = "<group>"; };
A1FF19131DE8EEA900FD0527 /* NewGoalCollectionViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NewGoalCollectionViewCell.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -338,7 +336,6 @@
A1F8F07A232C05410060B83E /* JSONGoal.swift */,
A1453B3E1AEDFCC8006F48DA /* SignInViewController.swift */,
A149B36F1AEF528C00F19A09 /* SettingsViewController.swift */,
A1EFB53F1F0F2E57005C75AE /* CreateGoalViewController.swift */,
A1A8BDE51FEAE8DD007D61D6 /* ConfigureNotificationsViewController.swift */,
A11A87C51FEBFF7200A43E47 /* ChooseGoalSortViewController.swift */,
A10DC2DE207BFCBA00FB7B3A /* RemoveHKMetricViewController.swift */,
Expand Down Expand Up @@ -757,7 +754,6 @@
A11BA9A41FCE54E3004BB425 /* HealthStoreManager.swift in Sources */,
A15FF4201AEB621000A9AD22 /* GoalCollectionViewCell.swift in Sources */,
A1619EA61BEECC6700E14B3A /* EditGoalNotificationsViewController.swift in Sources */,
A1EFB5401F0F2E57005C75AE /* CreateGoalViewController.swift in Sources */,
A12BA9541AFFF21800AFEF32 /* Crypto.swift in Sources */,
A1A8BDE61FEAE8DD007D61D6 /* ConfigureNotificationsViewController.swift in Sources */,
A14249231FD07631007736B3 /* OAuthSignInManager.swift in Sources */,
Expand Down
55 changes: 0 additions & 55 deletions BeeSwift/CreateGoalViewController.swift

This file was deleted.

32 changes: 23 additions & 9 deletions BeeSwift/GalleryViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import SnapKit
import MBProgressHUD
import SwiftyJSON
import HealthKit
import SafariServices

class GalleryViewController: UIViewController, UICollectionViewDelegateFlowLayout, UICollectionViewDelegate, UICollectionViewDataSource, UISearchBarDelegate {


class GalleryViewController: UIViewController, UICollectionViewDelegateFlowLayout, UICollectionViewDelegate, UICollectionViewDataSource, UISearchBarDelegate, SFSafariViewControllerDelegate {
var collectionView :UICollectionView?
var collectionViewLayout :UICollectionViewLayout?
let lastUpdatedView = UIView()
Expand All @@ -26,12 +27,12 @@ class GalleryViewController: UIViewController, UICollectionViewDelegateFlowLayou
let noGoalsLabel = BSLabel()
let outofdateLabel = BSLabel()
let searchBar = UISearchBar()
var lastUpdated : Date?
var lastUpdated: Date?
let maxSearchBarHeight: Int = 50

var goals : Array<JSONGoal> = []
var filteredGoals : Array<JSONGoal> = []

override func viewDidLoad() {
super.viewDidLoad()

Expand Down Expand Up @@ -312,7 +313,7 @@ class GalleryViewController: UIViewController, UICollectionViewDelegateFlowLayou
if searchText == "" {
self.filteredGoals = self.goals
} else {
self.filteredGoals = self.goals.filter { (goal) -> Bool in
self.filteredGoals = self.goals.filter { (goal) -> Bool in
return goal.slug.lowercased().contains(searchText.lowercased())
}
}
Expand All @@ -330,7 +331,13 @@ class GalleryViewController: UIViewController, UICollectionViewDelegateFlowLayou
}

@objc func handleCreateGoalButtonPressed() {
self.navigationController?.pushViewController(CreateGoalViewController(), animated: true)
guard let username = CurrentUserManager.sharedManager.username,
let access_token = CurrentUserManager.sharedManager.accessToken,
let createGoalUrl = URL(string: "\(RequestManager.baseURLString)/api/v1/users/\(username).json?access_token=\(access_token)&redirect_to_url=\(RequestManager.baseURLString)/new?ios=true") else { return }

let safariVC = SFSafariViewController(url: createGoalUrl)
safariVC.delegate = self
self.showDetailViewController(safariVC, sender: self)
}

@objc func updateLastUpdatedLabel() {
Expand All @@ -343,7 +350,7 @@ class GalleryViewController: UIViewController, UICollectionViewDelegateFlowLayou
}
else if lastUpdated.timeIntervalSinceNow < -120 {
color = UIColor.black
lastTextString = "Last updated: \(-1*Int(lastUpdated.timeIntervalSinceNow/60)) minutes ago"
lastTextString = "Last updated: \(-1 * Int(lastUpdated.timeIntervalSinceNow / 60)) minutes ago"
}
else if lastUpdated.timeIntervalSinceNow < -60 {
color = UIColor.black
Expand All @@ -358,7 +365,7 @@ class GalleryViewController: UIViewController, UICollectionViewDelegateFlowLayou
color = UIColor.red
lastTextString = "Last updated: a long time ago..."
}
let lastText :NSMutableAttributedString = NSMutableAttributedString(string: lastTextString)
let lastText: NSMutableAttributedString = NSMutableAttributedString(string: lastTextString)
lastText.addAttribute(NSAttributedStringKey.foregroundColor, value: color, range: NSRange(location: 0, length: lastText.string.count))
self.lastUpdatedLabel.attributedText = lastText
}
Expand Down Expand Up @@ -475,7 +482,7 @@ class GalleryViewController: UIViewController, UICollectionViewDelegateFlowLayou
let row = (indexPath as NSIndexPath).row
if row < self.filteredGoals.count { self.openGoal(self.filteredGoals[row]) }
}

@objc func openGoalFromNotification(_ notification: Notification) {
let slug = (notification as NSNotification).userInfo!["slug"] as! String
let matchingGoal = self.goals.filter({ (goal) -> Bool in
Expand All @@ -492,5 +499,12 @@ class GalleryViewController: UIViewController, UICollectionViewDelegateFlowLayou
goalViewController.goal = goal
self.navigationController?.pushViewController(goalViewController, animated: true)
}

// MARK: - SFSafariViewControllerDelegate

func safariViewControllerDidFinish(_ controller: SFSafariViewController) {
controller.dismiss(animated: true, completion: nil)
self.fetchGoals()
}
}