From c6f0572d9ae4e85a6828acf60a585e7cbaeda3e3 Mon Sep 17 00:00:00 2001 From: lubenard Date: Mon, 17 Jan 2022 15:20:45 +0100 Subject: [PATCH] Added datas and improved visibility on widget --- .../oring_reminder/CurrentSessionWidgetProvider.java | 9 +++++++-- .../custom_components/CustomListSearchAdapter.java | 4 ++-- .../custom_components/HistoryViewHolder.java | 4 ++-- .../oring_reminder/ui/EntryDetailsFragment.java | 10 +++++----- .../com/lubenard/oring_reminder/ui/MainFragment.java | 4 ++-- .../java/com/lubenard/oring_reminder/utils/Utils.java | 10 ++++++++-- app/src/main/res/values-de/strings.xml | 1 + app/src/main/res/values-fr/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 9 files changed, 29 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/com/lubenard/oring_reminder/CurrentSessionWidgetProvider.java b/app/src/main/java/com/lubenard/oring_reminder/CurrentSessionWidgetProvider.java index 085b838..7193956 100644 --- a/app/src/main/java/com/lubenard/oring_reminder/CurrentSessionWidgetProvider.java +++ b/app/src/main/java/com/lubenard/oring_reminder/CurrentSessionWidgetProvider.java @@ -118,9 +118,14 @@ public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] a timeBeforeRemove *= -1; } - remoteViews.setTextViewText(R.id.widget_date_from, lastEntry.getDatePut()); + String[] lastEntrySplitted = lastEntry.getDatePut().split(" "); + + String timeRemoval = context.getString(R.string.at) + Utils.getdateFormatted(calendar.getTime()).split(" ")[1]; + + remoteViews.setTextViewText(R.id.widget_date_from, Utils.convertDateIntoReadable(lastEntrySplitted[0], true) + "\n" + lastEntrySplitted[1]); remoteViews.setTextViewText(R.id.widget_worn_for, String.format("%dh%02dm", wornFor / 60, wornFor % 60)); - remoteViews.setTextViewText(R.id.widget_time_remaining, String.format(context.getString(textResourceWhenGetItOff), timeBeforeRemove / 60, timeBeforeRemove % 60)); + remoteViews.setTextViewText(R.id.widget_time_remaining, String.format(context.getString(textResourceWhenGetItOff), timeBeforeRemove / 60, timeBeforeRemove % 60) + "\n" + + timeRemoval); // Change 'Start session' button into 'Stop session' remoteViews.setTextViewText(R.id.widget_button_new_stop_session, context.getString(R.string.stop_active_session)); diff --git a/app/src/main/java/com/lubenard/oring_reminder/custom_components/CustomListSearchAdapter.java b/app/src/main/java/com/lubenard/oring_reminder/custom_components/CustomListSearchAdapter.java index c7719fc..98d929c 100644 --- a/app/src/main/java/com/lubenard/oring_reminder/custom_components/CustomListSearchAdapter.java +++ b/app/src/main/java/com/lubenard/oring_reminder/custom_components/CustomListSearchAdapter.java @@ -81,13 +81,13 @@ public View getView(int position, View convertView, ViewGroup parent) { // Forced to split with a space because the date format is YYYY-MM-dd hh:MM:ss String[] datePut = dataModel.getDatePut().split(" "); - viewHolder.worn_date.setText(Utils.convertDateIntoReadable(datePut[0])); + viewHolder.worn_date.setText(Utils.convertDateIntoReadable(datePut[0], false)); viewHolder.weared_from.setText(datePut[1]); if (!dataModel.getDateRemoved().equals("NOT SET YET")) { String[] dateRemoved = dataModel.getDateRemoved().split(" "); - viewHolder.worn_date.setText(Utils.convertDateIntoReadable(datePut[0]) + " -> " + Utils.convertDateIntoReadable(dateRemoved[0])); + viewHolder.worn_date.setText(Utils.convertDateIntoReadable(datePut[0], false) + " -> " + Utils.convertDateIntoReadable(dateRemoved[0], false)); viewHolder.weared_to.setText(dateRemoved[1]); } else viewHolder.weared_to.setText(dataModel.getDateRemoved()); diff --git a/app/src/main/java/com/lubenard/oring_reminder/custom_components/HistoryViewHolder.java b/app/src/main/java/com/lubenard/oring_reminder/custom_components/HistoryViewHolder.java index 79d79ce..fff0d8a 100644 --- a/app/src/main/java/com/lubenard/oring_reminder/custom_components/HistoryViewHolder.java +++ b/app/src/main/java/com/lubenard/oring_reminder/custom_components/HistoryViewHolder.java @@ -85,9 +85,9 @@ public void updateElementDatas(RingSession dataModel, Context context) { String[] datePut = dataModel.getDatePut().split(" "); if (dataModel.getDatePut().split(" ")[0].equals(dataModel.getDateRemoved().split(" ")[0])) - worn_date.setText(Utils.convertDateIntoReadable(dataModel.getDatePut().split(" ")[0])); + worn_date.setText(Utils.convertDateIntoReadable(dataModel.getDatePut().split(" ")[0], false)); else if (dataModel.getIsRunning() == 0) - worn_date.setText(Utils.convertDateIntoReadable(dataModel.getDatePut().split(" ")[0]) + " -> " + Utils.convertDateIntoReadable(dataModel.getDateRemoved().split(" ")[0])); + worn_date.setText(Utils.convertDateIntoReadable(dataModel.getDatePut().split(" ")[0], false) + " -> " + Utils.convertDateIntoReadable(dataModel.getDateRemoved().split(" ")[0], false)); weared_from.setText(datePut[1]); diff --git a/app/src/main/java/com/lubenard/oring_reminder/ui/EntryDetailsFragment.java b/app/src/main/java/com/lubenard/oring_reminder/ui/EntryDetailsFragment.java index b363552..07f8c7b 100644 --- a/app/src/main/java/com/lubenard/oring_reminder/ui/EntryDetailsFragment.java +++ b/app/src/main/java/com/lubenard/oring_reminder/ui/EntryDetailsFragment.java @@ -330,7 +330,7 @@ private void updateAbleToGetItOffUI(Calendar calendar) { Log.d(TAG, "timeBeforeRemove = " + timeBeforeRemove); String[] ableToGetItOffStringDate = Utils.getdateFormatted(calendar.getTime()).split(" "); - ableToGetItOff.setText(getString(R.string._message_able_to_get_it_off) + Utils.convertDateIntoReadable(ableToGetItOffStringDate[0]) + " " + ableToGetItOffStringDate[1]); + ableToGetItOff.setText(getString(R.string._message_able_to_get_it_off) + Utils.convertDateIntoReadable(ableToGetItOffStringDate[0], false) + " " + ableToGetItOffStringDate[1]); if (timeBeforeRemove >= 0) texteRessourceWhenGetItOff = R.string.in_about_entry_details; else { @@ -371,7 +371,7 @@ private void updatePauseList() { wornForTextView.setText(R.string.removed_during); TextView textView_date = view.findViewById(R.id.main_history_date); - textView_date.setText(Utils.convertDateIntoReadable(dateRemoved[0])); + textView_date.setText(Utils.convertDateIntoReadable(dateRemoved[0], false)); TextView textView_hour_from = view.findViewById(R.id.custom_view_date_weared_from); textView_hour_from.setText(dateRemoved[1]); @@ -384,7 +384,7 @@ private void updatePauseList() { String[] datePut = pausesDatas.get(i).getDatePut().split(" "); textView_hour_to.setText(datePut[1]); if (!dateRemoved[0].equals(datePut[0])) - textView_date.setText(Utils.convertDateIntoReadable(dateRemoved[0]) + " -> " + Utils.convertDateIntoReadable(datePut[0])); + textView_date.setText(Utils.convertDateIntoReadable(dateRemoved[0], false) + " -> " + Utils.convertDateIntoReadable(datePut[0], false)); textView_worn_for.setTextColor(getContext().getResources().getColor(android.R.color.holo_green_dark)); textView_worn_for.setText(convertTimeWeared(pausesDatas.get(i).getTimeWeared())); } else { @@ -443,7 +443,7 @@ private void updateAllFragmentDatas(boolean updateProgressBar) { whenGetItOff = view.findViewById(R.id.details_entry_when_get_it_off); progressBar = view.findViewById(R.id.progress_bar); - put.setText(Utils.convertDateIntoReadable(entryDetails.getDatePut().split(" ")[0]) + " " + entryDetails.getDatePut().split(" ")[1]); + put.setText(Utils.convertDateIntoReadable(entryDetails.getDatePut().split(" ")[0], false) + " " + entryDetails.getDatePut().split(" ")[1]); // Choose color if the timeWeared is enough or not // Depending of the timeWeared set in the settings @@ -479,7 +479,7 @@ private void updateAllFragmentDatas(boolean updateProgressBar) { } else { timeBeforeRemove = Utils.getDateDiff(entryDetails.getDatePut(), entryDetails.getDateRemoved(), TimeUnit.MINUTES) - AfterBootBroadcastReceiver.computeTotalTimePause(dbManager, entryId); Log.d(TAG, "TimeBeforeRemove is " + timeBeforeRemove); - removed.setText(Utils.convertDateIntoReadable(entryDetails.getDateRemoved().split(" ")[0]) + " " + entryDetails.getDateRemoved().split(" ")[1]); + removed.setText(Utils.convertDateIntoReadable(entryDetails.getDateRemoved().split(" ")[0], false) + " " + entryDetails.getDateRemoved().split(" ")[1]); int time_spent_wearing = entryDetails.getTimeWeared(); if (time_spent_wearing < 60) textview_progress.setText(entryDetails.getTimeWeared() + getString(R.string.minute_with_M_uppercase)); diff --git a/app/src/main/java/com/lubenard/oring_reminder/ui/MainFragment.java b/app/src/main/java/com/lubenard/oring_reminder/ui/MainFragment.java index 6212184..113a673 100644 --- a/app/src/main/java/com/lubenard/oring_reminder/ui/MainFragment.java +++ b/app/src/main/java/com/lubenard/oring_reminder/ui/MainFragment.java @@ -92,9 +92,9 @@ private void updateHistoryList() { TextView textView_date = view.findViewById(R.id.main_history_date); if (entrysDatas.get(i).getDatePut().split(" ")[0].equals(entrysDatas.get(i).getDateRemoved().split(" ")[0])) - textView_date.setText(Utils.convertDateIntoReadable(entrysDatas.get(i).getDatePut().split(" ")[0])); + textView_date.setText(Utils.convertDateIntoReadable(entrysDatas.get(i).getDatePut().split(" ")[0], false)); else - textView_date.setText(Utils.convertDateIntoReadable(entrysDatas.get(i).getDatePut().split(" ")[0]) + " -> " + Utils.convertDateIntoReadable(entrysDatas.get(i).getDateRemoved().split(" ")[0])); + textView_date.setText(Utils.convertDateIntoReadable(entrysDatas.get(i).getDatePut().split(" ")[0], false) + " -> " + Utils.convertDateIntoReadable(entrysDatas.get(i).getDateRemoved().split(" ")[0], false)); TextView textView_hour_from = view.findViewById(R.id.custom_view_date_weared_from); textView_hour_from.setText(entrysDatas.get(i).getDatePut().split(" ")[1]); diff --git a/app/src/main/java/com/lubenard/oring_reminder/utils/Utils.java b/app/src/main/java/com/lubenard/oring_reminder/utils/Utils.java index 644452f..0ffb59f 100644 --- a/app/src/main/java/com/lubenard/oring_reminder/utils/Utils.java +++ b/app/src/main/java/com/lubenard/oring_reminder/utils/Utils.java @@ -138,7 +138,7 @@ public static long getDateDiff(Date date1, Date date2, TimeUnit timeUnit) { * @param s * @return */ - public static String convertDateIntoReadable(String s) { + public static String convertDateIntoReadable(String s, boolean shorterVersion) { Date date = null; try { date = new SimpleDateFormat("yyyy-MM-dd").parse(s); @@ -146,7 +146,13 @@ public static String convertDateIntoReadable(String s) { e.printStackTrace(); } - SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd LLLL yyyy", new Locale(current_language)); + SimpleDateFormat simpleDateFormat; + if (shorterVersion) + simpleDateFormat = new SimpleDateFormat("dd MMM yyyy", new Locale(current_language)); + else { + simpleDateFormat = new SimpleDateFormat("dd LLLL yyyy", new Locale(current_language)); + } + return simpleDateFormat.format(date); } diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 0f0e6ef..0f425dd 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -165,4 +165,5 @@ Geschichte: Ungefähr getragene Zeit:\n%d Wochen\n%d Tage\n%d Stunden\n%d Minuten\n Heute: + "Mit " diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 4e753cd..901c8c6 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -168,4 +168,5 @@ Historique : Temps porté approximatif:\n%d semaines\n%d jours\n%d heures\n%d minutes Aujourd\'hui : + "A " diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b4c1db0..970b981 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -165,4 +165,5 @@ History: Time worn approximately:\n%d weeks\n%d days\n%d hours\n%d minutes\n Today: + "At " \ No newline at end of file