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 --- res/drawable-hdpi-v11/stat_notify_download.png | Bin 0 -> 300 bytes res/drawable-hdpi/stat_notify_download.png | Bin 0 -> 350 bytes res/drawable-mdpi-v11/stat_notify_download.png | Bin 0 -> 234 bytes res/drawable-mdpi/stat_notify_download.png | Bin 0 -> 272 bytes res/drawable-xhdpi-v11/stat_notify_download.png | Bin 0 -> 379 bytes res/drawable-xhdpi/stat_notify_download.png | Bin 0 -> 404 bytes res/drawable-xxhdpi-v11/stat_notify_download.png | Bin 0 -> 531 bytes res/drawable-xxhdpi/stat_notify_download.png | Bin 0 -> 558 bytes .../daneren2005/dsub/activity/DownloadActivity.java | 6 ++++++ src/github/daneren2005/dsub/activity/MainActivity.java | 3 +++ .../daneren2005/dsub/fragments/DownloadFragment.java | 7 +++++++ .../daneren2005/dsub/service/DownloadServiceImpl.java | 11 +++++++++++ src/github/daneren2005/dsub/util/Util.java | 2 +- 13 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 res/drawable-hdpi-v11/stat_notify_download.png create mode 100644 res/drawable-hdpi/stat_notify_download.png create mode 100644 res/drawable-mdpi-v11/stat_notify_download.png create mode 100644 res/drawable-mdpi/stat_notify_download.png create mode 100644 res/drawable-xhdpi-v11/stat_notify_download.png create mode 100644 res/drawable-xhdpi/stat_notify_download.png create mode 100644 res/drawable-xxhdpi-v11/stat_notify_download.png create mode 100644 res/drawable-xxhdpi/stat_notify_download.png diff --git a/res/drawable-hdpi-v11/stat_notify_download.png b/res/drawable-hdpi-v11/stat_notify_download.png new file mode 100644 index 00000000..48ca6924 Binary files /dev/null and b/res/drawable-hdpi-v11/stat_notify_download.png differ diff --git a/res/drawable-hdpi/stat_notify_download.png b/res/drawable-hdpi/stat_notify_download.png new file mode 100644 index 00000000..aa1b6c92 Binary files /dev/null and b/res/drawable-hdpi/stat_notify_download.png differ diff --git a/res/drawable-mdpi-v11/stat_notify_download.png b/res/drawable-mdpi-v11/stat_notify_download.png new file mode 100644 index 00000000..4164e0fa Binary files /dev/null and b/res/drawable-mdpi-v11/stat_notify_download.png differ diff --git a/res/drawable-mdpi/stat_notify_download.png b/res/drawable-mdpi/stat_notify_download.png new file mode 100644 index 00000000..4c2a22de Binary files /dev/null and b/res/drawable-mdpi/stat_notify_download.png differ diff --git a/res/drawable-xhdpi-v11/stat_notify_download.png b/res/drawable-xhdpi-v11/stat_notify_download.png new file mode 100644 index 00000000..96ceb383 Binary files /dev/null and b/res/drawable-xhdpi-v11/stat_notify_download.png differ diff --git a/res/drawable-xhdpi/stat_notify_download.png b/res/drawable-xhdpi/stat_notify_download.png new file mode 100644 index 00000000..bd4cb567 Binary files /dev/null and b/res/drawable-xhdpi/stat_notify_download.png differ diff --git a/res/drawable-xxhdpi-v11/stat_notify_download.png b/res/drawable-xxhdpi-v11/stat_notify_download.png new file mode 100644 index 00000000..b2dc5651 Binary files /dev/null and b/res/drawable-xxhdpi-v11/stat_notify_download.png differ diff --git a/res/drawable-xxhdpi/stat_notify_download.png b/res/drawable-xxhdpi/stat_notify_download.png new file mode 100644 index 00000000..9d9a7f3e Binary files /dev/null and b/res/drawable-xxhdpi/stat_notify_download.png differ 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