Java Code Examples for io.realm.RealmList#size()

The following examples show how to use io.realm.RealmList#size() . 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: RealmMember.java    From iGap-Android with GNU Affero General Public License v3.0 6 votes vote down vote up
public static RealmResults<RealmMember> filterRole(long roomId, ProtoGlobal.Room.Type roomType, String role) {
    Realm realm = Realm.getDefaultInstance();
    RealmList<RealmMember> memberList = null;
    RealmResults<RealmMember> mList = emptyResult(realm);
    RealmRoom realmRoom = realm.where(RealmRoom.class).equalTo(RealmRoomFields.ID, roomId).findFirst();
    if (realmRoom != null) {
        if (roomType == ProtoGlobal.Room.Type.GROUP) {
            memberList = realmRoom.getGroupRoom().getMembers();
        } else if (roomType == ProtoGlobal.Room.Type.CHANNEL) {
            memberList = realmRoom.getChannelRoom().getMembers();
        }

        if (memberList != null && memberList.size() > 0) {
            if (role.equals(ProtoGroupGetMemberList.GroupGetMemberList.FilterRole.ALL.toString())) {
                mList = memberList.where().findAll();
            } else {
                mList = memberList.where().equalTo(RealmMemberFields.ROLE, role).findAll();
            }
        }
    }
    return mList;
}
 
Example 2
Source File: RealmBarDataSet.java    From NetKnight with Apache License 2.0 6 votes vote down vote up
@Override
public BarEntry buildEntryFromResultObject(T realmObject, int xIndex) {
    DynamicRealmObject dynamicObject = new DynamicRealmObject(realmObject);

    if (dynamicObject.getFieldType(mValuesField) == RealmFieldType.LIST) {

        RealmList<DynamicRealmObject> list = dynamicObject.getList(mValuesField);
        float[] values = new float[list.size()];

        int i = 0;
        for (DynamicRealmObject o : list) {
            values[i] = o.getFloat(mStackValueFieldName);
            i++;
        }

        return new BarEntry(values,
                mIndexField == null ? xIndex : dynamicObject.getInt(mIndexField));
    } else {
        float value = dynamicObject.getFloat(mValuesField);
        return new BarEntry(value,
                mIndexField == null ? xIndex : dynamicObject.getInt(mIndexField));
    }
}
 
Example 3
Source File: RealmBarDataSet.java    From JNChartDemo with Apache License 2.0 6 votes vote down vote up
@Override
public BarEntry buildEntryFromResultObject(T realmObject, int xIndex) {
    DynamicRealmObject dynamicObject = new DynamicRealmObject(realmObject);

    if (dynamicObject.getFieldType(mValuesField) == RealmFieldType.LIST) {

        RealmList<DynamicRealmObject> list = dynamicObject.getList(mValuesField);
        float[] values = new float[list.size()];

        int i = 0;
        for (DynamicRealmObject o : list) {
            values[i] = o.getFloat(mStackValueFieldName);
            i++;
        }

        return new BarEntry(values,
                mIndexField == null ? xIndex : dynamicObject.getInt(mIndexField));
    } else {
        float value = dynamicObject.getFloat(mValuesField);
        return new BarEntry(value,
                mIndexField == null ? xIndex : dynamicObject.getInt(mIndexField));
    }
}
 
Example 4
Source File: RealmBarDataSet.java    From MPAndroidChart-Realm with Apache License 2.0 6 votes vote down vote up
@Override
public BarEntry buildEntryFromResultObject(T realmObject, float x) {
    DynamicRealmObject dynamicObject = new DynamicRealmObject(realmObject);

    if (dynamicObject.getFieldType(mYValuesField) == RealmFieldType.LIST) {

        RealmList<DynamicRealmObject> list = dynamicObject.getList(mYValuesField);
        float[] values = new float[list.size()];

        int i = 0;
        for (DynamicRealmObject o : list) {
            values[i] = o.getFloat(mStackValueFieldName);
            i++;
        }

        return new BarEntry(
                mXValuesField == null ? x : dynamicObject.getFloat(mXValuesField), values);
    } else {
        float value = dynamicObject.getFloat(mYValuesField);
        return new BarEntry(mXValuesField == null ? x : dynamicObject.getFloat(mXValuesField), value);
    }
}
 
