diff --git a/WallPanelApp/build.gradle b/WallPanelApp/build.gradle index 88bfff9..39b21f1 100644 --- a/WallPanelApp/build.gradle +++ b/WallPanelApp/build.gradle @@ -29,7 +29,7 @@ repositories { def versionMajor = 0 def versionMinor = 8 def versionPatch = 4 -def versionBuild = 2 // bump for dog food builds, public betas, etc. +def versionBuild = 3 // bump for dog food builds, public betas, etc. android { kapt { @@ -37,7 +37,7 @@ android { correctErrorTypes = true } compileSdkVersion 27 - buildToolsVersion "28.0.2" + buildToolsVersion '28.0.3' defaultConfig { applicationId "com.thanksmister.iot.wallpanel" minSdkVersion versions.min_sdk 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 242ea73..3b0e97a 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 @@ -16,7 +16,6 @@ package com.thanksmister.iot.wallpanel.network -import android.annotation.SuppressLint import android.app.KeyguardManager import android.arch.lifecycle.LifecycleService import android.arch.lifecycle.Observer @@ -28,7 +27,6 @@ import android.os.* import android.provider.Settings import android.support.v4.content.ContextCompat import android.support.v4.content.LocalBroadcastManager -import android.widget.Toast import com.koushikdutta.async.AsyncServer import com.koushikdutta.async.ByteBufferList import com.koushikdutta.async.http.body.JSONObjectBody @@ -103,6 +101,7 @@ class WallPanelService : LifecycleService(), MQTTModule.MQTTListener { private val reconnectHandler = Handler() private var appLaunchUrl: String? = null private var localBroadCastManager: LocalBroadcastManager? = null + private var mqttAlertMessageShown = false inner class WallPanelServiceBinder : Binder() { val service: WallPanelService @@ -314,6 +313,10 @@ class WallPanelService : LifecycleService(), MQTTModule.MQTTListener { override fun onMQTTConnect() { Timber.w("onMQTTConnect") + if(mqttAlertMessageShown) { + clearAlertMessage() // clear any dialogs + mqttAlertMessageShown = false + } publishMessage(COMMAND_STATE, state.toString()) clearFaceDetected() clearMotionDetected() @@ -322,16 +325,22 @@ class WallPanelService : LifecycleService(), MQTTModule.MQTTListener { override fun onMQTTDisconnect() { Timber.e("onMQTTDisconnect") if(hasNetwork()) { - sendAlertMessage(getString(R.string.error_mqtt_connection)) - //reconnectHandler.postDelayed(restartMqttRunnable, 3000) + if(!mqttAlertMessageShown) { + mqttAlertMessageShown = true + sendAlertMessage(getString(R.string.error_mqtt_connection)) + } + reconnectHandler.postDelayed(restartMqttRunnable, 30000) } } override fun onMQTTException(message: String) { Timber.e("onMQTTException: $message") if(hasNetwork()) { - sendAlertMessage(getString(R.string.error_mqtt_exception)) - //reconnectHandler.postDelayed(restartMqttRunnable, 3000) + if(!mqttAlertMessageShown) { + mqttAlertMessageShown = true + sendAlertMessage(getString(R.string.error_mqtt_exception)) + } + reconnectHandler.postDelayed(restartMqttRunnable, 30000) } } @@ -765,6 +774,13 @@ class WallPanelService : LifecycleService(), MQTTModule.MQTTListener { bm.sendBroadcast(intent) } + private fun clearAlertMessage() { + Timber.d("clearAlertMessage") + val intent = Intent(BROADCAST_CLEAR_ALERT_MESSAGE) + val bm = LocalBroadcastManager.getInstance(applicationContext) + bm.sendBroadcast(intent) + } + private fun sendWakeScreen() { Timber.d("sendWakeScreen") val intent = Intent(BROADCAST_SCREEN_WAKE) @@ -857,6 +873,7 @@ class WallPanelService : LifecycleService(), MQTTModule.MQTTListener { const val BROADCAST_EVENT_SCREEN_TOUCH = "BROADCAST_EVENT_SCREEN_TOUCH" const val SCREEN_WAKE_TIME = 30000L const val BROADCAST_ALERT_MESSAGE = "BROADCAST_ALERT_MESSAGE" + const val BROADCAST_CLEAR_ALERT_MESSAGE = "BROADCAST_CLEAR_ALERT_MESSAGE" const val BROADCAST_TOAST_MESSAGE = "BROADCAST_TOAST_MESSAGE" const val BROADCAST_SCREEN_WAKE = "BROADCAST_SCREEN_WAKE" } diff --git a/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/ui/activities/BrowserActivity.kt b/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/ui/activities/BrowserActivity.kt index b168892..61f072b 100644 --- a/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/ui/activities/BrowserActivity.kt +++ b/WallPanelApp/src/main/java/com/thanksmister/iot/wallpanel/ui/activities/BrowserActivity.kt @@ -34,6 +34,7 @@ import android.widget.Toast import com.thanksmister.iot.wallpanel.R import com.thanksmister.iot.wallpanel.network.WallPanelService import com.thanksmister.iot.wallpanel.network.WallPanelService.Companion.BROADCAST_ALERT_MESSAGE +import com.thanksmister.iot.wallpanel.network.WallPanelService.Companion.BROADCAST_CLEAR_ALERT_MESSAGE import com.thanksmister.iot.wallpanel.network.WallPanelService.Companion.BROADCAST_TOAST_MESSAGE import com.thanksmister.iot.wallpanel.persistence.Configuration import com.thanksmister.iot.wallpanel.utils.DialogUtils @@ -75,6 +76,8 @@ abstract class BrowserActivity : DaggerAppCompatActivity() { } else if (BROADCAST_ALERT_MESSAGE == intent.action) { val message = intent.getStringExtra(BROADCAST_ALERT_MESSAGE) dialogUtils.showAlertDialog(this@BrowserActivity, message) + } else if (BROADCAST_CLEAR_ALERT_MESSAGE == intent.action) { + dialogUtils.clearDialogs() } } } @@ -111,6 +114,7 @@ abstract class BrowserActivity : DaggerAppCompatActivity() { filter.addAction(BROADCAST_ACTION_JS_EXEC) filter.addAction(BROADCAST_ACTION_CLEAR_BROWSER_CACHE) filter.addAction(BROADCAST_ACTION_RELOAD_PAGE) + filter.addAction(BROADCAST_CLEAR_ALERT_MESSAGE) filter.addAction(BROADCAST_ALERT_MESSAGE) filter.addAction(BROADCAST_TOAST_MESSAGE) val bm = LocalBroadcastManager.getInstance(this) diff --git a/build.gradle b/build.gradle index f92b36f..672facb 100644 --- a/build.gradle +++ b/build.gradle @@ -27,7 +27,7 @@ buildscript { mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:3.2.0-rc02' + classpath 'com.android.tools.build:gradle:3.2.1' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath 'io.fabric.tools:gradle:1.+' }