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.graphics.Typeface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
@ -35,6 +36,7 @@ import androidx.recyclerview.widget.RecyclerView;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
public class AdapterCertificate extends RecyclerView.Adapter<AdapterCertificate.ViewHolder> {
private ICertificate intf;
@ -42,6 +44,7 @@ public class AdapterCertificate extends RecyclerView.Adapter<AdapterCertificate.
private LifecycleOwner owner;
private LayoutInflater inflater;
private String email;
private List<EntityCertificate> items = new ArrayList<>();
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) {
tvEmail.setText(certificate.email);
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);
}
public void set(@NonNull List<EntityCertificate> certificates) {
Log.i("Set certificates=" + certificates.size());
public void set(String email, @NonNull List<EntityCertificate> certificates) {
Log.i("Set email=" + email + " certificates=" + certificates.size());
DiffUtil.DiffResult diff = DiffUtil.calculateDiff(new DiffCallback(items, certificates), false);
items = certificates;
this.email = email;
this.items = certificates;
diff.dispatchUpdatesTo(new ListUpdateCallback() {
@Override

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

@ -3999,12 +3999,12 @@ public class FragmentCompose extends FragmentBase {
pbWait.setVisibility(View.VISIBLE);
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
public void onChanged(List<EntityCertificate> certificates) {
pbWait.setVisibility(View.GONE);
rvCertificate.setVisibility(View.VISIBLE);
adapter.set(certificates);
adapter.set(email, certificates);
}
});

Loading…
Cancel
Save