Search in sources :

Example 1 with QuickSearchMoreListItem

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

the class QuickSearchDialogFragment method addMoreButton.

private void addMoreButton(boolean searchMoreAvailable) {
    if (!paused && !cancelPrev && mainSearchFragment != null && !isTextEmpty()) {
        QuickSearchMoreListItem moreListItem = new QuickSearchMoreListItem(app, null, new SearchMoreItemOnClickListener() {

            @Override
            public void increaseRadiusOnClick() {
                if (!interruptedSearch) {
                    SearchSettings settings = searchUICore.getSearchSettings();
                    searchUICore.updateSettings(settings.setRadiusLevel(settings.getRadiusLevel() + 1));
                }
                runCoreSearch(searchQuery, false, true);
            }

            @Override
            public void onlineSearchOnClick() {
                startOnlineSearch();
                mainSearchFragment.getAdapter().clear();
                updateTabbarVisibility(false);
                runCoreSearch(searchQuery, false, true);
            }
        });
        moreListItem.setInterruptedSearch(interruptedSearch);
        moreListItem.setEmptySearch(isResultEmpty());
        moreListItem.setOnlineSearch(isOnlineSearch());
        moreListItem.setSearchMoreAvailable(searchMoreAvailable);
        mainSearchFragment.addListItem(moreListItem);
    }
}
Also used : QuickSearchMoreListItem(net.osmand.plus.search.listitems.QuickSearchMoreListItem) SearchMoreItemOnClickListener(net.osmand.plus.search.listitems.QuickSearchMoreListItem.SearchMoreItemOnClickListener) SearchSettings(net.osmand.search.core.SearchSettings)

Example 2 with QuickSearchMoreListItem

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

the class QuickSearchListAdapter method getView.

