|
|
@ -49,13 +49,12 @@ public class AdapterContact extends RecyclerView.Adapter<AdapterContact.ViewHold
|
|
|
|
private int colorAccent;
|
|
|
|
private int colorAccent;
|
|
|
|
private int textColorSecondary;
|
|
|
|
private int textColorSecondary;
|
|
|
|
|
|
|
|
|
|
|
|
private List<EntityContact> all = new ArrayList<>();
|
|
|
|
private List<EntityContact> items = new ArrayList<>();
|
|
|
|
private List<EntityContact> filtered = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static NumberFormat nf = NumberFormat.getNumberInstance();
|
|
|
|
private static NumberFormat nf = NumberFormat.getNumberInstance();
|
|
|
|
|
|
|
|
|
|
|
|
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
|
|
|
|
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
|
|
|
|
private View itemView;
|
|
|
|
private View view;
|
|
|
|
private ImageView ivType;
|
|
|
|
private ImageView ivType;
|
|
|
|
private ImageView ivAvatar;
|
|
|
|
private ImageView ivAvatar;
|
|
|
|
private TextView tvName;
|
|
|
|
private TextView tvName;
|
|
|
@ -67,7 +66,7 @@ public class AdapterContact extends RecyclerView.Adapter<AdapterContact.ViewHold
|
|
|
|
ViewHolder(View itemView) {
|
|
|
|
ViewHolder(View itemView) {
|
|
|
|
super(itemView);
|
|
|
|
super(itemView);
|
|
|
|
|
|
|
|
|
|
|
|
this.itemView = itemView;
|
|
|
|
view = itemView.findViewById(R.id.clItem);
|
|
|
|
ivType = itemView.findViewById(R.id.ivType);
|
|
|
|
ivType = itemView.findViewById(R.id.ivType);
|
|
|
|
ivAvatar = itemView.findViewById(R.id.ivAvatar);
|
|
|
|
ivAvatar = itemView.findViewById(R.id.ivAvatar);
|
|
|
|
tvName = itemView.findViewById(R.id.tvName);
|
|
|
|
tvName = itemView.findViewById(R.id.tvName);
|
|
|
@ -78,16 +77,18 @@ public class AdapterContact extends RecyclerView.Adapter<AdapterContact.ViewHold
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void wire() {
|
|
|
|
private void wire() {
|
|
|
|
itemView.setOnClickListener(this);
|
|
|
|
view.setOnClickListener(this);
|
|
|
|
itemView.setOnLongClickListener(this);
|
|
|
|
view.setOnLongClickListener(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void unwire() {
|
|
|
|
private void unwire() {
|
|
|
|
itemView.setOnClickListener(null);
|
|
|
|
view.setOnClickListener(null);
|
|
|
|
itemView.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);
|
|
|
|
|
|
|
|
|
|
|
|
if (contact.type == EntityContact.TYPE_FROM)
|
|
|
|
if (contact.type == EntityContact.TYPE_FROM)
|
|
|
|
ivType.setImageResource(R.drawable.baseline_mail_24);
|
|
|
|
ivType.setImageResource(R.drawable.baseline_mail_24);
|
|
|
|
else if (contact.type == EntityContact.TYPE_TO)
|
|
|
|
else if (contact.type == EntityContact.TYPE_TO)
|
|
|
@ -106,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.favorite ? R.drawable.baseline_star_24 : R.drawable.baseline_star_border_24);
|
|
|
|
ivFavorite.setImageResource(contact.state == 1 ? R.drawable.baseline_star_24 : R.drawable.baseline_star_border_24);
|
|
|
|
ivFavorite.setImageTintList(ColorStateList.valueOf(contact.favorite ? colorAccent : textColorSecondary));
|
|
|
|
ivFavorite.setImageTintList(ColorStateList.valueOf(contact.state == 1 ? colorAccent : textColorSecondary));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
view.requestLayout();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
@ -116,20 +119,22 @@ public class AdapterContact extends RecyclerView.Adapter<AdapterContact.ViewHold
|
|
|
|
if (pos == RecyclerView.NO_POSITION)
|
|
|
|
if (pos == RecyclerView.NO_POSITION)
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
EntityContact contact = filtered.get(pos);
|
|
|
|
EntityContact contact = items.get(pos);
|
|
|
|
|
|
|
|
contact.state = ++contact.state % 3;
|
|
|
|
|
|
|
|
notifyItemChanged(pos);
|
|
|
|
|
|
|
|
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putLong("id", contact.id);
|
|
|
|
args.putLong("id", contact.id);
|
|
|
|
args.putBoolean("favorite", !contact.favorite);
|
|
|
|
args.putInt("state", contact.state);
|
|
|
|
|
|
|
|
|
|
|
|
new SimpleTask<Void>() {
|
|
|
|
new SimpleTask<Void>() {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
protected Void onExecute(Context context, Bundle args) {
|
|
|
|
protected Void onExecute(Context context, Bundle args) {
|
|
|
|
long id = args.getLong("id");
|
|
|
|
long id = args.getLong("id");
|
|
|
|
boolean favorite = args.getBoolean("favorite");
|
|
|
|
int state = args.getInt("state");
|
|
|
|
|
|
|
|
|
|
|
|
DB db = DB.getInstance(context);
|
|
|
|
DB db = DB.getInstance(context);
|
|
|
|
db.contact().setContactFavorite(id, favorite);
|
|
|
|
db.contact().setContactState(id, state);
|
|
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -143,7 +148,7 @@ public class AdapterContact extends RecyclerView.Adapter<AdapterContact.ViewHold
|
|
|
|
protected void onException(Bundle args, Throwable ex) {
|
|
|
|
protected void onException(Bundle args, Throwable ex) {
|
|
|
|
Helper.unexpectedError(context, owner, ex);
|
|
|
|
Helper.unexpectedError(context, owner, ex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}.execute(context, owner, args, "contact:favorite");
|
|
|
|
}.execute(context, owner, args, "contact:state");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
@ -152,7 +157,7 @@ public class AdapterContact extends RecyclerView.Adapter<AdapterContact.ViewHold
|
|
|
|
if (pos == RecyclerView.NO_POSITION)
|
|
|
|
if (pos == RecyclerView.NO_POSITION)
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
EntityContact contact = filtered.get(pos);
|
|
|
|
EntityContact contact = items.get(pos);
|
|
|
|
|
|
|
|
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putLong("id", contact.id);
|
|
|
|
args.putLong("id", contact.id);
|
|
|
@ -196,13 +201,11 @@ public class AdapterContact extends RecyclerView.Adapter<AdapterContact.ViewHold
|
|
|
|
public void set(@NonNull List<EntityContact> contacts) {
|
|
|
|
public void set(@NonNull List<EntityContact> contacts) {
|
|
|
|
Log.i("Set contacts=" + contacts.size());
|
|
|
|
Log.i("Set contacts=" + contacts.size());
|
|
|
|
|
|
|
|
|
|
|
|
all = contacts;
|
|
|
|
DiffUtil.DiffResult diff = DiffUtil.calculateDiff(new DiffCallback(items, contacts));
|
|
|
|
|
|
|
|
|
|
|
|
DiffUtil.DiffResult diff = DiffUtil.calculateDiff(new DiffCallback(filtered, all));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
filtered.clear();
|
|
|
|
items = contacts;
|
|
|
|
filtered.addAll(all);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
diff.dispatchUpdatesTo(this);
|
|
|
|
diff.dispatchUpdatesTo(new ListUpdateCallback() {
|
|
|
|
diff.dispatchUpdatesTo(new ListUpdateCallback() {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onInserted(int position, int count) {
|
|
|
|
public void onInserted(int position, int count) {
|
|
|
@ -224,16 +227,15 @@ public class AdapterContact extends RecyclerView.Adapter<AdapterContact.ViewHold
|
|
|
|
Log.i("Changed @" + position + " #" + count);
|
|
|
|
Log.i("Changed @" + position + " #" + count);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
diff.dispatchUpdatesTo(this);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private class DiffCallback extends DiffUtil.Callback {
|
|
|
|
private class DiffCallback extends DiffUtil.Callback {
|
|
|
|
private List<EntityContact> prev;
|
|
|
|
private List<EntityContact> prev = new ArrayList<>();
|
|
|
|
private List<EntityContact> next;
|
|
|
|
private List<EntityContact> next = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
|
|
DiffCallback(List<EntityContact> prev, List<EntityContact> next) {
|
|
|
|
DiffCallback(List<EntityContact> prev, List<EntityContact> next) {
|
|
|
|
this.prev = prev;
|
|
|
|
this.prev.addAll(prev);
|
|
|
|
this.next = next;
|
|
|
|
this.next.addAll(next);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
@ -263,12 +265,12 @@ public class AdapterContact extends RecyclerView.Adapter<AdapterContact.ViewHold
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public long getItemId(int position) {
|
|
|
|
public long getItemId(int position) {
|
|
|
|
return filtered.get(position).id;
|
|
|
|
return items.get(position).id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public int getItemCount() {
|
|
|
|
public int getItemCount() {
|
|
|
|
return filtered.size();
|
|
|
|
return items.size();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
@ -280,7 +282,7 @@ public class AdapterContact extends RecyclerView.Adapter<AdapterContact.ViewHold
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
|
|
|
|
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
|
|
|
|
holder.unwire();
|
|
|
|
holder.unwire();
|
|
|
|
EntityContact contact = filtered.get(position);
|
|
|
|
EntityContact contact = items.get(position);
|
|
|
|
holder.bindTo(contact);
|
|
|
|
holder.bindTo(contact);
|
|
|
|
holder.wire();
|
|
|
|
holder.wire();
|
|
|
|
}
|
|
|
|
}
|
|
|
|