|
|
|
@ -18,11 +18,12 @@ protocol MasterDelegate : DetailDelegate { |
|
|
|
func loadItem(selectedItem: MediaItem, completionHandler: @escaping (MediaItem) -> Void) |
|
|
|
} |
|
|
|
|
|
|
|
class MasterViewController: UITableViewController, UISearchResultsUpdating { |
|
|
|
class MasterViewController: UITableViewController, UISearchResultsUpdating, UITableViewDropDelegate { |
|
|
|
let searchController = UISearchController(searchResultsController: nil) |
|
|
|
let model = ItemModel() |
|
|
|
var delegate : MasterDelegate? |
|
|
|
var detailDelegate : DetailDelegate? |
|
|
|
var detailController : DetailViewController? |
|
|
|
|
|
|
|
var authenticated = false |
|
|
|
|
|
|
|
@ -39,6 +40,7 @@ class MasterViewController: UITableViewController, UISearchResultsUpdating { |
|
|
|
searchController.dimsBackgroundDuringPresentation = false |
|
|
|
definesPresentationContext = true |
|
|
|
tableView.tableHeaderView = searchController.searchBar |
|
|
|
tableView.dropDelegate = self |
|
|
|
} |
|
|
|
|
|
|
|
override func didReceiveMemoryWarning() { |
|
|
|
@ -92,6 +94,29 @@ class MasterViewController: UITableViewController, UISearchResultsUpdating { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
func createFolder(_ item: MediaItem) { |
|
|
|
let ac = UIAlertController(title: "Enter new folder name", message: nil, preferredStyle: .alert) |
|
|
|
ac.addTextField() |
|
|
|
|
|
|
|
let submitAction = UIAlertAction(title: "Submit", style: .default) { [unowned ac] _ in |
|
|
|
let answer = ac.textFields![0].text! |
|
|
|
|
|
|
|
do { |
|
|
|
try FileHelper.createDir(name: answer) |
|
|
|
item.name = answer |
|
|
|
item.path = answer |
|
|
|
self.tableView.reloadData() |
|
|
|
} catch { |
|
|
|
print(error) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
ac.addAction(submitAction) |
|
|
|
ac.addAction(UIAlertAction(title: "cancel", style: .cancel)) |
|
|
|
|
|
|
|
present(ac, animated: true) |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Item ausgewaehlt |
|
|
|
*/ |
|
|
|
@ -105,6 +130,11 @@ class MasterViewController: UITableViewController, UISearchResultsUpdating { |
|
|
|
|
|
|
|
let selectedItem = model.items[indexPath.row] |
|
|
|
|
|
|
|
if (selectedItem.local && selectedItem.name == "new") { |
|
|
|
createFolder(selectedItem) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
if selectedItem.isDetails() { |
|
|
|
gotoDetails(selectedItem) |
|
|
|
return |
|
|
|
@ -156,6 +186,7 @@ class MasterViewController: UITableViewController, UISearchResultsUpdating { |
|
|
|
let controller = (segue.destination as! UINavigationController).topViewController as! DetailViewController |
|
|
|
controller.detailItem = item |
|
|
|
controller.delegate = delegate |
|
|
|
detailController = controller |
|
|
|
|
|
|
|
if item.isPic() { |
|
|
|
// größere Vorschau für Fotos |
|
|
|
@ -209,5 +240,91 @@ class MasterViewController: UITableViewController, UISearchResultsUpdating { |
|
|
|
|
|
|
|
cell.accessoryType = UITableViewCell.AccessoryType.none |
|
|
|
} |
|
|
|
|
|
|
|
func tableView(_ tableView: UITableView, dropSessionDidUpdate session: UIDropSession, withDestinationIndexPath destinationIndexPath: IndexPath?) -> UITableViewDropProposal { |
|
|
|
|
|
|
|
if tableView.indexPathForSelectedRow == destinationIndexPath { |
|
|
|
return UITableViewDropProposal(operation: .forbidden) |
|
|
|
} |
|
|
|
|
|
|
|
if let d = destinationIndexPath { |
|
|
|
if model.items.count <= d.row { |
|
|
|
return UITableViewDropProposal(operation: .forbidden) |
|
|
|
} |
|
|
|
if (model.items[d.row].path == "new") { |
|
|
|
return UITableViewDropProposal(operation: .forbidden) |
|
|
|
} |
|
|
|
if (!model.items[d.row].local) { |
|
|
|
return UITableViewDropProposal(operation: .forbidden) |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
return UITableViewDropProposal(operation: .forbidden) |
|
|
|
} |
|
|
|
|
|
|
|
if session.canLoadObjects(ofClass: NSString.self) { |
|
|
|
return UITableViewDropProposal(operation: .move, intent: .insertAtDestinationIndexPath) |
|
|
|
} else { |
|
|
|
return UITableViewDropProposal(operation: .forbidden) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
func tableView(_ tableView: UITableView, performDropWith coordinator: UITableViewDropCoordinator) { |
|
|
|
let destinationIndexPath: IndexPath |
|
|
|
|
|
|
|
if let indexPath = coordinator.destinationIndexPath { |
|
|
|
destinationIndexPath = indexPath |
|
|
|
} else { |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
// attempt to load strings from the drop coordinator |
|
|
|
let progress = coordinator.session.loadObjects(ofClass: NSString.self) { items in |
|
|
|
// convert the item provider array to a string array or bail out |
|
|
|
guard let strings = items as? [String] else { return } |
|
|
|
|
|
|
|
let r = destinationIndexPath.row |
|
|
|
if r < self.model.items.count { |
|
|
|
let destinationItem = self.model.items[r] |
|
|
|
|
|
|
|
// loop over all the strings we received |
|
|
|
for (index, string) in strings.enumerated() { |
|
|
|
print(string) |
|
|
|
|
|
|
|
let items = try! JSONDecoder().decode(MediaModel.self, from: string.data(using: .utf8)!) |
|
|
|
let m = MediaItem(model: items) |
|
|
|
m.local = true |
|
|
|
let at = m.playerURL! |
|
|
|
m.path = destinationItem.path |
|
|
|
let to = m.playerURL! |
|
|
|
print(destinationItem.name) |
|
|
|
|
|
|
|
do { |
|
|
|
try FileManager.default.moveItem(at: at, to: to) |
|
|
|
try FileManager.default.moveItem(at: at.appendingPathExtension("json"), to: to.appendingPathExtension("json")) |
|
|
|
|
|
|
|
let weiter:Weiter = { |
|
|
|
(g) in |
|
|
|
let fav = NetworkManager.sharedInstance.favorites |
|
|
|
ItemModel().sortItems(selectedItem: fav, children: g) |
|
|
|
self.model.items = fav.children |
|
|
|
|
|
|
|
|
|
|
|
if let s = tableView.indexPathForSelectedRow { |
|
|
|
let refreshed = self.model.items[s.row] |
|
|
|
self.detailController!.detailItem = refreshed |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
NetworkManager.sharedInstance.loadFavDirs("", completionHandler: weiter) |
|
|
|
} catch { |
|
|
|
print(error) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|