From d446081331ae1e9effffc63c3f232ca16fff5611 Mon Sep 17 00:00:00 2001 From: Thomas Date: Sun, 3 Jan 2021 10:02:11 +0100 Subject: [PATCH] Small fix --- .../fedilab/fedilabtube/LoginActivity.java | 25 ++++++++++++++++--- .../MastodonWebviewConnectActivity.java | 11 ++++++++ .../fedilabtube/WebviewConnectActivity.java | 12 +++++++++ 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/app/fedilab/fedilabtube/LoginActivity.java b/app/src/main/java/app/fedilab/fedilabtube/LoginActivity.java index 8463ebc..310ea22 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/LoginActivity.java +++ b/app/src/main/java/app/fedilab/fedilabtube/LoginActivity.java @@ -78,7 +78,6 @@ public class LoginActivity extends AppCompatActivity { SpannableString content_create; - //noinspection ConstantConditions if (BuildConfig.FLAVOR.compareTo("queermotion") == 0) { content_create = new SpannableString(getString(R.string.register_account)); } else { @@ -101,7 +100,6 @@ public class LoginActivity extends AppCompatActivity { if (BuildConfig.full_instances && BuildConfig.instance_switcher) { binding.loginInstanceContainer.setVisibility(View.VISIBLE); } - //noinspection ConstantConditions if (BuildConfig.FLAVOR.compareTo("queermotion") == 0) { binding.loginInstance.setText("queermotion.org"); } @@ -121,7 +119,6 @@ public class LoginActivity extends AppCompatActivity { binding.loginPasswdContainer.setLayoutParams(layoutParamsP); } - if (!BuildConfig.full_instances) { binding.loginUid.setOnFocusChangeListener((v, hasFocus) -> { if (!hasFocus) { @@ -173,7 +170,27 @@ public class LoginActivity extends AppCompatActivity { } }); } - + if (BuildConfig.allow_remote_connections) { + binding.loginInstance.setOnFocusChangeListener((v, hasFocus) -> { + if (!hasFocus) { + if (binding.loginInstance.getText() != null) { + new Thread(() -> { + String testInstance = binding.loginInstance.getText().toString(); + WellKnownNodeinfo.NodeInfo instanceNodeInfo = null; + if (BuildConfig.allow_remote_connections) { + instanceNodeInfo = new RetrofitPeertubeAPI(LoginActivity.this, testInstance, null).getNodeInfo(); + } + if (instanceNodeInfo != null && + (instanceNodeInfo.getSoftware().getName().toUpperCase().trim().compareTo("MASTODON") == 0 || + instanceNodeInfo.getSoftware().getName().toUpperCase().trim().compareTo("PLEROMA") == 0) + ) { + connectToFediverse(testInstance, instanceNodeInfo); + } + }).start(); + } + } + }); + } binding.loginButton.setOnClickListener(v -> { if (!BuildConfig.full_instances) { diff --git a/app/src/main/java/app/fedilab/fedilabtube/MastodonWebviewConnectActivity.java b/app/src/main/java/app/fedilab/fedilabtube/MastodonWebviewConnectActivity.java index e5aae6c..017aeb9 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/MastodonWebviewConnectActivity.java +++ b/app/src/main/java/app/fedilab/fedilabtube/MastodonWebviewConnectActivity.java @@ -23,6 +23,7 @@ import android.content.SharedPreferences; import android.net.Uri; import android.os.Build; import android.os.Bundle; +import android.view.MenuItem; import android.webkit.CookieManager; import android.webkit.CookieSyncManager; import android.webkit.WebChromeClient; @@ -160,6 +161,16 @@ public class MastodonWebviewConnectActivity extends AppCompatActivity { webView.loadUrl(redirectUserToAuthorizeAndLogin(clientId, instance)); } + @Override + public boolean onOptionsItemSelected(MenuItem item) { + int itemId = item.getItemId(); + if (itemId == android.R.id.home) { + finish(); + return true; + } + return super.onOptionsItemSelected(item); + } + @Override public void onBackPressed() { if (webView != null && webView.canGoBack()) { diff --git a/app/src/main/java/app/fedilab/fedilabtube/WebviewConnectActivity.java b/app/src/main/java/app/fedilab/fedilabtube/WebviewConnectActivity.java index 28ee24a..1878487 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/WebviewConnectActivity.java +++ b/app/src/main/java/app/fedilab/fedilabtube/WebviewConnectActivity.java @@ -19,6 +19,7 @@ import android.content.Context; import android.content.SharedPreferences; import android.os.Build; import android.os.Bundle; +import android.view.MenuItem; import android.webkit.CookieManager; import android.webkit.CookieSyncManager; import android.webkit.WebChromeClient; @@ -158,6 +159,17 @@ public class WebviewConnectActivity extends AppCompatActivity { } + @Override + public boolean onOptionsItemSelected(MenuItem item) { + int itemId = item.getItemId(); + if (itemId == android.R.id.home) { + finish(); + return true; + } + return super.onOptionsItemSelected(item); + } + + @Override public void onBackPressed() { if (webView != null && webView.canGoBack()) {