use of net.iGap.structs.AttachmentObject in project iGap-Android by KianIranian-STDG.
the class MessageDataStorage method createForwardMessage.
public void createForwardMessage(final long destinationRoomId, final long newMessageId, MessageObject sourceMessage, boolean isMessage, DatabaseDelegate databaseDelegate) {
storageQueue.postRunnable(() -> {
FileLog.i(TAG, "createForwardMessage: " + destinationRoomId + " " + newMessageId);
try {
final RealmRoomMessage[] forwardedMessage = new RealmRoomMessage[1];
MessageObject messageObject = null;
RealmRoomMessage copyMessage = null;
database.beginTransaction();
if (isMessage && sourceMessage.forwardedMessage == null) {
forwardedMessage[0] = database.createObject(RealmRoomMessage.class, newMessageId);
forwardedMessage[0].setCreateTime(TimeUtils.currentLocalTime());
forwardedMessage[0].setRoomId(destinationRoomId);
forwardedMessage[0].setStatus(ProtoGlobal.RoomMessageStatus.SENDING.toString());
forwardedMessage[0].setMessageType(ProtoGlobal.RoomMessageType.forNumber(sourceMessage.messageType));
forwardedMessage[0].setMessage(sourceMessage.message);
if (sourceMessage.attachment != null) {
AttachmentObject attObject = sourceMessage.attachment;
LocalFileType type = attObject.filePath == null ? LocalFileType.THUMBNAIL : LocalFileType.FILE;
String filePath = attObject.filePath != null ? attObject.filePath : attObject.thumbnailPath;
forwardedMessage[0].setAttachment(newMessageId, filePath, attObject.width, attObject.height, attObject.size, attObject.name, attObject.duration, attObject.token, type);
}
if (sourceMessage.contact != null) {
RoomContactObject contactObject = sourceMessage.contact;
ProtoGlobal.RoomMessageContact.Builder builder = ProtoGlobal.RoomMessageContact.newBuilder();
builder.setPhone(0, contactObject.phones.get(0));
builder.setFirstName(contactObject.firstName);
builder.setLastName(contactObject.lastName);
builder.setEmail(0, contactObject.emails.get(0));
RealmRoomMessageContact roomMessageContact = RealmRoomMessageContact.put(database, builder.build());
forwardedMessage[0].setRoomMessageContact(roomMessageContact);
}
forwardedMessage[0].setUserId(AccountManager.getInstance().getCurrentUser().getId());
database.copyToRealmOrUpdate(forwardedMessage[0]);
copyMessage = database.copyFromRealm(forwardedMessage[0]);
} else {
RealmRoomMessage roomMessage = database.where(RealmRoomMessage.class).equalTo("messageId", sourceMessage.id).findFirst();
if (roomMessage != null) {
forwardedMessage[0] = database.createObject(RealmRoomMessage.class, newMessageId);
if (roomMessage.getForwardMessage() != null) {
forwardedMessage[0].setForwardMessage(roomMessage.getForwardMessage());
forwardedMessage[0].setHasMessageLink(roomMessage.getForwardMessage().getHasMessageLink());
} else {
forwardedMessage[0].setForwardMessage(roomMessage);
forwardedMessage[0].setHasMessageLink(roomMessage.getHasMessageLink());
}
forwardedMessage[0].setCreateTime(TimeUtils.currentLocalTime());
forwardedMessage[0].setMessageType(ProtoGlobal.RoomMessageType.TEXT);
forwardedMessage[0].setRoomId(destinationRoomId);
forwardedMessage[0].setStatus(ProtoGlobal.RoomMessageStatus.SENDING.toString());
forwardedMessage[0].setUserId(AccountManager.getInstance().getCurrentUser().getId());
copyMessage = database.copyFromRealm(forwardedMessage[0]);
}
}
messageObject = MessageObject.create(copyMessage);
RealmRoomMessage realmSourceMessage = database.where(RealmRoomMessage.class).equalTo("messageId", sourceMessage.id).findFirst();
assert realmSourceMessage != null;
RealmRoomMessage copyOfSource = database.copyFromRealm(realmSourceMessage);
database.commitTransaction();
MessageObject finalMessageObject = messageObject;
RealmRoomMessage finalCopyMessage = copyMessage;
G.runOnUiThread(() -> {
databaseDelegate.run(finalMessageObject, finalCopyMessage, copyOfSource.getRoomId(), copyOfSource.getMessageId());
});
} catch (Exception e) {
FileLog.e(e);
}
});
}
use of net.iGap.structs.AttachmentObject in project iGap-Android by KianIranian-STDG.
the class StoryDisplayFragment method updateStory.
private void updateStory() {
storyDisplayImage.setVisibility(View.VISIBLE);
storyProgress.setVisibility(View.VISIBLE);
storyVideoProgress.setVisibility(View.GONE);
if (stories.get(counter).getTxt() == null || stories.get(counter).getTxt().trim().equals("") || stories.get(counter).getTxt().trim().isEmpty()) {
captionRootView.setVisibility(View.GONE);
} else if (stories.get(counter).getTxt() != null) {
captionRootView.setVisibility(View.VISIBLE);
if (stories.get(counter).getTxt().length() >= 100) {
captionRootView.setTextSize(20);
} else if (stories.get(counter).getTxt().length() >= 17) {
captionRootView.setTextSize(28);
} else {
captionRootView.setTextSize(40);
}
captionRootView.setMovementMethod(ScrollingMovementMethod.getInstance());
captionRootView.setText(stories.get(counter).getTxt());
}
storyTime.setText(LastSeenTimeUtil.computeTime(context, stories.get(counter).getUserId(), stories.get(counter).getStoryData() / 1000L, false, false));
nickName.setText(stories.get(counter).getDisplayName());
if (stories.get(counter).isRoom()) {
chatIconTv.setVisibility(View.VISIBLE);
} else {
chatIconTv.setVisibility(View.GONE);
}
if (stories.get(counter).isVerified()) {
verifyIconTv.setVisibility(View.VISIBLE);
} else {
verifyIconTv.setVisibility(View.GONE);
}
replyTo.setText(EmojiManager.getInstance().replaceEmoji(storyUser.getUserName(), replyTo.getPaint().getFontMetricsInt()) + " \u25CF " + context.getString(R.string.moments_string));
replyCaption.setText(stories.get(counter).getTxt() != null ? stories.get(counter).getTxt() : "Photo");
AttachmentObject attachmentObject = stories.get(counter).getAttachment();
String path = attachmentObject.filePath != null ? attachmentObject.filePath : attachmentObject.thumbnailPath;
if (stories.get(counter).getStoryId() != 0 && !getMessageDataStorage().isStorySeen(stories.get(counter).getStoryId())) {
AbstractObject req = null;
IG_RPC.Story_Add_View story_add_view = new IG_RPC.Story_Add_View();
story_add_view.storyId = String.valueOf(stories.get(counter).getStoryId());
req = story_add_view;
getRequestManager().sendRequest(req, (response, error) -> {
if (error == null) {
IG_RPC.Res_Story_Add_View res = (IG_RPC.Res_Story_Add_View) response;
getMessageDataStorage().storySetSeen(res.storyId);
} else {
storyVideoProgress.setVisibility(View.GONE);
}
});
}
if (counter == (stories.size() - 1) && !getMessageDataStorage().isAllStorySeen(storyUser.getRoomId() == 0, storyUser.getRoomId() == 0 ? storyUser.getUserId() : storyUser.getRoomId())) {
getMessageDataStorage().storySetSeenAll(storyUser.getRoomId() == 0 ? storyUser.getUserId() : storyUser.getRoomId(), true, storyUser.getRoomId() == 0);
int storyUnSeenCount = getMessageDataStorage().getUnSeenStoryCount();
if (storyUnSeenCount > 0) {
G.onUnreadChange.onChange(storyUnSeenCount, true);
} else {
G.onUnreadChange.onChange(0, true);
}
EventManager.getInstance(AccountManager.selectedAccount).postEvent(EventManager.STORY_ALL_SEEN);
}
File file = new File(path != null ? path : "");
storyDisplayImage.setImageBitmap(null);
if (file.exists()) {
loadImage(path);
} else {
path = attachmentObject.thumbnailPath != null ? attachmentObject.thumbnailPath : "";
file = new File(path);
if (file.exists()) {
Story story = stories.get(counter);
if (story.getAttachment().filePath != null && (new File(story.getAttachment().filePath).exists())) {
return;
}
Bitmap bitmap = AndroidUtils.blurImage(BitmapFactory.decodeFile(path));
storyDisplayImage.setImageBitmap(bitmap);
} else {
ProtoFileDownload.FileDownload.Selector selector;
if (attachmentObject.largeThumbnail != null) {
selector = ProtoFileDownload.FileDownload.Selector.LARGE_THUMBNAIL;
path = AndroidUtils.getFilePathWithCashId(attachmentObject.smallThumbnail.cacheId, attachmentObject.name, G.context.getExternalFilesDir(Environment.DIRECTORY_PICTURES).getAbsolutePath(), true);
if (new File(path).exists()) {
Story story = stories.get(counter);
if (story.getAttachment().filePath != null && (new File(story.getAttachment().filePath).exists())) {
return;
}
Bitmap bitmap = AndroidUtils.blurImage(BitmapFactory.decodeFile(path));
storyDisplayImage.setImageBitmap(bitmap);
} else {
DownloadObject downloadObject = DownloadObject.createForThumb(attachmentObject, ProtoGlobal.RoomMessageType.STORY.getNumber(), false);
if (downloadObject != null) {
downloadObject.downloadId = stories.get(counter).getStoryId();
getDownloader().download(downloadObject, selector, arg -> {
if (arg.status == Status.SUCCESS) {
if (arg.data != null) {
String filePath = arg.data.getFilePath();
Story story = stories.get(counter);
if (story.getStoryId() == arg.data.getDownloadObject().downloadId) {
if (story.getAttachment().filePath != null && (new File(story.getAttachment().filePath).exists())) {
return;
}
Bitmap bitmap = AndroidUtils.blurImage(BitmapFactory.decodeFile(filePath));
G.runOnUiThread(() -> storyDisplayImage.setImageBitmap(bitmap));
}
}
}
});
}
}
} else if (attachmentObject.smallThumbnail != null) {
selector = ProtoFileDownload.FileDownload.Selector.SMALL_THUMBNAIL;
path = AndroidUtils.getFilePathWithCashId(attachmentObject.smallThumbnail.cacheId, attachmentObject.name, G.context.getExternalFilesDir(Environment.DIRECTORY_PICTURES).getAbsolutePath(), true);
if (new File(path).exists()) {
Story story = stories.get(counter);
if (story.getAttachment().filePath != null && (new File(story.getAttachment().filePath).exists())) {
return;
}
Bitmap bitmap = AndroidUtils.blurImage(BitmapFactory.decodeFile(path));
storyDisplayImage.setImageBitmap(bitmap);
} else {
DownloadObject downloadObject = DownloadObject.createForThumb(attachmentObject, ProtoGlobal.RoomMessageType.STORY.getNumber(), false);
if (downloadObject != null) {
downloadObject.downloadId = stories.get(counter).getStoryId();
getDownloader().download(downloadObject, selector, arg -> {
if (arg.status == Status.SUCCESS) {
if (arg.data != null) {
String filePath = arg.data.getFilePath();
Story story = stories.get(counter);
if (story.getStoryId() == arg.data.getDownloadObject().downloadId) {
if (story.getAttachment().filePath != null && (new File(story.getAttachment().filePath).exists())) {
return;
}
Bitmap bitmap = AndroidUtils.blurImage(BitmapFactory.decodeFile(filePath));
G.runOnUiThread(() -> storyDisplayImage.setImageBitmap(bitmap));
}
}
}
});
}
}
}
}
DownloadObject object = DownloadObject.createForStory(attachmentObject, stories.get(counter).getStoryId(), true);
if (object != null) {
ProtoFileDownload.FileDownload.Selector imageSelector = ProtoFileDownload.FileDownload.Selector.FILE;
Downloader.getInstance(AccountManager.selectedAccount).download(object, imageSelector, HttpRequest.PRIORITY.PRIORITY_HIGH, arg -> {
if (arg.status == Status.SUCCESS && arg.data != null) {
String filepath = arg.data.getFilePath();
long downloadId = arg.data.getDownloadObject().downloadId;
Story story = stories.get(counter);
if (downloadId == story.getStoryId()) {
story.getAttachment().filePath = filepath;
G.runOnUiThread(() -> loadImage(filepath));
}
}
});
}
}
}
use of net.iGap.structs.AttachmentObject 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.structs.AttachmentObject in project iGap-Android by KianIranian-STDG.
the class ShowMediaListener method getFilePath.
public String getFilePath(MessageObject messageObject) {
String result = "";
AttachmentObject at = messageObject.forwardedMessage != null ? messageObject.forwardedMessage.attachment : messageObject.attachment;
if (at != null) {
if (at.filePath != null)
result = at.filePath;
}
int messageType = messageObject.forwardedMessage != null ? messageObject.forwardedMessage.messageType : messageObject.messageType;
if (result.length() < 1) {
String mimeType = DownloadObject.extractMime(at.name);
String path = AndroidUtils.suitableAppFilePath(ProtoGlobal.RoomMessageType.forNumber(messageType));
result = new File(path + "/" + at.cacheId + "_" + mimeType).getAbsolutePath();
return result;
}
return result;
}
use of net.iGap.structs.AttachmentObject in project iGap-Android by KianIranian-STDG.
the class DownloadObject method createForStory.
public static DownloadObject createForStory(AttachmentObject attachment, long storyId, boolean big) {
if (attachment == null) {
return null;
}
final AttachmentObject thumbnail = big ? attachment.largeThumbnail : attachment.smallThumbnail;
if (thumbnail == null || thumbnail.cacheId == null) {
return null;
}
DownloadObject struct = new DownloadObject();
struct.selector = big ? FILE_VALUE : SMALL_THUMBNAIL_VALUE;
struct.key = createKey(String.valueOf(thumbnail.cacheId), struct.selector);
struct.mainCacheId = attachment.cacheId;
struct.fileToken = attachment.token;
struct.fileName = attachment.name;
struct.fileSize = attachment.largeThumbnail.size;
struct.mimeType = struct.extractMime(struct.fileName);
struct.priority = HttpRequest.PRIORITY.PRIORITY_MEDIUM;
struct.downloadId = storyId;
String filePath = null;
if (big) {
filePath = suitableAppFilePath(ProtoGlobal.RoomMessageType.STORY);
} else {
filePath = AndroidUtils.getFilePathWithCashId(attachment.cacheId, attachment.name, G.DIR_IMAGE_USER, true);
}
struct.destFile = new File(filePath + "/" + struct.mainCacheId + "_" + struct.mimeType);
struct.tempFile = new File(G.context.getCacheDir() + "/" + struct.key);
struct.messageType = ProtoGlobal.RoomMessageType.STORY;
if (struct.tempFile.exists()) {
struct.offset = struct.tempFile.length();
if (struct.offset > 0 && struct.fileSize > 0) {
struct.progress = (int) ((struct.offset * 100) / struct.fileSize);
}
}
return struct;
}
Aggregations