mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Cleanup contributions state when service starts.
This will clean up stale 'Uploading' or 'Queued' entries that failed to do so because of service crashes
This commit is contained in:
parent
297f3277de
commit
e6a8f4d626
2 changed files with 26 additions and 12 deletions
|
|
@ -33,6 +33,8 @@ public class UploadService extends Service {
|
||||||
|
|
||||||
private static final int ACTION_UPLOAD_FILE = 1;
|
private static final int ACTION_UPLOAD_FILE = 1;
|
||||||
|
|
||||||
|
public static final String ACTION_START_SERVICE = EXTRA_PREFIX + ".upload";
|
||||||
|
|
||||||
private NotificationManager notificationManager;
|
private NotificationManager notificationManager;
|
||||||
private ContentProviderClient contributionsProviderClient;
|
private ContentProviderClient contributionsProviderClient;
|
||||||
private CommonsApplication app;
|
private CommonsApplication app;
|
||||||
|
|
@ -197,23 +199,33 @@ public class UploadService extends Service {
|
||||||
contribution.setContentProviderClient(contributionsProviderClient);
|
contribution.setContentProviderClient(contributionsProviderClient);
|
||||||
|
|
||||||
contribution.save();
|
contribution.save();
|
||||||
|
toUpload++;
|
||||||
|
if (curProgressNotification != null && toUpload != 1) {
|
||||||
|
curProgressNotification.contentView.setTextViewText(R.id.uploadNotificationsCount, String.format(getString(R.string.uploads_pending_notification_indicator), toUpload));
|
||||||
|
Log.d("Commons", String.format("%d uploads left", toUpload));
|
||||||
|
notificationManager.notify(NOTIFICATION_UPLOAD_IN_PROGRESS, curProgressNotification);
|
||||||
|
}
|
||||||
|
|
||||||
postMessage(ACTION_UPLOAD_FILE, contribution);
|
postMessage(ACTION_UPLOAD_FILE, contribution);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||||
toUpload++;
|
if(intent.getAction() == ACTION_START_SERVICE) {
|
||||||
if(curProgressNotification != null && toUpload != 1) {
|
ContentValues failedValues = new ContentValues();
|
||||||
curProgressNotification.contentView.setTextViewText(R.id.uploadNotificationsCount, String.format(getString(R.string.uploads_pending_notification_indicator), toUpload));
|
failedValues.put(Contribution.Table.COLUMN_STATE, Contribution.STATE_FAILED);
|
||||||
Log.d("Commons", String.format("%d uploads left", toUpload));
|
|
||||||
notificationManager.notify(NOTIFICATION_UPLOAD_IN_PROGRESS, curProgressNotification);
|
int updated = getContentResolver().update(ContributionsContentProvider.BASE_URI,
|
||||||
|
failedValues,
|
||||||
|
Contribution.Table.COLUMN_STATE + " = ? OR " + Contribution.Table.COLUMN_STATE + " = ?",
|
||||||
|
new String[]{ String.valueOf(Contribution.STATE_QUEUED), String.valueOf(Contribution.STATE_IN_PROGRESS) }
|
||||||
|
);
|
||||||
|
Log.d("Commons", "Set " + updated + " uploads to failed");
|
||||||
|
} else {
|
||||||
|
|
||||||
|
Contribution contribution = mediaFromIntent(intent);
|
||||||
|
queueContribution(contribution);
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.d("Commons", "Received startcommand");
|
|
||||||
Contribution contribution = mediaFromIntent(intent);
|
|
||||||
queueContribution(contribution);
|
|
||||||
|
|
||||||
return START_REDELIVER_INTENT;
|
return START_REDELIVER_INTENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -169,8 +169,10 @@ public class ContributionsActivity extends AuthenticatedActivity implements Load
|
||||||
.cacheInMemory()
|
.cacheInMemory()
|
||||||
.cacheOnDisc()
|
.cacheOnDisc()
|
||||||
.resetViewBeforeLoading().build();
|
.resetViewBeforeLoading().build();
|
||||||
|
Intent uploadServiceIntent = new Intent(this, UploadService.class);
|
||||||
bindService(new Intent(this, UploadService.class), uploadServiceConnection, Context.BIND_AUTO_CREATE);
|
uploadServiceIntent.setAction(UploadService.ACTION_START_SERVICE);
|
||||||
|
startService(uploadServiceIntent);
|
||||||
|
bindService(uploadServiceIntent, uploadServiceConnection, Context.BIND_AUTO_CREATE);
|
||||||
|
|
||||||
Cursor allContributions = getContentResolver().query(ContributionsContentProvider.BASE_URI, Contribution.Table.ALL_FIELDS, CONTRIBUTION_SELECTION, null, CONTRIBUTION_SORT);
|
Cursor allContributions = getContentResolver().query(ContributionsContentProvider.BASE_URI, Contribution.Table.ALL_FIELDS, CONTRIBUTION_SELECTION, null, CONTRIBUTION_SORT);
|
||||||
contributionsAdapter = new ContributionAdapter(this, allContributions, 0);
|
contributionsAdapter = new ContributionAdapter(this, allContributions, 0);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue