Experiment: identity/linked contact

This commit is contained in:
M66B
2023-03-25 15:46:56 +01:00
parent 0d883b50c8
commit fed1994b23
8 changed files with 3181 additions and 2 deletions

View File

@@ -31,6 +31,7 @@ import android.graphics.Color;
import android.graphics.Paint;
import android.net.Uri;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
@@ -120,6 +121,8 @@ public class FragmentIdentity extends FragmentBase {
private EditText etCc;
private EditText etBcc;
private EditText etInternal;
private Button btnUri;
private TextView tvUri;
private CheckBox cbSignDefault;
private CheckBox cbEncryptDefault;
private CheckBox cbUnicode;
@@ -153,6 +156,7 @@ public class FragmentIdentity extends FragmentBase {
private static final int REQUEST_SAVE = 2;
private static final int REQUEST_DELETE = 3;
private static final int REQUEST_SIGNATURE = 4;
private static final int REQUEST_URI = 5;
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -220,6 +224,8 @@ public class FragmentIdentity extends FragmentBase {
etCc = view.findViewById(R.id.etCc);
etBcc = view.findViewById(R.id.etBcc);
etInternal = view.findViewById(R.id.etInternal);
btnUri = view.findViewById(R.id.btnUri);
tvUri = view.findViewById(R.id.tvUri);
cbSignDefault = view.findViewById(R.id.cbSignDefault);
cbEncryptDefault = view.findViewById(R.id.cbEncryptDefault);
cbUnicode = view.findViewById(R.id.cbUnicode);
@@ -481,6 +487,15 @@ public class FragmentIdentity extends FragmentBase {
}
});
btnUri.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent pick = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
pick.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivityForResult(Helper.getChooser(getContext(), pick), REQUEST_URI);
}
});
cbEncryptDefault.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
@@ -527,6 +542,10 @@ public class FragmentIdentity extends FragmentBase {
cbInsecure.setVisibility(View.GONE);
btnAdvanced.setVisibility(View.GONE);
if (!BuildConfig.DEBUG) {
Helper.hide(btnUri);
Helper.hide(tvUri);
}
etEhlo.setHint(EmailService.getDefaultEhlo());
@@ -710,6 +729,7 @@ public class FragmentIdentity extends FragmentBase {
args.putString("cc", etCc.getText().toString().trim());
args.putString("bcc", etBcc.getText().toString().trim());
args.putString("internal", etInternal.getText().toString().replaceAll(" ", ""));
args.putString("uri", tvUri.getText().toString());
args.putBoolean("sign_default", cbSignDefault.isChecked());
args.putBoolean("encrypt_default", cbEncryptDefault.isChecked());
args.putBoolean("unicode", cbUnicode.isChecked());
@@ -794,6 +814,7 @@ public class FragmentIdentity extends FragmentBase {
String cc = args.getString("cc");
String bcc = args.getString("bcc");
String internal = args.getString("internal");
String uri = args.getString("uri");
boolean sign_default = args.getBoolean("sign_default");
boolean encrypt_default = args.getBoolean("encrypt_default");
boolean unicode = args.getBoolean("unicode");
@@ -856,6 +877,9 @@ public class FragmentIdentity extends FragmentBase {
if (TextUtils.isEmpty(internal))
internal = null;
if (TextUtils.isEmpty(uri))
uri = null;
if (TextUtils.isEmpty(display))
display = null;
@@ -949,6 +973,8 @@ public class FragmentIdentity extends FragmentBase {
return true;
if (!Objects.equals(identity.internal, internal))
return true;
if (!Objects.equals(identity.uri, uri))
return true;
if (!Objects.equals(identity.sign_default, sign_default))
return true;
if (!Objects.equals(identity.encrypt_default, encrypt_default))
@@ -1052,6 +1078,7 @@ public class FragmentIdentity extends FragmentBase {
identity.cc = cc;
identity.bcc = bcc;
identity.internal = internal;
identity.uri = uri;
identity.sign_default = sign_default;
identity.encrypt_default = encrypt_default;
identity.unicode = unicode;
@@ -1238,6 +1265,7 @@ public class FragmentIdentity extends FragmentBase {
etCc.setText(identity == null ? null : identity.cc);
etBcc.setText(identity == null ? null : identity.bcc);
etInternal.setText(identity == null ? null : identity.internal);
tvUri.setText(identity == null ? null : identity.uri);
cbSignDefault.setChecked(identity != null && identity.sign_default);
cbEncryptDefault.setChecked(identity != null && identity.encrypt_default);
cbUnicode.setChecked(identity != null && identity.unicode);
@@ -1444,6 +1472,9 @@ public class FragmentIdentity extends FragmentBase {
if (resultCode == RESULT_OK && data != null)
onHtml(data.getExtras());
break;
case REQUEST_URI:
onPickUri(resultCode == RESULT_OK ? data : null);
break;
}
} catch (Throwable ex) {
Log.e(ex);
@@ -1488,4 +1519,9 @@ public class FragmentIdentity extends FragmentBase {
private void onHtml(Bundle args) {
signature = args.getString("html");
}
private void onPickUri(Intent intent) {
Uri uri = (intent == null ? null : intent.getData());
tvUri.setText(uri == null ? null : uri.toString());
}
}