gt:                         ArrayList<TLRPC.Chat> chats = new ArrayList<>();
context: /*
   * This is the source code of Telegram for Android v. 3.x.x.
   * It is licensed under GNU GPL v. 2 or later.
   * You should have received a copy of the license in this archive (see LICENSE).
   *
   * Copyright Nikolai Kudashov, 2013-2015.
   */
  
  package org.telegram.ui.Adapters;
  
  import android.content.Context;
  import android.text.TextUtils;
  import android.view.View;
  import android.view.ViewGroup;
  
  import org.telegram.SQLite.SQLiteCursor;
  import org.telegram.SQLite.SQLitePreparedStatement;
  import org.telegram.messenger.AndroidUtilities;
  import org.telegram.messenger.ContactsController;
  import org.telegram.messenger.LocaleController;
  import org.telegram.messenger.MessageObject;
  import org.telegram.messenger.MessagesController;
  import org.telegram.messenger.MessagesStorage;
  import org.telegram.messenger.support.widget.RecyclerView;
  import org.telegram.messenger.FileLog;
  import org.telegram.messenger.R;
  import org.telegram.tgnet.ConnectionsManager;
  import org.telegram.tgnet.NativeByteBuffer;
  import org.telegram.tgnet.RequestDelegate;
  import org.telegram.tgnet.TLObject;
  import org.telegram.tgnet.TLRPC;
  import org.telegram.ui.Cells.DialogCell;
  import org.telegram.ui.Cells.GreySectionCell;
  import org.telegram.ui.Cells.HashtagSearchCell;
  import org.telegram.ui.Cells.LoadingCell;
  import org.telegram.ui.Cells.ProfileSearchCell;
  
  import java.util.ArrayList;
  import java.util.Collections;
  import java.util.Comparator;
  import java.util.HashMap;
  import java.util.Locale;
  import java.util.Timer;
  import java.util.TimerTask;
  
  public class DialogsSearchAdapter extends BaseSearchAdapterRecycler {
  
      private Context mContext;
      private Timer searchTimer;
      private ArrayList<TLObject> searchResult = new ArrayList<>();
      private ArrayList<CharSequence> searchResultNames = new ArrayList<>();
      private ArrayList<MessageObject> searchResultMessages = new ArrayList<>();
      private ArrayList<String> searchResultHashtags = new ArrayList<>();
      private String lastSearchText;
      private int reqId = 0;
      private int lastReqId;
      private MessagesActivitySearchAdapterDelegate delegate;
      private int needMessagesSearch;
      private boolean messagesSearchEndReached;
      private String lastMessagesSearchString;
      private int lastSearchId = 0;
      private int dialogsType;
  
      private ArrayList<RecentSearchObject> recentSearchObjects = new ArrayList<>();
      private HashMap<Long, RecentSearchObject> recentSearchObjectsById = new HashMap<>();
  
      private class Holder extends RecyclerView.ViewHolder {
  
          public Holder(View itemView) {
              super(itemView);
          }
      }
  
      private class DialogSearchResult {
          public TLObject object;
          public int date;
          public CharSequence name;
      }
  
      protected static class RecentSearchObject {
          TLObject object;
          int date;
          long did;
      }
  
      public interface MessagesActivitySearchAdapterDelegate {
          void searchStateChanged(boolean searching);
      }
  
      public DialogsSearchAdapter(Context context, int messagesSearch, int type) {
          mContext = context;
          needMessagesSearch = messagesSearch;
          dialogsType = type;
          loadRecentSearch();
      }
  
      public void setDelegate(MessagesActivitySearchAdapterDelegate delegate) {
          this.delegate = delegate;
      }
  
      public boolean isMessagesSearchEndReached() {
          return messagesSearchEndReached;
      }
  
      public void loadMoreSearchMessages() {
          searchMessagesInternal(lastMessagesSearchString);
      }
  
      public String getLastSearchString() {
          return lastMessagesSearchString;
      }
  
      private void searchMessagesInternal(final String query) {
          if (needMessagesSearch == 0 || (lastMessagesSearchString == null || lastMessagesSearchString.length() == 0) && (query == null || query.length() == 0)) {
              return;
          }
          if (reqId != 0) {
              ConnectionsManager.getInstance().cancelRequest(reqId, true);
              reqId = 0;
          }
          if (query == null || query.length() == 0) {
              searchResultMessages.clear();
              lastReqId = 0;
              lastMessagesSearchString = null;
              notifyDataSetChanged();
              if (delegate != null) {
                  delegate.searchStateChanged(false);
              }
              return;
          }
          final TLRPC.TL_messages_search req = new TLRPC.TL_messages_search();
          req.limit = 20;
          req.peer = new TLRPC.TL_inputPeerEmpty();
          req.q = query;
          if (lastMessagesSearchString != null && query.equals(lastMessagesSearchString) && !searchResultMessages.isEmpty()) {
              req.max_id = searchResultMessages.get(searchResultMessages.size() - 1).getId();
          }
          lastMessagesSearchString = query;
          req.filter = new TLRPC.TL_inputMessagesFilterEmpty();
          final int currentReqId = ++lastReqId;
          if (delegate != null) {
              delegate.searchStateChanged(true);
          }
          reqId = ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() {
              @Override
              public void run(final TLObject response, final TLRPC.TL_error error) {
                  AndroidUtilities.runOnUIThread(new Runnable() {
                      @Override
                      public void run() {
                          if (currentReqId == lastReqId) {
                              if (error == null) {
                                  TLRPC.messages_Messages res = (TLRPC.messages_Messages) response;
                                  MessagesStorage.getInstance().putUsersAndChats(res.users, res.chats, true, true);
                                  MessagesController.getInstance().putUsers(res.users, false);
                                  MessagesController.getInstance().putChats(res.chats, false);
                                  if (req.max_id == 0) {
                                      searchResultMessages.clear();
                                  }
                                  for (TLRPC.Message message : res.messages) {
                                      searchResultMessages.add(new MessageObject(message, null, false));
                                  }
                                  messagesSearchEndReached = res.messages.size() != 20;
                                  notifyDataSetChanged();
                              }
                          }
                          if (delegate != null) {
                              delegate.searchStateChanged(false);
                          }
                          reqId = 0;
                      }
                  });
              }
          }, ConnectionsManager.RequestFlagFailOnServerErrors);
      }
  
      public boolean hasRecentRearch() {
          return !recentSearchObjects.isEmpty();
      }
  
      public boolean isRecentSearchDisplayed() {
          return needMessagesSearch != 2 && (lastSearchText == null || lastSearchText.length() == 0) && !recentSearchObjects.isEmpty();
      }
  
      public void loadRecentSearch() {
          MessagesStorage.getInstance().getStorageQueue().postRunnable(new Runnable() {
              @Override
              public void run() {
                  try {
                      SQLiteCursor cursor = MessagesStorage.getInstance().getDatabase().queryFinalized("SELECT did, date FROM search_recent WHERE 1");
  
                      ArrayList<Integer> usersToLoad = new ArrayList<>();
                      ArrayList<Integer> chatsToLoad = new ArrayList<>();
                      ArrayList<Integer> encryptedToLoad = new ArrayList<>();
                      ArrayList<TLRPC.User> encUsers = new ArrayList<>();
  
                      final ArrayList<RecentSearchObject> arrayList = new ArrayList<>();
                      final HashMap<Long, RecentSearchObject> hashMap = new HashMap<>();
                      while (cursor.next()) {
                          long did = cursor.longValue(0);
  
                          boolean add = false;
                          int lower_id = (int) did;
                          int high_id = (int) (did >> 32);
                          if (lower_id != 0) {
                              if (high_id == 1) {
                                  if (dialogsType == 0 && !chatsToLoad.contains(lower_id)) {
                                      chatsToLoad.add(lower_id);
                                      add = true;
                                  }
                              } else {
                                  if (lower_id > 0) {
                                      if (dialogsType != 2 && !usersToLoad.contains(lower_id)) {
                                          usersToLoad.add(lower_id);
                                          add = true;
                                      }
                                  } else {
                                      if (!chatsToLoad.contains(-lower_id)) {
                                          chatsToLoad.add(-lower_id);
                                          add = true;
                                      }
                                  }
                              }
                          } else if (dialogsType == 0) {
                              if (!encryptedToLoad.contains(high_id)) {
                                  encryptedToLoad.add(high_id);
                                  add = true;
                              }
                          }
                          if (add) {
                              RecentSearchObject recentSearchObject = new RecentSearchObject();
                              recentSearchObject.did = did;
                              recentSearchObject.date = cursor.intValue(1);
                              arrayList.add(recentSearchObject);
                              hashMap.put(recentSearchObject.did, recentSearchObject);
                          }
                      }
                      cursor.dispose();
  
  
                      ArrayList<TLRPC.User> users = new ArrayList<>();
  
                      if (!encryptedToLoad.isEmpty()) {
                          ArrayList<TLRPC.EncryptedChat> encryptedChats = new ArrayList<>();
                          MessagesStorage.getInstance().getEncryptedChatsInternal(TextUtils.join(",", encryptedToLoad), encryptedChats, usersToLoad);
                          for (int a = 0; a < encryptedChats.size(); a++) {
                              hashMap.get((long) encryptedChats.get(a).id << 32).object = encryptedChats.get(a);
                          }
                      }
  
                      if (!chatsToLoad.isEmpty()) {
  