You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
116 lines
3.8 KiB
116 lines
3.8 KiB
//
|
|
// MasterViewController.swift
|
|
// kplayer
|
|
//
|
|
// Created by Marco Schmickler on 24.05.15.
|
|
// Copyright (c) 2015 Marco Schmickler. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
import CoreData
|
|
|
|
class MasterViewController: UITableViewController {
|
|
|
|
var detailViewController: DetailViewController? = nil
|
|
|
|
var items = [MediaItem]()
|
|
|
|
override func awakeFromNib() {
|
|
super.awakeFromNib()
|
|
if UIDevice.currentDevice().userInterfaceIdiom == .Pad {
|
|
self.clearsSelectionOnViewWillAppear = false
|
|
self.preferredContentSize = CGSize(width: 320.0, height: 600.0)
|
|
}
|
|
}
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
|
|
NetworkManager.sharedInstance.loadDirs("/srv/samba/ren/knk_archiv4") { (g) in
|
|
var d = Dictionary<String, MediaItem>()
|
|
|
|
for f in g {
|
|
var p = d[f.path]
|
|
|
|
if p == nil {
|
|
p = MediaItem(name: "", path: f.path, root: f.root, type: ItemType.FOLDER)
|
|
d[f.path] = p!
|
|
println(p)
|
|
}
|
|
|
|
p!.children.append(f)
|
|
f.parent = p!
|
|
}
|
|
|
|
self.items = Array(d.values)
|
|
|
|
self.tableView.reloadData()
|
|
}
|
|
|
|
// Do any additional setup after loading the view, typically from a nib.
|
|
self.navigationItem.leftBarButtonItem = self.editButtonItem()
|
|
|
|
let addButton = UIBarButtonItem(barButtonSystemItem: .Add, target: self, action: "insertNewObject:")
|
|
self.navigationItem.rightBarButtonItem = addButton
|
|
if let split = self.splitViewController {
|
|
let controllers = split.viewControllers
|
|
self.detailViewController = controllers[controllers.count-1].topViewController as? DetailViewController
|
|
}
|
|
}
|
|
|
|
override func didReceiveMemoryWarning() {
|
|
super.didReceiveMemoryWarning()
|
|
// Dispose of any resources that can be recreated.
|
|
}
|
|
|
|
func insertNewObject(sender: AnyObject) {
|
|
}
|
|
|
|
// MARK: - Segues
|
|
|
|
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
|
|
if segue.identifier == "showDetail" {
|
|
if let indexPath = self.tableView.indexPathForSelectedRow() {
|
|
let object = items[indexPath.row]
|
|
let controller = (segue.destinationViewController as! UINavigationController).topViewController as! DetailViewController
|
|
controller.detailItem = object
|
|
controller.navigationItem.leftBarButtonItem = self.splitViewController?.displayModeButtonItem()
|
|
controller.navigationItem.leftItemsSupplementBackButton = true
|
|
}
|
|
}
|
|
}
|
|
|
|
// MARK: - Table View
|
|
|
|
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
|
|
return 1
|
|
}
|
|
|
|
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
|
return count(items)
|
|
}
|
|
|
|
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
|
|
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! UITableViewCell
|
|
self.configureCell(cell, atIndexPath: indexPath)
|
|
return cell
|
|
}
|
|
|
|
override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
|
|
// Return false if you do not want the specified item to be editable.
|
|
return false
|
|
}
|
|
|
|
override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
|
|
if editingStyle == .Delete {
|
|
}
|
|
}
|
|
|
|
func configureCell(cell: UITableViewCell, atIndexPath indexPath: NSIndexPath) {
|
|
let object = items[indexPath.row]
|
|
cell.textLabel!.text = object.path
|
|
}
|
|
|
|
|
|
}
|
|
|