From c04ae69ec580c7d86eed872626cc98bdd2769c81 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Wed, 22 Jul 2015 20:26:21 -0700 Subject: #506 Show sleep time remaining --- .../daneren2005/dsub/fragments/NowPlayingFragment.java | 16 ++++++++++++---- .../github/daneren2005/dsub/service/DownloadService.java | 6 ++++++ 2 files changed, 18 insertions(+), 4 deletions(-) (limited to 'app/src/main/java') diff --git a/app/src/main/java/github/daneren2005/dsub/fragments/NowPlayingFragment.java b/app/src/main/java/github/daneren2005/dsub/fragments/NowPlayingFragment.java index bec43a22..c754f370 100644 --- a/app/src/main/java/github/daneren2005/dsub/fragments/NowPlayingFragment.java +++ b/app/src/main/java/github/daneren2005/dsub/fragments/NowPlayingFragment.java @@ -131,6 +131,7 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis private boolean scrollWhenLoaded = false; private int lastY = 0; private int currentPlayingSize = 0; + private MenuItem timerMenu; /** * Called when the activity is first created. @@ -525,10 +526,11 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis menuInflater.inflate(R.menu.nowplaying_offline, menu); } else { menuInflater.inflate(R.menu.nowplaying, menu); - - if(downloadService != null && downloadService.getSleepTimer()) { - menu.findItem(R.id.menu_toggle_timer).setTitle(R.string.download_stop_timer); - } + } + if(downloadService != null && downloadService.getSleepTimer()) { + int timeRemaining = downloadService.getSleepTimeRemaining(); + timerMenu = menu.findItem(R.id.menu_toggle_timer); + timerMenu.setTitle(context.getResources().getString(R.string.download_stop_time_remaining, Util.formatDuration(timeRemaining))); } if(downloadService != null && downloadService.getKeepScreenOn()) { menu.findItem(R.id.menu_screen_on_off).setChecked(true); @@ -1380,6 +1382,12 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis progressBar.setProgress(0); progressBar.setEnabled(false); } + + DownloadService downloadService = getDownloadService(); + if(downloadService.getSleepTimer() && timerMenu != null) { + int timeRemaining = downloadService.getSleepTimeRemaining(); + timerMenu.setTitle(context.getResources().getString(R.string.download_stop_time_remaining, Util.formatDuration(timeRemaining))); + } } @Override diff --git a/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java b/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java index ab757c59..a9f82919 100644 --- a/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java +++ b/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java @@ -157,6 +157,7 @@ public class DownloadService extends Service { private Timer sleepTimer; private int timerDuration; + private long timerStart; private boolean autoPlayStart = false; private MediaRouteManager mediaRouter; @@ -1808,6 +1809,11 @@ public class DownloadService extends Service { } }, timerDuration * 60 * 1000); + timerStart = System.currentTimeMillis(); + } + + public int getSleepTimeRemaining() { + return (int) (timerStart + (timerDuration * 60 * 1000) - System.currentTimeMillis()) / 1000; } public void stopSleepTimer() { -- cgit v1.2.3