Search in sources :

Example 1 with QuickSearchButtonListItem

use of net.osmand.plus.search.listitems.QuickSearchButtonListItem in project Osmand by osmandapp.

the class QuickSearchDialogFragment method reloadCategoriesInternal.

private void reloadCategoriesInternal() {
    try {
        if (SearchUICore.isDebugMode()) {
            LOG.info("UI >> Start loading categories");
        }
        SearchResultCollection res = searchUICore.shallowSearch(SearchAmenityTypesAPI.class, "", null);
        if (res != null) {
            List<QuickSearchListItem> rows = new ArrayList<>();
            for (SearchResult sr : res.getCurrentSearchResults()) {
                rows.add(new QuickSearchListItem(app, sr));
            }
            if (OsmandPlugin.getEnabledPlugin(OsmandRasterMapsPlugin.class) != null) {
                rows.add(new QuickSearchButtonListItem(app, R.drawable.ic_world_globe_dark, app.getString(R.string.search_online_address), new OnClickListener() {

                    @Override
                    public void onClick(View view) {
                        startOnlineSearch();
                        mainSearchFragment.getAdapter().clear();
                        updateTabbarVisibility(false);
                        openKeyboard();
                    }
                }));
            }
            rows.add(new QuickSearchButtonListItem(app, R.drawable.ic_action_search_dark, app.getString(R.string.custom_search), new OnClickListener() {

                @Override
                public void onClick(View v) {
                    PoiUIFilter filter = app.getPoiFilters().getCustomPOIFilter();
                    filter.clearFilter();
                    QuickSearchCustomPoiFragment.showDialog(QuickSearchDialogFragment.this, filter.getFilterId());
                }
            }));
            if (categoriesSearchFragment != null) {
                categoriesSearchFragment.updateListAdapter(rows, false);
            }
        }
        if (SearchUICore.isDebugMode()) {
            LOG.info("UI >> Categories loaded");
        }
    } catch (IOException e) {
        e.printStackTrace();
        app.showToastMessage(e.getMessage());
    }
}
Also used : QuickSearchButtonListItem(net.osmand.plus.search.listitems.QuickSearchButtonListItem) ArrayList(java.util.ArrayList) SearchResultCollection(net.osmand.search.SearchUICore.SearchResultCollection) QuickSearchListItem(net.osmand.plus.search.listitems.QuickSearchListItem) SearchMoreItemOnClickListener(net.osmand.plus.search.listitems.QuickSearchMoreListItem.SearchMoreItemOnClickListener) OnClickListener(android.view.View.OnClickListener) SearchResult(net.osmand.search.core.SearchResult) IOException(java.io.IOException) OsmandRasterMapsPlugin(net.osmand.plus.rastermaps.OsmandRasterMapsPlugin) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) PoiUIFilter(net.osmand.plus.poi.PoiUIFilter)

Example 2 with QuickSearchButtonListItem

use of net.osmand.plus.search.listitems.QuickSearchButtonListItem in project Osmand by osmandapp.

the class QuickSearchDialogFragment method reloadCitiesInternal.