Example 5
Source File: FragmentChannelProfileViewModel.java    From iGap-Android with GNU Affero General Public License v3.0 5 votes vote down vote up
private void addMemberToChannel() {
    List<StructContactInfo> userList = Contacts.retrieve(null);
    RealmList<RealmMember> memberList = RealmMember.getMembers(getRealm(), roomId);

    for (int i = 0; i < memberList.size(); i++) {
        for (int j = 0; j < userList.size(); j++) {
            if (userList.get(j).peerId == memberList.get(i).getPeerId()) {
                userList.remove(j);
                break;
            }
        }
    }

    Fragment fragment = ShowCustomList.newInstance(userList, new OnSelectedList() {
        @Override
        public void getSelectedList(boolean result, String message, int countForShowLastMessage, final ArrayList<StructContactInfo> list) {

            for (int i = 0; i < list.size(); i++) {
                new RequestChannelAddMember().channelAddMember(roomId, list.get(i).peerId);
            }
        }
    });

    Bundle bundle = new Bundle();
    bundle.putBoolean("DIALOG_SHOWING", false);
    bundle.putLong("COUNT_MESSAGE", noLastMessage);
    fragment.setArguments(bundle);

    new HelperFragment(fragment).setReplace(false).load();
}
 
Example 6
Source File: FragmentGroupProfileViewModel.java    From iGap-Android with GNU Affero General Public License v3.0 5 votes vote down vote up
private void addMemberToGroup() {
    List<StructContactInfo> userList = Contacts.retrieve(null);
    RealmList<RealmMember> memberList = RealmMember.getMembers(getRealm(), roomId);

    for (int i = 0; i < memberList.size(); i++) {
        for (int j = 0; j < userList.size(); j++) {
            if (userList.get(j).peerId == memberList.get(i).getPeerId()) {
                userList.remove(j);
                break;
            }
        }
    }

    Fragment fragment = ShowCustomList.newInstance(userList, new OnSelectedList() {
        @Override
        public void getSelectedList(boolean result, final String type, final int countForShowLastMessage, final ArrayList<StructContactInfo> list) {
            G.handler.post(new Runnable() {
                @Override
                public void run() {
                    for (int i = 0; i < list.size(); i++) {
                        new RequestGroupAddMember().groupAddMember(roomId, list.get(i).peerId, RealmRoomMessage.findCustomMessageId(roomId, EnumCustomMessageId.convertType(type), countForShowLastMessage));
                    }
                }
            });
        }
    });

    Bundle bundle = new Bundle();
    bundle.putBoolean("DIALOG_SHOWING", true);
    bundle.putLong("COUNT_MESSAGE", noLastMessage);
    fragment.setArguments(bundle);
    new HelperFragment(fragment).setReplace(false).load();
}
 
Example 7
Source File: RealmRegisteredInfo.java    From iGap-Android with GNU Affero General Public License v3.0 5 votes vote down vote up
public RealmAvatar getLastAvatar() {
    RealmList<RealmAvatar> avatars = getAvatars();
    if (avatars.isEmpty()) {
        return null;
    }
    // make sure return last avatar which has attachment
    for (int i = avatars.size() - 1; i >= 0; i--) {
        RealmAvatar avatar = getAvatars().get(i);
        if (avatar.getFile() != null) {
            return avatar;
        }
    }
    return null;
}
 
Example 8
Source File: RealmBarDataSet.java    From Stayfit with Apache License 2.0 5 votes vote down vote up
@Override
public void build(RealmResults<T> results) {

    for (T realmObject : results) {

        DynamicRealmObject dynamicObject = new DynamicRealmObject(realmObject);

        try { // normal entry

            float value = dynamicObject.getFloat(mValuesField);
            mValues.add(new BarEntry(value, dynamicObject.getInt(mIndexField)));

        } catch (IllegalArgumentException e) { // stacked entry

            RealmList<DynamicRealmObject> list = dynamicObject.getList(mValuesField);
            float[] values = new float[list.size()];

            int i = 0;
            for (DynamicRealmObject o : list) {
                values[i] = o.getFloat(mStackValueFieldName);
                i++;
            }

            mValues.add(new BarEntry(values, dynamicObject.getInt(mIndexField)));
        }
    }

    calcStackSize();
}
 
Example 9
Source File: Item.java    From realm-android-adapters with Apache License 2.0 5 votes vote down vote up
static void create(Realm realm, boolean randomlyInsert) {
    Parent parent = realm.where(Parent.class).findFirst();
    RealmList<Item> items = parent.getItemList();
    Item counter = realm.createObject(Item.class, increment());
    if (randomlyInsert && items.size() > 0) {
        Random rand = new Random();
        items.listIterator(rand.nextInt(items.size())).add(counter);
    } else {
        items.add(counter);
    }
}
 
Example 10
Source File: RealmListTypeAdapter.java    From paperparcel with Apache License 2.0 4 votes vote down vote up
@Override public void writeToParcel(@NonNull RealmList<T> value, @NonNull Parcel dest, int flags) {
  dest.writeInt(value.size());
  for (int i = 0; i < value.size(); i++) {
    itemAdapter.writeToParcel(value.get(i), dest, flags);
  }
}