Sort/highlight matching public keys

pull/168/head
M66B 5 years ago
parent a26a462d5f
commit a34698622a

@ -20,6 +20,7 @@ package eu.faircode.email;
*/ */
import android.content.Context; import android.content.Context;
import android.graphics.Typeface;
import android.os.Bundle; import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -35,6 +36,7 @@ import androidx.recyclerview.widget.RecyclerView;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects;
public class AdapterCertificate extends RecyclerView.Adapter<AdapterCertificate.ViewHolder> { public class AdapterCertificate extends RecyclerView.Adapter<AdapterCertificate.ViewHolder> {
private ICertificate intf; private ICertificate intf;
@ -42,6 +44,7 @@ public class AdapterCertificate extends RecyclerView.Adapter<AdapterCertificate.
private LifecycleOwner owner; private LifecycleOwner owner;
private LayoutInflater inflater; private LayoutInflater inflater;
private String email;
private List<EntityCertificate> items = new ArrayList<>(); private List<EntityCertificate> items = new ArrayList<>();
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener { public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
@ -110,6 +113,10 @@ public class AdapterCertificate extends RecyclerView.Adapter<AdapterCertificate.
private void bindTo(EntityCertificate certificate) { private void bindTo(EntityCertificate certificate) {
tvEmail.setText(certificate.email); tvEmail.setText(certificate.email);
tvSubject.setText(certificate.subject); tvSubject.setText(certificate.subject);
boolean preferred = Objects.equals(email, certificate.email);
tvEmail.setTypeface(preferred ? Typeface.DEFAULT_BOLD : Typeface.DEFAULT);
tvSubject.setTypeface(preferred ? Typeface.DEFAULT_BOLD : Typeface.DEFAULT);
} }
} }
@ -122,12 +129,13 @@ public class AdapterCertificate extends RecyclerView.Adapter<AdapterCertificate.
setHasStableIds(true); setHasStableIds(true);
} }
public void set(@NonNull List<EntityCertificate> certificates) { public void set(String email, @NonNull List<EntityCertificate> certificates) {
Log.i("Set certificates=" + certificates.size()); Log.i("Set email=" + email + " certificates=" + certificates.size());
DiffUtil.DiffResult diff = DiffUtil.calculateDiff(new DiffCallback(items, certificates), false); DiffUtil.DiffResult diff = DiffUtil.calculateDiff(new DiffCallback(items, certificates), false);
items = certificates; this.email = email;
this.items = certificates;
diff.dispatchUpdatesTo(new ListUpdateCallback() { diff.dispatchUpdatesTo(new ListUpdateCallback() {
@Override @Override

@ -29,8 +29,8 @@ import java.util.List;
@Dao @Dao
public interface DaoCertificate { public interface DaoCertificate {
@Query("SELECT * FROM certificate" + @Query("SELECT * FROM certificate" +
" ORDER BY email") " ORDER BY (email = :email) DESC, email, subject")
LiveData<List<EntityCertificate>> liveCertificates(); LiveData<List<EntityCertificate>> liveCertificates(String email);
@Query("SELECT * FROM certificate" + @Query("SELECT * FROM certificate" +
" WHERE id = :id") " WHERE id = :id")

@ -3999,12 +3999,12 @@ public class FragmentCompose extends FragmentBase {
pbWait.setVisibility(View.VISIBLE); pbWait.setVisibility(View.VISIBLE);
DB db = DB.getInstance(getContext()); DB db = DB.getInstance(getContext());
db.certificate().liveCertificates().observe(getViewLifecycleOwner(), new Observer<List<EntityCertificate>>() { db.certificate().liveCertificates(email).observe(getViewLifecycleOwner(), new Observer<List<EntityCertificate>>() {
@Override @Override
public void onChanged(List<EntityCertificate> certificates) { public void onChanged(List<EntityCertificate> certificates) {
pbWait.setVisibility(View.GONE); pbWait.setVisibility(View.GONE);
rvCertificate.setVisibility(View.VISIBLE); rvCertificate.setVisibility(View.VISIBLE);
adapter.set(certificates); adapter.set(email, certificates);
} }
}); });

Loading…
Cancel
Save