2020-10-08 23:37:23 +02:00
|
|
|
package nodomain.freeyourgadget.gadgetbridge.activities.charts;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
2020-10-12 23:10:59 +02:00
|
|
|
import java.text.DecimalFormat;
|
2020-10-08 23:37:23 +02:00
|
|
|
import java.util.Date;
|
2020-10-11 09:24:57 +02:00
|
|
|
import java.util.concurrent.TimeUnit;
|
2020-10-08 23:37:23 +02:00
|
|
|
|
2020-10-12 23:10:59 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.adapter.AbstractActivityListingAdapter;
|
2020-10-08 23:37:23 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.util.DateTimeUtils;
|
|
|
|
|
2020-10-12 23:10:59 +02:00
|
|
|
public class ActivityListingAdapter extends AbstractActivityListingAdapter<StepAnalysis.StepSession> {
|
2020-10-08 23:37:23 +02:00
|
|
|
public ActivityListingAdapter(Context context) {
|
|
|
|
super(context);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-10-12 23:10:59 +02:00
|
|
|
protected String getTimeFrom(StepAnalysis.StepSession item) {
|
|
|
|
Date time = item.getStepStart();
|
|
|
|
return DateTimeUtils.formatTime(time.getHours(), time.getMinutes());
|
|
|
|
}
|
2020-10-11 09:24:57 +02:00
|
|
|
|
2020-10-12 23:10:59 +02:00
|
|
|
@Override
|
|
|
|
protected String getTimeTo(StepAnalysis.StepSession item) {
|
|
|
|
Date time = item.getStepEnd();
|
|
|
|
return DateTimeUtils.formatTime(time.getHours(), time.getMinutes());
|
|
|
|
}
|
2020-10-11 09:24:57 +02:00
|
|
|
|
2020-10-12 23:10:59 +02:00
|
|
|
@Override
|
|
|
|
protected String getActivityName(StepAnalysis.StepSession item) {
|
|
|
|
return ActivityKind.asString(item.getActivityKind(), getContext());
|
2020-10-08 23:37:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-10-12 23:10:59 +02:00
|
|
|
protected String getStepLabel(StepAnalysis.StepSession item) {
|
|
|
|
return String.valueOf(item.getSteps());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected String getDistanceLabel(StepAnalysis.StepSession item) {
|
2020-10-14 22:28:42 +02:00
|
|
|
float distance = item.getDistance();
|
|
|
|
String unit = "###m";
|
|
|
|
if (distance > 2000) {
|
|
|
|
distance = distance / 1000;
|
|
|
|
unit = "###.#km";
|
|
|
|
}
|
|
|
|
DecimalFormat df = new DecimalFormat(unit);
|
2020-10-12 23:10:59 +02:00
|
|
|
//DecimalFormatSymbols symbols = df.getDecimalFormatSymbols();
|
|
|
|
//symbols.setGroupingSeparator(' ');
|
2020-10-14 22:28:42 +02:00
|
|
|
return df.format(distance);
|
2020-10-12 23:10:59 +02:00
|
|
|
}
|
2020-10-11 09:24:57 +02:00
|
|
|
|
2020-10-12 23:10:59 +02:00
|
|
|
@Override
|
|
|
|
protected String getHrLabel(StepAnalysis.StepSession item) {
|
|
|
|
return String.valueOf(item.getHeartRateAverage());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected String getIntensityLabel(StepAnalysis.StepSession item) {
|
|
|
|
DecimalFormat df = new DecimalFormat("###.#");
|
|
|
|
return df.format(item.getIntensity());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected String getDurationLabel(StepAnalysis.StepSession item) {
|
|
|
|
long duration = item.getStepEnd().getTime() - item.getStepStart().getTime();
|
|
|
|
return DateTimeUtils.formatDurationHoursMinutes(duration, TimeUnit.MILLISECONDS);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-10-14 20:02:01 +02:00
|
|
|
public boolean hasHR(StepAnalysis.StepSession item) {
|
2020-10-12 23:10:59 +02:00
|
|
|
if (item.getHeartRateAverage() > 0) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2020-10-08 23:37:23 +02:00
|
|
|
}
|
|
|
|
|
2020-10-14 20:02:01 +02:00
|
|
|
@Override
|
|
|
|
public boolean hasIntensity(StepAnalysis.StepSession item) {
|
|
|
|
if (item.getIntensity() > 0) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-14 22:28:42 +02:00
|
|
|
@Override
|
|
|
|
protected boolean hasDistance(StepAnalysis.StepSession item) {
|
|
|
|
if (item.getDistance() > 0) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-08 23:37:23 +02:00
|
|
|
@Override
|
|
|
|
protected int getIcon(StepAnalysis.StepSession item) {
|
|
|
|
int activityKind = item.getActivityKind();
|
|
|
|
return ActivityKind.getIconId(activityKind);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|