Merge branch 'notify-download-progress' into 'master'
Show progress bar in download notification. This enhances the download notification to include a progress bar of the downloads progress. (It doesn't show the actual size of the download or the number of bytes downloaded in text yet. Need to think about internationalizing this from the `AppDetails` `updateProgress` method so that it is not copy-pasted in two places.) See merge request !261
This commit is contained in:
commit
58aa19f392
@ -17,6 +17,8 @@
|
|||||||
|
|
||||||
package org.fdroid.fdroid.net;
|
package org.fdroid.fdroid.net;
|
||||||
|
|
||||||
|
import android.app.Notification;
|
||||||
|
import android.app.NotificationManager;
|
||||||
import android.app.Service;
|
import android.app.Service;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@ -135,7 +137,7 @@ public class DownloaderService extends Service {
|
|||||||
}
|
}
|
||||||
} else if (ACTION_QUEUE.equals(intent.getAction())) {
|
} else if (ACTION_QUEUE.equals(intent.getAction())) {
|
||||||
if (Preferences.get().isUpdateNotificationEnabled()) {
|
if (Preferences.get().isUpdateNotificationEnabled()) {
|
||||||
createNotification(intent.getDataString());
|
startForeground(NOTIFY_DOWNLOADING, createNotification(intent.getDataString()).build());
|
||||||
}
|
}
|
||||||
Log.i(TAG, "Queued " + intent);
|
Log.i(TAG, "Queued " + intent);
|
||||||
Message msg = serviceHandler.obtainMessage();
|
Message msg = serviceHandler.obtainMessage();
|
||||||
@ -150,14 +152,13 @@ public class DownloaderService extends Service {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createNotification(String urlString) {
|
private NotificationCompat.Builder createNotification(String urlString) {
|
||||||
NotificationCompat.Builder builder =
|
return new NotificationCompat.Builder(this)
|
||||||
new NotificationCompat.Builder(this)
|
.setAutoCancel(true)
|
||||||
.setAutoCancel(true)
|
.setContentTitle(getString(R.string.downloading))
|
||||||
.setContentTitle(getString(R.string.downloading))
|
.setSmallIcon(android.R.drawable.stat_sys_download)
|
||||||
.setSmallIcon(android.R.drawable.stat_sys_download)
|
.setContentText(urlString)
|
||||||
.setContentText(urlString);
|
.setProgress(100, 0, true);
|
||||||
startForeground(NOTIFY_DOWNLOADING, builder.build());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -214,6 +215,12 @@ public class DownloaderService extends Service {
|
|||||||
intent.putExtra(Downloader.EXTRA_BYTES_READ, bytesRead);
|
intent.putExtra(Downloader.EXTRA_BYTES_READ, bytesRead);
|
||||||
intent.putExtra(Downloader.EXTRA_TOTAL_BYTES, totalBytes);
|
intent.putExtra(Downloader.EXTRA_TOTAL_BYTES, totalBytes);
|
||||||
localBroadcastManager.sendBroadcast(intent);
|
localBroadcastManager.sendBroadcast(intent);
|
||||||
|
|
||||||
|
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
||||||
|
Notification notification = createNotification(uri.toString())
|
||||||
|
.setProgress(totalBytes, bytesRead, false)
|
||||||
|
.build();
|
||||||
|
nm.notify(NOTIFY_DOWNLOADING, notification);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
downloader.download();
|
downloader.download();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user