Эх сурвалжийг харах

Change setSubtitleToolbarIcon behavior

Signed-off-by: marinofaggiana <ios@nextcloud.com>
marinofaggiana 3 жил өмнө
parent
commit
bbf4ac27c3

+ 0 - 8
Nextcloud.xcodeproj/project.pbxproj

@@ -392,9 +392,7 @@
 		F7EFC0CD256BF8DD00461AAD /* NCUserStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7EFC0CC256BF8DD00461AAD /* NCUserStatus.swift */; };
 		F7F1E54C2492369A00E42386 /* NCMediaCommandView.xib in Resources */ = {isa = PBXBuildFile; fileRef = F7F1E54B2492369A00E42386 /* NCMediaCommandView.xib */; };
 		F7F4F0F727ECDBA4008676F9 /* NCSubtitles.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7F4F0F327ECDBA4008676F9 /* NCSubtitles.swift */; };
-		F7F4F0F827ECDBA4008676F9 /* NCPlayerToolBar+SubtitlePlayerToolBarDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7F4F0F427ECDBA4008676F9 /* NCPlayerToolBar+SubtitlePlayerToolBarDelegate.swift */; };
 		F7F4F0F927ECDBA4008676F9 /* NCSubtitlePlayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7F4F0F527ECDBA4008676F9 /* NCSubtitlePlayer.swift */; };
-		F7F4F0FA27ECDBA4008676F9 /* NCSubtitlePlayer+PlayerSubtitleDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7F4F0F627ECDBA4008676F9 /* NCSubtitlePlayer+PlayerSubtitleDelegate.swift */; };
 		F7F4F10527ECDBDB008676F9 /* Inconsolata-SemiBold.ttf in Resources */ = {isa = PBXBuildFile; fileRef = F7F4F0FD27ECDBDB008676F9 /* Inconsolata-SemiBold.ttf */; };
 		F7F4F10627ECDBDB008676F9 /* Inconsolata-Medium.ttf in Resources */ = {isa = PBXBuildFile; fileRef = F7F4F0FE27ECDBDB008676F9 /* Inconsolata-Medium.ttf */; };
 		F7F4F10727ECDBDB008676F9 /* Inconsolata-Black.ttf in Resources */ = {isa = PBXBuildFile; fileRef = F7F4F0FF27ECDBDB008676F9 /* Inconsolata-Black.ttf */; };
@@ -916,9 +914,7 @@
 		F7F1E54B2492369A00E42386 /* NCMediaCommandView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = NCMediaCommandView.xib; sourceTree = "<group>"; };
 		F7F35B592578FB63003F5589 /* CollaboraOnlineWebViewKeyboardManager.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CollaboraOnlineWebViewKeyboardManager.framework; path = Carthage/Build/iOS/CollaboraOnlineWebViewKeyboardManager.framework; sourceTree = "<group>"; };
 		F7F4F0F327ECDBA4008676F9 /* NCSubtitles.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NCSubtitles.swift; sourceTree = "<group>"; };
-		F7F4F0F427ECDBA4008676F9 /* NCPlayerToolBar+SubtitlePlayerToolBarDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NCPlayerToolBar+SubtitlePlayerToolBarDelegate.swift"; sourceTree = "<group>"; };
 		F7F4F0F527ECDBA4008676F9 /* NCSubtitlePlayer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NCSubtitlePlayer.swift; sourceTree = "<group>"; };
-		F7F4F0F627ECDBA4008676F9 /* NCSubtitlePlayer+PlayerSubtitleDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NCSubtitlePlayer+PlayerSubtitleDelegate.swift"; sourceTree = "<group>"; };
 		F7F4F0FD27ECDBDB008676F9 /* Inconsolata-SemiBold.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Inconsolata-SemiBold.ttf"; sourceTree = "<group>"; };
 		F7F4F0FE27ECDBDB008676F9 /* Inconsolata-Medium.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Inconsolata-Medium.ttf"; sourceTree = "<group>"; };
 		F7F4F0FF27ECDBDB008676F9 /* Inconsolata-Black.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Inconsolata-Black.ttf"; sourceTree = "<group>"; };
@@ -1693,9 +1689,7 @@
 			isa = PBXGroup;
 			children = (
 				F7F4F0F327ECDBA4008676F9 /* NCSubtitles.swift */,
