Search in sources :

Example 1 with WikivoyageSearchHistoryItem

use of net.osmand.plus.wikivoyage.data.WikivoyageSearchHistoryItem in project Osmand by osmandapp.

the class SearchRecyclerViewAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int pos) {
    if (viewHolder instanceof HeaderVH) {
        ((HeaderVH) viewHolder).title.setText((String) getItem(pos));
    } else {
        ItemVH holder = (ItemVH) viewHolder;
        boolean lastItem = pos == getItemCount() - 1;
        Object item = getItem(pos);
        if (item instanceof WikivoyageSearchResult) {
            WikivoyageSearchResult searchRes = (WikivoyageSearchResult) item;
            RequestCreator rc = Picasso.get().load(TravelArticle.getImageUrl(searchRes.getImageTitle(), true));
            WikivoyageUtils.setupNetworkPolicy(app.getSettings(), rc);
            rc.transform(new CropCircleTransformation()).placeholder(placeholder).into(holder.icon);
            holder.title.setText(searchRes.getArticleTitle());
            holder.leftDescr.setText(searchRes.getIsPartOf());
            holder.rightDescr.setText(searchRes.getFirstLangsString());
        } else {
            WikivoyageSearchHistoryItem historyItem = (WikivoyageSearchHistoryItem) item;
            holder.icon.setImageDrawable(historyPlaceholder);
            holder.title.setText(historyItem.getArticleTitle());
            holder.leftDescr.setText(historyItem.getIsPartOf());
            holder.rightDescr.setText(Algorithms.capitalizeFirstLetter(historyItem.getLang()));
        }
        holder.divider.setVisibility(lastItem ? View.GONE : View.VISIBLE);
        holder.shadow.setVisibility(lastItem ? View.VISIBLE : View.GONE);
    }
}
Also used : WikivoyageSearchHistoryItem(net.osmand.plus.wikivoyage.data.WikivoyageSearchHistoryItem) CropCircleTransformation(net.osmand.plus.widgets.tools.CropCircleTransformation) WikivoyageSearchResult(net.osmand.plus.wikivoyage.data.WikivoyageSearchResult) RequestCreator(com.squareup.picasso.RequestCreator)

Example 2 with WikivoyageSearchHistoryItem

use of net.osmand.plus.wikivoyage.data.WikivoyageSearchHistoryItem in project Osmand by osmandapp.

the class WikivoyageSearchDialogFragment method onCreateView.

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    final OsmandApplication app = getMyApplication();
    searchHelper = new WikivoyageSearchHelper(app);
    final View mainView = inflate(R.layout.fragment_wikivoyage_search_dialog, container);
    Toolbar toolbar = (Toolbar) mainView.findViewById(R.id.toolbar);
    setupToolbar(toolbar);
    toolbar.setContentInsetStartWithNavigation(getResources().getDimensionPixelOffset(R.dimen.wikivoyage_search_divider_margin_start));
    searchEt = (EditText) toolbar.findViewById(R.id.searchEditText);
    searchEt.setHint(R.string.shared_string_search);
    searchEt.addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            String newQuery = s.toString();
            if (!searchQuery.equalsIgnoreCase(newQuery)) {
                searchQuery = newQuery;
                if (searchQuery.isEmpty()) {
                    cancelSearch();
                    setAdapterItems(null);
                } else {
                    runSearch();
                }
            }
        }
    });
    progressBar = (ProgressBar) toolbar.findViewById(R.id.searchProgressBar);
    clearIb = (ImageButton) toolbar.findViewById(R.id.clearButton);
    clearIb.setImageDrawable(getContentIcon(R.drawable.ic_action_remove_dark));
    clearIb.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            searchEt.setText("");
        }
    });
    adapter = new SearchRecyclerViewAdapter(app);
    final RecyclerView rv = (RecyclerView) mainView.findViewById(R.id.recycler_view);
    rv.setLayoutManager(new LinearLayoutManager(getContext()));
    rv.setAdapter(adapter);
    adapter.setOnItemClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            int pos = rv.getChildAdapterPosition(v);
            FragmentManager fm = getFragmentManager();
            if (pos != RecyclerView.NO_POSITION && fm != null) {
                Object item = adapter.getItem(pos);
                if (item instanceof WikivoyageSearchResult) {
                    WikivoyageSearchResult res = (WikivoyageSearchResult) item;
                    WikivoyageArticleDialogFragment.showInstance(fm, res.getArticleId(), new ArrayList<>(res.getLangs()));
                } else if (item instanceof WikivoyageSearchHistoryItem) {
                    WikivoyageSearchHistoryItem historyItem = (WikivoyageSearchHistoryItem) item;
                    WikivoyageArticleDialogFragment.showInstanceByTitle(app, fm, historyItem.getArticleTitle(), historyItem.getLang());
                }
            }
        }
    });
    return mainView;
}
Also used : WikivoyageSearchHistoryItem(net.osmand.plus.wikivoyage.data.WikivoyageSearchHistoryItem) OsmandApplication(net.osmand.plus.OsmandApplication) ArrayList(java.util.ArrayList) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) FragmentManager(androidx.fragment.app.FragmentManager) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) WikivoyageSearchResult(net.osmand.plus.wikivoyage.data.WikivoyageSearchResult) RecyclerView(androidx.recyclerview.widget.RecyclerView) Toolbar(androidx.appcompat.widget.Toolbar) Nullable(androidx.annotation.Nullable)

Aggregations

WikivoyageSearchHistoryItem (net.osmand.plus.wikivoyage.data.WikivoyageSearchHistoryItem)2 WikivoyageSearchResult (net.osmand.plus.wikivoyage.data.WikivoyageSearchResult)2 Editable (android.text.Editable)1 TextWatcher (android.text.TextWatcher)1 View (android.view.View)1 Nullable (androidx.annotation.Nullable)1 Toolbar (androidx.appcompat.widget.Toolbar)1 FragmentManager (androidx.fragment.app.FragmentManager)1 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 RequestCreator (com.squareup.picasso.RequestCreator)1 ArrayList (java.util.ArrayList)1 OsmandApplication (net.osmand.plus.OsmandApplication)1 CropCircleTransformation (net.osmand.plus.widgets.tools.CropCircleTransformation)1