FairEmail/app/src/main/java/eu/faircode/email/AdapterIdentity.java

595 lines
24 KiB
Java
Raw Normal View History

2018-08-02 13:33:06 +00:00
package eu.faircode.email;
/*
2018-08-14 05:53:24 +00:00
This file is part of FairEmail.
2018-08-02 13:33:06 +00:00
2018-08-14 05:53:24 +00:00
FairEmail is free software: you can redistribute it and/or modify
2018-08-02 13:33:06 +00:00
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.
2018-10-29 10:46:49 +00:00
FairEmail is distributed in the hope that it will be useful,
2018-08-02 13:33:06 +00:00
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
2018-10-29 10:46:49 +00:00
along with FairEmail. If not, see <http://www.gnu.org/licenses/>.
2018-08-02 13:33:06 +00:00
2024-01-01 07:50:49 +00:00
Copyright 2018-2024 by Marcel Bokhorst (M66B)
2018-08-02 13:33:06 +00:00
*/
2023-03-04 07:57:12 +00:00
import static eu.faircode.email.ServiceAuthenticator.AUTH_TYPE_OAUTH;
2022-02-11 09:44:59 +00:00
import static eu.faircode.email.ServiceAuthenticator.AUTH_TYPE_PASSWORD;
2018-08-02 13:33:06 +00:00
import android.content.Context;
import android.content.DialogInterface;
2018-08-02 13:33:06 +00:00
import android.content.Intent;
2021-11-30 10:27:50 +00:00
import android.content.SharedPreferences;
2018-11-10 16:47:11 +00:00
import android.graphics.Color;
2020-01-21 09:52:34 +00:00
import android.graphics.Typeface;
import android.os.Bundle;
2020-01-21 09:52:34 +00:00
import android.text.SpannableString;
2020-01-21 10:41:07 +00:00
import android.text.style.RelativeSizeSpan;
2020-01-21 09:52:34 +00:00
import android.text.style.StyleSpan;
2018-08-02 13:33:06 +00:00
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
2018-08-02 13:33:06 +00:00
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.PopupMenu;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleObserver;
import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.OnLifecycleEvent;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
2021-11-30 10:27:50 +00:00
import androidx.preference.PreferenceManager;
import androidx.recyclerview.widget.DiffUtil;
import androidx.recyclerview.widget.ListUpdateCallback;
import androidx.recyclerview.widget.RecyclerView;
2018-08-02 13:33:06 +00:00
import java.text.Collator;
2019-01-25 18:13:00 +00:00
import java.text.DateFormat;
2018-08-02 13:33:06 +00:00
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;
public class AdapterIdentity extends RecyclerView.Adapter<AdapterIdentity.ViewHolder> {
private Fragment parentFragment;
2018-08-02 13:33:06 +00:00
private Context context;
private LifecycleOwner owner;
2018-12-24 13:41:49 +00:00
private LayoutInflater inflater;
2018-08-02 13:33:06 +00:00
2021-11-30 10:27:50 +00:00
private int colorStripeWidth;
private int colorWarning;
private int textColorTertiary;
2023-02-02 06:53:59 +00:00
private boolean debug;
2021-11-30 10:27:50 +00:00
2019-03-15 11:53:22 +00:00
private List<TupleIdentityEx> items = new ArrayList<>();
2018-08-02 13:33:06 +00:00
2019-07-15 19:28:25 +00:00
private DateFormat DTF;
2019-01-25 18:13:00 +00:00
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
2019-03-19 10:55:16 +00:00
private View view;
private View vwColor;
private ImageView ivSync;
2019-12-21 15:07:59 +00:00
private ImageView ivOAuth;
2019-03-19 10:55:16 +00:00
private ImageView ivPrimary;
2020-06-30 06:31:07 +00:00
private ImageView ivGroup;
2019-03-19 10:55:16 +00:00
private TextView tvName;
private TextView tvUser;
private TextView tvHost;
private ImageView ivState;
private TextView tvAccount;
2019-10-29 17:32:54 +00:00
private TextView tvSignKeyId;
2019-03-19 10:55:16 +00:00
private TextView tvLast;
2020-07-02 06:00:49 +00:00
private TextView tvMaxSize;
private TextView tvDrafts;
2019-03-19 10:55:16 +00:00
private TextView tvError;
2018-08-02 13:33:06 +00:00
2019-05-03 16:59:27 +00:00
private TwoStateOwner powner = new TwoStateOwner(owner, "IdentityPopup");
2018-08-02 13:33:06 +00:00
ViewHolder(View itemView) {
super(itemView);
2019-03-15 11:53:22 +00:00
view = itemView.findViewById(R.id.clItem);
2018-11-10 16:47:11 +00:00
vwColor = itemView.findViewById(R.id.vwColor);
2019-03-19 10:55:16 +00:00
ivSync = itemView.findViewById(R.id.ivSync);
2019-12-21 15:07:59 +00:00
ivOAuth = itemView.findViewById(R.id.ivOAuth);
2018-08-02 13:33:06 +00:00
ivPrimary = itemView.findViewById(R.id.ivPrimary);
2020-06-30 06:31:07 +00:00
ivGroup = itemView.findViewById(R.id.ivGroup);
2018-08-02 13:33:06 +00:00
tvName = itemView.findViewById(R.id.tvName);
2018-08-15 10:32:51 +00:00
tvUser = itemView.findViewById(R.id.tvUser);
tvHost = itemView.findViewById(R.id.tvHost);
2018-08-15 11:26:59 +00:00
ivState = itemView.findViewById(R.id.ivState);
2018-08-08 10:22:12 +00:00
tvAccount = itemView.findViewById(R.id.tvAccount);
2019-10-29 17:32:54 +00:00
tvSignKeyId = itemView.findViewById(R.id.tvSignKeyId);
2019-01-25 18:13:00 +00:00
tvLast = itemView.findViewById(R.id.tvLast);
2020-07-02 06:00:49 +00:00
tvMaxSize = itemView.findViewById(R.id.tvMaxSize);
tvDrafts = itemView.findViewById(R.id.tvDrafts);
2018-08-15 10:32:51 +00:00
tvError = itemView.findViewById(R.id.tvError);
2021-11-30 10:27:50 +00:00
2021-11-30 13:48:46 +00:00
if (vwColor != null)
vwColor.getLayoutParams().width = colorStripeWidth;
2018-08-02 13:33:06 +00:00
}
private void wire() {
2019-03-15 11:53:22 +00:00
view.setOnClickListener(this);
view.setOnLongClickListener(this);
2018-08-02 13:33:06 +00:00
}
private void unwire() {
2019-03-15 11:53:22 +00:00
view.setOnClickListener(null);
view.setOnLongClickListener(null);
2018-08-02 13:33:06 +00:00
}
2018-08-08 10:22:12 +00:00
private void bindTo(TupleIdentityEx identity) {
view.setAlpha(identity.synchronize && identity.accountSynchronize ? 1.0f : Helper.LOW_LIGHT);
Integer color = (identity.color == null ? identity.accountColor : identity.color);
vwColor.setBackgroundColor(color == null ? Color.TRANSPARENT : color);
2019-08-13 08:27:17 +00:00
vwColor.setVisibility(ActivityBilling.isPro(context) ? View.VISIBLE : View.INVISIBLE);
2019-03-19 10:55:16 +00:00
2020-09-28 07:18:56 +00:00
ivSync.setImageResource(identity.synchronize ? R.drawable.twotone_sync_24 : R.drawable.twotone_sync_disabled_24);
ivSync.setContentDescription(context.getString(identity.synchronize ? R.string.title_legend_synchronize_on : R.string.title_legend_synchronize_off));
2019-03-19 10:55:16 +00:00
2020-10-25 21:20:48 +00:00
ivOAuth.setVisibility(identity.auth_type == AUTH_TYPE_PASSWORD ? View.GONE : View.VISIBLE);
2023-03-04 07:57:12 +00:00
ivOAuth.setImageResource(identity.auth_type == AUTH_TYPE_OAUTH
? R.drawable.twotone_security_24
: R.drawable.twotone_show_chart_24);
2019-03-19 10:55:16 +00:00
ivPrimary.setVisibility(identity.primary ? View.VISIBLE : View.GONE);
2020-06-30 06:31:07 +00:00
ivGroup.setVisibility(identity.self ? View.GONE : View.VISIBLE);
2019-03-19 10:55:16 +00:00
tvName.setText(identity.getDisplayName());
2023-02-02 06:53:59 +00:00
StringBuilder user = new StringBuilder(identity.email);
if (identity.provider != null && (BuildConfig.DEBUG || debug))
user.append(" (").append(identity.provider).append(')');
tvUser.setText(user);
2018-08-15 11:26:59 +00:00
if ("connected".equals(identity.state)) {
2020-09-28 16:37:00 +00:00
ivState.setImageResource(R.drawable.twotone_cloud_done_24);
ivState.setContentDescription(context.getString(R.string.title_legend_connected));
} else if ("connecting".equals(identity.state)) {
2020-09-28 07:18:56 +00:00
ivState.setImageResource(R.drawable.twotone_cloud_queue_24);
ivState.setContentDescription(context.getString(R.string.title_legend_connecting));
} else {
2018-09-14 13:13:59 +00:00
ivState.setImageDrawable(null);
ivState.setContentDescription(null);
}
2018-08-15 11:26:59 +00:00
ivState.setVisibility(identity.synchronize ? View.VISIBLE : View.INVISIBLE);
tvHost.setText(String.format("%s:%d/%s",
identity.host,
identity.port,
EmailService.getEncryptionName(identity.encryption)));
tvHost.setTextColor(identity.insecure ? colorWarning : textColorTertiary);
2019-01-25 18:13:00 +00:00
tvAccount.setText(identity.accountName);
2019-12-05 19:23:31 +00:00
StringBuilder sb = new StringBuilder();
if (identity.sign_key != null)
sb.append(Long.toHexString(identity.sign_key));
if (identity.sign_key_alias != null) {
if (sb.length() != 0)
sb.append(", ");
sb.append(identity.sign_key_alias);
}
if (identity.encrypt == 1) {
if (sb.length() != 0)
sb.append(", ");
sb.append("S/MIME");
}
2019-12-05 19:23:31 +00:00
tvSignKeyId.setText(context.getString(R.string.title_sign_key, sb.toString()));
tvSignKeyId.setVisibility(sb.length() > 0 ? View.VISIBLE : View.GONE);
2019-01-25 18:13:00 +00:00
tvLast.setText(context.getString(R.string.title_last_connected,
(identity.last_connected == null ? "-" : DTF.format(identity.last_connected))) +
(BuildConfig.DEBUG ?
"/" + (identity.last_modified == null ? "-" : DTF.format(identity.last_modified)) : ""));
2020-07-02 06:00:49 +00:00
2020-07-02 08:19:01 +00:00
tvMaxSize.setText(identity.max_size == null ? null : Helper.humanReadableByteCount(identity.max_size));
2020-07-02 06:00:49 +00:00
tvMaxSize.setVisibility(identity.max_size == null ? View.GONE : View.VISIBLE);
2019-01-25 18:13:00 +00:00
tvDrafts.setVisibility(identity.drafts == null ? View.VISIBLE : View.GONE);
2018-08-15 11:26:59 +00:00
tvError.setText(identity.error);
tvError.setVisibility(identity.error == null ? View.GONE : View.VISIBLE);
}
2018-08-02 13:33:06 +00:00
@Override
public void onClick(View view) {
int pos = getAdapterPosition();
if (pos == RecyclerView.NO_POSITION)
return;
2019-03-15 11:53:22 +00:00
TupleIdentityEx identity = items.get(pos);
2018-08-02 13:33:06 +00:00
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
lbm.sendBroadcast(
2018-08-04 15:46:22 +00:00
new Intent(ActivitySetup.ACTION_EDIT_IDENTITY)
2018-08-08 06:55:47 +00:00
.putExtra("id", identity.id));
2018-08-02 13:33:06 +00:00
}
@Override
public boolean onLongClick(View v) {
int pos = getAdapterPosition();
if (pos == RecyclerView.NO_POSITION)
return false;
final TupleIdentityEx identity = items.get(pos);
2019-05-03 16:59:27 +00:00
PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(context, powner, view);
int order = 0;
2020-01-21 09:52:34 +00:00
SpannableString ss = new SpannableString(identity.email);
ss.setSpan(new StyleSpan(Typeface.ITALIC), 0, ss.length(), 0);
2020-01-21 10:41:07 +00:00
ss.setSpan(new RelativeSizeSpan(0.9f), 0, ss.length(), 0);
popupMenu.getMenu().add(Menu.NONE, 0, order++, ss).setEnabled(false);
2019-06-25 08:53:06 +00:00
popupMenu.getMenu().add(Menu.NONE, R.string.title_enabled, order++, R.string.title_enabled)
.setCheckable(true).setChecked(identity.synchronize);
popupMenu.getMenu().add(Menu.NONE, R.string.title_primary, order++, R.string.title_primary)
.setCheckable(true).setChecked(identity.primary);
2020-04-16 08:31:59 +00:00
if (identity.sign_key != null || identity.sign_key_alias != null)
popupMenu.getMenu().add(Menu.NONE, R.string.title_reset_sign_key, order++, R.string.title_reset_sign_key);
2023-06-17 14:08:49 +00:00
popupMenu.getMenu().add(Menu.NONE, R.string.title_advanced_create_alias, order++, R.string.title_advanced_create_alias);
popupMenu.getMenu().add(Menu.NONE, R.string.title_edit_properties, order++, R.string.title_edit_properties);
popupMenu.getMenu().add(Menu.NONE, R.string.title_copy, order++, R.string.title_copy);
popupMenu.getMenu().add(Menu.NONE, R.string.title_delete, order++, R.string.title_delete);
2019-08-13 10:07:30 +00:00
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
2021-02-05 10:15:02 +00:00
int itemId = item.getItemId();
if (itemId == R.string.title_enabled) {
onActionSync(!item.isChecked());
return true;
} else if (itemId == R.string.title_primary) {
onActionPrimary(!item.isChecked());
return true;
} else if (itemId == R.string.title_reset_sign_key) {
onActionClearSignKey();
return true;
2023-06-17 14:08:49 +00:00
} else if (itemId == R.string.title_advanced_create_alias) {
onActionAlias();
return true;
} else if (itemId == R.string.title_edit_properties) {
onClick(view);
return true;
2021-02-05 10:15:02 +00:00
} else if (itemId == R.string.title_copy) {
onActionCopy();
return true;
} else if (itemId == R.string.title_delete) {
onActionDelete();
return true;
}
2021-02-05 10:15:02 +00:00
return false;
}
private void onActionSync(boolean sync) {
Bundle args = new Bundle();
args.putLong("id", identity.id);
args.putBoolean("sync", sync);
new SimpleTask<Boolean>() {
@Override
protected Boolean onExecute(Context context, Bundle args) {
long id = args.getLong("id");
boolean sync = args.getBoolean("sync");
DB db = DB.getInstance(context);
if (!sync)
db.identity().setIdentityError(id, null);
db.identity().setIdentitySynchronize(id, sync);
return sync;
}
@Override
protected void onException(Bundle args, Throwable ex) {
2019-12-06 07:50:46 +00:00
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);
}
}.execute(context, owner, args, "identity:enable");
}
private void onActionPrimary(boolean primary) {
Bundle args = new Bundle();
args.putLong("id", identity.id);
args.putLong("account", identity.account);
args.putBoolean("primary", primary);
new SimpleTask<Void>() {
@Override
protected Void onExecute(Context context, Bundle args) {
long id = args.getLong("id");
long account = args.getLong("account");
boolean primary = args.getBoolean("primary");
DB db = DB.getInstance(context);
try {
db.beginTransaction();
2021-03-21 13:53:30 +00:00
if (primary)
db.identity().resetPrimary(account);
db.identity().setIdentityPrimary(id, primary);
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
return null;
}
@Override
protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);
}
}.execute(context, owner, args, "identity:primary");
}
2019-08-13 10:07:30 +00:00
private void onActionClearSignKey() {
Bundle args = new Bundle();
args.putLong("id", identity.id);
new SimpleTask<Boolean>() {
@Override
protected Boolean onExecute(Context context, Bundle args) {
long id = args.getLong("id");
DB db = DB.getInstance(context);
2019-12-05 19:23:31 +00:00
try {
db.beginTransaction();
db.identity().setIdentitySignKey(id, null);
db.identity().setIdentitySignKeyAlias(id, null);
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
return null;
}
@Override
protected void onException(Bundle args, Throwable ex) {
2019-12-06 07:50:46 +00:00
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);
}
}.execute(context, owner, args, "identitty:clear_sign_key");
}
2023-06-17 14:08:49 +00:00
private void onActionAlias() {
Bundle args = new Bundle();
args.putLong("id", identity.id);
args.putString("name", identity.name);
args.putString("email", identity.email);
FragmentDialogAlias fragment = new FragmentDialogAlias();
fragment.setArguments(args);
fragment.show(parentFragment.getParentFragmentManager(), "alias:create");
}
2019-08-13 10:07:30 +00:00
private void onActionCopy() {
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
lbm.sendBroadcast(
new Intent(ActivitySetup.ACTION_EDIT_IDENTITY)
.putExtra("id", identity.id)
.putExtra("copy", true));
}
private void onActionDelete() {
new AlertDialog.Builder(view.getContext())
.setIcon(R.drawable.twotone_warning_24)
.setTitle(identity.email)
.setMessage(R.string.title_identity_delete)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
onDelete();
}
})
.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// Do nothing
}
})
.show();
}
private void onDelete() {
Bundle args = new Bundle();
args.putLong("id", identity.id);
new SimpleTask<Void>() {
@Override
protected Void onExecute(Context context, Bundle args) {
long id = args.getLong("id");
DB db = DB.getInstance(context);
db.identity().deleteIdentity(id);
Core.clearIdentities();
return null;
}
@Override
protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);
}
}.execute(context, owner, args, "identity:delete");
}
});
popupMenu.show();
return true;
}
2018-08-02 13:33:06 +00:00
}
AdapterIdentity(Fragment parentFragment) {
this.parentFragment = parentFragment;
this.context = parentFragment.getContext();
this.owner = parentFragment.getViewLifecycleOwner();
2018-12-24 13:41:49 +00:00
this.inflater = LayoutInflater.from(context);
2021-11-30 10:27:50 +00:00
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean color_stripe_wide = prefs.getBoolean("color_stripe_wide", false);
this.colorStripeWidth = Helper.dp2pixels(context, color_stripe_wide ? 12 : 6);
this.colorWarning = Helper.resolveColor(context, R.attr.colorWarning);
this.textColorTertiary = Helper.resolveColor(context, android.R.attr.textColorTertiary);
2023-02-02 06:53:59 +00:00
this.debug = prefs.getBoolean("debug", false);
2021-11-30 10:27:50 +00:00
2019-07-15 19:28:25 +00:00
this.DTF = Helper.getDateTimeInstance(context, DateFormat.SHORT, DateFormat.SHORT);
2018-08-02 13:33:06 +00:00
setHasStableIds(true);
owner.getLifecycle().addObserver(new LifecycleObserver() {
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
public void onDestroyed() {
2019-12-07 16:02:42 +00:00
Log.d(AdapterIdentity.this + " parent destroyed");
AdapterIdentity.this.parentFragment = null;
2021-09-28 08:18:20 +00:00
owner.getLifecycle().removeObserver(this);
}
});
2018-08-02 13:33:06 +00:00
}
2018-08-08 10:22:12 +00:00
public void set(@NonNull List<TupleIdentityEx> identities) {
2018-12-24 12:27:45 +00:00
Log.i("Set identities=" + identities.size());
2018-08-02 13:33:06 +00:00
final Collator collator = Collator.getInstance(Locale.getDefault());
collator.setStrength(Collator.SECONDARY); // Case insensitive, process accents etc
2018-08-08 10:22:12 +00:00
Collections.sort(identities, new Comparator<TupleIdentityEx>() {
2018-08-02 13:33:06 +00:00
@Override
2018-08-08 10:22:12 +00:00
public int compare(TupleIdentityEx i1, TupleIdentityEx i2) {
2021-10-14 12:27:21 +00:00
int c = collator.compare(
i1.accountCategory == null ? "" : i1.accountCategory,
i2.accountCategory == null ? "" : i2.accountCategory);
if (c != 0)
return c;
2019-03-15 11:53:22 +00:00
int n = collator.compare(i1.getDisplayName(), i2.getDisplayName());
if (n != 0)
return n;
int e = collator.compare(i1.email, i2.email);
if (e != 0)
return e;
return i1.id.compareTo(i2.id);
2018-08-02 13:33:06 +00:00
}
});
2019-03-15 11:53:22 +00:00
DiffUtil.DiffResult diff = DiffUtil.calculateDiff(new DiffCallback(items, identities), false);
2018-08-02 13:33:06 +00:00
2019-03-15 11:53:22 +00:00
items = identities;
2018-08-02 13:33:06 +00:00
diff.dispatchUpdatesTo(new ListUpdateCallback() {
@Override
public void onInserted(int position, int count) {
2019-12-07 16:02:42 +00:00
Log.d("Inserted @" + position + " #" + count);
2018-08-02 13:33:06 +00:00
}
@Override
public void onRemoved(int position, int count) {
2019-12-07 16:02:42 +00:00
Log.d("Removed @" + position + " #" + count);
2018-08-02 13:33:06 +00:00
}
@Override
public void onMoved(int fromPosition, int toPosition) {
2019-12-07 16:02:42 +00:00
Log.d("Moved " + fromPosition + ">" + toPosition);
2018-08-02 13:33:06 +00:00
}
@Override
public void onChanged(int position, int count, Object payload) {
2019-12-07 16:02:42 +00:00
Log.d("Changed @" + position + " #" + count);
2018-08-02 13:33:06 +00:00
}
});
2022-03-23 17:19:14 +00:00
try {
diff.dispatchUpdatesTo(this);
} catch (Throwable ex) {
Log.e(ex);
}
2018-08-02 13:33:06 +00:00
}
2020-12-30 18:29:20 +00:00
private static class DiffCallback extends DiffUtil.Callback {
2019-03-15 11:53:22 +00:00
private List<TupleIdentityEx> prev = new ArrayList<>();
private List<TupleIdentityEx> next = new ArrayList<>();
2018-08-02 13:33:06 +00:00
2019-02-10 18:02:55 +00:00
DiffCallback(List<TupleIdentityEx> prev, List<TupleIdentityEx> next) {
2019-03-15 11:53:22 +00:00
this.prev.addAll(prev);
this.next.addAll(next);
2018-08-02 13:33:06 +00:00
}
@Override
public int getOldListSize() {
return prev.size();
}
@Override
public int getNewListSize() {
return next.size();
}
@Override
public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) {
2018-08-08 10:22:12 +00:00
TupleIdentityEx i1 = prev.get(oldItemPosition);
TupleIdentityEx i2 = next.get(newItemPosition);
2018-08-02 13:33:06 +00:00
return i1.id.equals(i2.id);
}
@Override
public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) {
2018-08-08 10:22:12 +00:00
TupleIdentityEx i1 = prev.get(oldItemPosition);
TupleIdentityEx i2 = next.get(newItemPosition);
2018-08-02 13:33:06 +00:00
return i1.equals(i2);
}
}
@Override
public long getItemId(int position) {
2019-03-15 11:53:22 +00:00
return items.get(position).id;
2018-08-02 13:33:06 +00:00
}
2021-10-14 12:27:21 +00:00
public TupleIdentityEx getItemAtPosition(int pos) {
if (pos >= 0 && pos < items.size())
return items.get(pos);
else
return null;
}
2018-08-02 13:33:06 +00:00
@Override
public int getItemCount() {
2019-03-15 11:53:22 +00:00
return items.size();
2018-08-02 13:33:06 +00:00
}
@Override
@NonNull
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
2018-12-24 13:41:49 +00:00
return new ViewHolder(inflater.inflate(R.layout.item_identity, parent, false));
2018-08-02 13:33:06 +00:00
}
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
2019-03-15 11:53:22 +00:00
TupleIdentityEx identity = items.get(position);
2020-11-12 07:07:30 +00:00
holder.powner.recreate(identity == null ? null : identity.id);
2018-08-02 13:33:06 +00:00
2020-11-12 07:07:30 +00:00
holder.unwire();
holder.bindTo(identity);
2018-08-02 13:33:06 +00:00
holder.wire();
}
}