Skip to content

Commit

Permalink
Added datas and improved visibility on widget
Browse files Browse the repository at this point in the history
  • Loading branch information
lubenard committed Jan 17, 2022
1 parent df75f9a commit c6f0572
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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]);
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
10 changes: 8 additions & 2 deletions app/src/main/java/com/lubenard/oring_reminder/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,21 @@ 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);
} catch (ParseException e) {
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);
}

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,5 @@
<string name="history_colon">Geschichte:</string>
<string name="time_worn_appr">Ungefähr getragene Zeit:\n%d Wochen\n%d Tage\n%d Stunden\n%d Minuten\n</string>
<string name="today">Heute:</string>
<string name="at">"Mit "</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,5 @@
<string name="history_colon">Historique :</string>
<string name="time_worn_appr">Temps porté approximatif:\n%d semaines\n%d jours\n%d heures\n%d minutes</string>
<string name="today">Aujourd\'hui :</string>
<string name="at">"A "</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,5 @@
<string name="history_colon">History:</string>
<string name="time_worn_appr">Time worn approximately:\n%d weeks\n%d days\n%d hours\n%d minutes\n</string>
<string name="today">Today:</string>
<string name="at">"At "</string>
</resources>

0 comments on commit c6f0572

Please sign in to comment.