From 48665ebccee0478db6d6948bf2bf88f3ab19ae2d Mon Sep 17 00:00:00 2001 From: Grishka Date: Tue, 10 Oct 2023 23:28:09 +0300 Subject: [PATCH] Scroll search to top on query change --- .../fragments/discover/SearchFragment.java | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) 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 fcbb6f19a..59c47a903 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 @@ -32,6 +32,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; public class SearchFragment extends BaseStatusListFragment{ private String currentQuery; @@ -137,7 +138,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<>(); @@ -158,16 +159,10 @@ public class SearchFragment extends BaseStatusListFragment{ } prevDisplayItems=new ArrayList<>(displayItems); unfilteredResults=results; + boolean wasRefreshing=refreshing; 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); + if(wasRefreshing) + list.scrollToPosition(0); } }) .exec(accountID);