mirror of
https://github.com/m2049r/xmrwallet
synced 2025-09-03 08:23:04 +02:00
Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
d94d6e6925 | ||
![]() |
4a819cc159 | ||
![]() |
f40c3d6c6d | ||
![]() |
82b25df7ad | ||
![]() |
08f815e830 | ||
![]() |
4e59be2dff | ||
![]() |
45c5883e11 | ||
![]() |
067a23e6a5 | ||
![]() |
d21fd41c44 |
@@ -1,14 +1,14 @@
|
||||
apply plugin: 'com.android.application'
|
||||
|
||||
android {
|
||||
compileSdkVersion 28
|
||||
compileSdkVersion 29
|
||||
buildToolsVersion '29.0.2'
|
||||
defaultConfig {
|
||||
applicationId "com.m2049r.xmrwallet"
|
||||
minSdkVersion 21
|
||||
targetSdkVersion 28
|
||||
versionCode 503
|
||||
versionName "1.15.3 'Dark Fork'"
|
||||
targetSdkVersion 29
|
||||
versionCode 602
|
||||
versionName "1.16.2 'Karmic Nodes'"
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
@@ -112,17 +112,17 @@ android {
|
||||
dependencies {
|
||||
implementation 'androidx.core:core:1.3.2'
|
||||
implementation 'androidx.appcompat:appcompat:1.2.0'
|
||||
implementation group: 'com.google.android.material', name: 'material', version: '1.3.0-alpha03'
|
||||
implementation 'com.google.android.material:material:1.3.0-alpha03'
|
||||
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
|
||||
implementation 'androidx.recyclerview:recyclerview:1.1.0'
|
||||
implementation 'androidx.cardview:cardview:1.0.0'
|
||||
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.2.0-alpha01'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
|
||||
|
||||
implementation 'me.dm7.barcodescanner:zxing:1.9.8'
|
||||
implementation "com.squareup.okhttp3:okhttp:$rootProject.ext.okHttpVersion"
|
||||
implementation "com.burgstaller:okhttp-digest:2.0"
|
||||
implementation "com.jakewharton.timber:timber:$rootProject.ext.timberVersion"
|
||||
implementation "com.squareup.okhttp3:okhttp:4.9.0"
|
||||
implementation "com.burgstaller:okhttp-digest:2.1"
|
||||
implementation "com.jakewharton.timber:timber:4.7.1"
|
||||
|
||||
implementation 'com.nulab-inc:zxcvbn:1.3.0'
|
||||
|
||||
@@ -131,12 +131,14 @@ dependencies {
|
||||
implementation 'org.slf4j:slf4j-nop:1.7.30'
|
||||
implementation 'com.github.brnunes:swipeablerecyclerview:1.0.2'
|
||||
|
||||
// https://mvnrepository.com/artifact/com.github.aelstad/keccakj
|
||||
implementation 'com.github.aelstad:keccakj:1.1.0'
|
||||
|
||||
testImplementation "junit:junit:$rootProject.ext.junitVersion"
|
||||
testImplementation "org.mockito:mockito-all:$rootProject.ext.mockitoVersion"
|
||||
testImplementation "com.squareup.okhttp3:mockwebserver:$rootProject.ext.okHttpVersion"
|
||||
testImplementation "com.squareup.okhttp3:mockwebserver:4.9.0"
|
||||
testImplementation 'org.json:json:20180813'
|
||||
testImplementation 'net.jodah:concurrentunit:0.4.4'
|
||||
|
||||
compileOnly 'org.projectlombok:lombok:1.18.16'
|
||||
annotationProcessor 'org.projectlombok:lombok:1.18.16'
|
||||
}
|
||||
|
@@ -13,6 +13,7 @@
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||
|
||||
<application
|
||||
android:requestLegacyExternalStorage="true"
|
||||
android:name=".XmrWalletApplication"
|
||||
android:allowBackup="false"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
|
@@ -185,7 +185,6 @@ public class Dispatcher implements PeerRetriever.OnGetPeers {
|
||||
|
||||
public void seedPeers(Collection<NodeInfo> seedNodes) {
|
||||
for (NodeInfo node : seedNodes) {
|
||||
node.clear();
|
||||
if (node.isFavourite()) {
|
||||
rpcNodes.add(node);
|
||||
if (listener != null) listener.onGet(node);
|
||||
|
@@ -46,6 +46,7 @@ import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||
import com.m2049r.xmrwallet.data.DefaultNodes;
|
||||
import com.m2049r.xmrwallet.data.Node;
|
||||
import com.m2049r.xmrwallet.data.NodeInfo;
|
||||
import com.m2049r.xmrwallet.dialog.AboutFragment;
|
||||
@@ -74,6 +75,7 @@ import java.io.IOException;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
@@ -90,6 +92,7 @@ public class LoginActivity extends BaseActivity
|
||||
private static final String GENERATE_STACK = "gen";
|
||||
|
||||
private static final String NODES_PREFS_NAME = "nodes";
|
||||
private static final String SELECTED_NODE_PREFS_NAME = "selected_node";
|
||||
private static final String PREF_DAEMON_TESTNET = "daemon_testnet";
|
||||
private static final String PREF_DAEMON_STAGENET = "daemon_stagenet";
|
||||
private static final String PREF_DAEMON_MAINNET = "daemon_mainnet";
|
||||
@@ -105,10 +108,21 @@ public class LoginActivity extends BaseActivity
|
||||
|
||||
@Override
|
||||
public void setNode(NodeInfo node) {
|
||||
if ((node != null) && (node.getNetworkType() != WalletManager.getInstance().getNetworkType()))
|
||||
throw new IllegalArgumentException("network type does not match");
|
||||
this.node = node;
|
||||
WalletManager.getInstance().setDaemon(node);
|
||||
setNode(node, true);
|
||||
}
|
||||
|
||||
private void setNode(NodeInfo node, boolean save) {
|
||||
if (node != this.node) {
|
||||
if ((node != null) && (node.getNetworkType() != WalletManager.getInstance().getNetworkType()))
|
||||
throw new IllegalArgumentException("network type does not match");
|
||||
this.node = node;
|
||||
for (NodeInfo nodeInfo : favouriteNodes) {
|
||||
nodeInfo.setSelected(nodeInfo == node);
|
||||
}
|
||||
WalletManager.getInstance().setDaemon(node);
|
||||
if (save)
|
||||
saveSelectedNode();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -117,7 +131,22 @@ public class LoginActivity extends BaseActivity
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFavouriteNodes(Set<NodeInfo> nodes) {
|
||||
public Set<NodeInfo> getOrPopulateFavourites() {
|
||||
if (favouriteNodes.isEmpty()) {
|
||||
for (DefaultNodes node : DefaultNodes.values()) {
|
||||
NodeInfo nodeInfo = NodeInfo.fromString(node.getUri());
|
||||
if (nodeInfo != null) {
|
||||
nodeInfo.setFavourite(true);
|
||||
favouriteNodes.add(nodeInfo);
|
||||
}
|
||||
}
|
||||
saveFavourites();
|
||||
}
|
||||
return favouriteNodes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFavouriteNodes(Collection<NodeInfo> nodes) {
|
||||
Timber.d("adding %d nodes", nodes.size());
|
||||
favouriteNodes.clear();
|
||||
for (NodeInfo node : nodes) {
|
||||
@@ -125,38 +154,31 @@ public class LoginActivity extends BaseActivity
|
||||
if (node.isFavourite())
|
||||
favouriteNodes.add(node);
|
||||
}
|
||||
if (favouriteNodes.isEmpty() && (!nodes.isEmpty())) { // no favourites - pick best ones
|
||||
List<NodeInfo> nodeList = new ArrayList<>(nodes);
|
||||
Collections.sort(nodeList, NodeInfo.BestNodeComparator);
|
||||
int i = 0;
|
||||
for (NodeInfo node : nodeList) {
|
||||
Timber.d("adding %s", node);
|
||||
node.setFavourite(true);
|
||||
favouriteNodes.add(node);
|
||||
if (++i >= 3) break; // add max first 3 nodes
|
||||
}
|
||||
Toast.makeText(this, getString(R.string.node_nobookmark, i), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
saveFavourites();
|
||||
}
|
||||
|
||||
private void loadFavouritesWithNetwork() {
|
||||
Helper.runWithNetwork(new Helper.Action() {
|
||||
@Override
|
||||
public boolean run() {
|
||||
loadFavourites();
|
||||
return true;
|
||||
}
|
||||
Helper.runWithNetwork(() -> {
|
||||
loadFavourites();
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
private void loadFavourites() {
|
||||
Timber.d("loadFavourites");
|
||||
favouriteNodes.clear();
|
||||
final String selectedNodeId = getSelectedNodeId();
|
||||
Map<String, ?> storedNodes = getSharedPreferences(NODES_PREFS_NAME, Context.MODE_PRIVATE).getAll();
|
||||
for (Map.Entry<String, ?> nodeEntry : storedNodes.entrySet()) {
|
||||
if (nodeEntry != null) // just in case, ignore possible future errors
|
||||
addFavourite((String) nodeEntry.getValue());
|
||||
if (nodeEntry != null) { // just in case, ignore possible future errors
|
||||
final String nodeId = (String) nodeEntry.getValue();
|
||||
final NodeInfo addedNode = addFavourite(nodeId);
|
||||
if (addedNode != null) {
|
||||
if (nodeId.equals(selectedNodeId)) {
|
||||
addedNode.setSelected(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (storedNodes.isEmpty()) { // try to load legacy list & remove it (i.e. migrate the data once)
|
||||
SharedPreferences sharedPref = getPreferences(Context.MODE_PRIVATE);
|
||||
@@ -180,13 +202,12 @@ public class LoginActivity extends BaseActivity
|
||||
}
|
||||
|
||||
private void saveFavourites() {
|
||||
List<Node> favourites = new ArrayList<>();
|
||||
Timber.d("SAVE");
|
||||
SharedPreferences.Editor editor = getSharedPreferences(NODES_PREFS_NAME, Context.MODE_PRIVATE).edit();
|
||||
editor.clear();
|
||||
int i = 1;
|
||||
for (Node info : favouriteNodes) {
|
||||
String nodeString = info.toNodeString();
|
||||
final String nodeString = info.toNodeString();
|
||||
editor.putString(Integer.toString(i), nodeString);
|
||||
Timber.d("saved %d:%s", i, nodeString);
|
||||
i++;
|
||||
@@ -194,13 +215,14 @@ public class LoginActivity extends BaseActivity
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
private void addFavourite(String nodeString) {
|
||||
NodeInfo nodeInfo = NodeInfo.fromString(nodeString);
|
||||
private NodeInfo addFavourite(String nodeString) {
|
||||
final NodeInfo nodeInfo = NodeInfo.fromString(nodeString);
|
||||
if (nodeInfo != null) {
|
||||
nodeInfo.setFavourite(true);
|
||||
favouriteNodes.add(nodeInfo);
|
||||
} else
|
||||
Timber.w("nodeString invalid: %s", nodeString);
|
||||
return nodeInfo;
|
||||
}
|
||||
|
||||
private void loadLegacyList(final String legacyListString) {
|
||||
@@ -211,6 +233,34 @@ public class LoginActivity extends BaseActivity
|
||||
}
|
||||
}
|
||||
|
||||
private void saveSelectedNode() { // save only if changed
|
||||
final NodeInfo nodeInfo = getNode();
|
||||
final String selectedNodeId = getSelectedNodeId();
|
||||
if (nodeInfo != null) {
|
||||
if (!nodeInfo.toNodeString().equals(selectedNodeId))
|
||||
saveSelectedNode(nodeInfo);
|
||||
} else {
|
||||
if (selectedNodeId != null)
|
||||
saveSelectedNode(null);
|
||||
}
|
||||
}
|
||||
|
||||
private void saveSelectedNode(NodeInfo nodeInfo) {
|
||||
SharedPreferences.Editor editor = getSharedPreferences(SELECTED_NODE_PREFS_NAME, Context.MODE_PRIVATE).edit();
|
||||
if (nodeInfo == null) {
|
||||
editor.clear();
|
||||
} else {
|
||||
editor.putString("0", getNode().toNodeString());
|
||||
}
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
private String getSelectedNodeId() {
|
||||
return getSharedPreferences(SELECTED_NODE_PREFS_NAME, Context.MODE_PRIVATE)
|
||||
.getString("0", null);
|
||||
}
|
||||
|
||||
|
||||
private Toolbar toolbar;
|
||||
|
||||
@Override
|
||||
@@ -1244,6 +1294,14 @@ public class LoginActivity extends BaseActivity
|
||||
case R.id.action_help_node:
|
||||
HelpFragment.display(getSupportFragmentManager(), R.string.help_node);
|
||||
return true;
|
||||
case R.id.action_default_nodes: {
|
||||
Fragment f = getSupportFragmentManager().findFragmentById(R.id.fragment_container);
|
||||
if ((WalletManager.getInstance().getNetworkType() == NetworkType.NetworkType_Mainnet) &&
|
||||
(f instanceof NodeFragment)) {
|
||||
((NodeFragment) f).restoreDefaultNodes();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case R.id.action_privacy_policy:
|
||||
PrivacyFragment.display(getSupportFragmentManager());
|
||||
return true;
|
||||
@@ -1253,12 +1311,13 @@ public class LoginActivity extends BaseActivity
|
||||
case R.id.action_theme:
|
||||
onChangeTheme();
|
||||
return true;
|
||||
case R.id.action_ledger_seed:
|
||||
case R.id.action_ledger_seed: {
|
||||
Fragment f = getSupportFragmentManager().findFragmentById(R.id.fragment_container);
|
||||
if (f instanceof GenerateFragment) {
|
||||
((GenerateFragment) f).convertLedgerSeed();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
@@ -1310,6 +1369,7 @@ public class LoginActivity extends BaseActivity
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
boolean checkDevice(String walletName, String password) {
|
||||
|
@@ -45,6 +45,7 @@ import com.m2049r.xmrwallet.layout.WalletInfoAdapter;
|
||||
import com.m2049r.xmrwallet.model.WalletManager;
|
||||
import com.m2049r.xmrwallet.util.Helper;
|
||||
import com.m2049r.xmrwallet.util.KeyStoreHelper;
|
||||
import com.m2049r.xmrwallet.util.NodePinger;
|
||||
import com.m2049r.xmrwallet.util.Notice;
|
||||
import com.m2049r.xmrwallet.widget.Toolbar;
|
||||
|
||||
@@ -105,6 +106,8 @@ public class LoginFragment extends Fragment implements WalletInfoAdapter.OnInter
|
||||
|
||||
Set<NodeInfo> getFavouriteNodes();
|
||||
|
||||
Set<NodeInfo> getOrPopulateFavourites();
|
||||
|
||||
boolean hasLedger();
|
||||
}
|
||||
|
||||
@@ -132,11 +135,7 @@ public class LoginFragment extends Fragment implements WalletInfoAdapter.OnInter
|
||||
activityCallback.setTitle(null);
|
||||
activityCallback.setToolbarButton(Toolbar.BUTTON_CREDITS);
|
||||
activityCallback.showNet();
|
||||
NodeInfo node = activityCallback.getNode();
|
||||
if (node == null)
|
||||
findBestNode();
|
||||
else
|
||||
showNode(node);
|
||||
pingSelectedNode();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -186,23 +185,10 @@ public class LoginFragment extends Fragment implements WalletInfoAdapter.OnInter
|
||||
|
||||
pbNode = view.findViewById(R.id.pbNode);
|
||||
llNode = view.findViewById(R.id.llNode);
|
||||
llNode.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (activityCallback.getFavouriteNodes().isEmpty())
|
||||
startNodePrefs();
|
||||
else
|
||||
findBestNode();
|
||||
}
|
||||
});
|
||||
llNode.setOnClickListener(v -> startNodePrefs());
|
||||
tvNodeName = view.findViewById(R.id.tvNodeName);
|
||||
tvNodeAddress = view.findViewById(R.id.tvNodeAddress);
|
||||
view.findViewById(R.id.ibOption).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
startNodePrefs();
|
||||
}
|
||||
});
|
||||
view.findViewById(R.id.ibRenew).setOnClickListener(v -> findBestNode());
|
||||
|
||||
Helper.hideKeyboard(getActivity());
|
||||
|
||||
@@ -421,32 +407,57 @@ public class LoginFragment extends Fragment implements WalletInfoAdapter.OnInter
|
||||
}
|
||||
|
||||
public void findBestNode() {
|
||||
new AsyncFindBestNode().execute();
|
||||
new AsyncFindBestNode().execute(AsyncFindBestNode.FIND_BEST);
|
||||
}
|
||||
|
||||
private class AsyncFindBestNode extends AsyncTask<Void, Void, NodeInfo> {
|
||||
public void pingSelectedNode() {
|
||||
new AsyncFindBestNode().execute(AsyncFindBestNode.PING_SELECTED);
|
||||
}
|
||||
|
||||
private NodeInfo autoselect(Set<NodeInfo> nodes) {
|
||||
if (nodes.isEmpty()) return null;
|
||||
NodePinger.execute(nodes, null);
|
||||
List<NodeInfo> nodeList = new ArrayList<>(nodes);
|
||||
Collections.sort(nodeList, NodeInfo.BestNodeComparator);
|
||||
return nodeList.get(0);
|
||||
}
|
||||
|
||||
private class AsyncFindBestNode extends AsyncTask<Integer, Void, NodeInfo> {
|
||||
final static int PING_SELECTED = 0;
|
||||
final static int FIND_BEST = 1;
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
super.onPreExecute();
|
||||
pbNode.setVisibility(View.VISIBLE);
|
||||
llNode.setVisibility(View.INVISIBLE);
|
||||
activityCallback.setNode(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected NodeInfo doInBackground(Void... params) {
|
||||
List<NodeInfo> nodesToTest = new ArrayList<>(activityCallback.getFavouriteNodes());
|
||||
Timber.d("testing best node from %d", nodesToTest.size());
|
||||
if (nodesToTest.isEmpty()) return null;
|
||||
for (NodeInfo node : nodesToTest) {
|
||||
node.testRpcService(); // TODO: do this in parallel?
|
||||
// no: it's better if it looks like it's doing something
|
||||
}
|
||||
Collections.sort(nodesToTest, NodeInfo.BestNodeComparator);
|
||||
NodeInfo bestNode = nodesToTest.get(0);
|
||||
if (bestNode.isValid()) {
|
||||
activityCallback.setNode(bestNode);
|
||||
return bestNode;
|
||||
protected NodeInfo doInBackground(Integer... params) {
|
||||
Set<NodeInfo> favourites = activityCallback.getOrPopulateFavourites();
|
||||
NodeInfo selectedNode;
|
||||
if (params[0] == FIND_BEST) {
|
||||
selectedNode = autoselect(favourites);
|
||||
} else if (params[0] == PING_SELECTED) {
|
||||
selectedNode = activityCallback.getNode();
|
||||
if (!activityCallback.getFavouriteNodes().contains(selectedNode))
|
||||
selectedNode = null; // it's not in the favourites (any longer)
|
||||
if (selectedNode == null)
|
||||
for (NodeInfo node : favourites) {
|
||||
if (node.isSelected()) {
|
||||
selectedNode = node;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (selectedNode == null) { // autoselect
|
||||
selectedNode = autoselect(favourites);
|
||||
} else
|
||||
selectedNode.testRpcService();
|
||||
} else throw new IllegalStateException();
|
||||
if ((selectedNode != null) && selectedNode.isValid()) {
|
||||
activityCallback.setNode(selectedNode);
|
||||
return selectedNode;
|
||||
} else {
|
||||
activityCallback.setNode(null);
|
||||
return null;
|
||||
@@ -462,17 +473,10 @@ public class LoginFragment extends Fragment implements WalletInfoAdapter.OnInter
|
||||
Timber.d("found a good node %s", result.toString());
|
||||
showNode(result);
|
||||
} else {
|
||||
if (!activityCallback.getFavouriteNodes().isEmpty()) {
|
||||
tvNodeName.setText(getResources().getText(R.string.node_refresh_hint));
|
||||
tvNodeName.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_refresh_black_24dp, 0, 0, 0);
|
||||
tvNodeAddress.setText(null);
|
||||
tvNodeAddress.setVisibility(View.GONE);
|
||||
} else {
|
||||
tvNodeName.setText(getResources().getText(R.string.node_create_hint));
|
||||
tvNodeName.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
|
||||
tvNodeAddress.setText(null);
|
||||
tvNodeAddress.setVisibility(View.GONE);
|
||||
}
|
||||
tvNodeName.setText(getResources().getText(R.string.node_create_hint));
|
||||
tvNodeName.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
|
||||
tvNodeAddress.setText(null);
|
||||
tvNodeAddress.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -485,12 +489,11 @@ public class LoginFragment extends Fragment implements WalletInfoAdapter.OnInter
|
||||
private void showNode(NodeInfo nodeInfo) {
|
||||
tvNodeName.setText(nodeInfo.getName());
|
||||
tvNodeName.setCompoundDrawablesWithIntrinsicBounds(NodeInfoAdapter.getPingIcon(nodeInfo), 0, 0, 0);
|
||||
tvNodeAddress.setText(nodeInfo.getAddress());
|
||||
Helper.showTimeDifference(tvNodeAddress, nodeInfo.getTimestamp());
|
||||
tvNodeAddress.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
private void startNodePrefs() {
|
||||
activityCallback.setNode(null);
|
||||
activityCallback.onNodePrefs();
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -610,6 +610,8 @@ public class ReceiveFragment extends Fragment {
|
||||
super.onPostExecute(result);
|
||||
if (dialogOpened)
|
||||
progressCallback.dismissProgressDialog();
|
||||
if (!isAdded()) // never mind then
|
||||
return;
|
||||
tvAddress.setText(newSubaddress);
|
||||
tvAddressLabel.setText(getString(R.string.generate_address_label_sub,
|
||||
wallet.getNumSubaddresses() - 1));
|
||||
|
@@ -579,11 +579,7 @@ public class WalletActivity extends BaseActivity implements WalletFragment.Liste
|
||||
});
|
||||
if (numAccounts != wallet.getNumAccounts()) {
|
||||
numAccounts = wallet.getNumAccounts();
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
updateAccountsList();
|
||||
}
|
||||
});
|
||||
runOnUiThread(this::updateAccountsList);
|
||||
}
|
||||
try {
|
||||
final WalletFragment walletFragment = (WalletFragment)
|
||||
@@ -1055,21 +1051,23 @@ public class WalletActivity extends BaseActivity implements WalletFragment.Liste
|
||||
}
|
||||
|
||||
void updateAccountsList() {
|
||||
final Wallet wallet = getWallet();
|
||||
Menu menu = accountsView.getMenu();
|
||||
menu.removeGroup(R.id.accounts_list);
|
||||
final int n = wallet.getNumAccounts();
|
||||
final boolean showBalances = (n > 1) && !isStreetMode();
|
||||
for (int i = 0; i < n; i++) {
|
||||
final String label = (showBalances ?
|
||||
getString(R.string.label_account, wallet.getAccountLabel(i), Helper.getDisplayAmount(wallet.getBalance(i), 2))
|
||||
: wallet.getAccountLabel(i));
|
||||
final MenuItem item = menu.add(R.id.accounts_list, getAccountId(i), 2 * i, label);
|
||||
item.setIcon(R.drawable.ic_account_balance_wallet_black_24dp);
|
||||
if (i == wallet.getAccountIndex())
|
||||
item.setChecked(true);
|
||||
final Wallet wallet = getWallet();
|
||||
if (wallet != null) {
|
||||
final int n = wallet.getNumAccounts();
|
||||
final boolean showBalances = (n > 1) && !isStreetMode();
|
||||
for (int i = 0; i < n; i++) {
|
||||
final String label = (showBalances ?
|
||||
getString(R.string.label_account, wallet.getAccountLabel(i), Helper.getDisplayAmount(wallet.getBalance(i), 2))
|
||||
: wallet.getAccountLabel(i));
|
||||
final MenuItem item = menu.add(R.id.accounts_list, getAccountId(i), 2 * i, label);
|
||||
item.setIcon(R.drawable.ic_account_balance_wallet_black_24dp);
|
||||
if (i == wallet.getAccountIndex())
|
||||
item.setChecked(true);
|
||||
}
|
||||
menu.setGroupCheckable(R.id.accounts_list, true, true);
|
||||
}
|
||||
menu.setGroupCheckable(R.id.accounts_list, true, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -191,7 +191,7 @@ public class BarcodeData {
|
||||
}
|
||||
}
|
||||
|
||||
if (!Wallet.isAddressValid(address)) {
|
||||
if ((address == null) || !Wallet.isAddressValid(address)) {
|
||||
Timber.d("address invalid");
|
||||
return null;
|
||||
}
|
||||
|
@@ -0,0 +1,19 @@
|
||||
package com.m2049r.xmrwallet.data;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
// Nodes stolen from https://moneroworld.com/#nodes
|
||||
|
||||
@AllArgsConstructor
|
||||
public enum DefaultNodes {
|
||||
MONERUJO("nodex.monerujo.io:18081"),
|
||||
XMRTO("node.xmr.to:18081"),
|
||||
SUPPORTXMR("node.supportxmr.com:18081"),
|
||||
HASHVAULT("nodes.hashvault.pro:18081"),
|
||||
MONEROWORLD("node.moneroworld.com:18089"),
|
||||
XMRTW("opennode.xmr-tw.org:18089");
|
||||
|
||||
@Getter
|
||||
private final String uri;
|
||||
}
|
@@ -26,6 +26,8 @@ import java.net.URLDecoder;
|
||||
import java.net.URLEncoder;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import timber.log.Timber;
|
||||
|
||||
public class Node {
|
||||
@@ -33,15 +35,29 @@ public class Node {
|
||||
static public final String STAGENET = "stagenet";
|
||||
static public final String TESTNET = "testnet";
|
||||
|
||||
@Getter
|
||||
private String name = null;
|
||||
@Getter
|
||||
final private NetworkType networkType;
|
||||
InetAddress hostAddress;
|
||||
@Getter
|
||||
private String host;
|
||||
@Getter
|
||||
@Setter
|
||||
int rpcPort = 0;
|
||||
private int levinPort = 0;
|
||||
@Getter
|
||||
@Setter
|
||||
private String username = "";
|
||||
@Getter
|
||||
@Setter
|
||||
private String password = "";
|
||||
@Getter
|
||||
@Setter
|
||||
private boolean favourite = false;
|
||||
@Getter
|
||||
@Setter
|
||||
private boolean selected = false;
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
@@ -193,7 +209,6 @@ public class Node {
|
||||
this.levinPort = socketAddress.getPort();
|
||||
this.username = "";
|
||||
this.password = "";
|
||||
//this.name = socketAddress.getHostName(); // triggers DNS so we don't do it by default
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
@@ -204,14 +219,6 @@ public class Node {
|
||||
return hostAddress.getHostAddress();
|
||||
}
|
||||
|
||||
public String getHost() {
|
||||
return host;
|
||||
}
|
||||
|
||||
public int getRpcPort() {
|
||||
return rpcPort;
|
||||
}
|
||||
|
||||
public void setHost(String host) throws UnknownHostException {
|
||||
if ((host == null) || (host.isEmpty()))
|
||||
throw new UnknownHostException("loopback not supported (yet?)");
|
||||
@@ -219,18 +226,6 @@ public class Node {
|
||||
this.hostAddress = InetAddress.getByName(host);
|
||||
}
|
||||
|
||||
public void setUsername(String user) {
|
||||
username = user;
|
||||
}
|
||||
|
||||
public void setPassword(String pass) {
|
||||
password = pass;
|
||||
}
|
||||
|
||||
public void setRpcPort(int port) {
|
||||
this.rpcPort = port;
|
||||
}
|
||||
|
||||
public void setName() {
|
||||
if (name == null)
|
||||
this.name = hostAddress.getHostName();
|
||||
@@ -243,30 +238,6 @@ public class Node {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public NetworkType getNetworkType() {
|
||||
return networkType;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public boolean isFavourite() {
|
||||
return favourite;
|
||||
}
|
||||
|
||||
public void setFavourite(boolean favourite) {
|
||||
this.favourite = favourite;
|
||||
}
|
||||
|
||||
public void toggleFavourite() {
|
||||
favourite = !favourite;
|
||||
}
|
||||
|
@@ -21,8 +21,8 @@ import com.burgstaller.okhttp.CachingAuthenticatorDecorator;
|
||||
import com.burgstaller.okhttp.digest.CachingAuthenticator;
|
||||
import com.burgstaller.okhttp.digest.Credentials;
|
||||
import com.burgstaller.okhttp.digest.DigestAuthenticator;
|
||||
import com.m2049r.levin.scanner.Dispatcher;
|
||||
import com.m2049r.levin.scanner.LevinPeer;
|
||||
import com.m2049r.xmrwallet.util.NodePinger;
|
||||
import com.m2049r.xmrwallet.util.OkHttpHelper;
|
||||
|
||||
import org.json.JSONException;
|
||||
@@ -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;
|
||||
@@ -46,14 +48,24 @@ import okhttp3.ResponseBody;
|
||||
import timber.log.Timber;
|
||||
|
||||
public class NodeInfo extends Node {
|
||||
final static public int MIN_MAJOR_VERSION = 11;
|
||||
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;
|
||||
@@ -61,13 +73,13 @@ public class NodeInfo extends Node {
|
||||
responseTime = Double.MAX_VALUE;
|
||||
responseCode = 0;
|
||||
timestamp = 0;
|
||||
tested = false;
|
||||
}
|
||||
|
||||
static public NodeInfo fromString(String nodeString) {
|
||||
try {
|
||||
return new NodeInfo(nodeString);
|
||||
} catch (IllegalArgumentException ex) {
|
||||
Timber.w(ex);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -113,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);
|
||||
}
|
||||
@@ -145,23 +137,20 @@ public class NodeInfo extends Node {
|
||||
return isSuccessful() && (majorVersion >= MIN_MAJOR_VERSION) && (responseTime < Double.MAX_VALUE);
|
||||
}
|
||||
|
||||
static public Comparator<NodeInfo> BestNodeComparator = new Comparator<NodeInfo>() {
|
||||
@Override
|
||||
public int compare(NodeInfo o1, NodeInfo o2) {
|
||||
if (o1.isValid()) {
|
||||
if (o2.isValid()) { // both are valid
|
||||
// higher node wins
|
||||
int heightDiff = (int) (o2.height - o1.height);
|
||||
if (Math.abs(heightDiff) > Dispatcher.HEIGHT_WINDOW)
|
||||
return heightDiff;
|
||||
// if they are (nearly) equal, faster node wins
|
||||
return (int) Math.signum(o1.responseTime - o2.responseTime);
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
static public Comparator<NodeInfo> BestNodeComparator = (o1, o2) -> {
|
||||
if (o1.isValid()) {
|
||||
if (o2.isValid()) { // both are valid
|
||||
// higher node wins
|
||||
int heightDiff = (int) (o2.height - o1.height);
|
||||
if (heightDiff != 0)
|
||||
return heightDiff;
|
||||
// if they are equal, faster node wins
|
||||
return (int) Math.signum(o1.responseTime - o2.responseTime);
|
||||
} else {
|
||||
return 1;
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -192,7 +181,7 @@ public class NodeInfo extends Node {
|
||||
}
|
||||
|
||||
private static final int HTTP_TIMEOUT = OkHttpHelper.HTTP_TIMEOUT;
|
||||
public static final double PING_GOOD = HTTP_TIMEOUT / 3; //ms
|
||||
public static final double PING_GOOD = HTTP_TIMEOUT / 3.0; //ms
|
||||
public static final double PING_MEDIUM = 2 * PING_GOOD; //ms
|
||||
public static final double PING_BAD = HTTP_TIMEOUT;
|
||||
|
||||
@@ -200,7 +189,15 @@ public class NodeInfo extends Node {
|
||||
return testRpcService(rpcPort);
|
||||
}
|
||||
|
||||
public boolean testRpcService(NodePinger.Listener listener) {
|
||||
boolean result = testRpcService(rpcPort);
|
||||
if (listener != null)
|
||||
listener.publish(this);
|
||||
return result;
|
||||
}
|
||||
|
||||
private boolean testRpcService(int port) {
|
||||
Timber.d("Testing %s", toNodeString());
|
||||
clear();
|
||||
try {
|
||||
OkHttpClient client = OkHttpHelper.getEagerClient();
|
||||
@@ -247,8 +244,9 @@ public class NodeInfo extends Node {
|
||||
}
|
||||
}
|
||||
} catch (IOException | JSONException ex) {
|
||||
// failure
|
||||
Timber.d(ex.getMessage());
|
||||
Timber.d(ex);
|
||||
} finally {
|
||||
tested = true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@@ -17,8 +17,6 @@
|
||||
package com.m2049r.xmrwallet.layout;
|
||||
|
||||
import android.content.Context;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@@ -26,8 +24,13 @@ import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.m2049r.xmrwallet.R;
|
||||
import com.m2049r.xmrwallet.data.NodeInfo;
|
||||
import com.m2049r.xmrwallet.util.ColorHelper;
|
||||
import com.m2049r.xmrwallet.util.Helper;
|
||||
|
||||
import java.net.HttpURLConnection;
|
||||
import java.text.SimpleDateFormat;
|
||||
@@ -35,7 +38,6 @@ import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.TimeZone;
|
||||
|
||||
@@ -44,6 +46,8 @@ public class NodeInfoAdapter extends RecyclerView.Adapter<NodeInfoAdapter.ViewHo
|
||||
|
||||
public interface OnInteractionListener {
|
||||
void onInteraction(View view, NodeInfo item);
|
||||
|
||||
void onLongInteraction(View view, NodeInfo item);
|
||||
}
|
||||
|
||||
private final List<NodeInfo> nodeItems = new ArrayList<>();
|
||||
@@ -106,8 +110,9 @@ public class NodeInfoAdapter extends RecyclerView.Adapter<NodeInfoAdapter.ViewHo
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
||||
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;
|
||||
@@ -116,16 +121,20 @@ 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);
|
||||
ibBookmark.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
nodeItem.toggleFavourite();
|
||||
showStar();
|
||||
ibBookmark.setOnClickListener(v -> {
|
||||
nodeItem.toggleFavourite();
|
||||
showStar();
|
||||
if (!nodeItem.isFavourite()) {
|
||||
nodeItem.setSelected(false);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
itemView.setOnClickListener(this);
|
||||
itemView.setOnLongClickListener(this);
|
||||
}
|
||||
|
||||
private void showStar() {
|
||||
@@ -139,16 +148,22 @@ public class NodeInfoAdapter extends RecyclerView.Adapter<NodeInfoAdapter.ViewHo
|
||||
void bind(int position) {
|
||||
nodeItem = nodeItems.get(position);
|
||||
tvName.setText(nodeItem.getName());
|
||||
final String ts = TS_FORMATTER.format(new Date(nodeItem.getTimestamp() * 1000));
|
||||
ivPing.setImageResource(getPingIcon(nodeItem));
|
||||
if (nodeItem.isValid()) {
|
||||
tvIp.setText(context.getString(R.string.node_height, ts));
|
||||
if (nodeItem.isTested()) {
|
||||
if (nodeItem.isValid()) {
|
||||
Helper.showTimeDifference(tvIp, nodeItem.getTimestamp());
|
||||
} else {
|
||||
tvIp.setText(getResponseErrorText(context, nodeItem.getResponseCode()));
|
||||
tvIp.setTextColor(ColorHelper.getThemedColor(tvIp.getContext(), R.attr.colorError));
|
||||
}
|
||||
} else {
|
||||
tvIp.setText(getResponseErrorText(context, nodeItem.getResponseCode()));
|
||||
tvIp.setText(context.getResources().getString(R.string.node_testing, nodeItem.getHostAddress()));
|
||||
}
|
||||
itemView.setOnClickListener(this);
|
||||
itemView.setSelected(nodeItem.isSelected());
|
||||
itemView.setClickable(itemsClickable);
|
||||
itemView.setEnabled(itemsClickable);
|
||||
ibBookmark.setClickable(itemsClickable);
|
||||
pbBookmark.setVisibility(nodeItem.isSelecting() ? View.VISIBLE : View.INVISIBLE);
|
||||
showStar();
|
||||
}
|
||||
|
||||
@@ -157,10 +172,24 @@ 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onLongClick(View view) {
|
||||
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.onLongInteraction(view, nodeItems.get(position));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
static public int getPingIcon(NodeInfo nodeInfo) {
|
||||
|
@@ -275,6 +275,7 @@ public class WalletManager {
|
||||
return networkType;
|
||||
}
|
||||
|
||||
// this should not be called on the main thread as it connects to the node (and takes a long time)
|
||||
public void setDaemon(Node node) {
|
||||
if (node != null) {
|
||||
this.daemonAddress = node.getAddress();
|
||||
|
@@ -2,6 +2,7 @@ package com.m2049r.xmrwallet.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Color;
|
||||
|
||||
import com.m2049r.xmrwallet.R;
|
||||
|
||||
@@ -10,4 +11,9 @@ public class ColorHelper {
|
||||
TypedArray styledAttributes = ctx.getTheme().obtainStyledAttributes(R.style.MyMaterialTheme, new int[]{attrId});
|
||||
return styledAttributes.getResourceId(0, 0);
|
||||
}
|
||||
|
||||
static public int getThemedColor(Context ctx, int attrId) {
|
||||
TypedArray styledAttributes = ctx.getTheme().obtainStyledAttributes(R.style.MyMaterialTheme, new int[]{attrId});
|
||||
return styledAttributes.getColor(0, Color.BLACK);
|
||||
}
|
||||
}
|
||||
|
@@ -71,6 +71,7 @@ import java.math.BigInteger;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.net.URL;
|
||||
import java.util.Calendar;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
@@ -662,4 +663,30 @@ public class Helper {
|
||||
static public boolean preventScreenshot() {
|
||||
return !(BuildConfig.DEBUG || BuildConfig.FLAVOR_type.equals("alpha"));
|
||||
}
|
||||
|
||||
static public final int STALE_NODE_HOURS = 2;
|
||||
|
||||
static public void showTimeDifference(TextView view, long timeInSeconds) {
|
||||
final Context ctx = view.getContext();
|
||||
final long now = Calendar.getInstance().getTimeInMillis() / 1000;
|
||||
final long secs = (now - timeInSeconds);
|
||||
final long mins = secs / 60; // in minutes
|
||||
final long hours = mins / 60;
|
||||
final long days = hours / 24;
|
||||
String msg;
|
||||
if (mins < 2) {
|
||||
msg = ctx.getString(R.string.node_updated_now, secs);
|
||||
} else if (hours < 2) {
|
||||
msg = ctx.getString(R.string.node_updated_mins, mins);
|
||||
} else if (days < 2) {
|
||||
msg = ctx.getString(R.string.node_updated_hours, hours);
|
||||
} else {
|
||||
msg = ctx.getString(R.string.node_updated_days, days);
|
||||
}
|
||||
view.setText(msg);
|
||||
if (hours >= STALE_NODE_HOURS)
|
||||
view.setTextColor(ColorHelper.getThemedColor(view.getContext(), R.attr.colorError));
|
||||
else
|
||||
view.setTextColor(ColorHelper.getThemedColor(view.getContext(), android.R.attr.textColorPrimary));
|
||||
}
|
||||
}
|
||||
|
53
app/src/main/java/com/m2049r/xmrwallet/util/NodePinger.java
Normal file
53
app/src/main/java/com/m2049r/xmrwallet/util/NodePinger.java
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2018 m2049r
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.m2049r.xmrwallet.util;
|
||||
|
||||
import com.m2049r.xmrwallet.data.NodeInfo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import timber.log.Timber;
|
||||
|
||||
public class NodePinger {
|
||||
static final public int NUM_THREADS = 10;
|
||||
static final public long MAX_TIME = 5L; // seconds
|
||||
|
||||
public interface Listener {
|
||||
void publish(NodeInfo node);
|
||||
}
|
||||
|
||||
static public void execute(Collection<NodeInfo> nodes, final Listener listener) {
|
||||
final ExecutorService exeService = Executors.newFixedThreadPool(NUM_THREADS);
|
||||
List<Callable<Boolean>> taskList = new ArrayList<>();
|
||||
for (NodeInfo node : nodes) {
|
||||
taskList.add(() -> node.testRpcService(listener));
|
||||
}
|
||||
|
||||
try {
|
||||
exeService.invokeAll(taskList, MAX_TIME, TimeUnit.SECONDS);
|
||||
} catch (InterruptedException ex) {
|
||||
Timber.w(ex);
|
||||
}
|
||||
exeService.shutdownNow();
|
||||
}
|
||||
}
|
@@ -119,6 +119,8 @@ public class RestoreHeight {
|
||||
blockheight.put("2020-07-01", 2132318L);
|
||||
blockheight.put("2020-08-01", 2154590L);
|
||||
blockheight.put("2020-09-01", 2176790L);
|
||||
blockheight.put("2020-10-01", 2198370L);
|
||||
blockheight.put("2020-11-01", 2220670L);
|
||||
}
|
||||
|
||||
public long getHeight(String date) {
|
||||
|
@@ -179,7 +179,7 @@ public class ExchangeView extends LinearLayout {
|
||||
|
||||
// make progress circle gray
|
||||
pbExchange.getIndeterminateDrawable().
|
||||
setColorFilter(getResources().getColor(ColorHelper.getThemedResourceId(getContext(), R.attr.colorPrimaryVariant)),
|
||||
setColorFilter(ColorHelper.getThemedColor(getContext(), R.attr.colorPrimaryVariant),
|
||||
android.graphics.PorterDuff.Mode.MULTIPLY);
|
||||
|
||||
sCurrencyA.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||
|
9
app/src/main/res/drawable/ic_renew_24dp.xml
Normal file
9
app/src/main/res/drawable/ic_renew_24dp.xml
Normal file
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="@color/btn_color_selector"
|
||||
android:pathData="M12,6v3l4,-4 -4,-4v3c-4.42,0 -8,3.58 -8,8 0,1.57 0.46,3.03 1.24,4.26L6.7,14.8c-0.45,-0.83 -0.7,-1.79 -0.7,-2.8 0,-3.31 2.69,-6 6,-6zM18.76,7.74L17.3,9.2c0.44,0.84 0.7,1.79 0.7,2.8 0,3.31 -2.69,6 -6,6v-3l-4,4 4,4v-3c4.42,0 8,-3.58 8,-8 0,-1.57 -0.46,-3.03 -1.24,-4.26z" />
|
||||
</vector>
|
@@ -1,9 +0,0 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="@color/btn_color_selector"
|
||||
android:pathData="M15.5,14h-0.79l-0.28,-0.27C15.41,12.59 16,11.11 16,9.5 16,5.91 13.09,3 9.5,3S3,5.91 3,9.5 5.91,16 9.5,16c1.61,0 3.09,-0.59 4.23,-1.57l0.27,0.28v0.79l5,4.99L20.49,19l-4.99,-5zM9.5,14C7.01,14 5,11.99 5,9.5S7.01,5 9.5,5 14,7.01 14,9.5 11.99,14 9.5,14z" />
|
||||
</vector>
|
@@ -6,6 +6,12 @@
|
||||
</shape>
|
||||
</item>
|
||||
|
||||
<item android:state_selected="true">
|
||||
<shape>
|
||||
<solid android:color="@color/monerujoPinkAlpha" />
|
||||
</shape>
|
||||
</item>
|
||||
|
||||
<item android:state_pressed="false">
|
||||
<shape>
|
||||
<solid android:color="@android:color/transparent" />
|
||||
|
@@ -37,7 +37,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_toStartOf="@+id/ibOption">
|
||||
android:layout_toStartOf="@+id/ibRenew">
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/pbNode"
|
||||
@@ -49,7 +49,7 @@
|
||||
android:id="@+id/llNode"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="?android:attr/selectableItemBackgroundBorderless"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
android:gravity="start|center_vertical"
|
||||
android:orientation="vertical">
|
||||
|
||||
@@ -73,7 +73,7 @@
|
||||
</FrameLayout>
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/ibOption"
|
||||
android:id="@+id/ibRenew"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentEnd="true"
|
||||
@@ -81,7 +81,7 @@
|
||||
android:background="?android:attr/selectableItemBackgroundBorderless"
|
||||
android:gravity="center"
|
||||
android:padding="12dp"
|
||||
android:src="@drawable/ic_search_24dp" />
|
||||
android:src="@drawable/ic_renew_24dp" />
|
||||
</RelativeLayout>
|
||||
|
||||
<EditText
|
||||
|
@@ -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">
|
||||
|
||||
|
@@ -8,4 +8,10 @@
|
||||
android:orderInCategory="500"
|
||||
android:title="@string/menu_help"
|
||||
app:showAsAction="ifRoom" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_default_nodes"
|
||||
android:orderInCategory="500"
|
||||
android:title="@string/menu_default_nodes"
|
||||
app:showAsAction="never" />
|
||||
</menu>
|
@@ -399,4 +399,11 @@
|
||||
</string-array>
|
||||
<string name="gunther_says">There is nothing here\nPlease create or restore a wallet</string>
|
||||
|
||||
<string name="menu_default_nodes">Restore default nodes</string>
|
||||
<string name="toast_default_nodes">Restoring already in progress…</string>
|
||||
|
||||
<string name="node_updated_now">Last Block: %1$d seconds ago</string>
|
||||
<string name="node_updated_mins">Last Block: %1$d minutes ago</string>
|
||||
<string name="node_updated_hours">Last Block: %1$d hours ago</string>
|
||||
<string name="node_updated_days">Last Block: %1$d days ago</string>
|
||||
</resources>
|
||||
|
@@ -402,4 +402,11 @@
|
||||
</string-array>
|
||||
<string name="gunther_says">There is nothing here\nPlease create or restore a wallet</string>
|
||||
|
||||
<string name="menu_default_nodes">Restore default nodes</string>
|
||||
<string name="toast_default_nodes">Restoring already in progress…</string>
|
||||
|
||||
<string name="node_updated_now">Last Block: %1$d seconds ago</string>
|
||||
<string name="node_updated_mins">Last Block: %1$d minutes ago</string>
|
||||
<string name="node_updated_hours">Last Block: %1$d hours ago</string>
|
||||
<string name="node_updated_days">Last Block: %1$d days ago</string>
|
||||
</resources>
|
||||
|
@@ -401,4 +401,11 @@
|
||||
</string-array>
|
||||
<string name="gunther_says">There is nothing here\nPlease create or restore a wallet</string>
|
||||
|
||||
<string name="menu_default_nodes">Restore default nodes</string>
|
||||
<string name="toast_default_nodes">Restoring already in progress…</string>
|
||||
|
||||
<string name="node_updated_now">Last Block: %1$d seconds ago</string>
|
||||
<string name="node_updated_mins">Last Block: %1$d minutes ago</string>
|
||||
<string name="node_updated_hours">Last Block: %1$d hours ago</string>
|
||||
<string name="node_updated_days">Last Block: %1$d days ago</string>
|
||||
</resources>
|
||||
|
@@ -401,4 +401,11 @@
|
||||
</string-array>
|
||||
<string name="gunther_says">There is nothing here\nPlease create or restore a wallet</string>
|
||||
|
||||
<string name="menu_default_nodes">Restore default nodes</string>
|
||||
<string name="toast_default_nodes">Restoring already in progress…</string>
|
||||
|
||||
<string name="node_updated_now">Last Block: %1$d seconds ago</string>
|
||||
<string name="node_updated_mins">Last Block: %1$d minutes ago</string>
|
||||
<string name="node_updated_hours">Last Block: %1$d hours ago</string>
|
||||
<string name="node_updated_days">Last Block: %1$d days ago</string>
|
||||
</resources>
|
||||
|
@@ -392,4 +392,11 @@
|
||||
</string-array>
|
||||
<string name="gunther_says">There is nothing here\nPlease create or restore a wallet</string>
|
||||
|
||||
<string name="menu_default_nodes">Restore default nodes</string>
|
||||
<string name="toast_default_nodes">Restoring already in progress…</string>
|
||||
|
||||
<string name="node_updated_now">Last Block: %1$d seconds ago</string>
|
||||
<string name="node_updated_mins">Last Block: %1$d minutes ago</string>
|
||||
<string name="node_updated_hours">Last Block: %1$d hours ago</string>
|
||||
<string name="node_updated_days">Last Block: %1$d days ago</string>
|
||||
</resources>
|
||||
|
@@ -399,4 +399,11 @@
|
||||
</string-array>
|
||||
<string name="gunther_says">There is nothing here\nPlease create or restore a wallet</string>
|
||||
|
||||
<string name="menu_default_nodes">Restore default nodes</string>
|
||||
<string name="toast_default_nodes">Restoring already in progress…</string>
|
||||
|
||||
<string name="node_updated_now">Last Block: %1$d seconds ago</string>
|
||||
<string name="node_updated_mins">Last Block: %1$d minutes ago</string>
|
||||
<string name="node_updated_hours">Last Block: %1$d hours ago</string>
|
||||
<string name="node_updated_days">Last Block: %1$d days ago</string>
|
||||
</resources>
|
||||
|
@@ -405,4 +405,11 @@
|
||||
</string-array>
|
||||
<string name="gunther_says">There is nothing here\nPlease create or restore a wallet</string>
|
||||
|
||||
<string name="menu_default_nodes">Restore default nodes</string>
|
||||
<string name="toast_default_nodes">Restoring already in progress…</string>
|
||||
|
||||
<string name="node_updated_now">Last Block: %1$d seconds ago</string>
|
||||
<string name="node_updated_mins">Last Block: %1$d minutes ago</string>
|
||||
<string name="node_updated_hours">Last Block: %1$d hours ago</string>
|
||||
<string name="node_updated_days">Last Block: %1$d days ago</string>
|
||||
</resources>
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user