123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- import Foundation
- class NCViewer: NSObject {
- @objc static let shared: NCViewer = {
- let instance = NCViewer()
- return instance
- }()
-
- let appDelegate = UIApplication.shared.delegate as! AppDelegate
- private var viewerQuickLook: NCViewerQuickLook?
-
- func view(viewController: UIViewController, metadata: tableMetadata) {
-
- if metadata.typeFile == k_metadataTypeFile_audio || metadata.typeFile == k_metadataTypeFile_video {
-
- if let navigationController = getPushNavigationController(viewController: viewController, serverUrl: metadata.serverUrl) {
- let viewController:NCViewerVideo = UIStoryboard(name: "NCViewerVideo", bundle: nil).instantiateInitialViewController() as! NCViewerVideo
-
- viewController.metadata = metadata
- navigationController.pushViewController(viewController, animated: true)
- }
- return
- }
-
-
- if metadata.typeFile == k_metadataTypeFile_document {
-
-
- if metadata.contentType == "application/pdf" {
-
- if let navigationController = getPushNavigationController(viewController: viewController, serverUrl: metadata.serverUrl) {
- let viewController:NCViewerPDF = UIStoryboard(name: "NCViewerPDF", bundle: nil).instantiateInitialViewController() as! NCViewerPDF
-
- viewController.metadata = metadata
-
- navigationController.pushViewController(viewController, animated: true)
- }
- return
- }
- }
-
-
- let fileNamePath = NSTemporaryDirectory() + metadata.fileNameView
- CCUtility.copyFile(atPath: CCUtility.getDirectoryProviderStorageOcId(metadata.ocId, fileNameView: metadata.fileNameView), toPath: fileNamePath)
- viewerQuickLook = NCViewerQuickLook.init()
- viewerQuickLook?.quickLook(url: URL(fileURLWithPath: fileNamePath))
- }
-
- private func getPushNavigationController(viewController: UIViewController, serverUrl: String) -> UINavigationController? {
-
- if viewController is NCFiles || viewController is NCFavorite || viewController is NCOffline || viewController is NCRecent || viewController is NCFileViewInFolder {
- if serverUrl == appDelegate.activeServerUrl {
- return viewController.navigationController
- }
- }
- return nil
- }
- }
- extension NCViewer: NCSelectDelegate {
-
- func dismissSelect(serverUrl: String?, metadata: tableMetadata?, type: String, items: [Any], buttonType: String, overwrite: Bool) {
- if let metadata = metadata, let serverUrl = serverUrl {
- if buttonType == "done" {
- NCNetworking.shared.moveMetadata(metadata, serverUrlTo: serverUrl, overwrite: overwrite) { (errorCode, errorDescription) in
- if errorCode != 0 {
- NCContentPresenter.shared.messageNotification("_error_", description: errorDescription, delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: errorCode)
- }
- }
- } else {
- NCNetworking.shared.copyMetadata(metadata, serverUrlTo: serverUrl, overwrite: overwrite) { (errorCode, errorDescription) in
- if errorCode != 0 {
- NCContentPresenter.shared.messageNotification("_error_", description: errorDescription, delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.error, errorCode: errorCode)
- }
- }
- }
- }
- }
- }
|