Skip to content

Commit

Permalink
* ignore alarmo arming events when they have no delays, this is same …
Browse files Browse the repository at this point in the history
…as receiving the state change

* add feature to disable the bottom bar on the dashboard displays
* increase inactivity time for settings
  • Loading branch information
thanksmister committed May 31, 2021
1 parent 9a3556a commit 326b757
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 53 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ apply plugin: 'com.google.firebase.crashlytics'
def versionMajor = 1
def versionMinor = 1
def versionPatch = 1
def versionBuild = 5 // bump for dog food builds, public betas, etc.
def versionBuild = 6 // 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 @@ -428,12 +428,7 @@ class AlarmPanelService : LifecycleService(), MQTTModule.MQTTListener {
STATE_ARM_NIGHT,
STATE_ARM_AWAY,
STATE_ARM_HOME,
STATE_DISARM,
COMMAND_ARM_CUSTOM_BYPASS,
COMMAND_ARM_NIGHT,
COMMAND_ARM_AWAY,
COMMAND_DISARM,
COMMAND_ARM_HOME -> {
STATE_DISARM -> {
insertMessage(id, topic, payload, TYPE_ALARM, delay)
}
STATE_TRIGGERED -> {
Expand Down Expand Up @@ -479,9 +474,7 @@ class AlarmPanelService : LifecycleService(), MQTTModule.MQTTListener {
* Publish command with default payload.
*/
private fun publishCommand(command: String, message: String) {
mqttModule?.let {
it.publishCommand(command, message)
}
mqttModule?.publishCommand(command, message)
}

/**
Expand Down Expand Up @@ -701,16 +694,15 @@ class AlarmPanelService : LifecycleService(), MQTTModule.MQTTListener {
sendAlertMessage(getString(R.string.error_arm_failed))
insertMessage(id, topic, event, TYPE_EVENT)
}
// TODO hack for events from alarmo with no delay values, they should be ignored and only use alarm state
STATE_ARM_HOME,
STATE_ARM_AWAY,
STATE_ARM_NIGHT,
STATE_ARM_CUSTOM_BYPASS,
COMMAND_ARM_HOME,
COMMAND_ARM_AWAY,
COMMAND_ARM_NIGHT,
COMMAND_ARM_CUSTOM_BYPASS -> {
STATE_ARM_CUSTOM_BYPASS -> {
val delay = MqttUtils.parseDelayFromJson(payload)
insertMessage(id, topic, event, TYPE_ALARM, delay)
if(delay > 0) {
insertMessage(id, topic, event, TYPE_ALARM, delay)
}
}
// TODO this is a hack for alarmo because does not append delay time to pending
EVENT_TRIGGER -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,7 @@ constructor(private val context: Context, private val sharedPreferences: SharedP
return (alarmMode == MqttUtils.STATE_ARM_HOME
|| alarmMode == MqttUtils.STATE_ARM_CUSTOM_BYPASS
|| alarmMode == MqttUtils.STATE_ARM_NIGHT
|| alarmMode == MqttUtils.STATE_ARM_AWAY
|| alarmMode == MqttUtils.COMMAND_ARM_HOME
|| alarmMode == MqttUtils.COMMAND_ARM_CUSTOM_BYPASS
|| alarmMode == MqttUtils.COMMAND_ARM_NIGHT
|| alarmMode == MqttUtils.COMMAND_ARM_AWAY)
|| alarmMode == MqttUtils.STATE_ARM_AWAY)
}

fun isAlarmDisarmedMode(): Boolean {
Expand Down Expand Up @@ -160,7 +156,7 @@ constructor(private val context: Context, private val sharedPreferences: SharedP
get() = sharedPreferences.getBoolean(PREF_HARDWARE_ACCELERATION, false)
set(value) = sharedPreferences.edit().putBoolean(PREF_HARDWARE_ACCELERATION, value).apply()

var platformBar: Boolean
var dashboardBar: Boolean
get() = this.sharedPreferences.getBoolean(PREF_PLATFORM_BAR, true)
set(value) = this.sharedPreferences.edit().putBoolean(PREF_PLATFORM_BAR, value).apply()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import com.thanksmister.iot.mqtt.alarmpanel.constants.CodeTypes
import com.thanksmister.iot.mqtt.alarmpanel.network.AlarmPanelService
import com.thanksmister.iot.mqtt.alarmpanel.network.AlarmPanelService.Companion.BROADCAST_EVENT_PUBLISH_PANIC
import com.thanksmister.iot.mqtt.alarmpanel.network.AlarmPanelService.Companion.BROADCAST_SNACK_MESSAGE
import com.thanksmister.iot.mqtt.alarmpanel.network.MQTTOptions
import com.thanksmister.iot.mqtt.alarmpanel.persistence.Weather
import com.thanksmister.iot.mqtt.alarmpanel.ui.adapters.MainSlidePagerAdapter
import com.thanksmister.iot.mqtt.alarmpanel.ui.fragments.*
Expand Down Expand Up @@ -764,7 +763,7 @@ class MainActivity : BaseActivity(),
dots[i].setImageDrawable(drawable)
}
if(idx == 0) {
//settingsContainer.visibility = View.VISIBLE
settingsContainer.visibility = View.VISIBLE
buttonSettings.visibility = View.VISIBLE
if (configuration.hasScreenSaver()) {
buttonSleep.visibility = View.VISIBLE
Expand All @@ -779,10 +778,10 @@ class MainActivity : BaseActivity(),
buttonRefresh.visibility = View.GONE
platformButton.visibility = View.GONE
} else {
if(configuration.platformBar.not()) {
// settingsContainer.visibility = View.GONE
if(configuration.dashboardBar.not()) {
settingsContainer.visibility = View.GONE
} else {
//settingsContainer.visibility = View.VISIBLE
settingsContainer.visibility = View.VISIBLE
buttonSleep.visibility = View.GONE
alertButton.visibility = View.GONE
buttonRefresh.visibility = View.VISIBLE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class SettingsActivity : DaggerAppCompatActivity(){

override fun onResume() {
super.onResume()
inactivityHandler.postDelayed(inactivityCallback, 60000)
inactivityHandler.postDelayed(inactivityCallback, 180000)
}

override fun onDestroy() {
Expand All @@ -131,7 +131,7 @@ class SettingsActivity : DaggerAppCompatActivity(){

override fun onUserInteraction() {
inactivityHandler.removeCallbacks(inactivityCallback)
inactivityHandler.postDelayed(inactivityCallback, 60000)
inactivityHandler.postDelayed(inactivityCallback, 180000)
}

private fun logs() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,21 +232,16 @@ class ControlsFragment : BaseFragment() {
setArmedMode(payload, delay)
}
STATE_ARMING -> {
if (configuration.isAlarmArming().not()) {
if (configuration.isAlarmArming().not() && configuration.isAlarmArmedMode().not()) {
setArmingMode(payload, delay)
}
}
STATE_ARM_CUSTOM_BYPASS,
STATE_ARM_NIGHT,
STATE_ARM_HOME,
STATE_DISARM,
STATE_ARM_AWAY,
COMMAND_ARM_CUSTOM_BYPASS,
COMMAND_ARM_HOME,
COMMAND_ARM_NIGHT,
COMMAND_ARM_AWAY,
COMMAND_DISARM -> {
if (configuration.isAlarmArmedMode().not()) {
STATE_ARM_AWAY -> {
if (configuration.isAlarmArmedMode().not() && configuration.isAlarmArming().not()) {
setArmingMode(payload, delay)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,11 @@ import android.content.Context
import android.content.Intent
import android.content.SharedPreferences
import android.os.Bundle
import android.text.TextUtils
import android.view.View
import androidx.preference.*
import com.thanksmister.iot.mqtt.alarmpanel.R
import com.thanksmister.iot.mqtt.alarmpanel.persistence.Configuration
import com.thanksmister.iot.mqtt.alarmpanel.ui.activities.DashboardsActivity
import com.thanksmister.iot.mqtt.alarmpanel.ui.activities.LiveCameraActivity
import com.thanksmister.iot.mqtt.alarmpanel.ui.activities.SensorsActivity
import com.thanksmister.iot.mqtt.alarmpanel.ui.activities.SettingsActivity
import dagger.android.support.AndroidSupportInjection
import javax.inject.Inject
Expand All @@ -37,12 +34,14 @@ class PlatformSettingsFragment : PreferenceFragmentCompat(), SharedPreferences.O
@Inject lateinit var configuration: Configuration

private var browserHeaderPreference: EditTextPreference? = null
private var platformBarPreference: CheckBoxPreference? = null

private val manageDashboardsPreference: Preference by lazy {
findPreference("button_dashboards") as Preference
}

private val platformBarPreference: SwitchPreference by lazy {
findPreference("pref_platform_bar") as SwitchPreference
}

override fun onAttach(context: Context) {
AndroidSupportInjection.inject(this)
super.onAttach(context)
Expand Down Expand Up @@ -78,9 +77,9 @@ class PlatformSettingsFragment : PreferenceFragmentCompat(), SharedPreferences.O
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {

super.onViewCreated(view, savedInstanceState)
platformBarPreference = findPreference("pref_platform_bar") as CheckBoxPreference

browserHeaderPreference = findPreference(getString(R.string.key_setting_browser_user_agent)) as EditTextPreference
platformBarPreference?.isChecked = configuration.platformBar
platformBarPreference.isChecked = configuration.dashboardBar

manageDashboardsPreference.onPreferenceClickListener = Preference.OnPreferenceClickListener {
startDashboardsActivity(it.context)
Expand All @@ -95,8 +94,7 @@ class PlatformSettingsFragment : PreferenceFragmentCompat(), SharedPreferences.O
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String) {
when (key) {
"pref_platform_bar" -> {
val checked = platformBarPreference!!.isChecked
configuration.platformBar = checked
configuration.dashboardBar = platformBarPreference.isChecked
}
getString(R.string.key_setting_browser_user_agent) -> {
val value = browserHeaderPreference!!.text
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@
<string name="toast_screen_timeout">Screen timed out…</string>
<string name="button_hide_text">Hide</string>
<string name="pref_title_platform_bar">Show Bottom Bar</string>
<string name="pref_description_show_platform_bar">When checked, displays a bottom navigation buttons on the platform screen.</string>
<string name="pref_description_show_platform_bar">When checked, displays a bottom navigation buttons on the dashboard screen.</string>
<string name="pref_telegram_title">Telegram</string>
<string name="pref_telegram_chat_id_summary">Enter your Telegram bot chat id.</string>
<string name="pref_telegram_token_summary">Enter your Telegram bot API token.</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/xml/preferences_platform.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
android:summary="Add, edit, and remove dashboards."
android:title="Manage Dashboards" />

<CheckBoxPreference
<SwitchPreference
android:defaultValue="true"
android:key="pref_platform_bar"
android:summary="@string/pref_description_show_platform_bar"
Expand Down
11 changes: 6 additions & 5 deletions app/src/main/res/xml/preferences_screen.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@
android:title="@string/preference_title_sun"
android:textSize="12sp"/>

<SwitchPreference
android:defaultValue="true"
android:key="pref_settings_inactivity_timer"
android:title="Enable switch screens on inactivity"
android:summary="When active, screen will switch to alarm screen on user inactivity."/>

</PreferenceCategory>

<PreferenceCategory android:title="@string/pref_title_screen_brightness">
Expand Down Expand Up @@ -104,11 +110,6 @@
android:summary="When active, uses unsplash.it to get random wallpapers"
android:key="pref_screensaver_wallpaper" />

<SwitchPreference
android:defaultValue="true"
android:key="pref_settings_inactivity_timer"
android:title="Enable switch screens on inactivity"
android:summary="When active, screen will switch to alarm screen on user inactivity."/>

<EditTextPreference
android:key="pref_settings_image_rotation"
Expand Down

0 comments on commit 326b757

Please sign in to comment.