Move update of crypto settings to submit button and add Cancel

This commit is contained in:
Philip Whitehouse 2016-10-07 03:23:58 +01:00
parent dbb6cc4d88
commit 5271977f76
2 changed files with 22 additions and 12 deletions

View file

@ -53,9 +53,16 @@ public class CryptoSettingsDialog extends DialogFragment implements CryptoStatus
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setView(view);
builder.setNegativeButton(R.string.crypto_settings_cancel, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int i) {
dialog.dismiss();
}
});
builder.setPositiveButton(R.string.crypto_settings_ok, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
changeCryptoSettings();
dialog.dismiss();
}
});
@ -63,6 +70,20 @@ public class CryptoSettingsDialog extends DialogFragment implements CryptoStatus
return builder.create();
}
private void changeCryptoSettings() {
Activity activity = getActivity();
if (activity == null) {
// is this supposed to happen?
return;
}
boolean activityIsCryptoModeChangedListener = activity instanceof OnCryptoModeChangedListener;
if (!activityIsCryptoModeChangedListener) {
throw new AssertionError("This dialog must be called by an OnCryptoModeChangedListener!");
}
((OnCryptoModeChangedListener) activity).onCryptoModeChanged(currentMode);
}
void updateView(boolean animate) {
switch (currentMode) {
case DISABLE:
@ -103,18 +124,6 @@ public class CryptoSettingsDialog extends DialogFragment implements CryptoStatus
currentMode = CryptoMode.PRIVATE;
}
updateView(true);
Activity activity = getActivity();
if (activity == null) {
// is this supposed to happen?
return;
}
boolean activityIsCryptoModeChangedListener = activity instanceof OnCryptoModeChangedListener;
if (!activityIsCryptoModeChangedListener) {
throw new AssertionError("This dialog must be called by an OnCryptoModeChangedListener!");
}
((OnCryptoModeChangedListener) activity).onCryptoModeChanged(currentMode);
}
public interface OnCryptoModeChangedListener {

View file

@ -1139,6 +1139,7 @@ Please submit bug reports, contribute new features and ask questions at
<string name="crypto_download_complete_message_to_decrypt">Click \'Download complete message\' to allow decryption.</string>
<string name="preview_encrypted">*Encrypted*</string>
<string name="add_from_contacts">Add from Contacts</string>
<string name="crypto_settings_cancel">Cancel</string>
<string name="crypto_settings_ok">Proceed</string>
<string name="recipient_cc">Cc</string>
<string name="recipient_bcc">Bcc</string>