-				F7F4F0F427ECDBA4008676F9 /* NCPlayerToolBar+SubtitlePlayerToolBarDelegate.swift */,
 				F7F4F0F527ECDBA4008676F9 /* NCSubtitlePlayer.swift */,
-				F7F4F0F627ECDBA4008676F9 /* NCSubtitlePlayer+PlayerSubtitleDelegate.swift */,
 			);
 			path = NCSubtitle;
 			sourceTree = "<group>";
@@ -2537,7 +2531,6 @@
 				F70753F12542A9A200972D44 /* NCViewerMedia.swift in Sources */,
 				F7A80BCB252624C100C7CD01 /* NCFileViewInFolder.swift in Sources */,
 				F78A18B823CDE2B300F681F3 /* NCViewerRichWorkspace.swift in Sources */,
-				F7F4F0FA27ECDBA4008676F9 /* NCSubtitlePlayer+PlayerSubtitleDelegate.swift in Sources */,
 				F77910AB25DD53C700CEDB9E /* NCSettingsBundleHelper.swift in Sources */,
 				AF4BF61927562A4B0081CEEF /* NCManageDatabase+Metadata.swift in Sources */,
 				F78A18B623CDD07D00F681F3 /* NCViewerRichWorkspaceWebView.swift in Sources */,
@@ -2637,7 +2630,6 @@
 				F7CBC31C24F78E79004D3812 /* NCSortMenu.swift in Sources */,
 				F769454822E9F20D000A798A /* NCShareNetworking.swift in Sources */,
 				F7C9555521F0C5470024296E /* NCActivity.swift in Sources */,
-				F7F4F0F827ECDBA4008676F9 /* NCPlayerToolBar+SubtitlePlayerToolBarDelegate.swift in Sources */,
 				F7725A60251F33BB00D125E0 /* NCFiles.swift in Sources */,
 				F704B5E52430AA8000632F5F /* NCCreateFormUploadConflict.swift in Sources */,
 				F765608F23BF813600765969 /* NCContentPresenter.swift in Sources */,

+ 2 - 0
iOSClient/Supporting Files/en.lproj/Localizable.strings

@@ -847,3 +847,5 @@
 "_conversion_max_compatibility_"    = "Max compatibility, the conversion can take much longer";
 "_video_tap_for_close_"     = "A slight pressure to close the processing";
 "_subtitle_not_found_"      = "Subtitle not found";
+"_disable_"                 = "Disable";
+

+ 0 - 7
iOSClient/Viewer/NCViewerMedia/NCPlayer/NCPlayer.swift

