mirror of
https://bitbucket.org/vendoo/vendoo_v1.0.git
synced 2025-12-25 03:37:39 +00:00
103 lines
4.6 KiB
Swift
103 lines
4.6 KiB
Swift
//
|
|
// HomeViewController.swift
|
|
// Vendoo
|
|
//
|
|
// Created by Okechi Onyeje on 5/26/16.
|
|
// Copyright © 2016 Okechi Onyeje. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
class HomeViewController: UITabBarController {
|
|
//acts as RESTful api call manager for etsy
|
|
//call this from tabbar controller to use etsy REST calls
|
|
let etsyManager: EtsyRESTAPIManager = EtsyRESTAPIManager()
|
|
let fbGraphManager = FacebookGraphAPIManager()
|
|
let firebaseManager = FirebaseManager()
|
|
let ebayGraphManager = EbayWebServiceManager()
|
|
var userListings: [Listing] = []
|
|
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
|
|
// Do any additional setup after loading the view.
|
|
dispatch_async(dispatch_get_main_queue(), {
|
|
self.firebaseManager.ref.child("Users/\(self.firebaseManager.user_email)/user_Listings").observeSingleEventOfType( .Value, withBlock: {
|
|
(snapshot) -> Void in
|
|
|
|
let listingDict = snapshot.value as? [String : AnyObject]
|
|
if listingDict != nil {
|
|
dispatch_async(dispatch_get_main_queue(), {
|
|
|
|
for (keys, values) in listingDict! {
|
|
|
|
self.firebaseManager.ref.observeSingleEventOfType(.Value, withBlock: { snapshot in
|
|
|
|
let databaseDict = snapshot.value as! [String : AnyObject]
|
|
|
|
let storageRef = self.firebaseManager.storage.referenceForURL((databaseDict["image_storage"] as? String)!)
|
|
let listingImage = storageRef.child("images/\(keys).jpg")
|
|
|
|
|
|
//@TODO: add in logic to programmatically retrieve each stored image and store in listing object as a way to display each image
|
|
listingImage.dataWithMaxSize(10 * 1024 * 1024, completion: {
|
|
(data, error) -> Void in
|
|
|
|
if(error != nil){
|
|
print("problem retrieving items")
|
|
}else{
|
|
|
|
let listingInfo = values as? [String : AnyObject]
|
|
let imageData = UIImage(data: data!)
|
|
self.userListings.append(
|
|
Listing(itemTitle: (listingInfo!["listingTitle"] as? String)!,
|
|
itemCategory: listingInfo!["listingCategory"] as? String,
|
|
itemPrice: listingInfo!["listingPrice"] as? String,
|
|
itemDescription: listingInfo!["listingDescription"] as? String,
|
|
itemImage: imageData!,
|
|
isDraftListing: (listingInfo!["isListingDraft"] as? Bool)!,
|
|
itemKey: keys,
|
|
networksSellingOn: (listingInfo!["networks"] as? Dictionary<String, Bool>)!
|
|
))
|
|
|
|
NSNotificationCenter.defaultCenter().postNotificationName("finished_fetching_listings", object: nil)
|
|
|
|
|
|
}
|
|
})
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
}
|
|
|
|
|
|
})
|
|
})
|
|
}
|
|
|
|
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 prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
|
|
// Get the new view controller using segue.destinationViewController.
|
|
// Pass the selected object to the new view controller.
|
|
}
|
|
|
|
|
|
}
|