@NonNull
@Override
public View getView(final int position, View convertView, @NonNull ViewGroup parent) {
    final QuickSearchListItem listItem = getItem(position);
    QuickSearchListItemType type = listItem.getType();
    LinearLayout view;
    if (type == QuickSearchListItemType.SEARCH_MORE) {
        if (convertView == null) {
            LayoutInflater inflater = (LayoutInflater) app.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            view = (LinearLayout) inflater.inflate(R.layout.search_more_list_item, null);
        } else {
            view = (LinearLayout) convertView;
        }
        if (listItem.getSpannableName() != null) {
            ((TextView) view.findViewById(R.id.title)).setText(listItem.getSpannableName());
        } else {
            ((TextView) view.findViewById(R.id.title)).setText(listItem.getName());
        }
        final QuickSearchMoreListItem searchMoreItem = (QuickSearchMoreListItem) listItem;
        int emptyDescId = searchMoreItem.isSearchMoreAvailable() ? R.string.nothing_found_descr : R.string.modify_the_search_query;
        ((TextView) view.findViewById(R.id.empty_search_description)).setText(emptyDescId);
        boolean emptySearchVisible = searchMoreItem.isEmptySearch() && !searchMoreItem.isInterruptedSearch();
        boolean moreDividerVisible = emptySearchVisible && searchMoreItem.isSearchMoreAvailable();
        view.findViewById(R.id.empty_search).setVisibility(emptySearchVisible ? View.VISIBLE : View.GONE);
        view.findViewById(R.id.more_divider).setVisibility(moreDividerVisible ? View.VISIBLE : View.GONE);
        SearchUICore searchUICore = app.getSearchUICore().getCore();
        String textTitle = app.getString(R.string.nothing_found_in_radius) + " " + OsmAndFormatter.getFormattedDistance(searchUICore.getMinimalSearchRadius(searchUICore.getPhrase()), app);
        ((TextView) view.findViewById(R.id.empty_search_title)).setText(textTitle);
        View increaseRadiusRow = view.findViewById(R.id.increase_radius_row);
        increaseRadiusRow.setVisibility(searchMoreItem.isSearchMoreAvailable() ? View.VISIBLE : View.GONE);
        increaseRadiusRow.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                ((QuickSearchMoreListItem) listItem).increaseRadiusOnClick();
            }
        });
        if (!searchMoreItem.isOnlineSearch()) {
            View onlineSearchRow = view.findViewById(R.id.online_search_row);
            onlineSearchRow.setVisibility(View.VISIBLE);
            onlineSearchRow.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View view) {
                    searchMoreItem.onlineSearchOnClick();
                }
            });
        }
    } else if (type == QuickSearchListItemType.BUTTON) {
        if (convertView == null) {
            LayoutInflater inflater = (LayoutInflater) app.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            view = (LinearLayout) inflater.inflate(R.layout.search_custom_list_item, null);
        } else {
            view = (LinearLayout) convertView;
        }
        ((ImageView) view.findViewById(R.id.imageView)).setImageDrawable(listItem.getIcon());
        if (listItem.getSpannableName() != null) {
            ((TextView) view.findViewById(R.id.title)).setText(listItem.getSpannableName());
        } else {
            ((TextView) view.findViewById(R.id.title)).setText(listItem.getName());
        }
    } else if (type == QuickSearchListItemType.SELECT_ALL) {
        if (convertView == null) {
            LayoutInflater inflater = (LayoutInflater) app.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            view = (LinearLayout) inflater.inflate(R.layout.select_all_list_item, null);
        } else {
            view = (LinearLayout) convertView;
        }
        final CheckBox ch = (CheckBox) view.findViewById(R.id.toggle_item);
        ch.setVisibility(View.VISIBLE);
        ch.setChecked(selectAll);
        ch.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                toggleCheckbox(position, ch);
            }
        });
    } else if (type == QuickSearchListItemType.HEADER) {
        if (convertView == null) {
            LayoutInflater inflater = (LayoutInflater) app.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            view = (LinearLayout) inflater.inflate(R.layout.search_header_list_item, null);
        } else {
            view = (LinearLayout) convertView;
        }
        view.findViewById(R.id.top_divider).setVisibility(((QuickSearchHeaderListItem) listItem).isShowTopDivider() ? View.VISIBLE : View.GONE);
        if (listItem.getSpannableName() != null) {
            ((TextView) view.findViewById(R.id.title)).setText(listItem.getSpannableName());
        } else {
            ((TextView) view.findViewById(R.id.title)).setText(listItem.getName());
        }
    } else if (type == QuickSearchListItemType.TOP_SHADOW) {
        if (convertView == null) {
            LayoutInflater inflater = (LayoutInflater) app.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            view = (LinearLayout) inflater.inflate(R.layout.list_shadow_header, null);
        } else {
            view = (LinearLayout) convertView;
        }
        return view;
    } else if (type == QuickSearchListItemType.BOTTOM_SHADOW) {
        if (convertView == null) {
            LayoutInflater inflater = (LayoutInflater) app.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            view = (LinearLayout) inflater.inflate(R.layout.list_shadow_footer, null);
        } else {
            view = (LinearLayout) convertView;
        }
        return view;
    } else {
        if (convertView == null) {
            LayoutInflater inflater = (LayoutInflater) app.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            view = (LinearLayout) inflater.inflate(R.layout.search_list_item, null);
        } else {
            view = (LinearLayout) convertView;
        }
        final CheckBox ch = (CheckBox) view.findViewById(R.id.toggle_item);
        if (selectionMode) {
            ch.setVisibility(View.VISIBLE);
            ch.setChecked(selectedItems.contains(listItem));
            ch.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    toggleCheckbox(position, ch);
                }
            });
        } else {
            ch.setVisibility(View.GONE);
        }
        ImageView imageView = (ImageView) view.findViewById(R.id.imageView);
        TextView title = (TextView) view.findViewById(R.id.title);
        TextView subtitle = (TextView) view.findViewById(R.id.subtitle);
        imageView.setImageDrawable(listItem.getIcon());
        String name = listItem.getName();
        if (listItem.getSpannableName() != null) {
            title.setText(listItem.getSpannableName());
        } else {
            title.setText(name);
        }
        String desc = listItem.getTypeName();
        Object searchResultObject = listItem.getSearchResult().object;
        if (searchResultObject instanceof AbstractPoiType) {
            AbstractPoiType abstractPoiType = (AbstractPoiType) searchResultObject;
            String[] synonyms = abstractPoiType.getSynonyms().split(";");
            QuickSearchHelper searchHelper = app.getSearchUICore();
            SearchUICore searchUICore = searchHelper.getCore();
            String searchPhrase = searchUICore.getPhrase().getText(true);
            SearchPhrase.NameStringMatcher nm = new SearchPhrase.NameStringMatcher(searchPhrase, CollatorStringMatcher.StringMatcherMode.CHECK_STARTS_FROM_SPACE);
            if (!searchPhrase.isEmpty() && !nm.matches(abstractPoiType.getTranslation())) {
                if (nm.matches(abstractPoiType.getEnTranslation())) {
                    desc = listItem.getTypeName() + " (" + abstractPoiType.getEnTranslation() + ")";
                } else {
                    for (String syn : synonyms) {
                        if (nm.matches(syn)) {
                            desc = listItem.getTypeName() + " (" + syn + ")";
                            break;
                        }
                    }
                }
            }
        }
        boolean hasDesc = false;
        if (!Algorithms.isEmpty(desc) && !desc.equals(name)) {
            subtitle.setText(desc);
            subtitle.setVisibility(View.VISIBLE);
            hasDesc = true;
        } else {
            subtitle.setVisibility(View.GONE);
        }
        Drawable typeIcon = listItem.getTypeIcon();
        ImageView group = (ImageView) view.findViewById(R.id.type_name_icon);
        if (typeIcon != null && hasDesc) {
            group.setImageDrawable(typeIcon);
            group.setVisibility(View.VISIBLE);
        } else {
            group.setVisibility(View.GONE);
        }
        LinearLayout timeLayout = (LinearLayout) view.findViewById(R.id.time_layout);
        TextView timeText = (TextView) view.findViewById(R.id.time);
        ImageView timeIcon = (ImageView) view.findViewById(R.id.time_icon);
        if (listItem.getSearchResult().object instanceof Amenity && ((Amenity) listItem.getSearchResult().object).getOpeningHours() != null) {
            Amenity amenity = (Amenity) listItem.getSearchResult().object;
            OpeningHoursParser.OpeningHours rs = OpeningHoursParser.parseOpenedHours(amenity.getOpeningHours());
            if (rs != null) {
                Calendar inst = Calendar.getInstance();
                inst.setTimeInMillis(System.currentTimeMillis());
                boolean worksNow = rs.isOpenedForTime(inst);
                // 30 minutes later
                inst.setTimeInMillis(System.currentTimeMillis() + 30 * 60 * 1000);
                boolean worksLater = rs.isOpenedForTime(inst);
                int colorId = worksNow ? worksLater ? R.color.color_ok : R.color.color_intermediate : R.color.color_warning;
                timeLayout.setVisibility(View.VISIBLE);
                timeIcon.setImageDrawable(app.getIconsCache().getIcon(R.drawable.ic_small_time, colorId));
                timeText.setTextColor(app.getResources().getColor(colorId));
                String rt = rs.getCurrentRuleTime(inst);
                timeText.setText(rt == null ? "" : rt);
            } else {
                timeLayout.setVisibility(View.GONE);
            }
        } else {
            timeLayout.setVisibility(View.GONE);
        }
        updateCompassVisibility(view, listItem);
    }
    view.setBackgroundColor(app.getResources().getColor(app.getSettings().isLightContent() ? R.color.bg_color_light : R.color.bg_color_dark));
    View divider = view.findViewById(R.id.divider);
    if (divider != null) {
        if (position == getCount() - 1 || getItem(position + 1).getType() == QuickSearchListItemType.HEADER || getItem(position + 1).getType() == QuickSearchListItemType.BOTTOM_SHADOW) {
            divider.setVisibility(View.GONE);
        } else {
            divider.setVisibility(View.VISIBLE);
            if (getItem(position + 1).getType() == QuickSearchListItemType.SEARCH_MORE || type == QuickSearchListItemType.SELECT_ALL) {
                LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, dp1);
                p.setMargins(0, 0, 0, 0);
                divider.setLayoutParams(p);
            } else {
                LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, dp1);
                p.setMargins(dp56, 0, 0, 0);
                divider.setLayoutParams(p);
            }
        }
    }
    ViewCompat.setAccessibilityDelegate(view, accessibilityAssistant);
    return view;
}
Also used : QuickSearchMoreListItem(net.osmand.plus.search.listitems.QuickSearchMoreListItem) SearchPhrase(net.osmand.search.core.SearchPhrase) QuickSearchListItemType(net.osmand.plus.search.listitems.QuickSearchListItemType) QuickSearchListItem(net.osmand.plus.search.listitems.QuickSearchListItem) TextView(android.widget.TextView) ImageView(android.widget.ImageView) Amenity(net.osmand.data.Amenity) Calendar(java.util.Calendar) Drawable(android.graphics.drawable.Drawable) AbstractPoiType(net.osmand.osm.AbstractPoiType) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) SearchUICore(net.osmand.search.SearchUICore) CheckBox(android.widget.CheckBox) LayoutInflater(android.view.LayoutInflater) LinearLayout(android.widget.LinearLayout) NonNull(android.support.annotation.NonNull)

Aggregations

QuickSearchMoreListItem (net.osmand.plus.search.listitems.QuickSearchMoreListItem)2 Drawable (android.graphics.drawable.Drawable)1 NonNull (android.support.annotation.NonNull)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 CheckBox (android.widget.CheckBox)1 ImageView (android.widget.ImageView)1 LinearLayout (android.widget.LinearLayout)1 TextView (android.widget.TextView)1 Calendar (java.util.Calendar)1 Amenity (net.osmand.data.Amenity)1 AbstractPoiType (net.osmand.osm.AbstractPoiType)1 QuickSearchListItem (net.osmand.plus.search.listitems.QuickSearchListItem)1 QuickSearchListItemType (net.osmand.plus.search.listitems.QuickSearchListItemType)1 SearchMoreItemOnClickListener (net.osmand.plus.search.listitems.QuickSearchMoreListItem.SearchMoreItemOnClickListener)1 SearchUICore (net.osmand.search.SearchUICore)1 SearchPhrase (net.osmand.search.core.SearchPhrase)1 SearchSettings (net.osmand.search.core.SearchSettings)1