forked from organicmaps/organicmaps
[android] Fixed NPE in download map adapter (monkey test)
This commit is contained in:
parent
0b733cefd7
commit
49d1a60b7e
2 changed files with 26 additions and 18 deletions
|
@ -1,8 +1,10 @@
|
|||
package com.mapswithme.maps.downloader;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Class representing a single item in countries hierarchy.
|
||||
* Fields are filled by native code.
|
||||
|
@ -63,6 +65,7 @@ public final class CountryItem implements Comparable<CountryItem>
|
|||
// Internal ID for grouping under headers in the list
|
||||
int headerId;
|
||||
// Internal field to store search result name
|
||||
@Nullable
|
||||
String searchResultName;
|
||||
|
||||
private static void ensureRootIdKnown()
|
||||
|
|
|
@ -5,16 +5,9 @@ import android.content.DialogInterface;
|
|||
import android.content.Intent;
|
||||
import android.graphics.Typeface;
|
||||
import android.location.Location;
|
||||
import androidx.annotation.DrawableRes;
|
||||
import androidx.annotation.LayoutRes;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.StringRes;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.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.view.LayoutInflater;
|
||||
|
@ -23,6 +16,14 @@ import android.view.ViewGroup;
|
|||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.DrawableRes;
|
||||
import androidx.annotation.LayoutRes;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.StringRes;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import com.cocosw.bottomsheet.BottomSheet;
|
||||
import com.mapswithme.maps.Framework;
|
||||
import com.mapswithme.maps.MwmActivity;
|
||||
|
@ -562,20 +563,24 @@ class DownloaderAdapter extends RecyclerView.Adapter<DownloaderAdapter.ViewHolde
|
|||
{
|
||||
super.bind(item);
|
||||
|
||||
String found = null;
|
||||
if (mSearchResultsMode)
|
||||
{
|
||||
mName.setMaxLines(1);
|
||||
mName.setText(mItem.name);
|
||||
|
||||
String found = mItem.searchResultName.toLowerCase();
|
||||
SpannableStringBuilder builder = new SpannableStringBuilder(mItem.searchResultName);
|
||||
int start = found.indexOf(mSearchQuery);
|
||||
int end = start + mSearchQuery.length();
|
||||
String searchResultName = mItem.searchResultName;
|
||||
if (!TextUtils.isEmpty(searchResultName))
|
||||
{
|
||||
found = searchResultName.toLowerCase();
|
||||
SpannableStringBuilder builder = new SpannableStringBuilder(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);
|
||||
|
||||
if (start > -1)
|
||||
builder.setSpan(new StyleSpan(Typeface.BOLD), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
|
||||
mFoundName.setText(builder);
|
||||
mFoundName.setText(builder);
|
||||
}
|
||||
|
||||
if (!mItem.isExpandable())
|
||||
UiUtils.setTextAndHideIfEmpty(mSubtitle, mItem.topmostParentName);
|
||||
|
@ -595,7 +600,7 @@ class DownloaderAdapter extends RecyclerView.Adapter<DownloaderAdapter.ViewHolde
|
|||
mItem.totalChildCount)));
|
||||
}
|
||||
|
||||
UiUtils.showIf(mSearchResultsMode, mFoundName);
|
||||
UiUtils.showIf(mSearchResultsMode && !TextUtils.isEmpty(found), mFoundName);
|
||||
|
||||
long size;
|
||||
if (mItem.status == CountryItem.STATUS_ENQUEUED ||
|
||||
|
|
Loading…
Add table
Reference in a new issue