Multiple upload notifications work!

And they are no longer ongoing! Fixes #5 and #6
This commit is contained in:
YuviPanda 2012-10-15 21:44:50 +05:30
parent eacb733dd5
commit e3a2384956

View file

@ -37,17 +37,19 @@ public class UploadService extends IntentService {
private class NotificationUpdateProgressListener implements ProgressListener { private class NotificationUpdateProgressListener implements ProgressListener {
Notification curNotification; Notification curNotification;
String notificationTag;
private int lastPercent = 0; private int lastPercent = 0;
public NotificationUpdateProgressListener(Notification curNotification) { public NotificationUpdateProgressListener(Notification curNotification, String notificationTag) {
Log.d("Commons", "Fuckity"); Log.d("Commons", "Fuckity");
this.curNotification = curNotification; this.curNotification = curNotification;
this.notificationTag = notificationTag;
} }
@Override @Override
public void onProgress(long transferred, long total) { public void onProgress(long transferred, long total) {
int percent =(int) ((double)transferred / (double)total * 100); int percent =(int) ((double)transferred / (double)total * 100);
if(percent > lastPercent) { if(percent > lastPercent) {
curNotification.contentView.setProgressBar(R.id.uploadNotificationProgress, 100, percent, false); curNotification.contentView.setProgressBar(R.id.uploadNotificationProgress, 100, percent, false);
notificationManager.notify(NOTIFICATION_DOWNLOAD_IN_PROGRESS, curNotification); notificationManager.notify(notificationTag, NOTIFICATION_DOWNLOAD_IN_PROGRESS, curNotification);
lastPercent = percent; lastPercent = percent;
} }
} }
@ -79,6 +81,8 @@ public class UploadService extends IntentService {
String pageContents = intent.getStringExtra(EXTRA_PAGE_CONTENT); String pageContents = intent.getStringExtra(EXTRA_PAGE_CONTENT);
String editSummary = intent.getStringExtra(EXTRA_EDIT_SUMMARY); String editSummary = intent.getStringExtra(EXTRA_EDIT_SUMMARY);
String notificationTag = mediaUri.toString();
try { try {
file = this.getContentResolver().openInputStream(mediaUri); file = this.getContentResolver().openInputStream(mediaUri);
length = this.getContentResolver().openAssetFileDescriptor(mediaUri, "r").getLength(); length = this.getContentResolver().openAssetFileDescriptor(mediaUri, "r").getLength();
@ -96,21 +100,19 @@ public class UploadService extends IntentService {
.setAutoCancel(true) .setAutoCancel(true)
.setContent(notificationView) .setContent(notificationView)
.setContentIntent(PendingIntent.getActivity(getApplicationContext(), 0, new Intent(), 0)) .setContentIntent(PendingIntent.getActivity(getApplicationContext(), 0, new Intent(), 0))
.setOngoing(true)
.getNotification(); .getNotification();
notificationManager.notify(NOTIFICATION_DOWNLOAD_IN_PROGRESS, curNotification); notificationManager.notify(notificationTag, NOTIFICATION_DOWNLOAD_IN_PROGRESS, curNotification);
Log.d("Commons", "Just before"); Log.d("Commons", "Just before");
try { try {
result = api.upload(filename, file, length, pageContents, editSummary, new NotificationUpdateProgressListener(curNotification)); result = api.upload(filename, file, length, pageContents, editSummary, new NotificationUpdateProgressListener(curNotification, notificationTag));
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
throw new RuntimeException(e); throw new RuntimeException(e);
} }
Log.d("Commons", "After"); Log.d("Commons", "After");
notificationView.setTextViewText(R.id.uploadNotificationTitle, filename + " Uploaded!"); notificationManager.cancel(notificationTag, NOTIFICATION_DOWNLOAD_IN_PROGRESS);
notificationManager.notify(NOTIFICATION_DOWNLOAD_IN_PROGRESS, curNotification);
} }
} }