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.text.SpannableString;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.style.ImageSpan;
import android.view.LayoutInflater;
import android.view.View;
@ -160,23 +161,20 @@ public class ContactSelectionListAdapter extends CursorRecyclerViewAdapter<ViewH
}
}
private String getHeaderString(int position) {
private @NonNull String getHeaderString(int 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) {
return getContext().getString(R.string.app_name);
} else {
String letter = cursor.getString(cursor.getColumnIndexOrThrow(ContactsDatabase.NAME_COLUMN))
.trim()
.substring(0,1)
.toUpperCase();
if (Character.isLetterOrDigit(letter.codePointAt(0))) {
return letter;
} else {
} else if (!TextUtils.isEmpty(letter)) {
String firstChar = letter.trim().substring(0, 1).toUpperCase();
if (Character.isLetterOrDigit(firstChar.codePointAt(0))) {
return firstChar;
}
}
return "#";
}
}
}
private Cursor getCursorAtPositionOrThrow(int position) {
Cursor cursor = getCursor();