io.realm.RealmList Java Examples

The following examples show how to use io.realm.RealmList. 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: RealmChannelRoom.java    From iGap-Android with GNU Affero General Public License v3.0 6 votes vote down vote up
public static ChannelChatRole detectMemberRole(long roomId, long messageSenderId) {
    ChannelChatRole role = ChannelChatRole.UNRECOGNIZED;
    Realm realm = Realm.getDefaultInstance();
    RealmRoom realmRoom = realm.where(RealmRoom.class).equalTo(RealmRoomFields.ID, roomId).findFirst();
    if (realmRoom != null) {
        if (realmRoom.getChannelRoom() != null) {
            RealmList<RealmMember> realmMembers = realmRoom.getChannelRoom().getMembers();
            for (RealmMember realmMember : realmMembers) {
                if (realmMember.getPeerId() == messageSenderId) {
                    role = ChannelChatRole.valueOf(realmMember.getRole());
                }
            }
        }
    }
    realm.close();
    return role;
}
 
Example #2
Source File: GhostApiTest.java    From quill with MIT License 6 votes vote down vote up
private static void createRandomPost(AuthToken token,
                                     Action3<Post, Response<PostList>, Post> callback) {
    String title = getRandomString(20);
    String markdown = getRandomString(100);
    Post newPost = new Post();
    newPost.setTitle(title);
    newPost.setMarkdown(markdown);
    newPost.setTags(new RealmList<>());
    newPost.setCustomExcerpt(markdown.substring(0, 100));
    Response<PostList> response = execute(API.createPost(token.getAuthHeader(),
            PostStubList.from(newPost)));
    String createdId = response.body().posts.get(0).getId();
    Post created = execute(API.getPost(token.getAuthHeader(), createdId)).body().posts.get(0);

    try {
        callback.call(newPost, response, created);
    } finally {
        execute(API.deletePost(token.getAuthHeader(), created.getId()));
    }
}
 
Example #3
Source File: RealmMember.java    From iGap-Android with GNU Affero General Public License v3.0 6 votes vote down vote up
public static RealmList<RealmMember> getMembers(Realm realm, long roomId) {
    RealmRoom realmRoom = realm.where(RealmRoom.class).equalTo(RealmRoomFields.ID, roomId).findFirst();
    RealmList<RealmMember> memberList = new RealmList<>();
    if (realmRoom != null) {
        if (realmRoom.getType() == GROUP) {
            if (realmRoom.getGroupRoom() != null) {
                memberList = realmRoom.getGroupRoom().getMembers();
            }
        } else {
            if (realmRoom.getChannelRoom() != null) {
                memberList = realmRoom.getChannelRoom().getMembers();
            }
        }
    }
    return memberList;
}
 
Example #4
Source File: GitCommitModel.java    From mvvm-template with GNU General Public License v3.0 6 votes vote down vote up
protected GitCommitModel(Parcel in) {
    this.sha = in.readString();
    this.url = in.readString();
    this.message = in.readString();
    this.author = in.readParcelable(User.class.getClassLoader());
    this.committer = in.readParcelable(User.class.getClassLoader());
    this.tree = in.readParcelable(User.class.getClassLoader());
    this.distincted = in.readByte() != 0;

    this.parents = new RealmList<>();
    ArrayList<GitCommitModel> list = in.createTypedArrayList(GitCommitModel.CREATOR);
    if (list != null && list.size() > 0) {
        parents.addAll(list);
    }

    this.commentCount = in.readInt();
}
 
Example #5
Source File: Champion.java    From Theogony with MIT License 6 votes vote down vote up
public Champion(int id, String key, String name, String title,
                String image, String lore, String blurb,
                String enemytipsc, String allytipsc, String tagsc,
                String partype, Info info, Stats stats, Passive passive,
                RealmList<Spell> spells, RealmList<Skin> skins) {
    this.id = id;
    this.key = key;
    this.name = name;
    this.title = title;
    this.image = image;
    this.lore = lore;
    this.blurb = blurb;
    this.enemytipsc = enemytipsc;
    this.allytipsc = allytipsc;
    this.tagsc = tagsc;
    this.partype = partype;
    this.info = info;
    this.stats = stats;
    this.passive = passive;
    this.spells = spells;
    this.skins = skins;
}
 