private void reloadCitiesInternal() {
    if (SearchUICore.isDebugMode()) {
        LOG.info("UI >> Start loading nearest cities");
    }
    startNearestCitySearch();
    runCoreSearch("", false, false, new SearchResultListener() {

        @Override
        public void searchStarted(SearchPhrase phrase) {
        }

        @Override
        public void publish(SearchResultCollection res, boolean append) {
        }

        @Override
        public boolean searchFinished(SearchPhrase phrase) {
            SearchResultCollection res = getResultCollection();
            if (SearchUICore.isDebugMode()) {
                LOG.info("UI >> Nearest cities found: " + (res != null ? res.getCurrentSearchResults().size() : 0));
            }
            final OsmandSettings settings = app.getSettings();
            List<QuickSearchListItem> rows = new ArrayList<>();
            if (SearchUICore.isDebugMode()) {
                LOG.info("UI >> Start last city searching (within nearests)");
            }
            SearchResult lastCity = null;
            if (res != null) {
                citiesLoaded = res.getCurrentSearchResults().size() > 0;
                final long lastCityId = settings.getLastSearchedCity();
                for (SearchResult sr : res.getCurrentSearchResults()) {
                    if (sr.objectType == ObjectType.CITY && ((City) sr.object).getId() == lastCityId) {
                        lastCity = sr;
                        break;
                    }
                }
            }
            if (SearchUICore.isDebugMode()) {
                LOG.info("UI >> Last city found: " + (lastCity != null ? lastCity.localeName : "-"));
            }
            final String lastCityName = lastCity == null ? settings.getLastSearchedCityName() : lastCity.localeName;
            if (!Algorithms.isEmpty(lastCityName)) {
                String selectStreets = app.getString(R.string.select_street);
                String inCityName = app.getString(R.string.shared_string_in_name, lastCityName);
                Spannable spannable = new SpannableString(selectStreets + " " + inCityName);
                boolean light = settings.isLightContent();
                spannable.setSpan(new ForegroundColorSpan(getResources().getColor(light ? R.color.icon_color : R.color.color_white)), selectStreets.length() + 1, spannable.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                final SearchResult lastCityFinal = lastCity;
                rows.add(new QuickSearchButtonListItem(app, R.drawable.ic_action_street_name, spannable, new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        if (lastCityFinal == null) {
                            final long lastCityId = settings.getLastSearchedCity();
                            final LatLon lastCityPoint = settings.getLastSearchedPoint();
                            if (lastCityId != -1 && lastCityPoint != null) {
                                startLastCitySearch(lastCityPoint);
                                if (SearchUICore.isDebugMode()) {
                                    LOG.info("UI >> Start last city searching (standalone)");
                                }
                                runCoreSearch("", false, false, new SearchResultListener() {

                                    boolean cityFound = false;

                                    @Override
                                    public void publish(SearchResultCollection res, boolean append) {
                                        if (res != null) {
                                            for (SearchResult sr : res.getCurrentSearchResults()) {
                                                if (sr.objectType == ObjectType.CITY && ((City) sr.object).getId() == lastCityId) {
                                                    if (SearchUICore.isDebugMode()) {
                                                        LOG.info("UI >> Last city found: " + sr.localeName);
                                                    }
                                                    cityFound = true;
                                                    completeQueryWithObject(sr);
                                                    break;
                                                }
                                            }
                                        }
                                    }

                                    @Override
                                    public void searchStarted(SearchPhrase phrase) {
                                    }

                                    @Override
                                    public boolean searchFinished(SearchPhrase phrase) {
                                        if (!cityFound) {
                                            replaceQueryWithText(lastCityName + " ");
                                        }
                                        return false;
                                    }
                                });
                                restoreSearch();
                            } else {
                                replaceQueryWithText(lastCityName + " ");
                            }
                        } else {
                            completeQueryWithObject(lastCityFinal);
                        }
                        openKeyboard();
                    }
                }));
            }
            rows.add(new QuickSearchButtonListItem(app, R.drawable.ic_action_building_number, app.getString(R.string.select_city), new OnClickListener() {

                @Override
                public void onClick(View v) {
                    searchEditText.setHint(R.string.type_city_town);
                    startCitySearch();
                    updateTabbarVisibility(false);
                    runCoreSearch("", false, false);
                    openKeyboard();
                }
            }));
            rows.add(new QuickSearchButtonListItem(app, R.drawable.ic_action_postcode, app.getString(R.string.select_postcode), new OnClickListener() {

                @Override
                public void onClick(View v) {
                    searchEditText.setHint(R.string.type_postcode);
                    startPostcodeSearch();
                    mainSearchFragment.getAdapter().clear();
                    updateTabbarVisibility(false);
                    openKeyboard();
                }
            }));
            rows.add(new QuickSearchButtonListItem(app, R.drawable.ic_action_marker_dark, app.getString(R.string.coords_search), new OnClickListener() {

                @Override
                public void onClick(View v) {
                    LatLon latLon = searchUICore.getSearchSettings().getOriginalLocation();
                    QuickSearchCoordinatesFragment.showDialog(QuickSearchDialogFragment.this, latLon.getLatitude(), latLon.getLongitude());
                }
            }));
            if (res != null) {
                rows.add(new QuickSearchHeaderListItem(app, app.getString(R.string.nearest_cities), true));
                int limit = 15;
                for (SearchResult sr : res.getCurrentSearchResults()) {
                    if (limit > 0) {
                        rows.add(new QuickSearchListItem(app, sr));
                    }
                    limit--;
                }
            }
            addressSearchFragment.updateListAdapter(rows, false);
            if (SearchUICore.isDebugMode()) {
                LOG.info("UI >> Nearest cities loaded");
            }
            return true;
        }
    });
    restoreSearch();
}
Also used : ForegroundColorSpan(android.text.style.ForegroundColorSpan) QuickSearchButtonListItem(net.osmand.plus.search.listitems.QuickSearchButtonListItem) QuickSearchHeaderListItem(net.osmand.plus.search.listitems.QuickSearchHeaderListItem) SearchResult(net.osmand.search.core.SearchResult) SpannableString(android.text.SpannableString) City(net.osmand.data.City) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) SearchPhrase(net.osmand.search.core.SearchPhrase) OsmandSettings(net.osmand.plus.OsmandSettings) SpannableString(android.text.SpannableString) LatLon(net.osmand.data.LatLon) SearchResultCollection(net.osmand.search.SearchUICore.SearchResultCollection) SearchMoreItemOnClickListener(net.osmand.plus.search.listitems.QuickSearchMoreListItem.SearchMoreItemOnClickListener) OnClickListener(android.view.View.OnClickListener) QuickSearchListItem(net.osmand.plus.search.listitems.QuickSearchListItem) ArrayList(java.util.ArrayList) List(java.util.List) Spannable(android.text.Spannable)

Aggregations

View (android.view.View)2 OnClickListener (android.view.View.OnClickListener)2 AdapterView (android.widget.AdapterView)2 ImageView (android.widget.ImageView)2 ListView (android.widget.ListView)2 TextView (android.widget.TextView)2 ArrayList (java.util.ArrayList)2 QuickSearchButtonListItem (net.osmand.plus.search.listitems.QuickSearchButtonListItem)2 QuickSearchListItem (net.osmand.plus.search.listitems.QuickSearchListItem)2 SearchMoreItemOnClickListener (net.osmand.plus.search.listitems.QuickSearchMoreListItem.SearchMoreItemOnClickListener)2 SearchResultCollection (net.osmand.search.SearchUICore.SearchResultCollection)2 SearchResult (net.osmand.search.core.SearchResult)2 Spannable (android.text.Spannable)1 SpannableString (android.text.SpannableString)1 ForegroundColorSpan (android.text.style.ForegroundColorSpan)1 IOException (java.io.IOException)1 List (java.util.List)1 City (net.osmand.data.City)1 LatLon (net.osmand.data.LatLon)1 OsmandSettings (net.osmand.plus.OsmandSettings)1