Show failed uploads in my contributions

This commit is contained in:
YuviPanda 2013-02-04 00:34:59 +05:30
parent a57d0316f8
commit 59caee38a9
4 changed files with 43 additions and 39 deletions

View file

@ -38,6 +38,7 @@
<string name="title_activity_contributions">My Contributions</string>
<string name="contribution_state_queued">Queued</string>
<string name="contribution_state_failed">Failed</string>
<string name="contribution_state_in_progress">Uploading</string>
<string name="menu_from_gallery">From Gallery</string>
<string name="menu_from_camera">Take Photo</string>

View file

@ -247,19 +247,7 @@ public class UploadService extends IntentService {
result = api.upload(contribution.getFilename(), file, contribution.getDataLength(), contribution.getPageContents(), contribution.getEditSummary(), notificationUpdater);
} catch(IOException e) {
Log.d("Commons", "I have a network fuckup");
stopForeground(true);
Notification failureNotification = new NotificationCompat.Builder(this).setAutoCancel(true)
.setSmallIcon(R.drawable.ic_launcher)
.setAutoCancel(true)
.setContentIntent(PendingIntent.getService(getApplicationContext(), 0, intent, 0))
.setTicker(String.format(getString(R.string.upload_failed_notification_title), contribution.getFilename()))
.setContentTitle(String.format(getString(R.string.upload_failed_notification_title), contribution.getFilename()))
.setContentText(getString(R.string.upload_failed_notification_subtitle))
.getNotification();
notificationManager.notify(NOTIFICATION_UPLOAD_FAILED, failureNotification);
contribution.setState(Contribution.STATE_QUEUED);
contribution.save();
showFailedNotification(contribution);
return;
} finally {
toUpload--;
@ -271,28 +259,35 @@ public class UploadService extends IntentService {
SimpleDateFormat isoFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); // Assuming MW always gives me UTC
String descUrl = result.getString("/api/upload/imageinfo/@descriptionurl");
String resultStatus = result.getString("/api/upload/@result");
if(!resultStatus.equals("success")) {
showFailedNotification(contribution);
} else {
Date dateUploaded = null;
try {
dateUploaded = isoFormat.parse(result.getString("/api/upload/imageinfo/@timestamp"));
} catch(java.text.ParseException e) {
throw new RuntimeException(e); // Hopefully mediawiki doesn't give me bogus stuff?
}
Intent openUploadedPageIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(descUrl));
Notification doneNotification = new NotificationCompat.Builder(this)
.setAutoCancel(true)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle(String.format(getString(R.string.upload_completed_notification_title), contribution.getFilename()))
.setContentText(getString(R.string.upload_completed_notification_text))
.setTicker(String.format(getString(R.string.upload_completed_notification_title), contribution.getFilename()))
.setContentIntent(PendingIntent.getActivity(this, 0, openUploadedPageIntent, 0))
.getNotification();
notificationManager.notify(notificationTag, NOTIFICATION_DOWNLOAD_COMPLETE, doneNotification);
contribution.setState(Contribution.STATE_COMPLETED);
contribution.setDateUploaded(dateUploaded);
contribution.save();
}
}
private void showFailedNotification(Contribution contribution) {
stopForeground(true);
Notification failureNotification = new NotificationCompat.Builder(this).setAutoCancel(true)
.setSmallIcon(R.drawable.ic_launcher)
.setAutoCancel(true)
.setContentIntent(PendingIntent.getActivity(this, 0, new Intent(this, ContributionsActivity.class), 0))
.setTicker(String.format(getString(R.string.upload_failed_notification_title), contribution.getFilename()))
.setContentTitle(String.format(getString(R.string.upload_failed_notification_title), contribution.getFilename()))
.setContentText(getString(R.string.upload_failed_notification_subtitle))
.getNotification();
notificationManager.notify(NOTIFICATION_UPLOAD_FAILED, failureNotification);
contribution.setState(Contribution.STATE_FAILED);
contribution.save();
}
}

View file

@ -14,8 +14,9 @@ public class Contribution extends Media {
// No need to be bitwise - they're mutually exclusive
public static final int STATE_COMPLETED = -1;
public static final int STATE_QUEUED = 1;
public static final int STATE_IN_PROGRESS = 2;
public static final int STATE_FAILED = 1;
public static final int STATE_QUEUED = 2;
public static final int STATE_IN_PROGRESS = 3;
private ContentProviderClient client;
private Uri contentUri;

View file

@ -88,13 +88,20 @@ public class ContributionsActivity extends AuthenticatedActivity implements Load
}
titleView.setText(cursor.getString(COLUMN_FILENAME));
if(state == Contribution.STATE_COMPLETED) {
switch(state) {
case Contribution.STATE_COMPLETED:
Date uploaded = new Date(cursor.getLong(COLUMN_UPLOADED));
stateView.setText(SimpleDateFormat.getDateInstance().format(uploaded));
} else if(state == Contribution.STATE_QUEUED) {
break;
case Contribution.STATE_QUEUED:
stateView.setText(R.string.contribution_state_queued);
} else if(state == Contribution.STATE_IN_PROGRESS) {
break;
case Contribution.STATE_IN_PROGRESS:
stateView.setText(R.string.contribution_state_in_progress);
break;
case Contribution.STATE_FAILED:
stateView.setText(R.string.contribution_state_failed);
break;
}
}