marinofaggiana 6 years ago
parent
commit
b7983fb7a6

+ 1 - 1
iOSClient/AudioRecorder/NCAudioRecorderViewController.swift

@@ -111,7 +111,7 @@ class NCAudioRecorderViewController: UIViewController , NCAudioRecorderDelegate
     
     func audioMeterDidUpdate(_ db: Float) {
         
-        print("db level: %f", db)
+        //print("db level: %f", db)
         
         self.recording.recorder?.updateMeters()
         let ALPHA = 0.05

+ 30 - 9
iOSClient/Main/Create cloud/NCCreateFormUploadVoiceNote.storyboard

@@ -19,10 +19,10 @@
                         <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                         <subviews>
                             <tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" scrollEnabled="NO" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="eeP-9N-ZRP">
-                                <rect key="frame" x="0.0" y="89" width="375" height="200"/>
+                                <rect key="frame" x="0.0" y="89" width="375" height="150"/>
                                 <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
                                 <constraints>
-                                    <constraint firstAttribute="height" constant="200" id="kKy-VZ-d0g"/>
+                                    <constraint firstAttribute="height" constant="150" id="kKy-VZ-d0g"/>
                                 </constraints>
                                 <connections>
                                     <outlet property="dataSource" destination="uQo-FX-ejX" id="Y7U-AM-3WZ"/>
@@ -30,7 +30,7 @@
                                 </connections>
                             </tableView>
                             <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="s98-hk-uUP">
-                                <rect key="frame" x="150" y="346" width="75" height="75"/>
+                                <rect key="frame" x="150" y="249" width="75" height="75"/>
                                 <constraints>
                                     <constraint firstAttribute="width" constant="75" id="h48-gg-iPB"/>
                                     <constraint firstAttribute="height" constant="75" id="mjB-VI-Gzf"/>
@@ -40,21 +40,40 @@
                                     <action selector="playStop:" destination="uQo-FX-ejX" eventType="touchUpInside" id="4AN-dB-Qq8"/>
                                 </connections>
                             </button>
-                            <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="we1-Q7-8Us">
-                                <rect key="frame" x="10" y="309" width="355" height="17"/>
+                            <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="00:00:00" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="we1-Q7-8Us">
+                                <rect key="frame" x="20" y="334" width="70" height="17"/>
+                                <constraints>
+                                    <constraint firstAttribute="width" constant="70" id="Su3-nN-I5z"/>
+                                </constraints>
+                                <fontDescription key="fontDescription" type="system" pointSize="14"/>
+                                <nil key="textColor"/>
+                                <nil key="highlightedColor"/>
+                            </label>
+                            <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="00:00:00" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="zd0-7e-z9V" userLabel="Label Duration">
+                                <rect key="frame" x="285" y="334" width="70" height="17"/>
+                                <constraints>
+                                    <constraint firstAttribute="width" constant="70" id="JZa-Lm-wgx"/>
+                                </constraints>
                                 <fontDescription key="fontDescription" type="system" pointSize="14"/>
                                 <nil key="textColor"/>
                                 <nil key="highlightedColor"/>
                             </label>
+                            <progressView opaque="NO" contentMode="scaleToFill" verticalHuggingPriority="750" progress="0.5" translatesAutoresizingMaskIntoConstraints="NO" id="6HO-NK-obf">
+                                <rect key="frame" x="100" y="341.5" width="175" height="2"/>
+                            </progressView>
                         </subviews>
                         <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
                         <constraints>
                             <constraint firstItem="eeP-9N-ZRP" firstAttribute="top" secondItem="ILQ-5j-b92" secondAttribute="top" constant="25" id="AEH-dn-vHh"/>
-                            <constraint firstItem="we1-Q7-8Us" firstAttribute="top" secondItem="eeP-9N-ZRP" secondAttribute="bottom" constant="20" id="Rgu-v2-bFJ"/>
-                            <constraint firstItem="ILQ-5j-b92" firstAttribute="trailing" secondItem="we1-Q7-8Us" secondAttribute="trailing" constant="10" id="hlz-TT-1Ue"/>
-                            <constraint firstItem="we1-Q7-8Us" firstAttribute="leading" secondItem="ILQ-5j-b92" secondAttribute="leading" constant="10" id="mDe-vt-V6l"/>
+                            <constraint firstItem="6HO-NK-obf" firstAttribute="leading" secondItem="we1-Q7-8Us" secondAttribute="trailing" constant="10" id="C6M-oc-T1Z"/>
+                            <constraint firstItem="6HO-NK-obf" firstAttribute="centerY" secondItem="we1-Q7-8Us" secondAttribute="centerY" id="J28-Wh-Byv"/>
+                            <constraint firstItem="ILQ-5j-b92" firstAttribute="trailing" secondItem="zd0-7e-z9V" secondAttribute="trailing" constant="20" id="Zkq-S4-Hnu"/>
+                            <constraint firstItem="zd0-7e-z9V" firstAttribute="leading" secondItem="6HO-NK-obf" secondAttribute="trailing" constant="10" id="bKe-sM-Gvy"/>
+                            <constraint firstItem="we1-Q7-8Us" firstAttribute="top" secondItem="s98-hk-uUP" secondAttribute="bottom" constant="10" id="ehi-c7-6om"/>
+                            <constraint firstItem="zd0-7e-z9V" firstAttribute="top" secondItem="s98-hk-uUP" secondAttribute="bottom" constant="10" id="elb-sf-8LP"/>
+                            <constraint firstItem="s98-hk-uUP" firstAttribute="top" secondItem="eeP-9N-ZRP" secondAttribute="bottom" constant="10" id="o8u-gE-61X"/>
                             <constraint firstItem="eeP-9N-ZRP" firstAttribute="leading" secondItem="ILQ-5j-b92" secondAttribute="leading" id="pNx-zH-54E"/>
-                            <constraint firstItem="s98-hk-uUP" firstAttribute="top" secondItem="we1-Q7-8Us" secondAttribute="bottom" constant="20" id="t2J-Ir-ONd"/>
+                            <constraint firstItem="we1-Q7-8Us" firstAttribute="leading" secondItem="ILQ-5j-b92" secondAttribute="leading" constant="20" id="uvM-m5-Ofp"/>
                             <constraint firstItem="s98-hk-uUP" firstAttribute="centerX" secondItem="ILQ-5j-b92" secondAttribute="centerX" id="vLn-iu-xOz"/>
                             <constraint firstItem="ILQ-5j-b92" firstAttribute="trailing" secondItem="eeP-9N-ZRP" secondAttribute="trailing" id="yxz-bK-MTp"/>
                         </constraints>
@@ -63,7 +82,9 @@
                     <navigationItem key="navigationItem" id="YB9-Lg-X9d"/>
                     <connections>
                         <outlet property="buttonPlayStop" destination="s98-hk-uUP" id="Aek-KA-loq"/>
+                        <outlet property="labelDuration" destination="zd0-7e-z9V" id="GQW-RU-pdA"/>
                         <outlet property="labelTimer" destination="we1-Q7-8Us" id="9LN-EV-8tm"/>
+                        <outlet property="progressView" destination="6HO-NK-obf" id="ZwP-0h-8Df"/>
                         <outlet property="tableView" destination="eeP-9N-ZRP" id="dzG-bV-m9u"/>
                     </connections>
                 </viewController>

+ 21 - 10
iOSClient/Main/Create cloud/NCCreateFormUploadVoiceNote.swift

@@ -27,12 +27,14 @@ class NCCreateFormUploadVoiceNote: XLFormViewController, NCSelectDelegate, AVAud
     
     @IBOutlet weak var buttonPlayStop: UIButton!
     @IBOutlet weak var labelTimer: UILabel!
+    @IBOutlet weak var labelDuration: UILabel!
+    @IBOutlet weak var progressView: UIProgressView!
 
     private var serverUrl = ""
     private var titleServerUrl = ""
     private var fileName = ""
     private var fileNamePath = ""
-    private var durationPlayerString = ""
+    private var durationPlayer: TimeInterval = 0
     private var counterSecondPlayer: TimeInterval = 0
     
     private var audioPlayer = AVAudioPlayer()
@@ -57,7 +59,7 @@ class NCCreateFormUploadVoiceNote: XLFormViewController, NCSelectDelegate, AVAud
             try audioPlayer = AVAudioPlayer(contentsOf: URL(fileURLWithPath: fileNamePath))
             audioPlayer.prepareToPlay()
             audioPlayer.delegate = self
-            durationPlayerString = NCUtility.sharedInstance.formatSecondsToString(TimeInterval(audioPlayer.duration))
+            durationPlayer = TimeInterval(audioPlayer.duration)
         } catch {
             buttonPlayStop.isEnabled = false
         }
