diff --git a/app/src/main/java/com/m2049r/xmrwallet/layout/DiffCallback.java b/app/src/main/java/com/m2049r/xmrwallet/layout/DiffCallback.java index 0cb84ae..4cd6481 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/layout/DiffCallback.java +++ b/app/src/main/java/com/m2049r/xmrwallet/layout/DiffCallback.java @@ -23,6 +23,7 @@ public abstract class DiffCallback extends DiffUtil.Callback { public int getNewListSize() { return mNewList.size(); } + public abstract boolean areItemsTheSame(int oldItemPosition, int newItemPosition); public abstract boolean areContentsTheSame(int oldItemPosition, int newItemPosition); diff --git a/app/src/main/java/com/m2049r/xmrwallet/layout/NodeInfoAdapter.java b/app/src/main/java/com/m2049r/xmrwallet/layout/NodeInfoAdapter.java index 31e3f60..fcd2099 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/layout/NodeInfoAdapter.java +++ b/app/src/main/java/com/m2049r/xmrwallet/layout/NodeInfoAdapter.java @@ -54,7 +54,7 @@ public class NodeInfoAdapter extends RecyclerView.Adapter nodeItems = new ArrayList<>(); private final OnInteractionListener listener; - private Context context; + private final Context context; public NodeInfoAdapter(Context context, OnInteractionListener listener) { this.context = context; @@ -72,23 +72,20 @@ public class NodeInfoAdapter extends RecyclerView.Adapter newItemsCollection) { List newItems; - if(newItemsCollection !=null) { + if (newItemsCollection != null) { newItems = new ArrayList<>(newItemsCollection); Collections.sort(newItems, NodeInfo.BestNodeComparator); } else { newItems = new ArrayList<>(); } - final NodeInfoAdapter.NodeDiff diffCallback = new NodeInfoAdapter.NodeDiff(nodeItems,newItems); + final NodeInfoAdapter.NodeDiff diffCallback = new NodeInfoAdapter.NodeDiff(nodeItems, newItems); final DiffUtil.DiffResult diffResult = DiffUtil.calculateDiff(diffCallback); nodeItems.clear(); nodeItems.addAll(newItems); diffResult.dispatchUpdatesTo(this); } + public void setNodes() { setNodes(nodeItems); } diff --git a/app/src/main/java/com/m2049r/xmrwallet/layout/TransactionInfoAdapter.java b/app/src/main/java/com/m2049r/xmrwallet/layout/TransactionInfoAdapter.java index 2e971c1..2699818 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/layout/TransactionInfoAdapter.java +++ b/app/src/main/java/com/m2049r/xmrwallet/layout/TransactionInfoAdapter.java @@ -23,6 +23,7 @@ import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; +import androidx.annotation.NonNull; import androidx.core.content.ContextCompat; import androidx.recyclerview.widget.DiffUtil; import androidx.recyclerview.widget.RecyclerView; @@ -47,10 +48,10 @@ public class TransactionInfoAdapter extends RecyclerView.Adapter infoItems; private final OnInteractionListener listener; - private Context context; + private final Context context; public TransactionInfoAdapter(Context context, OnInteractionListener listener) { this.context = context; @@ -74,7 +75,6 @@ public class TransactionInfoAdapter extends RecyclerView.Adapter { public TransactionInfoDiff(List oldList, List newList) { @@ -83,25 +83,23 @@ public class TransactionInfoAdapter extends RecyclerView.Adapter newItems) { - if(newItems == null) { + if (newItems == null) { newItems = new ArrayList<>(); Timber.d("setInfos null"); } else { Timber.d("setInfos %s", newItems.size()); } Collections.sort(newItems); - final DiffCallback diffCallback = new TransactionInfoAdapter.TransactionInfoDiff(infoItems,newItems); + final DiffCallback diffCallback = new TransactionInfoAdapter.TransactionInfoDiff(infoItems, newItems); final DiffUtil.DiffResult diffResult = DiffUtil.calculateDiff(diffCallback); infoItems.clear(); infoItems.addAll(newItems); @@ -132,7 +130,7 @@ public class TransactionInfoAdapter extends RecyclerView.Adapter newItems = new ArrayList<>(infoItems); - if (newItems.size()>position) + if (newItems.size() > position) newItems.remove(position); setInfos(newItems); // in case the nodeinfo has changed } diff --git a/app/src/main/java/com/m2049r/xmrwallet/layout/WalletInfoAdapter.java b/app/src/main/java/com/m2049r/xmrwallet/layout/WalletInfoAdapter.java index 514b9a6..b9ad73c 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/layout/WalletInfoAdapter.java +++ b/app/src/main/java/com/m2049r/xmrwallet/layout/WalletInfoAdapter.java @@ -24,6 +24,7 @@ import android.view.ViewGroup; import android.widget.ImageButton; import android.widget.TextView; +import androidx.annotation.NonNull; import androidx.appcompat.widget.PopupMenu; import androidx.recyclerview.widget.DiffUtil; import androidx.recyclerview.widget.RecyclerView; @@ -64,6 +65,7 @@ public class WalletInfoAdapter extends RecyclerView.Adapter { public WalletInfoDiff(List oldList, List newList) { @@ -72,9 +74,7 @@ public class WalletInfoAdapter extends RecyclerView.Adapter newItems) { - if(newItems == null) { + if (newItems == null) { newItems = new ArrayList<>(); Timber.d("setInfos null"); } else { Timber.d("setInfos %s", newItems.size()); } Collections.sort(newItems); - final DiffCallback diffCallback = new WalletInfoAdapter.WalletInfoDiff(infoItems,newItems); + final DiffCallback diffCallback = new WalletInfoAdapter.WalletInfoDiff(infoItems, newItems); final DiffUtil.DiffResult diffResult = DiffUtil.calculateDiff(diffCallback); infoItems.clear(); infoItems.addAll(newItems); diffResult.dispatchUpdatesTo(this); } - class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener { final TextView tvName; final TextView tvAddress; @@ -132,35 +132,24 @@ public class WalletInfoAdapter extends RecyclerView.Adapter { + if (popupOpen) return; + //creating a popup menu + PopupMenu popup = new PopupMenu(context, ibOptions); + //inflating menu from xml resource + popup.inflate(R.menu.list_context_menu); + popupOpen = true; + //adding click listener + popup.setOnMenuItemClickListener(item -> { + if (listener != null) { + return listener.onContextInteraction(item, infoItem); + } + return false; + }); + //displaying the popup + popup.show(); + popup.setOnDismissListener(menu -> popupOpen = false); - } }); itemView.setOnClickListener(this); }