1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-25 10:05:49 +01:00

Make nicer format for Date/Time in ActivitySummaryList

This commit is contained in:
vanous 2020-08-24 16:54:05 +02:00
parent 34eee787d7
commit df6f59213b
3 changed files with 30 additions and 6 deletions

View File

@ -17,14 +17,17 @@
package nodomain.freeyourgadget.gadgetbridge.adapter;
import android.content.Context;
import android.text.format.DateUtils;
import android.widget.Toast;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.concurrent.TimeUnit;
import de.greenrobot.dao.query.QueryBuilder;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
import nodomain.freeyourgadget.gadgetbridge.entities.BaseActivitySummary;
@ -116,16 +119,32 @@ public class ActivitySummariesAdapter extends AbstractItemAdapter<BaseActivitySu
@Override
protected String getDetails(BaseActivitySummary item) {
Date startTime = item.getStartTime();
Long duration = (item.getEndTime().getTime() - item.getStartTime().getTime());
if (startTime != null) {
return DateTimeUtils.formatDateTime(startTime) + " (" + DateTimeUtils.formatDurationHoursMinutes(duration, TimeUnit.MILLISECONDS) + ")";
}
String activityDay;
String activityTime;
String activityDayTime;
Long duration = item.getEndTime().getTime() - item.getStartTime().getTime();
return "Unknown activity";
if (DateUtils.isToday(startTime.getTime())) {
activityDay = getContext().getString(R.string.activity_summary_today);
} else if (DateTimeUtils.isYesterday(startTime)) {
activityDay = getContext().getString(R.string.activity_summary_yesterday);
} else {
activityDay = DateTimeUtils.formatDate(startTime);
}
Calendar calendar = Calendar.getInstance();
calendar.setTime(startTime);
int hours = calendar.get(Calendar.HOUR_OF_DAY);
int minutes = calendar.get(Calendar.MINUTE);
activityTime = DateTimeUtils.formatTime(hours, minutes);
activityDayTime = String.format("%s, %s", activityDay, activityTime);
return activityDayTime + " (" + DateTimeUtils.formatDurationHoursMinutes(duration, TimeUnit.MILLISECONDS) + ")";
}
return "Unknown time";
}
@Override

View File

@ -153,4 +153,7 @@ public class DateTimeUtils {
public static String minutesToHHMM(int minutes) {
return String.format(Locale.US, "%d:%02d", minutes / 60, minutes % 60); // no I do not want to use durationformatter :P
}
public static boolean isYesterday(Date d) {
return DateUtils.isToday(d.getTime() + DateUtils.DAY_IN_MILLIS);
}
}

View File

@ -707,6 +707,8 @@
<string name="activity_summaries">Sport Activities</string>
<string name="activity_summary_detail">Sport Activity Detail</string>
<string name="activity_summary_edit_name_title">Edit name</string>
<string name="activity_summary_today">Today</string>
<string name="activity_summary_yesterday">Yesterday</string>
<string name="activity_type_biking">Biking</string>
<string name="activity_type_treadmill">Treadmill</string>
<string name="activity_type_exercise">Exercise</string>