Example #6
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 #7
Source File: RealmGroupRoom.java    From iGap-Android with GNU Affero General Public License v3.0 6 votes vote down vote up
public static GroupChatRole detectMemberRole(long roomId, long messageSenderId) {
    GroupChatRole role = GroupChatRole.UNRECOGNIZED;
    Realm realm = Realm.getDefaultInstance();
    RealmRoom realmRoom = realm.where(RealmRoom.class).equalTo(RealmRoomFields.ID, roomId).findFirst();
    if (realmRoom != null) {
        if (realmRoom.getGroupRoom() != null) {
            RealmList<RealmMember> realmMembers = realmRoom.getGroupRoom().getMembers();
            for (RealmMember realmMember : realmMembers) {
                if (realmMember.getPeerId() == messageSenderId) {
                    role = GroupChatRole.valueOf(realmMember.getRole());
                }
            }
        }
    }
    realm.close();
    return role;
}
 
Example #8
Source File: RealmChannelRoom.java    From iGap-Android with GNU Affero General Public License v3.0 6 votes vote down vote up
public static ProtoGlobal.ChannelRoom.Role detectMemberRoleServerEnum(long roomId, long messageSenderId) {
    ProtoGlobal.ChannelRoom.Role role = ProtoGlobal.ChannelRoom.Role.UNRECOGNIZED;
    Realm realm = Realm.getDefaultInstance();
    RealmRoom realmRoom = realm.where(RealmRoom.class).equalTo(RealmRoomFields.ID, roomId).findFirst();
    if (realmRoom != null) {
        if (realmRoom.getChannelRoom() != null) {
            RealmList<RealmMember> realmMembers = realmRoom.getChannelRoom().getMembers();
            for (RealmMember realmMember : realmMembers) {
                if (realmMember.getPeerId() == messageSenderId) {
                    role = ProtoGlobal.ChannelRoom.Role.valueOf(realmMember.getRole());
                }
            }
        }
    }
    realm.close();
    return role;
}
 
Example #9
Source File: Spell.java    From Theogony with MIT License 6 votes vote down vote up
public Spell(String name, String description, String sanitizedDescription,
             String tooltip, String sanitizedTooltip, String image, String resource,
             int maxrank, String costType, String costBurn, String cooldownBurn,
             RealmList<Var> vars, String rangeBurn, String key) {
    this.name = name;
    this.description = description;
    this.sanitizedDescription = sanitizedDescription;
    this.tooltip = tooltip;
    this.sanitizedTooltip = sanitizedTooltip;
    this.image = image;
    this.resource = resource;
    this.maxrank = maxrank;
    this.costType = costType;
    this.costBurn = costBurn;
    this.cooldownBurn = cooldownBurn;
    this.vars = vars;
    this.rangeBurn = rangeBurn;
    this.key = key;
}
 
Example #10
Source File: ApiaryTest.java    From go-bees with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void apiaryTest() {
    Apiary apiary = ApiaryMother.newDefaultApiary();
    // Image url
    apiary.setImageUrl("asdf");
    assertEquals("asdf", apiary.getImageUrl());
    // Add hive
    int hives = apiary.getHives().size();
    apiary.addHive(HiveMother.newDefaultHive());
    assertEquals(hives + 1, apiary.getHives().size());
    apiary.setHives(null);
    // Meteo records
    assertNull(apiary.getMeteoRecords());
    apiary.setMeteoRecords(new RealmList<MeteoRecord>());
    assertNotNull(apiary.getMeteoRecords());
    apiary.addMeteoRecord(new MeteoRecord());
    assertEquals(1, apiary.getMeteoRecords().size());
    List<MeteoRecord> meteoRecords = Lists.newArrayList(new MeteoRecord(), new MeteoRecord());
    apiary.addMeteoRecords(meteoRecords);
    assertEquals(3, apiary.getMeteoRecords().size());

}
 
Example #11
Source File: RealmMember.java    From iGap-Android with GNU Affero General Public License v3.0 6 votes vote down vote up
public static boolean kickMember(Realm realm, final long roomId, final long userId) {

        //test this <code>realmRoom.getGroupRoom().getMembers().where().equalTo(RealmMemberFields.PEER_ID, builder.getMemberId()).findFirst();</code> for kick member
        RealmRoom realmRoom = realm.where(RealmRoom.class).equalTo(RealmRoomFields.ID, roomId).findFirst();
        if (realmRoom != null) {
            RealmList<RealmMember> realmMembers = new RealmList<>();
            if (realmRoom.getType() == GROUP) {
                if (realmRoom.getGroupRoom() != null) {
                    realmMembers = realmRoom.getGroupRoom().getMembers();
                }
            } else {
                if (realmRoom.getChannelRoom() != null) {
                    realmMembers = realmRoom.getChannelRoom().getMembers();
                }
            }
            for (RealmMember realmMember : realmMembers) {
                if (realmMember.getPeerId() == userId) {
                    realmMember.deleteFromRealm();
                    return true;
                }
            }
        }
        return false;
    }
 
