From 8b0706880118f6b571664c78e5d9c1f2c69bcdae Mon Sep 17 00:00:00 2001 From: Sukhpal Singh Date: Tue, 13 Aug 2019 22:25:38 +1000 Subject: [PATCH 1/2] #18 Adding total sleep time to the sleep summary --- .../fridgecow/smartalarm/SleepSummaryActivity.java | 9 +++++++++ app/src/main/res/layout/activity_sleep_summary.xml | 14 ++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/app/src/main/java/com/fridgecow/smartalarm/SleepSummaryActivity.java b/app/src/main/java/com/fridgecow/smartalarm/SleepSummaryActivity.java index f55f8ce..80c0364 100644 --- a/app/src/main/java/com/fridgecow/smartalarm/SleepSummaryActivity.java +++ b/app/src/main/java/com/fridgecow/smartalarm/SleepSummaryActivity.java @@ -135,6 +135,15 @@ protected void onCreate(Bundle savedInstanceState) { currentMetric = findViewById(R.id.detectedwaketime); Date wakeDate = new Date((long) mData.get(mData.size() - 1).getStart()); currentMetric.setText(timeFormat.format(wakeDate)); + + currentMetric = findViewById(R.id.totalsleeptime); + int sleepHours = (int) ((totalTime / (1000 * 60 * 60)) % 24); + int mins = (int) ((totalTime / (1000 * 60)) % 60); + currentMetric.setText( + (sleepHours > 9 ? sleepHours : "0" + sleepHours) + + ":" + + (mins > 9 ? mins : "0" + mins) + ); } private void loadIntentExtras(){ diff --git a/app/src/main/res/layout/activity_sleep_summary.xml b/app/src/main/res/layout/activity_sleep_summary.xml index 08f7495..216e631 100644 --- a/app/src/main/res/layout/activity_sleep_summary.xml +++ b/app/src/main/res/layout/activity_sleep_summary.xml @@ -161,6 +161,20 @@ android:text="TextView" android:textAppearance="@style/TextAppearance.AppCompat" /> + + + +