歌尔基办 v2.7.0版本的 MD5 值为:921fd7c85ec097e8cab7f049269b36e4

以下内容为反编译后的 BaseLocationAdapter.java 源代码,内容仅作参考


package im.ovithmjoec.ui.adapters;

import com.baidu.location.BDLocation;
import com.baidu.mapapi.model.LatLng;
import com.baidu.mapapi.utils.DistanceUtil;
import im.ovithmjoec.messenger.AndroidUtilities;
import im.ovithmjoec.messenger.FileLog;
import im.ovithmjoec.messenger.MessagesController;
import im.ovithmjoec.messenger.MessagesStorage;
import im.ovithmjoec.messenger.UserConfig;
import im.ovithmjoec.tgnet.ConnectionsManager;
import im.ovithmjoec.tgnet.RequestDelegate;
import im.ovithmjoec.tgnet.TLObject;
import im.ovithmjoec.tgnet.TLRPC;
import im.ovithmjoec.ui.adapters.BaseLocationAdapter;
import im.ovithmjoec.ui.components.RecyclerListView;
import java.util.ArrayList;
import java.util.Timer;
import java.util.TimerTask;
public abstract class BaseLocationAdapter extends RecyclerListView.SelectionAdapter {
    private int currentRequestNum;
    private BaseLocationAdapterDelegate delegate;
    private long dialogId;
    private BDLocation lastSearchLocation;
    private String lastSearchQuery;
    private Timer searchTimer;
    protected boolean searching;
    private boolean searchingUser;
    protected ArrayList<TLRPC.TL_messageMediaVenue> places = new ArrayList<>();
    protected ArrayList<String> iconUrls = new ArrayList<>();
    private int currentAccount = UserConfig.selectedAccount;

    public interface BaseLocationAdapterDelegate {
        void didLoadedSearchResult(ArrayList<TLRPC.TL_messageMediaVenue> arrayList);
    }

    public void destroy() {
        if (this.currentRequestNum != 0) {
            ConnectionsManager.getInstance(this.currentAccount).cancelRequest(this.currentRequestNum, true);
            this.currentRequestNum = 0;
        }
    }

    public void setDelegate(long j, BaseLocationAdapterDelegate baseLocationAdapterDelegate) {
        this.dialogId = j;
        this.delegate = baseLocationAdapterDelegate;
    }

    public void searchDelayed(String str, BDLocation bDLocation) {
        if (str == null || str.length() == 0) {
            this.places.clear();
            notifyDataSetChanged();
            return;
        }
        try {
            if (this.searchTimer != null) {
                this.searchTimer.cancel();
            }
        } catch (Exception e) {
            FileLog.e(e);
        }
        Timer timer = new Timer();
        this.searchTimer = timer;
        timer.schedule(new AnonymousClass1(str, bDLocation), 200L, 500L);
    }

    public class AnonymousClass1 extends TimerTask {
        final BDLocation val$coordinate;
        final String val$query;

        AnonymousClass1(String str, BDLocation bDLocation) {
            this.val$query = str;
            this.val$coordinate = bDLocation;
        }

