diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/ActivityListingAdapter.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/ActivityListingAdapter.java index 2e7e67628..6a6f524a3 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/ActivityListingAdapter.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/ActivityListingAdapter.java @@ -287,6 +287,22 @@ public class ActivityListingAdapter extends AbstractActivityListingAdapter activitySamples; activitySamples = getSamples(db, device); List stepSessions = null; + ActivitySession ongoingSession = null; StepAnalysis stepAnalysis = new StepAnalysis(); boolean isEmptySummary = false; @@ -105,8 +104,9 @@ public class ActivityListingChartFragment extends AbstractChartFragment { isEmptySummary = true; } stepSessions = stepAnalysis.calculateSummary(stepSessions, isEmptySummary); + ongoingSession = stepAnalysis.getOngoingSessions(stepSessions); } - return new MyChartsData(stepSessions); + return new MyChartsData(stepSessions, ongoingSession); } @Override @@ -119,12 +119,17 @@ public class ActivityListingChartFragment extends AbstractChartFragment { } stepsDateView.setText(DateTimeUtils.formatDate(new Date(tsDateFrom * 1000L))); + if (GBApplication.getPrefs().getBoolean("charts_show_ongoing_activity", true)) { + if (mcd.getOngoingSession() != null) { + showOngoingActivitySnackbar(mcd.getOngoingSession()); + } + } stepListAdapter.setItems(mcd.getStepSessions(), true); } @Override protected void renderCharts() { - } + } @Override protected void setupLegend(Chart chart) { @@ -143,16 +148,52 @@ public class ActivityListingChartFragment extends AbstractChartFragment { return getAllSamples(db, device, tsFrom, tsTo); } + private void showOngoingActivitySnackbar(ActivitySession ongoingSession) { + + String distanceLabel = stepListAdapter.getDistanceLabel(ongoingSession); + String stepLabel = stepListAdapter.getStepLabel(ongoingSession); + String durationLabel = stepListAdapter.getDurationLabel(ongoingSession); + String hrLabel = stepListAdapter.getHrLabel(ongoingSession); + String activityName = stepListAdapter.getActivityName(ongoingSession); + int icon = stepListAdapter.getIcon(ongoingSession); + + + String text = String.format("%s:\u00A0%s, %s:\u00A0%s, %s:\u00A0%s, %s:\u00A0%s", activityName, durationLabel, getString(R.string.heart_rate), hrLabel, getString(R.string.steps), stepLabel, getString(R.string.distance), distanceLabel); + + final Snackbar snackbar = Snackbar.make(rootView, text, 1000 * 8); + + View snackbarView = snackbar.getView(); + snackbarView.setBackgroundColor(getContext().getResources().getColor(R.color.accent)); + snackbar.setActionTextColor(Color.WHITE); + snackbar.setAction(getString(R.string.dialog_hide).toUpperCase(), new View.OnClickListener() { + @Override + public void onClick(View view) { + snackbar.dismiss(); + + } + } + ); + snackbar.show(); + } + private static class MyChartsData extends ChartsData { private final List stepSessions; + private final ActivitySession ongoingSession; - MyChartsData(List stepSessions) { + MyChartsData(List stepSessions, ActivitySession ongoingSession) { this.stepSessions = stepSessions; + this.ongoingSession = ongoingSession; + } public List getStepSessions() { return stepSessions; } + + public ActivitySession getOngoingSession() { + return this.ongoingSession; + } + } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/StepAnalysis.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/StepAnalysis.java index f0b0897c3..f5986ad92 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/StepAnalysis.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/StepAnalysis.java @@ -124,7 +124,9 @@ public class StepAnalysis { float distance = (float) (activeSteps * STEP_LENGTH_M); sessionEnd = new Date((sample.getTimestamp() - durationSinceLastActiveStep) * 1000L); activityKind = detect_activity_kind(session_length, activeSteps, heartRateAverage, activeIntensity); - result.add(new ActivitySession(sessionStart, sessionEnd, activeSteps, heartRateAverage, activeIntensity, distance, activityKind)); + ActivitySession activitySession = new ActivitySession(sessionStart, sessionEnd, activeSteps, heartRateAverage, activeIntensity, distance, activityKind); + //activitySession.setSessionType(ActivitySession.SESSION_ONGOING); + result.add(activitySession); } sessionStart = null; } @@ -144,7 +146,9 @@ public class StepAnalysis { float distance = (float) (activeSteps * STEP_LENGTH_M); sessionEnd = getDateFromSample(previousSample); activityKind = detect_activity_kind(session_length, activeSteps, heartRateAverage, activeIntensity); - result.add(new ActivitySession(sessionStart, sessionEnd, activeSteps, heartRateAverage, activeIntensity, distance, activityKind)); + ActivitySession ongoingActivity = new ActivitySession(sessionStart, sessionEnd, activeSteps, heartRateAverage, activeIntensity, distance, activityKind); + ongoingActivity.setSessionType(ActivitySession.SESSION_ONGOING); + result.add(ongoingActivity); } } return result; @@ -195,6 +199,16 @@ public class StepAnalysis { return newList; } + public ActivitySession getOngoingSessions(List sessions) { + + for (ActivitySession session : sessions) { + if (session.getSessionType() == ActivitySession.SESSION_ONGOING) { + return session; + } + } + return null; + } + private int calculateSumOfInts(List samples) { int result = 0; for (Integer sample : samples) { diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/adapter/AbstractActivityListingAdapter.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/adapter/AbstractActivityListingAdapter.java index a50e42483..018d5f1bb 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/adapter/AbstractActivityListingAdapter.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/adapter/AbstractActivityListingAdapter.java @@ -199,6 +199,8 @@ public abstract class AbstractActivityListingAdapter extends ArrayAdapter protected abstract String getDurationLabel(T item); + protected abstract String getSpeedLabel(T item); + protected abstract String getSessionCountLabel(T item); protected abstract boolean hasHR(T item); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/adapter/ActivitySummariesAdapter.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/adapter/ActivitySummariesAdapter.java index d25a6fbdf..85b972265 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/adapter/ActivitySummariesAdapter.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/adapter/ActivitySummariesAdapter.java @@ -357,6 +357,11 @@ public class ActivitySummariesAdapter extends AbstractActivityListingAdapterActive time Movement\nIntensity Activities + Hide + Show ongoing activity popup Lack of sleep: %1$s Overslept: %1$s diff --git a/app/src/main/res/xml/charts_preferences.xml b/app/src/main/res/xml/charts_preferences.xml index 6a5fc82df..183fecd67 100644 --- a/app/src/main/res/xml/charts_preferences.xml +++ b/app/src/main/res/xml/charts_preferences.xml @@ -53,6 +53,13 @@ android:summaryOff="@string/pref_charts_range_off" android:summaryOn="@string/pref_charts_range_on" android:title="@string/pref_title_charts_range" /> + + +