Local contacts improvements

This commit is contained in:
M66B 2019-03-16 16:58:57 +00:00
parent 936a0dc9bc
commit 044d94c6b5
5 changed files with 38 additions and 24 deletions

View File

@ -78,18 +78,16 @@ public class AdapterContact extends RecyclerView.Adapter<AdapterContact.ViewHold
private void wire() {
view.setOnClickListener(this);
if (BuildConfig.DEBUG)
view.setOnLongClickListener(this);
view.setOnLongClickListener(this);
}
private void unwire() {
view.setOnClickListener(null);
if (BuildConfig.DEBUG)
view.setOnLongClickListener(null);
view.setOnLongClickListener(null);
}
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)
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
: DateUtils.getRelativeTimeSpanString(context, contact.last_contacted));
ivFavorite.setImageResource(contact.state == 1 ? R.drawable.baseline_star_24 : R.drawable.baseline_star_border_24);
ivFavorite.setImageTintList(ColorStateList.valueOf(contact.state == 1 ? colorAccent : textColorSecondary));
ivFavorite.setImageResource(contact.state == EntityContact.STATE_FAVORITE
? R.drawable.baseline_star_24 : R.drawable.baseline_star_border_24);
ivFavorite.setImageTintList(ColorStateList.valueOf(
contact.state == EntityContact.STATE_FAVORITE ? colorAccent : textColorSecondary));
view.requestLayout();
}
@ -122,7 +122,11 @@ public class AdapterContact extends RecyclerView.Adapter<AdapterContact.ViewHold
return;
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);
Bundle args = new Bundle();
@ -170,7 +174,7 @@ public class AdapterContact extends RecyclerView.Adapter<AdapterContact.ViewHold
long id = args.getLong("id");
DB db = DB.getInstance(context);
db.contact().deleteContact(id);
db.contact().setContactState(id, EntityContact.STATE_IGNORE);
return null;
}

View File

@ -35,18 +35,15 @@ public interface DaoContact {
List<EntityContact> 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<List<EntityContact>> 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<EntityContact> 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")

View File

@ -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();

View File

@ -6,6 +6,17 @@
android:layout_height="match_parent"
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
android:id="@+id/rvContacts"
android:layout_width="0dp"
@ -15,7 +26,7 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintTop_toBottomOf="@+id/tvHintActions" />
<eu.faircode.email.ContentLoadingProgressBar
android:id="@+id/pbWait"

View File

@ -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_image_link">Image link</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_show_organization">Show organization</string>