diff --git a/app/src/main/java/app/fedilab/fedilabtube/MainActivity.java b/app/src/main/java/app/fedilab/fedilabtube/MainActivity.java index c3ff0c9..4a1117c 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/MainActivity.java +++ b/app/src/main/java/app/fedilab/fedilabtube/MainActivity.java @@ -123,6 +123,22 @@ public class MainActivity extends AppCompatActivity { navView.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener); + Fragment fragment = getSupportFragmentManager().findFragmentByTag("5"); + if(fragment != null) + getSupportFragmentManager().beginTransaction().remove(fragment).commit(); + fragment = getSupportFragmentManager().findFragmentByTag("4"); + if(fragment != null) + getSupportFragmentManager().beginTransaction().remove(fragment).commit(); + fragment = getSupportFragmentManager().findFragmentByTag("3"); + if(fragment != null) + getSupportFragmentManager().beginTransaction().remove(fragment).commit(); + fragment = getSupportFragmentManager().findFragmentByTag("2"); + if(fragment != null) + getSupportFragmentManager().beginTransaction().remove(fragment).commit(); + fragment = getSupportFragmentManager().findFragmentByTag("1"); + if(fragment != null) + getSupportFragmentManager().beginTransaction().remove(fragment).commit(); + recentFragment = new DisplayVideosFragment(); Bundle bundle = new Bundle(); bundle.putSerializable(Helper.TIMELINE_TYPE, TimelineVM.TimelineType.RECENT); @@ -161,7 +177,6 @@ public class MainActivity extends AppCompatActivity { fm.beginTransaction().add(R.id.nav_host_fragment, trendingFragment, "2").hide(trendingFragment).commit(); fm.beginTransaction().add(R.id.nav_host_fragment, overviewFragment, "1").commit(); } - toolbar.setOnClickListener(v->{ if(active instanceof DisplayVideosFragment) { ((DisplayVideosFragment) active).scrollToTop(); diff --git a/app/src/main/java/app/fedilab/fedilabtube/client/PeertubeService.java b/app/src/main/java/app/fedilab/fedilabtube/client/PeertubeService.java index 64a2a27..5da2997 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/client/PeertubeService.java +++ b/app/src/main/java/app/fedilab/fedilabtube/client/PeertubeService.java @@ -66,7 +66,7 @@ public interface PeertubeService { Call getWellKnownNodeinfo(); @GET("{nodeInfoPath}") - Call getNodeinfo(@Path("nodeInfoPath") String nodeInfoPath); + Call getNodeinfo(@Path(value = "nodeInfoPath", encoded = true) String nodeInfoPath); @GET("{captionContent}") Call getCaptionContent(@Path("captionContent") String captionContent); diff --git a/app/src/main/java/app/fedilab/fedilabtube/client/RetrofitPeertubeAPI.java b/app/src/main/java/app/fedilab/fedilabtube/client/RetrofitPeertubeAPI.java index e3de5c9..2e60c35 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/client/RetrofitPeertubeAPI.java +++ b/app/src/main/java/app/fedilab/fedilabtube/client/RetrofitPeertubeAPI.java @@ -25,6 +25,7 @@ import android.os.Looper; import java.io.File; import java.io.IOException; import java.io.UnsupportedEncodingException; +import java.net.URL; import java.net.URLDecoder; import java.util.ArrayList; import java.util.LinkedHashMap; @@ -959,13 +960,18 @@ public class RetrofitPeertubeAPI { * @return APIResponse */ public WellKnownNodeinfo.NodeInfo getNodeInfo() { - PeertubeService peertubeService = init(); + PeertubeService peertubeService = initTranslation(); try { Call wellKnownNodeinfoCall = peertubeService.getWellKnownNodeinfo(); Response response = wellKnownNodeinfoCall.execute(); if (response.isSuccessful() && response.body() != null) { - if (response.body().getHref() != null) { - Call nodeinfo = peertubeService.getNodeinfo(response.body().getHref()); + int size = response.body().getLinks().size(); + String url = response.body().getLinks().get(size - 1).getHref(); + if (size > 0 && url != null) { + peertubeService = initTranslation(); + String path = new URL(url).getPath(); + path = path.replaceFirst("/", "").trim(); + Call nodeinfo = peertubeService.getNodeinfo(path); Response responseNodeInfo = nodeinfo.execute(); return responseNodeInfo.body(); } diff --git a/app/src/main/java/app/fedilab/fedilabtube/client/entities/WellKnownNodeinfo.java b/app/src/main/java/app/fedilab/fedilabtube/client/entities/WellKnownNodeinfo.java index 2a8f981..8a14df5 100644 --- a/app/src/main/java/app/fedilab/fedilabtube/client/entities/WellKnownNodeinfo.java +++ b/app/src/main/java/app/fedilab/fedilabtube/client/entities/WellKnownNodeinfo.java @@ -17,27 +17,44 @@ package app.fedilab.fedilabtube.client.entities; import com.google.gson.annotations.SerializedName; +import java.util.List; + @SuppressWarnings({"unused", "RedundantSuppression"}) public class WellKnownNodeinfo { - @SerializedName("reel") - private String reel; - @SerializedName("href") - private String href; - public String getReel() { - return reel; + + @SerializedName("links") + private List links; + + public List getLinks() { + return links; } - public void setReel(String reel) { - this.reel = reel; + public void setLinks(List links) { + this.links = links; } - public String getHref() { - return href; - } + public static class NodeInfoLinks { + @SerializedName("reel") + private String reel; + @SerializedName("href") + private String href; - public void setHref(String href) { - this.href = href; + public String getReel() { + return reel; + } + + public void setReel(String reel) { + this.reel = reel; + } + + public String getHref() { + return href; + } + + public void setHref(String href) { + this.href = href; + } } public static class NodeInfo {