diff --git a/mastodon/build.gradle b/mastodon/build.gradle index 69f06c0d7..3e5e06289 100644 --- a/mastodon/build.gradle +++ b/mastodon/build.gradle @@ -75,7 +75,7 @@ dependencies { implementation 'me.grishka.litex:dynamicanimation:1.1.0-alpha03' implementation 'me.grishka.litex:viewpager:1.0.0' implementation 'me.grishka.litex:viewpager2:1.0.0' - implementation 'me.grishka.appkit:appkit:1.2.6' + implementation 'me.grishka.appkit:appkit:1.2.7' implementation 'com.google.code.gson:gson:2.8.9' implementation 'org.jsoup:jsoup:1.14.3' implementation 'com.squareup:otto:1.3.8' diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/SearchFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/SearchFragment.java index e65f8c9be..cfbb2f295 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/SearchFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/SearchFragment.java @@ -35,6 +35,8 @@ import java.util.stream.Collectors; import androidx.recyclerview.widget.RecyclerView; import me.grishka.appkit.Nav; +import me.grishka.appkit.api.Callback; +import me.grishka.appkit.api.ErrorResponse; import me.grishka.appkit.api.SimpleCallback; import me.grishka.appkit.utils.MergeRecyclerAdapter; import me.grishka.appkit.utils.V; @@ -128,7 +130,7 @@ public class SearchFragment extends BaseStatusListFragment{ }else{ progressVisibilityListener.onProgressVisibilityChanged(true); currentRequest=new GetSearchResults(currentQuery, null, true) - .setCallback(new SimpleCallback<>(this){ + .setCallback(new Callback<>(){ @Override public void onSuccess(SearchResults result){ ArrayList results=new ArrayList<>(); @@ -148,6 +150,17 @@ public class SearchFragment extends BaseStatusListFragment{ unfilteredResults=results; onDataLoaded(filterSearchResults(results), false); } + + @Override + public void onError(ErrorResponse error){ + currentRequest=null; + Activity a=getActivity(); + if(a==null) + return; + error.showToast(a); + if(progressVisibilityListener!=null) + progressVisibilityListener.onProgressVisibilityChanged(false); + } }) .exec(accountID); } @@ -159,12 +172,11 @@ public class SearchFragment extends BaseStatusListFragment{ super.updateList(); return; } - imgLoader.deactivate(); UiUtils.updateList(prevDisplayItems, displayItems, list, adapter, (i1, i2)->i1.parentID.equals(i2.parentID) && i1.index==i2.index && i1.getType()==i2.getType()); boolean recent=isInRecentMode(); if(recent!=headerAdapter.isVisible()) headerAdapter.setVisible(recent); - imgLoader.activate(); + imgLoader.forceUpdateImages(); prevDisplayItems=null; } diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/onboarding/InstanceCatalogFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/onboarding/InstanceCatalogFragment.java index 863ecf033..19f9bb20e 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/onboarding/InstanceCatalogFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/onboarding/InstanceCatalogFragment.java @@ -1,5 +1,6 @@ package org.joinmastodon.android.fragments.onboarding; +import android.app.Activity; import android.app.ProgressDialog; import android.content.Context; import android.net.Uri; @@ -9,6 +10,7 @@ import android.os.LocaleList; import android.text.Editable; import android.text.TextUtils; import android.text.TextWatcher; +import android.util.Log; import android.view.KeyEvent; import android.view.View; import android.view.ViewGroup; @@ -21,6 +23,7 @@ import android.widget.RadioButton; import android.widget.TextView; import org.joinmastodon.android.R; +import org.joinmastodon.android.api.MastodonAPIController; import org.joinmastodon.android.api.MastodonAPIRequest; import org.joinmastodon.android.api.MastodonErrorResponse; import org.joinmastodon.android.api.requests.instance.GetInstance; @@ -36,7 +39,13 @@ import org.joinmastodon.android.ui.M3AlertDialogBuilder; import org.joinmastodon.android.ui.tabs.TabLayout; import org.joinmastodon.android.ui.utils.UiUtils; import org.parceler.Parcels; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.InputSource; +import java.io.IOException; import java.net.IDN; import java.util.ArrayList; import java.util.Collections; @@ -46,6 +55,8 @@ import java.util.List; import java.util.Map; import java.util.stream.Collectors; +import javax.xml.parsers.DocumentBuilderFactory; + import androidx.annotation.NonNull; import androidx.recyclerview.widget.DiffUtil; import androidx.recyclerview.widget.RecyclerView; @@ -58,6 +69,9 @@ import me.grishka.appkit.utils.MergeRecyclerAdapter; import me.grishka.appkit.utils.SingleViewRecyclerAdapter; import me.grishka.appkit.utils.V; import me.grishka.appkit.views.UsableRecyclerView; +import okhttp3.Call; +import okhttp3.Request; +import okhttp3.Response; public class InstanceCatalogFragment extends BaseRecyclerFragment{ private InstancesAdapter adapter; @@ -75,9 +89,11 @@ public class InstanceCatalogFragment extends BaseRecyclerFragment categories=new ArrayList<>(); private String loadingInstanceDomain; private GetInstance loadingInstanceRequest; + private Call loadingInstanceRedirectRequest; private HashMap instancesCache=new HashMap<>(); private ProgressDialog instanceProgressDialog; private View buttonBar; + private HashMap redirects=new HashMap<>(), redirectsInverse=new HashMap<>(); private boolean isSignup; @@ -271,7 +287,7 @@ public class InstanceCatalogFragment extends BaseRecyclerFragment{ - if(loadingInstanceRequest!=null){ - loadingInstanceRequest.cancel(); - loadingInstanceRequest=null; - loadingInstanceDomain=null; - } - }); + instanceProgressDialog.setOnCancelListener(dialog->cancelLoadingInstanceInfo()); instanceProgressDialog.show(); } @@ -429,10 +439,12 @@ public class InstanceCatalogFragment extends BaseRecyclerFragmentshowInstanceInfoLoadError(domain, e)); + } + + @Override + public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException{ + loadingInstanceRedirectRequest=null; + loadingInstanceDomain=null; + Activity a=getActivity(); + if(a==null) + return; + try(response){ + if(!response.isSuccessful()){ + a.runOnUiThread(()->showInstanceInfoLoadError(domain, response.code()+" "+response.message())); + return; + } + InputSource source=new InputSource(response.body().charStream()); + Document doc=DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(source); + NodeList list=doc.getElementsByTagName("Link"); + for(int i=0;iloadInstanceInfo(redirectDomain, true)); + return; + } + } + } + a.runOnUiThread(()->showInstanceInfoLoadError(domain, origError)); + }catch(Exception x){ + a.runOnUiThread(()->showInstanceInfoLoadError(domain, x)); + } + } + }); + } + @Override public void onApplyWindowInsets(WindowInsets insets){ if(Build.VERSION.SDK_INT>=27){ @@ -580,7 +678,7 @@ public class InstanceCatalogFragment extends BaseRecyclerFragment + android:paddingTop="12dp" + android:paddingBottom="12dp">