Refactoring

This commit is contained in:
M66B 2021-10-24 20:44:52 +02:00
parent 7a0bd58bc3
commit 86e81ee738
1 changed files with 47 additions and 34 deletions

View File

@ -5753,42 +5753,10 @@ public class FragmentCompose extends FragmentBase {
if (draft.ui_encrypt == null || if (draft.ui_encrypt == null ||
EntityMessage.ENCRYPT_NONE.equals(draft.ui_encrypt)) { EntityMessage.ENCRYPT_NONE.equals(draft.ui_encrypt)) {
if (recipients.size() > 0) { args.putBoolean("remind_pgp", hasPgpKey(context, recipients));
if (pgpService != null && pgpService.isBound()) { args.putBoolean("remind_smime", hasSmimeKey(context, recipients));
String[] userIds = new String[recipients.size()];
for (int i = 0; i < recipients.size(); i++) {
InternetAddress recipient = (InternetAddress) recipients.get(i);
userIds[i] = recipient.getAddress();
} }
Intent intent = new Intent(OpenPgpApi.ACTION_GET_KEY_IDS);
intent.putExtra(OpenPgpApi.EXTRA_USER_IDS, userIds);
try {
OpenPgpApi api = new OpenPgpApi(context, pgpService.getService());
Intent result = api.executeApi(intent, (InputStream) null, (OutputStream) null);
int resultCode = result.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR);
if (resultCode == OpenPgpApi.RESULT_CODE_SUCCESS) {
long[] keyIds = result.getLongArrayExtra(OpenPgpApi.EXTRA_KEY_IDS);
args.putBoolean("remind_pgp", keyIds.length > 0);
}
} catch (Throwable ex) {
Log.w(ex);
}
}
for (Address address : recipients) {
String email = ((InternetAddress) address).getAddress();
List<EntityCertificate> certs = db.certificate().getCertificateByEmail(email);
if (certs != null && certs.size() > 0) {
args.putBoolean("remind_smime", true);
break;
}
}
}
}
if (TextUtils.isEmpty(draft.subject)) if (TextUtils.isEmpty(draft.subject))
args.putBoolean("remind_subject", true); args.putBoolean("remind_subject", true);
@ -6418,6 +6386,51 @@ public class FragmentCompose extends FragmentBase {
return -1; return -1;
} }
private boolean hasPgpKey(Context context, List<Address> recipients) {
if (pgpService == null || !pgpService.isBound())
return false;
if (recipients == null || recipients.size() == 0)
return false;
String[] userIds = new String[recipients.size()];
for (int i = 0; i < recipients.size(); i++) {
InternetAddress recipient = (InternetAddress) recipients.get(i);
userIds[i] = recipient.getAddress();
}
Intent intent = new Intent(OpenPgpApi.ACTION_GET_KEY_IDS);
intent.putExtra(OpenPgpApi.EXTRA_USER_IDS, userIds);
try {
OpenPgpApi api = new OpenPgpApi(context, pgpService.getService());
Intent result = api.executeApi(intent, (InputStream) null, (OutputStream) null);
int resultCode = result.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR);
if (resultCode == OpenPgpApi.RESULT_CODE_SUCCESS) {
long[] keyIds = result.getLongArrayExtra(OpenPgpApi.EXTRA_KEY_IDS);
return (keyIds.length > 0);
}
} catch (Throwable ex) {
Log.w(ex);
}
return false;
}
private boolean hasSmimeKey(Context context, List<Address> recipients) {
if (recipients == null || recipients.size() == 0)
return false;
DB db = DB.getInstance(context);
for (Address address : recipients) {
String email = ((InternetAddress) address).getAddress();
List<EntityCertificate> certs = db.certificate().getCertificateByEmail(email);
if (certs != null && certs.size() > 0)
return true;
}
return false;
}
private AdapterView.OnItemSelectedListener identitySelected = new AdapterView.OnItemSelectedListener() { private AdapterView.OnItemSelectedListener identitySelected = new AdapterView.OnItemSelectedListener() {
@Override @Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {