Scroll search to top on query change

This commit is contained in:
Grishka 2023-10-10 23:28:09 +03:00
parent 103aaafff1
commit 48665ebcce
1 changed files with 5 additions and 10 deletions

View File

@ -32,6 +32,7 @@ import java.util.stream.Collectors;
import me.grishka.appkit.Nav; import me.grishka.appkit.Nav;
import me.grishka.appkit.api.Callback; import me.grishka.appkit.api.Callback;
import me.grishka.appkit.api.ErrorResponse; import me.grishka.appkit.api.ErrorResponse;
import me.grishka.appkit.api.SimpleCallback;
public class SearchFragment extends BaseStatusListFragment<SearchResult>{ public class SearchFragment extends BaseStatusListFragment<SearchResult>{
private String currentQuery; private String currentQuery;
@ -137,7 +138,7 @@ public class SearchFragment extends BaseStatusListFragment<SearchResult>{
}*/ }*/
int offset=_offset; int offset=_offset;
currentRequest=new GetSearchResults(currentQuery, type, type==null, maxID, offset, type==null ? 0 : count) currentRequest=new GetSearchResults(currentQuery, type, type==null, maxID, offset, type==null ? 0 : count)
.setCallback(new Callback<>(){ .setCallback(new SimpleCallback<SearchResults>(this){
@Override @Override
public void onSuccess(SearchResults result){ public void onSuccess(SearchResults result){
ArrayList<SearchResult> results=new ArrayList<>(); ArrayList<SearchResult> results=new ArrayList<>();
@ -158,16 +159,10 @@ public class SearchFragment extends BaseStatusListFragment<SearchResult>{
} }
prevDisplayItems=new ArrayList<>(displayItems); prevDisplayItems=new ArrayList<>(displayItems);
unfilteredResults=results; unfilteredResults=results;
boolean wasRefreshing=refreshing;
onDataLoaded(filterSearchResults(results), type!=null && !results.isEmpty()); onDataLoaded(filterSearchResults(results), type!=null && !results.isEmpty());
} if(wasRefreshing)
list.scrollToPosition(0);
@Override
public void onError(ErrorResponse error){
currentRequest=null;
Activity a=getActivity();
if(a==null)
return;
error.showToast(a);
} }
}) })
.exec(accountID); .exec(accountID);