use of net.iGap.realm.RealmStoryProto in project iGap-Android by KianIranian-STDG.
the class MessageDataStorage method getCurrentUserRoomStories.
public List<StoryObject> getCurrentUserRoomStories(long roomId, int listMode) {
CountDownLatch countDownLatch = new CountDownLatch(1);
List<StoryObject> stories = new ArrayList<>();
storageQueue.postRunnable(() -> {
try {
RealmResults<RealmStoryProto> realmStoryProto;
boolean isAbleToAdd = true;
if (roomId == 0) {
realmStoryProto = database.where(RealmStoryProto.class).equalTo("isForRoom", true).equalTo("userId", AccountManager.getInstance().getCurrentUser().getId()).equalTo("sessionId", AccountManager.getInstance().getCurrentUser().getId()).equalTo("isForReply", false).findAll().sort(new String[] { "createdAt", "index" }, new Sort[] { Sort.DESCENDING, Sort.DESCENDING });
} else {
realmStoryProto = database.where(RealmStoryProto.class).equalTo("isForRoom", true).equalTo("roomId", roomId).equalTo("userId", AccountManager.getInstance().getCurrentUser().getId()).equalTo("sessionId", AccountManager.getInstance().getCurrentUser().getId()).equalTo("isForReply", false).findAll().sort(new String[] { "createdAt", "index" }, new Sort[] { Sort.DESCENDING, Sort.DESCENDING });
}
for (int i = 0; i < realmStoryProto.size(); i++) {
if (listMode == 0) {
for (int j = 0; j < stories.size(); j++) {
if (realmStoryProto.get(i).getRoomId() == stories.get(j).roomId) {
isAbleToAdd = false;
break;
} else {
isAbleToAdd = true;
}
}
if (isAbleToAdd) {
stories.add(StoryObject.create(realmStoryProto.get(i)));
}
} else {
stories.add(StoryObject.create(realmStoryProto.get(i)));
}
}
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.realm.RealmStoryProto 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.realm.RealmStoryProto 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.realm.RealmStoryProto in project iGap-Android by KianIranian-STDG.
the class MessageDataStorage method updateStoryStatus.
public void updateStoryStatus(long id, int status) {
CountDownLatch countDownLatch = new CountDownLatch(1);
storageQueue.postRunnable(() -> {
try {
database.executeTransaction(realm -> {
RealmStoryProto realmStoryProto = realm.where(RealmStoryProto.class).equalTo("isForReply", false).equalTo("id", id).findFirst();
if (realmStoryProto != null) {
realmStoryProto.setStatus(status);
}
});
countDownLatch.countDown();
} catch (Exception e) {
FileLog.e(e);
} finally {
countDownLatch.countDown();
}
});
try {
countDownLatch.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
use of net.iGap.realm.RealmStoryProto in project iGap-Android by KianIranian-STDG.
the class MessageDataStorage method getNotNullTokenStories.
public List<StoryObject> getNotNullTokenStories(long userId, int status) {
CountDownLatch countDownLatch = new CountDownLatch(1);
List<RealmStoryProto> stories = new ArrayList<>();
List<StoryObject> storyObjects = new ArrayList<>();
storageQueue.postRunnable(() -> {
try {
if (status == 0) {
stories.addAll(database.where(RealmStoryProto.class).equalTo("sessionId", AccountManager.getInstance().getCurrentUser().getId()).equalTo("isForReply", false).equalTo("userId", userId).isNotNull("fileToken").findAll());
} else {
stories.addAll(database.where(RealmStoryProto.class).equalTo("sessionId", AccountManager.getInstance().getCurrentUser().getId()).equalTo("isForReply", false).equalTo("userId", userId).equalTo("status", status).isNotNull("fileToken").findAll());
}
for (int i = 0; i < stories.size(); i++) {
storyObjects.add(StoryObject.create(database.copyFromRealm(stories.get(i))));
}
countDownLatch.countDown();
} catch (Exception e) {
FileLog.e(e);
} finally {
countDownLatch.countDown();
}
});
try {
countDownLatch.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
return storyObjects;
}
Aggregations