From 548369ca0b1278182e26d64834b774f62b96b2ca Mon Sep 17 00:00:00 2001 From: m2049r Date: Fri, 12 Mar 2021 00:49:12 +0100 Subject: [PATCH 1/2] fix updating when transfers between accounts --- .../m2049r/xmrwallet/layout/TransactionInfoAdapter.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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 a0251353..2e971c1b 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/layout/TransactionInfoAdapter.java +++ b/app/src/main/java/com/m2049r/xmrwallet/layout/TransactionInfoAdapter.java @@ -90,8 +90,11 @@ public class TransactionInfoAdapter extends RecyclerView.Adapter Date: Fri, 12 Mar 2021 00:57:22 +0100 Subject: [PATCH 2/2] clean whitespace & style --- .../m2049r/xmrwallet/layout/DiffCallback.java | 1 + .../xmrwallet/layout/NodeInfoAdapter.java | 16 +++--- .../layout/TransactionInfoAdapter.java | 32 +++++------ .../xmrwallet/layout/WalletInfoAdapter.java | 57 ++++++++----------- 4 files changed, 46 insertions(+), 60 deletions(-) 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 0cb84ae6..4cd64811 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 31e3f600..fcd20999 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 2e971c1b..26998180 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 514b9a65..b9ad73c9 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); }