|
|
|
@ -6,6 +6,7 @@ |
|
|
|
import Foundation |
|
|
|
import Nimbus |
|
|
|
import Haneke |
|
|
|
import Alamofire |
|
|
|
|
|
|
|
class MediaPhotoController: NIToolbarPhotoViewController, NIPhotoAlbumScrollViewDataSource, NIPhotoScrubberViewDataSource { |
|
|
|
|
|
|
|
@ -14,6 +15,10 @@ class MediaPhotoController: NIToolbarPhotoViewController, NIPhotoAlbumScrollView |
|
|
|
|
|
|
|
var requests = Array<ImageLoadOperation>() |
|
|
|
|
|
|
|
let THUMBS = "thumb" |
|
|
|
|
|
|
|
var imageCache = Cache<UIImage>(name: "thumbnails") |
|
|
|
|
|
|
|
lazy var operationQueue: NSOperationQueue = { |
|
|
|
var queue = NSOperationQueue() |
|
|
|
queue.name = "Photo queue" |
|
|
|
@ -22,6 +27,9 @@ class MediaPhotoController: NIToolbarPhotoViewController, NIPhotoAlbumScrollView |
|
|
|
}() |
|
|
|
|
|
|
|
override func viewDidLoad() { |
|
|
|
let thumbFormat = Format<UIImage>(name: THUMBS, diskCapacity: 100 * 1024 * 1024) |
|
|
|
imageCache.addFormat(thumbFormat) |
|
|
|
|
|
|
|
super.viewDidLoad() |
|
|
|
|
|
|
|
let backButton = UIBarButtonItem(barButtonSystemItem: .Cancel, target: self, action: Selector("back")) |
|
|
|
@ -39,10 +47,15 @@ class MediaPhotoController: NIToolbarPhotoViewController, NIPhotoAlbumScrollView |
|
|
|
|
|
|
|
let bsession = NSURLSession(configuration: back) |
|
|
|
|
|
|
|
var j=0; |
|
|
|
|
|
|
|
for i in items { |
|
|
|
if j++ > 1000 { |
|
|
|
break |
|
|
|
} |
|
|
|
let URL = NSURL(string: i.thumbUrlAbsolute)! |
|
|
|
let fetcher = MediaFetcher<UIImage>(URL: URL, session: bsession) |
|
|
|
let fetch = Shared.imageCache.fetch(fetcher: fetcher, formatName: HanekeGlobals.Cache.OriginalFormatName, failure: nil, success: nil) |
|
|
|
let fetch = imageCache.fetch(fetcher: fetcher, formatName: THUMBS, failure: nil, success: nil) |
|
|
|
|
|
|
|
fetch.onSuccess { |
|
|
|
s in |
|
|
|
@ -51,16 +64,87 @@ class MediaPhotoController: NIToolbarPhotoViewController, NIPhotoAlbumScrollView |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
override func didReceiveMemoryWarning() { |
|
|
|
println("warning") |
|
|
|
super.didReceiveMemoryWarning() |
|
|
|
// Dispose of any resources that can be recreated. |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func back() { |
|
|
|
completionHandler!() |
|
|
|
} |
|
|
|
|
|
|
|
func play() { |
|
|
|
let currentItem = items[photoAlbumView.centerPageIndex] |
|
|
|
|
|
|
|
if (currentItem.type == ItemType.PICS) { |
|
|
|
let items = currentItem |
|
|
|
|
|
|
|
let len = count(items.root) |
|
|
|
let url = NetworkManager.sharedInstance.baseurl + "/service/listfiles" + items.root + "/" + items.path + "/" + items.name |
|
|
|
|
|
|
|
println(items) |
|
|
|
println(url) |
|
|
|
|
|
|
|
Alamofire.request(.GET, url).responseSwiftyJSON({ |
|
|
|
(request, response, json, error) in |
|
|
|
|
|
|
|
var im = [MediaItem]() |
|
|
|
var hashes = Dictionary<String, String>() |
|
|
|
|
|
|
|
for (a, c) in json { |
|
|
|
// let (a,b) = j # |
|
|
|
let s = c.object as! NSString |
|
|
|
|
|
|
|
if s.hasSuffix(".jpg") { |
|
|
|
let l = s.length |
|
|
|
let name = (s as NSString).lastPathComponent |
|
|
|
var pathlen = l - len - count(name) |
|
|
|
|
|
|
|
// if (pathlen > 1000) { |
|
|
|
println(pathlen) |
|
|
|
println(name) |
|
|
|
println(s) |
|
|
|
// } |
|
|
|
if (pathlen < 2) { |
|
|
|
pathlen = 2 |
|
|
|
} |
|
|
|
|
|
|
|
let path = (s as NSString).substringWithRange(NSMakeRange(len + 1, pathlen - 2)) |
|
|
|
|
|
|
|
let folderName = path.lastPathComponent |
|
|
|
let fl = count(path) |
|
|
|
let pfl = fl - count(folderName) |
|
|
|
|
|
|
|
println("\(folderName) \(pfl)") |
|
|
|
let fpath = (s as NSString).substringWithRange(NSMakeRange(0, pfl)) |
|
|
|
|
|
|
|
let i = MediaItem(name: folderName, path: fpath, root: items.root, type: ItemType.PICS) |
|
|
|
i.thumbUrl = "\(s)?preview=true" |
|
|
|
if !name.hasPrefix(".") { |
|
|
|
im.append(i) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
let pc = MediaPhotoController() |
|
|
|
|
|
|
|
pc.items = im |
|
|
|
pc.completionHandler = { |
|
|
|
self.dismissViewControllerAnimated(true, completion: nil); |
|
|
|
} |
|
|
|
let navController = UINavigationController(rootViewController: pc) // Creating a navigation controller with pc at the root of the navigation stack. |
|
|
|
|
|
|
|
self.presentViewController(navController, animated: false, completion: nil) |
|
|
|
}) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
let controller = VideoPlayerController() |
|
|
|
controller.edit = false |
|
|
|
controller.allowEdit = false |
|
|
|
|
|
|
|
let currentItem = items[photoAlbumView.centerPageIndex] |
|
|
|
controller.currentItem = currentItem |
|
|
|
controller.navigationItem.leftItemsSupplementBackButton = true |
|
|
|
navigationController!.navigationBar.barTintColor = UIColor.blackColor() |
|
|
|
@ -110,7 +194,7 @@ class MediaPhotoController: NIToolbarPhotoViewController, NIPhotoAlbumScrollView |
|
|
|
|
|
|
|
var size = NIPhotoScrollViewPhotoSizeUnknown |
|
|
|
|
|
|
|
Shared.imageCache.fetch(key: URL.absoluteString!, formatName: HanekeGlobals.Cache.OriginalFormatName).onSuccess { |
|
|
|
imageCache.fetch(key: URL.absoluteString!, formatName: THUMBS).onSuccess { |
|
|
|
i in |
|
|
|
image = i |
|
|
|
size = NIPhotoScrollViewPhotoSizeThumbnail |
|
|
|
@ -121,12 +205,11 @@ class MediaPhotoController: NIToolbarPhotoViewController, NIPhotoAlbumScrollView |
|
|
|
isLoading[0] = false |
|
|
|
} else { |
|
|
|
let fetcher = NetworkFetcher<UIImage>(URL: URL) |
|
|
|
let fetch = Shared.imageCache.fetch(fetcher: fetcher, formatName: HanekeGlobals.Cache.OriginalFormatName, failure: nil, success: nil) |
|
|
|
let fetch = imageCache.fetch(fetcher: fetcher, formatName: THUMBS, failure: nil, success: nil) |
|
|
|
|
|
|
|
fetch.onSuccess { |
|
|
|
i in |
|
|
|
println("thumb loaded \(newItem.imageUrlAbsolute)") |
|
|
|
image = i |
|
|
|
size = NIPhotoScrollViewPhotoSizeThumbnail |
|
|
|
self.photoAlbumView.didLoadPhoto(image, atIndex: photoAtIndex, photoSize: size) |
|
|
|
} |
|
|
|
@ -207,16 +290,16 @@ class MediaPhotoController: NIToolbarPhotoViewController, NIPhotoAlbumScrollView |
|
|
|
let newItem = items[thumbnailIndex] |
|
|
|
let URL = NSURL(string: newItem.thumbUrlAbsolute)! |
|
|
|
|
|
|
|
var image: UIImage? = nil |
|
|
|
let fetcher = NetworkFetcher<UIImage>(URL: URL) |
|
|
|
let fetch = imageCache.fetch(fetcher: fetcher, formatName: THUMBS, failure: nil, success: nil) |
|
|
|
|
|
|
|
Shared.imageCache.fetch(URL: URL).onSuccess { |
|
|
|
fetch.onSuccess { |
|
|
|
i in |
|
|
|
image = i |
|
|
|
|
|
|
|
self.photoScrubberView.didLoadThumbnail(i, atIndex: thumbnailIndex); |
|
|
|
} |
|
|
|
|
|
|
|
return image |
|
|
|
return nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|