Example #12
Source File: Util.java    From rx-realm with MIT License 6 votes vote down vote up
@SuppressWarnings("unchecked")
protected static void collectRelatedRealmClass(Set<String> set, Class<? extends RealmObject> start) {
    if (set.add(start.getCanonicalName())) {
        List<Field> fields = ReflectionUtil.getPrivateFields(start);
        for (Field field: fields) {
            if (ReflectionUtil.isSubclass(field, RealmObject.class)) {
                final Class fieldType = field.getType();
                collectRelatedRealmClass(set, (Class<? extends RealmObject>) fieldType);
            } else if (ReflectionUtil.isSubclass(field, RealmList.class)) {
                final ParameterizedType genericType = (ParameterizedType) field.getGenericType();
                final Class aClass = (Class<?>) genericType.getActualTypeArguments()[0];
                collectRelatedRealmClass(set, (Class<? extends RealmObject>) aClass);
            }
        }
    }

}
 
Example #13
Source File: Apiary.java    From go-bees with GNU General Public License v3.0 5 votes vote down vote up
public Apiary(long id, String name, @Nullable String imageUrl, @Nullable Double locationLat,
              @Nullable Double locationLong, @Nullable String notes,
              @Nullable RealmList<Hive> hives, @Nullable MeteoRecord currentWeather,
              @Nullable RealmList<MeteoRecord> meteoRecords) {
    this.id = id;
    this.name = name;
    this.imageUrl = imageUrl;
    this.locationLat = locationLat;
    this.locationLong = locationLong;
    this.notes = notes;
    this.hives = hives;
    this.currentWeather = currentWeather;
    this.meteoRecords = meteoRecords;
}
 
Example #14
Source File: ModelTestUtils.java    From mvvm-template with GNU General Public License v3.0 5 votes vote down vote up
public static Issue sampleIssue(Long id, Long repoId) {
        Issue issue = new Issue();
        issue.setId(id);
//        issue.setRepoId(repoId);
        issue.setTitle("This is title of issue " + id);
        issue.setBody("This is body of issue " + id);
        issue.setCreatedAt(new Date());
        issue.setUser(sampleUser(43L));
        issue.setLabels(new RealmList<>());
        return issue;
    }
 
Example #15
Source File: RealmObservable.java    From Leaderboards with Apache License 2.0 5 votes vote down vote up
public static <T extends RealmObject> Observable<RealmList<T>> list(Context context, final Func1<Realm, RealmList<T>> function) {
    return Observable.create(new OnSubscribeRealmList<T>(context) {
        @Override
        public RealmList<T> get(Realm realm) {
            return function.call(realm);
        }
    });
}
 
Example #16
Source File: VideoRealmListDeserializer.java    From udacity-p1-p2-popular-movies with MIT License 5 votes vote down vote up
@Override
public RealmList<Video> deserialize(JsonElement element, Type type, JsonDeserializationContext context)
        throws JsonParseException {
    RealmList<Video> videos = new RealmList<>();
    JsonArray ja = element.getAsJsonObject().get("results").getAsJsonArray();
    for (JsonElement je : ja) {
        videos.add((Video) context.deserialize(je, Video.class));
    }
    return videos;
}
 
Example #17
Source File: ApiaryMother.java    From go-bees with GNU General Public License v3.0 5 votes vote down vote up
private void setValues(int numHives) {
    // Generate id
    Random r = new Random(System.nanoTime());
    id = r.nextInt(MAX_ID);
    // Generate name
    name = NAME_PREFIX + " " + id;
    // Generate hives
    List<Hive> generatedHives = generateHives(numHives);
    hives = new RealmList<>(generatedHives.toArray(new Hive[generatedHives.size()]));
    // Generate location
    Location location = getRandomNearLocation(LAT, LON);
    locationLat = location.getLatitude();
    locationLong = location.getLongitude();
}
 
Example #18
Source File: Hive.java    From go-bees with GNU General Public License v3.0 5 votes vote down vote up
public Hive(long id, String name, @Nullable String imageUrl,
            @Nullable String notes, Date lastRevision, @Nullable RealmList<Record> records) {
    this.id = id;
    this.name = name;
    this.imageUrl = imageUrl;
    this.notes = notes;
    this.lastRevision = lastRevision;
    this.records = records;
}
 
