use of net.iGap.story.MainStoryObject in project iGap-Android by KianIranian-STDG.
the class MessageDataStorage method getAllStories.
public List<MainStoryObject> getAllStories(String sortAs) {
CountDownLatch countDownLatch = new CountDownLatch(1);
List<RealmStory> stories = new ArrayList<>();
List<MainStoryObject> storyObjects = new ArrayList<>();
storageQueue.postRunnable(() -> {
try {
if (sortAs != null) {
stories.addAll(database.where(RealmStory.class).equalTo("sessionId", AccountManager.getInstance().getCurrentUser().getId()).findAll().sort(sortAs));
} else {
stories.addAll(database.where(RealmStory.class).equalTo("sessionId", AccountManager.getInstance().getCurrentUser().getId()).findAll());
}
for (int i = 0; i < stories.size(); i++) {
storyObjects.add(MainStoryObject.create(stories.get(i)));
}
countDownLatch.countDown();
} catch (Exception e) {
FileLog.e(e);
} finally {
countDownLatch.countDown();
}
});
try {
countDownLatch.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
return storyObjects;
}
use of net.iGap.story.MainStoryObject 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