From a3d2ba2009f61869762c655b3ab6f46b414b0b35 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Fri, 13 Sep 2013 10:41:17 -0700 Subject: Closes #150 Add notification while background downloading --- src/github/daneren2005/dsub/activity/DownloadActivity.java | 6 ++++++ src/github/daneren2005/dsub/activity/MainActivity.java | 3 +++ src/github/daneren2005/dsub/fragments/DownloadFragment.java | 7 +++++++ src/github/daneren2005/dsub/service/DownloadServiceImpl.java | 11 +++++++++++ src/github/daneren2005/dsub/util/Util.java | 2 +- 5 files changed, 28 insertions(+), 1 deletion(-) (limited to 'src/github') diff --git a/src/github/daneren2005/dsub/activity/DownloadActivity.java b/src/github/daneren2005/dsub/activity/DownloadActivity.java index 447bbb34..d8ebb98a 100644 --- a/src/github/daneren2005/dsub/activity/DownloadActivity.java +++ b/src/github/daneren2005/dsub/activity/DownloadActivity.java @@ -38,6 +38,7 @@ import github.daneren2005.dsub.domain.MusicDirectory; import github.daneren2005.dsub.service.DownloadFile; import github.daneren2005.dsub.service.MusicService; import github.daneren2005.dsub.service.MusicServiceFactory; +import github.daneren2005.dsub.util.Constants; import github.daneren2005.dsub.util.SilentBackgroundTask; import github.daneren2005.dsub.util.Util; import java.util.LinkedList; @@ -57,6 +58,11 @@ public class DownloadActivity extends SubsonicActivity { if (findViewById(R.id.download_container) != null && savedInstanceState == null) { currentFragment = new DownloadFragment(); + if(getIntent().hasExtra(Constants.INTENT_EXTRA_NAME_DOWNLOAD_VIEW)) { + Bundle args = new Bundle(); + args.putBoolean(Constants.INTENT_EXTRA_NAME_DOWNLOAD_VIEW, true); + currentFragment.setArguments(args); + } currentFragment.setPrimaryFragment(true); getSupportFragmentManager().beginTransaction().add(R.id.download_container, currentFragment, currentFragment.getSupportTag() + "").commit(); } diff --git a/src/github/daneren2005/dsub/activity/MainActivity.java b/src/github/daneren2005/dsub/activity/MainActivity.java index 8aa68b3d..9dbc2b5e 100644 --- a/src/github/daneren2005/dsub/activity/MainActivity.java +++ b/src/github/daneren2005/dsub/activity/MainActivity.java @@ -57,6 +57,9 @@ public class MainActivity extends SubsonicActivity { getIntent().removeExtra(Constants.INTENT_EXTRA_NAME_DOWNLOAD); Intent intent = new Intent(); intent.setClass(this, DownloadActivity.class); + if(getIntent().hasExtra(Constants.INTENT_EXTRA_NAME_DOWNLOAD_VIEW)) { + intent.putExtra(Constants.INTENT_EXTRA_NAME_DOWNLOAD_VIEW, true); + } startActivity(intent); } setContentView(R.layout.main); diff --git a/src/github/daneren2005/dsub/fragments/DownloadFragment.java b/src/github/daneren2005/dsub/fragments/DownloadFragment.java index 72186ff1..bf47e95e 100644 --- a/src/github/daneren2005/dsub/fragments/DownloadFragment.java +++ b/src/github/daneren2005/dsub/fragments/DownloadFragment.java @@ -120,6 +120,13 @@ public class DownloadFragment extends SubsonicFragment implements OnGestureListe startFlipped = true; } } + Bundle args = getArguments(); + if(args != null) { + if(args.getBoolean(Constants.INTENT_EXTRA_NAME_DOWNLOAD_VIEW)) { + startFlipped = true; + nowPlaying = false; + } + } } @Override diff --git a/src/github/daneren2005/dsub/service/DownloadServiceImpl.java b/src/github/daneren2005/dsub/service/DownloadServiceImpl.java index 26ca7f11..2df1f30a 100644 --- a/src/github/daneren2005/dsub/service/DownloadServiceImpl.java +++ b/src/github/daneren2005/dsub/service/DownloadServiceImpl.java @@ -115,6 +115,8 @@ public class DownloadServiceImpl extends Service implements DownloadService { private PowerManager.WakeLock wakeLock; private boolean keepScreenOn; private int cachedPosition = 0; + private long downloadRevision; + private boolean downloadOngoing = false; private static boolean equalizerAvailable; private static boolean visualizerAvailable; @@ -1423,6 +1425,15 @@ public class DownloadServiceImpl extends Service implements DownloadService { } } + if(!backgroundDownloadList.isEmpty() && downloadRevision != revision) { + Util.showDownloadingNotification(this, this, currentDownloading, backgroundDownloadList.size(), handler); + downloadRevision = revision; + downloadOngoing = true; + } else if(backgroundDownloadList.isEmpty() && downloadOngoing) { + Util.hideDownloadingNotification(this, this, handler); + downloadOngoing = false; + } + // Delete obsolete .partial and .complete files. cleanup(); } diff --git a/src/github/daneren2005/dsub/util/Util.java b/src/github/daneren2005/dsub/util/Util.java index ce3621fb..f5638110 100644 --- a/src/github/daneren2005/dsub/util/Util.java +++ b/src/github/daneren2005/dsub/util/Util.java @@ -936,7 +936,7 @@ public final class Util { public static void showDownloadingNotification(final Context context, final DownloadServiceImpl downloadService, DownloadFile file, int size, Handler handler) { NotificationCompat.Builder builder; builder = new NotificationCompat.Builder(context) - .setSmallIcon(R.drawable.downloading) + .setSmallIcon(R.drawable.stat_notify_download) .setContentTitle("Downloading " + size + " songs") .setContentText("Current: " + file.getSong().getTitle()) .setProgress(10, 5, true); -- cgit v1.2.3