use of net.iGap.realm.RealmStoryProto in project iGap-Android by KianIranian-STDG.
the class MessageDataStorage method getStoryById.
public MainStoryObject getStoryById(long userId, boolean needSort) {
CountDownLatch countDownLatch = new CountDownLatch(1);
List<MainStoryObject> stories = new ArrayList<>();
storageQueue.postRunnable(() -> {
FileLog.i(TAG, "getStoryById: " + "userId: " + userId + " needSort: " + needSort);
try {
List<StoryObject> storyObjects = new ArrayList<>();
MainStoryObject mainStoryObject;
RealmStory realmStory = database.where(RealmStory.class).equalTo("sessionId", AccountManager.getInstance().getCurrentUser().getId()).equalTo("userId", userId).findFirst();
if (realmStory != null) {
if (needSort) {
RealmResults<RealmStoryProto> realmStoryProtos = realmStory.getRealmStoryProtos().sort(new String[] { "createdAt", "index" }, new Sort[] { Sort.DESCENDING, Sort.DESCENDING });
for (int i = 0; i < realmStoryProtos.size(); i++) {
storyObjects.add(StoryObject.create(realmStoryProtos.get(i)));
}
mainStoryObject = MainStoryObject.create(realmStory);
mainStoryObject.storyObjects = storyObjects;
} else {
mainStoryObject = MainStoryObject.create(realmStory);
}
stories.add(mainStoryObject);
}
countDownLatch.countDown();
} catch (Exception e) {
FileLog.e(e);
} finally {
countDownLatch.countDown();
}
});
try {
countDownLatch.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
return (stories.size() > 0 ? stories.get(0) : null);
}
Aggregations