From 044d94c6b5d75b57476707c7f67a08583305d7c0 Mon Sep 17 00:00:00 2001 From: M66B Date: Sat, 16 Mar 2019 16:58:57 +0000 Subject: [PATCH] Local contacts improvements --- .../eu/faircode/email/AdapterContact.java | 22 +++++++++++-------- .../java/eu/faircode/email/DaoContact.java | 20 ++++++----------- .../java/eu/faircode/email/EntityContact.java | 6 ++++- app/src/main/res/layout/fragment_contacts.xml | 13 ++++++++++- app/src/main/res/values/strings.xml | 1 + 5 files changed, 38 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/AdapterContact.java b/app/src/main/java/eu/faircode/email/AdapterContact.java index 68606fb9aa..da2bf5e8c6 100644 --- a/app/src/main/java/eu/faircode/email/AdapterContact.java +++ b/app/src/main/java/eu/faircode/email/AdapterContact.java @@ -78,18 +78,16 @@ public class AdapterContact extends RecyclerView.Adapter getContacts(); @Query("SELECT * FROM contact" + - " ORDER BY" + - " CASE" + - " WHEN favorite = 1 THEN 0" + - " WHEN favorite = 2 THEN 2" + - " ELSE 1 END" + - ", times_contacted DESC" + - ", last_contacted DESC") + " ORDER BY times_contacted DESC, last_contacted DESC") LiveData> liveContacts(); @Query("SELECT * FROM contact" + - " WHERE favorite <> 2" + - " ORDER BY favorite DESC, times_contacted DESC, last_contacted DESC" + + " WHERE favorite <> " + EntityContact.STATE_IGNORE + + " ORDER BY" + + " CASE WHEN favorite = " + EntityContact.STATE_FAVORITE + " THEN 0 ELSE 1 END" + + ", times_contacted DESC" + + ", last_contacted DESC" + " LIMIT :count") List getFrequentlyContacted(int count); @@ -76,13 +73,10 @@ public interface DaoContact { @Query("UPDATE contact SET favorite = :state WHERE id = :id") int setContactState(long id, int state); - @Query("DELETE FROM contact WHERE id= :id") - int deleteContact(long id); - @Query("DELETE FROM contact" + " WHERE last_contacted IS NOT NULL" + " AND last_contacted < :before" + - " AND NOT favorite") + " AND favorite <> " + EntityContact.STATE_FAVORITE) int deleteContacts(long before); @Query("DELETE FROM contact") diff --git a/app/src/main/java/eu/faircode/email/EntityContact.java b/app/src/main/java/eu/faircode/email/EntityContact.java index bebeaaf200..79d05932c8 100644 --- a/app/src/main/java/eu/faircode/email/EntityContact.java +++ b/app/src/main/java/eu/faircode/email/EntityContact.java @@ -52,6 +52,10 @@ public class EntityContact implements Serializable { static final int TYPE_TO = 0; static final int TYPE_FROM = 1; + static final int STATE_DEFAULT = 0; + static final int STATE_FAVORITE = 1; + static final int STATE_IGNORE = 2; + @PrimaryKey(autoGenerate = true) public Long id; @NonNull @@ -66,7 +70,7 @@ public class EntityContact implements Serializable { public Long last_contacted; @NonNull @ColumnInfo(name = "favorite") - public Integer state = 0; + public Integer state = STATE_DEFAULT; public JSONObject toJSON() throws JSONException { JSONObject json = new JSONObject(); diff --git a/app/src/main/res/layout/fragment_contacts.xml b/app/src/main/res/layout/fragment_contacts.xml index b90c5ae6bc..3d64ed7ab1 100644 --- a/app/src/main/res/layout/fragment_contacts.xml +++ b/app/src/main/res/layout/fragment_contacts.xml @@ -6,6 +6,17 @@ android:layout_height="match_parent" tools:context=".ActivityView"> + + + app:layout_constraintTop_toBottomOf="@+id/tvHintActions" /> Downloading messages can take some time, depending on the speed of the provider, internet connection and device and on the number of messages. While downloading messages the app might respond slower. Image link Tracking image %1$sx%2$s + Long press a contact to never consider it as a favorite Open link Show organization