Skip to content

Commit a4388b4

Browse files
committed
* Added support for Portuguese language
* Added option to turn off application sounds (beeping)
1 parent 84a4855 commit a4388b4

File tree

14 files changed

+347
-8
lines changed

14 files changed

+347
-8
lines changed

app/src/main/java/com/thanksmister/iot/mqtt/alarmpanel/BaseActivity.kt

+2
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ abstract class BaseActivity : DaggerAppCompatActivity() {
9292
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED or WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON,
9393
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED or WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON)
9494
decorView = window.decorView
95+
96+
lifecycle.addObserver(dialogUtils)
9597
}
9698

9799
override fun onStart(){

app/src/main/java/com/thanksmister/iot/mqtt/alarmpanel/ui/Configuration.kt

+5
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ constructor(private val sharedPreferences: DPreference) {
8787
get() = this.sharedPreferences.getPrefBoolean(PREF_PLATFORM_BAR, true)
8888
set(value) = this.sharedPreferences.setPrefBoolean(PREF_PLATFORM_BAR, value)
8989

90+
var systemSounds: Boolean
91+
get() = this.sharedPreferences.getPrefBoolean(PREF_SYSTEM_SOUNDS, true)
92+
set(value) = this.sharedPreferences.setPrefBoolean(PREF_SYSTEM_SOUNDS, value)
93+
9094
var telegramChatId: String
9195
get() = this.sharedPreferences.getPrefString(PREF_TELEGRAM_CHAT_ID, "")
9296
set(value) = this.sharedPreferences.setPrefString(PREF_TELEGRAM_CHAT_ID, value)
@@ -274,6 +278,7 @@ constructor(private val sharedPreferences: DPreference) {
274278
@JvmField val PREF_IMAGE_CLIENT_ID = "pref_image_client_id"
275279
@JvmField val PREF_INACTIVITY_TIME = "pref_inactivity_time"
276280
@JvmField val PREF_MODULE_NOTIFICATION = "pref_module_notification"
281+
@JvmField val PREF_SYSTEM_SOUNDS = "pref_system_sounds"
277282
@JvmField val PREF_MODULE_TSS = "pref_module_tss"
278283
@JvmField val PREF_SYSTEM_NOTIFICATIONS = "pref_system_notifications"
279284
@JvmField val PREF_MODULE_ALERTS = "pref_module_alerts"

app/src/main/java/com/thanksmister/iot/mqtt/alarmpanel/ui/activities/MainActivity.kt

+5-1
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,11 @@ class MainActivity : BaseActivity(), ViewPager.OnPageChangeListener, ControlsFra
336336
override fun onMQTTException(message: String) {
337337
Timber.d("onMQTTException")
338338
this@MainActivity.runOnUiThread {
339-
dialogUtils.showAlertDialog(this@MainActivity, message)
339+
dialogUtils.showAlertDialog(this@MainActivity, message, DialogInterface.OnClickListener { _, _ ->
340+
if (mqttModule != null) {
341+
mqttModule!!.restart()
342+
}
343+
})
340344
}
341345
}
342346

app/src/main/java/com/thanksmister/iot/mqtt/alarmpanel/ui/fragments/AlarmSettingsFragment.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ class AlarmSettingsFragment : PreferenceFragmentCompat(), SharedPreferences.OnSh
240240
}, DialogInterface.OnCancelListener {
241241
confirmCode = false
242242
Toast.makeText(activity, R.string.toast_code_unchanged, Toast.LENGTH_SHORT).show()
243-
})
243+
}, configuration.systemSounds)
244244
}
245245
}
246246
}

app/src/main/java/com/thanksmister/iot/mqtt/alarmpanel/ui/fragments/ControlsFragment.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ class ControlsFragment : BaseFragment() {
286286
Timber.d("onCancel")
287287
dialogUtils.clearDialogs()
288288
}
289-
}, viewModel.getAlarmCode(), false, delayTime)
289+
}, viewModel.getAlarmCode(), false, delayTime, configuration.systemSounds)
290290
}
291291

292292
companion object {

app/src/main/java/com/thanksmister/iot/mqtt/alarmpanel/ui/fragments/MainFragment.kt

+3-2
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ class MainFragment : BaseFragment() {
155155
override fun onCancel() {
156156
dialogUtils.clearDialogs()
157157
}
158-
})
158+
}, configuration.systemSounds)
159159
}
160160
}
161161

@@ -177,7 +177,7 @@ class MainFragment : BaseFragment() {
177177
override fun onCancel() {
178178
dialogUtils.clearDialogs()
179179
}
180-
}, configuration.alarmCode, true, delayTime)
180+
}, configuration.alarmCode, true, delayTime, configuration.systemSounds)
181181
}
182182
}
183183

