|
|
|
@ -20,14 +20,13 @@ import android.content.Context;
|
|
|
|
|
import android.content.res.TypedArray;
|
|
|
|
|
import android.database.Cursor;
|
|
|
|
|
import android.provider.ContactsContract;
|
|
|
|
|
import android.support.annotation.DrawableRes;
|
|
|
|
|
import android.support.annotation.NonNull;
|
|
|
|
|
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.text.style.ForegroundColorSpan;
|
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
|
import android.view.View;
|
|
|
|
|
import android.view.View.OnClickListener;
|
|
|
|
@ -40,6 +39,7 @@ import org.thoughtcrime.securesms.ContactSelectionListFragment.StickyHeaderAdapt
|
|
|
|
|
import org.thoughtcrime.securesms.contacts.ContactSelectionListAdapter.HeaderViewHolder;
|
|
|
|
|
import org.thoughtcrime.securesms.contacts.ContactSelectionListAdapter.ViewHolder;
|
|
|
|
|
import org.thoughtcrime.securesms.database.CursorRecyclerViewAdapter;
|
|
|
|
|
import org.thoughtcrime.securesms.util.Util;
|
|
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.Map;
|
|
|
|
@ -103,7 +103,7 @@ public class ContactSelectionListAdapter extends CursorRecyclerViewAdapter<ViewH
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public long getHeaderId(int i) {
|
|
|
|
|
return getHeaderString(i).hashCode();
|
|
|
|
|
return Util.hashCode(getHeaderString(i), isPush(i));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@ -137,36 +137,33 @@ public class ContactSelectionListAdapter extends CursorRecyclerViewAdapter<ViewH
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onBindHeaderViewHolder(HeaderViewHolder viewHolder, int position) {
|
|
|
|
|
((TextView)viewHolder.itemView).setText(getSpannedHeaderString(position, R.drawable.ic_signal_grey_24dp));
|
|
|
|
|
((TextView)viewHolder.itemView).setText(getSpannedHeaderString(position));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public CharSequence getBubbleText(int position) {
|
|
|
|
|
return getSpannedHeaderString(position, R.drawable.ic_signal_white_48dp);
|
|
|
|
|
return getHeaderString(position);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Map<Long, String> getSelectedContacts() {
|
|
|
|
|
return selectedContacts;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private CharSequence getSpannedHeaderString(int position, @DrawableRes int drawable) {
|
|
|
|
|
Cursor cursor = getCursorAtPositionOrThrow(position);
|
|
|
|
|
|
|
|
|
|
if (cursor.getInt(cursor.getColumnIndexOrThrow(ContactsDatabase.CONTACT_TYPE_COLUMN)) == ContactsDatabase.PUSH_TYPE) {
|
|
|
|
|
SpannableString spannable = new SpannableString(" ");
|
|
|
|
|
spannable.setSpan(new ImageSpan(getContext(), drawable, ImageSpan.ALIGN_BOTTOM), 0, spannable.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
|
|
|
|
private CharSequence getSpannedHeaderString(int position) {
|
|
|
|
|
final String headerString = getHeaderString(position);
|
|
|
|
|
if (isPush(position)) {
|
|
|
|
|
SpannableString spannable = new SpannableString(headerString);
|
|
|
|
|
spannable.setSpan(new ForegroundColorSpan(getContext().getResources().getColor(R.color.signal_primary)), 0, headerString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
|
|
|
|
return spannable;
|
|
|
|
|
} else {
|
|
|
|
|
return getHeaderString(position);
|
|
|
|
|
return headerString;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 if (!TextUtils.isEmpty(letter)) {
|
|
|
|
|
if (!TextUtils.isEmpty(letter)) {
|
|
|
|
|
String firstChar = letter.trim().substring(0, 1).toUpperCase();
|
|
|
|
|
if (Character.isLetterOrDigit(firstChar.codePointAt(0))) {
|
|
|
|
|
return firstChar;
|
|
|
|
@ -176,12 +173,19 @@ public class ContactSelectionListAdapter extends CursorRecyclerViewAdapter<ViewH
|
|
|
|
|
return "#";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean isPush(int position) {
|
|
|
|
|
final Cursor cursor = getCursorAtPositionOrThrow(position);
|
|
|
|
|
return cursor.getInt(cursor.getColumnIndexOrThrow(ContactsDatabase.CONTACT_TYPE_COLUMN)) == ContactsDatabase.PUSH_TYPE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Cursor getCursorAtPositionOrThrow(int position) {
|
|
|
|
|
Cursor cursor = getCursor();
|
|
|
|
|
if (cursor == null) {
|
|
|
|
|
throw new IllegalStateException("Cursor should not be null here.");
|
|
|
|
|
}
|
|
|
|
|
if (!cursor.moveToPosition(position));
|
|
|
|
|
if (!cursor.moveToPosition(position)) {
|
|
|
|
|
throw new IllegalStateException("Cursor couldn't be moved to position.");
|
|
|
|
|
}
|
|
|
|
|
return cursor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|