diff options
author | Scott Jackson <daneren2005@gmail.com> | 2014-09-25 14:23:55 -0700 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2014-09-25 14:23:55 -0700 |
commit | 8d52a48c1fb5f9c4dbe427a0a21c2e1ef62a42db (patch) | |
tree | 184076192b4e6da2404e9676d90d4e3a79e66849 /src | |
parent | 836d8cf5d5f891250afcfe39af11623fe0b20445 (diff) | |
download | dsub-8d52a48c1fb5f9c4dbe427a0a21c2e1ef62a42db.tar.gz dsub-8d52a48c1fb5f9c4dbe427a0a21c2e1ef62a42db.tar.bz2 dsub-8d52a48c1fb5f9c4dbe427a0a21c2e1ef62a42db.zip |
Update widget to display current playing when service is not started
Diffstat (limited to 'src')
-rw-r--r-- | src/github/daneren2005/dsub/provider/DSubWidgetProvider.java | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/src/github/daneren2005/dsub/provider/DSubWidgetProvider.java b/src/github/daneren2005/dsub/provider/DSubWidgetProvider.java index d66bc0ec..34e1c41b 100644 --- a/src/github/daneren2005/dsub/provider/DSubWidgetProvider.java +++ b/src/github/daneren2005/dsub/provider/DSubWidgetProvider.java @@ -88,6 +88,11 @@ public class DSubWidgetProvider extends AppWidgetProvider { public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { defaultAppWidget(context, appWidgetIds); } + + @Override + public void onEnabled(Context context) { + notifyInstances(context, DownloadService.getInstance(), false); + } protected int getLayout() { return 0; @@ -155,7 +160,23 @@ public class DSubWidgetProvider extends AppWidgetProvider { } } - MusicDirectory.Entry currentPlaying = service.getCurrentPlaying() == null ? null : service.getCurrentPlaying().getSong(); + // Get Entry from current playing DownloadFile + DownloadFile currentFile; + MusicDirectory.Entry currentPlaying = null; + if(service == null) { + // Deserialize from playling list to setup + DownloadServiceLifecycleSupport.State state = FileUtil.deserialize(context, DownloadLifecycleSupport.FILENAME_DOWNLOADS_SER, DownloadServiceLifecycleSupport.State.class); + if(state != null && state.currentPlayingIndex != -1) { + currentFile = state.songs.get(state.currentPlayingIndex); + } + } else { + currentFile = service.getCurrentPlaying(); + } + + if(currentFile != null) { + currentPlaying = currentFile.getSong(); + } + String title = currentPlaying == null ? null : currentPlaying.getTitle(); CharSequence artist = currentPlaying == null ? null : currentPlaying.getArtist(); CharSequence album = currentPlaying == null ? null : currentPlaying.getAlbum(); |