mirror of
https://github.com/moparisthebest/open-keychain
synced 2025-02-17 07:30:14 -05:00
Some fixes for delete after encryption
This commit is contained in:
parent
7c22fc843b
commit
cc66435e38
@ -28,8 +28,10 @@ import android.support.v4.app.DialogFragment;
|
|||||||
import android.support.v4.app.FragmentActivity;
|
import android.support.v4.app.FragmentActivity;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
import org.sufficientlysecure.keychain.util.FileHelper;
|
import org.sufficientlysecure.keychain.util.FileHelper;
|
||||||
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
@ -69,41 +71,44 @@ public class DeleteFileDialogFragment extends DialogFragment {
|
|||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
dismiss();
|
dismiss();
|
||||||
String scheme = deleteUri.getScheme();
|
|
||||||
|
|
||||||
if(scheme.equals(ContentResolver.SCHEME_FILE)) {
|
// NOTE: Use Toasts, not Snackbars. When sharing to another application snackbars
|
||||||
if(new File(deleteUri.getPath()).delete()) {
|
// would not show up!
|
||||||
Toast.makeText(getActivity(), R.string.file_delete_successful, Toast.LENGTH_SHORT).show();
|
|
||||||
return;
|
// Use DocumentsContract on Android >= 4.4
|
||||||
}
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||||
}
|
try {
|
||||||
else if(scheme.equals(ContentResolver.SCHEME_CONTENT)) {
|
|
||||||
// We can not securely delete Uris, so just use usual delete on them
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
|
||||||
if (DocumentsContract.deleteDocument(getActivity().getContentResolver(), deleteUri)) {
|
if (DocumentsContract.deleteDocument(getActivity().getContentResolver(), deleteUri)) {
|
||||||
Toast.makeText(getActivity(), R.string.file_delete_successful, Toast.LENGTH_SHORT).show();
|
Toast.makeText(getActivity(), getActivity().getString(R.string.file_delete_successful,
|
||||||
|
deleteFilename), Toast.LENGTH_LONG).show();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
} catch (UnsupportedOperationException e) {
|
||||||
|
Log.d(Constants.TAG, "Catched UnsupportedOperationException, can happen when delete is not supported!", e);
|
||||||
if (getActivity().getContentResolver().delete(deleteUri, null, null) > 0) {
|
|
||||||
Toast.makeText(getActivity(), R.string.file_delete_successful, Toast.LENGTH_SHORT).show();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// some Uri's a ContentResolver fails to delete is handled by the java.io.File's delete
|
|
||||||
// via the path of the Uri
|
|
||||||
if(new File(deleteUri.getPath()).delete()) {
|
|
||||||
Toast.makeText(getActivity(), R.string.file_delete_successful, Toast.LENGTH_SHORT).show();
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Toast.makeText(getActivity(), getActivity().getString(R.string.error_file_delete_failed,
|
try {
|
||||||
deleteFilename), Toast.LENGTH_SHORT).show();
|
if (getActivity().getContentResolver().delete(deleteUri, null, null) > 0) {
|
||||||
|
Toast.makeText(getActivity(), getActivity().getString(R.string.file_delete_successful,
|
||||||
|
deleteFilename), Toast.LENGTH_LONG).show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} catch (UnsupportedOperationException e) {
|
||||||
|
Log.d(Constants.TAG, "Catched UnsupportedOperationException, can happen when delete is not supported!", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
// some Uri's a ContentResolver fails to delete is handled by the java.io.File's delete
|
||||||
|
// via the path of the Uri
|
||||||
|
if (new File(deleteUri.getPath()).delete()) {
|
||||||
|
Toast.makeText(getActivity(), getActivity().getString(R.string.file_delete_successful,
|
||||||
|
deleteFilename), Toast.LENGTH_LONG).show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Note: We can't delete every file...
|
// Note: We can't delete every file...
|
||||||
// If possible we should find out if deletion is possible before even showing the option to do so.
|
Toast.makeText(getActivity(), getActivity().getString(R.string.error_file_delete_failed,
|
||||||
|
deleteFilename), Toast.LENGTH_LONG).show();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
alert.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
|
alert.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
|
||||||
|
@ -1,21 +1,21 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:padding="4dp"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:clickable="true"
|
||||||
|
android:minHeight="?android:attr/listPreferredItemHeight"
|
||||||
|
style="?android:attr/borderlessButtonStyle">
|
||||||
|
|
||||||
<FrameLayout
|
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:padding="4dp"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:clickable="true"
|
|
||||||
style="@style/SelectableItem">
|
|
||||||
<TextView
|
<TextView
|
||||||
android:paddingLeft="8dp"
|
android:paddingLeft="8dp"
|
||||||
android:paddingRight="8dp"
|
android:paddingRight="8dp"
|
||||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_gravity="center"
|
android:layout_gravity="center"
|
||||||
android:text="@string/btn_add_files"
|
android:text="@string/btn_add_files"
|
||||||
android:drawableLeft="@drawable/ic_folder_grey_24dp"
|
android:drawableLeft="@drawable/ic_folder_grey_24dp"
|
||||||
android:drawablePadding="8dp"
|
android:drawablePadding="8dp"
|
||||||
android:gravity="center"/>
|
android:gravity="center" />
|
||||||
</FrameLayout>
|
</FrameLayout>
|
@ -220,7 +220,7 @@
|
|||||||
<string name="yubikey_pin_for">"Enter PIN to access YubiKey for '%s'"</string>
|
<string name="yubikey_pin_for">"Enter PIN to access YubiKey for '%s'"</string>
|
||||||
<string name="nfc_text">"Hold YubiKey against the back of your device."</string>
|
<string name="nfc_text">"Hold YubiKey against the back of your device."</string>
|
||||||
<string name="file_delete_confirmation">"Are you sure you want to delete\n%s?"</string>
|
<string name="file_delete_confirmation">"Are you sure you want to delete\n%s?"</string>
|
||||||
<string name="file_delete_successful">"Successfully deleted."</string>
|
<string name="file_delete_successful">"'%s' has been deleted."</string>
|
||||||
<string name="no_file_selected">"Select a file first."</string>
|
<string name="no_file_selected">"Select a file first."</string>
|
||||||
<string name="encrypt_sign_successful">"Successfully signed and/or encrypted."</string>
|
<string name="encrypt_sign_successful">"Successfully signed and/or encrypted."</string>
|
||||||
<string name="encrypt_sign_clipboard_successful">"Successfully signed and/or encrypted to clipboard."</string>
|
<string name="encrypt_sign_clipboard_successful">"Successfully signed and/or encrypted to clipboard."</string>
|
||||||
@ -261,7 +261,7 @@
|
|||||||
no punctuation, all lowercase,
|
no punctuation, all lowercase,
|
||||||
they will be put after "error_message", e.g. "Error: file not found"
|
they will be put after "error_message", e.g. "Error: file not found"
|
||||||
-->
|
-->
|
||||||
<string name="error_file_delete_failed">"deleting '%s' failed"</string>
|
<string name="error_file_delete_failed">"Deleting '%s' failed. Please do this manually!"</string>
|
||||||
<string name="error_file_not_found">"file not found"</string>
|
<string name="error_file_not_found">"file not found"</string>
|
||||||
<string name="error_no_secret_key_found">"no suitable secret key found"</string>
|
<string name="error_no_secret_key_found">"no suitable secret key found"</string>
|
||||||
<string name="error_external_storage_not_ready">"external storage not ready"</string>
|
<string name="error_external_storage_not_ready">"external storage not ready"</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user