Skip to content

Commit 8592f8c

Browse files
authored
Improve warning setup (#373)
* show out of data area * refactor and add tests * update java * update * cleanup * cleanup * cleanup * tests * add more tests * refactor AlarmView * more refactoring * fix issue * cleanup * more refactoring * add AlarmView test * add tests * another test * add tests * add two more tests
1 parent 490d82c commit 8592f8c

File tree

71 files changed

+3631
-1614
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+3631
-1614
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
uses: actions/setup-java@dded0888837ed1f317902acf8a20df0ad188d165 # v5.0.0
2525
with:
2626
distribution: 'zulu'
27-
java-version: '17'
27+
java-version: '21'
2828

2929
- name: Setup Android SDK
3030
uses: android-actions/setup-android@9fc6c4e9069bf8d3d10b2204b1fb8f6ef7065407 # v3.2.2

app/build.gradle.kts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ android {
4141
}
4242

4343
compileOptions {
44-
sourceCompatibility = JavaVersion.VERSION_17
45-
targetCompatibility = JavaVersion.VERSION_17
44+
sourceCompatibility = JavaVersion.VERSION_21
45+
targetCompatibility = JavaVersion.VERSION_21
4646
}
4747

4848
kotlin {
49-
jvmToolchain(17)
49+
jvmToolchain(21)
5050
compilerOptions {
5151
apiVersion.set(KotlinVersion.KOTLIN_2_2)
5252
}

app/src/androidTest/java/org/blitzortung/android/app/MainTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class MainTest {
2525
@get:Rule
2626
val activityRule = ActivityScenarioRule(Main::class.java)
2727

28-
private lateinit var uiDevice: androidx.test.uiautomator.UiDevice
28+
private lateinit var uiDevice: UiDevice
2929
private val timeout = 5000L // 5 seconds
3030

3131
@Before

app/src/main/java/org/blitzortung/android/alert/AlertLabelHandler.kt

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,33 +19,47 @@
1919
package org.blitzortung.android.alert
2020

2121
import android.content.Context
22-
import org.blitzortung.android.app.R
22+
import org.blitzortung.android.app.R.color.Green
23+
import org.blitzortung.android.app.R.color.RedWarn
24+
import org.blitzortung.android.app.R.color.Yellow
2325

2426
class AlertLabelHandler(
2527
private val alertLabel: AlertLabel,
2628
private val context: Context,
2729
) {
28-
fun apply(result: AlertResult?) {
29-
var warningText = ""
30+
fun apply(result: Warning) {
3031

31-
var textColorResource = R.color.Green
32-
33-
if (result != null && result.closestStrikeDistance < Float.POSITIVE_INFINITY) {
34-
textColorResource =
35-
when (result.closestStrikeDistance) {
36-
in 0.0..20.0 -> R.color.RedWarn
37-
in 20.0..50.0 -> R.color.Yellow
38-
else -> R.color.Green
39-
}
40-
val distanceUnit = context.resources.getString(result.parameters.measurementSystem.unitNameString)
41-
warningText = "%.0f$distanceUnit".format(result.closestStrikeDistance)
42-
if (result.closestStrikeDistance > 0.1) {
43-
warningText += " ${result.bearingName}"
44-
}
32+
val (warningText, textColorResource) = when (result) {
33+
is LocalActivity -> extractStatus(result)
34+
Outlying -> "<->" to RedWarn
35+
NoData -> "" to Green
36+
NoLocation -> "?" to RedWarn
4537
}
4638

4739
val color = context.getColor(textColorResource)
4840
alertLabel.setAlarmTextColor(color)
4941
alertLabel.setAlarmText(warningText)
5042
}
43+
44+
fun extractStatus(result: LocalActivity): Pair<String, Int> {
45+
return if (result.closestStrikeDistance < Float.POSITIVE_INFINITY) {
46+
val textColorResource =
47+
when (result.closestStrikeDistance) {
48+
in 0.0..20.0 -> RedWarn
49+
in 20.0..50.0 -> Yellow
50+
else -> Green
51+
}
52+
val distanceUnit = context.resources.getString(result.parameters.measurementSystem.unitNameString)
53+
val status =
54+
"%.0f$distanceUnit".format(result.closestStrikeDistance) + if (result.closestStrikeDistance > 0.1) {
55+
" ${result.bearingName}"
56+
} else {
57+
""
58+
}
59+
status to textColorResource
60+
} else {
61+
"" to Green
62+
}
63+
}
64+
5165
}

app/src/main/java/org/blitzortung/android/alert/AlertParameters.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,6 @@ data class AlertParameters(
2525
val rangeSteps: List<Float>,
2626
val sectorLabels: List<String>,
2727
val measurementSystem: MeasurementSystem,
28-
)
28+
) {
29+
val sectorWidth = (360 / sectorLabels.size).toFloat()
30+
}

app/src/main/java/org/blitzortung/android/alert/AlertResult.kt renamed to app/src/main/java/org/blitzortung/android/alert/Warning.kt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,20 @@ package org.blitzortung.android.alert
2020

2121
import org.blitzortung.android.alert.data.AlertSector
2222

23-
data class AlertResult(
23+
sealed interface Warning
24+
25+
object Outlying : Warning
26+
27+
object NoData : Warning
28+
29+
object NoLocation : Warning
30+
31+
data class LocalActivity(
2432
val sectors: List<AlertSector>,
2533
val parameters: AlertParameters,
2634
val referenceTime: Long,
27-
) {
35+
) : Warning {
36+
2837
val sectorsByDistance: Map<Float, AlertSector> by lazy {
2938
sectors
3039
.filter { it.closestStrikeDistance < Float.POSITIVE_INFINITY }

app/src/main/java/org/blitzortung/android/alert/event/AlertCancelEvent.kt

Lines changed: 0 additions & 23 deletions
This file was deleted.

app/src/main/java/org/blitzortung/android/alert/event/AlertEvent.kt

Lines changed: 0 additions & 23 deletions
This file was deleted.

app/src/main/java/org/blitzortung/android/alert/event/AlertResultEvent.kt

Lines changed: 0 additions & 25 deletions
This file was deleted.

app/src/main/java/org/blitzortung/android/alert/handler/AlertDataHandler.kt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ import android.location.Location
2323
import android.util.Log
2424
import javax.inject.Inject
2525
import kotlin.math.max
26+
import org.blitzortung.android.alert.LocalActivity
2627
import org.blitzortung.android.alert.AlertParameters
27-
import org.blitzortung.android.alert.AlertResult
28+
import org.blitzortung.android.alert.Warning
29+
import org.blitzortung.android.alert.Outlying
2830
import org.blitzortung.android.alert.data.AlertSector
2931
import org.blitzortung.android.app.Main.Companion.LOG_TAG
3032
import org.blitzortung.android.data.beans.GridElement
@@ -44,7 +46,7 @@ open class AlertDataHandler
4446
location: Location,
4547
parameters: AlertParameters,
4648
referenceTime: Long = System.currentTimeMillis(),
47-
): AlertResult? {
49+
): Warning {
4850
val gridParameters: GridParameters? = strikes.gridParameters
4951
if (gridParameters != null &&
5052
!gridParameters.isGlobal &&
@@ -58,7 +60,7 @@ open class AlertDataHandler
5860
LOG_TAG,
5961
"Location $location is not in grid ${gridParameters.longitudeInterval} + ${gridParameters.latitudeInterval}",
6062
)
61-
return null
63+
return Outlying
6264
}
6365

6466
val sectors = createSectors(parameters)
@@ -83,7 +85,7 @@ open class AlertDataHandler
8385
}
8486
}
8587

86-
return AlertResult(sectors.map { aggregatingAlertDataMapper.mapSector(it) }, parameters, referenceTime)
88+
return LocalActivity(sectors.map { aggregatingAlertDataMapper.mapSector(it) }, parameters, referenceTime)
8789
}
8890

8991
private fun checkStrike(
@@ -141,13 +143,13 @@ open class AlertDataHandler
141143

142144
fun getLatestTimstampWithin(
143145
distanceLimit: Float,
144-
alertResult: AlertResult,
146+
alertResult: LocalActivity,
145147
): Long = alertResult.sectors.fold(0L) { latestTimestamp, sector ->
146148
max(latestTimestamp, getLatestTimestampWithin(distanceLimit, sector))
147149
}
148150

149151
fun getTextMessage(
150-
alertResult: AlertResult,
152+
alertResult: LocalActivity,
151153
notificationDistanceLimit: Float,
152154
resources: Resources,
153155
): String = alertResult.sectorsByDistance

0 commit comments

Comments
 (0)