@@ -188,6 +188,7 @@ class MainFragment : BaseFragment() {
188188
val code = configuration.alarmCode
189189
val disarmView = activity!!.findViewById<AlarmTriggeredView>(R.id.alarmTriggeredView)
190190
disarmView.setCode(code)
191+
disarmView.setUseSound(configuration.systemSounds)
191192
disarmView.listener = object : AlarmTriggeredView.ViewListener {
192193
override fun onComplete() {
193194
listener!!.publishDisarmed()

app/src/main/java/com/thanksmister/iot/mqtt/alarmpanel/ui/fragments/NotificationsSettingsFragment.kt

+7
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class NotificationsSettingsFragment : PreferenceFragmentCompat(), SharedPreferen
4646
private var systemPreference: CheckBoxPreference? = null
4747
private var notificationsPreference: CheckBoxPreference? = null
4848
private var tssPreference: CheckBoxPreference? = null
49+
private var soundPreference: CheckBoxPreference? = null
4950
private var alertsPreference: CheckBoxPreference? = null
5051
private var descriptionPreference: Preference? = null
5152
private var mqttOptions: MQTTOptions? = null
@@ -87,6 +88,7 @@ class NotificationsSettingsFragment : PreferenceFragmentCompat(), SharedPreferen
8788

8889
topicPreference = findPreference(PREF_NOTIFICATION_TOPIC) as EditTextPreference
8990
notificationsPreference = findPreference(Configuration.PREF_MODULE_NOTIFICATION) as CheckBoxPreference
91+
soundPreference = findPreference(Configuration.PREF_SYSTEM_SOUNDS) as CheckBoxPreference
9092
tssPreference = findPreference(Configuration.PREF_MODULE_TSS) as CheckBoxPreference
9193
alertsPreference = findPreference(Configuration.PREF_MODULE_ALERTS) as CheckBoxPreference
9294
systemPreference = findPreference(Configuration.PREF_SYSTEM_NOTIFICATIONS) as CheckBoxPreference
@@ -96,6 +98,7 @@ class NotificationsSettingsFragment : PreferenceFragmentCompat(), SharedPreferen
9698
tssPreference!!.isChecked = configuration.hasTssModule()
9799
alertsPreference!!.isChecked = configuration.hasAlertsModule()
98100
systemPreference!!.isChecked = configuration.hasSystemAlerts()
101+
soundPreference!!.isChecked = configuration.systemSounds
99102

100103
if (!TextUtils.isEmpty(mqttOptions!!.getNotificationTopic())) {
101104
topicPreference!!.text = mqttOptions!!.getNotificationTopic()
@@ -128,6 +131,10 @@ class NotificationsSettingsFragment : PreferenceFragmentCompat(), SharedPreferen
128131
tssPreference!!.isEnabled = checked
129132
alertsPreference!!.isEnabled = checked
130133
}
134+
Configuration.PREF_SYSTEM_SOUNDS -> {
135+
val sounds = soundPreference!!.isChecked
136+
configuration.systemSounds = sounds
137+
}
131138
Configuration.PREF_MODULE_TSS -> {
132139
val tss = tssPreference!!.isChecked
133140
configuration.setTssModule(tss)

app/src/main/java/com/thanksmister/iot/mqtt/alarmpanel/ui/views/BaseAlarmView.kt

+14
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ abstract class BaseAlarmView : LinearLayout {
1616
var currentCode: Int = 0
1717
var codeComplete = false
1818
var enteredCode = ""
19+
var useSystemSound: Boolean = true
1920

2021
private var soundUtils: SoundUtils? = null
2122

@@ -105,6 +106,10 @@ abstract class BaseAlarmView : LinearLayout {
105106
destroySoundUtils()
106107
}
107108

109+
fun setUseSound(value: Boolean) {
110+
useSystemSound = value
111+
}
112+
108113
fun setCode(code: Int) {
109114
currentCode = code
110115
}
@@ -115,12 +120,18 @@ abstract class BaseAlarmView : LinearLayout {
115120
abstract fun reset()
116121

117122
fun destroySoundUtils() {
123+
if(!useSystemSound)
124+
return
125+
118126
if (soundUtils != null) {
119127
soundUtils?.destroyBuzzer()
120128
}
121129
}
122130

123131
private fun playButtonPress() {
132+
if(!useSystemSound)
133+
return
134+
124135
if (soundUtils == null) {
125136
soundUtils = SoundUtils(context)
126137
soundUtils?.init()
@@ -129,6 +140,9 @@ abstract class BaseAlarmView : LinearLayout {
129140
}
130141

131142
fun playContinuousBeep() {
143+
if(!useSystemSound)
144+
return
145+
132146
if (soundUtils == null) {
133147
soundUtils = SoundUtils(context)
134148
soundUtils?.init()

app/src/main/java/com/thanksmister/iot/mqtt/alarmpanel/utils/DialogUtils.kt

+6-3
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,14 @@ class DialogUtils(base: Context?) : ContextWrapper(base), LifecycleObserver {
151151
* it resets the timer.
152152
*/
153153
fun showAlarmDisableDialog(activity: AppCompatActivity, alarmCodeListener: AlarmDisableView.ViewListener,
154-
code: Int, beep: Boolean, timeRemaining: Int) {
154+
code: Int, beep: Boolean, timeRemaining: Int, systemSounds: Boolean) {
155155
clearDialogs()
156156
val inflater = activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
157157
val view = inflater.inflate(R.layout.dialog_alarm_disable, null, false)
158158
val alarmCodeView = view.findViewById<AlarmDisableView>(R.id.alarmDisableView)
159159
alarmCodeView.setListener(alarmCodeListener)
160160
alarmCodeView.setCode(code)
161+
alarmCodeView.setUseSound(systemSounds)
161162
alarmCodeView.startCountDown(timeRemaining)
162163
if (beep) {
163164
alarmCodeView.playContinuousBeep()
@@ -166,18 +167,19 @@ class DialogUtils(base: Context?) : ContextWrapper(base), LifecycleObserver {
166167
dialog!!.setOnDismissListener { alarmCodeView.destroySoundUtils() }
167168
}
168169

169-
fun showSettingsCodeDialog(activity: AppCompatActivity, code: Int, listener: SettingsCodeView.ViewListener) {
170+
fun showSettingsCodeDialog(activity: AppCompatActivity, code: Int, listener: SettingsCodeView.ViewListener, systemSounds: Boolean) {
170171
clearDialogs()
171172
val inflater = activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
172173
val view = inflater.inflate(R.layout.dialog_settings_code, null, false)
173174
val settingsCodeView = view.findViewById<SettingsCodeView>(R.id.settingsCodeView)
174175
settingsCodeView.setCode(code)
175176
settingsCodeView.setListener(listener)
177+
settingsCodeView.setUseSound(systemSounds)
176178
dialog = buildImmersiveDialog(activity, true, view, false)
177179
}
178180

179181
fun showCodeDialog(activity: AppCompatActivity, confirmCode: Boolean, listener: AlarmCodeView.ViewListener,
180-
onCancelListener: DialogInterface.OnCancelListener) {
182+
onCancelListener: DialogInterface.OnCancelListener, systemSounds: Boolean) {
181183
clearDialogs()
182184
val inflater = activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
183185
val view = inflater.inflate(R.layout.dialog_alarm_code_set, null, false)
@@ -187,6 +189,7 @@ class DialogUtils(base: Context?) : ContextWrapper(base), LifecycleObserver {
187189
titleTextView.setText(R.string.text_renter_alarm_code_title)
188190
}
189191
alarmCodeView.setListener(listener)
192+
alarmCodeView.setUseSound(systemSounds)
190193
dialog = buildImmersiveDialog(activity, true, view, false)
191194
dialog!!.setOnCancelListener(onCancelListener)
192195
}

app/src/main/res/values-es/strings.xml

+2
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,8 @@
246246
<string name="pref_camera_send_image_notes">Puedes usar Telegram, Mailgun o ambos para enviar imágenes capturadas.</string>
247247
<string name="menu_item_help">Ayuda</string>
248248
<string name="error_mailgun_credentials">Hubo un problema al enviar la imagen por correo, compruebe sus credenciales de Mailgun.</string>
249+
<string name="pref_system_sounds_summary">Alternar el sonido utilizado para presionar botones y diálogos.</string>
250+
<string name="pref_system_sounds_title">Sonidos del sistema</string>
249251

250252
<string-array name="inactivity_times">
251253
<item>15 segundos</item>

app/src/main/res/values-nl/strings.xml

+2
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,8 @@
246246
<string name="pref_camera_send_image_notes">U kunt Telegram, Mailgun of beide gebruiken om vastgelegde afbeeldingen te verzenden.</string>
247247
<string name="menu_item_help">Helpen</string>
248248
<string name="error_mailgun_credentials">Er is een probleem opgetreden bij het verzenden van de afbeelding. Controleer uw Mailgun-inloggegevens.</string>
249+
<string name="pref_system_sounds_summary">Schakel het geluid in dat wordt gebruikt voor het indrukken van knoppen en dialogen.</string>
250+
<string name="pref_system_sounds_title">Systeemgeluiden</string>
249251

250252
<string-array name="inactivity_times">
251253
<item>15 seconden</item>

0 commit comments

Comments
 (0)