use of net.iGap.module.downloader.DownloadObject in project iGap-Android by KianIranian-STDG.
the class AdapterChatBackground method onBindViewHolder.
@Override
public void onBindViewHolder(@NotNull RecyclerView.ViewHolder holder, int position) {
if (holder instanceof ViewHolderImage) {
if (position == 0) {
((ViewHolderImage) holder).messageProgress.setVisibility(View.GONE);
((ViewHolderImage) holder).imageView.setImageResource(R.drawable.add_chat_background_setting);
} else {
((ViewHolderImage) holder).messageProgress.setVisibility(View.VISIBLE);
((ViewHolderImage) holder).imageView.setImageDrawable(null);
StructWallpaper wallpaper = mList.get(position - 1);
String path = "";
if (wallpaper.getWallpaperType() == FragmentChatBackground.WallpaperType.proto) {
RealmAttachment pf = wallpaper.getProtoWallpaper().getFile();
// final String path = G.context.getExternalFilesDir(Environment.DIRECTORY_PICTURES) + "/" + pf.getCacheId() + "_" + pf.getName();
path = pf.getLocalFilePath() != null ? pf.getLocalFilePath() : "";
File file = new File(path);
if (file.exists()) {
G.imageLoader.displayImage(AndroidUtils.suitablePath(path), ((ViewHolderImage) holder).imageView);
} else {
path = pf.getLocalThumbnailPath() != null ? pf.getLocalThumbnailPath() : "";
file = new File(path);
if (file.exists()) {
G.imageLoader.displayImage(AndroidUtils.suitablePath(path), ((ViewHolderImage) holder).imageView);
} else {
DownloadObject downloadObject = DownloadObject.createForRoomMessage(AttachmentObject.create(pf), ProtoGlobal.RoomMessageType.IMAGE.getNumber());
Downloader.getInstance(AccountManager.selectedAccount).download(downloadObject, arg -> {
if (arg.status == Status.SUCCESS && arg.data != null) {
String filepath = arg.data.getFilePath();
String fileToken = arg.data.getToken();
if (!(new File(filepath).exists())) {
HelperLog.getInstance().setErrorLog(new Exception("File Dont Exist After Download !!" + filepath));
}
DbManager.getInstance().doRealmTransaction(realm -> {
for (RealmAvatar realmAvatar1 : realm.where(RealmAvatar.class).equalTo("file.token", fileToken).findAll()) {
realmAvatar1.getFile().setLocalFilePath(filepath);
}
});
G.runOnUiThread(() -> G.handler.post(() -> {
if (((ViewHolderImage) holder).imageView != null) {
G.imageLoader.displayImage(AndroidUtils.suitablePath(filepath), ((ViewHolderImage) holder).imageView);
}
}));
}
});
}
}
} else {
G.imageLoader.displayImage(AndroidUtils.suitablePath(wallpaper.getPath()), ((ViewHolderImage) holder).imageView);
}
String bigImagePath;
bigImagePath = path;
if (new File(bigImagePath).exists()) {
((ViewHolderImage) holder).messageProgress.setVisibility(View.GONE);
} else {
((ViewHolderImage) holder).messageProgress.setVisibility(View.VISIBLE);
startDownload(position - 1, ((ViewHolderImage) holder).messageProgress);
}
}
holder.itemView.setOnClickListener(v -> {
if (position == 0) {
onImageClick.onAddImageClick();
} else {
onImageClick.onClick(type, holder.getAdapterPosition() - 1);
}
});
} else if (holder instanceof ViewHolderSolid) {
((ViewHolderSolid) holder).cardView.setCardBackgroundColor(Color.parseColor(solidColorList.get(position)));
holder.itemView.setOnClickListener(v -> onImageClick.onClick(type, holder.getAdapterPosition()));
}
}
use of net.iGap.module.downloader.DownloadObject 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.module.downloader.DownloadObject 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.module.downloader.DownloadObject in project iGap-Android by KianIranian-STDG.
the class FragmentChat method saveSelectedMessageToDownload.
private void saveSelectedMessageToDownload(MessageObject messageObject, int pos) {
String filename;
String filepath;
int messageType;
if (messageObject.forwardedMessage != null) {
filename = messageObject.forwardedMessage.getAttachment().name;
filepath = messageObject.forwardedMessage.getAttachment().filePath != null ? messageObject.forwardedMessage.getAttachment().filePath : AndroidUtils.getFilePathWithCashId(messageObject.forwardedMessage.getAttachment().cacheId, filename, messageObject.forwardedMessage.messageType);
} else {
filename = messageObject.getAttachment().name;
filepath = messageObject.getAttachment().filePath != null ? messageObject.getAttachment().filePath : AndroidUtils.getFilePathWithCashId(messageObject.getAttachment().cacheId, filename, messageObject.messageType);
}
if (new File(filepath).exists()) {
getStoragePermission(filepath, filename);
} else {
final int _messageType = messageObject.forwardedMessage != null ? messageObject.forwardedMessage.messageType : messageObject.messageType;
String cacheId = messageObject.forwardedMessage != null ? messageObject.forwardedMessage.getAttachment().cacheId : messageObject.getAttachment().cacheId;
final String name = messageObject.forwardedMessage != null ? messageObject.forwardedMessage.getAttachment().name : messageObject.getAttachment().name;
String fileToken = messageObject.forwardedMessage != null ? messageObject.forwardedMessage.getAttachment().token : messageObject.getAttachment().token;
String fileUrl = messageObject.forwardedMessage != null ? messageObject.forwardedMessage.getAttachment().publicUrl : messageObject.getAttachment().publicUrl;
Long size = messageObject.forwardedMessage != null ? messageObject.forwardedMessage.getAttachment().size : messageObject.getAttachment().size;
if (cacheId == null) {
return;
}
final String _path = AndroidUtils.getFilePathWithCashId(cacheId, name, _messageType);
// TODO: 1/6/21 MESSAGE_REFACTOR
DownloadObject fileObject = DownloadObject.createForRoomMessage(messageObject);
if (fileObject != null) {
getDownloader().download(fileObject, arg -> {
if (arg.data != null && arg.data.getProgress() == 100) {
if (canUpdateAfterDownload) {
G.handler.post(() -> {
getStoragePermission(_path, name);
});
}
}
});
}
onDownloadAllEqualCashId(cacheId, messageObject.id + "");
mAdapter.notifyItemChanged(pos);
}
}
use of net.iGap.module.downloader.DownloadObject in project iGap-Android by KianIranian-STDG.
the class FragmentChat method saveSelectedMessageToMusic.
private void saveSelectedMessageToMusic(MessageObject message, int pos) {
String filename;
String filepath;
if (message.forwardedMessage != null) {
filename = message.forwardedMessage.getAttachment().name;
filepath = message.forwardedMessage.getAttachment().filePath != null ? message.forwardedMessage.getAttachment().filePath : AndroidUtils.getFilePathWithCashId(message.forwardedMessage.getAttachment().cacheId, filename, message.forwardedMessage.messageType);
} else {
filename = message.getAttachment().name;
filepath = message.getAttachment().filePath != null ? message.getAttachment().filePath : AndroidUtils.getFilePathWithCashId(message.getAttachment().cacheId, message.getAttachment().name, message.messageType);
}
if (new File(filepath).exists()) {
HelperSaveFile.saveFileToDownLoadFolder(filepath, filename, HelperSaveFile.FolderType.music);
} else {
final int _messageType = message.forwardedMessage != null ? message.forwardedMessage.messageType : message.messageType;
String cacheId = message.forwardedMessage != null ? message.forwardedMessage.getAttachment().cacheId : message.getAttachment().cacheId;
final String name = message.forwardedMessage != null ? message.forwardedMessage.getAttachment().name : message.getAttachment().name;
String fileToken = message.forwardedMessage != null ? message.forwardedMessage.getAttachment().token : message.getAttachment().token;
String fileUrl = message.forwardedMessage != null ? message.forwardedMessage.getAttachment().publicUrl : message.getAttachment().publicUrl;
Long size = message.forwardedMessage != null ? message.forwardedMessage.getAttachment().size : message.getAttachment().size;
if (cacheId == null) {
return;
}
ProtoFileDownload.FileDownload.Selector selector = ProtoFileDownload.FileDownload.Selector.FILE;
final String _path = AndroidUtils.getFilePathWithCashId(cacheId, name, _messageType);
// TODO: 1/6/21 MESSAGE_REFACTOR
DownloadObject fileObject = DownloadObject.createForRoomMessage(message);
if (fileObject != null) {
getDownloader().download(fileObject, selector, arg -> {
if (canUpdateAfterDownload) {
G.handler.post(() -> {
if (arg.status == Status.SUCCESS || arg.status == Status.LOADING) {
if (arg.data != null && arg.data.getProgress() == 100) {
HelperSaveFile.saveFileToDownLoadFolder(_path, name, HelperSaveFile.FolderType.music);
}
}
});
}
});
}
onDownloadAllEqualCashId(cacheId, message.id + "");
mAdapter.notifyItemChanged(pos);
}
}
Aggregations