Skip to content

Commit

Permalink
* Updated dialog behavior for MQTT errors
Browse files Browse the repository at this point in the history
  • Loading branch information
thanksmister committed Nov 5, 2018
1 parent 29688b9 commit 7964cd1
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 44 deletions.
2 changes: 1 addition & 1 deletion WallPanelApp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ repositories {
def versionMajor = 0
def versionMinor = 8
def versionPatch = 4
def versionBuild = 3 // bump for dog food builds, public betas, etc.
def versionBuild = 4 // bump for dog food builds, public betas, etc.

android {
kapt {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ class WallPanel : DaggerApplication() {
super.onCreate()
if (BuildConfig.DEBUG) {
Timber.plant(Timber.DebugTree())
Fabric.with(this, Crashlytics())
Fabric.with(this, Answers())
Timber.plant(CrashlyticsTree())
} else {
Fabric.with(this, Crashlytics())
Fabric.with(this, Answers())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import com.thanksmister.iot.wallpanel.utils.NotificationUtils
import dagger.android.AndroidInjection
import org.json.JSONException
import org.json.JSONObject
import timber.log.BuildConfig
import timber.log.Timber
import java.io.IOException
import java.nio.ByteBuffer
Expand Down Expand Up @@ -102,6 +103,7 @@ class WallPanelService : LifecycleService(), MQTTModule.MQTTListener {
private var appLaunchUrl: String? = null
private var localBroadCastManager: LocalBroadcastManager? = null
private var mqttAlertMessageShown = false
private var mqttConnected = false

inner class WallPanelServiceBinder : Binder() {
val service: WallPanelService
Expand Down Expand Up @@ -311,32 +313,35 @@ class WallPanelService : LifecycleService(), MQTTModule.MQTTListener {
}
}

//Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1
override fun onMQTTConnect() {
Timber.w("onMQTTConnect")
if(mqttAlertMessageShown) {
if(!mqttConnected) {
clearAlertMessage() // clear any dialogs
mqttAlertMessageShown = false
mqttConnected = true
}
publishMessage(COMMAND_STATE, state.toString())
clearFaceDetected()
clearMotionDetected()
}

//Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1
override fun onMQTTDisconnect() {
Timber.e("onMQTTDisconnect")
if(hasNetwork()) {
if(!mqttAlertMessageShown) {
if(!mqttAlertMessageShown && !mqttConnected) {
mqttAlertMessageShown = true
sendAlertMessage(getString(R.string.error_mqtt_connection))
}
reconnectHandler.postDelayed(restartMqttRunnable, 30000)
}
}

//Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1
override fun onMQTTException(message: String) {
Timber.e("onMQTTException: $message")
if(hasNetwork()) {
if(!mqttAlertMessageShown) {
if(!mqttAlertMessageShown && !mqttConnected) {
mqttAlertMessageShown = true
sendAlertMessage(getString(R.string.error_mqtt_exception))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,14 @@ import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.content.pm.PackageManager
import android.os.Build
import android.os.Bundle
import android.support.v4.app.ActivityCompat
import android.support.v4.content.LocalBroadcastManager
import android.view.KeyEvent
import android.view.View
import android.view.ViewTreeObserver
import android.view.WindowManager
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
Expand Down Expand Up @@ -70,13 +67,13 @@ abstract class BrowserActivity : DaggerAppCompatActivity() {
} else if (BROADCAST_ACTION_RELOAD_PAGE == intent.action) {
Timber.d("Browser page reloading.")
reload()
} else if (BROADCAST_TOAST_MESSAGE == intent.action) {
} else if (BROADCAST_TOAST_MESSAGE == intent.action && !isFinishing) {
val message = intent.getStringExtra(BROADCAST_TOAST_MESSAGE)
Toast.makeText(applicationContext, message, Toast.LENGTH_SHORT).show()
} else if (BROADCAST_ALERT_MESSAGE == intent.action) {
} else if (BROADCAST_ALERT_MESSAGE == intent.action && !isFinishing) {
val message = intent.getStringExtra(BROADCAST_ALERT_MESSAGE)
dialogUtils.showAlertDialog(this@BrowserActivity, message)
} else if (BROADCAST_CLEAR_ALERT_MESSAGE == intent.action) {
} else if (BROADCAST_CLEAR_ALERT_MESSAGE == intent.action && !isFinishing) {
dialogUtils.clearDialogs()
}
}
Expand All @@ -96,7 +93,7 @@ abstract class BrowserActivity : DaggerAppCompatActivity() {

decorView = window.decorView

if(configuration.cameraEnabled || configuration.hasCameraDetections()) {
if(configuration.cameraEnabled || configuration.hasCameraDetections() && Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1) {
window.setFlags(WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED, WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED)
}

Expand All @@ -105,6 +102,8 @@ abstract class BrowserActivity : DaggerAppCompatActivity() {
} else {
window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
}

lifecycle.addObserver(dialogUtils)
}

override fun onResume() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,20 @@
package com.thanksmister.iot.wallpanel.ui.activities

import android.annotation.SuppressLint
import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.support.design.widget.Snackbar
import android.support.v7.preference.PreferenceManager
import android.support.v7.app.AlertDialog
import android.text.TextUtils
import android.view.KeyEvent
import android.view.MotionEvent
import android.view.View
import android.webkit.WebSettings
import android.view.ViewTreeObserver
import android.widget.Toast
import com.thanksmister.iot.wallpanel.R
import com.thanksmister.iot.wallpanel.persistence.Configuration

import kotlinx.android.synthetic.main.activity_browser.*
import org.xwalk.core.XWalkCookieManager
import org.xwalk.core.XWalkResourceClient
import org.xwalk.core.XWalkView
import org.xwalk.core.XWalkCookieManager

import timber.log.Timber
import javax.inject.Inject
import android.content.DialogInterface
import android.net.http.SslError
import android.support.v7.app.AlertDialog
import android.view.ViewTreeObserver
import android.webkit.SslErrorHandler
import android.webkit.WebView
import android.widget.Toast
import kotlinx.android.synthetic.main.activity_browser.*


class BrowserActivityLegacy : BrowserActivity() {
Expand All @@ -55,6 +42,8 @@ class BrowserActivityLegacy : BrowserActivity() {

super.onCreate(savedInstanceState)

Timber.i("BrowserActivityLegacy")

try {
setContentView(R.layout.activity_browser)
} catch (e: Exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,16 @@ import android.net.http.SslError
import android.os.Build
import android.os.Bundle
import android.support.design.widget.Snackbar
import android.support.v7.app.AlertDialog
import android.text.TextUtils
import android.view.MotionEvent
import android.view.View
import android.view.ViewTreeObserver
import android.webkit.*
import android.widget.Toast
import com.thanksmister.iot.wallpanel.R
import kotlinx.android.synthetic.main.activity_browser.*
import timber.log.Timber
import android.webkit.WebView
import android.widget.Toast
import android.content.DialogInterface
import android.support.v7.app.AlertDialog
import android.view.ViewTreeObserver


class BrowserActivityNative : BrowserActivity() {
Expand All @@ -42,7 +40,7 @@ class BrowserActivityNative : BrowserActivity() {
@SuppressLint("SetJavaScriptEnabled", "ClickableViewAccessibility")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

Timber.i("BrowserActivityNative")
try {
setContentView(R.layout.activity_browser)
} catch (e: Exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,25 +160,26 @@ class SettingsActivity : DaggerAppCompatActivity(), SettingsFragment.OnSettingsF

override fun onBrowserButton() {
val browserType = configuration.androidBrowserType
Timber.i("onBrowserButton browserType $browserType")
val targetClass: Class<*>
when (browserType) {
Configuration.PREF_BROWSER_NATIVE -> {
Timber.d("Explicitly using native browser")
Timber.i("Explicitly using native browser")
targetClass = BrowserActivityNative::class.java
}
Configuration.PREF_BROWSER_LEGACY -> {
Timber.d("Explicitly using legacy browser")
Timber.i("Explicitly using legacy browser")
targetClass = BrowserActivityLegacy::class.java
}
Configuration.PREF_BROWSER_AUTO -> {
Timber.d("Auto-selecting dashboard browser")
Timber.i("Auto-selecting dashboard browser")
targetClass = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
BrowserActivityNative::class.java
else
BrowserActivityLegacy::class.java
}
else -> {
Timber.d("Auto-selecting dashboard browser")
Timber.i("Auto-selecting dashboard browser")
targetClass = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
BrowserActivityNative::class.java
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,19 @@ class WelcomeActivity : DaggerAppCompatActivity() {
}

private fun startBrowserActivity() {
Timber.i("startBrowserActivity Called")
val browserType = configuration.androidBrowserType
Timber.i("startBrowserActivity browserType $browserType")
val targetClass: Class<*>
when (browserType) {
"Native" -> {
Configuration.PREF_BROWSER_NATIVE -> {
Timber.i( "Explicitly using native browser")
targetClass = BrowserActivityNative::class.java
}
"Legacy" -> {
Configuration.PREF_BROWSER_LEGACY -> {
Timber.i("Explicitly using legacy browser")
targetClass = BrowserActivityLegacy::class.java
}
"Auto" -> {
Configuration.PREF_BROWSER_AUTO -> {
Timber.i("Auto-selecting dashboard browser")
targetClass = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
BrowserActivityNative::class.java
Expand Down
21 changes: 21 additions & 0 deletions WallPanelApp/src/main/res/values-v14/bools.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!--
~ Copyright (c) 2018 ThanksMister LLC
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software distributed
~ under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<resources>

<bool name="largeheap">true</bool>

</resources>
21 changes: 21 additions & 0 deletions WallPanelApp/src/main/res/values/bools.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!--
~ Copyright (c) 2018 ThanksMister LLC
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software distributed
~ under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<resources>

<bool name="largeheap">false</bool>

</resources>

0 comments on commit 7964cd1

Please sign in to comment.