From f7a98c7a6b2a36e78b937ddaee3f9f874d9a8e7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Pro=C3=9F?= Date: Wed, 15 Jul 2020 16:03:49 +0200 Subject: [PATCH] Allow colon for estimated time of log reports --- .../res/layout/send_log_layout_new.xml | 2 +- org.envirocar.app/res/values/strings.xml | 4 +-- .../app/views/others/SendLogFileActivity.java | 29 +++++++++++++------ 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/org.envirocar.app/res/layout/send_log_layout_new.xml b/org.envirocar.app/res/layout/send_log_layout_new.xml index 9ed6a3542..a4ce37160 100644 --- a/org.envirocar.app/res/layout/send_log_layout_new.xml +++ b/org.envirocar.app/res/layout/send_log_layout_new.xml @@ -82,7 +82,7 @@ android:layout_height="wrap_content" android:gravity="start|top" android:imeOptions="actionNext" - android:inputType="number" + android:inputType="date|time" android:padding="12dp" /> diff --git a/org.envirocar.app/res/values/strings.xml b/org.envirocar.app/res/values/strings.xml index 3109359fb..27d2d629e 100644 --- a/org.envirocar.app/res/values/strings.xml +++ b/org.envirocar.app/res/values/strings.xml @@ -106,8 +106,8 @@ Report an Issue Summary of what went wrong - Time since crash: - in minutes + Estimated time + 10:00 No Checkbox Selected You have not selected any of the checkboxes. These help developers sort through issues quickly and resolve them. Please consider filling those that are relevant. diff --git a/org.envirocar.app/src/org/envirocar/app/views/others/SendLogFileActivity.java b/org.envirocar.app/src/org/envirocar/app/views/others/SendLogFileActivity.java index 20577726e..c818431b2 100644 --- a/org.envirocar.app/src/org/envirocar/app/views/others/SendLogFileActivity.java +++ b/org.envirocar.app/src/org/envirocar/app/views/others/SendLogFileActivity.java @@ -57,9 +57,11 @@ import java.io.FileFilter; import java.io.IOException; import java.text.DateFormat; +import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; +import java.util.Calendar; import java.util.Date; import java.util.List; import java.util.Locale; @@ -312,7 +314,7 @@ private String createComments() { } private String createEstimatedTimeStamp() { - long now = System.currentTimeMillis(); + String text; try { text = whenField.getText().toString(); @@ -321,15 +323,24 @@ private String createEstimatedTimeStamp() { text = null; } - int delta; - if (text == null || text.isEmpty()) { - delta = 0; - } else { - delta = Integer.parseInt(text); - } + String[] hoursAndMinutes = text.split(":"); - Date date = new Date(now - delta * 1000 * 60); - return SimpleDateFormat.getDateTimeInstance().format(date); + Calendar calendar = Calendar.getInstance(); + + if(hoursAndMinutes.length > 1){ + try { + calendar.set(Calendar.HOUR_OF_DAY, Integer.parseInt(hoursAndMinutes[0])); + } catch (Exception e) { + LOG.info("Could not parse hour of day."); + } + + try { + calendar.set(Calendar.MINUTE, Integer.parseInt(hoursAndMinutes[1])); + } catch (Exception e) { + LOG.info("Could not parse minute."); + } + } + return SimpleDateFormat.getDateTimeInstance().format(calendar.getTime()); }