Search in sources :

Example 1 with Contact

use of com.googlecode.gwtphonegap.client.contacts.Contact in project gwtphonegap by dankurka.

the class ContactsBrowserImpl method loadContactsFromStorage.

protected LightMap<Contact> loadContactsFromStorage() {
    LightMap<Contact> map = CollectionFactory.constructMap();
    String item = storage.getItem("gwtphonegap-contact-emulation");
    if (item == null) {
        return map;
    }
    JSONValue parsed = JSONParser.parseStrict(item);
    JSONObject root = parsed.isObject();
    if (root == null) {
        return map;
    } else {
        Set<String> set = root.keySet();
        for (String key : set) {
            JSONObject jsonContact = root.get(key).isObject();
            Contact contact = parseContact(jsonContact);
            map.put(contact.getId(), contact);
        }
    }
    return map;
}
Also used : JSONValue(com.google.gwt.json.client.JSONValue) JSONObject(com.google.gwt.json.client.JSONObject) Contact(com.googlecode.gwtphonegap.client.contacts.Contact)

Example 2 with Contact

use of com.googlecode.gwtphonegap.client.contacts.Contact in project gwtphonegap by dankurka.

the class ContactsBrowserImpl method toArray.

private LightArray<Contact> toArray(LightMap<Contact> map) {
    LightArray<Contact> array = CollectionFactory.constructArray();
    LightArray<String> keys = map.getKeys();
    for (int i = 0; i < keys.length(); i++) {
        Contact contact = map.get(keys.get(i));
        array.set(i, contact);
    }
    return array;
}
Also used : Contact(com.googlecode.gwtphonegap.client.contacts.Contact)

Example 3 with Contact

use of com.googlecode.gwtphonegap.client.contacts.Contact in project gwtphonegap by dankurka.

the class ContactsBrowserImpl method store.

private void store(LightMap<Contact> fromStorage) {
    JSONObject map = new JSONObject();
    LightArray<String> keys = fromStorage.getKeys();
    for (int i = 0; i < keys.length(); i++) {
        Contact contact = fromStorage.get(keys.get(i));
        JSONObject jsonContact = ((ContactBrowserImpl) contact).serializeContact();
        map.put(contact.getId(), jsonContact);
    }
    storage.setItem("gwtphonegap-contact-emulation", map.toString());
}
Also used : JSONObject(com.google.gwt.json.client.JSONObject) Contact(com.googlecode.gwtphonegap.client.contacts.Contact)

Example 4 with Contact

use of com.googlecode.gwtphonegap.client.contacts.Contact in project gwtphonegap by dankurka.

the class ContactsBrowserImpl method find.

@Override
public void find(LightArray<String> fields, ContactFindCallback callback, ContactFindOptions contactFindOptions) {
    LightMap<Contact> fromStorage = loadContactsFromStorage();
    if (fields.length() == 0) {
        callback.onSuccess(toArray(fromStorage));
    }
    LightMap<Contact> result = CollectionFactory.constructMap();
    LightArray<String> keys = fromStorage.getKeys();
    String filter = contactFindOptions.getFilter();
    for (int i = 0; i < keys.length(); i++) {
        Contact contact = fromStorage.get(keys.get(i));
        for (int j = 0; j < fields.length(); j++) {
            String string = fields.get(j);
            if ("name".equals(string)) {
                if (contact.getName().getFamilyName() != null && contact.getName().getFamilyName().contains(filter)) {
                    result.put(contact.getId(), contact);
                    break;
                }
                if (contact.getName().getFamilyName() != null && contact.getName().getGivenName().contains(filter)) {
                    result.put(contact.getId(), contact);
                    break;
                }
            } else {
            // TODO implement the rest
            }
        }
    }
    callback.onSuccess(toArray(result));
}
Also used : Contact(com.googlecode.gwtphonegap.client.contacts.Contact)

Aggregations

Contact (com.googlecode.gwtphonegap.client.contacts.Contact)4 JSONObject (com.google.gwt.json.client.JSONObject)2 JSONValue (com.google.gwt.json.client.JSONValue)1