diff --git a/app/src/main/java/com/m2049r/xmrwallet/NodeFragment.java b/app/src/main/java/com/m2049r/xmrwallet/NodeFragment.java index 74c7dacd..f5eda553 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/NodeFragment.java +++ b/app/src/main/java/com/m2049r/xmrwallet/NodeFragment.java @@ -59,6 +59,7 @@ import java.text.NumberFormat; import java.util.Collection; import java.util.HashSet; import java.util.Iterator; +import java.util.Objects; import java.util.Set; import timber.log.Timber; @@ -214,9 +215,15 @@ public class NodeFragment extends Fragment nodeItem.setFavourite(true); activityCallback.setFavouriteNodes(nodeList); } - nodeItem.setSelected(true); - activityCallback.setNode(nodeItem); // this marks it as selected & saves it as well - nodesAdapter.dataSetChanged(); // to refresh test results + AsyncTask.execute(() -> { + activityCallback.setNode(nodeItem); // this marks it as selected & saves it as well + nodeItem.setSelecting(false); + try { + Objects.requireNonNull(getActivity()).runOnUiThread(() -> nodesAdapter.allowClick(true)); + } catch (NullPointerException ex) { + // it's ok + } + }); } // open up edit dialog diff --git a/app/src/main/java/com/m2049r/xmrwallet/data/NodeInfo.java b/app/src/main/java/com/m2049r/xmrwallet/data/NodeInfo.java index 75319738..b4d8d7ae 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/data/NodeInfo.java +++ b/app/src/main/java/com/m2049r/xmrwallet/data/NodeInfo.java @@ -36,6 +36,8 @@ import java.util.Comparator; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import lombok.Getter; +import lombok.Setter; import okhttp3.HttpUrl; import okhttp3.MediaType; import okhttp3.OkHttpClient; @@ -49,12 +51,21 @@ public class NodeInfo extends Node { final static public int MIN_MAJOR_VERSION = 14; final static public String RPC_VERSION = "2.0"; + @Getter private long height = 0; + @Getter private long timestamp = 0; + @Getter private int majorVersion = 0; + @Getter private double responseTime = Double.MAX_VALUE; + @Getter private int responseCode = 0; + @Getter private boolean tested = false; + @Getter + @Setter + private boolean selecting = false; public void clear() { height = 0; @@ -65,10 +76,6 @@ public class NodeInfo extends Node { tested = false; } - public boolean isTested() { - return tested; - } - static public NodeInfo fromString(String nodeString) { try { return new NodeInfo(nodeString); @@ -118,26 +125,6 @@ public class NodeInfo extends Node { super(); } - public long getHeight() { - return height; - } - - public long getTimestamp() { - return timestamp; - } - - public int getMajorVersion() { - return majorVersion; - } - - public double getResponseTime() { - return responseTime; - } - - public int getResponseCode() { - return responseCode; - } - public boolean isSuccessful() { return (responseCode >= 200) && (responseCode < 300); } 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 b1643b36..c3eb2446 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/layout/NodeInfoAdapter.java +++ b/app/src/main/java/com/m2049r/xmrwallet/layout/NodeInfoAdapter.java @@ -112,6 +112,7 @@ public class NodeInfoAdapter extends RecyclerView.Adapter<NodeInfoAdapter.ViewHo class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener { final ImageButton ibBookmark; + final View pbBookmark; final TextView tvName; final TextView tvIp; final ImageView ivPing; @@ -120,6 +121,7 @@ public class NodeInfoAdapter extends RecyclerView.Adapter<NodeInfoAdapter.ViewHo ViewHolder(View itemView) { super(itemView); ibBookmark = itemView.findViewById(R.id.ibBookmark); + pbBookmark = itemView.findViewById(R.id.pbBookmark); tvName = itemView.findViewById(R.id.tvName); tvIp = itemView.findViewById(R.id.tvAddress); ivPing = itemView.findViewById(R.id.ivPing); @@ -161,6 +163,7 @@ public class NodeInfoAdapter extends RecyclerView.Adapter<NodeInfoAdapter.ViewHo itemView.setClickable(itemsClickable); itemView.setEnabled(itemsClickable); ibBookmark.setClickable(itemsClickable); + pbBookmark.setVisibility(nodeItem.isSelecting() ? View.VISIBLE : View.INVISIBLE); showStar(); } @@ -169,7 +172,10 @@ public class NodeInfoAdapter extends RecyclerView.Adapter<NodeInfoAdapter.ViewHo if (listener != null) { int position = getAdapterPosition(); // gets item position if (position != RecyclerView.NO_POSITION) { // Check if an item was deleted, but the user clicked it before the UI removed it - listener.onInteraction(view, nodeItems.get(position)); + final NodeInfo node = nodeItems.get(position); + node.setSelecting(true); + allowClick(false); + listener.onInteraction(view, node); } } } diff --git a/app/src/main/res/layout/item_node.xml b/app/src/main/res/layout/item_node.xml index c0d20184..5ec8ec5b 100644 --- a/app/src/main/res/layout/item_node.xml +++ b/app/src/main/res/layout/item_node.xml @@ -7,18 +7,31 @@ android:layout_marginEnd="8dp" android:background="@drawable/selector_login"> - <ImageButton - android:id="@+id/ibBookmark" + <FrameLayout + android:id="@+id/flBookmark" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentStart="true" - android:layout_centerInParent="true" - android:layout_marginStart="8dp" - android:layout_marginEnd="8dp" - android:padding="12dp" - android:background="?android:attr/selectableItemBackgroundBorderless" - android:gravity="center" - android:src="@drawable/ic_favorite_border_24dp" /> + android:layout_centerInParent="true"> + + <ImageButton + android:id="@+id/ibBookmark" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_marginStart="8dp" + android:layout_marginEnd="8dp" + android:background="?android:attr/selectableItemBackgroundBorderless" + android:gravity="center" + android:padding="12dp" + android:src="@drawable/ic_favorite_border_24dp" /> + + <ProgressBar + android:id="@+id/pbBookmark" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:visibility="invisible" /> + + </FrameLayout> <LinearLayout android:id="@+id/llNode" @@ -28,7 +41,7 @@ android:layout_centerInParent="true" android:layout_margin="8dp" android:layout_toStartOf="@+id/ivPing" - android:layout_toEndOf="@id/ibBookmark" + android:layout_toEndOf="@id/flBookmark" android:gravity="start" android:orientation="vertical">