mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Make delete button work
This commit is contained in:
parent
43a6551d6e
commit
0bdef367b9
4 changed files with 44 additions and 1 deletions
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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()) {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue