Search in sources :

Example 6 with QuickSearchListItem

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

the class QuickSearchListAdapter method setSelectionMode.

public void setSelectionMode(boolean selectionMode, int position) {
    this.selectionMode = selectionMode;
    selectAll = false;
    selectedItems.clear();
    if (position != -1) {
        QuickSearchListItem item = getItem(position);
        selectedItems.add(item);
    }
    if (selectionMode) {
        QuickSearchSelectAllListItem selectAllListItem = new QuickSearchSelectAllListItem(app, null, null);
        insertListItem(selectAllListItem, 0);
        if (selectionListener != null) {
            selectionListener.onUpdateSelectionMode(selectedItems);
        }
    } else {
        if (selectionListener != null) {
            selectionListener.reloadData();
        }
    }
// notifyDataSetInvalidated();
}
Also used : QuickSearchListItem(net.osmand.plus.search.listitems.QuickSearchListItem) QuickSearchSelectAllListItem(net.osmand.plus.search.listitems.QuickSearchSelectAllListItem)

Example 7 with QuickSearchListItem

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

the class QuickSearchListFragment method updateListAdapter.

public void updateListAdapter(List<QuickSearchListItem> listItems, boolean append) {
    if (listAdapter != null) {
        List<QuickSearchListItem> list = new ArrayList<>(listItems);
        if (list.size() > 0) {
            list.add(0, new QuickSearchTopShadowListItem(getMyApplication()));
            list.add(new QuickSearchBottomShadowListItem(getMyApplication()));
        }
        listAdapter.setListItems(list);
        if (!append) {
            getListView().setSelection(0);
        }
    }
}
Also used : QuickSearchTopShadowListItem(net.osmand.plus.search.listitems.QuickSearchTopShadowListItem) ArrayList(java.util.ArrayList) QuickSearchListItem(net.osmand.plus.search.listitems.QuickSearchListItem) QuickSearchBottomShadowListItem(net.osmand.plus.search.listitems.QuickSearchBottomShadowListItem)

Example 8 with QuickSearchListItem

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

the class QuickSearchListAdapter method setListItems.

public void setListItems(List<QuickSearchListItem> items) {
    setNotifyOnChange(false);
    clear();
    hasSearchMoreItem = false;
    for (QuickSearchListItem item : items) {
        add(item);
        if (!hasSearchMoreItem && item.getType() == QuickSearchListItemType.SEARCH_MORE) {
            hasSearchMoreItem = true;
        }
    }
    setNotifyOnChange(true);
    notifyDataSetChanged();
}
Also used : QuickSearchListItem(net.osmand.plus.search.listitems.QuickSearchListItem)

Example 9 with QuickSearchListItem

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

the class QuickSearchListAdapter method toggleCheckbox.

public void toggleCheckbox(int position, CheckBox ch) {
    QuickSearchListItemType type = getItem(position).getType();
    if (type == QuickSearchListItemType.SELECT_ALL) {
        selectAll = ch.isChecked();
        if (ch.isChecked()) {
            selectedItems.clear();
            for (int i = 0; i < getCount(); i++) {
                QuickSearchListItemType t = getItem(i).getType();
                if (t == QuickSearchListItemType.SEARCH_RESULT) {
                    selectedItems.add(getItem(i));
                }
            }
        } else {
            selectedItems.clear();
        }
        notifyDataSetChanged();
        if (selectionListener != null) {
            selectionListener.onUpdateSelectionMode(selectedItems);
        }
    } else {
        QuickSearchListItem listItem = getItem(position);
        if (ch.isChecked()) {
            selectedItems.add(listItem);
        } else {
            selectedItems.remove(listItem);
        }
        if (selectionListener != null) {
            selectionListener.onUpdateSelectionMode(selectedItems);
        }
    }
}
Also used : QuickSearchListItemType(net.osmand.plus.search.listitems.QuickSearchListItemType) QuickSearchListItem(net.osmand.plus.search.listitems.QuickSearchListItem)

Example 10 with QuickSearchListItem

use of net.osmand.plus.search.listitems.QuickSearchListItem 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

QuickSearchListItem (net.osmand.plus.search.listitems.QuickSearchListItem)11 ArrayList (java.util.ArrayList)7 SearchResult (net.osmand.search.core.SearchResult)5 View (android.view.View)4 ImageView (android.widget.ImageView)4 TextView (android.widget.TextView)4 OnClickListener (android.view.View.OnClickListener)3 AdapterView (android.widget.AdapterView)3 ListView (android.widget.ListView)3 SearchMoreItemOnClickListener (net.osmand.plus.search.listitems.QuickSearchMoreListItem.SearchMoreItemOnClickListener)3 SearchResultCollection (net.osmand.search.SearchUICore.SearchResultCollection)3 SearchPhrase (net.osmand.search.core.SearchPhrase)3 SpannableString (android.text.SpannableString)2 IOException (java.io.IOException)2 List (java.util.List)2 LatLon (net.osmand.data.LatLon)2 AbstractPoiType (net.osmand.osm.AbstractPoiType)2 PoiUIFilter (net.osmand.plus.poi.PoiUIFilter)2 QuickSearchBottomShadowListItem (net.osmand.plus.search.listitems.QuickSearchBottomShadowListItem)2 QuickSearchButtonListItem (net.osmand.plus.search.listitems.QuickSearchButtonListItem)2