From 0abc7a61d8ccd4fed9184e2af5e0c186a3cce4e0 Mon Sep 17 00:00:00 2001 From: mhutti1 Date: Mon, 13 Feb 2017 19:45:58 +0000 Subject: [PATCH] Fixed some notification visual glitches #460 --- .../kiwix/kiwixmobile/downloader/DownloadFragment.java | 9 ++++++--- .../kiwix/kiwixmobile/downloader/DownloadService.java | 10 +++++++--- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/org/kiwix/kiwixmobile/downloader/DownloadFragment.java b/src/org/kiwix/kiwixmobile/downloader/DownloadFragment.java index 4e59c62b8..d3f6adcdc 100644 --- a/src/org/kiwix/kiwixmobile/downloader/DownloadFragment.java +++ b/src/org/kiwix/kiwixmobile/downloader/DownloadFragment.java @@ -157,7 +157,10 @@ public class DownloadFragment extends Fragment { ProgressBar downloadProgress = (ProgressBar) convertView.findViewById(R.id.downloadProgress); ImageView pause = (ImageView) convertView.findViewById(R.id.pause); - if (LibraryFragment.mService.downloadProgress.get(mKeys[position]) != 0) { + if (LibraryFragment.mService.downloadStatus.get(mKeys[position]) == 0) { + downloadProgress.setProgress(0); + pause.setImageDrawable(ContextCompat.getDrawable(getActivity(), R.drawable.ic_pause_black_24dp)); + } else { downloadProgress.setProgress(LibraryFragment.mService.downloadProgress.get(mKeys[position])); if (LibraryFragment.mService.downloadStatus.get(mKeys[position]) == DownloadService.PAUSE) { pause.setImageDrawable(ContextCompat.getDrawable(getActivity(), R.drawable.ic_play_arrow_black_24dp)); @@ -170,10 +173,10 @@ public class DownloadFragment extends Fragment { pause.setOnClickListener(v -> { if (LibraryFragment.mService.downloadStatus.get(mKeys[position]) == DownloadService.PLAY) { LibraryFragment.mService.pauseDownload(mKeys[position]); - pause.setImageDrawable(getResources().getDrawable(R.drawable.ic_play_arrow_black_24dp)); + pause.setImageDrawable(ContextCompat.getDrawable(getActivity(), R.drawable.ic_play_arrow_black_24dp)); } else { LibraryFragment.mService.playDownload(mKeys[position]); - pause.setImageDrawable(getResources().getDrawable(R.drawable.ic_pause_black_24dp)); + pause.setImageDrawable(ContextCompat.getDrawable(getActivity(), R.drawable.ic_pause_black_24dp)); } }); diff --git a/src/org/kiwix/kiwixmobile/downloader/DownloadService.java b/src/org/kiwix/kiwixmobile/downloader/DownloadService.java index 3cb7b0b00..e8fc9d581 100644 --- a/src/org/kiwix/kiwixmobile/downloader/DownloadService.java +++ b/src/org/kiwix/kiwixmobile/downloader/DownloadService.java @@ -143,6 +143,7 @@ public class DownloadService extends Service { .addAction(stop) .setOngoing(true)); + notificationManager.notify(notificationCount, notification.get(notificationCount).build()); downloadStatus.put(notificationCount, PLAY); LibraryFragment.downloadingBooks.remove(book); String url = intent.getExtras().getString(DownloadIntent.DOWNLOAD_URL_PARAMETER); @@ -234,12 +235,13 @@ public class DownloadService extends Service { notification.get(notificationID).setContentIntent(pendingIntent); notification.get(notificationID).mActions.clear(); updateForeground(); - } else if (progress == 0) { - // Tells android to not kill the service - startForeground(notificationCount, notification.get(notificationCount).build()); } notification.get(notificationID).setProgress(100, progress, false); notificationManager.notify(notificationID, notification.get(notificationID).build()); + if (progress == 0) { + // Tells android to not kill the service + updateForeground(); + } if (DownloadFragment.mDownloads != null && DownloadFragment.mDownloads.get(notificationID) != null) { handler.post(new Runnable() { @Override @@ -314,6 +316,8 @@ public class DownloadService extends Service { book.remoteUrl = book.getUrl(); book.file = fullFile; bookDao.saveBook(book); + downloadStatus.put(chunk.getNotificationID(), PLAY); + downloadProgress.put(chunk.getNotificationID(), 0); } byte[] buffer = new byte[2048];