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;
}
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;
}
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());
}
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));
}
Aggregations