mirror of
https://github.com/nerzhul/ownCloud-SMS-App.git
synced 2025-06-24 16:26:45 +00:00
Contactload code cleanup
This commit is contained in:
parent
a5a03dbfcd
commit
d4904797f7
@ -75,42 +75,7 @@ public interface ASyncContactLoad {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Read all contacts
|
// Read all contacts
|
||||||
ContentResolver cr = _context.getContentResolver();
|
readContacts(serverPhoneList);
|
||||||
Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI,
|
|
||||||
null, null, null, null);
|
|
||||||
if (((cur != null) ? cur.getCount() : 0) > 0) {
|
|
||||||
String id, name;
|
|
||||||
while ((cur != null) && cur.moveToNext()) {
|
|
||||||
id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID));
|
|
||||||
name = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
|
|
||||||
if (Integer.parseInt(cur.getString(
|
|
||||||
cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {
|
|
||||||
|
|
||||||
// Fetch all phone numbers
|
|
||||||
Cursor pCur = cr.query(
|
|
||||||
ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
|
|
||||||
null,
|
|
||||||
ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?",
|
|
||||||
new String[]{id}, null);
|
|
||||||
while ((pCur != null) && pCur.moveToNext()) {
|
|
||||||
String phoneNo = pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER))
|
|
||||||
.replaceAll(" ", "");
|
|
||||||
if (serverPhoneList.contains(phoneNo)) {
|
|
||||||
if (!_objects.contains(name)) {
|
|
||||||
_objects.add(name);
|
|
||||||
}
|
|
||||||
serverPhoneList.remove(phoneNo);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (pCur != null) {
|
|
||||||
pCur.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (cur != null) {
|
|
||||||
cur.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
for (String phone : serverPhoneList) {
|
for (String phone : serverPhoneList) {
|
||||||
_objects.add(phone);
|
_objects.add(phone);
|
||||||
@ -128,6 +93,51 @@ public interface ASyncContactLoad {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void readContacts(ArrayList<String> serverPhoneList) {
|
||||||
|
ContentResolver cr = _context.getContentResolver();
|
||||||
|
Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI,
|
||||||
|
null, null, null, null);
|
||||||
|
if (cur == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cur.getCount() == 0) {
|
||||||
|
cur.close();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String id, name;
|
||||||
|
while (cur.moveToNext()) {
|
||||||
|
id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID));
|
||||||
|
name = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
|
||||||
|
if (Integer.parseInt(cur.getString(
|
||||||
|
cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {
|
||||||
|
|
||||||
|
// Fetch all phone numbers
|
||||||
|
Cursor pCur = cr.query(
|
||||||
|
ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
|
||||||
|
null,
|
||||||
|
ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?",
|
||||||
|
new String[]{id}, null);
|
||||||
|
while ((pCur != null) && pCur.moveToNext()) {
|
||||||
|
String phoneNo = pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER))
|
||||||
|
.replaceAll(" ", "");
|
||||||
|
if (serverPhoneList.contains(phoneNo)) {
|
||||||
|
if (!_objects.contains(name)) {
|
||||||
|
_objects.add(name);
|
||||||
|
}
|
||||||
|
serverPhoneList.remove(phoneNo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (pCur != null) {
|
||||||
|
pCur.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cur.close();
|
||||||
|
}
|
||||||
|
|
||||||
protected void onPostExecute(Boolean success) {
|
protected void onPostExecute(Boolean success) {
|
||||||
_adapter.notifyDataSetChanged();
|
_adapter.notifyDataSetChanged();
|
||||||
_layout.setRefreshing(false);
|
_layout.setRefreshing(false);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user