Skip to content

Commit eff7585

Browse files
committed
Merge branch 'release-2.5.11'
* release-2.5.11: Bump versionCOde and versionName for 2.5.11 NotificationHelper: test that function to make sure it doesn't break in the future hotfix: NotificationHelper: fix crash on vibration preference parsing
2 parents 4a3e6e6 + a491540 commit eff7585

File tree

3 files changed

+76
-11
lines changed

3 files changed

+76
-11
lines changed

Calendula/build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ android {
7676
defaultConfig {
7777
minSdkVersion 18
7878
targetSdkVersion 26
79-
versionCode 41
80-
versionName "2.5.10"
79+
versionCode 42
80+
versionName "2.5.11"
8181
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
8282
applicationId "es.usc.citius.servando.calendula"
8383
multiDexEnabled true

Calendula/src/main/java/es/usc/citius/servando/calendula/notifications/NotificationHelper.kt

+9-9
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ object NotificationHelper {
3232

3333
@JvmField
3434
val VIBRATION_PATTERN_MEDS =
35-
longArrayOf(1000, 200, 100, 500, 400, 200, 100, 500, 400, 200, 100, 500, 1000)
35+
longArrayOf(1000, 200, 100, 500, 400, 200, 100, 500, 400, 200, 100, 500, 1000)
3636
@JvmField
3737
val VIBRATION_PATTERN_DEFAULT = longArrayOf(1000, 200, 500, 200, 100, 200, 1000)
3838
@JvmField
@@ -62,18 +62,18 @@ object NotificationHelper {
6262
val medChannelName = context.getString(R.string.channel_meds_name)
6363
val medChannelDesc = context.getString(R.string.channel_meds_description)
6464
val medChannel = NotificationChannel(
65-
CHANNEL_MEDS_ID,
66-
medChannelName,
67-
NotificationManager.IMPORTANCE_HIGH
65+
CHANNEL_MEDS_ID,
66+
medChannelName,
67+
NotificationManager.IMPORTANCE_HIGH
6868
)
6969
medChannel.description = medChannelDesc
7070
//create other channel
7171
val defaultChannelName = context.getString(R.string.channel_default_name)
7272
val defaultChannelDesc = context.getString(R.string.channel_default_description)
7373
val defaultChannel = NotificationChannel(
74-
CHANNEL_DEFAULT_ID,
75-
defaultChannelName,
76-
NotificationManager.IMPORTANCE_DEFAULT
74+
CHANNEL_DEFAULT_ID,
75+
defaultChannelName,
76+
NotificationManager.IMPORTANCE_DEFAULT
7777
)
7878

7979
defaultChannel.description = defaultChannelDesc
@@ -93,8 +93,8 @@ object NotificationHelper {
9393
@JvmStatic
9494
fun isNotificationVibrationEnabled(context: Context): Boolean {
9595

96-
val vibrationSettingInt =
97-
PreferenceUtils.getInt(PreferenceKeys.SETTINGS_NOTIFICATION_VIBRATION, 0)
96+
val vibrationSettingInt = Integer.parseInt(
97+
PreferenceUtils.getString(PreferenceKeys.SETTINGS_NOTIFICATION_VIBRATION, "0"))
9898
val audioManager = context.getSystemService(Context.AUDIO_SERVICE) as AudioManager
9999

100100
return when (vibrationSettingInt) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Calendula - An assistant for personal medication management.
3+
* Copyright (C) 2014-2018 CiTIUS - University of Santiago de Compostela
4+
*
5+
* Calendula is free software; you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation; either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this software. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
package es.usc.citius.servando.calendula.notifications
20+
21+
import es.usc.citius.servando.calendula.util.PreferenceKeys
22+
import es.usc.citius.servando.calendula.util.PreferenceUtils
23+
import org.junit.Assert.assertFalse
24+
import org.junit.Assert.assertTrue
25+
import org.junit.Test
26+
import org.junit.runner.RunWith
27+
import org.robolectric.RobolectricTestRunner
28+
import org.robolectric.RuntimeEnvironment
29+
30+
31+
@RunWith(RobolectricTestRunner::class)
32+
class NotificationHelperTest {
33+
34+
35+
@Test
36+
fun `Vibration is enabled when the vibration preference is the default value`() {
37+
PreferenceUtils.edit().remove(PreferenceKeys.SETTINGS_NOTIFICATION_VIBRATION.key()).apply()
38+
39+
val notificationVibrationEnabled =
40+
NotificationHelper.isNotificationVibrationEnabled(RuntimeEnvironment.systemContext)
41+
42+
assertTrue(notificationVibrationEnabled)
43+
}
44+
45+
@Test
46+
fun `Vibration is enabled when the vibration preference is set to vibrate`() {
47+
PreferenceUtils.edit().putString(PreferenceKeys.SETTINGS_NOTIFICATION_VIBRATION.key(), "0").apply()
48+
49+
val notificationVibrationEnabled =
50+
NotificationHelper.isNotificationVibrationEnabled(RuntimeEnvironment.systemContext)
51+
52+
assertTrue(notificationVibrationEnabled)
53+
}
54+
55+
56+
@Test
57+
fun `Vibration is disabled when the vibration preference is set to off`() {
58+
PreferenceUtils.edit().putString(PreferenceKeys.SETTINGS_NOTIFICATION_VIBRATION.key(), "3").apply()
59+
60+
val notificationVibrationEnabled =
61+
NotificationHelper.isNotificationVibrationEnabled(RuntimeEnvironment.systemContext)
62+
63+
assertFalse(notificationVibrationEnabled)
64+
}
65+
}

0 commit comments

Comments
 (0)