14 changed files with 358 additions and 308 deletions
-
8kplayer.xcodeproj/project.pbxproj
-
2kplayer/AppDelegate.swift
-
7kplayer/core/DatabaseManager.swift
-
2kplayer/core/ItemModel.swift
-
15kplayer/core/ItemType.swift
-
47kplayer/core/LocalManager.swift
-
7kplayer/core/MediaItem.swift
-
6kplayer/core/NetworkManager.swift
-
12kplayer/detail/BrowserController.swift
-
143kplayer/detail/DetailViewController+Show.swift
-
180kplayer/detail/DetailViewController.swift
-
201kplayer/master/MasterViewController.swift
-
13kplayer/master/NetworkDelegate.swift
-
21kplayer/util/UIViewController+Alert.swift
@ -0,0 +1,143 @@ |
|||
// |
|||
// 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) { |
|||
if sectionItem.isVideo() { |
|||
showVideo(selectedItem: selectedItem) |
|||
} else if sectionItem.isPic() { |
|||
showPhotos(sectionItem.children) |
|||
} else if sectionItem.isWeb() { |
|||
showWeb(selectedItem: selectedItem) |
|||
} else if sectionItem.type == ItemType.DOWNLOAD { |
|||
showDownload(sectionItem: sectionItem) |
|||
} |
|||
} |
|||
|
|||
func showPhotos(_ 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 |
|||
} |
|||
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! |
|||
} |
|||
|
|||
children = baseItem.children |
|||
clonedChildren = baseItem.clone().children |
|||
|
|||
let model = SVideoModel(allItems: children, currentSnapshot: se, baseItem: baseItem) |
|||
|
|||
model.edit = delegate!.settings().edit |
|||
model.loop = delegate!.settings().autoloop |
|||
model.zoomed = delegate!.settings().zoomed |
|||
|
|||
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 = UIHostingController(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) |
|||
|
|||
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 |
|||
} |
|||
} |
|||
@ -0,0 +1,21 @@ |
|||
// |
|||
// Created by Marco Schmickler on 23.01.22. |
|||
// Copyright (c) 2022 Marco Schmickler. All rights reserved. |
|||
// |
|||
|
|||
import Foundation |
|||
import UIKit |
|||
|
|||
extension UIViewController { |
|||
func showAlert(title:String, message:String ) { |
|||
|
|||
let alertVC = UIAlertController(title: title, message: message, preferredStyle: .alert) |
|||
|
|||
let okAction = UIAlertAction(title: "Ok", style: .default, handler: nil) |
|||
alertVC.addAction(okAction) |
|||
|
|||
DispatchQueue.main.async() { () -> Void in |
|||
self.present(alertVC, animated: true, completion: nil) |
|||
} |
|||
} |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue