Make delete button work

This commit is contained in:
Brion Vibber 2013-05-10 15:43:15 -07:00
parent 43a6551d6e
commit 0bdef367b9
4 changed files with 44 additions and 1 deletions

View file

@ -155,6 +155,19 @@ public class Contribution extends Media {
}
}
public void delete() {
try {
if(contentUri == null) {
// noooo
throw new RuntimeException("tried to delete item with no content URI");
} else {
client.delete(contentUri, null, null);
}
} catch (RemoteException e) {
throw new RuntimeException(e);
}
}
public ContentValues toContentValues() {
ContentValues cv = new ContentValues();

View file

@ -131,6 +131,18 @@ public class ContributionsActivity
}
}
public void deleteUpload(int i) {
allContributions.moveToPosition(i);
Contribution c = Contribution.fromCursor(allContributions);
if(c.getState() == Contribution.STATE_FAILED) {
Log.d("Commons", "Deleting failed contrib " + c.toContentValues().toString());
c.setContentProviderClient(getContentResolver().acquireContentProviderClient(ContributionsContentProvider.AUTHORITY));
c.delete();
} else {
Log.d("Commons", "Skipping deletion for non-failed contrib " + c.toContentValues().toString());
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()) {

View file

@ -94,7 +94,24 @@ public class ContributionsContentProvider extends ContentProvider{
@Override
public int delete(Uri uri, String s, String[] strings) {
return 0;
int rows = 0;
int uriType = uriMatcher.match(uri);
SQLiteDatabase db = dbOpenHelper.getReadableDatabase();
switch(uriType) {
case CONTRIBUTIONS_ID:
Log.d("Commons", "Deleting contribution id " + uri.getLastPathSegment());
rows = db.delete(Contribution.Table.TABLE_NAME,
"_id = ?",
new String[] { uri.getLastPathSegment() }
);
break;
default:
throw new IllegalArgumentException("Unknown URI" + uri);
}
getContext().getContentResolver().notifyChange(uri, null);
return rows;
}
@Override

View file

@ -139,6 +139,7 @@ public class MediaDetailPagerFragment extends SherlockFragment implements ViewPa
return true;
case R.id.menu_abort_current_image:
// todo: delete image
((ContributionsActivity)getSherlockActivity()).deleteUpload(pager.getCurrentItem());
getSherlockActivity().getSupportFragmentManager().popBackStack();
return true;
default: