mirror of
https://github.com/M66B/FairEmail.git
synced 2025-01-02 13:14:39 +00:00
Chips: show key availability
This commit is contained in:
parent
dc37308af0
commit
5b6febf254
2 changed files with 53 additions and 4 deletions
|
@ -56,7 +56,11 @@ import java.io.InputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
|
||||||
|
import javax.mail.Address;
|
||||||
import javax.mail.internet.AddressException;
|
import javax.mail.internet.AddressException;
|
||||||
import javax.mail.internet.InternetAddress;
|
import javax.mail.internet.InternetAddress;
|
||||||
|
|
||||||
|
@ -66,6 +70,9 @@ public class EditTextMultiAutoComplete extends AppCompatMultiAutoCompleteTextVie
|
||||||
private int colorAccent;
|
private int colorAccent;
|
||||||
private ContextThemeWrapper ctx;
|
private ContextThemeWrapper ctx;
|
||||||
private Tokenizer tokenizer;
|
private Tokenizer tokenizer;
|
||||||
|
private Map<String, Boolean> encryption = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
private static ExecutorService executor = Helper.getBackgroundExecutor(1, "chips");
|
||||||
|
|
||||||
public EditTextMultiAutoComplete(@NonNull Context context) {
|
public EditTextMultiAutoComplete(@NonNull Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
|
@ -245,8 +252,8 @@ public class EditTextMultiAutoComplete extends AppCompatMultiAutoCompleteTextVie
|
||||||
int s = edit.getSpanStart(span);
|
int s = edit.getSpanStart(span);
|
||||||
int e = edit.getSpanEnd(span);
|
int e = edit.getSpanEnd(span);
|
||||||
if (s == start && e == i + 1) {
|
if (s == start && e == i + 1) {
|
||||||
found = true;
|
found = !span.needsUpdate();
|
||||||
if (!(focus && overlap(start, i, selStart, selEnd)))
|
if (found && !(focus && overlap(start, i, selStart, selEnd)))
|
||||||
tbd.remove(span);
|
tbd.remove(span);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -309,12 +316,40 @@ public class EditTextMultiAutoComplete extends AppCompatMultiAutoCompleteTextVie
|
||||||
}
|
}
|
||||||
cd.setText(text);
|
cd.setText(text);
|
||||||
cd.setChipBackgroundColor(ColorStateList.valueOf(colorAccent));
|
cd.setChipBackgroundColor(ColorStateList.valueOf(colorAccent));
|
||||||
cd.setMaxWidth(getWidth());
|
|
||||||
cd.setBounds(0, 0, cd.getIntrinsicWidth(), cd.getIntrinsicHeight());
|
|
||||||
|
|
||||||
ClipImageSpan is = new ClipImageSpan(cd);
|
ClipImageSpan is = new ClipImageSpan(cd);
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R)
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R)
|
||||||
is.setContentDescription(email);
|
is.setContentDescription(email);
|
||||||
|
|
||||||
|
Boolean has = encryption.get(email);
|
||||||
|
if (has == null) {
|
||||||
|
final List<Address> recipient = Arrays.asList(new Address[]{parsed[0]});
|
||||||
|
executor.submit(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
boolean has =
|
||||||
|
PgpHelper.hasPgpKey(context, recipient) ||
|
||||||
|
SmimeHelper.hasSmimeKey(context, recipient);
|
||||||
|
encryption.put(email, has);
|
||||||
|
if (has) {
|
||||||
|
is.invalidate();
|
||||||
|
post(update);
|
||||||
|
}
|
||||||
|
} catch (Throwable ex) {
|
||||||
|
Log.w(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else if (has) {
|
||||||
|
cd.setTextEndPadding(dp3);
|
||||||
|
cd.setCloseIcon(context.getDrawable(R.drawable.twotone_lock_24));
|
||||||
|
cd.setCloseIconVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
cd.setMaxWidth(getWidth());
|
||||||
|
cd.setBounds(0, 0, cd.getIntrinsicWidth(), cd.getIntrinsicHeight());
|
||||||
|
|
||||||
edit.setSpan(is, start, i + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
edit.setSpan(is, start, i + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||||
|
|
||||||
if (kar == ',' &&
|
if (kar == ',' &&
|
||||||
|
@ -346,8 +381,18 @@ public class EditTextMultiAutoComplete extends AppCompatMultiAutoCompleteTextVie
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class ClipImageSpan extends ImageSpan {
|
private static class ClipImageSpan extends ImageSpan {
|
||||||
|
private boolean update;
|
||||||
|
|
||||||
public ClipImageSpan(@NonNull Drawable drawable) {
|
public ClipImageSpan(@NonNull Drawable drawable) {
|
||||||
super(drawable, DynamicDrawableSpan.ALIGN_BOTTOM);
|
super(drawable, DynamicDrawableSpan.ALIGN_BOTTOM);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void invalidate() {
|
||||||
|
update = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean needsUpdate() {
|
||||||
|
return update;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -67,6 +67,10 @@ public class PgpHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static boolean hasPgpKey(Context context, List<Address> recipients) {
|
||||||
|
return hasPgpKey(context, recipients, CONNECT_TIMEOUT);
|
||||||
|
}
|
||||||
|
|
||||||
static boolean hasPgpKey(Context context, List<Address> recipients, long timeout) {
|
static boolean hasPgpKey(Context context, List<Address> recipients, long timeout) {
|
||||||
if (recipients == null || recipients.size() == 0)
|
if (recipients == null || recipients.size() == 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Reference in a new issue