Simplify and fix delete key dialog

This commit is contained in:
Dominik Schürmann 2014-04-11 19:52:59 +02:00
parent 45b450e78a
commit 305b8c1858
3 changed files with 8 additions and 49 deletions

View File

@ -28,15 +28,12 @@ import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRingData; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRingData;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
import org.sufficientlysecure.keychain.provider.KeychainDatabase;
import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.provider.ProviderHelper;
import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Log;
@ -49,11 +46,7 @@ public class DeleteKeyDialogFragment extends DialogFragment {
public static final int MESSAGE_OKAY = 1; public static final int MESSAGE_OKAY = 1;
public static final int MESSAGE_ERROR = 0; public static final int MESSAGE_ERROR = 0;
private boolean mIsSingleSelection = false;
private TextView mMainMessage; private TextView mMainMessage;
private CheckBox mCheckDeleteSecret;
private LinearLayout mDeleteSecretKeyView;
private View mInflateView; private View mInflateView;
private Messenger mMessenger; private Messenger mMessenger;
@ -61,14 +54,12 @@ public class DeleteKeyDialogFragment extends DialogFragment {
/** /**
* Creates new instance of this delete file dialog fragment * Creates new instance of this delete file dialog fragment
*/ */
public static DeleteKeyDialogFragment newInstance(Messenger messenger, public static DeleteKeyDialogFragment newInstance(Messenger messenger, long[] masterKeyIds) {
long[] masterKeyIds) {
DeleteKeyDialogFragment frag = new DeleteKeyDialogFragment(); DeleteKeyDialogFragment frag = new DeleteKeyDialogFragment();
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putParcelable(ARG_MESSENGER, messenger); args.putParcelable(ARG_MESSENGER, messenger);
args.putLongArray(ARG_DELETE_MASTER_KEY_IDS, masterKeyIds); args.putLongArray(ARG_DELETE_MASTER_KEY_IDS, masterKeyIds);
//We don't need the key type
frag.setArguments(args); frag.setArguments(args);
@ -85,39 +76,32 @@ public class DeleteKeyDialogFragment extends DialogFragment {
AlertDialog.Builder builder = new AlertDialog.Builder(activity); AlertDialog.Builder builder = new AlertDialog.Builder(activity);
//Setup custom View to display in AlertDialog // Setup custom View to display in AlertDialog
LayoutInflater inflater = activity.getLayoutInflater(); LayoutInflater inflater = activity.getLayoutInflater();
mInflateView = inflater.inflate(R.layout.view_key_delete_fragment, null); mInflateView = inflater.inflate(R.layout.view_key_delete_fragment, null);
builder.setView(mInflateView); builder.setView(mInflateView);
mDeleteSecretKeyView = (LinearLayout) mInflateView.findViewById(R.id.deleteSecretKeyView);
mMainMessage = (TextView) mInflateView.findViewById(R.id.mainMessage); mMainMessage = (TextView) mInflateView.findViewById(R.id.mainMessage);
mCheckDeleteSecret = (CheckBox) mInflateView.findViewById(R.id.checkDeleteSecret);
builder.setTitle(R.string.warning); builder.setTitle(R.string.warning);
// If only a single key has been selected // If only a single key has been selected
if (masterKeyIds.length == 1) { if (masterKeyIds.length == 1) {
mIsSingleSelection = true;
long masterKeyId = masterKeyIds[0]; long masterKeyId = masterKeyIds[0];
HashMap<String, Object> data = new ProviderHelper(activity).getUnifiedData(masterKeyId, new String[]{ HashMap<String, Object> data = new ProviderHelper(activity).getUnifiedData(masterKeyId, new String[]{
KeyRings.USER_ID, KeyRings.USER_ID,
KeyRings.HAS_SECRET KeyRings.HAS_SECRET
}, new int[] { ProviderHelper.FIELD_TYPE_STRING, ProviderHelper.FIELD_TYPE_INTEGER }); }, new int[]{ProviderHelper.FIELD_TYPE_STRING, ProviderHelper.FIELD_TYPE_INTEGER});
String userId = (String) data.get(KeyRings.USER_ID); String userId = (String) data.get(KeyRings.USER_ID);
boolean hasSecret = ((Long) data.get(KeyRings.HAS_SECRET)) == 1; boolean hasSecret = ((Long) data.get(KeyRings.HAS_SECRET)) == 1;
// Hide the Checkbox and TextView since this is a single selection,user will be notified through message
mDeleteSecretKeyView.setVisibility(View.GONE);
// Set message depending on which key it is. // Set message depending on which key it is.
mMainMessage.setText(getString( mMainMessage.setText(getString(
hasSecret ? R.string.secret_key_deletion_confirmation hasSecret ? R.string.secret_key_deletion_confirmation
: R.string.public_key_deletetion_confirmation, : R.string.public_key_deletetion_confirmation,
userId)); userId));
} else { } else {
mDeleteSecretKeyView.setVisibility(View.VISIBLE);
mMainMessage.setText(R.string.key_deletion_confirmation_multi); mMainMessage.setText(R.string.key_deletion_confirmation_multi);
} }
@ -127,10 +111,10 @@ public class DeleteKeyDialogFragment extends DialogFragment {
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
boolean success = false; boolean success = false;
for(long masterKeyId : masterKeyIds) { for (long masterKeyId : masterKeyIds) {
int count = activity.getContentResolver().delete( int count = activity.getContentResolver().delete(
KeyRingData.buildPublicKeyRingUri(Long.toString(masterKeyId)), null, null KeyRingData.buildPublicKeyRingUri(Long.toString(masterKeyId)), null, null
); );
success = count > 0; success = count > 0;
} }
if (success) { if (success) {

View File

@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:orientation="vertical"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -12,27 +11,4 @@
android:layout_margin="4dp" android:layout_margin="4dp"
android:textAppearance="?android:textAppearanceMedium" /> android:textAppearance="?android:textAppearanceMedium" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="1"
android:id="@+id/deleteSecretKeyView">
<CheckBox
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.1"
android:layout_margin="4dp"
android:id="@+id/checkDeleteSecret" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:textAppearance="?android:textAppearanceMedium"
android:layout_weight="0.9"
android:text="@string/secret_key_delete_text" />
</LinearLayout>
</LinearLayout> </LinearLayout>

View File

@ -220,12 +220,11 @@
<string name="specify_file_to_export_to">Please specify which file to export to.\nWARNING: File will be overwritten if it exists.</string> <string name="specify_file_to_export_to">Please specify which file to export to.\nWARNING: File will be overwritten if it exists.</string>
<string name="specify_file_to_export_secret_keys_to">Please specify which file to export to.\nWARNING: You are about to export SECRET keys.\nWARNING: File will be overwritten if it exists.</string> <string name="specify_file_to_export_secret_keys_to">Please specify which file to export to.\nWARNING: You are about to export SECRET keys.\nWARNING: File will be overwritten if it exists.</string>
<string name="key_deletion_confirmation">Do you really want to delete the key \'%s\'?\nYou can\'t undo this!</string> <string name="key_deletion_confirmation">Do you really want to delete the key \'%s\'?\nYou can\'t undo this!</string>
<string name="key_deletion_confirmation_multi">Do you really want to delete all selected keys?\nYou can\'t undo this!</string> <string name="key_deletion_confirmation_multi">Do you really want to delete all selected keys (including secret keys)?\nYou can\'t undo this!</string>
<string name="secret_key_deletion_confirmation">Do you really want to delete the SECRET key \'%s\'?\nYou can\'t undo this!</string> <string name="secret_key_deletion_confirmation">Do you really want to delete the SECRET key \'%s\'?\nYou can\'t undo this!</string>
<string name="ask_save_changed_key">You have made changes to the keyring, would you like to save it?</string> <string name="ask_save_changed_key">You have made changes to the keyring, would you like to save it?</string>
<string name="ask_empty_id_ok">"You have added an empty user ID, are you sure you want to continue?"</string> <string name="ask_empty_id_ok">"You have added an empty user ID, are you sure you want to continue?"</string>
<string name="public_key_deletetion_confirmation">Do you really want to delete the PUBLIC key \'%s\'?\nYou can\'t undo this!</string> <string name="public_key_deletetion_confirmation">Do you really want to delete the public key \'%s\'?\nYou can\'t undo this!</string>
<string name="secret_key_delete_text">Delete Secret Keys ?</string>
<string name="also_export_secret_keys">Also export secret keys?</string> <string name="also_export_secret_keys">Also export secret keys?</string>
<plurals name="keys_added_and_updated_1"> <plurals name="keys_added_and_updated_1">