Skip to content
Snippets Groups Projects
Commit dabd6e8e authored by Matthias Urhahn's avatar Matthias Urhahn
Browse files

Merge branch 'release/1.12.x' into release/1.13.x

parents 0eb0d3a8 8edbcbfd
No related branches found
No related tags found
No related merge requests found
......@@ -3,11 +3,13 @@ package de.rki.coronawarnapp.notification
import android.content.Context
import androidx.navigation.NavDeepLinkBuilder
import de.rki.coronawarnapp.R
import de.rki.coronawarnapp.storage.LocalData
import de.rki.coronawarnapp.ui.main.MainActivity
import de.rki.coronawarnapp.util.device.ForegroundState
import de.rki.coronawarnapp.util.di.AppContext
import de.rki.coronawarnapp.util.formatter.TestResult
import kotlinx.coroutines.flow.first
import timber.log.Timber
import javax.inject.Inject
import javax.inject.Provider
......@@ -21,6 +23,11 @@ class TestResultAvailableNotificationService @Inject constructor(
suspend fun showTestResultAvailableNotification(testResult: TestResult) {
if (foregroundState.isInForeground.first()) return
if (!LocalData.isNotificationsTestEnabled) {
Timber.i("Don't show test result available notification because user doesn't want to be informed")
return
}
val pendingIntent = navDeepLinkBuilderProvider.get().apply {
setGraph(R.navigation.nav_graph)
setComponentName(MainActivity::class.java)
......
......@@ -22,7 +22,7 @@ fun formatStatisticalValue(
return when (decimals) {
in Int.MIN_VALUE..0 -> DecimalFormat("#,###", DecimalFormatSymbols(locale))
1 -> DecimalFormat("#,###.#", DecimalFormatSymbols(locale))
1 -> DecimalFormat("#,###.0", DecimalFormatSymbols(locale))
else -> DecimalFormat("#,###.##", DecimalFormatSymbols(locale))
}.format(value)
}
......@@ -6,6 +6,7 @@ import android.content.Context
import androidx.navigation.NavDeepLinkBuilder
import de.rki.coronawarnapp.CoronaWarnApplication
import de.rki.coronawarnapp.R
import de.rki.coronawarnapp.storage.LocalData
import de.rki.coronawarnapp.util.device.ForegroundState
import de.rki.coronawarnapp.util.formatter.TestResult
import io.kotest.matchers.shouldBe
......@@ -41,11 +42,13 @@ class TestResultAvailableNotificationServiceTest {
MockKAnnotations.init(this)
mockkObject(CoronaWarnApplication)
mockkObject(LocalData)
every { CoronaWarnApplication.getAppContext() } returns context
every { context.getSystemService(Context.NOTIFICATION_SERVICE) } returns notificationManager
every { navDeepLinkBuilderProvider.get() } returns navDeepLinkBuilder
every { navDeepLinkBuilder.createPendingIntent() } returns pendingIntent
every { LocalData.isNotificationsTestEnabled } returns true
}
@AfterEach
......@@ -110,4 +113,23 @@ class TestResultAvailableNotificationServiceTest {
)
}
}
@Test
fun `test notification in background disabled`() = runBlockingTest {
coEvery { foregroundState.isInForeground } returns flow { emit(false) }
every { LocalData.isNotificationsTestEnabled } returns false
createInstance().apply {
showTestResultAvailableNotification(TestResult.POSITIVE)
verify(exactly = 0) {
notificationHelper.sendNotification(
title = any(),
content = any(),
notificationId = any(),
pendingIntent = any()
)
}
}
}
}
......@@ -55,6 +55,8 @@ internal class StatisticsNumberValueFormatterTest {
Arguments.of(12.3456, 1, Locale.GERMANY, "12,3"),
Arguments.of(12.3456, 2, Locale.GERMANY, "12,35"),
Arguments.of(1.0036, 1, Locale.GERMANY, "1,0"),
Arguments.of(12.3456, 1, Locale.UK, "12.3"),
Arguments.of(12.6543, -1, Locale.GERMANY, "13"),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment