2019-03-14 18:47:10 +00:00
|
|
|
package eu.faircode.email;
|
|
|
|
|
|
|
|
/*
|
|
|
|
This file is part of FairEmail.
|
|
|
|
|
|
|
|
FairEmail is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
FairEmail is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with FairEmail. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
Copyright 2018-2019 by Marcel Bokhorst (M66B)
|
|
|
|
*/
|
|
|
|
|
2019-03-14 19:00:26 +00:00
|
|
|
import android.Manifest;
|
2019-03-14 18:47:10 +00:00
|
|
|
import android.content.Context;
|
2019-03-15 08:36:23 +00:00
|
|
|
import android.content.res.ColorStateList;
|
2019-03-14 18:47:10 +00:00
|
|
|
import android.net.Uri;
|
2019-03-15 08:36:23 +00:00
|
|
|
import android.os.Bundle;
|
2019-06-29 07:23:50 +00:00
|
|
|
import android.os.ParcelFileDescriptor;
|
2019-03-16 18:10:56 +00:00
|
|
|
import android.text.TextUtils;
|
2019-03-14 18:47:10 +00:00
|
|
|
import android.view.LayoutInflater;
|
2019-08-16 08:27:10 +00:00
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuItem;
|
2019-03-14 18:47:10 +00:00
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
2019-08-16 08:27:10 +00:00
|
|
|
import androidx.appcompat.widget.PopupMenu;
|
2019-07-01 07:30:07 +00:00
|
|
|
import androidx.fragment.app.Fragment;
|
|
|
|
import androidx.lifecycle.Lifecycle;
|
|
|
|
import androidx.lifecycle.LifecycleObserver;
|
2019-03-15 08:36:23 +00:00
|
|
|
import androidx.lifecycle.LifecycleOwner;
|
2019-07-01 07:30:07 +00:00
|
|
|
import androidx.lifecycle.OnLifecycleEvent;
|
2019-03-14 18:47:10 +00:00
|
|
|
import androidx.recyclerview.widget.DiffUtil;
|
|
|
|
import androidx.recyclerview.widget.ListUpdateCallback;
|
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
|
2019-04-17 18:21:44 +00:00
|
|
|
import java.text.NumberFormat;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2019-09-23 20:07:22 +00:00
|
|
|
import java.util.Locale;
|
2019-04-17 18:21:44 +00:00
|
|
|
|
2019-03-14 18:47:10 +00:00
|
|
|
public class AdapterContact extends RecyclerView.Adapter<AdapterContact.ViewHolder> {
|
2019-07-01 07:30:07 +00:00
|
|
|
private Fragment parentFragment;
|
|
|
|
|
2019-03-14 18:47:10 +00:00
|
|
|
private Context context;
|
2019-03-15 08:36:23 +00:00
|
|
|
private LifecycleOwner owner;
|
2019-03-14 18:47:10 +00:00
|
|
|
private LayoutInflater inflater;
|
2019-03-14 19:00:26 +00:00
|
|
|
private boolean contacts;
|
2019-03-15 08:36:23 +00:00
|
|
|
private int colorAccent;
|
|
|
|
private int textColorSecondary;
|
2019-03-14 18:47:10 +00:00
|
|
|
|
2019-03-16 18:10:56 +00:00
|
|
|
private String search = null;
|
2019-03-17 08:26:17 +00:00
|
|
|
private List<TupleContactEx> all = new ArrayList<>();
|
|
|
|
private List<TupleContactEx> selected = new ArrayList<>();
|
2019-03-14 18:47:10 +00:00
|
|
|
|
2019-07-22 07:52:08 +00:00
|
|
|
private NumberFormat NF = NumberFormat.getNumberInstance();
|
2019-03-14 19:00:26 +00:00
|
|
|
|
2019-03-15 08:41:22 +00:00
|
|
|
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
|
2019-03-15 11:31:26 +00:00
|
|
|
private View view;
|
2019-03-14 18:47:10 +00:00
|
|
|
private ImageView ivType;
|
|
|
|
private ImageView ivAvatar;
|
|
|
|
private TextView tvName;
|
|
|
|
private TextView tvEmail;
|
|
|
|
private TextView tvTimes;
|
|
|
|
private TextView tvLast;
|
2019-03-15 08:36:23 +00:00
|
|
|
private ImageView ivFavorite;
|
2019-03-14 18:47:10 +00:00
|
|
|
|
2019-08-16 08:27:10 +00:00
|
|
|
private TwoStateOwner powner = new TwoStateOwner(owner, "ContactPopup");
|
|
|
|
|
2019-03-14 18:47:10 +00:00
|
|
|
ViewHolder(View itemView) {
|
|
|
|
super(itemView);
|
|
|
|
|
2019-03-15 11:31:26 +00:00
|
|
|
view = itemView.findViewById(R.id.clItem);
|
2019-03-14 18:47:10 +00:00
|
|
|
ivType = itemView.findViewById(R.id.ivType);
|
|
|
|
ivAvatar = itemView.findViewById(R.id.ivAvatar);
|
|
|
|
tvName = itemView.findViewById(R.id.tvName);
|
|
|
|
tvEmail = itemView.findViewById(R.id.tvEmail);
|
|
|
|
tvTimes = itemView.findViewById(R.id.tvTimes);
|
|
|
|
tvLast = itemView.findViewById(R.id.tvLast);
|
2019-03-15 08:36:23 +00:00
|
|
|
ivFavorite = itemView.findViewById(R.id.ivFavorite);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void wire() {
|
2019-03-15 11:31:26 +00:00
|
|
|
view.setOnClickListener(this);
|
2019-03-16 16:58:57 +00:00
|
|
|
view.setOnLongClickListener(this);
|
2019-03-15 08:36:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void unwire() {
|
2019-03-15 11:31:26 +00:00
|
|
|
view.setOnClickListener(null);
|
2019-03-16 16:58:57 +00:00
|
|
|
view.setOnLongClickListener(null);
|
2019-03-14 18:47:10 +00:00
|
|
|
}
|
|
|
|
|
2019-03-17 08:26:17 +00:00
|
|
|
private void bindTo(TupleContactEx contact) {
|
2019-03-16 16:58:57 +00:00
|
|
|
view.setAlpha(contact.state == EntityContact.STATE_IGNORE ? Helper.LOW_LIGHT : 1.0f);
|
2019-03-15 11:31:26 +00:00
|
|
|
|
2019-03-14 18:47:10 +00:00
|
|
|
if (contact.type == EntityContact.TYPE_FROM)
|
2019-03-16 16:14:49 +00:00
|
|
|
ivType.setImageResource(R.drawable.baseline_call_received_24);
|
2019-03-14 18:47:10 +00:00
|
|
|
else if (contact.type == EntityContact.TYPE_TO)
|
2019-03-16 16:14:49 +00:00
|
|
|
ivType.setImageResource(R.drawable.baseline_call_made_24);
|
2019-03-14 18:47:10 +00:00
|
|
|
else
|
|
|
|
ivType.setImageDrawable(null);
|
|
|
|
|
2019-03-14 19:00:26 +00:00
|
|
|
if (contact.avatar == null || !contacts)
|
2019-03-14 18:47:10 +00:00
|
|
|
ivAvatar.setImageDrawable(null);
|
|
|
|
else
|
2019-05-13 14:38:39 +00:00
|
|
|
try {
|
2019-06-29 07:23:50 +00:00
|
|
|
Uri uri = Uri.parse(contact.avatar + "/photo");
|
|
|
|
|
2019-05-13 14:38:39 +00:00
|
|
|
/*
|
|
|
|
java.lang.NullPointerException: Attempt to invoke virtual method 'java.io.FileDescriptor android.content.res.AssetFileDescriptor.getFileDescriptor()' on a null object reference
|
|
|
|
java.lang.NullPointerException: Attempt to invoke virtual method 'java.io.FileDescriptor android.content.res.AssetFileDescriptor.getFileDescriptor()' on a null object reference
|
|
|
|
at android.graphics.ImageDecoder$ContentResolverSource.createImageDecoder(ImageDecoder.java:286)
|
|
|
|
at android.graphics.ImageDecoder.decodeDrawableImpl(ImageDecoder.java:1652)
|
|
|
|
at android.graphics.ImageDecoder.decodeDrawable(ImageDecoder.java:1645)
|
|
|
|
at android.widget.ImageView.getDrawableFromUri(ImageView.java:952)
|
|
|
|
at android.widget.ImageView.resolveUri(ImageView.java:921)
|
2019-06-29 07:23:50 +00:00
|
|
|
|
2019-05-13 14:38:39 +00:00
|
|
|
at android.widget.ImageView.setImageURI(ImageView.java:532)
|
|
|
|
at androidx.appcompat.widget.AppCompatImageView.setImageURI(SourceFile:116)
|
2019-06-29 07:23:50 +00:00
|
|
|
|
|
|
|
at android.widget.ImageView.onMeasure(ImageView.java:1056)
|
|
|
|
at android.view.View.measure(View.java:23188)
|
|
|
|
at androidx.constraintlayout.widget.ConstraintLayout$Measurer.measure(SourceFile:806)
|
2019-05-13 14:38:39 +00:00
|
|
|
*/
|
2019-06-29 07:23:50 +00:00
|
|
|
ParcelFileDescriptor pfd = context.getContentResolver().openFileDescriptor(uri, "r");
|
|
|
|
if (pfd == null)
|
|
|
|
throw new IllegalArgumentException();
|
|
|
|
pfd.close();
|
|
|
|
|
|
|
|
ivAvatar.setImageURI(uri);
|
2019-05-13 14:38:39 +00:00
|
|
|
} catch (Throwable ex) {
|
|
|
|
Log.e(ex);
|
2019-06-29 07:23:50 +00:00
|
|
|
ivAvatar.setImageResource(R.drawable.baseline_broken_image_24);
|
2019-05-13 14:38:39 +00:00
|
|
|
}
|
2019-03-14 18:47:10 +00:00
|
|
|
|
2019-03-14 19:00:26 +00:00
|
|
|
tvName.setText(contact.name == null ? contact.email : contact.name);
|
2019-03-17 08:26:17 +00:00
|
|
|
tvEmail.setText(contact.accountName + "/" + contact.email);
|
2019-07-22 07:52:08 +00:00
|
|
|
tvTimes.setText(NF.format(contact.times_contacted));
|
2019-03-14 19:00:26 +00:00
|
|
|
tvLast.setText(contact.last_contacted == null ? null
|
2019-04-19 11:08:30 +00:00
|
|
|
: Helper.getRelativeTimeSpanString(context, contact.last_contacted));
|
2019-03-15 08:36:23 +00:00
|
|
|
|
2019-03-16 16:58:57 +00:00
|
|
|
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));
|
2019-03-15 11:31:26 +00:00
|
|
|
|
|
|
|
view.requestLayout();
|
2019-03-15 08:36:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onClick(View view) {
|
|
|
|
int pos = getAdapterPosition();
|
|
|
|
if (pos == RecyclerView.NO_POSITION)
|
|
|
|
return;
|
|
|
|
|
2019-03-17 08:26:17 +00:00
|
|
|
TupleContactEx contact = selected.get(pos);
|
2019-03-16 16:58:57 +00:00
|
|
|
if (contact.state == EntityContact.STATE_DEFAULT)
|
|
|
|
contact.state = EntityContact.STATE_FAVORITE;
|
|
|
|
else
|
|
|
|
contact.state = EntityContact.STATE_DEFAULT;
|
|
|
|
|
2019-03-15 11:31:26 +00:00
|
|
|
notifyItemChanged(pos);
|
2019-03-15 08:36:23 +00:00
|
|
|
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putLong("id", contact.id);
|
2019-03-15 11:31:26 +00:00
|
|
|
args.putInt("state", contact.state);
|
2019-03-15 08:36:23 +00:00
|
|
|
|
|
|
|
new SimpleTask<Void>() {
|
|
|
|
@Override
|
|
|
|
protected Void onExecute(Context context, Bundle args) {
|
|
|
|
long id = args.getLong("id");
|
2019-03-15 11:31:26 +00:00
|
|
|
int state = args.getInt("state");
|
2019-03-15 08:36:23 +00:00
|
|
|
|
|
|
|
DB db = DB.getInstance(context);
|
2019-03-15 11:31:26 +00:00
|
|
|
db.contact().setContactState(id, state);
|
2019-03-15 08:36:23 +00:00
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onExecuted(Bundle args, Void data) {
|
|
|
|
Shortcuts.update(context, owner);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onException(Bundle args, Throwable ex) {
|
2019-10-12 15:16:53 +00:00
|
|
|
Helper.unexpectedError(parentFragment.getParentFragmentManager(), ex);
|
2019-03-15 08:36:23 +00:00
|
|
|
}
|
2019-03-15 11:31:26 +00:00
|
|
|
}.execute(context, owner, args, "contact:state");
|
2019-03-14 18:47:10 +00:00
|
|
|
}
|
2019-03-15 08:41:22 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onLongClick(View view) {
|
|
|
|
int pos = getAdapterPosition();
|
|
|
|
if (pos == RecyclerView.NO_POSITION)
|
|
|
|
return false;
|
|
|
|
|
2019-03-17 08:26:17 +00:00
|
|
|
TupleContactEx contact = selected.get(pos);
|
2019-03-15 08:41:22 +00:00
|
|
|
|
2019-08-16 08:27:10 +00:00
|
|
|
PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(context, powner, view);
|
2019-03-15 08:41:22 +00:00
|
|
|
|
2019-08-16 08:27:10 +00:00
|
|
|
popupMenu.getMenu().add(Menu.NONE, 0, 0, contact.email).setEnabled(false);
|
|
|
|
if (contact.state != EntityContact.STATE_IGNORE)
|
|
|
|
popupMenu.getMenu().add(Menu.NONE, R.string.title_advanced_never_favorite, 1, R.string.title_advanced_never_favorite);
|
|
|
|
popupMenu.getMenu().add(Menu.NONE, R.string.title_delete, 2, R.string.title_delete);
|
|
|
|
|
|
|
|
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
2019-03-15 08:41:22 +00:00
|
|
|
@Override
|
2019-08-16 08:27:10 +00:00
|
|
|
public boolean onMenuItemClick(MenuItem item) {
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
case R.string.title_advanced_never_favorite:
|
|
|
|
onActionNeverFavorite();
|
|
|
|
return true;
|
|
|
|
case R.string.title_delete:
|
|
|
|
onActionDelete();
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2019-03-15 08:41:22 +00:00
|
|
|
|
2019-08-16 08:27:10 +00:00
|
|
|
private void onActionNeverFavorite() {
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putLong("id", contact.id);
|
2019-03-15 08:41:22 +00:00
|
|
|
|
2019-08-16 08:27:10 +00:00
|
|
|
new SimpleTask<Void>() {
|
|
|
|
@Override
|
|
|
|
protected Void onExecute(Context context, Bundle args) {
|
|
|
|
long id = args.getLong("id");
|
2019-03-15 08:41:22 +00:00
|
|
|
|
2019-08-16 08:27:10 +00:00
|
|
|
DB db = DB.getInstance(context);
|
|
|
|
db.contact().setContactState(id, EntityContact.STATE_IGNORE);
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onExecuted(Bundle args, Void data) {
|
|
|
|
Shortcuts.update(context, owner);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onException(Bundle args, Throwable ex) {
|
2019-10-12 15:16:53 +00:00
|
|
|
Helper.unexpectedError(parentFragment.getParentFragmentManager(), ex);
|
2019-08-16 08:27:10 +00:00
|
|
|
}
|
|
|
|
}.execute(context, owner, args, "contact:favorite");
|
2019-03-15 08:41:22 +00:00
|
|
|
}
|
|
|
|
|
2019-08-16 08:27:10 +00:00
|
|
|
private void onActionDelete() {
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putLong("id", contact.id);
|
|
|
|
|
|
|
|
new SimpleTask<Void>() {
|
|
|
|
@Override
|
|
|
|
protected Void onExecute(Context context, Bundle args) {
|
|
|
|
long id = args.getLong("id");
|
|
|
|
|
|
|
|
DB db = DB.getInstance(context);
|
|
|
|
db.contact().deleteContact(id);
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onExecuted(Bundle args, Void data) {
|
|
|
|
Shortcuts.update(context, owner);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onException(Bundle args, Throwable ex) {
|
2019-10-12 15:16:53 +00:00
|
|
|
Helper.unexpectedError(parentFragment.getParentFragmentManager(), ex);
|
2019-08-16 08:27:10 +00:00
|
|
|
}
|
|
|
|
}.execute(context, owner, args, "contact:delete");
|
2019-03-15 08:41:22 +00:00
|
|
|
}
|
2019-08-16 08:27:10 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
popupMenu.show();
|
2019-03-15 08:41:22 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2019-03-14 18:47:10 +00:00
|
|
|
}
|
|
|
|
|
2019-07-01 07:30:07 +00:00
|
|
|
AdapterContact(Fragment parentFragment) {
|
|
|
|
this.parentFragment = parentFragment;
|
|
|
|
|
|
|
|
this.context = parentFragment.getContext();
|
|
|
|
this.owner = parentFragment.getViewLifecycleOwner();
|
2019-03-14 18:47:10 +00:00
|
|
|
this.inflater = LayoutInflater.from(context);
|
2019-07-01 07:30:07 +00:00
|
|
|
|
2019-03-14 19:00:26 +00:00
|
|
|
this.contacts = Helper.hasPermission(context, Manifest.permission.READ_CONTACTS);
|
2019-03-15 08:36:23 +00:00
|
|
|
this.colorAccent = Helper.resolveColor(context, R.attr.colorAccent);
|
|
|
|
this.textColorSecondary = Helper.resolveColor(context, android.R.attr.textColorSecondary);
|
2019-07-01 07:30:07 +00:00
|
|
|
|
2019-03-14 18:47:10 +00:00
|
|
|
setHasStableIds(true);
|
2019-07-01 07:30:07 +00:00
|
|
|
|
|
|
|
owner.getLifecycle().addObserver(new LifecycleObserver() {
|
|
|
|
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
|
|
|
|
public void onDestroyed() {
|
|
|
|
Log.i(AdapterContact.this + " parent destroyed");
|
|
|
|
AdapterContact.this.parentFragment = null;
|
|
|
|
}
|
|
|
|
});
|
2019-03-14 18:47:10 +00:00
|
|
|
}
|
|
|
|
|
2019-03-17 08:26:17 +00:00
|
|
|
public void set(@NonNull List<TupleContactEx> contacts) {
|
2019-03-14 18:47:10 +00:00
|
|
|
Log.i("Set contacts=" + contacts.size());
|
|
|
|
|
2019-03-16 18:10:56 +00:00
|
|
|
all = contacts;
|
|
|
|
|
2019-03-17 08:26:17 +00:00
|
|
|
List<TupleContactEx> items;
|
2019-03-16 18:10:56 +00:00
|
|
|
if (TextUtils.isEmpty(search))
|
|
|
|
items = all;
|
|
|
|
else {
|
|
|
|
items = new ArrayList<>();
|
2019-09-23 20:07:22 +00:00
|
|
|
String query = search.toLowerCase(Locale.ROOT).trim();
|
2019-03-17 08:26:17 +00:00
|
|
|
for (TupleContactEx contact : contacts)
|
2019-09-23 20:07:22 +00:00
|
|
|
if (contact.email.toLowerCase(Locale.ROOT).contains(query) ||
|
2019-03-16 18:10:56 +00:00
|
|
|
(contact.name != null && contact.name.toLowerCase().contains(query)))
|
|
|
|
items.add(contact);
|
|
|
|
}
|
|
|
|
|
|
|
|
DiffUtil.DiffResult diff = DiffUtil.calculateDiff(new DiffCallback(selected, items), false);
|
2019-03-14 18:47:10 +00:00
|
|
|
|
2019-03-16 18:10:56 +00:00
|
|
|
selected = items;
|
2019-03-14 18:47:10 +00:00
|
|
|
|
|
|
|
diff.dispatchUpdatesTo(new ListUpdateCallback() {
|
|
|
|
@Override
|
|
|
|
public void onInserted(int position, int count) {
|
|
|
|
Log.i("Inserted @" + position + " #" + count);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onRemoved(int position, int count) {
|
|
|
|
Log.i("Removed @" + position + " #" + count);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onMoved(int fromPosition, int toPosition) {
|
|
|
|
Log.i("Moved " + fromPosition + ">" + toPosition);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onChanged(int position, int count, Object payload) {
|
|
|
|
Log.i("Changed @" + position + " #" + count);
|
|
|
|
}
|
|
|
|
});
|
2019-03-15 11:53:22 +00:00
|
|
|
diff.dispatchUpdatesTo(this);
|
2019-03-14 18:47:10 +00:00
|
|
|
}
|
|
|
|
|
2019-03-16 18:10:56 +00:00
|
|
|
public void search(String query) {
|
|
|
|
search = query;
|
|
|
|
set(all);
|
|
|
|
}
|
|
|
|
|
2019-03-14 18:47:10 +00:00
|
|
|
private class DiffCallback extends DiffUtil.Callback {
|
2019-03-17 08:26:17 +00:00
|
|
|
private List<TupleContactEx> prev = new ArrayList<>();
|
|
|
|
private List<TupleContactEx> next = new ArrayList<>();
|
2019-03-14 18:47:10 +00:00
|
|
|
|
2019-03-17 08:26:17 +00:00
|
|
|
DiffCallback(List<TupleContactEx> prev, List<TupleContactEx> next) {
|
2019-03-15 11:31:26 +00:00
|
|
|
this.prev.addAll(prev);
|
|
|
|
this.next.addAll(next);
|
2019-03-14 18:47:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getOldListSize() {
|
|
|
|
return prev.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getNewListSize() {
|
|
|
|
return next.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) {
|
2019-03-17 08:26:17 +00:00
|
|
|
TupleContactEx c1 = prev.get(oldItemPosition);
|
|
|
|
TupleContactEx c2 = next.get(newItemPosition);
|
2019-03-14 18:47:10 +00:00
|
|
|
return c1.id.equals(c2.id);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) {
|
2019-03-17 08:26:17 +00:00
|
|
|
TupleContactEx c1 = prev.get(oldItemPosition);
|
|
|
|
TupleContactEx c2 = next.get(newItemPosition);
|
2019-03-14 18:47:10 +00:00
|
|
|
return c1.equals(c2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public long getItemId(int position) {
|
2019-03-16 18:10:56 +00:00
|
|
|
return selected.get(position).id;
|
2019-03-14 18:47:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getItemCount() {
|
2019-03-16 18:10:56 +00:00
|
|
|
return selected.size();
|
2019-03-14 18:47:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@NonNull
|
|
|
|
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
|
|
|
return new ViewHolder(inflater.inflate(R.layout.item_contact, parent, false));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
|
2019-03-15 08:36:23 +00:00
|
|
|
holder.unwire();
|
2019-03-17 08:26:17 +00:00
|
|
|
TupleContactEx contact = selected.get(position);
|
2019-03-14 18:47:10 +00:00
|
|
|
holder.bindTo(contact);
|
2019-03-15 08:36:23 +00:00
|
|
|
holder.wire();
|
2019-03-14 18:47:10 +00:00
|
|
|
}
|
2019-08-16 08:27:10 +00:00
|
|
|
|
|
|
|
@Override
|
2019-09-21 18:28:03 +00:00
|
|
|
public void onViewDetachedFromWindow(@NonNull ViewHolder holder) {
|
2019-08-16 08:27:10 +00:00
|
|
|
holder.powner.recreate();
|
|
|
|
}
|
2019-03-14 18:47:10 +00:00
|
|
|
}
|