1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-19 00:19:25 +01:00

Show exercises in a different color

Thanks @Martin.JM
This commit is contained in:
Arjan Schrijver 2024-03-05 14:50:03 +01:00
parent 2bb0d1e816
commit 48bfcad6fd
3 changed files with 38 additions and 5 deletions

View File

@ -41,6 +41,7 @@ public abstract class AbstractDashboardWidget extends Fragment {
protected @ColorInt int color_not_worn = Color.BLACK;
protected @ColorInt int color_worn = Color.rgb(128, 128, 128);
protected @ColorInt int color_activity = Color.GREEN;
protected @ColorInt int color_exercise = Color.rgb(255, 128, 0);
protected @ColorInt int color_deep_sleep = Color.BLUE;
protected @ColorInt int color_light_sleep = Color.rgb(150, 150, 255);
protected @ColorInt int color_distance = Color.BLUE;

View File

@ -52,6 +52,7 @@ import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.activities.DashboardFragment;
import nodomain.freeyourgadget.gadgetbridge.activities.charts.StepAnalysis;
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
import nodomain.freeyourgadget.gadgetbridge.entities.BaseActivitySummary;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
@ -109,12 +110,14 @@ public class DashboardTodayWidget extends AbstractDashboardWidget {
l_worn.setSpan(new ForegroundColorSpan(color_worn), 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
SpannableString l_activity = new SpannableString("" + getString(R.string.activity_type_activity));
l_activity.setSpan(new ForegroundColorSpan(color_activity), 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
SpannableString l_exercise = new SpannableString("" + getString(R.string.activity_type_exercise));
l_exercise.setSpan(new ForegroundColorSpan(color_exercise), 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
SpannableString l_deep_sleep = new SpannableString("" + getString(R.string.activity_type_deep_sleep));
l_deep_sleep.setSpan(new ForegroundColorSpan(color_deep_sleep), 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
SpannableString l_light_sleep = new SpannableString("" + getString(R.string.activity_type_light_sleep));
l_light_sleep.setSpan(new ForegroundColorSpan(color_light_sleep), 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
SpannableStringBuilder legendBuilder = new SpannableStringBuilder();
legend.setText(legendBuilder.append(l_not_worn).append(" ").append(l_worn).append(" ").append(l_activity).append("\n").append(l_light_sleep).append(" ").append(l_deep_sleep));
legend.setText(legendBuilder.append(l_not_worn).append(" ").append(l_worn).append("\n").append(l_activity).append(" ").append(l_exercise).append("\n").append(l_light_sleep).append(" ").append(l_deep_sleep));
legend.setVisibility(prefs.getBoolean("dashboard_widget_today_legend", true) ? View.VISIBLE : View.GONE);
@ -155,25 +158,33 @@ public class DashboardTodayWidget extends AbstractDashboardWidget {
// If the current timestamp is already saved, compare the activity kinds and
// keep the most 'important' one
switch (activityTimestamps.get(i)) {
case ActivityKind.TYPE_EXERCISE:
break;
case ActivityKind.TYPE_ACTIVITY:
if (activityKind == ActivityKind.TYPE_EXERCISE)
activityTimestamps.put(i, activityKind);
break;
case ActivityKind.TYPE_DEEP_SLEEP:
if (activityKind == ActivityKind.TYPE_ACTIVITY)
if (activityKind == ActivityKind.TYPE_EXERCISE ||
activityKind == ActivityKind.TYPE_ACTIVITY)
activityTimestamps.put(i, activityKind);
break;
case ActivityKind.TYPE_LIGHT_SLEEP:
if (activityKind == ActivityKind.TYPE_ACTIVITY ||
if (activityKind == ActivityKind.TYPE_EXERCISE ||
activityKind == ActivityKind.TYPE_ACTIVITY ||
activityKind == ActivityKind.TYPE_DEEP_SLEEP)
activityTimestamps.put(i, activityKind);
break;
case ActivityKind.TYPE_REM_SLEEP:
if (activityKind == ActivityKind.TYPE_ACTIVITY ||
if (activityKind == ActivityKind.TYPE_EXERCISE ||
activityKind == ActivityKind.TYPE_ACTIVITY ||
activityKind == ActivityKind.TYPE_DEEP_SLEEP ||
activityKind == ActivityKind.TYPE_LIGHT_SLEEP)
activityTimestamps.put(i, activityKind);
break;
case ActivityKind.TYPE_SLEEP:
if (activityKind == ActivityKind.TYPE_ACTIVITY ||
if (activityKind == ActivityKind.TYPE_EXERCISE ||
activityKind == ActivityKind.TYPE_ACTIVITY ||
activityKind == ActivityKind.TYPE_DEEP_SLEEP ||
activityKind == ActivityKind.TYPE_LIGHT_SLEEP ||
activityKind == ActivityKind.TYPE_REM_SLEEP)
@ -258,6 +269,7 @@ public class DashboardTodayWidget extends AbstractDashboardWidget {
List<GBDevice> devices = GBApplication.app().getDeviceManager().getDevices();
List<ActivitySample> allActivitySamples = new ArrayList<>();
List<ActivitySession> stepSessions = new ArrayList<>();
List<BaseActivitySummary> activitySummaries = null;
try (DBHandler dbHandler = GBApplication.acquireDB()) {
for (GBDevice dev : devices) {
if ((dashboardData.showAllDevices || dashboardData.showDeviceList.contains(dev.getAddress())) && dev.getDeviceCoordinator().supportsActivityTracking()) {
@ -267,6 +279,7 @@ public class DashboardTodayWidget extends AbstractDashboardWidget {
stepSessions.addAll(stepAnalysis.calculateStepSessions(activitySamples));
}
}
activitySummaries = DashboardUtils.getWorkoutSamples(dbHandler, dashboardData);
} catch (Exception e) {
LOG.warn("Could not retrieve activity amounts: ", e);
}
@ -284,6 +297,11 @@ public class DashboardTodayWidget extends AbstractDashboardWidget {
// Add to day results
addActivity(sample.getTimestamp(), sample.getTimestamp() + 60, sample.getKind());
}
if (activitySummaries != null) {
for (BaseActivitySummary baseActivitySummary : activitySummaries) {
addActivity(baseActivitySummary.getStartTime().getTime() / 1000, baseActivitySummary.getEndTime().getTime() / 1000, ActivityKind.TYPE_EXERCISE);
}
}
for (ActivitySession session : stepSessions) {
addActivity(session.getStartTime().getTime() / 1000, session.getEndTime().getTime() / 1000, ActivityKind.TYPE_ACTIVITY);
}
@ -398,6 +416,10 @@ public class DashboardTodayWidget extends AbstractDashboardWidget {
paint.setStrokeWidth(barWidth);
paint.setColor(color_deep_sleep);
canvas.drawArc(margin, margin, width - margin, height - margin, start_angle, sweep_angle, false, paint);
} else if (activity.activityKind == ActivityKind.TYPE_EXERCISE) {
paint.setStrokeWidth(barWidth);
paint.setColor(color_exercise);
canvas.drawArc(margin, margin, width - margin, height - margin, start_angle, sweep_angle, false, paint);
} else {
paint.setStrokeWidth(barWidth);
paint.setColor(color_activity);

View File

@ -20,6 +20,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
@ -30,6 +31,8 @@ import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator;
import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
import nodomain.freeyourgadget.gadgetbridge.entities.AbstractActivitySample;
import nodomain.freeyourgadget.gadgetbridge.entities.BaseActivitySummary;
import nodomain.freeyourgadget.gadgetbridge.entities.BaseActivitySummaryDao;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySession;
@ -178,4 +181,11 @@ public class DashboardUtils {
DeviceCoordinator coordinator = device.getDeviceCoordinator();
return coordinator.getSampleProvider(device, db.getDaoSession());
}
public static List<BaseActivitySummary> getWorkoutSamples(DBHandler db, DashboardFragment.DashboardData dashboardData) {
return db.getDaoSession().getBaseActivitySummaryDao().queryBuilder().where(
BaseActivitySummaryDao.Properties.StartTime.gt(new Date(dashboardData.timeFrom * 1000L)),
BaseActivitySummaryDao.Properties.EndTime.lt(new Date(dashboardData.timeTo * 1000L))
).build().list();
}
}