Search in sources :

Example 6 with MainStoryObject

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;
}
Also used : RealmStory(net.iGap.realm.RealmStory) ArrayList(java.util.ArrayList) MainStoryObject(net.iGap.story.MainStoryObject) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 7 with MainStoryObject

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);
}
Also used : MainStoryObject(net.iGap.story.MainStoryObject) StoryObject(net.iGap.story.StoryObject) RealmStoryProto(net.iGap.realm.RealmStoryProto) RealmStory(net.iGap.realm.RealmStory) ArrayList(java.util.ArrayList) MainStoryObject(net.iGap.story.MainStoryObject) CountDownLatch(java.util.concurrent.CountDownLatch)

Aggregations

ArrayList (java.util.ArrayList)7 MainStoryObject (net.iGap.story.MainStoryObject)7 RealmStory (net.iGap.realm.RealmStory)6 RealmStoryProto (net.iGap.realm.RealmStoryProto)6 StoryObject (net.iGap.story.StoryObject)6 CountDownLatch (java.util.concurrent.CountDownLatch)5 Context (android.content.Context)1 Canvas (android.graphics.Canvas)1 Color (android.graphics.Color)1 Paint (android.graphics.Paint)1 BitmapDrawable (android.graphics.drawable.BitmapDrawable)1 TextUtils (android.text.TextUtils)1 Log (android.util.Log)1 TypedValue (android.util.TypedValue)1 Gravity (android.view.Gravity)1 View (android.view.View)1 FrameLayout (android.widget.FrameLayout)1 LinearLayout (android.widget.LinearLayout)1 TextView (android.widget.TextView)1 NonNull (androidx.annotation.NonNull)1