fix original file deletion (and instrumentation)

This commit is contained in:
Vincent Breitmoser
2015-06-23 21:56:23 +02:00
parent 45a8510bf0
commit 8d141176bd
4 changed files with 29 additions and 11 deletions

View File

@@ -165,7 +165,7 @@ public class AsymmetricFileOperationTests {
// delete file
onView(withText(R.string.btn_delete_original)).perform(click());
checkSnackbar(Style.OK, R.string.file_delete_none);
checkSnackbar(Style.WARN, R.string.file_delete_none);
}

View File

@@ -210,10 +210,13 @@ public class TemporaryStorageProvider extends ContentProvider {
@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
if (uri.getLastPathSegment() != null) {
selection = DatabaseUtil.concatenateWhere(selection, COLUMN_ID + "=?");
selectionArgs = DatabaseUtil.appendSelectionArgs(selectionArgs, new String[]{uri.getLastPathSegment()});
if (uri == null || uri.getLastPathSegment() == null) {
return 0;
}
selection = DatabaseUtil.concatenateWhere(selection, COLUMN_ID + "=?");
selectionArgs = DatabaseUtil.appendSelectionArgs(selectionArgs, new String[]{uri.getLastPathSegment()});
Cursor files = db.getReadableDatabase().query(TABLE_FILES, new String[]{COLUMN_ID}, selection,
selectionArgs, null, null, null);
if (files != null) {

View File

@@ -499,18 +499,33 @@ public class DecryptListFragment
private void deleteFile(Activity activity, Uri uri) {
try {
int deleted = activity.getContentResolver().delete(uri, null, null);
if (deleted > 0) {
if ("file".equals(uri.getScheme())) {
File file = new File(uri.getPath());
if (file.delete()) {
Notify.create(activity, R.string.file_delete_ok, Style.OK).show();
} else {
Notify.create(activity, R.string.file_delete_none, Style.WARN).show();
}
} catch (Exception e) {
Log.e(Constants.TAG, "exception deleting file", e);
Notify.create(activity, R.string.file_delete_exception, Style.ERROR).show();
return;
}
if ("content".equals(uri.getScheme())) {
try {
int deleted = activity.getContentResolver().delete(uri, null, null);
if (deleted > 0) {
Notify.create(activity, R.string.file_delete_ok, Style.OK).show();
} else {
Notify.create(activity, R.string.file_delete_none, Style.WARN).show();
}
} catch (Exception e) {
Log.e(Constants.TAG, "exception deleting file", e);
Notify.create(activity, R.string.file_delete_exception, Style.ERROR).show();
}
return;
}
Notify.create(activity, R.string.file_delete_exception, Style.ERROR).show();
}
public static class DecryptFilesAdapter extends RecyclerView.Adapter<ViewHolder> {

View File

@@ -1347,6 +1347,6 @@
<string name="file_saved">"File saved!"</string>
<string name="file_delete_ok">"Original file deleted."</string>
<string name="file_delete_none">"No file deleted! (Already deleted?)"</string>
<string name="file_delete_exception">"Could not delete original file!"</string>
<string name="file_delete_exception">"Original file could not be deleted!"</string>
</resources>