Commit 28021b50 authored by Thomas's avatar Thomas
Browse files

Fix issue #1131 - User search suggestions have duplicates

parent 7b2e44c4
Loading
Loading
Loading
Loading
+7 −6
Original line number Diff line number Diff line
@@ -1527,14 +1527,14 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
                    int[] to = new int[]{R.id.account_pp, R.id.account_un};
                    String searchGroup = matcherMention.group();
                    AccountsVM accountsVM = new ViewModelProvider(BaseMainActivity.this).get(AccountsVM.class);
                    MatrixCursor cursor = new MatrixCursor(new String[]{BaseColumns._ID,
                            SearchManager.SUGGEST_COLUMN_ICON_1,
                            SearchManager.SUGGEST_COLUMN_TEXT_1});
                    accountsVM.searchAccounts(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, searchGroup, 5, false, false)
                    accountsVM.searchAccounts(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, searchGroup, 10, false, false)
                            .observe(BaseMainActivity.this, accounts -> {
                                if (accounts == null) {
                                    return;
                                }
                                MatrixCursor cursor = new MatrixCursor(new String[]{BaseColumns._ID,
                                        SearchManager.SUGGEST_COLUMN_ICON_1,
                                        SearchManager.SUGGEST_COLUMN_TEXT_1});
                                AccountsSearchTopBarAdapter cursorAdapter = new AccountsSearchTopBarAdapter(BaseMainActivity.this, accounts, R.layout.drawer_account_search, null, from, to, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
                                binding.toolbarSearch.setSuggestionsAdapter(cursorAdapter);
                                new Thread(() -> {
@@ -1562,8 +1562,7 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
                    String[] from = new String[]{SearchManager.SUGGEST_COLUMN_TEXT_1};
                    int[] to = new int[]{R.id.tag_name};
                    String searchGroup = matcherTag.group();
                    MatrixCursor cursor = new MatrixCursor(new String[]{BaseColumns._ID,
                            SearchManager.SUGGEST_COLUMN_TEXT_1});

                    searchVM.search(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, searchGroup, null,
                            "hashtags", false, true, false, 0,
                            null, null, 10).observe(BaseMainActivity.this,
@@ -1571,6 +1570,8 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
                                if (results == null || results.hashtags == null) {
                                    return;
                                }
                                MatrixCursor cursor = new MatrixCursor(new String[]{BaseColumns._ID,
                                        SearchManager.SUGGEST_COLUMN_TEXT_1});
                                TagSearchTopBarAdapter cursorAdapter = new TagSearchTopBarAdapter(BaseMainActivity.this, results.hashtags, R.layout.drawer_tag_search, null, from, to, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
                                binding.toolbarSearch.setSuggestionsAdapter(cursorAdapter);
                                int i = 0;
+11 −3
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@ package app.fedilab.android.mastodon.ui.drawer;
 * You should have received a copy of the GNU General Public License along with Fedilab; if not,
 * see <http://www.gnu.org/licenses>. */


import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
@@ -30,6 +31,7 @@ import java.util.List;
import app.fedilab.android.R;
import app.fedilab.android.mastodon.activities.HashTagActivity;
import app.fedilab.android.mastodon.client.entities.api.Tag;
import app.fedilab.android.mastodon.client.entities.app.CachedBundle;
import app.fedilab.android.mastodon.helper.Helper;


@@ -63,9 +65,15 @@ public class TagSearchTopBarAdapter extends SimpleCursorAdapter {
            if (tags != null && tags.size() > position) {
                Intent intent = new Intent(context, HashTagActivity.class);
                Bundle b = new Bundle();
                b.putString(Helper.ARG_SEARCH_KEYWORD, tags.get(position).name.trim());
                intent.putExtras(b);
                String tag = tags.get(position).name.trim().replace("#","");
                b.putString(Helper.ARG_SEARCH_KEYWORD, tag.trim());
                new CachedBundle(context).insertBundle(b, Helper.getCurrentAccount(context), bundleId -> {
                    Bundle bundle = new Bundle();
                    bundle.putLong(Helper.ARG_INTENT_ID, bundleId);
                    intent.putExtras(bundle);
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    context.startActivity(intent);
                });
            }
        });
    }