use of net.iGap.messageprogress.OnProgress in project iGap-Android by KianIranian-STDG.
the class AbstractMessage method prepareAttachmentIfNeeded.
private void prepareAttachmentIfNeeded(final VH holder, final int messageType) {
/**
* runs if message has attachment
*/
NewChatItemHolder mHolder;
if (holder instanceof NewChatItemHolder)
mHolder = (NewChatItemHolder) holder;
else
return;
if (attachment != null) {
if (mHolder instanceof VideoWithTextItem.ViewHolder || mHolder instanceof ImageWithTextItem.ViewHolder) {
ReserveSpaceRoundedImageView imageViewReservedSpace = (ReserveSpaceRoundedImageView) ((IThumbNailItem) holder).getThumbNailImageView();
int _with = attachment.width;
int _hight = attachment.height;
if (_with == 0) {
if (attachment.smallThumbnail != null) {
_with = attachment.smallThumbnail.width;
_hight = attachment.smallThumbnail.height;
}
}
boolean setDefualtImage = false;
if (messageType == ProtoGlobal.RoomMessageType.IMAGE_VALUE || messageType == IMAGE_TEXT_VALUE) {
if (attachment.filePath == null && attachment.thumbnailPath == null && _with == 0) {
_with = (int) G.context.getResources().getDimension(R.dimen.dp120);
_hight = (int) G.context.getResources().getDimension(R.dimen.dp120);
setDefualtImage = true;
}
} else {
if (attachment.thumbnailPath == null && _with == 0) {
_with = (int) G.context.getResources().getDimension(R.dimen.dp120);
_hight = (int) G.context.getResources().getDimension(R.dimen.dp120);
setDefualtImage = true;
}
}
int[] dimens = imageViewReservedSpace.reserveSpace(_with, _hight, type);
if (dimens[0] != 0 && dimens[1] != 0) {
mHolder.getContentBloke().getLayoutParams().width = dimens[0];
}
if (setDefualtImage) {
imageViewReservedSpace.setImageResource(R.mipmap.difaultimage);
}
if (holder instanceof VideoWithTextItem.ViewHolder) {
((VideoWithTextItem.ViewHolder) holder).getMoreButton().setOnClickListener(v -> {
OnClickRow(((VideoWithTextItem.ViewHolder) holder), v);
});
}
if (holder instanceof ImageWithTextItem.ViewHolder) {
((ImageWithTextItem.ViewHolder) holder).getMoreButton().setOnClickListener(v -> {
OnClickRow(((ImageWithTextItem.ViewHolder) holder), v);
});
}
} else if (messageType == ProtoGlobal.RoomMessageType.GIF_VALUE || messageType == GIF_TEXT_VALUE) {
ReserveSpaceGifImageView imageViewReservedSpace = (ReserveSpaceGifImageView) ((IThumbNailItem) holder).getThumbNailImageView();
int _with = attachment.width;
int _hight = attachment.height;
if (_with == 0) {
_with = (int) G.context.getResources().getDimension(R.dimen.dp200);
}
if (_hight == 0) {
_hight = (int) G.context.getResources().getDimension(R.dimen.dp200);
}
int[] dimens = imageViewReservedSpace.reserveSpace(_with, _hight, type);
mHolder.getContentBloke().getLayoutParams().width = dimens[0];
}
String filePath = null;
if (attachment.filePath != null) {
filePath = attachment.filePath;
if (!new File(filePath).exists()) {
attachment.filePath = filePath = AndroidUtils.getFilePathWithCashId(attachment.cacheId, attachment.name, messageObject.messageType);
}
} else if (messageObject.isFileExistWithCacheId(false)) {
filePath = messageObject.getCacheFile(false);
}
if (attachment.isFileExistsOnLocalAndIsImage(messageObject)) {
onLoadThumbnailFromLocal(holder, getCacheId(messageObject), filePath, LocalFileType.FILE);
} else if (messageType == ProtoGlobal.RoomMessageType.VOICE_VALUE || messageType == ProtoGlobal.RoomMessageType.AUDIO_VALUE || messageType == AUDIO_TEXT_VALUE) {
onLoadThumbnailFromLocal(holder, getCacheId(messageObject), filePath, LocalFileType.FILE);
} else {
if (attachment.isThumbnailExistsOnLocal(messageObject)) {
String thumbPath = attachment.thumbnailPath != null ? attachment.thumbnailPath : messageObject.getCacheFile(true);
onLoadThumbnailFromLocal(holder, getCacheId(messageObject), thumbPath, LocalFileType.THUMBNAIL);
} else {
if (messageType != ProtoGlobal.RoomMessageType.CONTACT_VALUE) {
if (mHolder instanceof StickerItem.ViewHolder || mHolder instanceof AnimatedStickerItem.ViewHolder) {
} else {
downLoadThumbnail(holder);
}
}
}
}
if (hasProgress(holder)) {
final MessageProgress _Progress = ((IProgress) holder).getProgress();
_Progress.setTag(messageObject.id);
_Progress.setVisibility(View.GONE);
if (mHolder instanceof StickerItem.ViewHolder || mHolder instanceof AnimatedStickerItem.ViewHolder)
return;
AppUtils.setProgresColor(_Progress.progressBar);
_Progress.withOnMessageProgress(new OnMessageProgressClick() {
@Override
public void onMessageProgressClick(MessageProgress progress) {
forOnCLick(holder);
}
});
if (!attachment.isFileExistsOnLocal(messageObject)) {
if (HelperCheckInternetConnection.currentConnectivityType == null) {
checkAutoDownload(holder, holder.itemView.getContext(), HelperCheckInternetConnection.ConnectivityType.WIFI);
checkAutoDownload(holder, holder.itemView.getContext(), HelperCheckInternetConnection.ConnectivityType.MOBILE);
} else {
checkAutoDownload(holder, holder.itemView.getContext(), HelperCheckInternetConnection.currentConnectivityType);
}
}
_Progress.withOnProgress(new OnProgress() {
@Override
public void onProgressFinished() {
onProgressFinish(holder, attachment, messageType);
}
});
prepareProgress(holder);
}
}
}
use of net.iGap.messageprogress.OnProgress 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);
}
}
});
}
});
}
use of net.iGap.messageprogress.OnProgress in project iGap-Android by KianIranian-STDG.
the class AdapterChatBackground method startDownload.
private void startDownload(final int position, final MessageProgress messageProgress) {
if (mList.get(position).getProtoWallpaper() != null) {
messageProgress.withDrawable(R.drawable.ic_cancel, true);
RealmAttachment pf = mList.get(position).getProtoWallpaper().getFile();
messageProgress.withOnProgress(new OnProgress() {
@Override
public void onProgressFinished() {
messageProgress.post(new Runnable() {
@Override
public void run() {
messageProgress.withProgress(0);
messageProgress.setVisibility(View.GONE);
notifyItemChanged(position);
}
});
}
});
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);
}
});
} else if (arg.status == Status.LOADING && arg.data != null) {
messageProgress.post(new Runnable() {
@Override
public void run() {
messageProgress.withProgress(arg.data.getProgress());
}
});
} else if (arg.status == Status.ERROR) {
messageProgress.post(new Runnable() {
@Override
public void run() {
messageProgress.withProgress(0);
messageProgress.withDrawable(R.drawable.ic_download, true);
}
});
}
});
}
}
Aggregations