mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 12:23:58 +01:00
More accurate feedback about current status of upload!
This commit is contained in:
parent
034fde1007
commit
eb8edb2f06
2 changed files with 29 additions and 3 deletions
|
|
@ -23,4 +23,7 @@
|
|||
|
||||
<string name="upload_completed_notification_title">%1$s uploaded!</string>
|
||||
<string name="upload_completed_notification_text">Tap to view your upload</string>
|
||||
<string name="upload_progress_notification_title_start">Starting %1$s upload</string>
|
||||
<string name="upload_progress_notification_title_in_progress">%1$s uploading</string>
|
||||
<string name="upload_progress_notification_title_finishing">Finishing uploading %1$s</string>
|
||||
</resources>
|
||||
|
|
@ -39,19 +39,38 @@ public class UploadService extends IntentService {
|
|||
|
||||
Notification curNotification;
|
||||
String notificationTag;
|
||||
boolean notificationTitleChanged;
|
||||
|
||||
String notificationProgressTitle;
|
||||
String notificationFinishingTitle;
|
||||
|
||||
private int lastPercent = 0;
|
||||
public NotificationUpdateProgressListener(Notification curNotification, String notificationTag) {
|
||||
|
||||
public NotificationUpdateProgressListener(Notification curNotification, String notificationTag, String notificationProgressTitle, String notificationFinishingTitle) {
|
||||
this.curNotification = curNotification;
|
||||
this.notificationTag = notificationTag;
|
||||
this.notificationProgressTitle = notificationProgressTitle;
|
||||
this.notificationFinishingTitle = notificationFinishingTitle;
|
||||
}
|
||||
@Override
|
||||
public void onProgress(long transferred, long total) {
|
||||
RemoteViews curView = curNotification.contentView;
|
||||
if(!notificationTitleChanged) {
|
||||
curView.setTextViewText(R.id.uploadNotificationTitle, notificationProgressTitle);
|
||||
notificationTitleChanged = false;
|
||||
notificationManager.notify(notificationTag, NOTIFICATION_DOWNLOAD_IN_PROGRESS, curNotification);
|
||||
}
|
||||
int percent =(int) ((double)transferred / (double)total * 100);
|
||||
if(percent > lastPercent) {
|
||||
curNotification.contentView.setProgressBar(R.id.uploadNotificationProgress, 100, percent, false);
|
||||
notificationManager.notify(notificationTag, NOTIFICATION_DOWNLOAD_IN_PROGRESS, curNotification);
|
||||
lastPercent = percent;
|
||||
}
|
||||
if(percent == 100) {
|
||||
// Completed!
|
||||
curView.setTextViewText(R.id.uploadNotificationTitle, notificationFinishingTitle);
|
||||
notificationManager.notify(notificationTag, NOTIFICATION_DOWNLOAD_IN_PROGRESS, curNotification);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -92,7 +111,7 @@ public class UploadService extends IntentService {
|
|||
}
|
||||
|
||||
notificationView = new RemoteViews(getPackageName(), R.layout.layout_upload_progress);
|
||||
notificationView.setTextViewText(R.id.uploadNotificationTitle, "Uploading " + filename);
|
||||
notificationView.setTextViewText(R.id.uploadNotificationTitle, String.format(getString(R.string.upload_progress_notification_title_start), filename));
|
||||
notificationView.setProgressBar(R.id.uploadNotificationProgress, 100, 0, false);
|
||||
|
||||
Log.d("Commons", "Before execution!");
|
||||
|
|
@ -106,8 +125,12 @@ public class UploadService extends IntentService {
|
|||
notificationManager.notify(notificationTag, NOTIFICATION_DOWNLOAD_IN_PROGRESS, progressNotification);
|
||||
|
||||
Log.d("Commons", "Just before");
|
||||
NotificationUpdateProgressListener notificationUpdater = new NotificationUpdateProgressListener(progressNotification, notificationTag,
|
||||
String.format(getString(R.string.upload_progress_notification_title_in_progress), filename),
|
||||
String.format(getString(R.string.upload_progress_notification_title_finishing), filename)
|
||||
);
|
||||
try {
|
||||
result = api.upload(filename, file, length, pageContents, editSummary, new NotificationUpdateProgressListener(progressNotification, notificationTag));
|
||||
result = api.upload(filename, file, length, pageContents, editSummary, notificationUpdater);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue