Local contacts improvements

pull/153/head
M66B 7 years ago
parent 936a0dc9bc
commit 044d94c6b5

@ -78,18 +78,16 @@ public class AdapterContact extends RecyclerView.Adapter<AdapterContact.ViewHold
private void wire() { private void wire() {
view.setOnClickListener(this); view.setOnClickListener(this);
if (BuildConfig.DEBUG) view.setOnLongClickListener(this);
view.setOnLongClickListener(this);
} }
private void unwire() { private void unwire() {
view.setOnClickListener(null); view.setOnClickListener(null);
if (BuildConfig.DEBUG) view.setOnLongClickListener(null);
view.setOnLongClickListener(null);
} }
private void bindTo(EntityContact contact) { private void bindTo(EntityContact contact) {
view.setAlpha(contact.state == 2 ? Helper.LOW_LIGHT : 1.0f); view.setAlpha(contact.state == EntityContact.STATE_IGNORE ? Helper.LOW_LIGHT : 1.0f);
if (contact.type == EntityContact.TYPE_FROM) if (contact.type == EntityContact.TYPE_FROM)
ivType.setImageResource(R.drawable.baseline_call_received_24); ivType.setImageResource(R.drawable.baseline_call_received_24);
@ -109,8 +107,10 @@ public class AdapterContact extends RecyclerView.Adapter<AdapterContact.ViewHold
tvLast.setText(contact.last_contacted == null ? null tvLast.setText(contact.last_contacted == null ? null
: DateUtils.getRelativeTimeSpanString(context, contact.last_contacted)); : DateUtils.getRelativeTimeSpanString(context, contact.last_contacted));
ivFavorite.setImageResource(contact.state == 1 ? R.drawable.baseline_star_24 : R.drawable.baseline_star_border_24); ivFavorite.setImageResource(contact.state == EntityContact.STATE_FAVORITE
ivFavorite.setImageTintList(ColorStateList.valueOf(contact.state == 1 ? colorAccent : textColorSecondary)); ? R.drawable.baseline_star_24 : R.drawable.baseline_star_border_24);
ivFavorite.setImageTintList(ColorStateList.valueOf(
contact.state == EntityContact.STATE_FAVORITE ? colorAccent : textColorSecondary));
view.requestLayout(); view.requestLayout();
} }
@ -122,7 +122,11 @@ public class AdapterContact extends RecyclerView.Adapter<AdapterContact.ViewHold
return; return;
EntityContact contact = items.get(pos); EntityContact contact = items.get(pos);
contact.state = ++contact.state % 3; if (contact.state == EntityContact.STATE_DEFAULT)
contact.state = EntityContact.STATE_FAVORITE;
else
contact.state = EntityContact.STATE_DEFAULT;
notifyItemChanged(pos); notifyItemChanged(pos);
Bundle args = new Bundle(); Bundle args = new Bundle();
@ -170,7 +174,7 @@ public class AdapterContact extends RecyclerView.Adapter<AdapterContact.ViewHold
long id = args.getLong("id"); long id = args.getLong("id");
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
db.contact().deleteContact(id); db.contact().setContactState(id, EntityContact.STATE_IGNORE);
return null; return null;
} }

@ -35,18 +35,15 @@ public interface DaoContact {
List<EntityContact> getContacts(); List<EntityContact> getContacts();
@Query("SELECT * FROM contact" + @Query("SELECT * FROM contact" +
" ORDER BY" + " ORDER BY times_contacted DESC, last_contacted DESC")
" CASE" +
" WHEN favorite = 1 THEN 0" +
" WHEN favorite = 2 THEN 2" +
" ELSE 1 END" +
", times_contacted DESC" +
", last_contacted DESC")
LiveData<List<EntityContact>> liveContacts(); LiveData<List<EntityContact>> liveContacts();
@Query("SELECT * FROM contact" + @Query("SELECT * FROM contact" +
" WHERE favorite <> 2" + " WHERE favorite <> " + EntityContact.STATE_IGNORE +
" ORDER BY favorite DESC, times_contacted DESC, last_contacted DESC" + " ORDER BY" +
" CASE WHEN favorite = " + EntityContact.STATE_FAVORITE + " THEN 0 ELSE 1 END" +
", times_contacted DESC" +
", last_contacted DESC" +
" LIMIT :count") " LIMIT :count")
List<EntityContact> getFrequentlyContacted(int count); List<EntityContact> getFrequentlyContacted(int count);
@ -76,13 +73,10 @@ public interface DaoContact {
@Query("UPDATE contact SET favorite = :state WHERE id = :id") @Query("UPDATE contact SET favorite = :state WHERE id = :id")
int setContactState(long id, int state); int setContactState(long id, int state);
@Query("DELETE FROM contact WHERE id= :id")
int deleteContact(long id);
@Query("DELETE FROM contact" + @Query("DELETE FROM contact" +
" WHERE last_contacted IS NOT NULL" + " WHERE last_contacted IS NOT NULL" +
" AND last_contacted < :before" + " AND last_contacted < :before" +
" AND NOT favorite") " AND favorite <> " + EntityContact.STATE_FAVORITE)
int deleteContacts(long before); int deleteContacts(long before);
@Query("DELETE FROM contact") @Query("DELETE FROM contact")

@ -52,6 +52,10 @@ public class EntityContact implements Serializable {
static final int TYPE_TO = 0; static final int TYPE_TO = 0;
static final int TYPE_FROM = 1; 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) @PrimaryKey(autoGenerate = true)
public Long id; public Long id;
@NonNull @NonNull
@ -66,7 +70,7 @@ public class EntityContact implements Serializable {
public Long last_contacted; public Long last_contacted;
@NonNull @NonNull
@ColumnInfo(name = "favorite") @ColumnInfo(name = "favorite")
public Integer state = 0; public Integer state = STATE_DEFAULT;
public JSONObject toJSON() throws JSONException { public JSONObject toJSON() throws JSONException {
JSONObject json = new JSONObject(); JSONObject json = new JSONObject();

@ -6,6 +6,17 @@
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context=".ActivityView"> tools:context=".ActivityView">
<TextView
android:id="@+id/tvHintActions"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="6dp"
android:text="@string/title_hint_ignore_contact"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="?android:attr/textColorPrimary"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/rvContacts" android:id="@+id/rvContacts"
android:layout_width="0dp" android:layout_width="0dp"
@ -15,7 +26,7 @@
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toBottomOf="@+id/tvHintActions" />
<eu.faircode.email.ContentLoadingProgressBar <eu.faircode.email.ContentLoadingProgressBar
android:id="@+id/pbWait" android:id="@+id/pbWait"

@ -529,6 +529,7 @@
<string name="title_hint_sync">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.</string> <string name="title_hint_sync">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.</string>
<string name="title_hint_image_link">Image link</string> <string name="title_hint_image_link">Image link</string>
<string name="title_hint_tracking_image">Tracking image %1$sx%2$s</string> <string name="title_hint_tracking_image">Tracking image %1$sx%2$s</string>
<string name="title_hint_ignore_contact">Long press a contact to never consider it as a favorite</string>
<string name="title_open_link">Open link</string> <string name="title_open_link">Open link</string>
<string name="title_show_organization">Show organization</string> <string name="title_show_organization">Show organization</string>

Loading…
Cancel
Save