Java Code Examples for io.realm.RealmQuery#count()

The following examples show how to use io.realm.RealmQuery#count() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AddContactDialogFragment.java    From natrium-android-wallet with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private boolean validateAddress() {
    // check for valid address
    if (binding.contactAddress.getText().toString().trim().isEmpty()) {
        showAddressError(R.string.send_enter_address);
        return false;
    }
    Address address = new Address(binding.contactAddress.getText().toString());
    if (!address.isValidAddress()) {
        showAddressError(R.string.send_invalid_address);
        return false;
    }
    RealmQuery realmQuery = realm.where(Contact.class);
    realmQuery.equalTo("address", address.getAddress());
    if (realmQuery.count() > 0) {
        showAddressError(R.string.contact_address_exists);
        return false;
    }
    hideAddressError();
    return true;
}
 
Example 2
Source File: AddContactDialogFragment.java    From natrium-android-wallet with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private boolean validateName() {
    String name = binding.contactName.getText().toString().trim();
    if (!name.startsWith("@")) {
        name = "@" + name;
    }
    if (name.isEmpty() || name.length() <= 1) {
        showNameError(R.string.contact_name_missing);
        return false;
    } else {
        RealmQuery realmQuery = realm.where(Contact.class);
        realmQuery.equalTo("name", name);
        if (realmQuery.count() > 0) {
            showNameError(R.string.contact_name_exists);
            return false;
        }
    }
    hideNameError();
    return true;
}
 
Example 3
Source File: HomeFragment.java    From natrium-android-wallet with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private String getContactName(String address) {
    if (mContactCache.containsKey(address)) {
        return mContactCache.get(address);
    }
    RealmQuery realmQuery = realm.where(Contact.class);
    realmQuery.equalTo("address", address);
    if (realmQuery.count() > 0) {
        Contact c = (Contact) realmQuery.findFirst();
        mContactCache.put(address, c.getDisplayName());
        return c.getDisplayName();
    }
    return null;
}