Java Code Examples for org.telegram.messenger.AndroidUtilities#fixLocationCoord()

The following examples show how to use org.telegram.messenger.AndroidUtilities#fixLocationCoord() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BaseLocationAdapter.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public void searchPlacesWithQuery(final String query, final Location coordinate, boolean searchUser)
{
    if (coordinate == null || lastSearchLocation != null && coordinate.distanceTo(lastSearchLocation) < 200)
    {
        return;
    }
    lastSearchLocation = coordinate;
    lastSearchQuery = query;
    if (searching)
    {
        searching = false;
        if (currentRequestNum != 0)
        {
            ConnectionsManager.getInstance(currentAccount).cancelRequest(currentRequestNum, true);
            currentRequestNum = 0;
        }
    }
    searching = true;

    TLObject object = MessagesController.getInstance(currentAccount).getUserOrChat(MessagesController.getInstance(currentAccount).venueSearchBot);
    if (!(object instanceof TLRPC.User))
    {
        if (searchUser)
        {
            searchBotUser();
        }
        return;
    }
    TLRPC.User user = (TLRPC.User) object;

    TLRPC.TL_messages_getInlineBotResults req = new TLRPC.TL_messages_getInlineBotResults();
    req.query = query == null ? "" : query;
    req.bot = MessagesController.getInstance(currentAccount).getInputUser(user);
    req.offset = "";

    req.geo_point = new TLRPC.TL_inputGeoPoint();
    req.geo_point.lat = AndroidUtilities.fixLocationCoord(coordinate.getLatitude());
    req.geo_point._long = AndroidUtilities.fixLocationCoord(coordinate.getLongitude());
    req.flags |= 1;

    int lower_id = (int) dialogId;
    int high_id = (int) (dialogId >> 32);
    if (lower_id != 0)
    {
        req.peer = MessagesController.getInstance(currentAccount).getInputPeer(lower_id);
    }
    else
    {
        req.peer = new TLRPC.TL_inputPeerEmpty();
    }

    currentRequestNum = ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() ->
    {
        currentRequestNum = 0;
        searching = false;
        places.clear();
        iconUrls.clear();

        if (error != null)
        {
            if (delegate != null)
            {
                delegate.didLoadedSearchResult(places);
            }
        }
        else
        {
            TLRPC.messages_BotResults res = (TLRPC.messages_BotResults) response;
            for (int a = 0, size = res.results.size(); a < size; a++)
            {
                TLRPC.BotInlineResult result = res.results.get(a);
                if (!"venue".equals(result.type) || !(result.send_message instanceof TLRPC.TL_botInlineMessageMediaVenue))
                {
                    continue;
                }
                TLRPC.TL_botInlineMessageMediaVenue mediaVenue = (TLRPC.TL_botInlineMessageMediaVenue) result.send_message;
                iconUrls.add("https://ss3.4sqi.net/img/categories_v2/" + mediaVenue.venue_type + "_64.png");
                TLRPC.TL_messageMediaVenue venue = new TLRPC.TL_messageMediaVenue();
                venue.geo = mediaVenue.geo;
                venue.address = mediaVenue.address;
                venue.title = mediaVenue.title;
                venue.venue_type = mediaVenue.venue_type;
                venue.venue_id = mediaVenue.venue_id;
                venue.provider = mediaVenue.provider;
                places.add(venue);
            }
        }
        notifyDataSetChanged();
    }));
    notifyDataSetChanged();
}
 
Example 2
Source File: BaseLocationAdapter.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public void searchPlacesWithQuery(final String query, final Location coordinate, boolean searchUser)
{
    if (coordinate == null || lastSearchLocation != null && coordinate.distanceTo(lastSearchLocation) < 200)
    {
        return;
    }
    lastSearchLocation = coordinate;
    lastSearchQuery = query;
    if (searching)
    {
        searching = false;
        if (currentRequestNum != 0)
        {
            ConnectionsManager.getInstance(currentAccount).cancelRequest(currentRequestNum, true);
            currentRequestNum = 0;
        }
    }
    searching = true;

    TLObject object = MessagesController.getInstance(currentAccount).getUserOrChat(MessagesController.getInstance(currentAccount).venueSearchBot);
    if (!(object instanceof TLRPC.User))
    {
        if (searchUser)
        {
            searchBotUser();
        }
        return;
    }
    TLRPC.User user = (TLRPC.User) object;

    TLRPC.TL_messages_getInlineBotResults req = new TLRPC.TL_messages_getInlineBotResults();
    req.query = query == null ? "" : query;
    req.bot = MessagesController.getInstance(currentAccount).getInputUser(user);
    req.offset = "";

    req.geo_point = new TLRPC.TL_inputGeoPoint();
    req.geo_point.lat = AndroidUtilities.fixLocationCoord(coordinate.getLatitude());
    req.geo_point._long = AndroidUtilities.fixLocationCoord(coordinate.getLongitude());
    req.flags |= 1;

    int lower_id = (int) dialogId;
    int high_id = (int) (dialogId >> 32);
    if (lower_id != 0)
    {
        req.peer = MessagesController.getInstance(currentAccount).getInputPeer(lower_id);
    }
    else
    {
        req.peer = new TLRPC.TL_inputPeerEmpty();
    }

    currentRequestNum = ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() ->
    {
        currentRequestNum = 0;
        searching = false;
        places.clear();
        iconUrls.clear();

        if (error != null)
        {
            if (delegate != null)
            {
                delegate.didLoadedSearchResult(places);
            }
        }
        else
        {
            TLRPC.messages_BotResults res = (TLRPC.messages_BotResults) response;
            for (int a = 0, size = res.results.size(); a < size; a++)
            {
                TLRPC.BotInlineResult result = res.results.get(a);
                if (!"venue".equals(result.type) || !(result.send_message instanceof TLRPC.TL_botInlineMessageMediaVenue))
                {
                    continue;
                }
                TLRPC.TL_botInlineMessageMediaVenue mediaVenue = (TLRPC.TL_botInlineMessageMediaVenue) result.send_message;
                iconUrls.add("https://ss3.4sqi.net/img/categories_v2/" + mediaVenue.venue_type + "_64.png");
                TLRPC.TL_messageMediaVenue venue = new TLRPC.TL_messageMediaVenue();
                venue.geo = mediaVenue.geo;
                venue.address = mediaVenue.address;
                venue.title = mediaVenue.title;
                venue.venue_type = mediaVenue.venue_type;
                venue.venue_id = mediaVenue.venue_id;
                venue.provider = mediaVenue.provider;
                places.add(venue);
            }
        }
        notifyDataSetChanged();
    }));
    notifyDataSetChanged();
}