Skip to content

Instantly share code, notes, and snippets.

@logtdm
Created April 18, 2018 19:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save logtdm/c1131b2f6a5191e4264cf0334265d54b to your computer and use it in GitHub Desktop.
Save logtdm/c1131b2f6a5191e4264cf0334265d54b to your computer and use it in GitHub Desktop.
App to assist the caregivers of people with Alzheimer's Disease
//
// AppDelegate.swift
// Stream
//
// Created by Taylor Martin on 2017-11-18.
// Copyright © 2017 Taylor Martin. All rights reserved.
//
import UIKit
import Firebase
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
FirebaseApp.configure()
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 invalidate graphics rendering callbacks. 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 active 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.
}
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
}
//
// Bridging-Heaher.h
// messageapp
//
// Created by Taylor Martin on 2018-02-15.
// Copyright © 2018 Taylor Martin. All rights reserved.
//
#ifndef Bridging_Heaher_h
#define Bridging_Heaher_h
#import <JSQMessagesViewController/JSQMessages.h>
#endif /* Bridging_Heaher_h */
//
// ChatViewController.swift
// Stream
//
// Created by Taylor Martin on 2018-03-15.
// Copyright © 2018 Taylor Martin. All rights reserved.
//
import UIKit
import JSQMessagesViewController
class ChatViewController: JSQMessagesViewController {
var messages = [JSQMessage]()
lazy var outgoingBubble: JSQMessagesBubbleImage = {
return JSQMessagesBubbleImageFactory()!.outgoingMessagesBubbleImage(with: UIColor.jsq_messageBubbleBlue())
}()
lazy var incomingBubble: JSQMessagesBubbleImage = {
return JSQMessagesBubbleImageFactory()!.incomingMessagesBubbleImage(with: UIColor.jsq_messageBubbleLightGray())
}()
override func viewDidLoad() {
super.viewDidLoad()
senderId = "123"
senderDisplayName = "Taylor"
inputToolbar.contentView.leftBarButtonItem = nil
collectionView.collectionViewLayout.incomingAvatarViewSize = CGSize.zero
collectionView.collectionViewLayout.outgoingAvatarViewSize = CGSize.zero
let query = Constants.refs.databaseChats.queryLimited(toLast: 100)
_ = query.observe(.childAdded, with: { [weak self] snapshot in
if let data = snapshot.value as? [String: String],
let id = data["sender_id"],
let name = data["name"],
let text = data["text"],
!text.isEmpty
{
if let message = JSQMessage(senderId: id, displayName: name, text: text)
{
self?.messages.append(message)
self?.finishReceivingMessage()
}
}
})
func showDisplayNameDialog()
{
let defaults = UserDefaults.standard
let alert = UIAlertController(title: "Your Display Name", message: "Before you can chat, please choose a display name. Others will see this name when you send chat messages. You can change your display name again by tapping the navigation bar.", preferredStyle: .alert)
alert.addTextField { textField in
if let name = defaults.string(forKey: "jsq_name")
{
textField.text = name
}
else
{
let names = ["Ford", "Arthur", "Zaphod", "Trillian", "Slartibartfast", "Humma Kavula", "Deep Thought"]
textField.text = names[Int(arc4random_uniform(UInt32(names.count)))]
}
}
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { [weak self, weak alert] _ in
if let textField = alert?.textFields?[0], !textField.text!.isEmpty {
self?.senderDisplayName = textField.text
self?.title = "Chat: \(self!.senderDisplayName!)"
defaults.set(textField.text, forKey: "jsq_name")
defaults.synchronize()
}
}))
present(alert, animated: true, completion: nil)
}
// Do any additional setup after loading the view, typically from a nib.
}
override func collectionView(_ collectionView: JSQMessagesCollectionView!, messageDataForItemAt indexPath: IndexPath!) -> JSQMessageData!
{
return messages[indexPath.item]
}
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
{
return messages.count
}
override func collectionView(_ collectionView: JSQMessagesCollectionView!, messageBubbleImageDataForItemAt indexPath: IndexPath!) -> JSQMessageBubbleImageDataSource!
{
return messages[indexPath.item].senderId == senderId ? outgoingBubble : incomingBubble
}
override func collectionView(_ collectionView: JSQMessagesCollectionView!, avatarImageDataForItemAt indexPath: IndexPath!) -> JSQMessageAvatarImageDataSource!
{
return nil
}
override func collectionView(_ collectionView: JSQMessagesCollectionView!, attributedTextForMessageBubbleTopLabelAt indexPath: IndexPath!) -> NSAttributedString!
{
return messages[indexPath.item].senderId == senderId ? nil : NSAttributedString(string: messages[indexPath.item].senderDisplayName)
}
override func collectionView(_ collectionView: JSQMessagesCollectionView!, layout collectionViewLayout: JSQMessagesCollectionViewFlowLayout!, heightForMessageBubbleTopLabelAt indexPath: IndexPath!) -> CGFloat
{
return messages[indexPath.item].senderId == senderId ? 0 : 15
}
override func didPressSend(_ button: UIButton!, withMessageText text: String!, senderId: String!, senderDisplayName: String!, date: Date!)
{
let ref = Constants.refs.databaseChats.childByAutoId()
let message = ["sender_id": senderId, "name": senderDisplayName, "text": text]
ref.setValue(message)
finishSendingMessage()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>AD_UNIT_ID_FOR_BANNER_TEST</key>
<string>ca-app-pub-3940256099942544/2934735716</string>
<key>AD_UNIT_ID_FOR_INTERSTITIAL_TEST</key>
<string>ca-app-pub-3940256099942544/4411468910</string>
<key>CLIENT_ID</key>
<string>980285984849-i6hl7pmmpg3f2urpp7cl0322j1s6n5u8.apps.googleusercontent.com</string>
<key>REVERSED_CLIENT_ID</key>
<string>com.googleusercontent.apps.980285984849-i6hl7pmmpg3f2urpp7cl0322j1s6n5u8</string>
<key>API_KEY</key>
<string>AIzaSyD0Yq4ef3v4x_qyHkJkQCTawVX3Q2aD-g8</string>
<key>GCM_SENDER_ID</key>
<string>980285984849</string>
<key>PLIST_VERSION</key>
<string>1</string>
<key>BUNDLE_ID</key>
<string>firstversion.Stream</string>
<key>PROJECT_ID</key>
<string>useraccount-3b08c</string>
<key>STORAGE_BUCKET</key>
<string>useraccount-3b08c.appspot.com</string>
<key>IS_ADS_ENABLED</key>
<true/>
<key>IS_ANALYTICS_ENABLED</key>
<false/>
<key>IS_APPINVITE_ENABLED</key>
<false/>
<key>IS_GCM_ENABLED</key>
<true/>
<key>IS_SIGNIN_ENABLED</key>
<true/>
<key>GOOGLE_APP_ID</key>
<string>1:980285984849:ios:be4cf38b97f4c8ac</string>
<key>DATABASE_URL</key>
<string>https://useraccount-3b08c.firebaseio.com</string>
</dict>
</plist>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>NSLocationAlwaysUsageDescription</key>
<string>Stream</string>
<key>NSLocationUsageDescription</key>
<string>Stream</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Stream</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>Stream</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>We need to access your photos</string>
</dict>
</plist>
//
// IS10.swift
// Stream
//
// Created by Taylor Martin on 2018-03-16.
// Copyright © 2018 Taylor Martin. All rights reserved.
//
import UIKit
import WebKit
class IS10: UIViewController {
@IBOutlet weak var WebView10: WKWebView!
override func viewDidLoad() {
super.viewDidLoad()
let url10 = URL(string: "http://caregiverexchange.ca/")
let request10 = URLRequest(url: url10!)
WebView10.load(request10)
// Do any additional setup after loading the view.
}
}
//
// IS11.swift
// Stream
//
// Created by Taylor Martin on 2018-03-16.
// Copyright © 2018 Taylor Martin. All rights reserved.
//
import UIKit
import WebKit
class IS11: UIViewController {
@IBOutlet weak var WebView11: WKWebView!
override func viewDidLoad() {
super.viewDidLoad()
let url11 = URL(string: "https://www.ontario.ca/page/ministry-seniors-affairs/")
let request11 = URLRequest(url: url11!)
WebView11.load(request11)
// Do any additional setup after loading the view.
}
}
//
// IS2.swift
// Stream
//
// Created by Taylor Martin on 2018-03-16.
// Copyright © 2018 Taylor Martin. All rights reserved.
//
import Foundation
//
// IS3.swift
// Stream
//
// Created by Taylor Martin on 2018-03-16.
// Copyright © 2018 Taylor Martin. All rights reserved.
//
import UIKit
import WebKit
class IS3: UIViewController {
@IBOutlet weak var WebView3: WKWebView!
override func viewDidLoad() {
super.viewDidLoad()
let url3 = URL(string: "https://www.comfortkeepers.ca/in-home-elder-care-services/alzheimers-disease-and-dementia-care/")
let request3 = URLRequest(url: url3!)
WebView3.load(request3)
// Do any additional setup after loading the view.
}
}
//
// IS4.swift
// Stream
//
// Created by Taylor Martin on 2018-03-16.
// Copyright © 2018 Taylor Martin. All rights reserved.
//
import UIKit
import WebKit
class IS4: UIViewController {
@IBOutlet weak var WebView4: WKWebView!
override func viewDidLoad() {
super.viewDidLoad()
let url4 = URL(string: "https://www.alz.org/care/")
let request4 = URLRequest(url: url4!)
WebView4.load(request4)
// Do any additional setup after loading the view.
}
}
//
// IS5.swift
// Stream
//
// Created by Taylor Martin on 2018-03-16.
// Copyright © 2018 Taylor Martin. All rights reserved.
//
import UIKit
import WebKit
class IS5: UIViewController {
@IBOutlet weak var WebView5: WKWebView!
override func viewDidLoad() {
super.viewDidLoad()
let url5 = URL(string: "http://www.homecareontario.ca/home-care-services/frequently-asked-questions/personalstories")
let request5 = URLRequest(url: url5!)
WebView5.load(request5)
// Do any additional setup after loading the view.
}
}
//
// IS6.swift
// Stream
//
// Created by Taylor Martin on 2018-03-16.
// Copyright © 2018 Taylor Martin. All rights reserved.
//
import UIKit
import WebKit
class IS6: UIViewController {
@IBOutlet weak var WebView6: WKWebView!
override func viewDidLoad() {
super.viewDidLoad()
let url6 = URL(string: "https://elizz.com/caregiver-resources/caregiving-tips/government-programs-for-caregivers")
let request6 = URLRequest(url: url6!)
WebView6.load(request6)
// Do any additional setup after loading the view.
}
}
//
// IS7.swift
// Stream
//
// Created by Taylor Martin on 2018-03-16.
// Copyright © 2018 Taylor Martin. All rights reserved.
//
import UIKit
import WebKit
class IS7: UIViewController {
@IBOutlet weak var WebView7: WKWebView!
override func viewDidLoad() {
super.viewDidLoad()
let url7 = URL(string: "http://alz.to/get-help/")
let request7 = URLRequest(url: url7!)
WebView7.load(request7)
// Do any additional setup after loading the view.
}
}
//
// IS8.swift
// Stream
//
// Created by Taylor Martin on 2018-03-16.
// Copyright © 2018 Taylor Martin. All rights reserved.
//
import UIKit
import WebKit
class IS8: UIViewController {
@IBOutlet weak var WebView8: WKWebView!
override func viewDidLoad() {
super.viewDidLoad()
let url8 = URL(string: "http://alzheimersocietyblog.ca/")
let request8 = URLRequest(url: url8!)
WebView8.load(request8)
// Do any additional setup after loading the view.
}
}
//
// IS9.swift
// Stream
//
// Created by Taylor Martin on 2018-03-16.
// Copyright © 2018 Taylor Martin. All rights reserved.
//
import UIKit
import WebKit
class IS9: UIViewController {
@IBOutlet weak var WebView9: WKWebView!
override func viewDidLoad() {
super.viewDidLoad()
let url9 = URL(string: "http://www.circleofcare.com/helping-caregivers/")
let request9 = URLRequest(url: url9!)
WebView9.load(request9)
// Do any additional setup after loading the view.
}
}
//
// Page2.swift
// Stream
//
// Created by Taylor Martin on 2017-11-29.
// Copyright © 2017 Taylor Martin. All rights reserved.
//
import UIKit
class Page2: UIViewController {
@IBOutlet weak var firstname: UITextField!
@IBOutlet weak var ScrollView: UIScrollView!
override func viewDidLoad() {
super.viewDidLoad()
ScrollView.contentSize.height = 900
firstname.delegate = self as? UITextFieldDelegate
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
@IBAction func createaccount(_ sender: Any) {
}
}
extension ViewController :UITextFieldDelegate {
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
textField.resignFirstResponder()
return true
}
}
//
// Page3.swift
// Stream
//
// Created by Taylor Martin on 2017-11-29.
// Copyright © 2017 Taylor Martin. All rights reserved.
//
import UIKit
class Page3: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}
//
// Page4.swift
// Stream
//
// Created by Taylor Martin on 2017-11-29.
// Copyright © 2017 Taylor Martin. All rights reserved.
//
import UIKit
import WebKit
class Page4: UIViewController {
@IBOutlet weak var WebView: WKWebView!
override func viewDidLoad() {
super.viewDidLoad()
let url = URL(string: "https://www.canada.ca/en/services/benefits/ei/ei-compassionate.html")
let request = URLRequest(url: url!)
WebView.load(request)
}
}
//
// Page5.swift
// Stream
//
// Created by Taylor Martin on 2017-11-29.
// Copyright © 2017 Taylor Martin. All rights reserved.
//
import UIKit
class Page5: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}
//
// Page6.swift
// Stream
//
// Created by Taylor Martin on 2017-11-29.
// Copyright © 2017 Taylor Martin. All rights reserved.
//
import UIKit
class Page6: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}
//
// Page7.swift
// Stream
//
// Created by Taylor Martin on 2017-11-29.
// Copyright © 2017 Taylor Martin. All rights reserved.
//
import UIKit
class Page7: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}
//
// Page8.swift
// Stream
//
// Created by Taylor Martin on 2017-11-29.
// Copyright © 2017 Taylor Martin. All rights reserved.
//
import UIKit
import MapKit
class Page8: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate {
@IBOutlet weak var mapkitView: MKMapView!
let locationManager = CLLocationManager ()
override func viewDidLoad() {
super.viewDidLoad()
mapkitView.delegate = self
mapkitView.showsScale = true
mapkitView.showsPointsOfInterest = true
mapkitView.showsUserLocation = true
locationManager.requestAlwaysAuthorization()
locationManager.requestWhenInUseAuthorization()
if CLLocationManager.locationServicesEnabled() {
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.startUpdatingLocation()
}
let sourceCoordinates = locationManager.location?.coordinate
let destCoordinates = CLLocationCoordinate2DMake(43.706535, -79.399372)
let sourcePlacemark = MKPlacemark(coordinate: sourceCoordinates!)
let destPlacemark = MKPlacemark(coordinate: destCoordinates)
let sourceItem = MKMapItem(placemark: sourcePlacemark)
let destItem = MKMapItem(placemark: destPlacemark)
let directionRequest = MKDirectionsRequest()
directionRequest.source = sourceItem
directionRequest.destination = destItem
directionRequest.transportType = .walking
let directions = MKDirections(request: directionRequest)
directions.calculate(completionHandler: ){
response, error in
guard let response = response else {
if let error = error {
print("Something wen't Wrong")
}
return
}
let route = response.routes[0]
self.mapkitView.add(route.polyline, level: .aboveRoads)
let rekt = route.polyline.boundingMapRect
self.mapkitView.setRegion(MKCoordinateRegionForMapRect(rekt), animated: true)
}
}
func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
let renderer = MKPolylineRenderer(overlay: overlay)
renderer.strokeColor = UIColor.blue
renderer.lineWidth = 5.0
return renderer
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}
//
// Page9.swift
// Stream
//
// Created by Taylor Martin on 2017-11-29.
// Copyright © 2017 Taylor Martin. All rights reserved.
//
import UIKit
class Page9: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}
# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'
target 'Stream' do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
# Pods for Stream
pod 'Firebase/Core'
pod 'Firebase/Auth'
pod 'Firebase/Database'
pod 'Firebase/Storage'
pod 'SwiftKeychainWrapper'
pod 'JSQMessagesViewController'
target 'StreamTests' do
inherit! :search_paths
# Pods for testing
end
target 'StreamUITests' do
inherit! :search_paths
# Pods for testing
end
end
//
// TableViewController.swift
// Stream
//
// Created by Taylor Martin on 2018-03-15.
// Copyright © 2018 Taylor Martin. All rights reserved.
//
import UIKit
class TableViewController: UITableViewController, UISearchResultsUpdating {
var dogs = [String]()
var filteredDogs = [String]()
var identities = [String]()
var searchController : UISearchController!
var resultsController = UITableViewController()
override func viewDidLoad() {
super.viewDidLoad()
dogs = ["EI Compassionate Care Benefits", "News and Events", "Alzheimer's and Dimentia Care", "Caregiving Help","Personal Stories", "Government Funding", "Get Help", "Blog Stories", "Mental Health", "Information Exchange", "Seniors Resources"]
identities = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K"]
self.resultsController.tableView.dataSource = self
self.resultsController.tableView.delegate = self
self.searchController = UISearchController(searchResultsController: self.resultsController)
self.tableView.tableHeaderView = self.searchController.searchBar
self.searchController.searchResultsUpdater = self
// Uncomment the following line to preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = false
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem
}
func updateSearchResults(for searchController: UISearchController) {
self.filteredDogs = self.dogs.filter { (dog:String) -> Bool in
if dog.lowercased().contains(self.searchController.searchBar.text!.lowercased()) {
return true
} else {
return false
}
}
self.resultsController.tableView.reloadData()
}
// MARK: - Table view data source
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if tableView == self.tableView {
return self.dogs.count
} else {
return self.filteredDogs.count
}
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell()
if tableView == self.tableView {
cell.textLabel?.text = self.dogs[indexPath.row]
} else {
cell.textLabel?.text = self.filteredDogs[indexPath.row]
}
return cell
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let vcName = identities[indexPath.row]
let viewController = storyboard?.instantiateViewController(withIdentifier: vcName)
self.navigationController?.pushViewController(viewController!, animated: true)
}
/*
// Override to support conditional editing of the table view.
override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
// Return false if you do not want the specified item to be editable.
return true
}
*/
/*
// Override to support editing the table view.
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
// Delete the row from the data source
tableView.deleteRows(at: [indexPath], with: .fade)
} else if editingStyle == .insert {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
*/
/*
// Override to support rearranging the table view.
override func tableView(_ tableView: UITableView, moveRowAt fromIndexPath: IndexPath, to: IndexPath) {
}
*/
/*
// Override to support conditional rearranging of the table view.
override func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool {
// Return false if you do not want the item to be re-orderable.
return true
}
*/
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}
//
// UserVC.swift
// Stream
//
// Created by Taylor Martin on 2018-03-14.
// Copyright © 2018 Taylor Martin. All rights reserved.
//
import UIKit
import Firebase
import FirebaseDatabase
import FirebaseStorage
import SwiftKeychainWrapper
class UserVC: UIViewController, UIImagePickerControllerDelegate,
UINavigationControllerDelegate {
@IBOutlet weak var userImagePicker: UIImageView!
@IBOutlet weak var usernameField: UITextField!
@IBOutlet weak var completeSignInBtn: UIButton!
var userUid: String!
var emailField: String!
var passwordField: String!
var imagePicker: UIImagePickerController!
var imageSelected = false
var username: String!
override func viewDidLoad() {
super.viewDidLoad()
imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.allowsEditing = true
// Do any additional setup after loading the view.
}
func keychain() {
KeychainWrapper.standard.set(userUid, forKey: "uid")
}
func imagePickerController(_ picker: UIImagePickerController,
didFinishPickingMediaWithInfo info: [String : Any]) {
if let image = info[UIImagePickerControllerEditedImage] as? UIImage {
userImagePicker.image = image
imageSelected = true
} else {
print("image wasn't selected")
}
imagePicker.dismiss(animated: true, completion: nil)
}
func setUpUser(img: String) {
let userData = [
"username": username!,
"userImg": img
]
keychain()
let setLocation = Database.database().reference().child("users").child(userUid)
setLocation.setValue(userData)
}
func uploadImg() {
if usernameField.text == nil {
print("must have username")
completeSignInBtn.isEnabled = false
} else {
username = usernameField.text
completeSignInBtn.isEnabled = true
}
guard let img = userImagePicker.image, imageSelected == true else {
print("image must be selected")
return
}
if let imgData = UIImageJPEGRepresentation(img, 0.2) {
let imgUid = NSUUID().uuidString
let metadata = StorageMetadata()
metadata.contentType = "img/jpeg"
Storage.storage().reference().child(imgUid).putData(imgData, metadata: metadata)
{ (metadata, error) in
if error != nil {
print("did not upload image")
} else {
print("uploaded")
let downloadURL = metadata?.downloadURL()?.absoluteString
if let url = downloadURL {
self.setUpUser(img: url)
}
}
}
}
}
@IBAction func completeAccount(_ sender: Any) {
Auth.auth().createUser(withEmail: emailField, password: passwordField,
completion: { (user,error) in
if error != nil {
print(error)
} else {
if let user = user {
self.userUid = user.uid
}
}
self.uploadImg()
})
dismiss(animated: true, completion: nil)
}
@IBAction func selectedImagePicker(_ sender: Any) {
present(imagePicker, animated: true, completion:nil)
}
@IBAction func cancel(_ sender: AnyObject) {
dismiss(animated: true, completion: nil)
}
}
//
// ViewController.swift
// Stream
//
// Created by Taylor Martin on 2017-11-18.
// Copyright © 2017 Taylor Martin. All rights reserved.
//
import UIKit
import Firebase
import SwiftKeychainWrapper
class ViewController: UIViewController {
@IBOutlet weak var emailField: UITextField!
@IBOutlet weak var passwordField: UITextField!
@IBOutlet weak var ScrollView: UIScrollView!
var userUid: String!
override func viewDidLoad() {
super.viewDidLoad()
ScrollView.contentSize.height = 1000
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func goToCreateUserVC(){
performSegue(withIdentifier: "SignUp", sender: nil)
}
func goToFeedVC() {
performSegue(withIdentifier: "ToFeed", sender: nil)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "SignUp" {
if let destination = segue.destination as? UserVC {
if userUid != nil {
destination.userUid = userUid
}
if emailField.text != nil {
destination.emailField = emailField.text
}
if passwordField.text != nil{
destination.passwordField = passwordField.text
}
}
}
func viewDidAppear(_ animated: Bool) {
if let _ = KeychainWrapper.standard.string(forKey: "uid") {
goToFeedVC()
}
}
func signInTapped(_ sender: Any){
if let email = emailField.text, let password = passwordField.text {
Auth.auth().signIn(withEmail: email, password: password, completion: { (user,error) in
if error == nil {
if let user = user {
self.userUid = user.uid
self.goToFeedVC()
}
} else {
self.goToCreateUserVC()
}
});
}
}
}
@IBAction func signInTapped(_ sender: Any) {
if let email = emailField.text, let password = passwordField.text {
Auth.auth().signIn(withEmail: email, password: password, completion: { (user,error) in
if error == nil {
if let user = user {
self.userUid = user.uid
self.goToFeedVC()
}
} else {
self.goToCreateUserVC()
}
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment