mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Show failed uploads in my contributions
This commit is contained in:
parent
a57d0316f8
commit
59caee38a9
4 changed files with 43 additions and 39 deletions
|
|
@ -38,6 +38,7 @@
|
||||||
|
|
||||||
<string name="title_activity_contributions">My Contributions</string>
|
<string name="title_activity_contributions">My Contributions</string>
|
||||||
<string name="contribution_state_queued">Queued</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="contribution_state_in_progress">Uploading</string>
|
||||||
<string name="menu_from_gallery">From Gallery</string>
|
<string name="menu_from_gallery">From Gallery</string>
|
||||||
<string name="menu_from_camera">Take Photo</string>
|
<string name="menu_from_camera">Take Photo</string>
|
||||||
|
|
|
||||||
|
|
@ -247,19 +247,7 @@ public class UploadService extends IntentService {
|
||||||
result = api.upload(contribution.getFilename(), file, contribution.getDataLength(), contribution.getPageContents(), contribution.getEditSummary(), notificationUpdater);
|
result = api.upload(contribution.getFilename(), file, contribution.getDataLength(), contribution.getPageContents(), contribution.getEditSummary(), notificationUpdater);
|
||||||
} catch(IOException e) {
|
} catch(IOException e) {
|
||||||
Log.d("Commons", "I have a network fuckup");
|
Log.d("Commons", "I have a network fuckup");
|
||||||
stopForeground(true);
|
showFailedNotification(contribution);
|
||||||
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();
|
|
||||||
return;
|
return;
|
||||||
} finally {
|
} finally {
|
||||||
toUpload--;
|
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
|
SimpleDateFormat isoFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); // Assuming MW always gives me UTC
|
||||||
|
|
||||||
|
String resultStatus = result.getString("/api/upload/@result");
|
||||||
String descUrl = result.getString("/api/upload/imageinfo/@descriptionurl");
|
if(!resultStatus.equals("success")) {
|
||||||
Date dateUploaded = null;
|
showFailedNotification(contribution);
|
||||||
try {
|
} else {
|
||||||
dateUploaded = isoFormat.parse(result.getString("/api/upload/imageinfo/@timestamp"));
|
Date dateUploaded = null;
|
||||||
} catch(java.text.ParseException e) {
|
try {
|
||||||
throw new RuntimeException(e); // Hopefully mediawiki doesn't give me bogus stuff?
|
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?
|
||||||
|
}
|
||||||
|
contribution.setState(Contribution.STATE_COMPLETED);
|
||||||
|
contribution.setDateUploaded(dateUploaded);
|
||||||
|
contribution.save();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Intent openUploadedPageIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(descUrl));
|
private void showFailedNotification(Contribution contribution) {
|
||||||
Notification doneNotification = new NotificationCompat.Builder(this)
|
stopForeground(true);
|
||||||
.setAutoCancel(true)
|
Notification failureNotification = new NotificationCompat.Builder(this).setAutoCancel(true)
|
||||||
.setSmallIcon(R.drawable.ic_launcher)
|
.setSmallIcon(R.drawable.ic_launcher)
|
||||||
.setContentTitle(String.format(getString(R.string.upload_completed_notification_title), contribution.getFilename()))
|
.setAutoCancel(true)
|
||||||
.setContentText(getString(R.string.upload_completed_notification_text))
|
.setContentIntent(PendingIntent.getActivity(this, 0, new Intent(this, ContributionsActivity.class), 0))
|
||||||
.setTicker(String.format(getString(R.string.upload_completed_notification_title), contribution.getFilename()))
|
.setTicker(String.format(getString(R.string.upload_failed_notification_title), contribution.getFilename()))
|
||||||
.setContentIntent(PendingIntent.getActivity(this, 0, openUploadedPageIntent, 0))
|
.setContentTitle(String.format(getString(R.string.upload_failed_notification_title), contribution.getFilename()))
|
||||||
|
.setContentText(getString(R.string.upload_failed_notification_subtitle))
|
||||||
.getNotification();
|
.getNotification();
|
||||||
|
notificationManager.notify(NOTIFICATION_UPLOAD_FAILED, failureNotification);
|
||||||
|
|
||||||
notificationManager.notify(notificationTag, NOTIFICATION_DOWNLOAD_COMPLETE, doneNotification);
|
contribution.setState(Contribution.STATE_FAILED);
|
||||||
contribution.setState(Contribution.STATE_COMPLETED);
|
|
||||||
contribution.setDateUploaded(dateUploaded);
|
|
||||||
contribution.save();
|
contribution.save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,8 +14,9 @@ public class Contribution extends Media {
|
||||||
|
|
||||||
// No need to be bitwise - they're mutually exclusive
|
// No need to be bitwise - they're mutually exclusive
|
||||||
public static final int STATE_COMPLETED = -1;
|
public static final int STATE_COMPLETED = -1;
|
||||||
public static final int STATE_QUEUED = 1;
|
public static final int STATE_FAILED = 1;
|
||||||
public static final int STATE_IN_PROGRESS = 2;
|
public static final int STATE_QUEUED = 2;
|
||||||
|
public static final int STATE_IN_PROGRESS = 3;
|
||||||
|
|
||||||
private ContentProviderClient client;
|
private ContentProviderClient client;
|
||||||
private Uri contentUri;
|
private Uri contentUri;
|
||||||
|
|
|
||||||
|
|
@ -88,13 +88,20 @@ public class ContributionsActivity extends AuthenticatedActivity implements Load
|
||||||
}
|
}
|
||||||
|
|
||||||
titleView.setText(cursor.getString(COLUMN_FILENAME));
|
titleView.setText(cursor.getString(COLUMN_FILENAME));
|
||||||
if(state == Contribution.STATE_COMPLETED) {
|
switch(state) {
|
||||||
Date uploaded = new Date(cursor.getLong(COLUMN_UPLOADED));
|
case Contribution.STATE_COMPLETED:
|
||||||
stateView.setText(SimpleDateFormat.getDateInstance().format(uploaded));
|
Date uploaded = new Date(cursor.getLong(COLUMN_UPLOADED));
|
||||||
} else if(state == Contribution.STATE_QUEUED) {
|
stateView.setText(SimpleDateFormat.getDateInstance().format(uploaded));
|
||||||
stateView.setText(R.string.contribution_state_queued);
|
break;
|
||||||
} else if(state == Contribution.STATE_IN_PROGRESS) {
|
case Contribution.STATE_QUEUED:
|
||||||
stateView.setText(R.string.contribution_state_in_progress);
|
stateView.setText(R.string.contribution_state_queued);
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue