use of net.iGap.realm.RealmStoryProto in project iGap-Android by KianIranian-STDG.
the class MessageDataStorage method isStorySeen.
public boolean isStorySeen(long storyId) {
CountDownLatch countDownLatch = new CountDownLatch(1);
boolean[] result = new boolean[1];
storageQueue.postRunnable(() -> {
try {
database.executeTransaction(realm -> {
RealmStoryProto realmStoryProto = realm.where(RealmStoryProto.class).equalTo("isForReply", false).equalTo("storyId", storyId).findFirst();
if (realmStoryProto != null) {
result[0] = realmStoryProto.isSeen();
}
});
countDownLatch.countDown();
} catch (Exception e) {
FileLog.e(e);
} finally {
countDownLatch.countDown();
}
});
try {
countDownLatch.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
return result[0];
}
use of net.iGap.realm.RealmStoryProto in project iGap-Android by KianIranian-STDG.
the class MessageDataStorage method getStoryWithFileToken.
public StoryObject getStoryWithFileToken(String fileToken) {
CountDownLatch countDownLatch = new CountDownLatch(1);
StoryObject[] storyObjects = new StoryObject[1];
storageQueue.postRunnable(() -> {
try {
RealmStoryProto realmStoryProto = database.where(RealmStoryProto.class).equalTo("sessionId", AccountManager.getInstance().getCurrentUser().getId()).equalTo("isForReply", false).equalTo("fileToken", fileToken).findFirst();
if (realmStoryProto != null) {
storyObjects[0] = StoryObject.create(realmStoryProto);
}
countDownLatch.countDown();
} catch (Exception e) {
FileLog.e(e);
} finally {
countDownLatch.countDown();
}
});
try {
countDownLatch.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
return storyObjects[0];
}
use of net.iGap.realm.RealmStoryProto in project iGap-Android by KianIranian-STDG.
the class MessageDataStorage method getStoryWithUploadId.
public StoryObject getStoryWithUploadId(long uploadId) {
CountDownLatch countDownLatch = new CountDownLatch(1);
StoryObject[] storyObjects = new StoryObject[1];
storageQueue.postRunnable(() -> {
try {
RealmStoryProto realmStoryProto = database.where(RealmStoryProto.class).equalTo("sessionId", AccountManager.getInstance().getCurrentUser().getId()).equalTo("isForReply", false).equalTo("id", uploadId).findFirst();
if (realmStoryProto != null) {
storyObjects[0] = StoryObject.create(realmStoryProto);
}
countDownLatch.countDown();
} catch (Exception e) {
FileLog.e(e);
} finally {
countDownLatch.countDown();
}
});
try {
countDownLatch.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
return storyObjects[0];
}
use of net.iGap.realm.RealmStoryProto in project iGap-Android by KianIranian-STDG.
the class StoryCell method setData.
public void setData(StoryObject storyObject, boolean isRoom, String displayName, String color, Context context, boolean needDivider, CircleStatus status, ImageLoadingView.Status imageLoadingStatus, IconClicked iconClicked) {
initView(context, needDivider, status, imageLoadingStatus, iconClicked, storyObject.createdAt);
this.userId = storyObject.userId;
this.roomId = storyObject.roomId;
this.isFromMyStatus = true;
String name = HelperImageBackColor.getFirstAlphabetName(storyObject.displayName != null ? storyObject.displayName : "");
if (circleImageLoading.getStatus() == ImageLoadingView.Status.FAILED) {
if (isRoom && mode == 0) {
deleteIcon.setTextColor(Color.RED);
topText.setText(storyObject.displayName);
bottomText.setText(context.getString(R.string.story_could_not_sent));
bottomText.setTextColor(Color.RED);
} else {
uploadIcon.setVisibility(VISIBLE);
deleteIcon.setVisibility(VISIBLE);
deleteIcon.setText(R.string.icon_delete);
topText.setVisibility(GONE);
bottomText.setVisibility(GONE);
middleText.setVisibility(VISIBLE);
middleText.setText(context.getString(R.string.story_could_not_sent));
middleText.setTextColor(Color.RED);
}
} else if (circleImageLoading.getStatus() == ImageLoadingView.Status.LOADING) {
if (isRoom && mode == 0) {
topText.setText(storyObject.displayName);
bottomText.setText(context.getString(R.string.story_sending));
} else {
uploadIcon.setVisibility(GONE);
deleteIcon.setVisibility(GONE);
topText.setVisibility(GONE);
middleText.setVisibility(VISIBLE);
middleText.setText(context.getString(R.string.story_sending));
middleText.setTextColor(Theme.getInstance().getTitleTextColor(context));
}
} else {
topText.setVisibility(VISIBLE);
bottomText.setVisibility(VISIBLE);
middleText.setVisibility(GONE);
uploadIcon.setVisibility(GONE);
deleteIcon.setVisibility(VISIBLE);
if (isRoom && mode == 0) {
topText.setText(storyObject.displayName);
} else {
if (G.selectedLanguage.equals("fa")) {
topText.setText(HelperCalander.convertToUnicodeFarsiNumber(String.valueOf(storyObject.viewCount)) + " " + context.getString(R.string.story_views));
} else {
topText.setText(storyObject.viewCount + " " + context.getString(R.string.story_views));
}
}
bottomText.setText(LastSeenTimeUtil.computeTime(context, storyObject.userId, storyObject.createdAt / 1000L, false, false));
}
AttachmentObject attachment = storyObject.attachmentObject;
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(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, storyObject.storyId, true);
Log.e("skfjskjfsd", "setData2: " + storyId + "/" + object.downloadId);
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 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