Example #19
Source File: Post.java    From quill with MIT License 5 votes vote down vote up
protected Post(Parcel in) {
    this.id = in.readString();
    this.uuid = in.readString();
    this.title = in.readString();
    this.slug = in.readString();
    //noinspection WrongConstant
    this.status = in.readString();
    this.markdown = in.readString();
    this.mobiledoc = in.readString();
    this.html = in.readString();
    this.tags = new RealmList<>();
    in.readList(this.tags, Tag.class.getClassLoader());
    this.featureImage = in.readString();
    this.featured = in.readByte() != 0;
    this.page = in.readByte() != 0;
    this.language = in.readString();
    this.author = in.readString();
    this.createdBy = in.readString();
    this.updatedBy = in.readString();
    this.publishedBy = in.readString();
    long tmpCreatedAt = in.readLong();
    this.createdAt = tmpCreatedAt == -1 ? null : new Date(tmpCreatedAt);
    long tmpUpdatedAt = in.readLong();
    this.updatedAt = tmpUpdatedAt == -1 ? null : new Date(tmpUpdatedAt);
    long tmpPublishedAt = in.readLong();
    this.publishedAt = tmpPublishedAt == -1 ? null : new Date(tmpPublishedAt);
    this.metaTitle = in.readString();
    this.metaDescription = in.readString();
    this.customExcerpt = in.readString();
    this.pendingActions = new RealmList<>();
    in.readList(this.pendingActions, PendingAction.class.getClassLoader());
    //noinspection WrongConstant
    this.conflictState = in.readString();
}
 
Example #20
Source File: PostViewActivity.java    From quill with MIT License 5 votes vote down vote up
@Override
public RealmList<Tag> getTags() {
    RealmList<Tag> tags = new RealmList<>();
    List<String> tagStrs = mPostTagsEditText.getTokens();
    for (String tagStr : tagStrs) {
        tags.add(new Tag(tagStr));
    }
    return tags;
}
 
Example #21
Source File: ImageVoMapper.java    From DaggerWorkshopGDG with Apache License 2.0 5 votes vote down vote up
public static RealmList<ImageVo> toVo(List<String> imageUrls) {
    RealmList<ImageVo> vos = null;

    if (imageUrls != null && !imageUrls.isEmpty()) {
        vos = new RealmList<>();

        for (String imageUrl : imageUrls) {
            vos.add(toVo(imageUrl));
        }
    }

    return vos;
}
 
Example #22
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 #23
Source File: RealmRegisteredInfo.java    From iGap-Android with GNU Affero General Public License v3.0 5 votes vote down vote up
public RealmList<RealmAvatar> getAvatars() {
    RealmList<RealmAvatar> avatars = new RealmList<>();
    Realm realm = Realm.getDefaultInstance();
    for (RealmAvatar avatar : realm.where(RealmAvatar.class).equalTo(RealmAvatarFields.OWNER_ID, id).findAll().sort(RealmAvatarFields.ID, Sort.ASCENDING)) {
        avatars.add(avatar);
    }
    realm.close();
    return avatars;
}
 
Example #24
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 #25
Source File: DatabaseHelper.java    From redgram-for-reddit with GNU General Public License v3.0 5 votes vote down vote up
public static RealmList<Subreddit> getSubreddits(Realm realm, String userId) {
    User user = getUserById(realm, userId);
    if(user != null){
        return user.getSubreddits();
    }
    return null;
}
 
Example #26
Source File: DatabaseHelper.java    From redgram-for-reddit with GNU General Public License v3.0 5 votes vote down vote up
public static RealmList<Subreddit> getSubreddits(Realm realm) {
    User user = getSessionUser(realm);
    if(user != null){
        return user.getSubreddits();
    }
    return null;
}
 
Example #27
Source File: RealmDemoData.java    From Stayfit with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor for stacked bars.
 *
 * @param stackValues
 * @param xIndex
 * @param xValue
 */
public RealmDemoData(float[] stackValues, int xIndex, String xValue) {
    this.xIndex = xIndex;
    this.xValue = xValue;
    this.stackValues = new RealmList<RealmFloat>();

    for (float val : stackValues) {
        this.stackValues.add(new RealmFloat(val));
    }
}
 
Example #28
Source File: RealmClientCondition.java    From iGap-Android with GNU Affero General Public License v3.0 4 votes vote down vote up
public RealmList<RealmOfflineDelete> getOfflineDeleted() {
    return offlineDeleted;
}
 
Example #29
Source File: RealmClientCondition.java    From iGap-Android with GNU Affero General Public License v3.0 4 votes vote down vote up
public void setOfflineDeleted(RealmList<RealmOfflineDelete> offlineDeleted) {
    this.offlineDeleted = offlineDeleted;
}
 
Example #30
Source File: RealmWallpaper.java    From iGap-Android with GNU Affero General Public License v3.0 4 votes vote down vote up
public RealmList<RealmWallpaperProto> getWallPaperList() {
    return realmWallpaperProto;
}