From fad1567c612579a5f16290729dae66810b794106 Mon Sep 17 00:00:00 2001 From: Mas7erMind Date: Thu, 7 Mar 2024 07:25:58 -0500 Subject: [PATCH] fix remote nodes connection --- app/build.gradle | 19 ++++++------ .../io/scalaproject/vault/LoginActivity.java | 29 +++++++++---------- .../io/scalaproject/vault/NodeFragment.java | 3 +- .../vault/ScalaVaultApplication.java | 4 +++ .../io/scalaproject/vault/util/Helper.java | 3 ++ 5 files changed, 32 insertions(+), 26 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 22ffe2ad..c3810108 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -4,11 +4,11 @@ android { defaultConfig { applicationId "io.scalaproject.vault" buildToolsVersion = '34.0.0' - compileSdk 33 + compileSdk 34 minSdkVersion 21 - targetSdkVersion 33 - versionCode 13 - versionName "1.1.2" + targetSdkVersion 34 + versionCode 14 + versionName "1.1.3" testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' externalNativeBuild { @@ -115,16 +115,15 @@ android { } dependencies { - //noinspection GradleDependency - implementation 'com.google.android.material:material:1.0.0' // keep version 1.0.0 as it fixes a bug with Material Button + + implementation 'com.google.android.material:material:1.11.0' // keep version 1.0.0 as it fixes a bug with Material Button implementation "com.android.support:support-v4" implementation "com.android.support:recyclerview-v7" implementation 'androidx.cardview:cardview:1.0.0' implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0' - //noinspection GradleDependency - implementation 'com.google.android.material:material:1.1.0' // keep version 1.1.0 as it fixes a bug with Material Button - //noinspection GradleDependency - implementation 'androidx.appcompat:appcompat:1.1.0' // keep version 1.1.0 as it fixes a bug with Material Button + + implementation 'com.google.android.material:material:1.11.0' // keep version 1.1.0 as it fixes a bug with Material Button + implementation 'androidx.appcompat:appcompat:1.6.1' // keep version 1.1.0 as it fixes a bug with Material Button implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation 'me.dm7.barcodescanner:zxing:1.9.8' diff --git a/app/src/main/java/io/scalaproject/vault/LoginActivity.java b/app/src/main/java/io/scalaproject/vault/LoginActivity.java index c9b99d4b..ef40b2b3 100644 --- a/app/src/main/java/io/scalaproject/vault/LoginActivity.java +++ b/app/src/main/java/io/scalaproject/vault/LoginActivity.java @@ -106,10 +106,10 @@ public class LoginActivity extends BaseActivity // to the IPNS gateway as well. static private final String IPNS_NAME = "node-list.scala.network"; static private final String[] NODES_REPOSITORY_IPNS_GATEWAYS = { - "https://dweb.link/ipns/", + "https://cloudflare-ipfs.com/ipns/", "https://ipfs.io/ipns/", "https://gateway.ipfs.io/ipns/", - "https://cloudflare-ipfs.com/ipns/" + "https://dweb.link/ipns/" }; static private final String DEFAULT_NODE = "{\n" + @@ -249,21 +249,20 @@ public void loadDefaultNodes() { String jsonString = ""; - // Load Pools data from IPFS gateways - for (String strNodeURLDir : NODES_REPOSITORY_IPNS_GATEWAYS) { - String strNodeURL = strNodeURLDir + IPNS_NAME; - if(Helper.isURLReachable(strNodeURL)) { - jsonString = Helper.fetchJSON(strNodeURL); - if (!jsonString.isEmpty()) - break; - } - } + // Load Pools data from the GitHub repository by default + if(Helper.isURLReachable(DEFAULT_NODES_REPOSITORY)) + jsonString = Helper.fetchJSON(DEFAULT_NODES_REPOSITORY); - // If IPFS is not available or is blocked by firewalls, use GitHub raw file + // If GitHub file is not available or is blocked by firewalls, use IPFS if(jsonString.isEmpty()) { - // Load Pools data from repository - if(Helper.isURLReachable(DEFAULT_NODES_REPOSITORY)) - jsonString = Helper.fetchJSON(DEFAULT_NODES_REPOSITORY); + for (String strNodeURLDir : NODES_REPOSITORY_IPNS_GATEWAYS) { + String strNodeURL = strNodeURLDir + IPNS_NAME; + if(Helper.isURLReachable(strNodeURL)) { + jsonString = Helper.fetchJSON(strNodeURL); + if (!jsonString.isEmpty()) + break; + } + } } // None of the URL can be reached. Load default data but don't cache it. diff --git a/app/src/main/java/io/scalaproject/vault/NodeFragment.java b/app/src/main/java/io/scalaproject/vault/NodeFragment.java index 93f7341e..e4867a73 100644 --- a/app/src/main/java/io/scalaproject/vault/NodeFragment.java +++ b/app/src/main/java/io/scalaproject/vault/NodeFragment.java @@ -452,7 +452,8 @@ private void complete() { nodesAdapter.allowClick(true); selectedNodeView = rvNodes.getChildAt(0);; - selectedNode = nodesAdapter.getNodes().get(0); + if(!nodesAdapter.getNodes().isEmpty()) + selectedNode = nodesAdapter.getNodes().get(0); setItemNodeLayout(selectedNodeView, true); Config.write(Config.CONFIG_KEY_USER_SELECTED_NODE, ""); diff --git a/app/src/main/java/io/scalaproject/vault/ScalaVaultApplication.java b/app/src/main/java/io/scalaproject/vault/ScalaVaultApplication.java index 50b564da..92ee48bc 100644 --- a/app/src/main/java/io/scalaproject/vault/ScalaVaultApplication.java +++ b/app/src/main/java/io/scalaproject/vault/ScalaVaultApplication.java @@ -44,6 +44,10 @@ public void onCreate() { super.onCreate(); SharedPreferences preferences = getSharedPreferences(getPackageName() + "_preferences", MODE_PRIVATE); Config.initialize(preferences); + + /*if (BuildConfig.DEBUG) { + Timber.plant(new Timber.DebugTree()); + }*/ } @Override diff --git a/app/src/main/java/io/scalaproject/vault/util/Helper.java b/app/src/main/java/io/scalaproject/vault/util/Helper.java index 5234b197..0d408406 100644 --- a/app/src/main/java/io/scalaproject/vault/util/Helper.java +++ b/app/src/main/java/io/scalaproject/vault/util/Helper.java @@ -682,7 +682,10 @@ static public boolean isURLReachable(String strURL) { try { URL url = new URL(strURL); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setReadTimeout(2000); return connection.getResponseCode() == 200; + } catch (java.net.SocketTimeoutException e) { + return false; } catch (IOException e) { e.printStackTrace(); return false;