Fixed duplicate contacts

pull/155/head
M66B 6 years ago
parent 3d1bd1cf86
commit 77d265f37a

@ -34,6 +34,7 @@ import android.content.pm.PackageManager;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.content.res.Resources; import android.content.res.Resources;
import android.database.Cursor; import android.database.Cursor;
import android.database.CursorWrapper;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.graphics.Matrix; import android.graphics.Matrix;
@ -486,20 +487,50 @@ public class FragmentCompose extends FragmentBase {
cadapter.setFilterQueryProvider(new FilterQueryProvider() { cadapter.setFilterQueryProvider(new FilterQueryProvider() {
public Cursor runQuery(CharSequence typed) { public Cursor runQuery(CharSequence typed) {
Log.i("Searching provided contact=" + typed); Log.i("Searching provided contact=" + typed);
return resolver.query( String wildcard = "%" + typed + "%";
return new CursorWrapper(resolver.query(
ContactsContract.CommonDataKinds.Email.CONTENT_URI, ContactsContract.CommonDataKinds.Email.CONTENT_URI,
new String[]{ new String[]{
ContactsContract.RawContacts._ID, ContactsContract.CommonDataKinds.Email.CONTACT_ID,
ContactsContract.Contacts.DISPLAY_NAME, ContactsContract.Contacts.DISPLAY_NAME,
ContactsContract.CommonDataKinds.Email.DATA ContactsContract.CommonDataKinds.Email.DATA
}, },
ContactsContract.CommonDataKinds.Email.DATA + " <> ''" + ContactsContract.CommonDataKinds.Email.DATA + " <> ''" +
" AND (" + ContactsContract.Contacts.DISPLAY_NAME + " LIKE '%" + typed + "%'" + " AND (" + ContactsContract.Contacts.DISPLAY_NAME + " LIKE ?" +
" OR " + ContactsContract.CommonDataKinds.Email.DATA + " LIKE '%" + typed + "%')", " OR " + ContactsContract.CommonDataKinds.Email.DATA + " LIKE ?)",
null, new String[]{wildcard, wildcard},
"CASE WHEN " + ContactsContract.Contacts.DISPLAY_NAME + " NOT LIKE '%@%' THEN 0 ELSE 1 END" + "CASE WHEN " + ContactsContract.Contacts.DISPLAY_NAME + " NOT LIKE '%@%' THEN 0 ELSE 1 END" +
", " + ContactsContract.Contacts.DISPLAY_NAME + ", " + ContactsContract.Contacts.DISPLAY_NAME + " COLLATE NOCASE" +
", " + ContactsContract.CommonDataKinds.Email.DATA + " COLLATE NOCASE"); ", " + ContactsContract.CommonDataKinds.Email.DATA + " COLLATE NOCASE")) {
@Override
public String[] getColumnNames() {
String[] names = super.getColumnNames();
names[0] = "_id";
return names;
}
@Override
public String getColumnName(int index) {
if (index == 0)
return "_id";
return super.getColumnName(index);
}
@Override
public int getColumnIndex(String name) {
if ("_id".equals(name))
return 0;
return super.getColumnIndex(name);
}
@Override
public int getColumnIndexOrThrow(String name) throws IllegalArgumentException {
if ("_id".equals(name))
return 0;
return super.getColumnIndexOrThrow(name);
}
};
} }
}); });
else else
@ -507,7 +538,8 @@ public class FragmentCompose extends FragmentBase {
@Override @Override
public Cursor runQuery(CharSequence typed) { public Cursor runQuery(CharSequence typed) {
Log.i("Searching local contact=" + typed); Log.i("Searching local contact=" + typed);
return db.contact().searchContacts(null, null, "%" + typed + "%"); String wildcard = "%" + typed + "%";
return db.contact().searchContacts(null, null, wildcard);
} }
}); });

Loading…
Cancel
Save