Display new notification when upload is complete

Full fix for issue #4
This commit is contained in:
YuviPanda 2012-10-26 00:02:31 +05:30
parent 111b618b2f
commit 034fde1007
2 changed files with 22 additions and 7 deletions

View file

@ -20,5 +20,7 @@
<string name="uploading_failed">Upload failed!</string> <string name="uploading_failed">Upload failed!</string>
<string name="authentication_failed">Authentication failed!</string> <string name="authentication_failed">Authentication failed!</string>
<string name="uploading_started">Upload started!</string> <string name="uploading_started">Upload started!</string>
<string name="upload_completed_notification_title">%1$s uploaded!</string>
<string name="upload_completed_notification_text">Tap to view your upload</string>
</resources> </resources>

View file

@ -32,7 +32,8 @@ public class UploadService extends IntentService {
public UploadService() { public UploadService() {
super("UploadService"); super("UploadService");
} }
public static final int NOTIFICATION_DOWNLOAD_IN_PROGRESS = 1; public static final int NOTIFICATION_DOWNLOAD_IN_PROGRESS = 0;
public static final int NOTIFICATION_DOWNLOAD_COMPLETE = 1;
private class NotificationUpdateProgressListener implements ProgressListener { private class NotificationUpdateProgressListener implements ProgressListener {
@ -66,6 +67,7 @@ public class UploadService extends IntentService {
notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
} }
@Override @Override
protected void onHandleIntent(Intent intent) { protected void onHandleIntent(Intent intent) {
MWApi api = ((CommonsApplication)this.getApplicationContext()).getApi(); MWApi api = ((CommonsApplication)this.getApplicationContext()).getApi();
@ -94,24 +96,35 @@ public class UploadService extends IntentService {
notificationView.setProgressBar(R.id.uploadNotificationProgress, 100, 0, false); notificationView.setProgressBar(R.id.uploadNotificationProgress, 100, 0, false);
Log.d("Commons", "Before execution!"); Log.d("Commons", "Before execution!");
Notification curNotification = new NotificationCompat.Builder(this).setAutoCancel(true) Notification progressNotification = new NotificationCompat.Builder(this).setAutoCancel(true)
.setSmallIcon(R.drawable.ic_launcher) .setSmallIcon(R.drawable.ic_launcher)
.setAutoCancel(true) .setAutoCancel(true)
.setContent(notificationView) .setContent(notificationView)
.setContentIntent(PendingIntent.getActivity(getApplicationContext(), 0, new Intent(), 0)) .setContentIntent(PendingIntent.getActivity(getApplicationContext(), 0, new Intent(), 0))
.getNotification(); .getNotification();
notificationManager.notify(notificationTag, NOTIFICATION_DOWNLOAD_IN_PROGRESS, curNotification); notificationManager.notify(notificationTag, NOTIFICATION_DOWNLOAD_IN_PROGRESS, progressNotification);
Log.d("Commons", "Just before"); Log.d("Commons", "Just before");
try { try {
result = api.upload(filename, file, length, pageContents, editSummary, new NotificationUpdateProgressListener(curNotification, notificationTag)); result = api.upload(filename, file, length, pageContents, editSummary, new NotificationUpdateProgressListener(progressNotification, notificationTag));
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
throw new RuntimeException(e); throw new RuntimeException(e);
} }
Log.d("Commons", "After");
notificationManager.cancel(notificationTag, NOTIFICATION_DOWNLOAD_IN_PROGRESS); notificationManager.cancel(notificationTag, NOTIFICATION_DOWNLOAD_IN_PROGRESS);
String descUrl = result.getString("/api/upload/imageinfo/@descriptionurl");
Intent openUploadedPageIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(descUrl));
Notification doneNotification = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle(String.format(getString(R.string.upload_completed_notification_title), filename))
.setContentText(getString(R.string.upload_completed_notification_text))
.setContentIntent(PendingIntent.getActivity(this, 0, openUploadedPageIntent, 0))
.getNotification();
notificationManager.notify(notificationTag, NOTIFICATION_DOWNLOAD_COMPLETE, doneNotification);
} }
} }