@@ -50,12 +50,6 @@ class NCPlayer: NSObject {
     public var durationTime: CMTime = .zero
     public var metadata: tableMetadata
     public var videoLayer: AVPlayerLayer?
-
-    public var isSubtitleShowed: Bool = false{
-        didSet {
-            self.playerToolBar?.changeSubtitleIconTo(visible: isSubtitleShowed)
-        }
-    }
     public var subtitleUrls: [URL] = []
 
     // MARK: - View Life Cycle
@@ -116,7 +110,6 @@ class NCPlayer: NSObject {
 
         playerToolBar?.show()
         setUpForSubtitle()
-        isSubtitleShowed = false
 
         print("Play URL: \(self.url)")
         player = AVPlayer(url: self.url)

+ 3 - 3
iOSClient/Viewer/NCViewerMedia/NCPlayer/NCPlayerToolBar.swift

@@ -84,8 +84,8 @@ class NCPlayerToolBar: UIView {
         muteButton.setImage(NCUtility.shared.loadImage(named: "audioOff", color: .lightGray), for: .normal)
         muteButton.isEnabled = false
 
-        subtitleButton.setImage(NCUtility.shared.loadImage(named: "captions.bubble", color: .lightGray), for: .normal)
-        subtitleButton.isEnabled = false
+        subtitleButton.setImage(NCUtility.shared.loadImage(named: "captions.bubble", color: .white), for: .normal)
+        subtitleButton.isEnabled = true
         subtitleButton.isHidden = true
 
         playbackSlider.value = 0
@@ -496,7 +496,7 @@ class NCPlayerToolBar: UIView {
     }
 
     @IBAction func tapSubtitle(_ sender: Any) {
-        self.subtitleIconTapped()
+        self.ncplayer?.showAlertSubtitles()
     }
 
     func forward() {

+ 0 - 56
iOSClient/Viewer/NCViewerMedia/NCPlayer/NCSubtitle/NCPlayerToolBar+SubtitlePlayerToolBarDelegate.swift

@@ -1,56 +0,0 @@
-//
-//  NCPlayerToolBar+SubtitlePlayerToolBarDelegate.swift
-//  Nextcloud
-//
-//  Created by Federico Malagoni on 11/03/22.
-//  Copyright © 2022 Marino Faggiana. All rights reserved.
-//
-//  Author Marino Faggiana <marino.faggiana@nextcloud.com>
-//
-//  This program is free software: you can redistribute it and/or modify
-//  it under the terms of the GNU General Public License as published by
-//  the Free Software Foundation, either version 3 of the License, or
-//  (at your option) any later version.
-//
-//  This program is distributed in the hope that it will be useful,
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-//  GNU General Public License for more details.
-//
-//  You should have received a copy of the GNU General Public License
-//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
-//
-
-import Foundation
-
-protocol SubtitlePlayerToolBarDelegate: AnyObject {
-    func subtitleIconTapped()
-    func changeSubtitleIconTo(visible: Bool)
-    func showIconSubtitle()
-}
-
-extension NCPlayerToolBar: SubtitlePlayerToolBarDelegate {
-
-    func subtitleIconTapped() {
-
-        self.ncplayer?.hideOrShowSubtitle()
-    }
-
-    func changeSubtitleIconTo(visible: Bool) {
-
-        let color: UIColor = visible ? .white : .lightGray
-        self.subtitleButton.setImage(NCUtility.shared.loadImage(named: "captions.bubble", color: color), for: .normal)
-    }
-
-    func showIconSubtitle() {
-
-        self.subtitleButton.isEnabled = true
-        self.subtitleButton.isHidden = false
-    }
-
-    func hideIconSubtitle() {
-
-        self.subtitleButton.isEnabled = false
-        self.subtitleButton.isHidden = true
-    }
-}

+ 0 - 94
iOSClient/Viewer/NCViewerMedia/NCPlayer/NCSubtitle/NCSubtitlePlayer+PlayerSubtitleDelegate.swift

@@ -1,94 +0,0 @@
-//
-//  NCSubtitlePlayer+PlayerSubtitleDelegate.swift
-//  Nextcloud
-//
-//  Created by Federico Malagoni on 11/03/22.
-//  Copyright © 2022 Marino Faggiana. All rights reserved.
-//
-//  Author Marino Faggiana <marino.faggiana@nextcloud.com>
-//
-//  This program is free software: you can redistribute it and/or modify
-//  it under the terms of the GNU General Public License as published by
-//  the Free Software Foundation, either version 3 of the License, or
-//  (at your option) any later version.
-//
-//  This program is distributed in the hope that it will be useful,
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-//  GNU General Public License for more details.
-//
-//  You should have received a copy of the GNU General Public License
-//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
-//
-
-import Foundation
-import NCCommunication
-import UIKit
-import AVFoundation
-import MediaPlayer
-import Alamofire
-import RealmSwift
-
-public protocol PlayerSubtitleDelegate: AnyObject {
-    func hideOrShowSubtitle()
-    func showAlertSubtitles()
-}
-
-extension NCPlayer: PlayerSubtitleDelegate {
-
-    func hideOrShowSubtitle() {
-        if self.isSubtitleShowed {
-            self.hideSubtitle()
-            self.isSubtitleShowed = false
-        } else {
-            self.showAlertSubtitles()
-        }
-    }
-
-    internal func showAlertSubtitles() {
-
-        let alert = UIAlertController(title: nil, message: NSLocalizedString("_subtitle_", comment: ""), preferredStyle: .actionSheet)
-
-        for url in subtitleUrls {
-
-            print("Play Subtitle at:\n\(url.path)")
-
-            let videoUrlTitle = self.metadata.fileName.alphanumeric.dropLast(3)
-            let subtitleUrlTitle = url.lastPathComponent.alphanumeric.dropLast(3)
-
-            var titleSubtitle = String(subtitleUrlTitle.dropFirst(videoUrlTitle.count))
-            if titleSubtitle.isEmpty {
-                titleSubtitle = NSLocalizedString("_subtitle_", comment: "")
-            }
-
-            alert.addAction(UIAlertAction(title: titleSubtitle, style: .default, handler: { [self] _ in
-
-                if NCUtilityFileSystem.shared.getFileSize(filePath: url.path) > 0 {
-
-                    self.open(fileFromLocal: url)
-                    if let viewController = viewController {
-                        self.addSubtitlesTo(viewController, self.playerToolBar)
-                        self.isSubtitleShowed = true
-                        self.showSubtitle()
-                    }
-
-                } else {
-
-                    let alertError = UIAlertController(title: NSLocalizedString("_error_", comment: ""), message: NSLocalizedString("_subtitle_not_found_", comment: ""), preferredStyle: .alert)
-                    alertError.addAction(UIKit.UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .default, handler: nil))
-
-                    viewController?.present(alertError, animated: true, completion: nil)
-                    self.isSubtitleShowed = false
-                }
-            }))
-        }
-
-        alert.addAction(UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel, handler: { _ in
-            self.isSubtitleShowed = false
-        }))
-
-        alert.popoverPresentationController?.sourceView = self.viewController?.view
-
-        self.viewController?.present(alert, animated: true, completion: nil)
-    }
-}

+ 50 - 3
iOSClient/Viewer/NCViewerMedia/NCPlayer/NCSubtitle/NCSubtitlePlayer.swift

@@ -133,14 +133,13 @@ extension NCPlayer {
         }
         self.setSubtitleToolbarIcon(subtitleUrls: subtitleUrls)
         self.hideSubtitle()
-        self.isSubtitleShowed = false
     }
 
     func setSubtitleToolbarIcon(subtitleUrls: [URL]) {
         if subtitleUrls.isEmpty {
-            self.playerToolBar?.hideIconSubtitle()
+            playerToolBar?.subtitleButton.isHidden = true
         } else {
-            self.playerToolBar?.showIconSubtitle()
+            playerToolBar?.subtitleButton.isHidden = false
         }
     }
 
@@ -340,4 +339,52 @@ extension NCPlayer {
         vc.view?.addConstraint(subtitleLabelWidthConstraint!)
         vc.view?.addConstraint(subtitleLabelBottomConstraint!)
     }
+
+    internal func showAlertSubtitles() {
+
+        let alert = UIAlertController(title: nil, message: NSLocalizedString("_subtitle_", comment: ""), preferredStyle: .actionSheet)
+
+        for url in subtitleUrls {
+
+            print("Play Subtitle at:\n\(url.path)")
+
+            let videoUrlTitle = self.metadata.fileName.alphanumeric.dropLast(3)
+            let subtitleUrlTitle = url.lastPathComponent.alphanumeric.dropLast(3)
+
+            var titleSubtitle = String(subtitleUrlTitle.dropFirst(videoUrlTitle.count))
+            if titleSubtitle.isEmpty {
+                titleSubtitle = NSLocalizedString("_subtitle_", comment: "")
+            }
+
+            alert.addAction(UIAlertAction(title: titleSubtitle, style: .default, handler: { [self] _ in
+
+                if NCUtilityFileSystem.shared.getFileSize(filePath: url.path) > 0 {
+
+                    self.open(fileFromLocal: url)
+                    if let viewController = viewController {
+                        self.addSubtitlesTo(viewController, self.playerToolBar)
+                        self.showSubtitle()
+                    }
+
+                } else {
+
+                    let alertError = UIAlertController(title: NSLocalizedString("_error_", comment: ""), message: NSLocalizedString("_subtitle_not_found_", comment: ""), preferredStyle: .alert)
+                    alertError.addAction(UIKit.UIAlertAction(title: NSLocalizedString("_ok_", comment: ""), style: .default, handler: nil))
+
+                    viewController?.present(alertError, animated: true, completion: nil)
+                }
+            }))
+        }
+
+        alert.addAction(UIAlertAction(title: NSLocalizedString("_disable_", comment: ""), style: .destructive, handler: { _ in
+            self.hideSubtitle()
+        }))
+
+        alert.addAction(UIAlertAction(title: NSLocalizedString("_cancel_", comment: ""), style: .cancel, handler: { _ in
+        }))
+
+        alert.popoverPresentationController?.sourceView = self.viewController?.view
+
+        self.viewController?.present(alert, animated: true, completion: nil)
+    }
 }