mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
parent
111b618b2f
commit
034fde1007
2 changed files with 22 additions and 7 deletions
|
|
@ -21,4 +21,6 @@
|
|||
<string name="authentication_failed">Authentication failed!</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>
|
||||
|
|
@ -32,7 +32,8 @@ public class UploadService extends IntentService {
|
|||
public 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 {
|
||||
|
||||
|
|
@ -66,6 +67,7 @@ public class UploadService extends IntentService {
|
|||
notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onHandleIntent(Intent intent) {
|
||||
MWApi api = ((CommonsApplication)this.getApplicationContext()).getApi();
|
||||
|
|
@ -94,24 +96,35 @@ public class UploadService extends IntentService {
|
|||
notificationView.setProgressBar(R.id.uploadNotificationProgress, 100, 0, false);
|
||||
|
||||
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)
|
||||
.setAutoCancel(true)
|
||||
.setContent(notificationView)
|
||||
.setContentIntent(PendingIntent.getActivity(getApplicationContext(), 0, new Intent(), 0))
|
||||
.getNotification();
|
||||
|
||||
notificationManager.notify(notificationTag, NOTIFICATION_DOWNLOAD_IN_PROGRESS, curNotification);
|
||||
notificationManager.notify(notificationTag, NOTIFICATION_DOWNLOAD_IN_PROGRESS, progressNotification);
|
||||
|
||||
Log.d("Commons", "Just before");
|
||||
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) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
Log.d("Commons", "After");
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue