From 18cc3a13f927896c87c041482ee5077feb7f736a Mon Sep 17 00:00:00 2001 From: tom79 Date: Sun, 31 Mar 2019 14:25:40 +0200 Subject: [PATCH] Divide searches --- .../mastodon/activities/PeertubeActivity.java | 6 +- .../activities/SearchResultActivity.java | 17 ++-- .../activities/SearchResultTabActivity.java | 87 ++++++++++++++++--- .../mastodon/activities/TootActivity.java | 6 +- .../mastodon/activities/WebviewActivity.java | 7 +- .../asynctasks/PostActionAsyncTask.java | 13 +-- .../asynctasks/RetrieveAccountsAsyncTask.java | 4 + .../RetrieveRemoteDataAsyncTask.java | 5 +- .../fr/gouv/etalab/mastodon/client/API.java | 3 +- .../fragments/DisplayAccountsFragment.java | 19 ++-- .../fragments/DisplaySearchTagsFragment.java | 4 +- .../fragments/DisplayStatusFragment.java | 9 +- .../etalab/mastodon/helper/CrossActions.java | 28 +++--- 13 files changed, 152 insertions(+), 56 deletions(-) diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/PeertubeActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/PeertubeActivity.java index 2e9539b51..04fb25e19 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/PeertubeActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/PeertubeActivity.java @@ -383,9 +383,9 @@ public class PeertubeActivity extends BaseActivity implements OnRetrievePeertube protected Void doInBackground(Void... voids) { if (peertube != null) { - Results search = new API(contextReference.get()).search("https://" + peertube.getAccount().getHost() + "/videos/watch/" + peertube.getUuid()); - if (search != null) { - remoteStatuses = search.getStatuses(); + APIResponse search = new API(contextReference.get()).search("https://" + peertube.getAccount().getHost() + "/videos/watch/" + peertube.getUuid()); + if (search != null && search.getResults() != null) { + remoteStatuses = search.getResults().getStatuses(); } } return null; diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/SearchResultActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/SearchResultActivity.java index 9d3bcd608..28152f00f 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/SearchResultActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/SearchResultActivity.java @@ -139,21 +139,24 @@ public class SearchResultActivity extends BaseActivity implements OnRetrieveSear @Override - public void onRetrieveSearch(Results results, Error error) { + public void onRetrieveSearch(APIResponse apiResponse) { loader.setVisibility(View.GONE); - if( error != null){ - Toasty.error(getApplicationContext(), error.getError(),Toast.LENGTH_LONG).show(); + if( apiResponse.getError() != null){ + if( apiResponse.getError().getError() != null) + Toasty.error(getApplicationContext(), apiResponse.getError().getError(),Toast.LENGTH_LONG).show(); + else + Toasty.error(getApplicationContext(), getString(R.string.toast_error),Toast.LENGTH_LONG).show(); return; } - if( results == null || (results.getAccounts().size() == 0 && results.getStatuses().size() == 0 && results.getHashtags().size() == 0)){ + if( apiResponse.getResults() == null || ( apiResponse.getResults().getAccounts().size() == 0 && apiResponse.getResults().getStatuses().size() == 0 && apiResponse.getResults().getHashtags().size() == 0)){ RelativeLayout no_result = findViewById(R.id.no_result); no_result.setVisibility(View.VISIBLE); return; } lv_search.setVisibility(View.VISIBLE); - List tags = results.getHashtags(); - List accounts = results.getAccounts(); - List statuses = results.getStatuses(); + List tags = apiResponse.getResults().getHashtags(); + List accounts = apiResponse.getResults().getAccounts(); + List statuses = apiResponse.getResults().getStatuses(); SearchListAdapter searchListAdapter = new SearchListAdapter(SearchResultActivity.this, statuses, accounts, tags); lv_search.setAdapter(searchListAdapter); diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/SearchResultTabActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/SearchResultTabActivity.java index bbb2b6492..e79de957c 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/SearchResultTabActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/SearchResultTabActivity.java @@ -17,11 +17,13 @@ package fr.gouv.etalab.mastodon.activities; import android.annotation.SuppressLint; import android.content.Context; import android.content.SharedPreferences; +import android.os.AsyncTask; import android.os.Bundle; import android.support.design.widget.TabLayout; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentStatePagerAdapter; +import android.support.v4.view.PagerAdapter; import android.support.v4.view.ViewPager; import android.support.v7.app.ActionBar; import android.support.v7.widget.Toolbar; @@ -30,12 +32,14 @@ import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; -import android.widget.ListView; -import android.widget.RelativeLayout; import android.widget.TextView; +import android.widget.Toast; + +import es.dmoral.toasty.Toasty; import fr.gouv.etalab.mastodon.R; import fr.gouv.etalab.mastodon.asynctasks.RetrieveAccountsAsyncTask; import fr.gouv.etalab.mastodon.asynctasks.RetrieveFeedsAsyncTask; +import fr.gouv.etalab.mastodon.asynctasks.RetrieveSearchAsyncTask; import fr.gouv.etalab.mastodon.fragments.DisplayAccountsFragment; import fr.gouv.etalab.mastodon.fragments.DisplaySearchTagsFragment; import fr.gouv.etalab.mastodon.fragments.DisplayStatusFragment; @@ -53,8 +57,6 @@ public class SearchResultTabActivity extends BaseActivity { private String search; - private ListView lv_search; - private RelativeLayout loader; private TabLayout tabLayout; private ViewPager search_viewpager; private DisplayStatusFragment displayStatusFragment; @@ -81,8 +83,18 @@ public class SearchResultTabActivity extends BaseActivity { setContentView(R.layout.activity_search_result_tabs); - loader = findViewById(R.id.loader); - lv_search = findViewById(R.id.lv_search); + + Bundle b = getIntent().getExtras(); + if(b != null){ + search = b.getString("search"); + if( search == null) + Toasty.error(this,getString(R.string.toast_error_search), Toast.LENGTH_LONG).show(); + }else{ + Toasty.error(this,getString(R.string.toast_error_search),Toast.LENGTH_LONG).show(); + } + if( search == null) + finish(); + tabLayout = findViewById(R.id.search_tabLayout); search_viewpager = findViewById(R.id.search_viewpager); @@ -111,8 +123,61 @@ public class SearchResultTabActivity extends BaseActivity { } } setTitle(search); - loader.setVisibility(View.VISIBLE); - lv_search.setVisibility(View.GONE); + tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.tags))); + tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.accounts))); + tabLayout.addTab(tabLayout.newTab().setText(getString(R.string.toots))); + + PagerAdapter mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager()); + search_viewpager.setAdapter(mPagerAdapter); + + search_viewpager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { + @Override + public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { + + } + + @Override + public void onPageSelected(int position) { + TabLayout.Tab tab = tabLayout.getTabAt(position); + if( tab != null) + tab.select(); + } + + @Override + public void onPageScrollStateChanged(int state) { + + } + }); + + tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { + @Override + public void onTabSelected(TabLayout.Tab tab) { + search_viewpager.setCurrentItem(tab.getPosition()); + } + + @Override + public void onTabUnselected(TabLayout.Tab tab) { + + } + + @Override + public void onTabReselected(TabLayout.Tab tab) { + Fragment fragment; + if( search_viewpager.getAdapter() != null) { + fragment = (Fragment) search_viewpager.getAdapter().instantiateItem(search_viewpager, tab.getPosition()); + if (fragment instanceof DisplayAccountsFragment) { + DisplayAccountsFragment displayAccountsFragment = ((DisplayAccountsFragment) fragment); + displayAccountsFragment.scrollToTop(); + } else if (fragment instanceof DisplayStatusFragment) { + DisplayStatusFragment displayStatusFragment = ((DisplayStatusFragment) fragment); + displayStatusFragment.scrollToTop(); + } else if (fragment instanceof DisplaySearchTagsFragment) { + DisplaySearchTagsFragment displaySearchTagsFragment = ((DisplaySearchTagsFragment) fragment); + displaySearchTagsFragment.scrollToTop(); + } + } + } + }); } @@ -144,22 +209,22 @@ public class SearchResultTabActivity extends BaseActivity { switch (position){ case 0: DisplaySearchTagsFragment displaySearchTagsFragment = new DisplaySearchTagsFragment(); - bundle.putSerializable("tagsOnly", true); displaySearchTagsFragment.setArguments(bundle); + bundle.putSerializable("search", search); return displaySearchTagsFragment; case 1: DisplayAccountsFragment displayAccountsFragment = new DisplayAccountsFragment(); bundle.putSerializable("type", RetrieveAccountsAsyncTask.Type.SEARCH); + bundle.putSerializable("tag", search); displayAccountsFragment.setArguments(bundle); return displayAccountsFragment; case 2: DisplayStatusFragment displayStatusFragment = new DisplayStatusFragment(); bundle = new Bundle(); bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.SEARCH); + bundle.putSerializable("tag", search); displayStatusFragment.setArguments(bundle); return displayStatusFragment; - - } return null; } diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/TootActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/TootActivity.java index 74107cc02..5d45a3673 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/TootActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/TootActivity.java @@ -2183,14 +2183,14 @@ public class TootActivity extends BaseActivity implements OnPostActionInterface, } @Override - public void onRetrieveSearch(Results results, Error error) { + public void onRetrieveSearch(APIResponse apiResponse) { if( pp_progress != null && pp_actionBar != null) { pp_progress.setVisibility(View.GONE); pp_actionBar.setVisibility(View.VISIBLE); } - if( results == null) + if( apiResponse == null || apiResponse.getResults() == null) return; - + Results results = apiResponse.getResults(); final List tags = results.getHashtags(); if( tags != null && tags.size() > 0){ TagsSearchAdapter tagsSearchAdapter = new TagsSearchAdapter(TootActivity.this, tags); diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/activities/WebviewActivity.java b/app/src/main/java/fr/gouv/etalab/mastodon/activities/WebviewActivity.java index 997a25998..af34635f9 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/activities/WebviewActivity.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/activities/WebviewActivity.java @@ -50,6 +50,7 @@ import java.util.List; import es.dmoral.toasty.Toasty; import fr.gouv.etalab.mastodon.R; import fr.gouv.etalab.mastodon.client.API; +import fr.gouv.etalab.mastodon.client.APIResponse; import fr.gouv.etalab.mastodon.client.Entities.Results; import fr.gouv.etalab.mastodon.helper.CountDrawable; import fr.gouv.etalab.mastodon.helper.Helper; @@ -288,9 +289,9 @@ public class WebviewActivity extends BaseActivity { protected Void doInBackground(Void... voids) { if(url != null) { - Results search = new API(contextReference.get()).search(peertubeLinkToFetch); - if (search != null) { - remoteStatuses = search.getStatuses(); + APIResponse search = new API(contextReference.get()).search(peertubeLinkToFetch); + if (search != null && search.getResults() != null) { + remoteStatuses = search.getResults().getStatuses(); } } return null; diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/PostActionAsyncTask.java b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/PostActionAsyncTask.java index 22879a673..5e18f1389 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/PostActionAsyncTask.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/PostActionAsyncTask.java @@ -22,6 +22,7 @@ import java.util.List; import fr.gouv.etalab.mastodon.activities.MainActivity; import fr.gouv.etalab.mastodon.client.API; +import fr.gouv.etalab.mastodon.client.APIResponse; import fr.gouv.etalab.mastodon.client.Entities.Account; import fr.gouv.etalab.mastodon.client.Entities.Error; import fr.gouv.etalab.mastodon.client.Entities.Results; @@ -139,9 +140,9 @@ public class PostActionAsyncTask extends AsyncTask { else uri = remoteStatus.getUrl(); } - Results search = api.search(uri); - if (search != null) { - List remoteStatuses = search.getStatuses(); + APIResponse search = api.search(uri); + if (search != null && search.getResults() != null) { + List remoteStatuses = search.getResults().getStatuses(); if (remoteStatuses != null && remoteStatuses.size() > 0) { fr.gouv.etalab.mastodon.client.Entities.Status statusTmp = remoteStatuses.get(0); this.targetedId = statusTmp.getId(); @@ -150,9 +151,9 @@ public class PostActionAsyncTask extends AsyncTask { } } else if (remoteAccount != null) { String searchString = remoteAccount.getAcct().contains("@") ? "@" + remoteAccount.getAcct() : "@" + remoteAccount.getAcct() + "@" + Helper.getLiveInstance(contextReference.get()); - Results search = api.search(searchString); - if (search != null) { - List accounts = search.getAccounts(); + APIResponse search = api.search(searchString); + if (search != null && search.getResults() != null) { + List accounts = search.getResults().getAccounts(); if (accounts != null && accounts.size() > 0) { Account accountTmp = accounts.get(0); this.targetedId = accountTmp.getId(); diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveAccountsAsyncTask.java b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveAccountsAsyncTask.java index d695c577f..b59ea270f 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveAccountsAsyncTask.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveAccountsAsyncTask.java @@ -93,6 +93,10 @@ public class RetrieveAccountsAsyncTask extends AsyncTask { apiResponse = gnuapi.getRebloggedBy(targetedId, max_id); } break; + case SEARCH: + api = new API(this.contextReference.get()); + apiResponse = api.search2(targetedId, API.searchType.ACCOUNTS, max_id); + break; case FAVOURITED: if( MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.GNU && MainActivity.social != UpdateAccountInfoAsyncTask.SOCIAL.FRIENDICA){ assert api != null; diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveRemoteDataAsyncTask.java b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveRemoteDataAsyncTask.java index fcaf9a6ee..a6331385b 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveRemoteDataAsyncTask.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveRemoteDataAsyncTask.java @@ -18,6 +18,7 @@ import android.content.Context; import android.os.AsyncTask; import java.lang.ref.WeakReference; import fr.gouv.etalab.mastodon.client.API; +import fr.gouv.etalab.mastodon.client.APIResponse; import fr.gouv.etalab.mastodon.client.Entities.Results; import fr.gouv.etalab.mastodon.helper.Helper; import fr.gouv.etalab.mastodon.interfaces.OnRetrieveRemoteAccountInterface; @@ -53,7 +54,9 @@ public class RetrieveRemoteDataAsyncTask extends AsyncTask { @Override protected Void doInBackground(Void... params) { API api = new API(this.contextReference.get()); - results = api.search(this.url); + APIResponse apiResponse = api.search(this.url); + if( apiResponse.getResults() != null) + results = apiResponse.getResults(); return null; } diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/client/API.java b/app/src/main/java/fr/gouv/etalab/mastodon/client/API.java index 9e482c835..c0e6177ac 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/client/API.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/client/API.java @@ -20,6 +20,7 @@ import android.content.SharedPreferences; import android.database.sqlite.SQLiteDatabase; import android.os.Bundle; import android.support.v4.content.LocalBroadcastManager; +import android.util.Log; import com.google.gson.JsonArray; import com.google.gson.JsonObject; @@ -3414,7 +3415,7 @@ public class API { List list_tmp = new ArrayList<>(); for(int i = 0; i < jsonArray.length(); i++){ try { - list_tmp.add(jsonArray.getString(i)); + list_tmp.add(jsonArray.getJSONObject(i).getString("name")); } catch (JSONException ignored) {} } return list_tmp; diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayAccountsFragment.java b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayAccountsFragment.java index 504a2263f..dc6374c6e 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayAccountsFragment.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayAccountsFragment.java @@ -69,7 +69,6 @@ public class DisplayAccountsFragment extends Fragment implements OnRetrieveAccou private boolean swiped; private RecyclerView lv_accounts; - @Override public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { @@ -80,7 +79,10 @@ public class DisplayAccountsFragment extends Fragment implements OnRetrieveAccou accounts = new ArrayList<>(); if (bundle != null) { type = (RetrieveAccountsAsyncTask.Type) bundle.get("type"); - targetedId = bundle.getString("targetedid", null); + if( bundle.containsKey("tag")) + targetedId = bundle.getString("tag", null); + else + targetedId = bundle.getString("targetedid", null); instance = bundle.getString("instance", null); name = bundle.getString("name", null); } @@ -113,7 +115,7 @@ public class DisplayAccountsFragment extends Fragment implements OnRetrieveAccou if (firstVisibleItem + visibleItemCount == totalItemCount) { if (!flag_loading) { flag_loading = true; - if (type == RetrieveAccountsAsyncTask.Type.FOLLOWERS || type == RetrieveAccountsAsyncTask.Type.FOLLOWING || type == RetrieveAccountsAsyncTask.Type.REBLOGGED || type == RetrieveAccountsAsyncTask.Type.FAVOURITED) + if (type == RetrieveAccountsAsyncTask.Type.SEARCH || type == RetrieveAccountsAsyncTask.Type.FOLLOWERS || type == RetrieveAccountsAsyncTask.Type.FOLLOWING || type == RetrieveAccountsAsyncTask.Type.REBLOGGED || type == RetrieveAccountsAsyncTask.Type.FAVOURITED) asyncTask = new RetrieveAccountsAsyncTask(context, type, targetedId, max_id, DisplayAccountsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); else if (type == RetrieveAccountsAsyncTask.Type.CHANNELS) asyncTask = new RetrieveAccountsAsyncTask(context, instance, name, DisplayAccountsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); @@ -135,7 +137,7 @@ public class DisplayAccountsFragment extends Fragment implements OnRetrieveAccou firstLoad = true; flag_loading = true; swiped = true; - if (type == RetrieveAccountsAsyncTask.Type.FOLLOWERS || type == RetrieveAccountsAsyncTask.Type.FOLLOWING|| type == RetrieveAccountsAsyncTask.Type.REBLOGGED || type == RetrieveAccountsAsyncTask.Type.FAVOURITED) + if (type == RetrieveAccountsAsyncTask.Type.SEARCH || type == RetrieveAccountsAsyncTask.Type.FOLLOWERS || type == RetrieveAccountsAsyncTask.Type.FOLLOWING|| type == RetrieveAccountsAsyncTask.Type.REBLOGGED || type == RetrieveAccountsAsyncTask.Type.FAVOURITED) asyncTask = new RetrieveAccountsAsyncTask(context, type, targetedId, max_id, DisplayAccountsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); else if (type == RetrieveAccountsAsyncTask.Type.CHANNELS) asyncTask = new RetrieveAccountsAsyncTask(context, instance, name, DisplayAccountsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); @@ -166,7 +168,7 @@ public class DisplayAccountsFragment extends Fragment implements OnRetrieveAccou break; } - if (type == RetrieveAccountsAsyncTask.Type.FOLLOWERS || type == RetrieveAccountsAsyncTask.Type.FOLLOWING|| type == RetrieveAccountsAsyncTask.Type.REBLOGGED || type == RetrieveAccountsAsyncTask.Type.FAVOURITED) + if (type == RetrieveAccountsAsyncTask.Type.SEARCH || type == RetrieveAccountsAsyncTask.Type.FOLLOWERS || type == RetrieveAccountsAsyncTask.Type.FOLLOWING|| type == RetrieveAccountsAsyncTask.Type.REBLOGGED || type == RetrieveAccountsAsyncTask.Type.FAVOURITED) asyncTask = new RetrieveAccountsAsyncTask(context, type, targetedId, max_id, DisplayAccountsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); else if (type == RetrieveAccountsAsyncTask.Type.CHANNELS) asyncTask = new RetrieveAccountsAsyncTask(context, instance, name, DisplayAccountsFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); @@ -213,7 +215,12 @@ public class DisplayAccountsFragment extends Fragment implements OnRetrieveAccou return; } flag_loading = (apiResponse.getMax_id() == null ); - List accounts = apiResponse.getAccounts(); + + List accounts; + if( apiResponse.getResults() != null && apiResponse.getResults().getAccounts() != null) + accounts = apiResponse.getResults().getAccounts(); + else + accounts = apiResponse.getAccounts(); if( !swiped && firstLoad && (accounts == null || accounts.size() == 0)) textviewNoAction.setVisibility(View.VISIBLE); else diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplaySearchTagsFragment.java b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplaySearchTagsFragment.java index d3e6796cf..120b09901 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplaySearchTagsFragment.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplaySearchTagsFragment.java @@ -59,10 +59,10 @@ public class DisplaySearchTagsFragment extends Fragment implements OnRetrieveSea @Override public View onCreateView(@NonNull LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) { - View rootView = inflater.inflate(R.layout.fragment_search, container, false); + View rootView = inflater.inflate(R.layout.fragment_search_tag, container, false); context = getContext(); - lv_search_tags = rootView.findViewById(R.id.lv_search_toots); + lv_search_tags = rootView.findViewById(R.id.lv_search_tags); loader = rootView.findViewById(R.id.loader); textviewNoAction = rootView.findViewById(R.id.no_action); loader.setVisibility(View.VISIBLE); diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayStatusFragment.java b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayStatusFragment.java index 015408a25..f3678b21e 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayStatusFragment.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/fragments/DisplayStatusFragment.java @@ -499,7 +499,12 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn apiResponse.setStatuses(statusesConversations); } int previousPosition = this.statuses.size(); - List statuses = apiResponse.getStatuses(); + List statuses; + + if( apiResponse.getResults() != null && apiResponse.getResults().getStatuses() != null) + statuses = apiResponse.getResults().getStatuses(); + else + statuses = apiResponse.getStatuses(); //At this point all statuses are in "List statuses" //Pagination for Pixelfed if(instanceType.equals("PIXELFED")) { @@ -984,7 +989,7 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn if (type == RetrieveFeedsAsyncTask.Type.USER || type == RetrieveFeedsAsyncTask.Type.CHANNEL) asyncTask = new RetrieveFeedsAsyncTask(context, type, targetedId, max_id, showMediaOnly, showPinned, showReply,DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); //Tag timelines - else if (type == RetrieveFeedsAsyncTask.Type.TAG) + else if (type == RetrieveFeedsAsyncTask.Type.TAG || type == RetrieveFeedsAsyncTask.Type.SEARCH) asyncTask = new RetrieveFeedsAsyncTask(context, type, tag, targetedId, max_id, DisplayStatusFragment.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); else if( type == RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE) { //Remote instances diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/helper/CrossActions.java b/app/src/main/java/fr/gouv/etalab/mastodon/helper/CrossActions.java index 5566d0563..aaf20fbd5 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/helper/CrossActions.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/helper/CrossActions.java @@ -41,6 +41,7 @@ import fr.gouv.etalab.mastodon.activities.TootActivity; import fr.gouv.etalab.mastodon.asynctasks.PostActionAsyncTask; import fr.gouv.etalab.mastodon.asynctasks.RetrieveFeedsAsyncTask; import fr.gouv.etalab.mastodon.client.API; +import fr.gouv.etalab.mastodon.client.APIResponse; import fr.gouv.etalab.mastodon.client.Entities.Account; import fr.gouv.etalab.mastodon.client.Entities.Mention; import fr.gouv.etalab.mastodon.client.Entities.Results; @@ -287,7 +288,8 @@ public class CrossActions { API api = new API(contextReference.get()); String url; url = "https://" + remoteAccount.getHost() + "/video-channels/" + remoteAccount.getAcct().split("@")[0]; - response = api.search(url); + APIResponse apiResponse = api.search(url); + response = apiResponse.getResults(); return null; } @Override @@ -328,7 +330,8 @@ public class CrossActions { else url = "https://" + remoteAccount.getInstance() + "/@" + remoteAccount.getAcct(); } - response = api.search(url); + APIResponse apiResponse = api.search(url); + response = apiResponse.getResults(); return null; } @Override @@ -369,7 +372,8 @@ public class CrossActions { @Override protected Void doInBackground(Void... voids) { API api = new API(contextReference.get(), account.getInstance(), account.getToken()); - response = api.search(remoteStatus.getUrl()); + APIResponse apiResponse = api.search(remoteStatus.getUrl()); + response = apiResponse.getResults(); return null; } @Override @@ -408,7 +412,8 @@ public class CrossActions { @Override protected Void doInBackground(Void... voids) { API api = new API(contextReference.get(), account.getInstance(), account.getToken()); - response = api.search(url); + APIResponse apiResponse = api.search(url); + response = apiResponse.getResults(); return null; } @Override @@ -479,7 +484,8 @@ public class CrossActions { @Override protected Void doInBackground(Void... voids) { API api = new API(contextReference.get(), account.getInstance(), account.getToken()); - response = api.search(status.getUrl()); + APIResponse apiResponse = api.search(status.getUrl()); + response = apiResponse.getResults(); return null; } @Override @@ -574,9 +580,9 @@ public class CrossActions { else uri = status.getUrl(); } - Results search = api.search(uri); - if (search != null) { - remoteStatuses = search.getStatuses(); + APIResponse search = api.search(uri); + if (search != null && search.getResults() != null) { + remoteStatuses = search.getResults().getStatuses(); } return null; } @@ -649,9 +655,9 @@ public class CrossActions { else uri = status.getUrl(); } - Results search = api.search(uri); - if( search != null){ - remoteStatuses = search.getStatuses(); + APIResponse search = api.search(uri); + if( search != null && search.getResults() != null){ + remoteStatuses = search.getResults().getStatuses(); } return null; }