        @Override
        public void run() {
            try {
                BaseLocationAdapter.this.searchTimer.cancel();
                BaseLocationAdapter.this.searchTimer = null;
            } catch (Exception e) {
                FileLog.e(e);
            }
            final String str = this.val$query;
            final BDLocation bDLocation = this.val$coordinate;
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    BaseLocationAdapter.AnonymousClass1.this.lambda$run$0$BaseLocationAdapter$1(str, bDLocation);
                }
            });
        }

        public void lambda$run$0$BaseLocationAdapter$1(String str, BDLocation bDLocation) {
            BaseLocationAdapter.this.lastSearchLocation = null;
            BaseLocationAdapter.this.searchPlacesWithQuery(str, bDLocation, true);
        }
    }

    private void searchBotUser() {
        if (this.searchingUser) {
            return;
        }
        this.searchingUser = true;
        TLRPC.TL_contacts_resolveUsername tL_contacts_resolveUsername = new TLRPC.TL_contacts_resolveUsername();
        tL_contacts_resolveUsername.username = MessagesController.getInstance(this.currentAccount).venueSearchBot;
        ConnectionsManager.getInstance(this.currentAccount).sendRequest(tL_contacts_resolveUsername, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                BaseLocationAdapter.this.lambda$searchBotUser$1$BaseLocationAdapter(tLObject, tL_error);
            }
        });
    }

    public void lambda$searchBotUser$1$BaseLocationAdapter(final TLObject tLObject, TLRPC.TL_error tL_error) {
        if (tLObject != null) {
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    BaseLocationAdapter.this.lambda$null$0$BaseLocationAdapter(tLObject);
                }
            });
        }
    }

    public void lambda$null$0$BaseLocationAdapter(TLObject tLObject) {
        TLRPC.TL_contacts_resolvedPeer tL_contacts_resolvedPeer = (TLRPC.TL_contacts_resolvedPeer) tLObject;
        MessagesController.getInstance(this.currentAccount).putUsers(tL_contacts_resolvedPeer.users, false);
        MessagesController.getInstance(this.currentAccount).putChats(tL_contacts_resolvedPeer.chats, false);
        MessagesStorage.getInstance(this.currentAccount).putUsersAndChats(tL_contacts_resolvedPeer.users, tL_contacts_resolvedPeer.chats, true, true);
        BDLocation bDLocation = this.lastSearchLocation;
        this.lastSearchLocation = null;
        searchPlacesWithQuery(this.lastSearchQuery, bDLocation, false);
    }

    public void searchPlacesWithQuery(String str, BDLocation bDLocation, boolean z) {
        LatLng latLng = new LatLng(bDLocation.getLatitude(), bDLocation.getLongitude());
        LatLng latLng2 = new LatLng(this.lastSearchLocation.getLatitude(), this.lastSearchLocation.getLongitude());
        if (bDLocation != null) {
            if (this.lastSearchLocation == null || DistanceUtil.getDistance(latLng2, latLng) >= 200.0d) {
                this.lastSearchLocation = bDLocation;
                this.lastSearchQuery = str;
                if (this.searching) {
                    this.searching = false;
                    if (this.currentRequestNum != 0) {
                        ConnectionsManager.getInstance(this.currentAccount).cancelRequest(this.currentRequestNum, true);
                        this.currentRequestNum = 0;
                    }
                }
                this.searching = true;
                TLObject userOrChat = MessagesController.getInstance(this.currentAccount).getUserOrChat(MessagesController.getInstance(this.currentAccount).venueSearchBot);
                if (!(userOrChat instanceof TLRPC.User)) {
                    if (z) {
                        searchBotUser();
                        return;
                    }
                    return;
                }
                TLRPC.User user = (TLRPC.User) userOrChat;
                TLRPC.TL_messages_getInlineBotResults tL_messages_getInlineBotResults = new TLRPC.TL_messages_getInlineBotResults();
                if (str == null) {
                    str = "";
                }
                tL_messages_getInlineBotResults.query = str;
                tL_messages_getInlineBotResults.bot = MessagesController.getInstance(this.currentAccount).getInputUser(user);
                tL_messages_getInlineBotResults.offset = "";
                tL_messages_getInlineBotResults.geo_point = new TLRPC.TL_inputGeoPoint();
                tL_messages_getInlineBotResults.geo_point.lat = AndroidUtilities.fixLocationCoord(bDLocation.getLatitude());
                tL_messages_getInlineBotResults.geo_point._long = AndroidUtilities.fixLocationCoord(bDLocation.getLongitude());
                tL_messages_getInlineBotResults.flags |= 1;
                int i = (int) this.dialogId;
                if (i != 0) {
                    tL_messages_getInlineBotResults.peer = MessagesController.getInstance(this.currentAccount).getInputPeer(i);
                } else {
                    tL_messages_getInlineBotResults.peer = new TLRPC.TL_inputPeerEmpty();
                }
                this.currentRequestNum = ConnectionsManager.getInstance(this.currentAccount).sendRequest(tL_messages_getInlineBotResults, new RequestDelegate() {
                    @Override
                    public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                        BaseLocationAdapter.this.lambda$searchPlacesWithQuery$3$BaseLocationAdapter(tLObject, tL_error);
                    }
                });
                notifyDataSetChanged();
            }
        }
    }

    public void lambda$searchPlacesWithQuery$3$BaseLocationAdapter(final TLObject tLObject, final TLRPC.TL_error tL_error) {
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                BaseLocationAdapter.this.lambda$null$2$BaseLocationAdapter(tL_error, tLObject);
            }
        });
    }

    public void lambda$null$2$BaseLocationAdapter(TLRPC.TL_error tL_error, TLObject tLObject) {
        this.currentRequestNum = 0;
        this.searching = false;
        this.places.clear();
        this.iconUrls.clear();
        if (tL_error != null) {
            BaseLocationAdapterDelegate baseLocationAdapterDelegate = this.delegate;
            if (baseLocationAdapterDelegate != null) {
                baseLocationAdapterDelegate.didLoadedSearchResult(this.places);
            }
        } else {
            TLRPC.messages_BotResults messages_botresults = (TLRPC.messages_BotResults) tLObject;
            int size = messages_botresults.results.size();
            for (int i = 0; i < size; i++) {
                TLRPC.BotInlineResult botInlineResult = messages_botresults.results.get(i);
                if ("venue".equals(botInlineResult.type) && (botInlineResult.send_message instanceof TLRPC.TL_botInlineMessageMediaVenue)) {
                    TLRPC.TL_botInlineMessageMediaVenue tL_botInlineMessageMediaVenue = (TLRPC.TL_botInlineMessageMediaVenue) botInlineResult.send_message;
                    ArrayList<String> arrayList = this.iconUrls;
                    arrayList.add("https://ss3.4sqi.net/img/categories_v2/" + tL_botInlineMessageMediaVenue.venue_type + "_64.png");
                    TLRPC.TL_messageMediaVenue tL_messageMediaVenue = new TLRPC.TL_messageMediaVenue();
                    tL_messageMediaVenue.geo = tL_botInlineMessageMediaVenue.geo;
                    tL_messageMediaVenue.address = tL_botInlineMessageMediaVenue.address;
                    tL_messageMediaVenue.title = tL_botInlineMessageMediaVenue.title;
                    tL_messageMediaVenue.venue_type = tL_botInlineMessageMediaVenue.venue_type;
                    tL_messageMediaVenue.venue_id = tL_botInlineMessageMediaVenue.venue_id;
                    tL_messageMediaVenue.provider = tL_botInlineMessageMediaVenue.provider;
                    this.places.add(tL_messageMediaVenue);
                }
            }
        }
        notifyDataSetChanged();
    }
}