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,12 +75,39 @@ public interface ASyncContactLoad {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Read all contacts
|
// Read all contacts
|
||||||
|
readContacts(serverPhoneList);
|
||||||
|
|
||||||
|
for (String phone : serverPhoneList) {
|
||||||
|
_objects.add(phone);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sort phone numbers
|
||||||
|
Collections.sort(_objects);
|
||||||
|
} catch (JSONException e) {
|
||||||
|
_objects.add(_context.getString(R.string.err_fetch_phonelist));
|
||||||
|
return false;
|
||||||
|
} catch (OCSyncException e) {
|
||||||
|
_objects.add(_context.getString(e.getErrorId()));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void readContacts(ArrayList<String> serverPhoneList) {
|
||||||
ContentResolver cr = _context.getContentResolver();
|
ContentResolver cr = _context.getContentResolver();
|
||||||
Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI,
|
Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI,
|
||||||
null, null, null, null);
|
null, null, null, null);
|
||||||
if (((cur != null) ? cur.getCount() : 0) > 0) {
|
if (cur == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cur.getCount() == 0) {
|
||||||
|
cur.close();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
String id, name;
|
String id, name;
|
||||||
while ((cur != null) && cur.moveToNext()) {
|
while (cur.moveToNext()) {
|
||||||
id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID));
|
id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID));
|
||||||
name = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
|
name = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
|
||||||
if (Integer.parseInt(cur.getString(
|
if (Integer.parseInt(cur.getString(
|
||||||
@ -107,27 +134,10 @@ public interface ASyncContactLoad {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (cur != null) {
|
|
||||||
cur.close();
|
cur.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (String phone : serverPhoneList) {
|
|
||||||
_objects.add(phone);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sort phone numbers
|
|
||||||
Collections.sort(_objects);
|
|
||||||
} catch (JSONException e) {
|
|
||||||
_objects.add(_context.getString(R.string.err_fetch_phonelist));
|
|
||||||
return false;
|
|
||||||
} catch (OCSyncException e) {
|
|
||||||
_objects.add(_context.getString(e.getErrorId()));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
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