From 9de83355e1872b6641676b0e2ddde688d080ec85 Mon Sep 17 00:00:00 2001 From: sk Date: Fri, 20 Oct 2023 13:04:51 +0200 Subject: [PATCH] revert api timeout and increase for search closes sk22#881 --- .../android/api/MastodonAPIController.java | 12 +++++------- .../android/api/MastodonAPIRequest.java | 3 ++- .../android/fragments/discover/SearchFragment.java | 13 +++---------- 3 files changed, 10 insertions(+), 18 deletions(-) diff --git a/mastodon/src/main/java/org/joinmastodon/android/api/MastodonAPIController.java b/mastodon/src/main/java/org/joinmastodon/android/api/MastodonAPIController.java index ae398cdbf..c4183c878 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/api/MastodonAPIController.java +++ b/mastodon/src/main/java/org/joinmastodon/android/api/MastodonAPIController.java @@ -53,9 +53,7 @@ public class MastodonAPIController{ .registerTypeAdapter(Status.class, new Status.StatusDeserializer()) .create(); private static WorkerThread thread=new WorkerThread("MastodonAPIController"); - private static OkHttpClient httpClient=new OkHttpClient.Builder() - .readTimeout(5, TimeUnit.MINUTES) - .build(); + private static OkHttpClient httpClient=new OkHttpClient.Builder().build(); private AccountSession session; private static List badDomains = new ArrayList<>(); @@ -113,13 +111,13 @@ public class MastodonAPIController{ } Request hreq=builder.build(); - Call call=httpClient.newCall(hreq); + OkHttpClient client=req.timeout>0 + ? httpClient.newBuilder().readTimeout(req.timeout, TimeUnit.MILLISECONDS).build() + : httpClient; + Call call=client.newCall(hreq); synchronized(req){ req.okhttpCall=call; } - if(req.timeout>0){ - call.timeout().timeout(req.timeout, TimeUnit.MILLISECONDS); - } if(BuildConfig.DEBUG) Log.d(TAG, "["+(session==null ? "no-auth" : session.getID())+"] Sending request: "+hreq); diff --git a/mastodon/src/main/java/org/joinmastodon/android/api/MastodonAPIRequest.java b/mastodon/src/main/java/org/joinmastodon/android/api/MastodonAPIRequest.java index 023c28f21..09cb7ca60 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/api/MastodonAPIRequest.java +++ b/mastodon/src/main/java/org/joinmastodon/android/api/MastodonAPIRequest.java @@ -153,8 +153,9 @@ public abstract class MastodonAPIRequest extends APIRequest{ headers.put(key, value); } - protected void setTimeout(long timeout){ + public MastodonAPIRequest setTimeout(long timeout){ this.timeout=timeout; + return this; } protected String getPathPrefix(){ 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 95b846925..599d82077 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 @@ -36,6 +36,7 @@ import java.util.stream.Collectors; 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.V; public class SearchFragment extends BaseStatusListFragment{ @@ -142,7 +143,7 @@ public class SearchFragment extends BaseStatusListFragment{ }*/ int offset=_offset; currentRequest=new GetSearchResults(currentQuery, type, type==null, maxID, offset, type==null ? 0 : count) - .setCallback(new Callback<>(){ + .setCallback(new SimpleCallback<>(this){ @Override public void onSuccess(SearchResults result){ ArrayList results=new ArrayList<>(); @@ -165,16 +166,8 @@ public class SearchFragment extends BaseStatusListFragment{ unfilteredResults=results; onDataLoaded(filterSearchResults(results), type!=null && !results.isEmpty()); } - - @Override - public void onError(ErrorResponse error){ - currentRequest=null; - Activity a=getActivity(); - if(a==null) - return; - error.showToast(a); - } }) + .setTimeout(180000) // 3 minutes (searches can take a long time) .exec(accountID); }