From 71cb4c191a5789b577778bfac1b06d20755d8307 Mon Sep 17 00:00:00 2001 From: Michael Huebler Date: Tue, 1 Sep 2020 21:02:08 +0200 Subject: [PATCH] Don't wrap around times after midnight in Details View. Closes #34 --- .../MatchesRecyclerViewAdapter.java | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/corona-warn-companion/src/main/java/org/tosl/coronawarncompanion/matchentries/MatchesRecyclerViewAdapter.java b/corona-warn-companion/src/main/java/org/tosl/coronawarncompanion/matchentries/MatchesRecyclerViewAdapter.java index 54bbdf3..89b641d 100644 --- a/corona-warn-companion/src/main/java/org/tosl/coronawarncompanion/matchentries/MatchesRecyclerViewAdapter.java +++ b/corona-warn-companion/src/main/java/org/tosl/coronawarncompanion/matchentries/MatchesRecyclerViewAdapter.java @@ -87,6 +87,7 @@ public MatchesRecyclerViewAdapter(DailyMatchEntries dailyMatchEntries, Context c this.mContext = context; this.mValues = new ArrayList<>(); TreeMap> treeMap = new TreeMap<>(); + // Sorted TreeMap > for (Map.Entry entry : dailyMatchEntries.getMap().entrySet()) { treeMap.put(entry.getValue().getList().get(0).startTimestampUTC, new Pair<>(entry.getKey(), entry.getValue())); @@ -259,12 +260,14 @@ public MatchEntryDetails() { public static MatchEntryDetails getMatchEntryDetails(ArrayList list, int timeZoneOffset) { + // Get the details for one risk encounter. + // Threshold value for break detection: final int pauseThresholdSeconds = 10; MatchEntryDetails result = new MatchEntryDetails(); - result.minTimestampLocalTZDay0 = Integer.MAX_VALUE; - result.maxTimestampLocalTZDay0 = Integer.MIN_VALUE; + int minTimestampLocalTZ = Integer.MAX_VALUE; + int maxTimestampLocalTZ = Integer.MIN_VALUE; result.dataPoints = new ArrayList<>(); result.dotColors = new ArrayList<>(); result.dataPointsMinAttenuation = new ArrayList<>(); @@ -291,11 +294,9 @@ public static MatchEntryDetails getMatchEntryDetails(ArrayList txPower) { @@ -310,15 +311,20 @@ public static MatchEntryDetails getMatchEntryDetails(ArrayList timestampLocalTZDay0) { - result.minTimestampLocalTZDay0 = timestampLocalTZDay0; + if (minTimestampLocalTZ > timestampLocalTZ) { + minTimestampLocalTZ = timestampLocalTZ; } - if (result.maxTimestampLocalTZDay0 < timestampLocalTZDay0) { - result.maxTimestampLocalTZDay0 = timestampLocalTZDay0; + if (maxTimestampLocalTZ < timestampLocalTZ) { + maxTimestampLocalTZ = timestampLocalTZ; } } } + // reduce timestamp to "day0", to improve resolution within the float x value of the graph: + int timestampMinOffset= (minTimestampLocalTZ / (24*3600)) * (24*3600); + result.minTimestampLocalTZDay0 = minTimestampLocalTZ - timestampMinOffset; + result.maxTimestampLocalTZDay0 = maxTimestampLocalTZ - timestampMinOffset; + // Second step: Process each scan record, group them, find the minimum attenuation in each group ArrayList dataPointsBuffer = new ArrayList<>(); ArrayList dotColorsBuffer = new ArrayList<>(); @@ -329,7 +335,7 @@ public static MatchEntryDetails getMatchEntryDetails(ArrayList mapEntry : dataPointsInterimMap.entrySet()) { // iterate over sorted TreeMap - int timestampLocalTZDay0 = mapEntry.getKey(); + int timestampLocalTZDay0 = mapEntry.getKey() - timestampMinOffset; int attenuation = mapEntry.getValue(); // Second step: look for a break (>= pauseThresholdSeconds)