瀏覽代碼

adapt IQAudioRecorderViewController: don't show play layout, record audio immediately

cyberta 5 年之前
父節點
當前提交
ac928d0bdb

+ 9 - 0
Pods/IQAudioRecorderController/IQAudioRecorderController/IQAudioRecorderViewController.h

@@ -88,6 +88,10 @@
  */
 @property (nonatomic, assign) BOOL allowCropping;
 
+/**
+ Show record button to switch between recording and playing media layout
+ */
+@property (nonatomic, assign) BOOL allowPlayback;
 
 ///--------------------------
 /// @name Audio Settings
@@ -124,6 +128,11 @@
  */
 @property(nonatomic,assign) NSInteger bitRate;
 
+/**
+ Immediately start recording on presenting IQAudioRecorderViewController
+*/
+@property(nonatomic,assign) BOOL recordOnCreation;
+
 @end
 
 

+ 41 - 10
Pods/IQAudioRecorderController/IQAudioRecorderController/IQAudioRecorderViewController.m

@@ -244,6 +244,7 @@
         _stopPlayButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"stop_playing" inBundle:resourcesBundle compatibleWithTraitCollection:nil] style:UIBarButtonItemStylePlain target:self action:@selector(stopPlayingButtonAction:)];
         _stopPlayButton.tintColor = [self _normalTintColor];
         _playButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemPlay target:self action:@selector(playAction:)];
+
         _playButton.tintColor = [self _normalTintColor];
 
         _pauseButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemPause target:self action:@selector(pausePlayingAction:)];
@@ -259,10 +260,14 @@
         {
             _cropOrDeleteButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemTrash target:self action:@selector(deleteAction:)];
         }
-        
+
         _cropOrDeleteButton.tintColor = [self _normalTintColor];
-        
-        [self setToolbarItems:@[_playButton,_flexItem, _startRecordingButton,_flexItem, _cropOrDeleteButton] animated:NO];
+
+        if (self.allowPlayback) {
+            [self setToolbarItems:@[_playButton,_flexItem, _startRecordingButton,_flexItem, _cropOrDeleteButton] animated:NO];
+        } else {
+            [self setToolbarItems:@[_startRecordingButton] animated:NO];
+        }
 
         _playButton.enabled = NO;
         _cropOrDeleteButton.enabled = NO;
@@ -334,7 +339,9 @@
         _cancelButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelAction:)];
         self.navigationItem.leftBarButtonItem = _cancelButton;
         _doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneAction:)];
-        _doneButton.enabled = NO;
+        if (!self.recordOnCreation) {
+            _doneButton.enabled = NO;
+        }
         self.navigationItem.rightBarButtonItem = _doneButton;
     }
     
@@ -346,6 +353,10 @@
         _viewPlayerDuration.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
         _viewPlayerDuration.backgroundColor = [UIColor clearColor];
     }
+
+    if (self.recordOnCreation) {
+        [self recordingButtonAction: nil];
+    }
 }
 
 -(void)setBarStyle:(UIBarStyle)barStyle
@@ -621,10 +632,14 @@
 {
     //UI Update
     {
-        [self setToolbarItems:@[_stopRecordingButton,_flexItem, _pauseRecordingButton,_flexItem, _cropOrDeleteButton] animated:YES];
+        if (self.allowPlayback) {
+            [self setToolbarItems:@[_stopRecordingButton,_flexItem, _pauseRecordingButton,_flexItem, _cropOrDeleteButton] animated:YES];
+            _doneButton.enabled = NO;
+        } else {
+            [self setToolbarItems:@[_flexItem, _pauseRecordingButton, _flexItem] animated:YES];
+        }
         _cropOrDeleteButton.enabled = NO;
         [self.navigationItem setLeftBarButtonItem:_cancelRecordingButton animated:YES];
-        _doneButton.enabled = NO;
     }
     
     /*
@@ -656,7 +671,11 @@
 {
     //UI Update
     {
-        [self setToolbarItems:@[_stopRecordingButton,_flexItem, _pauseRecordingButton,_flexItem, _cropOrDeleteButton] animated:YES];
+        if (self.allowPlayback) {
+            [self setToolbarItems:@[_stopRecordingButton,_flexItem, _pauseRecordingButton,_flexItem, _cropOrDeleteButton] animated:YES];
+        } else {
+            [self setToolbarItems:@[_flexItem, _pauseRecordingButton, _flexItem] animated:YES];
+        }
     }
 
     _isRecordingPaused = NO;
@@ -667,7 +686,11 @@
 {
     _isRecordingPaused = YES;
     [_audioRecorder pause];
-    [self setToolbarItems:@[_stopRecordingButton,_flexItem, _continueRecordingButton,_flexItem, _cropOrDeleteButton] animated:YES];
+    if (self.allowPlayback) {
+        [self setToolbarItems:@[_stopRecordingButton,_flexItem, _continueRecordingButton,_flexItem, _cropOrDeleteButton] animated:YES];
+    } else {
+        [self setToolbarItems:@[_flexItem, _continueRecordingButton, _flexItem] animated:YES];
+    }
 }
 
 -(void)stopRecordingButtonAction:(UIBarButtonItem*)item
@@ -693,7 +716,12 @@
     {
         //UI Update
         {
-            [self setToolbarItems:@[_playButton,_flexItem, _startRecordingButton,_flexItem, _cropOrDeleteButton] animated:YES];
+            if (self.allowPlayback) {
+                [self setToolbarItems:@[_playButton,_flexItem, _startRecordingButton,_flexItem, _cropOrDeleteButton] animated:YES];
+            } else {
+                [self setToolbarItems:@[_flexItem, _startRecordingButton, _flexItem] animated:YES];
+            }
+
             [self.navigationItem setLeftBarButtonItem:_cancelButton animated:YES];
             
             if ([[NSFileManager defaultManager] fileExistsAtPath:_recordingFilePath])
@@ -706,7 +734,7 @@
             {
                 _playButton.enabled = NO;
                 _cropOrDeleteButton.enabled = NO;
-                _doneButton.enabled = NO;
+                _doneButton.enabled = !self.allowPlayback;
             }
         }
 
@@ -734,6 +762,9 @@
 
 -(void)doneAction:(UIBarButtonItem*)item
 {
+    if (!self.allowPlayback) {
+        [self stopRecordingButtonAction:nil];
+    }
     [self notifySuccessDelegate];
 }
 

+ 2 - 0
deltachat-ios/Helper/MediaPicker.swift

@@ -39,6 +39,8 @@ class MediaPicker: NSObject, UINavigationControllerDelegate, UIImagePickerContro
         audioRecorderController.delegate = self
         audioRecorderController.title = String.localized("voice_message")
         audioRecorderController.allowCropping = false
+        audioRecorderController.allowPlayback = false
+        audioRecorderController.recordOnCreation = true
 
         audioRecorderController.maximumRecordDuration = 1200
         audioRecorderController.barStyle = .default