File tree Expand file tree Collapse file tree 1 file changed +20
-9
lines changed
app/src/main/kotlin/com/simplemobiletools/flashlight/helpers Expand file tree Collapse file tree 1 file changed +20
-9
lines changed Original file line number Diff line number Diff line change @@ -59,15 +59,8 @@ class MyCameraImpl(val context: Context) {
5959 disableFlashlight()
6060 }
6161
62- if (! isNougatPlus()) {
63- if (camera == null ) {
64- initCamera()
65- }
66-
67- if (camera == null ) {
68- context.toast(R .string.camera_error)
69- return false
70- }
62+ if (! tryInitCamera()) {
63+ return false
7164 }
7265
7366 if (isStroboscopeRunning) {
@@ -88,6 +81,10 @@ class MyCameraImpl(val context: Context) {
8881 stopStroboscope()
8982 }
9083
84+ if (! tryInitCamera()) {
85+ return false
86+ }
87+
9188 if (isFlashlightOn) {
9289 disableFlashlight()
9390 }
@@ -101,6 +98,20 @@ class MyCameraImpl(val context: Context) {
10198 bus!! .post(Events .StopSOS ())
10299 }
103100
101+ private fun tryInitCamera (): Boolean {
102+ if (! isNougatPlus()) {
103+ if (camera == null ) {
104+ initCamera()
105+ }
106+
107+ if (camera == null ) {
108+ context.toast(R .string.camera_error)
109+ return false
110+ }
111+ }
112+ return true
113+ }
114+
104115 fun handleCameraSetup () {
105116 if (isMarshmallow) {
106117 setupMarshmallowCamera()
You can’t perform that action at this time.
0 commit comments