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;
}
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);
}
}
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;
}
Aggregations