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.
203 lines
7.1 KiB
203 lines
7.1 KiB
//
|
|
// Created by Marco Schmickler on 23.01.22.
|
|
// Copyright (c) 2022 Marco Schmickler. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
import UIKit
|
|
import SwiftUI
|
|
|
|
extension DetailViewController {
|
|
|
|
func showDetails(sectionItem: MediaItem, selectedItem: MediaItem, section: Int) {
|
|
if sectionItem.isVideo() {
|
|
showVideo(selectedItem: selectedItem)
|
|
} else if sectionItem.isPic() {
|
|
showPhotos(sectionItem.children, selectedItem: selectedItem, section: section)
|
|
} else if sectionItem.isWeb() {
|
|
showWeb(selectedItem: selectedItem)
|
|
} else if sectionItem.type == ItemType.DOWNLOAD {
|
|
showDownload(sectionItem: sectionItem)
|
|
}
|
|
}
|
|
|
|
func showPhotos(_ im: [MediaItem], selectedItem: MediaItem, section: Int) {
|
|
let base = MediaItem(name: "", path: "", root: "", type: ItemType.PICFOLDER)
|
|
base.children = im
|
|
if im.count < 1 {
|
|
return
|
|
}
|
|
let model = SPhotoModel(allItems: base.clone().children)
|
|
model.selectItem(selectedItem)
|
|
model.folderItems = detailItem!.children
|
|
model.folderIndex = section
|
|
|
|
let view = SPhotoAlbumView(completionHandler: { saved in
|
|
self.collectionView.reloadData()
|
|
self.collectionView.collectionViewLayout.invalidateLayout()
|
|
|
|
self.dismiss(animated: true, completion: nil);
|
|
}, model: model)
|
|
|
|
|
|
let pc = SelfSizingHostingController(rootView: view)
|
|
pc.view.backgroundColor = .black
|
|
|
|
getWindow().rootViewController!.definesPresentationContext = true
|
|
pc.modalPresentationStyle = .overCurrentContext
|
|
getWindow().rootViewController!.present(pc, animated: true)
|
|
}
|
|
|
|
func showPhotos2(_ im: [MediaItem]) {
|
|
let pc = MediaPhotoController()
|
|
|
|
pc.items = im
|
|
pc.completionHandler = {
|
|
self.dismiss(animated: true, completion: nil);
|
|
}
|
|
let navController = UINavigationController(rootViewController: pc) // Creating a navigation controller with pc at the root of the navigation stack.
|
|
navController.modalPresentationStyle = .fullScreen
|
|
|
|
self.present(navController, animated: false, completion: nil)
|
|
}
|
|
|
|
func showWeb(selectedItem: MediaItem) {
|
|
if selectedItem.name.contains("strip") {
|
|
|
|
let chromeURL = selectedItem.name.replacingOccurrences(of: "https://", with: "googlechrome://")
|
|
UIApplication.shared.open(URL(string: chromeURL)!)
|
|
|
|
return
|
|
}
|
|
var webView = KBrowserView(item: selectedItem.name)
|
|
|
|
webView.completionHandler = {
|
|
self.dismiss(animated: true, completion: nil);
|
|
}
|
|
|
|
let pc = SelfSizingHostingController(rootView: webView)
|
|
pc.view.backgroundColor = .black
|
|
|
|
getWindow().rootViewController!.definesPresentationContext = true
|
|
pc.modalPresentationStyle = .overCurrentContext
|
|
getWindow().rootViewController!.present(pc, animated: true)
|
|
}
|
|
|
|
func showWeb2(selectedItem: MediaItem) {
|
|
if selectedItem.name.contains("strip") {
|
|
|
|
let chromeURL = selectedItem.name.replacingOccurrences(of: "https://", with: "googlechrome://")
|
|
UIApplication.shared.open(URL(string: chromeURL)!)
|
|
|
|
return
|
|
}
|
|
let pc = BrowserController()
|
|
pc.setCurrentItem(item: selectedItem)
|
|
|
|
pc.completionHandler = {
|
|
self.dismiss(animated: true, completion: nil);
|
|
}
|
|
let navController = UINavigationController(rootViewController: pc) // Creating a navigation controller with pc at the root of the navigation stack.
|
|
navController.modalPresentationStyle = .fullScreen
|
|
|
|
self.present(navController, animated: false, completion: nil)
|
|
}
|
|
|
|
func showVideo(selectedItem: MediaItem) {
|
|
var se = selectedItem
|
|
var children = [MediaItem]()
|
|
var clonedChildren = [MediaItem]()
|
|
var baseItem = selectedItem
|
|
|
|
if baseItem.type == ItemType.SNAPSHOT {
|
|
baseItem = selectedItem.parent!
|
|
}
|
|
|
|
if baseItem.compilation && mode {
|
|
baseItem.compilation = false
|
|
baseItem.children.removeAll()
|
|
baseItem.loaded = false
|
|
baseItem.parent = nil
|
|
NetworkManager.sharedInstance.loadItem(baseItem, index: 0)
|
|
return
|
|
}
|
|
|
|
children = baseItem.children
|
|
clonedChildren = baseItem.clone().children
|
|
|
|
let model = SVideoModel(allItems: children, currentSnapshot: se, baseItem: baseItem)
|
|
|
|
model.edit = delegate!.settings().edit
|
|
model.slow = delegate!.settings().slow
|
|
model.zoomed = delegate!.settings().zoomed
|
|
model.jump = delegate!.settings().jump
|
|
|
|
let player = SVideoPlayer(completionHandler: { saved in
|
|
if saved {
|
|
baseItem.children = model.allItems
|
|
self.delegate!.saveItem(selectedItem: baseItem)
|
|
}
|
|
else {
|
|
baseItem.children = clonedChildren
|
|
}
|
|
|
|
self.collectionView.reloadData()
|
|
self.collectionView.collectionViewLayout.invalidateLayout()
|
|
|
|
self.dismiss(animated: true, completion: nil);
|
|
}, model: model)
|
|
player
|
|
|
|
let pc = SelfSizingHostingController(rootView: player)
|
|
pc.view.backgroundColor = .black
|
|
|
|
getWindow().rootViewController!.definesPresentationContext = true
|
|
pc.modalPresentationStyle = .overCurrentContext
|
|
getWindow().rootViewController!.present(pc, animated: true)
|
|
}
|
|
|
|
func showDownload(sectionItem: MediaItem) {
|
|
let cancelAlert = UIAlertController(title: "Abort Download", message: "All data will be lost.", preferredStyle: UIAlertController.Style.alert)
|
|
|
|
cancelAlert.addAction(UIAlertAction(title: "Ok", style: .default, handler: { (action: UIAlertAction!) in
|
|
sectionItem.cancelled = true
|
|
if sectionItem.length == 1.0 {
|
|
NetworkManager.sharedInstance.currentDownloads.removeValue(forKey: sectionItem.name)
|
|
}
|
|
}))
|
|
|
|
cancelAlert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: { (action: UIAlertAction!) in
|
|
print("Handle Cancel Logic here")
|
|
}))
|
|
|
|
self.present(cancelAlert, animated: true)
|
|
}
|
|
|
|
func showAllVideos(_ item: MediaItem) {
|
|
let composition = MediaItem(name: item.name, path: item.path, root: item.root, type: ItemType.VIDEO)
|
|
composition.compilation = true
|
|
|
|
for d in item.children {
|
|
if d.children.isEmpty {
|
|
let clone = d.clone()
|
|
clone.parent = composition
|
|
clone.type = ItemType.SNAPSHOT
|
|
composition.children.append(clone)
|
|
}
|
|
else {
|
|
for c in d.children {
|
|
let clone = c.clone()
|
|
clone.parent = composition
|
|
composition.children.append(clone)
|
|
}
|
|
}
|
|
}
|
|
|
|
showVideo(selectedItem: composition.children[0])
|
|
}
|
|
|
|
func getWindow() -> UIWindow {
|
|
let delegate2 = UIApplication.shared.delegate!
|
|
return delegate2.window as! UIWindow
|
|
}
|
|
}
|