use of net.iGap.structs.AttachmentObject in project iGap-Android by KianIranian-STDG.
the class DownloadObject method createForThumb.
public static DownloadObject createForThumb(AttachmentObject attachment, int messageType, boolean big) {
if (attachment == null) {
return null;
}
final AttachmentObject thumbnail = big ? attachment.largeThumbnail : attachment.smallThumbnail;
if (thumbnail == null || (thumbnail.cacheId == null || thumbnail.cacheId.isEmpty())) {
return null;
}
DownloadObject struct = new DownloadObject();
struct.selector = big ? LARGE_THUMBNAIL_VALUE : SMALL_THUMBNAIL_VALUE;
struct.key = createKey(thumbnail.cacheId, struct.selector);
struct.thumbCacheId = thumbnail.cacheId;
struct.mainCacheId = attachment.cacheId;
struct.fileToken = attachment.token;
struct.fileName = attachment.name;
struct.fileSize = big ? attachment.largeThumbnail.size : attachment.smallThumbnail.size;
struct.mimeType = struct.extractMime(struct.fileName);
struct.publicUrl = struct.getPublicUrl(attachment.publicUrl);
struct.priority = HttpRequest.PRIORITY.PRIORITY_HIGH;
String path = suitableAppFilePath(ProtoGlobal.RoomMessageType.forNumber(messageType));
struct.destFile = new File(path + "/" + struct.thumbCacheId + "_" + struct.mimeType);
struct.tempFile = new File(G.context.getCacheDir() + "/" + struct.key);
struct.messageType = ProtoGlobal.RoomMessageType.valueOf(messageType);
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;
}
use of net.iGap.structs.AttachmentObject in project iGap-Android by KianIranian-STDG.
the class FragmentChat method onDownloadAllEqualCashId.
@Override
public void onDownloadAllEqualCashId(String cashId, String messageID) {
// TODO: 12/28/20 MESSAGE_REFACTOR
int start = ((LinearLayoutManager) recyclerView.getLayoutManager()).findFirstVisibleItemPosition();
if (start < 0) {
start = 0;
}
for (int i = start; i < mAdapter.getItemCount() && i < start + 15; i++) {
try {
AbstractMessage item = mAdapter.getAdapterItem(i);
AttachmentObject attachmentObject = item.messageObject.forwardedMessage != null ? item.messageObject.forwardedMessage.attachment : item.messageObject.attachment;
if (attachmentObject != null) {
if (attachmentObject.cacheId != null && attachmentObject.cacheId.equals(cashId) && !(item.messageObject.id + "").equals(messageID)) {
mAdapter.notifyItemChanged(i);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
use of net.iGap.structs.AttachmentObject in project iGap-Android by KianIranian-STDG.
the class FragmentChat method sendMessage.
/**
* *************************** Messaging ***************************
*/
private void sendMessage(int requestCode, String filePath) {
String message;
if (getWrittenMessage().length() > Config.MAX_TEXT_ATTACHMENT_LENGTH)
message = getWrittenMessage().substring(0, Config.MAX_TEXT_ATTACHMENT_LENGTH);
else
message = getWrittenMessage();
String mainMessage = getWrittenMessage();
if (filePath == null || (filePath.length() == 0 && requestCode != AttachFile.request_code_contact_phone)) {
clearReplyView();
return;
}
showPopup(-1);
if (isShowLayoutUnreadMessage) {
removeLayoutUnreadMessage();
}
long messageId = AppUtils.makeRandomId();
final long updateTime = TimeUtils.currentLocalTime();
ProtoGlobal.RoomMessageType messageType = null;
String fileName;
long duration = 0;
long fileSize;
int[] imageDimens = { 0, 0 };
final long senderID = AccountManager.getInstance().getCurrentUser().getId();
/**
* check if path is uri detect real path from uri
*/
String path = getFilePathFromUri(Uri.parse(filePath));
if (path != null) {
filePath = path;
}
if (requestCode == AttachFile.requestOpenGalleryForVideoMultipleSelect && filePath.toLowerCase().endsWith(".gif")) {
requestCode = AttachFile.requestOpenGalleryForImageMultipleSelect;
}
fileName = new File(filePath).getName();
fileSize = new File(filePath).length();
RealmRoomMessage roomMessage = new RealmRoomMessage();
StructMessageInfo structMessageInfoNew = new StructMessageInfo(roomMessage);
switch(requestCode) {
case IntentRequests.REQ_CROP:
case AttachFile.requestOpenGalleryForImageMultipleSelect:
if (!filePath.toLowerCase().endsWith(".gif")) {
if (isMessageWrote()) {
messageType = IMAGE_TEXT;
} else {
messageType = ProtoGlobal.RoomMessageType.IMAGE;
}
} else {
if (isMessageWrote()) {
messageType = GIF_TEXT;
} else {
messageType = ProtoGlobal.RoomMessageType.GIF;
}
}
imageDimens = AndroidUtils.getImageDimens(filePath);
break;
case AttachFile.request_code_TAKE_PICTURE:
if (AndroidUtils.getImageDimens(filePath)[0] == 0 && AndroidUtils.getImageDimens(filePath)[1] == 0) {
G.handler.post(new Runnable() {
@Override
public void run() {
Toast.makeText(context, "Picture Not Loaded", Toast.LENGTH_SHORT).show();
}
});
return;
}
imageDimens = AndroidUtils.getImageDimens(filePath);
if (isMessageWrote()) {
messageType = IMAGE_TEXT;
} else {
messageType = ProtoGlobal.RoomMessageType.IMAGE;
}
break;
case AttachFile.requestOpenGalleryForVideoMultipleSelect:
case request_code_VIDEO_CAPTURED:
// mainVideoPath
duration = AndroidUtils.getAudioDuration(G.fragmentActivity, filePath) / 1000;
if (isMessageWrote()) {
messageType = VIDEO_TEXT;
} else {
messageType = VIDEO;
}
break;
case AttachFile.request_code_pic_audi:
duration = AndroidUtils.getAudioDuration(G.fragmentActivity, filePath) / 1000;
if (isMessageWrote()) {
messageType = ProtoGlobal.RoomMessageType.AUDIO_TEXT;
} else {
messageType = ProtoGlobal.RoomMessageType.AUDIO;
}
String songArtist = AndroidUtils.getAudioArtistName(filePath);
long songDuration = AndroidUtils.getAudioDuration(G.fragmentActivity, filePath);
structMessageInfoNew.setSongArtist(songArtist);
structMessageInfoNew.setSongLength(songDuration);
break;
case AttachFile.request_code_pic_file:
case AttachFile.request_code_open_document:
if (isMessageWrote()) {
messageType = ProtoGlobal.RoomMessageType.FILE_TEXT;
} else {
messageType = ProtoGlobal.RoomMessageType.FILE;
}
break;
case AttachFile.request_code_contact_phone:
if (latestUri == null) {
break;
}
messageType = CONTACT;
ContactUtils contactUtils = new ContactUtils(G.fragmentActivity, latestUri);
String name = contactUtils.retrieveName();
String number = contactUtils.retrieveNumber();
structMessageInfoNew.setContactValues(name, "", number);
break;
case AttachFile.request_code_paint:
imageDimens = AndroidUtils.getImageDimens(filePath);
if (isMessageWrote()) {
messageType = IMAGE_TEXT;
} else {
messageType = ProtoGlobal.RoomMessageType.IMAGE;
}
break;
}
final ProtoGlobal.RoomMessageType finalMessageType = messageType;
final String finalFilePath = filePath;
final String finalFileName = fileName;
final long finalDuration = duration;
final long finalFileSize = fileSize;
final int[] finalImageDimens = imageDimens;
roomMessage.setMessageId(messageId);
roomMessage.setMessageType(finalMessageType);
roomMessage.setMessage(message);
DbManager.getInstance().doRealmTask(realm -> {
RealmRoomMessage.addTimeIfNeed(roomMessage, realm);
});
RealmRoomMessage.isEmojiInText(roomMessage, message);
roomMessage.setStatus(ProtoGlobal.RoomMessageStatus.SENDING.toString());
roomMessage.setRoomId(mRoomId);
RealmAttachment realmAttachment = new RealmAttachment();
realmAttachment.setId(messageId);
realmAttachment.setLocalFilePath(finalFilePath);
realmAttachment.setWidth(finalImageDimens[0]);
realmAttachment.setHeight(finalImageDimens[1]);
realmAttachment.setSize(finalFileSize);
realmAttachment.setName(finalFileName);
realmAttachment.setDuration(finalDuration);
if (messageType != CONTACT) {
roomMessage.setAttachment(realmAttachment);
}
roomMessage.setUserId(senderID);
roomMessage.setAuthorHash(RealmUserInfo.getCurrentUserAuthorHash());
roomMessage.setShowMessage(true);
roomMessage.setCreateTime(updateTime);
if (isReply()) {
MessageObject replyLayoutObject = (MessageObject) mReplayLayout.getTag();
RealmRoomMessage replyMessage = new RealmRoomMessage();
replyMessage.setUserId(replyLayoutObject.userId);
replyMessage.setUpdateTime(replyLayoutObject.updateTime);
replyMessage.setStatusVersion(replyLayoutObject.statusVersion);
replyMessage.setShowTime(replyLayoutObject.needToShow);
replyMessage.setRoomId(replyLayoutObject.roomId);
replyMessage.setPreviousMessageId(replyLayoutObject.previousMessageId);
replyMessage.setFutureMessageId(replyLayoutObject.futureMessageId);
replyMessage.setMessageId(replyLayoutObject.id);
replyMessage.setEdited(replyLayoutObject.edited);
replyMessage.setDeleted(replyLayoutObject.deleted);
replyMessage.setCreateTime(replyLayoutObject.createTime);
replyMessage.setMessage(replyLayoutObject.message);
replyMessage.setMessageType(ProtoGlobal.RoomMessageType.forNumber(replyLayoutObject.messageType));
replyMessage.setStatus(ProtoGlobal.RoomMessageStatus.forNumber(replyLayoutObject.status).toString());
if (replyLayoutObject.getAttachment() != null) {
AttachmentObject attachmentObject = replyLayoutObject.getAttachment();
RealmAttachment replyToAttachment = new RealmAttachment();
replyToAttachment.setId(replyLayoutObject.id);
replyToAttachment.setLocalFilePath(attachmentObject.filePath);
replyToAttachment.setWidth(attachmentObject.width);
replyToAttachment.setHeight(attachmentObject.height);
replyToAttachment.setSize(attachmentObject.size);
replyToAttachment.setName(attachmentObject.name);
replyToAttachment.setDuration(attachmentObject.duration);
replyMessage.setAttachment(replyToAttachment);
}
// TODO: 1/13/21 MESSAGE_REFACTOR
roomMessage.setReplyTo(replyMessage);
}
long replyMessageId = 0;
if (roomMessage.getReplyTo() != null) {
if (roomMessage.getReplyTo().getMessageId() < 0) {
replyMessageId = roomMessage.getReplyTo().getMessageId() * (-1);
} else {
replyMessageId = roomMessage.getReplyTo().getMessageId();
}
}
if (chatType == CHANNEL) {
RealmChannelExtra realmChannelExtra = new RealmChannelExtra();
realmChannelExtra.setMessageId(messageId);
if (RealmRoom.showSignature(mRoomId)) {
realmChannelExtra.setSignature(AccountManager.getInstance().getCurrentUser().getName());
} else {
realmChannelExtra.setSignature("");
}
realmChannelExtra.setThumbsUp("0");
realmChannelExtra.setThumbsDown("0");
realmChannelExtra.setViewsLabel("1");
roomMessage.setChannelExtra(realmChannelExtra);
}
if (finalMessageType == CONTACT) {
if (latestUri != null) {
ContactUtils contactUtils = new ContactUtils(G.fragmentActivity, latestUri);
String name = contactUtils.retrieveName();
String number = contactUtils.retrieveNumber();
RealmRoomMessageContact realmRoomMessageContact = new RealmRoomMessageContact();
realmRoomMessageContact.setId(AppUtils.makeRandomId());
realmRoomMessageContact.setFirstName(name);
realmRoomMessageContact.setLastName("");
RealmList<RealmString> listString = new RealmList<>();
RealmString phoneRealmStr = new RealmString();
phoneRealmStr.setString(number);
listString.add(phoneRealmStr);
realmRoomMessageContact.setPhones(listString);
roomMessage.setRoomMessageContact(realmRoomMessageContact);
}
}
String makeThumbnailFilePath = "";
if (finalMessageType == VIDEO || finalMessageType == VIDEO_TEXT) {
// mainVideoPath
makeThumbnailFilePath = finalFilePath;
}
if (finalMessageType == VIDEO || finalMessageType == VIDEO_TEXT) {
Bitmap bitmap = ThumbnailUtils.createVideoThumbnail(makeThumbnailFilePath, MediaStore.Video.Thumbnails.MINI_KIND);
if (bitmap != null) {
roomMessage.getAttachment().setLocalThumbnailPath(AndroidUtils.saveBitmap(bitmap));
roomMessage.getAttachment().setWidth(bitmap.getWidth());
roomMessage.getAttachment().setHeight(bitmap.getHeight());
}
}
new Thread(() -> {
DbManager.getInstance().doRealmTransaction(realm1 -> {
RealmRoom room = realm1.where(RealmRoom.class).equalTo("id", mRoomId).findFirst();
if (room != null) {
room.setDeleted(false);
}
RealmRoom.setLastMessageWithRoomMessage(realm1, roomMessage.getRoomId(), realm1.copyToRealmOrUpdate(roomMessage));
});
}).start();
if (finalMessageType == CONTACT) {
ChatSendMessageUtil messageUtil = getSendMessageUtil().newBuilder(chatType, finalMessageType, mRoomId).message(message);
messageUtil.contact(structMessageInfoNew.realmRoomMessage.getRoomMessageContact().getFirstName(), structMessageInfoNew.realmRoomMessage.getRoomMessageContact().getLastName(), structMessageInfoNew.realmRoomMessage.getRoomMessageContact().getPhones().first().getString());
if (isReply()) {
messageUtil.replyMessage(replyMessageId);
}
messageUtil.sendMessage(Long.toString(messageId));
}
if (isReply()) {
mReplayLayout.setTag(null);
G.handler.post(new Runnable() {
@Override
public void run() {
mReplayLayout.setVisibility(View.GONE);
}
});
}
G.handler.post(new Runnable() {
@Override
public void run() {
switchAddItem(new ArrayList<>(Collections.singletonList(structMessageInfoNew)), false);
if (mainMessage.length() > message.length()) {
sendNewMessage(mainMessage.substring(message.length()));
}
}
});
G.handler.postDelayed(new Runnable() {
@Override
public void run() {
scrollToEnd();
}
}, 100);
}
use of net.iGap.structs.AttachmentObject 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.structs.AttachmentObject in project iGap-Android by KianIranian-STDG.
the class FragmentMediaPlayer method startDownload.
private void startDownload(final int position, final MessageProgress messageProgress) {
messageProgress.withDrawable(R.drawable.ic_cancel, true);
final AttachmentObject at = MusicPlayer.mediaList.get(position).forwardedMessage != null ? MusicPlayer.mediaList.get(position).forwardedMessage.attachment : MusicPlayer.mediaList.get(position).attachment;
int messageType = MusicPlayer.mediaList.get(position).forwardedMessage != null ? MusicPlayer.mediaList.get(position).forwardedMessage.messageType : MusicPlayer.mediaList.get(position).messageType;
String dirPath = AndroidUtils.getFilePathWithCashId(at.cacheId, at.name, messageType);
messageProgress.withOnProgress(new OnProgress() {
@Override
public void onProgressFinished() {
G.handler.post(new Runnable() {
@Override
public void run() {
if (messageProgress.getTag() != null && messageProgress.getTag().equals(MusicPlayer.mediaList.get(position).id)) {
messageProgress.withProgress(0);
messageProgress.setVisibility(View.GONE);
updateViewAfterDownload(at.cacheId);
}
}
});
}
});
DownloadObject fileObject = DownloadObject.createForRoomMessage(MusicPlayer.mediaList.get(position));
if (fileObject == null) {
return;
}
getDownloader().download(fileObject, ProtoFileDownload.FileDownload.Selector.FILE, HttpRequest.PRIORITY.PRIORITY_HIGH, arg -> {
if (canUpdateAfterDownload) {
G.handler.post(() -> {
switch(arg.status) {
case SUCCESS:
case LOADING:
if (arg.data == null)
return;
if (messageProgress.getTag() != null && messageProgress.getTag().equals(MusicPlayer.mediaList.get(position).id)) {
messageProgress.withProgress(arg.data.getProgress());
}
break;
case ERROR:
if (messageProgress.getTag() != null && messageProgress.getTag().equals(MusicPlayer.mediaList.get(position).id)) {
messageProgress.withProgress(0);
messageProgress.withDrawable(R.drawable.ic_download, true);
}
}
});
}
});
}
Aggregations