diff --git a/WallPanelApp/build.gradle b/WallPanelApp/build.gradle index 06e7d07..d57a0cf 100644 --- a/WallPanelApp/build.gradle +++ b/WallPanelApp/build.gradle @@ -29,7 +29,7 @@ repositories { def versionMajor = 0 def versionMinor = 8 def versionPatch = 3 -def versionBuild = 1 // bump for dog food builds, public betas, etc. +def versionBuild = 2 // bump for dog food builds, public betas, etc. android { kapt { diff --git a/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/modules/CameraReader.kt b/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/modules/CameraReader.kt index 419df97..6643df8 100644 --- a/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/modules/CameraReader.kt +++ b/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/modules/CameraReader.kt @@ -139,16 +139,19 @@ constructor(private val context: Context) { buildDetectors(configuration) if(multiDetector != null) { try { - initCamera(configuration.cameraId, configuration.cameraFPS) - } catch (e : IOException) { + cameraSource = initCamera(configuration.cameraId, configuration.cameraFPS) + cameraSource!!.start() + } catch (e : Exception) { Timber.e(e.message) try { if(configuration.cameraId == CAMERA_FACING_FRONT) { - initCamera(CAMERA_FACING_BACK, configuration.cameraFPS) + cameraSource = initCamera(CAMERA_FACING_BACK, configuration.cameraFPS) + cameraSource!!.start() } else { - initCamera(CAMERA_FACING_FRONT, configuration.cameraFPS) + cameraSource = initCamera(CAMERA_FACING_FRONT, configuration.cameraFPS) + cameraSource!!.start() } - } catch (e : IOException) { + } catch (e : Exception) { Timber.e(e.message) cameraSource!!.stop() cameraCallback?.onCameraError() @@ -404,20 +407,13 @@ constructor(private val context: Context) { } @SuppressLint("MissingPermission") - @Throws(Exception::class) - private fun initCamera(camerId: Int, fsp: Float) { + private fun initCamera(camerId: Int, fsp: Float): CameraSource { Timber.d("initCamera camerId $camerId") - cameraSource = CameraSource.Builder(context, multiDetector) + return CameraSource.Builder(context, multiDetector) .setRequestedFps(fsp) .setRequestedPreviewSize(640, 480) .setFacing(camerId) .build() - - try { - cameraSource!!.start() - } catch (e: RuntimeException) { - throw e - } } interface OnCompleteListener { diff --git a/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/modules/MotionDetector.kt b/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/modules/MotionDetector.kt index 5958d2e..6860642 100644 --- a/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/modules/MotionDetector.kt +++ b/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/modules/MotionDetector.kt @@ -65,13 +65,18 @@ class MotionDetector private constructor(private val minLuma: Int, private val m return sparseArray } - val motionDetected = aggregateLumaMotionDetection!!.detect(img, w, h) - if (motionDetected) { - motion.type = MOTION_DETECTED - //Timber.d("MOTION_DETECTED") - } else { + try { + val motionDetected = aggregateLumaMotionDetection!!.detect(img, w, h) + if (motionDetected) { + motion.type = MOTION_DETECTED + //Timber.d("MOTION_DETECTED") + } else { + motion.type = MOTION_NOT_DETECTED + //Timber.d("MOTION_NOT_DETECTED") + } + } catch (e: Exception) { + Timber.e(e.message) motion.type = MOTION_NOT_DETECTED - //Timber.d("MOTION_NOT_DETECTED") } sparseArray.put(0, motion) return sparseArray diff --git a/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/network/MQTTService.kt b/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/network/MQTTService.kt index 3cb7d52..8120642 100644 --- a/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/network/MQTTService.kt +++ b/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/network/MQTTService.kt @@ -231,6 +231,8 @@ class MQTTService(private var context: Context, options: MQTTOptions, try { mqttClient!!.publish(mqttTopic, mqttMessage) Timber.d("Command Topic: $mqttTopic Payload: $message") + } catch (e: NullPointerException) { + Timber.e(e.message) } catch (e: MqttException) { Timber.e("Error Sending Command: " + e.message) e.printStackTrace() @@ -248,6 +250,8 @@ class MQTTService(private var context: Context, options: MQTTOptions, mqttClient!!.subscribe(topicFilters, MqttUtils.getQos(topicFilters!!.size), MqttUtils.getMqttMessageListeners(topicFilters.size, listener)) } + } catch (e: NullPointerException) { + Timber.e(e.message) } catch (e: MqttException) { if (listener != null) { listener!!.handleMqttException("Exception while subscribing: " + e.message) diff --git a/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/network/WallPanelService.kt b/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/network/WallPanelService.kt index aa13fa8..912e597 100644 --- a/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/network/WallPanelService.kt +++ b/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/network/WallPanelService.kt @@ -156,18 +156,17 @@ class WallPanelService : LifecycleService(), MQTTModule.MQTTListener { filter.addAction(Intent.ACTION_USER_PRESENT) localBroadCastManager = LocalBroadcastManager.getInstance(this) localBroadCastManager!!.registerReceiver(mBroadcastReceiver, filter) - } override fun onDestroy() { super.onDestroy() - if(localBroadCastManager != null) { - localBroadCastManager!!.unregisterReceiver(mBroadcastReceiver) - } if(mqttModule != null) { - mqttModule!!.pause() + mqttModule?.pause() mqttModule = null } + if(localBroadCastManager != null) { + localBroadCastManager?.unregisterReceiver(mBroadcastReceiver) + } cameraReader.stopCamera() sensorReader.stopReadings() stopHttp() @@ -334,11 +333,9 @@ class WallPanelService : LifecycleService(), MQTTModule.MQTTListener { } } - private val restartMqttRunnable = object: Runnable { - override fun run() { - if (mqttModule != null) { - mqttModule!!.restart() - } + private val restartMqttRunnable = Runnable { + if (mqttModule != null) { + mqttModule!!.restart() } } diff --git a/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/ui/fragments/CameraSettingsFragment.kt b/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/ui/fragments/CameraSettingsFragment.kt index 088693c..63b3155 100644 --- a/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/ui/fragments/CameraSettingsFragment.kt +++ b/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/ui/fragments/CameraSettingsFragment.kt @@ -139,10 +139,12 @@ class CameraSettingsFragment : BaseSettingsFragment() { qrCodePreference = findPreference("button_key_qr_code") cameraTestPreference = findPreference("button_key_camera_test") - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - if (ActivityCompat.checkSelfPermission(activity!!.applicationContext, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && activity != null) { + if (ActivityCompat.checkSelfPermission(activity!!, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) { configuration.cameraEnabled = false - dialogUtils.showAlertDialog(activity!!.applicationContext, getString(R.string.dialog_no_camera_permissions)) + if(activity != null) { + dialogUtils.showAlertDialog(activity!!, getString(R.string.dialog_no_camera_permissions)) + } return } } diff --git a/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/utils/DialogUtils.kt b/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/utils/DialogUtils.kt index e48a95b..9e763b6 100644 --- a/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/utils/DialogUtils.kt +++ b/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/utils/DialogUtils.kt @@ -44,14 +44,14 @@ class DialogUtils(base: Context?) : ContextWrapper(base), LifecycleObserver { hideDialog() } - fun hideDialog() { + private fun hideDialog() { if (dialog != null && dialog!!.isShowing) { dialog!!.dismiss() dialog = null } } - fun hideAlertDialog() { + private fun hideAlertDialog() { if (alertDialog != null && alertDialog!!.isShowing) { alertDialog!!.dismiss() alertDialog = null