Skip to content

Commit

Permalink
Updated to accept codes starting with the number 0
Browse files Browse the repository at this point in the history
  • Loading branch information
thanksmister committed Jul 16, 2021
1 parent f9e0a41 commit f2b23b3
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 55 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ apply plugin: 'com.google.firebase.crashlytics'

def versionMajor = 1
def versionMinor = 1
def versionPatch = 1
def versionBuild = 9 // bump for dog food builds, public betas, etc.
def versionPatch = 2
def versionBuild = 0 // bump for dog food builds, public betas, etc.

def ALARM_CODE() {
Properties properties = new Properties()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class MQTTModule (base: Context?,
stop()
}

fun publishAlarm(action : String, code: Int) {
fun publishAlarm(action : String, code: String) {
Timber.d("action: $action")
Timber.d("code: $code")
mqttService?.publishAlarm(action, code)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ class AlarmPanelService : LifecycleService(), MQTTModule.MQTTListener {
}
}

private fun publishAlarm(action: String, code: Int) {
private fun publishAlarm(action: String, code: String) {
mqttModule?.let {
it.publishAlarm(action, code)
if (action == COMMAND_DISARM) {
Expand Down Expand Up @@ -1079,17 +1079,17 @@ class AlarmPanelService : LifecycleService(), MQTTModule.MQTTListener {
this@AlarmPanelService.publishCommand(COMMAND_STATE, getState(userPresence.get()).toString())
} else if (BROADCAST_EVENT_ALARM_MODE == intent.action) {
val alarmMode = intent.getStringExtra(BROADCAST_EVENT_ALARM_MODE).orEmpty()
var alarmCode = intent.getStringExtra(BROADCAST_EVENT_ALARM_CODE).orEmpty().toIntOrNull()
if (alarmCode == null) alarmCode = 0
var alarmCode = intent.getStringExtra(BROADCAST_EVENT_ALARM_CODE).orEmpty()
if (alarmCode.isEmpty()) alarmCode = "0"
publishAlarm(alarmMode, alarmCode)
if(mqttOptions.useRemoteCode.not()) {
broadcastAlarmCommand(alarmMode)
}
} else if (BROADCAST_EVENT_PUBLISH_PANIC == intent.action) {
val mode = intent.getStringExtra(BROADCAST_EVENT_PUBLISH_PANIC).orEmpty()
var alarmCode = 0
var alarmCode = "0"
if (mqttOptions.useRemoteCode) {
alarmCode = -1
alarmCode = "-1"
}
publishAlarm(mode, alarmCode)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class MQTTService(private var context: Context,
disposable.dispose()
}

override fun publishAlarm(command: String, code: Int) {
override fun publishAlarm(command: String, code: String) {
try {
if (mReady.get()) {
mqttClient?.let {
Expand All @@ -95,29 +95,23 @@ class MQTTService(private var context: Context,
try {
initializeMqttClient()
} catch (e: MqttException) {
if (listener != null) {
listener!!.handleMqttException("Could not initialize MQTT: " + e.message)
}
listener?.handleMqttException("Could not initialize MQTT: " + e.message)
} catch (e: IOException) {
if (listener != null) {
listener!!.handleMqttException("Could not initialize MQTT: " + e.message)
}
listener?.handleMqttException("Could not initialize MQTT: " + e.message)
} catch (e: GeneralSecurityException) {
if (listener != null) {
listener!!.handleMqttException("Could not initialize MQTT: " + e.message)
}
listener?.handleMqttException("Could not initialize MQTT: " + e.message)
}
}
}
mqttOptions?.let {
val mqttMessage = MqttMessage()
var payloadString = command
if(it.useRemoteCode && code != 0) {
if(it.useRemoteCode && code != "0") {
val payloadJson = JSONObject()
payloadJson.put(MqttUtils.COMMAND, command)
if (code > 0) {
payloadJson.put(MqttUtils.CODE, code.toString())
} else if (command == MqttUtils.COMMAND_PANIC && code < 0) {
if (code != "-1" && code != "0") {
payloadJson.put(MqttUtils.CODE, code)
} else if (command == MqttUtils.COMMAND_PANIC && code == "-1") {
payloadJson.put(MqttUtils.CODE, "")
}
payloadString = payloadJson.toString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import com.thanksmister.iot.mqtt.alarmpanel.network.MQTTService.MqttManagerListe
import org.eclipse.paho.client.mqttv3.MqttException

interface MQTTServiceInterface {
fun publishAlarm(command: String, code: Int)
fun publishAlarm(command: String, code: String)
fun publishCommand(command: String, payload: String)
fun reconfigure(context: Context, newOptions: MQTTOptions, listener: MqttManagerListener)
@Throws(MqttException::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,20 @@ class ScreenSaverView : RelativeLayout {
screenSaverClockSmall.setTextSize(TypedValue.COMPLEX_UNIT_PX, initialSmall + 60)
}

if (useClockScreenSaver) { // use clock
screenSaverWebViewLayout.visibility = View.GONE
screenSaverImageLayout.visibility = View.GONE
screenSaverClockLayout.visibility = View.VISIBLE
if (!hasWeather) {
screenSaverWeatherLayout.visibility = View.GONE
} else {
setWeatherDataOnView()
screenSaverWeatherLayout.visibility = View.VISIBLE
}
timeHandler = Handler()
timeHandler?.postDelayed(timeRunnable, 10)
}

if (useUnsplashScreenSaver) {
screenSaverImageLayout.visibility = View.VISIBLE
screenSaverWebViewLayout.visibility = View.GONE
Expand All @@ -198,6 +212,7 @@ class ScreenSaverView : RelativeLayout {
}
rotationHandler = Handler()
rotationHandler?.postDelayed(delayRotationRunnable, 10)

} else if (useWebScreenSaver && webUrl.isNotEmpty()) {
screenSaverWebViewLayout.visibility = View.VISIBLE
screenSaverImageLayout.visibility = View.GONE
Expand All @@ -209,19 +224,8 @@ class ScreenSaverView : RelativeLayout {
timeHandler = Handler()
timeHandler?.postDelayed(timeRunnable, 10)
}

startWebScreenSaver(webUrl)
} else if (useClockScreenSaver) { // use clock
screenSaverWebViewLayout.visibility = View.GONE
screenSaverImageLayout.visibility = View.GONE
screenSaverClockLayout.visibility = View.VISIBLE
if (!hasWeather) {
screenSaverWeatherLayout.visibility = View.GONE
} else {
setWeatherDataOnView()
screenSaverWeatherLayout.visibility = View.VISIBLE
}
timeHandler = Handler()
timeHandler?.postDelayed(timeRunnable, 10)
}
}

Expand Down
8 changes: 4 additions & 4 deletions app/src/main/res/layout-land/dialog_screen_saver.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
~ limitations under the License.
-->

<com.thanksmister.iot.mqtt.alarmpanel.ui.views.ScreenSaverView
xmlns:android="http://schemas.android.com/apk/res/android"
<com.thanksmister.iot.mqtt.alarmpanel.ui.views.ScreenSaverView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/screenSaverView"
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand Down Expand Up @@ -56,7 +56,7 @@
android:layout_marginTop="8dp"
android:layout_width="72dp"
android:layout_height="72dp"
android:tint="@color/blue_alpha"
app:tint="@color/blue_alpha"
tools:src="@drawable/ic_thunderstorm" />

</LinearLayout>
Expand Down Expand Up @@ -122,7 +122,7 @@
android:layout_marginTop="4dp"
android:layout_width="44dp"
android:layout_height="44dp"
android:tint="@color/blue_alpha"
app:tint="@color/blue_alpha"
tools:src="@drawable/ic_thunderstorm" />

</LinearLayout>
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/res/layout-sw600dp-land/dialog_screen_saver.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
~ limitations under the License.
-->

<com.thanksmister.iot.mqtt.alarmpanel.ui.views.ScreenSaverView
xmlns:android="http://schemas.android.com/apk/res/android"
<com.thanksmister.iot.mqtt.alarmpanel.ui.views.ScreenSaverView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/screenSaverView"
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand Down Expand Up @@ -57,7 +57,7 @@
android:layout_marginTop="8dp"
android:layout_width="84dp"
android:layout_height="84dp"
android:tint="@color/blue_alpha"
app:tint="@color/blue_alpha"
tools:src="@drawable/ic_thunderstorm" />

</LinearLayout>
Expand Down Expand Up @@ -124,7 +124,7 @@
android:layout_marginTop="4dp"
android:layout_width="48dp"
android:layout_height="48dp"
android:tint="@color/blue_alpha"
app:tint="@color/blue_alpha"
tools:src="@drawable/ic_thunderstorm" />

</LinearLayout>
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/res/layout-sw600dp/dialog_screen_saver.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
~ limitations under the License.
-->

<com.thanksmister.iot.mqtt.alarmpanel.ui.views.ScreenSaverView
xmlns:android="http://schemas.android.com/apk/res/android"
<com.thanksmister.iot.mqtt.alarmpanel.ui.views.ScreenSaverView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/screenSaverView"
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand Down Expand Up @@ -57,7 +57,7 @@
android:layout_marginTop="8dp"
android:layout_width="84dp"
android:layout_height="84dp"
android:tint="@color/blue_alpha"
app:tint="@color/blue_alpha"
tools:src="@drawable/ic_thunderstorm" />

</LinearLayout>
Expand Down Expand Up @@ -124,7 +124,7 @@
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_marginTop="4dp"
android:tint="@color/blue_alpha"
app:tint="@color/blue_alpha"
tools:src="@drawable/ic_thunderstorm" />

</LinearLayout>
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/res/layout-sw720dp-land/dialog_screen_saver.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
~ limitations under the License.
-->

<com.thanksmister.iot.mqtt.alarmpanel.ui.views.ScreenSaverView
xmlns:android="http://schemas.android.com/apk/res/android"
<com.thanksmister.iot.mqtt.alarmpanel.ui.views.ScreenSaverView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/screenSaverView"
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand Down Expand Up @@ -57,7 +57,7 @@
android:layout_marginTop="8dp"
android:layout_width="96dp"
android:layout_height="96dp"
android:tint="@color/blue_alpha"
app:tint="@color/blue_alpha"
tools:src="@drawable/ic_thunderstorm" />

</LinearLayout>
Expand Down Expand Up @@ -124,7 +124,7 @@
android:layout_marginTop="4dp"
android:layout_width="64dp"
android:layout_height="64dp"
android:tint="@color/blue_alpha"
app:tint="@color/blue_alpha"
tools:src="@drawable/ic_thunderstorm" />

</LinearLayout>
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/res/layout-sw720dp/dialog_screen_saver.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
~ limitations under the License.
-->

<com.thanksmister.iot.mqtt.alarmpanel.ui.views.ScreenSaverView
xmlns:android="http://schemas.android.com/apk/res/android"
<com.thanksmister.iot.mqtt.alarmpanel.ui.views.ScreenSaverView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/screenSaverView"
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand Down Expand Up @@ -57,7 +57,7 @@
android:layout_marginTop="8dp"
android:layout_width="96dp"
android:layout_height="96dp"
android:tint="@color/blue_alpha"
app:tint="@color/blue_alpha"
tools:src="@drawable/ic_thunderstorm" />

</LinearLayout>
Expand Down Expand Up @@ -125,7 +125,7 @@
android:layout_marginTop="4dp"
android:layout_width="64dp"
android:layout_height="64dp"
android:tint="@color/blue_alpha"
app:tint="@color/blue_alpha"
tools:src="@drawable/ic_thunderstorm" />

</LinearLayout>
Expand Down

0 comments on commit f2b23b3

Please sign in to comment.