fix original file deletion (and instrumentation)
This commit is contained in:
@@ -165,7 +165,7 @@ public class AsymmetricFileOperationTests {
|
|||||||
// delete file
|
// delete file
|
||||||
onView(withText(R.string.btn_delete_original)).perform(click());
|
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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -210,10 +210,13 @@ public class TemporaryStorageProvider extends ContentProvider {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int delete(Uri uri, String selection, String[] selectionArgs) {
|
public int delete(Uri uri, String selection, String[] selectionArgs) {
|
||||||
if (uri.getLastPathSegment() != null) {
|
if (uri == null || uri.getLastPathSegment() == null) {
|
||||||
selection = DatabaseUtil.concatenateWhere(selection, COLUMN_ID + "=?");
|
return 0;
|
||||||
selectionArgs = DatabaseUtil.appendSelectionArgs(selectionArgs, new String[]{uri.getLastPathSegment()});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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,
|
Cursor files = db.getReadableDatabase().query(TABLE_FILES, new String[]{COLUMN_ID}, selection,
|
||||||
selectionArgs, null, null, null);
|
selectionArgs, null, null, null);
|
||||||
if (files != null) {
|
if (files != null) {
|
||||||
|
|||||||
@@ -499,18 +499,33 @@ public class DecryptListFragment
|
|||||||
|
|
||||||
private void deleteFile(Activity activity, Uri uri) {
|
private void deleteFile(Activity activity, Uri uri) {
|
||||||
|
|
||||||
try {
|
if ("file".equals(uri.getScheme())) {
|
||||||
int deleted = activity.getContentResolver().delete(uri, null, null);
|
File file = new File(uri.getPath());
|
||||||
if (deleted > 0) {
|
if (file.delete()) {
|
||||||
Notify.create(activity, R.string.file_delete_ok, Style.OK).show();
|
Notify.create(activity, R.string.file_delete_ok, Style.OK).show();
|
||||||
} else {
|
} else {
|
||||||
Notify.create(activity, R.string.file_delete_none, Style.WARN).show();
|
Notify.create(activity, R.string.file_delete_none, Style.WARN).show();
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
return;
|
||||||
Log.e(Constants.TAG, "exception deleting file", e);
|
|
||||||
Notify.create(activity, R.string.file_delete_exception, Style.ERROR).show();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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> {
|
public static class DecryptFilesAdapter extends RecyclerView.Adapter<ViewHolder> {
|
||||||
|
|||||||
@@ -1347,6 +1347,6 @@
|
|||||||
<string name="file_saved">"File saved!"</string>
|
<string name="file_saved">"File saved!"</string>
|
||||||
<string name="file_delete_ok">"Original file deleted."</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_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>
|
</resources>
|
||||||
|
|||||||
Reference in New Issue
Block a user