mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +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="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>
|
||||||
|
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue