From 2d03983b2194f81f5584c26a515260c1791aff67 Mon Sep 17 00:00:00 2001 From: Thomas Date: Wed, 30 Sep 2020 11:14:05 +0200 Subject: [PATCH] Fix node info --- .../main/java/app/fedilab/mobilizon/MainActivity.java | 9 +++++++++ .../app/fedilab/mobilizon/client/MobilizonService.java | 2 +- .../fedilab/mobilizon/client/RetrofitMobilizonAPI.java | 10 ++++++---- app/src/main/res/values/colors.xml | 4 ++-- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/app/fedilab/mobilizon/MainActivity.java b/app/src/main/java/app/fedilab/mobilizon/MainActivity.java index 45fdcab..46745c8 100644 --- a/app/src/main/java/app/fedilab/mobilizon/MainActivity.java +++ b/app/src/main/java/app/fedilab/mobilizon/MainActivity.java @@ -118,6 +118,14 @@ public class MainActivity extends AppCompatActivity { } } + @Override + public void onBackPressed() { + if( main_webview.canGoBack()){ + main_webview.goBack(); + } else { + super.onBackPressed(); + } + } @SuppressLint("ApplySharedPref") private void showRadioButtonDialogFullInstances() { @@ -143,6 +151,7 @@ public class MainActivity extends AppCompatActivity { editor.commit(); runOnUiThread(() -> { dialog.dismiss(); + main_webview.clearHistory(); main_webview.loadUrl("https://"+instance); }); } else { diff --git a/app/src/main/java/app/fedilab/mobilizon/client/MobilizonService.java b/app/src/main/java/app/fedilab/mobilizon/client/MobilizonService.java index 095af03..4359685 100644 --- a/app/src/main/java/app/fedilab/mobilizon/client/MobilizonService.java +++ b/app/src/main/java/app/fedilab/mobilizon/client/MobilizonService.java @@ -14,6 +14,6 @@ interface MobilizonService { Call getWellKnownNodeinfo(); @GET("{nodeInfoPath}") - Call getNodeinfo(@Path("nodeInfoPath") String nodeInfoPath); + Call getNodeinfo(@Path(value = "nodeInfoPath", encoded = true) String nodeInfoPath); } diff --git a/app/src/main/java/app/fedilab/mobilizon/client/RetrofitMobilizonAPI.java b/app/src/main/java/app/fedilab/mobilizon/client/RetrofitMobilizonAPI.java index 21a8acd..7affddd 100644 --- a/app/src/main/java/app/fedilab/mobilizon/client/RetrofitMobilizonAPI.java +++ b/app/src/main/java/app/fedilab/mobilizon/client/RetrofitMobilizonAPI.java @@ -15,7 +15,6 @@ package app.fedilab.mobilizon.client; * see . */ import android.content.Context; - import java.io.IOException; import java.net.URL; @@ -34,16 +33,18 @@ public class RetrofitMobilizonAPI { private String instance; + public RetrofitMobilizonAPI(Context context) { _context = context; instance = Helper.getLiveInstance(context); finalUrl = "https://" + Helper.getLiveInstance(context) + "/api/v1/"; } + public RetrofitMobilizonAPI(Context context, String instance) { _context = context; this.instance = instance; - finalUrl = "https://" + instance + "/api/v1/"; + finalUrl = "https://" + instance.toLowerCase() + "/"; } private MobilizonService init() { @@ -55,13 +56,13 @@ public class RetrofitMobilizonAPI { } + /** * Get NodeInfo * * @return APIResponse */ public WellKnownNodeinfo.NodeInfo getNodeInfo() { - finalUrl = "https://" + instance+"/"; MobilizonService mobilizonService = init(); try { Call wellKnownNodeinfoCall = mobilizonService.getWellKnownNodeinfo(); @@ -70,8 +71,9 @@ public class RetrofitMobilizonAPI { int size = response.body().getLinks().size(); String url = response.body().getLinks().get(size-1).getHref(); if (size > 0 && url != null) { + mobilizonService = init(); String path = new URL(url).getPath(); - path = path.replaceFirst("/", ""); + path = path.replaceFirst("/", "").trim(); Call nodeinfo = mobilizonService.getNodeinfo(path); Response responseNodeInfo = nodeinfo.execute(); return responseNodeInfo.body(); diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 0f0177a..b2568b1 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -1,6 +1,6 @@ #474467 - #1e7d97 - #ffd599 + #ffd599 + #1e7d97 \ No newline at end of file