Paginate search results
This commit is contained in:
parent
56a6d7243f
commit
c517f41595
|
@ -9,7 +9,7 @@ android {
|
||||||
applicationId "org.joinmastodon.android"
|
applicationId "org.joinmastodon.android"
|
||||||
minSdk 23
|
minSdk 23
|
||||||
targetSdk 33
|
targetSdk 33
|
||||||
versionCode 64
|
versionCode 65
|
||||||
versionName "2.0.4"
|
versionName "2.0.4"
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
resConfigs "ar-rSA", "be-rBY", "bn-rBD", "bs-rBA", "ca-rES", "cs-rCZ", "da-rDK", "de-rDE", "el-rGR", "es-rES", "eu-rES", "fa-rIR", "fi-rFI", "fil-rPH", "fr-rFR", "ga-rIE", "gd-rGB", "gl-rES", "hi-rIN", "hr-rHR", "hu-rHU", "hy-rAM", "ig-rNG", "in-rID", "is-rIS", "it-rIT", "iw-rIL", "ja-rJP", "kab", "ko-rKR", "my-rMM", "nl-rNL", "no-rNO", "oc-rFR", "pl-rPL", "pt-rBR", "pt-rPT", "ro-rRO", "ru-rRU", "si-rLK", "sl-rSI", "sv-rSE", "th-rTH", "tr-rTR", "uk-rUA", "ur-rIN", "vi-rVN", "zh-rCN", "zh-rTW"
|
resConfigs "ar-rSA", "be-rBY", "bn-rBD", "bs-rBA", "ca-rES", "cs-rCZ", "da-rDK", "de-rDE", "el-rGR", "es-rES", "eu-rES", "fa-rIR", "fi-rFI", "fil-rPH", "fr-rFR", "ga-rIE", "gd-rGB", "gl-rES", "hi-rIN", "hr-rHR", "hu-rHU", "hy-rAM", "ig-rNG", "in-rID", "is-rIS", "it-rIT", "iw-rIL", "ja-rJP", "kab", "ko-rKR", "my-rMM", "nl-rNL", "no-rNO", "oc-rFR", "pl-rPL", "pt-rBR", "pt-rPT", "ro-rRO", "ru-rRU", "si-rLK", "sl-rSI", "sv-rSE", "th-rTH", "tr-rTR", "uk-rUA", "ur-rIN", "vi-rVN", "zh-rCN", "zh-rTW"
|
||||||
|
|
|
@ -136,7 +136,7 @@ public class MainActivity extends FragmentStackActivity{
|
||||||
}
|
}
|
||||||
|
|
||||||
public void openSearchQuery(String q, String accountID, int progressText, boolean fromSearch){
|
public void openSearchQuery(String q, String accountID, int progressText, boolean fromSearch){
|
||||||
new GetSearchResults(q, null, true)
|
new GetSearchResults(q, null, true, null, 0, 0)
|
||||||
.setCallback(new Callback<>(){
|
.setCallback(new Callback<>(){
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(SearchResults result){
|
public void onSuccess(SearchResults result){
|
||||||
|
|
|
@ -4,13 +4,19 @@ import org.joinmastodon.android.api.MastodonAPIRequest;
|
||||||
import org.joinmastodon.android.model.SearchResults;
|
import org.joinmastodon.android.model.SearchResults;
|
||||||
|
|
||||||
public class GetSearchResults extends MastodonAPIRequest<SearchResults>{
|
public class GetSearchResults extends MastodonAPIRequest<SearchResults>{
|
||||||
public GetSearchResults(String query, Type type, boolean resolve){
|
public GetSearchResults(String query, Type type, boolean resolve, String maxID, int offset, int count){
|
||||||
super(HttpMethod.GET, "/search", SearchResults.class);
|
super(HttpMethod.GET, "/search", SearchResults.class);
|
||||||
addQueryParameter("q", query);
|
addQueryParameter("q", query);
|
||||||
if(type!=null)
|
if(type!=null)
|
||||||
addQueryParameter("type", type.name().toLowerCase());
|
addQueryParameter("type", type.name().toLowerCase());
|
||||||
if(resolve)
|
if(resolve)
|
||||||
addQueryParameter("resolve", "true");
|
addQueryParameter("resolve", "true");
|
||||||
|
if(maxID!=null)
|
||||||
|
addQueryParameter("max_id", maxID);
|
||||||
|
if(offset>0)
|
||||||
|
addQueryParameter("offset", String.valueOf(offset));
|
||||||
|
if(count>0)
|
||||||
|
addQueryParameter("limit", String.valueOf(count));
|
||||||
}
|
}
|
||||||
|
|
||||||
public GetSearchResults limit(int limit){
|
public GetSearchResults limit(int limit){
|
||||||
|
|
|
@ -47,7 +47,7 @@ public class ComposeAccountSearchFragment extends BaseAccountListFragment{
|
||||||
@Override
|
@Override
|
||||||
protected void doLoadData(int offset, int count){
|
protected void doLoadData(int offset, int count){
|
||||||
refreshing=true;
|
refreshing=true;
|
||||||
currentRequest=new GetSearchResults(currentQuery, GetSearchResults.Type.ACCOUNTS, false)
|
currentRequest=new GetSearchResults(currentQuery, GetSearchResults.Type.ACCOUNTS, false, null, 0, 0)
|
||||||
.setCallback(new SimpleCallback<>(this){
|
.setCallback(new SimpleCallback<>(this){
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(SearchResults result){
|
public void onSuccess(SearchResults result){
|
||||||
|
|
|
@ -3,7 +3,6 @@ package org.joinmastodon.android.fragments.discover;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.View;
|
|
||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
|
|
||||||
import org.joinmastodon.android.R;
|
import org.joinmastodon.android.R;
|
||||||
|
@ -20,7 +19,6 @@ import org.joinmastodon.android.model.Status;
|
||||||
import org.joinmastodon.android.ui.displayitems.AccountStatusDisplayItem;
|
import org.joinmastodon.android.ui.displayitems.AccountStatusDisplayItem;
|
||||||
import org.joinmastodon.android.ui.displayitems.HashtagStatusDisplayItem;
|
import org.joinmastodon.android.ui.displayitems.HashtagStatusDisplayItem;
|
||||||
import org.joinmastodon.android.ui.displayitems.StatusDisplayItem;
|
import org.joinmastodon.android.ui.displayitems.StatusDisplayItem;
|
||||||
import org.joinmastodon.android.ui.tabs.TabLayout;
|
|
||||||
import org.joinmastodon.android.ui.utils.UiUtils;
|
import org.joinmastodon.android.ui.utils.UiUtils;
|
||||||
import org.parceler.Parcels;
|
import org.parceler.Parcels;
|
||||||
|
|
||||||
|
@ -28,13 +26,12 @@ import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
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.utils.V;
|
|
||||||
|
|
||||||
public class SearchFragment extends BaseStatusListFragment<SearchResult>{
|
public class SearchFragment extends BaseStatusListFragment<SearchResult>{
|
||||||
private String currentQuery;
|
private String currentQuery;
|
||||||
|
@ -110,7 +107,7 @@ public class SearchFragment extends BaseStatusListFragment<SearchResult>{
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doLoadData(int offset, int count){
|
protected void doLoadData(int _offset, int count){
|
||||||
GetSearchResults.Type type;
|
GetSearchResults.Type type;
|
||||||
if(currentFilter.size()==1){
|
if(currentFilter.size()==1){
|
||||||
type=switch(currentFilter.iterator().next()){
|
type=switch(currentFilter.iterator().next()){
|
||||||
|
@ -125,7 +122,21 @@ public class SearchFragment extends BaseStatusListFragment<SearchResult>{
|
||||||
dataLoaded();
|
dataLoaded();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
currentRequest=new GetSearchResults(currentQuery, type, true)
|
String maxID=null;
|
||||||
|
// TODO server-side bug
|
||||||
|
/*int offset=0;
|
||||||
|
if(_offset>0){
|
||||||
|
if(type==GetSearchResults.Type.STATUSES){
|
||||||
|
if(!preloadedData.isEmpty())
|
||||||
|
maxID=preloadedData.get(preloadedData.size()-1).status.id;
|
||||||
|
else if(!data.isEmpty())
|
||||||
|
maxID=data.get(data.size()-1).status.id;
|
||||||
|
}else{
|
||||||
|
offset=_offset;
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
int offset=_offset;
|
||||||
|
currentRequest=new GetSearchResults(currentQuery, type, type==null, maxID, offset, type==null ? 0 : count)
|
||||||
.setCallback(new Callback<>(){
|
.setCallback(new Callback<>(){
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(SearchResults result){
|
public void onSuccess(SearchResults result){
|
||||||
|
@ -139,12 +150,15 @@ public class SearchFragment extends BaseStatusListFragment<SearchResult>{
|
||||||
results.add(new SearchResult(tag));
|
results.add(new SearchResult(tag));
|
||||||
}
|
}
|
||||||
if(result.statuses!=null){
|
if(result.statuses!=null){
|
||||||
for(Status status:result.statuses)
|
Set<String> alreadyLoadedStatuses=data.stream().filter(r->r.type==SearchResult.Type.STATUS).map(r->r.status.id).collect(Collectors.toSet());
|
||||||
|
for(Status status:result.statuses){
|
||||||
|
if(!alreadyLoadedStatuses.contains(status.id))
|
||||||
results.add(new SearchResult(status));
|
results.add(new SearchResult(status));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
prevDisplayItems=new ArrayList<>(displayItems);
|
prevDisplayItems=new ArrayList<>(displayItems);
|
||||||
unfilteredResults=results;
|
unfilteredResults=results;
|
||||||
onDataLoaded(filterSearchResults(results), false);
|
onDataLoaded(filterSearchResults(results), type!=null && !results.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -43,9 +43,7 @@ import org.joinmastodon.android.ui.viewholders.AccountViewHolder;
|
||||||
import org.joinmastodon.android.ui.viewholders.SimpleListItemViewHolder;
|
import org.joinmastodon.android.ui.viewholders.SimpleListItemViewHolder;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
@ -121,7 +119,7 @@ public class SearchQueryFragment extends MastodonRecyclerFragment<SearchResultVi
|
||||||
recentsHeader.setVisible(!data.isEmpty());
|
recentsHeader.setVisible(!data.isEmpty());
|
||||||
});
|
});
|
||||||
}else{
|
}else{
|
||||||
currentRequest=new GetSearchResults(currentQuery, null, false)
|
currentRequest=new GetSearchResults(currentQuery, null, false, null, 0, 0)
|
||||||
.limit(2)
|
.limit(2)
|
||||||
.setCallback(new SimpleCallback<>(this){
|
.setCallback(new SimpleCallback<>(this){
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -15,15 +15,12 @@ import android.widget.TextView;
|
||||||
import org.joinmastodon.android.R;
|
import org.joinmastodon.android.R;
|
||||||
import org.joinmastodon.android.api.requests.search.GetSearchResults;
|
import org.joinmastodon.android.api.requests.search.GetSearchResults;
|
||||||
import org.joinmastodon.android.api.session.AccountSessionManager;
|
import org.joinmastodon.android.api.session.AccountSessionManager;
|
||||||
import org.joinmastodon.android.model.Account;
|
|
||||||
import org.joinmastodon.android.model.Emoji;
|
import org.joinmastodon.android.model.Emoji;
|
||||||
import org.joinmastodon.android.model.Hashtag;
|
import org.joinmastodon.android.model.Hashtag;
|
||||||
import org.joinmastodon.android.model.SearchResults;
|
import org.joinmastodon.android.model.SearchResults;
|
||||||
import org.joinmastodon.android.model.viewmodel.AccountViewModel;
|
import org.joinmastodon.android.model.viewmodel.AccountViewModel;
|
||||||
import org.joinmastodon.android.ui.BetterItemAnimator;
|
import org.joinmastodon.android.ui.BetterItemAnimator;
|
||||||
import org.joinmastodon.android.ui.OutlineProviders;
|
import org.joinmastodon.android.ui.OutlineProviders;
|
||||||
import org.joinmastodon.android.ui.text.HtmlParser;
|
|
||||||
import org.joinmastodon.android.ui.utils.CustomEmojiHelper;
|
|
||||||
import org.joinmastodon.android.ui.utils.HideableSingleViewRecyclerAdapter;
|
import org.joinmastodon.android.ui.utils.HideableSingleViewRecyclerAdapter;
|
||||||
import org.joinmastodon.android.ui.utils.UiUtils;
|
import org.joinmastodon.android.ui.utils.UiUtils;
|
||||||
import org.joinmastodon.android.ui.views.FilterChipView;
|
import org.joinmastodon.android.ui.views.FilterChipView;
|
||||||
|
@ -240,7 +237,7 @@ public class ComposeAutocompleteViewController{
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doSearchUsers(){
|
private void doSearchUsers(){
|
||||||
currentRequest=new GetSearchResults(lastText, GetSearchResults.Type.ACCOUNTS, false)
|
currentRequest=new GetSearchResults(lastText, GetSearchResults.Type.ACCOUNTS, false, null, 0, 0)
|
||||||
.setCallback(new Callback<>(){
|
.setCallback(new Callback<>(){
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(SearchResults result){
|
public void onSuccess(SearchResults result){
|
||||||
|
@ -276,7 +273,7 @@ public class ComposeAutocompleteViewController{
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doSearchHashtags(){
|
private void doSearchHashtags(){
|
||||||
currentRequest=new GetSearchResults(lastText, GetSearchResults.Type.HASHTAGS, false)
|
currentRequest=new GetSearchResults(lastText, GetSearchResults.Type.HASHTAGS, false, null, 0, 0)
|
||||||
.setCallback(new Callback<>(){
|
.setCallback(new Callback<>(){
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(SearchResults result){
|
public void onSuccess(SearchResults result){
|
||||||
|
|
Loading…
Reference in New Issue