clean whitespace & style

This commit is contained in:
m2049r 2021-03-12 00:57:22 +01:00
parent 548369ca0b
commit 850ba7efef
No known key found for this signature in database
GPG Key ID: 4386E69AF260078D
4 changed files with 46 additions and 60 deletions

View File

@ -23,6 +23,7 @@ public abstract class DiffCallback<T> 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);

View File

@ -54,7 +54,7 @@ public class NodeInfoAdapter extends RecyclerView.Adapter<NodeInfoAdapter.ViewHo
private final List<NodeInfo> 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<NodeInfoAdapter.ViewHo
@Override
public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) {
return mOldList.get(oldItemPosition).equals(
mNewList.get(newItemPosition)
);
return mOldList.get(oldItemPosition).equals(mNewList.get(newItemPosition));
}
@Override
public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) {
return mOldList.get(oldItemPosition).toNodeString().equals(mNewList.get(newItemPosition).toNodeString())
&& mOldList.get(oldItemPosition).isSelected() == mNewList.get(newItemPosition).isSelected() ;
&& (mOldList.get(oldItemPosition).isSelected() == mNewList.get(newItemPosition).isSelected());
}
}
@Override
public @NonNull
ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.item_node, parent, false);
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_node, parent, false);
return new ViewHolder(view);
}
@ -111,18 +108,19 @@ public class NodeInfoAdapter extends RecyclerView.Adapter<NodeInfoAdapter.ViewHo
public void setNodes(Collection<NodeInfo> newItemsCollection) {
List<NodeInfo> 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);
}

View File

@ -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<TransactionInfo
private final SimpleDateFormat DATETIME_FORMATTER = new SimpleDateFormat("yyyy-MM-dd HH:mm");
private int outboundColour;
private int inboundColour;
private int pendingColour;
private int failedColour;
private final int outboundColour;
private final int inboundColour;
private final int pendingColour;
private final int failedColour;
public interface OnInteractionListener {
void onInteraction(View view, TransactionInfo item);
@ -59,7 +60,7 @@ public class TransactionInfoAdapter extends RecyclerView.Adapter<TransactionInfo
private final List<TransactionInfo> 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<TransactionInfo
DATETIME_FORMATTER.setTimeZone(tz);
}
private static class TransactionInfoDiff extends DiffCallback<TransactionInfo> {
public TransactionInfoDiff(List<TransactionInfo> oldList, List<TransactionInfo> newList) {
@ -83,25 +83,23 @@ public class TransactionInfoAdapter extends RecyclerView.Adapter<TransactionInfo
@Override
public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) {
return mOldList.get(oldItemPosition).hash.equals(
mNewList.get(newItemPosition).hash
);
return mOldList.get(oldItemPosition).hash.equals(mNewList.get(newItemPosition).hash);
}
@Override
public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) {
final TransactionInfo oldItem = mOldList.get(oldItemPosition);
final TransactionInfo newItem = mNewList.get(newItemPosition);
return oldItem.isPending == newItem.isPending
&& oldItem.isFailed == newItem.isFailed
&& oldItem.direction == newItem.direction;
return (oldItem.direction == newItem.direction)
&& (oldItem.isPending == newItem.isPending)
&& (oldItem.isFailed == newItem.isFailed);
}
}
@NonNull
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.item_transaction, parent, false);
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_transaction, parent, false);
return new ViewHolder(view);
}
@ -116,14 +114,14 @@ public class TransactionInfoAdapter extends RecyclerView.Adapter<TransactionInfo
}
public void setInfos(List<TransactionInfo> 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<TransactionInfo> diffCallback = new TransactionInfoAdapter.TransactionInfoDiff(infoItems,newItems);
final DiffCallback<TransactionInfo> 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<TransactionInfo
public void removeItem(int position) {
List<TransactionInfo> newItems = new ArrayList<>(infoItems);
if (newItems.size()>position)
if (newItems.size() > position)
newItems.remove(position);
setInfos(newItems); // in case the nodeinfo has changed
}

View File

@ -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<WalletInfoAdapter.Vi
TimeZone tz = cal.getTimeZone(); //get the local time zone.
DATETIME_FORMATTER.setTimeZone(tz);
}
private static class WalletInfoDiff extends DiffCallback<WalletManager.WalletInfo> {
public WalletInfoDiff(List<WalletManager.WalletInfo> oldList, List<WalletManager.WalletInfo> newList) {
@ -72,9 +74,7 @@ public class WalletInfoAdapter extends RecyclerView.Adapter<WalletInfoAdapter.Vi
@Override
public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) {
return mOldList.get(oldItemPosition).name.equals(
mNewList.get(newItemPosition).name
);
return mOldList.get(oldItemPosition).name.equals(mNewList.get(newItemPosition).name);
}
@Override
@ -83,6 +83,7 @@ public class WalletInfoAdapter extends RecyclerView.Adapter<WalletInfoAdapter.Vi
}
}
@NonNull
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
@ -105,21 +106,20 @@ public class WalletInfoAdapter extends RecyclerView.Adapter<WalletInfoAdapter.Vi
}
public void setInfos(List<WalletManager.WalletInfo> 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<WalletManager.WalletInfo> diffCallback = new WalletInfoAdapter.WalletInfoDiff(infoItems,newItems);
final DiffCallback<WalletManager.WalletInfo> 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<WalletInfoAdapter.Vi
tvName = itemView.findViewById(R.id.tvName);
tvAddress = itemView.findViewById(R.id.tvAddress);
ibOptions = itemView.findViewById(R.id.ibOptions);
ibOptions.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
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(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
if (listener != null) {
return listener.onContextInteraction(item, infoItem);
}
return false;
}
});
//displaying the popup
popup.show();
popup.setOnDismissListener(new PopupMenu.OnDismissListener() {
@Override
public void onDismiss(PopupMenu menu) {
popupOpen = false;
}
});
ibOptions.setOnClickListener(view -> {
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);
}