@@ -84,7 +86,12 @@ class NCCreateFormUploadVoiceNote: XLFormViewController, NCSelectDelegate, AVAud
         
         // Button Play Stop
         buttonPlayStop.setImage(CCGraphics.changeThemingColorImage(UIImage(named: "audioPlay")!, width: 200, height: 200, color: NCBrandColor.sharedInstance.icon), for: .normal)
-
+        
+        // Progress view
+        progressView.progressTintColor = NCBrandColor.sharedInstance.brandElement
+        progressView.trackTintColor = UIColor(red: 247.0/255.0, green: 247.0/255.0, blue: 247.0/255.0, alpha: 1.0)
+        progressView.progress = 0
+        
         // form
         initializeForm()
     }
@@ -92,7 +99,7 @@ class NCCreateFormUploadVoiceNote: XLFormViewController, NCSelectDelegate, AVAud
     override func viewWillAppear(_ animated: Bool) {
         super.viewWillAppear(animated)
         
-        updateLabelTimer()
+        updateTimerUI()
     }
     
     func initializeForm() {
@@ -265,13 +272,15 @@ class NCCreateFormUploadVoiceNote: XLFormViewController, NCSelectDelegate, AVAud
     
     //MARK: Player - Timer
 
-    func updateLabelTimer() {
-        labelTimer.text = NCUtility.sharedInstance.formatSecondsToString(counterSecondPlayer) + " - " + durationPlayerString
+    func updateTimerUI() {
+        labelTimer.text = NCUtility.sharedInstance.formatSecondsToString(counterSecondPlayer)
+        labelDuration.text = NCUtility.sharedInstance.formatSecondsToString(durationPlayer)
+        progressView.progress = Float(counterSecondPlayer / durationPlayer)
     }
     
     @objc func updateTimer() {
         counterSecondPlayer += 1
-        updateLabelTimer()
+        updateTimerUI()
     }
     
     @IBAction func playStop(_ sender: Any) {
@@ -283,7 +292,8 @@ class NCCreateFormUploadVoiceNote: XLFormViewController, NCSelectDelegate, AVAud
             
             timer.invalidate()
             counterSecondPlayer = 0
-            updateLabelTimer()
+            progressView.progress = 0
+            updateTimerUI()
             
             buttonPlayStop.setImage(CCGraphics.changeThemingColorImage(UIImage(named: "audioPlay")!, width: 200, height: 200, color: NCBrandColor.sharedInstance.icon), for: .normal)
             
@@ -292,7 +302,7 @@ class NCCreateFormUploadVoiceNote: XLFormViewController, NCSelectDelegate, AVAud
             audioPlayer.prepareToPlay()
             audioPlayer.play()
             
-            timer = Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(updateTimer), userInfo: nil, repeats: true)
+            timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(updateTimer), userInfo: nil, repeats: true)
             
             buttonPlayStop.setImage(CCGraphics.changeThemingColorImage(UIImage(named: "audioStop")!, width: 200, height: 200, color: NCBrandColor.sharedInstance.icon), for: .normal)
         }
@@ -302,7 +312,8 @@ class NCCreateFormUploadVoiceNote: XLFormViewController, NCSelectDelegate, AVAud
         
         timer.invalidate()
         counterSecondPlayer = 0
-        updateLabelTimer()
+        progressView.progress = 0
+        updateTimerUI()
         
         buttonPlayStop.setImage(CCGraphics.changeThemingColorImage(UIImage(named: "audioPlay")!, width: 200, height: 200, color: NCBrandColor.sharedInstance.icon), for: .normal)
     }