mirror of https://github.com/M66B/FairEmail.git
Show contact photos in contact selector
This commit is contained in:
parent
e8f918d366
commit
3af200791c
|
@ -26,12 +26,12 @@ public class AdapterIdentitySelect extends ArrayAdapter<TupleIdentityEx> {
|
|||
@NonNull
|
||||
@Override
|
||||
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
|
||||
return getLayout(position, convertView, parent, R.layout.spinner_item2);
|
||||
return getLayout(position, convertView, parent, R.layout.spinner_identity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getDropDownView(int position, View convertView, @NonNull ViewGroup parent) {
|
||||
return getLayout(position, convertView, parent, R.layout.spinner_item2_dropdown);
|
||||
return getLayout(position, convertView, parent, R.layout.spinner_identity_dropdown);
|
||||
}
|
||||
|
||||
private View getLayout(int position, View convertView, ViewGroup parent, int resid) {
|
||||
|
|
|
@ -58,7 +58,7 @@ public interface DaoContact {
|
|||
" AND email = :email COLLATE NOCASE")
|
||||
EntityContact getContact(long account, int type, String email);
|
||||
|
||||
@Query("SELECT id AS _id, name, email, name || ' *' AS display" +
|
||||
@Query("SELECT id AS _id, name, email, NULL AS photo, 1 AS local" +
|
||||
" FROM contact" +
|
||||
" WHERE (:account IS NULL OR account = :account)" +
|
||||
" AND (:type IS NULL OR type = :type)" +
|
||||
|
|
|
@ -81,6 +81,7 @@ import android.widget.CompoundButton;
|
|||
import android.widget.EditText;
|
||||
import android.widget.FilterQueryProvider;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.MultiAutoCompleteTextView;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
|
@ -670,12 +671,32 @@ public class FragmentCompose extends FragmentBase {
|
|||
|
||||
SimpleCursorAdapter cadapter = new SimpleCursorAdapter(
|
||||
getContext(),
|
||||
R.layout.spinner_item2_dropdown,
|
||||
R.layout.spinner_contact,
|
||||
null,
|
||||
new String[]{"display", "email"},
|
||||
new int[]{android.R.id.text1, android.R.id.text2},
|
||||
new String[]{"name", "email", "photo"},
|
||||
new int[]{R.id.tvName, R.id.tvEmail, R.id.ivPhoto},
|
||||
0);
|
||||
|
||||
cadapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
|
||||
@Override
|
||||
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
|
||||
if (view.getId() == R.id.ivPhoto) {
|
||||
ImageView photo = (ImageView) view;
|
||||
if (cursor.getInt(cursor.getColumnIndex("local")) == 1)
|
||||
photo.setImageDrawable(null);
|
||||
else {
|
||||
String uri = cursor.getString(columnIndex);
|
||||
if (uri == null)
|
||||
photo.setImageResource(R.drawable.baseline_person_24);
|
||||
else
|
||||
photo.setImageURI(Uri.parse(uri));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
cadapter.setCursorToStringConverter(new SimpleCursorAdapter.CursorToStringConverter() {
|
||||
public CharSequence convertToString(Cursor cursor) {
|
||||
int colName = cursor.getColumnIndex("name");
|
||||
|
@ -705,7 +726,7 @@ public class FragmentCompose extends FragmentBase {
|
|||
String wildcard = "%" + typed + "%";
|
||||
List<Cursor> cursors = new ArrayList<>();
|
||||
|
||||
MatrixCursor provided = new MatrixCursor(new String[]{"_id", "name", "email", "display"});
|
||||
MatrixCursor provided = new MatrixCursor(new String[]{"_id", "name", "email", "photo", "local"});
|
||||
boolean contacts = Helper.hasPermission(getContext(), Manifest.permission.READ_CONTACTS);
|
||||
if (contacts) {
|
||||
Cursor cursor = resolver.query(
|
||||
|
@ -713,7 +734,8 @@ public class FragmentCompose extends FragmentBase {
|
|||
new String[]{
|
||||
ContactsContract.CommonDataKinds.Email.CONTACT_ID,
|
||||
ContactsContract.Contacts.DISPLAY_NAME,
|
||||
ContactsContract.CommonDataKinds.Email.DATA
|
||||
ContactsContract.CommonDataKinds.Email.DATA,
|
||||
ContactsContract.Contacts.PHOTO_THUMBNAIL_URI
|
||||
},
|
||||
ContactsContract.CommonDataKinds.Email.DATA + " <> ''" +
|
||||
" AND (" + ContactsContract.Contacts.DISPLAY_NAME + " LIKE ?" +
|
||||
|
@ -725,10 +747,11 @@ public class FragmentCompose extends FragmentBase {
|
|||
|
||||
while (cursor != null && cursor.moveToNext())
|
||||
provided.newRow()
|
||||
.add(cursor.getLong(0))
|
||||
.add(cursor.getString(1))
|
||||
.add(cursor.getString(2))
|
||||
.add(cursor.getString(1));
|
||||
.add(cursor.getLong(0)) // id
|
||||
.add(cursor.getString(1)) // name
|
||||
.add(cursor.getString(2)) // email
|
||||
.add(cursor.getString(3)) // photo
|
||||
.add(0); // local
|
||||
}
|
||||
cursors.add(provided);
|
||||
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvName"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="6dp"
|
||||
android:layout_marginTop="6dp"
|
||||
android:layout_marginEnd="6dp"
|
||||
android:text="Name"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
|
||||
app:layout_constraintEnd_toStartOf="@+id/ivPhoto"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvEmail"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="6dp"
|
||||
android:layout_marginEnd="6dp"
|
||||
android:layout_marginBottom="6dp"
|
||||
android:text="Email"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
app:layout_constraintEnd_toStartOf="@+id/ivPhoto"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvName" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/ivPhoto"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_marginStart="6dp"
|
||||
android:layout_marginEnd="6dp"
|
||||
android:contentDescription="@string/title_legend_avatar"
|
||||
android:scaleType="centerCrop"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/tvEmail"
|
||||
app:layout_constraintDimensionRatio="1:1"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="@+id/tvName"
|
||||
app:srcCompat="@drawable/baseline_person_24" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
Loading…
Reference in New Issue