From 8c0e0af27024bf0e0de363daaca93461c17badbf Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 26 Mar 2017 15:05:14 +0200 Subject: [PATCH] move the permission checking things into a separate function --- .../com/simplemobiletools/camera/Preview.kt | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/camera/Preview.kt b/app/src/main/kotlin/com/simplemobiletools/camera/Preview.kt index 01e6df69..b6995deb 100644 --- a/app/src/main/kotlin/com/simplemobiletools/camera/Preview.kt +++ b/app/src/main/kotlin/com/simplemobiletools/camera/Preview.kt @@ -513,6 +513,24 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan mRecorder!!.setProfile(this) } + checkPermissions() + mRecorder!!.setPreviewDisplay(mSurfaceHolder.surface) + + val rotation = getVideoRotation() + mInitVideoRotation = rotation + mRecorder!!.setOrientationHint(90) + + try { + mRecorder!!.prepare() + } catch (e: Exception) { + setupFailed(e) + return false + } + + return true + } + + private fun checkPermissions(): Boolean { if (mActivity.needsStupidWritePermissions(mCurrVideoPath)) { if (config.treeUri.isEmpty()) { mActivity.toast(R.string.save_error_internal_storage) @@ -537,19 +555,6 @@ class Preview : ViewGroup, SurfaceHolder.Callback, MediaScannerConnection.OnScan } else { mRecorder!!.setOutputFile(mCurrVideoPath) } - mRecorder!!.setPreviewDisplay(mSurfaceHolder.surface) - - val rotation = getVideoRotation() - mInitVideoRotation = rotation - mRecorder!!.setOrientationHint(rotation) - - try { - mRecorder!!.prepare() - } catch (e: Exception) { - setupFailed(e) - return false - } - return true }