[new downloader][android] add: Highlight found results in downloader.

This commit is contained in:
Alexander Marchuk 2016-03-24 17:00:59 +03:00
parent 9402816748
commit 3c2c437ec0
3 changed files with 24 additions and 7 deletions

View file

@ -3,6 +3,7 @@ package com.mapswithme.maps.downloader;
import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Typeface;
import android.location.Location;
import android.support.annotation.AttrRes;
import android.support.annotation.DrawableRes;
@ -11,7 +12,10 @@ import android.support.annotation.StringRes;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.style.StyleSpan;
import android.util.SparseArray;
import android.util.SparseIntArray;
import android.view.LayoutInflater;
@ -53,6 +57,8 @@ class DownloaderAdapter extends RecyclerView.Adapter<DownloaderAdapter.ViewHolde
private final StickyRecyclerHeadersDecoration mHeadersDecoration;
private boolean mSearchResultsMode;
private String mSearchQuery;
private final List<CountryItem> mItems = new ArrayList<>();
private final Map<String, CountryItem> mCountryIndex = new HashMap<>(); // Country.id -> Country
@ -490,8 +496,17 @@ class DownloaderAdapter extends RecyclerView.Adapter<DownloaderAdapter.ViewHolde
if (mSearchResultsMode)
{
String found = mItem.searchResultName.toLowerCase();
SpannableStringBuilder builder = new SpannableStringBuilder(mItem.searchResultName);
int start = found.indexOf(mSearchQuery);
int end = start + mSearchQuery.length();
if (start > -1)
builder.setSpan(new StyleSpan(Typeface.BOLD), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
mSearchFoundName.setText(builder);
mSearchName.setText(mItem.name);
mSearchFoundName.setText(mItem.searchResultName);
UiUtils.setTextAndHideIfEmpty(mSearchParent, mItem.parentName);
}
else
@ -576,6 +591,7 @@ class DownloaderAdapter extends RecyclerView.Adapter<DownloaderAdapter.ViewHolde
private void refreshData()
{
mSearchResultsMode = false;
mSearchQuery = null;
mItems.clear();
@ -605,9 +621,10 @@ class DownloaderAdapter extends RecyclerView.Adapter<DownloaderAdapter.ViewHolde
refreshData();
}
void setSearchResultsMode(Collection<CountryItem> results)
void setSearchResultsMode(Collection<CountryItem> results, String query)
{
mSearchResultsMode = true;
mSearchQuery = query.toLowerCase();
mItems.clear();
mItems.addAll(results);

View file

@ -68,7 +68,7 @@ public class DownloaderFragment extends BaseMwmRecyclerFragment
if (isLast)
{
mAdapter.setSearchResultsMode(mResults.values());
mAdapter.setSearchResultsMode(mResults.values(), mToolbarController.getQuery());
mResults.clear();
onSearchEnd();

View file

@ -29,9 +29,9 @@ class SearchAdapter extends RecyclerView.Adapter<SearchAdapter.BaseViewHolder>
private final SearchFragment mSearchFragment;
private SearchResult[] mResults;
private Drawable mClosedMarkerBackground;
private final Drawable mClosedMarkerBackground;
protected static abstract class BaseViewHolder extends RecyclerView.ViewHolder
static abstract class BaseViewHolder extends RecyclerView.ViewHolder
{
SearchResult mResult;
// Position within search results
@ -221,7 +221,7 @@ class SearchAdapter extends RecyclerView.Adapter<SearchAdapter.BaseViewHolder>
}
}
public SearchAdapter(SearchFragment fragment)
SearchAdapter(SearchFragment fragment)
{
mSearchFragment = fragment;
mClosedMarkerBackground = fragment.getResources().getDrawable(ThemeUtils.isNightTheme() ? R.drawable.search_closed_marker_night
@ -320,7 +320,7 @@ class SearchAdapter extends RecyclerView.Adapter<SearchAdapter.BaseViewHolder>
refreshData(null);
}
public void refreshData(SearchResult[] results)
void refreshData(SearchResult[] results)
{
mResults = results;
notifyDataSetChanged();