fix crash on null Android contact name

fixes #4592
Closes #4594
// FREEBIE
This commit is contained in:
Jake McGinty 2015-11-18 18:24:47 -08:00 committed by Moxie Marlinspike
parent cd085faecd
commit 7aeb4c96ee

View File

@ -26,6 +26,7 @@ import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.text.SpannableString; import android.text.SpannableString;
import android.text.Spanned; import android.text.Spanned;
import android.text.TextUtils;
import android.text.style.ImageSpan; import android.text.style.ImageSpan;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -160,22 +161,19 @@ public class ContactSelectionListAdapter extends CursorRecyclerViewAdapter<ViewH
} }
} }
private String getHeaderString(int position) { private @NonNull String getHeaderString(int position) {
Cursor cursor = getCursorAtPositionOrThrow(position); Cursor cursor = getCursorAtPositionOrThrow(position);
String letter = cursor.getString(cursor.getColumnIndexOrThrow(ContactsDatabase.NAME_COLUMN));
if (cursor.getInt(cursor.getColumnIndexOrThrow(ContactsDatabase.CONTACT_TYPE_COLUMN)) == ContactsDatabase.PUSH_TYPE) { if (cursor.getInt(cursor.getColumnIndexOrThrow(ContactsDatabase.CONTACT_TYPE_COLUMN)) == ContactsDatabase.PUSH_TYPE) {
return getContext().getString(R.string.app_name); return getContext().getString(R.string.app_name);
} else { } else if (!TextUtils.isEmpty(letter)) {
String letter = cursor.getString(cursor.getColumnIndexOrThrow(ContactsDatabase.NAME_COLUMN)) String firstChar = letter.trim().substring(0, 1).toUpperCase();
.trim() if (Character.isLetterOrDigit(firstChar.codePointAt(0))) {
.substring(0,1) return firstChar;
.toUpperCase();
if (Character.isLetterOrDigit(letter.codePointAt(0))) {
return letter;
} else {
return "#";
} }
} }
return "#";
} }
private Cursor getCursorAtPositionOrThrow(int position) { private Cursor getCursorAtPositionOrThrow(int position) {