use of net.iGap.story.MainStoryObject in project iGap-Android by KianIranian-STDG.
the class MessageDataStorage method getSortedStoryObjectsInMainStoryObject.
public List<MainStoryObject> getSortedStoryObjectsInMainStoryObject(long userId, String[] sortBy, Sort[] orderBy) {
CountDownLatch countDownLatch = new CountDownLatch(1);
List<MainStoryObject> stories = new ArrayList<>();
storageQueue.postRunnable(() -> {
try {
RealmResults<RealmStoryProto> realmStoryProtos;
RealmResults<RealmStory> realmStory;
RealmStory myRealmStory = null;
RealmStory igapRealmStory = null;
boolean isExistIgapRoomStory = false;
igapRealmStory = database.where(RealmStory.class).equalTo("roomId", 2901).equalTo("sessionId", AccountManager.getInstance().getCurrentUser().getId()).findFirst();
if (igapRealmStory != null && igapRealmStory.getRealmStoryProtos().size() > 0) {
isExistIgapRoomStory = true;
}
if (userId == 0) {
myRealmStory = database.where(RealmStory.class).equalTo("sessionId", AccountManager.getInstance().getCurrentUser().getId()).equalTo("userId", AccountManager.getInstance().getCurrentUser().getId()).findFirst();
realmStory = database.where(RealmStory.class).equalTo("sessionId", AccountManager.getInstance().getCurrentUser().getId()).notEqualTo("userId", AccountManager.getInstance().getCurrentUser().getId()).sort("lastCreatedAt", Sort.DESCENDING).findAll();
} else {
realmStory = database.where(RealmStory.class).equalTo("sessionId", AccountManager.getInstance().getCurrentUser().getId()).equalTo("userId", userId).findAll();
}
if (realmStory != null && realmStory.size() > 0) {
for (int i = 0; i < realmStory.size(); i++) {
List<StoryObject> storyObjects = new ArrayList<>();
realmStoryProtos = realmStory.get(i).getRealmStoryProtos().sort(sortBy, orderBy);
if (isExistIgapRoomStory && realmStory.get(i).getRoomId() == 2901) {
stories.add(0, MainStoryObject.create(realmStory.get(i)));
} else {
stories.add(MainStoryObject.create(realmStory.get(i)));
}
for (int j = 0; j < realmStoryProtos.size(); j++) {
storyObjects.add(StoryObject.create(realmStoryProtos.get(j)));
}
stories.get(isExistIgapRoomStory && realmStory.get(i).getRoomId() == 2901 ? 0 : i).storyObjects = storyObjects;
}
if (userId == 0 && myRealmStory != null) {
List<StoryObject> storyObjects = new ArrayList<>();
realmStoryProtos = myRealmStory.getRealmStoryProtos().sort(sortBy, orderBy);
stories.add(0, MainStoryObject.create(myRealmStory));
for (int j = 0; j < realmStoryProtos.size(); j++) {
storyObjects.add(StoryObject.create(realmStoryProtos.get(j)));
}
stories.get(0).storyObjects = storyObjects;
}
} else {
if (userId == 0 && myRealmStory != null) {
List<StoryObject> storyObjects = new ArrayList<>();
realmStoryProtos = myRealmStory.getRealmStoryProtos().sort(sortBy, orderBy);
stories.add(0, MainStoryObject.create(myRealmStory));
for (int j = 0; j < realmStoryProtos.size(); j++) {
storyObjects.add(StoryObject.create(realmStoryProtos.get(j)));
}
stories.get(0).storyObjects = storyObjects;
}
}
countDownLatch.countDown();
} catch (Exception e) {
FileLog.e(e);
} finally {
countDownLatch.countDown();
}
});
try {
countDownLatch.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
return stories;
}
use of net.iGap.story.MainStoryObject in project iGap-Android by KianIranian-STDG.
the class MessageDataStorage method getOtherUsersStories.
public List<MainStoryObject> getOtherUsersStories() {
CountDownLatch countDownLatch = new CountDownLatch(1);
List<RealmStory> stories = new ArrayList<>();
List<MainStoryObject> mainStoryObjects = new ArrayList<>();
storageQueue.postRunnable(() -> {
try {
boolean isExistIgapRoomStory = false;
RealmStory igapRealmStory = database.where(RealmStory.class).equalTo("roomId", 2901).equalTo("sessionId", AccountManager.getInstance().getCurrentUser().getId()).findFirst();
stories.addAll(database.where(RealmStory.class).notEqualTo("userId", AccountManager.getInstance().getCurrentUser().getId()).equalTo("sessionId", AccountManager.getInstance().getCurrentUser().getId()).sort("lastCreatedAt", Sort.DESCENDING).findAll());
if (igapRealmStory != null && igapRealmStory.getRealmStoryProtos().size() > 0) {
isExistIgapRoomStory = true;
}
for (int i = 0; i < stories.size(); i++) {
List<StoryObject> storyObjects = new ArrayList<>();
RealmResults<RealmStoryProto> realmStoryProtos = stories.get(i).getRealmStoryProtos().sort(new String[] { "createdAt", "index" }, new Sort[] { Sort.DESCENDING, Sort.DESCENDING });
if (realmStoryProtos != null && realmStoryProtos.size() > 0) {
for (int j = 0; j < realmStoryProtos.size(); j++) {
storyObjects.add(StoryObject.create(realmStoryProtos.get(j)));
}
MainStoryObject mainStoryObject = MainStoryObject.create(database.copyFromRealm(stories.get(i)));
mainStoryObject.storyObjects = storyObjects;
if (isExistIgapRoomStory && stories.get(i).getRoomId() == 2901) {
mainStoryObjects.add(0, mainStoryObject);
} else {
mainStoryObjects.add(mainStoryObject);
}
}
}
countDownLatch.countDown();
} catch (Exception e) {
FileLog.e(e);
} finally {
countDownLatch.countDown();
}
});
try {
countDownLatch.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
return mainStoryObjects;
}
use of net.iGap.story.MainStoryObject in project iGap-Android by KianIranian-STDG.
the class StoryCell method setData.
public void setData(MainStoryObject mainStoryObject, String color, Context context, boolean needDivider, CircleStatus status, ImageLoadingView.Status imageLoadingStatus, IconClicked iconClicked) {
this.userId = mainStoryObject.userId;
this.roomId = mainStoryObject.roomId;
this.isVerified = mainStoryObject.isVerified;
initView(context, needDivider, status, imageLoadingStatus, iconClicked, mainStoryObject.storyObjects.get(0).createdAt);
circleImageLoading.setStatus(imageLoadingStatus);
if (userId == AccountManager.getInstance().getCurrentUser().getId()) {
topText.setText(context.getString(R.string.my_status));
} else {
if (roomId != 0) {
channelIconTv.setVisibility(VISIBLE);
}
if (isVerified) {
verifyIconTv.setVisibility(VISIBLE);
}
topText.setText(mainStoryObject.storyObjects.get(0).displayName != null ? mainStoryObject.storyObjects.get(0).displayName : "");
}
String name = HelperImageBackColor.getFirstAlphabetName(mainStoryObject.storyObjects.get(0).displayName != null ? mainStoryObject.storyObjects.get(0).displayName : "");
if (circleImageLoading.getStatus() == ImageLoadingView.Status.FAILED) {
bottomText.setText(context.getString(R.string.story_could_not_sent));
bottomText.setTextColor(Color.RED);
deleteIcon.setTextColor(Color.RED);
addIcon.setTextColor(Color.RED);
addIcon.setText(R.string.icon_error);
} else if (circleImageLoading.getStatus() == ImageLoadingView.Status.LOADING) {
bottomText.setText(context.getString(R.string.story_sending));
deleteIcon.setTextColor(Theme.getInstance().getTitleTextColor(context));
} else {
bottomText.setText(LastSeenTimeUtil.computeTime(context, mainStoryObject.userId, mainStoryObject.storyObjects.get(0).createdAt / 1000L, false, false));
}
AttachmentObject attachment = mainStoryObject.storyObjects.get(0).attachmentObject;
if (status == CircleStatus.LOADING_CIRCLE_IMAGE) {
if (attachment != null && (attachment.thumbnailPath != null || attachment.filePath != null)) {
try {
Glide.with(G.context).load(attachment.filePath != null ? attachment.filePath : attachment.thumbnailPath).placeholder(new BitmapDrawable(context.getResources(), HelperImageBackColor.drawAlphabetOnPicture(LayoutCreator.dp(64), name, color))).into(circleImageLoading);
} catch (Exception e) {
Glide.with(G.context).load(new BitmapDrawable(context.getResources(), HelperImageBackColor.drawAlphabetOnPicture(LayoutCreator.dp(64), name, color))).into(circleImageLoading);
}
} else if (attachment != null) {
Glide.with(G.context).load(new BitmapDrawable(context.getResources(), HelperImageBackColor.drawAlphabetOnPicture(LayoutCreator.dp(64), name, color))).into(circleImageLoading);
DownloadObject object = DownloadObject.createForStory(attachment, storyId, true);
if (object != null) {
Downloader.getInstance(AccountManager.selectedAccount).download(object, arg -> {
if (arg.status == Status.SUCCESS && arg.data != null) {
String filepath = arg.data.getFilePath();
String downloadedFileToken = arg.data.getToken();
if (!(new File(filepath).exists())) {
HelperLog.getInstance().setErrorLog(new Exception("File Dont Exist After Download !!" + filepath));
}
if (arg.data.getDownloadObject().downloadId == storyId) {
DbManager.getInstance().doRealmTransaction(realm1 -> {
RealmStoryProto realmStoryProto = realm1.where(RealmStoryProto.class).equalTo("isForReply", false).equalTo("storyId", storyId).findFirst();
if (realmStoryProto != null) {
realmStoryProto.getFile().setLocalFilePath(filepath);
}
});
G.runOnUiThread(() -> Glide.with(G.context).load(filepath).placeholder(new BitmapDrawable(context.getResources(), HelperImageBackColor.drawAlphabetOnPicture(LayoutCreator.dp(64), name, color))).into(circleImageLoading));
}
}
});
}
} else {
Glide.with(G.context).load(new BitmapDrawable(context.getResources(), HelperImageBackColor.drawAlphabetOnPicture(LayoutCreator.dp(64), name, color))).into(circleImageLoading);
}
}
}
use of net.iGap.story.MainStoryObject in project iGap-Android by KianIranian-STDG.
the class StoryViewFragment method onViewCreated.
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
if (isSingle) {
if (isForReply) {
DbManager.getInstance().doRealmTransaction(realm -> {
RealmStoryProto realmStoryProto = realm.where(RealmStoryProto.class).equalTo("isForReply", false).equalTo("storyId", storyId).findFirst();
if (realmStoryProto != null) {
MainStoryObject mainStoryObject = new MainStoryObject();
List<StoryObject> storyObjects = new ArrayList<>();
mainStoryObject.userId = realmStoryProto.getUserId();
storyObjects.add(StoryObject.create(realmStoryProto));
mainStoryObject.displayName = realmStoryProto.getDisplayName();
mainStoryObject.profileColor = realmStoryProto.getProfileColor();
mainStoryObject.storyObjects = storyObjects;
storyResults.add(mainStoryObject);
}
});
} else {
storyResults.addAll(getMessageDataStorage().getSortedStoryObjectsInMainStoryObject(userId, new String[] { "createdAt" }, new Sort[] { Sort.ASCENDING }));
}
} else {
if (isForRoom && !isForOtherRoom) {
storyResults.addAll(getMessageDataStorage().getSortedRoomStoryObjectsInMainStoryObject(0, isForOtherRoom, roomId, new String[] { "createdAt" }, new Sort[] { Sort.ASCENDING }));
} else {
storyResults.addAll(getMessageDataStorage().getSortedStoryObjectsInMainStoryObject(0, new String[] { "createdAt" }, new Sort[] { Sort.ASCENDING }));
}
}
setUpPager();
}
use of net.iGap.story.MainStoryObject in project iGap-Android by KianIranian-STDG.
the class MessageDataStorage method getSortedRoomStoryObjectsInMainStoryObject.
public List<MainStoryObject> getSortedRoomStoryObjectsInMainStoryObject(long userId, boolean isOtherRoomStory, long roomId, String[] sortBy, Sort[] orderBy) {
CountDownLatch countDownLatch = new CountDownLatch(1);
List<MainStoryObject> stories = new ArrayList<>();
storageQueue.postRunnable(() -> {
try {
RealmResults<RealmStoryProto> realmStoryProtos;
RealmResults<RealmStory> realmStory;
RealmStory myRealmStory = null;
if (isOtherRoomStory) {
myRealmStory = database.where(RealmStory.class).equalTo("sessionId", AccountManager.getInstance().getCurrentUser().getId()).equalTo("roomId", roomId).findFirst();
realmStory = database.where(RealmStory.class).equalTo("sessionId", AccountManager.getInstance().getCurrentUser().getId()).notEqualTo("userId", AccountManager.getInstance().getCurrentUser().getId()).sort("lastCreatedAt", Sort.DESCENDING).findAll();
} else {
realmStory = database.where(RealmStory.class).equalTo("sessionId", AccountManager.getInstance().getCurrentUser().getId()).equalTo("roomId", roomId).findAll();
if (realmStory == null || realmStory.size() == 0) {
realmStory = database.where(RealmStory.class).equalTo("sessionId", AccountManager.getInstance().getCurrentUser().getId()).equalTo("userId", AccountManager.getInstance().getCurrentUser().getId()).findAll();
}
}
if (realmStory != null && realmStory.size() > 0) {
for (int i = 0; i < realmStory.size(); i++) {
List<StoryObject> storyObjects = new ArrayList<>();
realmStoryProtos = realmStory.get(i).getRealmStoryProtos().sort(sortBy, orderBy);
stories.add(MainStoryObject.create(realmStory.get(i)));
for (int j = 0; j < realmStoryProtos.size(); j++) {
if (realmStoryProtos.get(j).isForRoom() && realmStoryProtos.get(j).getRoomId() == roomId) {
storyObjects.add(StoryObject.create(realmStoryProtos.get(j)));
}
}
stories.get(i).storyObjects = storyObjects;
}
if (isOtherRoomStory && myRealmStory != null) {
List<StoryObject> storyObjects = new ArrayList<>();
realmStoryProtos = myRealmStory.getRealmStoryProtos().sort(sortBy, orderBy);
stories.add(0, MainStoryObject.create(myRealmStory));
for (int j = 0; j < realmStoryProtos.size(); j++) {
if (realmStoryProtos.get(j).isForRoom() && realmStoryProtos.get(j).getRoomId() == roomId) {
storyObjects.add(StoryObject.create(realmStoryProtos.get(j)));
}
}
stories.get(0).storyObjects = storyObjects;
}
} else {
if (isOtherRoomStory && myRealmStory != null) {
List<StoryObject> storyObjects = new ArrayList<>();
realmStoryProtos = myRealmStory.getRealmStoryProtos().sort(sortBy, orderBy);
stories.add(0, MainStoryObject.create(myRealmStory));
for (int j = 0; j < realmStoryProtos.size(); j++) {
storyObjects.add(StoryObject.create(realmStoryProtos.get(j)));
}
stories.get(0).storyObjects = storyObjects;
}
}
countDownLatch.countDown();
} catch (Exception e) {
FileLog.e(e);
} finally {
countDownLatch.countDown();
}
});
try {
countDownLatch.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
return stories;
}
Aggregations