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

The following examples show how to use io.realm.RealmQuery#equalTo() . 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;
}
 
Example 4
Source File: RealmMember.java    From iGap-Android with GNU Affero General Public License v3.0 5 votes vote down vote up
public static RealmResults<RealmMember> filterMember(long roomId, @Nullable String filter) {
    Realm realm = Realm.getDefaultInstance();
    RealmRoom realmRoom = realm.where(RealmRoom.class).equalTo(RealmRoomFields.ID, roomId).findFirst();
    if (realmRoom == null) {
        return emptyResult(realm);
    }

    RealmResults<RealmMember> searchMember = emptyResult(realm);
    RealmResults<RealmRegisteredInfo> findMember;

    if (filter != null && filter.length() > 0) {
        findMember = realm.where(RealmRegisteredInfo.class).contains(RealmRegisteredInfoFields.DISPLAY_NAME, filter, Case.INSENSITIVE).findAll().sort(RealmRegisteredInfoFields.DISPLAY_NAME);
    } else {
        findMember = realm.where(RealmRegisteredInfo.class).equalTo(RealmRoomFields.ID, roomId).findAll().sort(RealmRegisteredInfoFields.DISPLAY_NAME);
    }
    try {
        RealmQuery<RealmMember> query;
        if (realmRoom.getType() == GROUP) {
            query = realmRoom.getGroupRoom().getMembers().where();
        } else {
            query = realmRoom.getChannelRoom().getMembers().where();
        }

        for (int i = 0; i < findMember.size(); i++) {
            if (i != 0) {
                query = query.or();
            }
            query = query.equalTo(RealmMemberFields.PEER_ID, findMember.get(i).getId());
        }
        if (findMember.size() > 0 || (filter == null || filter.length() == 0)) {
            searchMember = query.findAll();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return searchMember;
}
 
Example 5
Source File: ApiStorage.java    From ApiClient with Apache License 2.0 5 votes vote down vote up
@Override
public <Item extends RealmObject> RealmResults<Item> getItems(Class<Item> objectClass, String sortedFieldName, List<Integer> ids) {
    RealmQuery<Item> query = getQuery(objectClass);
    for (int i = 0; i < ids.size() - 1; i++) {
        query = query.equalTo(sortedFieldName, ids.get(i)).or();
    }
    query = query.equalTo(sortedFieldName, ids.get(ids.size() - 1));

    return query.findAllSortedAsync(sortedFieldName);
}
 
Example 6
Source File: Expense.java    From Expense-Tracker-App with MIT License 5 votes vote down vote up
public static RealmResults<Expense> getExpensesList(Date dateFrom, Date dateTo, @IExpensesType Integer type, Category category) {
    RealmQuery<Expense> realmQuery = RealmManager.getInstance().getRealmInstance()
            .where(Expense.class);
    if (dateTo != null) {
        realmQuery.between("date", dateFrom, dateTo);
    } else {
        realmQuery.equalTo("date", dateFrom);
    }
    if (category != null) realmQuery.equalTo("category.id", category.getId());
    if (type != null) realmQuery.equalTo("type", type);
    return realmQuery.findAll();
}