Search in sources :

Example 1 with WikivoyageSearchResult

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

the class WikivoyageArticleNavigationFragment method createNavigationListView.

private ExpandableListAdapter createNavigationListView(Map<WikivoyageSearchResult, List<WikivoyageSearchResult>> navigationMap) {
    final Context ctx = requireContext();
    expListView = new ExpandableListView(ctx);
    final ExpandableListAdapter listAdapter = new ExpandableListAdapter(ctx, navigationMap);
    expListView.setAdapter(listAdapter);
    Drawable transparent = AppCompatResources.getDrawable(ctx, R.color.color_transparent);
    expListView.setDivider(transparent);
    expListView.setGroupIndicator(transparent);
    expListView.setSelector(transparent);
    expListView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
    expListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {

        @Override
        public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
            WikivoyageSearchResult articleItem = listAdapter.getArticleItem(groupPosition, childPosition);
            sendResults(articleItem.getArticleTitle());
            dismiss();
            return true;
        }
    });
    expListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {

        @Override
        public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
            WikivoyageSearchResult articleItem = (WikivoyageSearchResult) listAdapter.getGroup(groupPosition);
            if (Algorithms.isEmpty(articleItem.getArticleTitle())) {
                Toast.makeText(ctx, R.string.wiki_article_not_found, Toast.LENGTH_LONG).show();
            } else {
                sendResults(articleItem.getArticleTitle());
                dismiss();
            }
            return true;
        }
    });
    return listAdapter;
}
Also used : Context(android.content.Context) Drawable(android.graphics.drawable.Drawable) OsmandBaseExpandableListAdapter(net.osmand.plus.base.OsmandBaseExpandableListAdapter) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) ExpandableListView(android.widget.ExpandableListView) WikivoyageSearchResult(net.osmand.plus.wikivoyage.data.WikivoyageSearchResult) ExpandableListView(android.widget.ExpandableListView) LinearLayout(android.widget.LinearLayout)

Example 2 with WikivoyageSearchResult

use of net.osmand.plus.wikivoyage.data.WikivoyageSearchResult 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 3 with WikivoyageSearchResult

use of net.osmand.plus.wikivoyage.data.WikivoyageSearchResult 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

WikivoyageSearchResult (net.osmand.plus.wikivoyage.data.WikivoyageSearchResult)3 View (android.view.View)2 WikivoyageSearchHistoryItem (net.osmand.plus.wikivoyage.data.WikivoyageSearchHistoryItem)2 Context (android.content.Context)1 Drawable (android.graphics.drawable.Drawable)1 Editable (android.text.Editable)1 TextWatcher (android.text.TextWatcher)1 ExpandableListView (android.widget.ExpandableListView)1 ImageView (android.widget.ImageView)1 LinearLayout (android.widget.LinearLayout)1 TextView (android.widget.TextView)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 OsmandBaseExpandableListAdapter (net.osmand.plus.base.OsmandBaseExpandableListAdapter)1