fix original file deletion (and instrumentation)
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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> {
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user