Fixed some notification visual glitches #460

This commit is contained in:
mhutti1 2017-02-13 19:45:58 +00:00
parent f22e6bf212
commit 0abc7a61d8
2 changed files with 13 additions and 6 deletions

View File

@ -157,7 +157,10 @@ public class DownloadFragment extends Fragment {
ProgressBar downloadProgress = (ProgressBar) convertView.findViewById(R.id.downloadProgress); ProgressBar downloadProgress = (ProgressBar) convertView.findViewById(R.id.downloadProgress);
ImageView pause = (ImageView) convertView.findViewById(R.id.pause); 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])); downloadProgress.setProgress(LibraryFragment.mService.downloadProgress.get(mKeys[position]));
if (LibraryFragment.mService.downloadStatus.get(mKeys[position]) == DownloadService.PAUSE) { if (LibraryFragment.mService.downloadStatus.get(mKeys[position]) == DownloadService.PAUSE) {
pause.setImageDrawable(ContextCompat.getDrawable(getActivity(), R.drawable.ic_play_arrow_black_24dp)); pause.setImageDrawable(ContextCompat.getDrawable(getActivity(), R.drawable.ic_play_arrow_black_24dp));
@ -170,10 +173,10 @@ public class DownloadFragment extends Fragment {
pause.setOnClickListener(v -> { pause.setOnClickListener(v -> {
if (LibraryFragment.mService.downloadStatus.get(mKeys[position]) == DownloadService.PLAY) { if (LibraryFragment.mService.downloadStatus.get(mKeys[position]) == DownloadService.PLAY) {
LibraryFragment.mService.pauseDownload(mKeys[position]); 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 { } else {
LibraryFragment.mService.playDownload(mKeys[position]); 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));
} }
}); });

View File

@ -143,6 +143,7 @@ public class DownloadService extends Service {
.addAction(stop) .addAction(stop)
.setOngoing(true)); .setOngoing(true));
notificationManager.notify(notificationCount, notification.get(notificationCount).build());
downloadStatus.put(notificationCount, PLAY); downloadStatus.put(notificationCount, PLAY);
LibraryFragment.downloadingBooks.remove(book); LibraryFragment.downloadingBooks.remove(book);
String url = intent.getExtras().getString(DownloadIntent.DOWNLOAD_URL_PARAMETER); 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).setContentIntent(pendingIntent);
notification.get(notificationID).mActions.clear(); notification.get(notificationID).mActions.clear();
updateForeground(); 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); notification.get(notificationID).setProgress(100, progress, false);
notificationManager.notify(notificationID, notification.get(notificationID).build()); 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) { if (DownloadFragment.mDownloads != null && DownloadFragment.mDownloads.get(notificationID) != null) {
handler.post(new Runnable() { handler.post(new Runnable() {
@Override @Override
@ -314,6 +316,8 @@ public class DownloadService extends Service {
book.remoteUrl = book.getUrl(); book.remoteUrl = book.getUrl();
book.file = fullFile; book.file = fullFile;
bookDao.saveBook(book); bookDao.saveBook(book);
downloadStatus.put(chunk.getNotificationID(), PLAY);
downloadProgress.put(chunk.getNotificationID(), 0);
} }
byte[] buffer = new byte[2048]; byte[] buffer = new byte[2048];