Search in sources :

Example 6 with AttachmentObject

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;
}
Also used : AttachmentObject(net.iGap.structs.AttachmentObject) File(java.io.File)

Example 7 with AttachmentObject

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();
        }
    }
}
Also used : AbstractMessage(net.iGap.adapter.items.chat.AbstractMessage) AttachmentObject(net.iGap.structs.AttachmentObject) MyLinearLayoutManager(net.iGap.module.MyLinearLayoutManager) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) SuppressLint(android.annotation.SuppressLint) IOException(java.io.IOException) JsonSyntaxException(com.google.gson.JsonSyntaxException)

Example 8 with AttachmentObject

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);
}
Also used : ThumbnailUtils(android.media.ThumbnailUtils) Bundle(android.os.Bundle) HelperNotification(net.iGap.helper.HelperNotification) StructBottomSheetForward(net.iGap.module.structs.StructBottomSheetForward) ProgressBar(android.widget.ProgressBar) NonNull(androidx.annotation.NonNull) FileLog(net.iGap.helper.FileLog) UploadObject(net.iGap.module.upload.UploadObject) IMAGE_VALUE(net.iGap.proto.ProtoGlobal.RoomMessageType.IMAGE_VALUE) ToolbarItem(net.iGap.messenger.ui.toolBar.ToolbarItem) AppCompatCheckBox(androidx.appcompat.widget.AppCompatCheckBox) NewChatItemHolder(net.iGap.adapter.items.chat.NewChatItemHolder) GroupChatRole(net.iGap.module.enums.GroupChatRole) HelperSetAction(net.iGap.helper.HelperSetAction) OnBotClick(net.iGap.observers.interfaces.OnBotClick) Handler(android.os.Handler) MediaStore(android.provider.MediaStore) Map(java.util.Map) OnChatSendMessageResponse(net.iGap.observers.interfaces.OnChatSendMessageResponse) ClipboardManager(android.content.ClipboardManager) CallActivity(net.iGap.activities.CallActivity) HelperError(net.iGap.helper.HelperError) DOWN(net.iGap.proto.ProtoClientGetRoomHistory.ClientGetRoomHistory.Direction.DOWN) GIF_TEXT(net.iGap.proto.ProtoGlobal.RoomMessageType.GIF_TEXT) RequestClientSubscribeToRoom(net.iGap.request.RequestClientSubscribeToRoom) ContextCompat(androidx.core.content.ContextCompat) HelperFragment(net.iGap.helper.HelperFragment) Log(android.util.Log) R.id.ac_ll_parent(net.iGap.R.id.ac_ll_parent) Realm(io.realm.Realm) HelperCalander(net.iGap.helper.HelperCalander) NumberTextView(net.iGap.messenger.ui.toolBar.NumberTextView) RealmObjectChangeListener(io.realm.RealmObjectChangeListener) RealmRoom(net.iGap.realm.RealmRoom) CHAT(net.iGap.proto.ProtoGlobal.Room.Type.CHAT) VIDEO(net.iGap.proto.ProtoGlobal.RoomMessageType.VIDEO) CHANNEL(net.iGap.proto.ProtoGlobal.Room.Type.CHANNEL) SoundPool(android.media.SoundPool) CountDownLatch(java.util.concurrent.CountDownLatch) RequestChatUpdateDraft(net.iGap.request.RequestChatUpdateDraft) OnHelperSetAction(net.iGap.observers.interfaces.OnHelperSetAction) AttachFile.getFilePathFromUri(net.iGap.module.AttachFile.getFilePathFromUri) CLIPBOARD_SERVICE(android.content.Context.CLIPBOARD_SERVICE) RequestChatGetRoom(net.iGap.request.RequestChatGetRoom) RealmCallConfig(net.iGap.realm.RealmCallConfig) SuggestedStickerAdapter(net.iGap.fragments.emoji.SuggestedStickerAdapter) ActivityMain(net.iGap.activities.ActivityMain) BottomSheetBehavior(com.google.android.material.bottomsheet.BottomSheetBehavior) HelperUrl(net.iGap.helper.HelperUrl) AccountManager(net.iGap.module.accountManager.AccountManager) ChatAttachmentPopup(net.iGap.module.dialog.ChatAttachmentPopup) RealmContacts(net.iGap.realm.RealmContacts) ParamWithInitBitmap(net.iGap.helper.avatar.ParamWithInitBitmap) Calendar(java.util.Calendar) WebSettings(android.webkit.WebSettings) ItemTouchHelper(androidx.recyclerview.widget.ItemTouchHelper) Toast(android.widget.Toast) ImageLoadingServiceInjector(net.iGap.module.imageLoaderService.ImageLoadingServiceInjector) IMAGE_TEXT(net.iGap.proto.ProtoGlobal.RoomMessageType.IMAGE_TEXT) AudioItem(net.iGap.adapter.items.chat.AudioItem) RealmRoomAccess(net.iGap.realm.RealmRoomAccess) MessageObject(net.iGap.structs.MessageObject) VideoWithTextItem(net.iGap.adapter.items.chat.VideoWithTextItem) G.twoPaneMode(net.iGap.G.twoPaneMode) AppCompatDelegate(androidx.appcompat.app.AppCompatDelegate) AttachFile.request_code_VIDEO_CAPTURED(net.iGap.module.AttachFile.request_code_VIDEO_CAPTURED) IOException(java.io.IOException) FragmentMediaContainer(net.iGap.messenger.ui.components.FragmentMediaContainer) IResendMessage(net.iGap.observers.interfaces.IResendMessage) EventEditText(net.iGap.module.customView.EventEditText) SharedPreferences(android.content.SharedPreferences) AUDIO_VALUE(net.iGap.proto.ProtoGlobal.RoomMessageType.AUDIO_VALUE) HelperMimeType(net.iGap.helper.HelperMimeType) RoomObject(net.iGap.helper.RoomObject) NotifyFrameLayout(net.iGap.libs.emojiKeyboard.NotifyFrameLayout) EditText(android.widget.EditText) FileListerDialog(net.iGap.module.FileListerDialog.FileListerDialog) RequestUserContactsBlock(net.iGap.request.RequestUserContactsBlock) ISendPosition(net.iGap.observers.interfaces.ISendPosition) BottomSheetDialog(com.google.android.material.bottomsheet.BottomSheetDialog) JsonObject(com.google.gson.JsonObject) LinearLayout(android.widget.LinearLayout) RequestClientUnsubscribeFromRoom(net.iGap.request.RequestClientUnsubscribeFromRoom) AppUtils(net.iGap.module.AppUtils) PackageManager(android.content.pm.PackageManager) WindowManager(android.view.WindowManager) StickerDialogFragment(net.iGap.fragments.emoji.add.StickerDialogFragment) Animator(android.animation.Animator) Theme(net.iGap.module.Theme) GIF_VALUE(net.iGap.proto.ProtoGlobal.RoomMessageType.GIF_VALUE) G(net.iGap.G) StatusTextFragment(net.iGap.story.StatusTextFragment) AccelerateDecelerateInterpolator(android.view.animation.AccelerateDecelerateInterpolator) RequestClientGetRoomHistory(net.iGap.request.RequestClientGetRoomHistory) IntentRequests(net.iGap.module.IntentRequests) RealmUserInfo(net.iGap.realm.RealmUserInfo) ACTION_STATE_SWIPE(androidx.recyclerview.widget.ItemTouchHelper.ACTION_STATE_SWIPE) ContentResolver(android.content.ContentResolver) UnreadMessage(net.iGap.adapter.items.chat.UnreadMessage) HelperPermission(net.iGap.helper.HelperPermission) IMessageItem(net.iGap.observers.interfaces.IMessageItem) Gson(com.google.gson.Gson) KeyboardView(net.iGap.libs.emojiKeyboard.KeyboardView) RecyclerView(androidx.recyclerview.widget.RecyclerView) RealmString(net.iGap.realm.RealmString) HelperImageBackColor(net.iGap.helper.HelperImageBackColor) VIDEO_VALUE(net.iGap.proto.ProtoGlobal.RoomMessageType.VIDEO_VALUE) ParamWithAvatarType(net.iGap.helper.avatar.ParamWithAvatarType) UP(net.iGap.proto.ProtoClientGetRoomHistory.ClientGetRoomHistory.Direction.UP) ProgressWaiting(net.iGap.adapter.items.chat.ProgressWaiting) VIDEO_TEXT(net.iGap.proto.ProtoGlobal.RoomMessageType.VIDEO_TEXT) MessageController(net.iGap.controllers.MessageController) Status(net.iGap.module.downloader.Status) ProtoChannelGetMessagesStats(net.iGap.proto.ProtoChannelGetMessagesStats) ItemBottomSheetForward(net.iGap.adapter.items.ItemBottomSheetForward) DisplayMetrics(android.util.DisplayMetrics) GIF_TEXT_VALUE(net.iGap.proto.ProtoGlobal.RoomMessageType.GIF_TEXT_VALUE) STORY_REPLY_VALUE(net.iGap.proto.ProtoGlobal.RoomMessageType.STORY_REPLY_VALUE) OnClientGetRoomMessage(net.iGap.observers.interfaces.OnClientGetRoomMessage) Disposable(io.reactivex.disposables.Disposable) RealmRegisteredInfo(net.iGap.realm.RealmRegisteredInfo) MusicPlayer(net.iGap.module.MusicPlayer) OnGetPermission(net.iGap.observers.interfaces.OnGetPermission) StickerRepository(net.iGap.repository.StickerRepository) ActivityTrimVideo(net.iGap.activities.ActivityTrimVideo) LocationManager(android.location.LocationManager) EditorInfo(android.view.inputmethod.EditorInfo) IOnBackPressed(net.iGap.observers.interfaces.IOnBackPressed) RealmRoomMessageLocation(net.iGap.realm.RealmRoomMessageLocation) AppCompatTextView(androidx.appcompat.widget.AppCompatTextView) ActivityManager(android.app.ActivityManager) GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) CallManager(net.iGap.viewmodel.controllers.CallManager) HelperGetMessageState(net.iGap.helper.HelperGetMessageState) OnVoiceRecord(net.iGap.observers.interfaces.OnVoiceRecord) RealmList(io.realm.RealmList) RequestClientGetFavoriteMenu(net.iGap.request.RequestClientGetFavoriteMenu) RealmRoomMessage.makeUnreadMessage(net.iGap.realm.RealmRoomMessage.makeUnreadMessage) TimeUtils(net.iGap.module.TimeUtils) AudioManager(android.media.AudioManager) InputMethodManager(android.view.inputmethod.InputMethodManager) FragmentActivity(androidx.fragment.app.FragmentActivity) AnimationUtils(android.view.animation.AnimationUtils) HelperCalander.convertToUnicodeFarsiNumber(net.iGap.helper.HelperCalander.convertToUnicodeFarsiNumber) RequestUserContactsUnblock(net.iGap.request.RequestUserContactsUnblock) MODE_PRIVATE(android.content.Context.MODE_PRIVATE) Build(android.os.Build) RequestUserInfo(net.iGap.request.RequestUserInfo) EmojiView(net.iGap.libs.emojiKeyboard.EmojiView) RequestChannelUpdateDraft(net.iGap.request.RequestChannelUpdateDraft) RealmAdditional(net.iGap.realm.RealmAdditional) JsonSyntaxException(com.google.gson.JsonSyntaxException) LayoutInflater(android.view.LayoutInflater) BadgeView(net.iGap.adapter.items.chat.BadgeView) RealmResults(io.realm.RealmResults) DialogAction(com.afollestad.materialdialogs.DialogAction) MaterialDesignTextView(net.iGap.module.MaterialDesignTextView) IDispatchTochEvent(net.iGap.observers.interfaces.IDispatchTochEvent) Color(android.graphics.Color) CountDownTimer(android.os.CountDownTimer) FileItem(net.iGap.adapter.items.chat.FileItem) StructMessageOption(net.iGap.module.structs.StructMessageOption) Bitmap(android.graphics.Bitmap) HelperSaveFile(net.iGap.helper.HelperSaveFile) STICKER_VALUE(net.iGap.proto.ProtoGlobal.RoomMessageType.STICKER_VALUE) ViewTreeObserver(android.view.ViewTreeObserver) VIDEO_TEXT_VALUE(net.iGap.proto.ProtoGlobal.RoomMessageType.VIDEO_TEXT_VALUE) VOICE_VALUE(net.iGap.proto.ProtoGlobal.RoomMessageType.VOICE_VALUE) R(net.iGap.R) OnConnectionChangeStateChat(net.iGap.observers.interfaces.OnConnectionChangeStateChat) ProtoClientGetRoomHistory(net.iGap.proto.ProtoClientGetRoomHistory) StickerItem(net.iGap.adapter.items.chat.StickerItem) SHOW(net.iGap.module.enums.ProgressState.SHOW) Vibrator(android.os.Vibrator) Activity(android.app.Activity) FastItemAdapter(com.mikepenz.fastadapter.commons.adapters.FastItemAdapter) Arrays(java.util.Arrays) MyLinearLayoutManager(net.iGap.module.MyLinearLayoutManager) RequestClientJoinByUsername(net.iGap.request.RequestClientJoinByUsername) VoiceRecord(net.iGap.module.VoiceRecord) ProtoFileDownload(net.iGap.proto.ProtoFileDownload) Uri(android.net.Uri) FrameLayout(android.widget.FrameLayout) ImageView(android.widget.ImageView) LastSeenTimeUtil(net.iGap.module.LastSeenTimeUtil) Drawable(android.graphics.drawable.Drawable) Manifest(android.Manifest) ProtoClientRoomReport(net.iGap.proto.ProtoClientRoomReport) AdditionalType(net.iGap.module.additionalData.AdditionalType) HelperPermission.showDeniedPermissionMessage(net.iGap.helper.HelperPermission.showDeniedPermissionMessage) Looper(android.os.Looper) DialogAnimation(net.iGap.module.DialogAnimation) Fragment(androidx.fragment.app.Fragment) OnSetAction(net.iGap.observers.interfaces.OnSetAction) Canvas(android.graphics.Canvas) ProgressState(net.iGap.module.enums.ProgressState) RealmConstants(net.iGap.realm.RealmConstants) CardView(androidx.cardview.widget.CardView) OnDeleteChatFinishActivity(net.iGap.observers.interfaces.OnDeleteChatFinishActivity) HelperTracker(net.iGap.helper.HelperTracker) RequestGroupUpdateDraft(net.iGap.request.RequestGroupUpdateDraft) OnLastSeenUpdateTiming(net.iGap.observers.interfaces.OnLastSeenUpdateTiming) OnComplete(net.iGap.observers.interfaces.OnComplete) RealmRoomDraft(net.iGap.realm.RealmRoomDraft) WALLET_VALUE(net.iGap.proto.ProtoGlobal.RoomMessageType.WALLET_VALUE) Set(java.util.Set) ChatSendMessageUtil(net.iGap.module.ChatSendMessageUtil) ChatMoreItem(net.iGap.model.ChatMoreItem) BotInit(net.iGap.module.BotInit) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) RealmGroupRoom(net.iGap.realm.RealmGroupRoom) Uploader(net.iGap.module.upload.Uploader) StringRes(androidx.annotation.StringRes) JsonArray(com.google.gson.JsonArray) FontIconTextView(net.iGap.module.FontIconTextView) Nullable(androidx.annotation.Nullable) BackDrawable(net.iGap.messenger.ui.toolBar.BackDrawable) HIDE(net.iGap.module.enums.ProgressState.HIDE) Tuple(net.iGap.libs.Tuple) OnGroupAvatarResponse(net.iGap.observers.interfaces.OnGroupAvatarResponse) SHP_SETTING(net.iGap.module.SHP_SETTING) Sort(io.realm.Sort) MyWebViewClient(net.iGap.libs.MyWebViewClient) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) VoiceItem(net.iGap.adapter.items.chat.VoiceItem) InputFilter(android.text.InputFilter) EventManager(net.iGap.observers.eventbus.EventManager) DownloadObject(net.iGap.module.downloader.DownloadObject) TextWatcher(android.text.TextWatcher) OnMessageReceive(net.iGap.observers.interfaces.OnMessageReceive) EmojiManager(net.iGap.libs.emojiKeyboard.emoji.EmojiManager) Config(net.iGap.Config) AttachmentObject(net.iGap.structs.AttachmentObject) StoryViewFragment(net.iGap.story.viewPager.StoryViewFragment) AttachFile.request_code_pic_audi(net.iGap.module.AttachFile.request_code_pic_audi) ImageSpan(android.text.style.ImageSpan) Environment(android.os.Environment) RequestClientGetRoomMessage(net.iGap.request.RequestClientGetRoomMessage) OnChatMessageRemove(net.iGap.observers.interfaces.OnChatMessageRemove) Editable(android.text.Editable) LOCATION_SERVICE(android.content.Context.LOCATION_SERVICE) ArrayList(java.util.ArrayList) VibrationEffect(android.os.VibrationEffect) LOCATION_VALUE(net.iGap.proto.ProtoGlobal.RoomMessageType.LOCATION_VALUE) RealmChannelExtra(net.iGap.realm.RealmChannelExtra) ConnectionState(net.iGap.module.enums.ConnectionState) HelperGetAction(net.iGap.helper.HelperGetAction) LayoutCreator(net.iGap.helper.LayoutCreator) IMAGE_TEXT_VALUE(net.iGap.proto.ProtoGlobal.RoomMessageType.IMAGE_TEXT_VALUE) WebChromeClient(android.webkit.WebChromeClient) Toolbar(net.iGap.messenger.ui.toolBar.Toolbar) LogWallet(net.iGap.adapter.items.chat.LogWallet) AvatarHandler(net.iGap.helper.avatar.AvatarHandler) RESULT_CANCELED(android.app.Activity.RESULT_CANCELED) StructWebView(net.iGap.module.structs.StructWebView) StickerSettingFragment(net.iGap.fragments.emoji.remove.StickerSettingFragment) AnimatedStickerItem(net.iGap.adapter.items.chat.AnimatedStickerItem) OnChatEditMessageResponse(net.iGap.observers.interfaces.OnChatEditMessageResponse) File(java.io.File) IItemAdapter(com.mikepenz.fastadapter.IItemAdapter) Gravity(android.view.Gravity) StructIGSticker(net.iGap.fragments.emoji.struct.StructIGSticker) Configuration(android.content.res.Configuration) LocationListener(net.iGap.observers.interfaces.LocationListener) LocationItem(net.iGap.adapter.items.chat.LocationItem) DbManager(net.iGap.module.accountManager.DbManager) CardToCardItem(net.iGap.adapter.items.chat.CardToCardItem) ValueAnimator(android.animation.ValueAnimator) FILE_TEXT_VALUE(net.iGap.proto.ProtoGlobal.RoomMessageType.FILE_TEXT_VALUE) ImageHelper(net.iGap.helper.ImageHelper) AttachFile.request_code_pic_file(net.iGap.module.AttachFile.request_code_pic_file) IMAGE(net.iGap.proto.ProtoGlobal.RoomMessageType.IMAGE) RealmRoomMessage.makeSeenAllMessageOfRoom(net.iGap.realm.RealmRoomMessage.makeSeenAllMessageOfRoom) AppCompatImageView(androidx.appcompat.widget.AppCompatImageView) ResendMessage(net.iGap.module.ResendMessage) AttachFile(net.iGap.module.AttachFile) LOG_VALUE(net.iGap.proto.ProtoGlobal.RoomMessageType.LOG_VALUE) LogWalletCardToCard(net.iGap.adapter.items.chat.LogWalletCardToCard) OnGetFavoriteMenu(net.iGap.observers.interfaces.OnGetFavoriteMenu) RealmChannelRoom(net.iGap.realm.RealmChannelRoom) AUDIO_TEXT_VALUE(net.iGap.proto.ProtoGlobal.RoomMessageType.AUDIO_TEXT_VALUE) ContactItem(net.iGap.adapter.items.chat.ContactItem) LISTENED_VALUE(net.iGap.proto.ProtoGlobal.RoomMessageStatus.LISTENED_VALUE) BottomSheetFragment(net.iGap.module.dialog.bottomsheet.BottomSheetFragment) View(android.view.View) Animation(android.view.animation.Animation) WebView(android.webkit.WebView) OnChatMessageSelectionChanged(net.iGap.observers.interfaces.OnChatMessageSelectionChanged) RealmRoomMessageContact(net.iGap.realm.RealmRoomMessageContact) StoryPagerFragment(net.iGap.story.StoryPagerFragment) ContactUtils(net.iGap.module.ContactUtils) ParentChatMoneyTransferFragment(net.iGap.fragments.chatMoneyTransfer.ParentChatMoneyTransferFragment) MessagesAdapter(net.iGap.adapter.MessagesAdapter) FILE_VALUE(net.iGap.proto.ProtoGlobal.RoomMessageType.FILE_VALUE) AdapterDrBot(net.iGap.adapter.AdapterDrBot) OnUpdateUserOrRoomInfo(net.iGap.observers.interfaces.OnUpdateUserOrRoomInfo) RequestClientRoomReport(net.iGap.request.RequestClientRoomReport) HelperGetDataFromOtherApp(net.iGap.helper.HelperGetDataFromOtherApp) ObjectAnimator(android.animation.ObjectAnimator) PassCode(net.iGap.model.PassCode) StructMessageInfo(net.iGap.module.structs.StructMessageInfo) InputType(android.text.InputType) StructIGStickerGroup(net.iGap.fragments.emoji.struct.StructIGStickerGroup) ViewStubCompat(androidx.appcompat.widget.ViewStubCompat) Additional(net.iGap.module.enums.Additional) TEXT_VALUE(net.iGap.proto.ProtoGlobal.RoomMessageType.TEXT_VALUE) LogWalletTopup(net.iGap.adapter.items.chat.LogWalletTopup) ViewGroup(android.view.ViewGroup) OnForwardBottomSheet(net.iGap.observers.interfaces.OnForwardBottomSheet) OnUserUpdateStatus(net.iGap.observers.interfaces.OnUserUpdateStatus) HelperLog(net.iGap.helper.HelperLog) OnChatSendMessage(net.iGap.observers.interfaces.OnChatSendMessage) List(java.util.List) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) TextView(android.widget.TextView) FragmentSettingAddStickers(net.iGap.fragments.emoji.add.FragmentSettingAddStickers) CONTACT_VALUE(net.iGap.proto.ProtoGlobal.RoomMessageType.CONTACT_VALUE) RequestQueue(net.iGap.request.RequestQueue) RelativeLayout(android.widget.RelativeLayout) TextItem(net.iGap.adapter.items.chat.TextItem) IUpdateLogItem(net.iGap.observers.interfaces.IUpdateLogItem) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) NotNull(org.jetbrains.annotations.NotNull) OpenBottomSheetItem(net.iGap.observers.interfaces.OpenBottomSheetItem) Context(android.content.Context) AndroidUtils(net.iGap.module.AndroidUtils) SEEN_VALUE(net.iGap.proto.ProtoGlobal.RoomMessageStatus.SEEN_VALUE) KeyEvent(android.view.KeyEvent) ResourcesCompat(androidx.core.content.res.ResourcesCompat) GifWithTextItem(net.iGap.adapter.items.chat.GifWithTextItem) RequestSignalingGetConfiguration(net.iGap.request.RequestSignalingGetConfiguration) OnChatDelete(net.iGap.observers.interfaces.OnChatDelete) Intent(android.content.Intent) HashMap(java.util.HashMap) RealmStickerItem(net.iGap.realm.RealmStickerItem) SUID(net.iGap.module.SUID) ClipData(android.content.ClipData) OnUserInfoResponse(net.iGap.observers.interfaces.OnUserInfoResponse) SuppressLint(android.annotation.SuppressLint) MotionEvent(android.view.MotionEvent) AnimatorSet(android.animation.AnimatorSet) TimeItem(net.iGap.adapter.items.chat.TimeItem) RealmRoomMessage(net.iGap.realm.RealmRoomMessage) Cursor(android.database.Cursor) LogWalletBill(net.iGap.adapter.items.chat.LogWalletBill) ACTIVITY_SERVICE(android.content.Context.ACTIVITY_SERVICE) CONTACT(net.iGap.proto.ProtoGlobal.RoomMessageType.CONTACT) ToolbarItems(net.iGap.messenger.ui.toolBar.ToolbarItems) FileWriter(java.io.FileWriter) ProtoResponse(net.iGap.proto.ProtoResponse) MessageLoader(net.iGap.module.MessageLoader) LogItem(net.iGap.adapter.items.chat.LogItem) HelperString(net.iGap.helper.HelperString) ViewMaker(net.iGap.adapter.items.chat.ViewMaker) StructBottomSheet(net.iGap.module.structs.StructBottomSheet) OnFileSelectedListener(net.iGap.module.FileListerDialog.OnFileSelectedListener) ProtoGlobal(net.iGap.proto.ProtoGlobal) ImageWithTextItem(net.iGap.adapter.items.chat.ImageWithTextItem) ChannelChatRole(net.iGap.module.enums.ChannelChatRole) GROUP(net.iGap.proto.ProtoGlobal.Room.Type.GROUP) Collections(java.util.Collections) MimeTypeMap(android.webkit.MimeTypeMap) AbstractMessage(net.iGap.adapter.items.chat.AbstractMessage) RealmAttachment(net.iGap.realm.RealmAttachment) RealmQuery(io.realm.RealmQuery) RealmList(io.realm.RealmList) ArrayList(java.util.ArrayList) ProtoGlobal(net.iGap.proto.ProtoGlobal) RealmString(net.iGap.realm.RealmString) RealmString(net.iGap.realm.RealmString) HelperString(net.iGap.helper.HelperString) ParamWithInitBitmap(net.iGap.helper.avatar.ParamWithInitBitmap) Bitmap(android.graphics.Bitmap) AttachmentObject(net.iGap.structs.AttachmentObject) RealmRoom(net.iGap.realm.RealmRoom) RealmChannelExtra(net.iGap.realm.RealmChannelExtra) StructMessageInfo(net.iGap.module.structs.StructMessageInfo) RealmRoomMessageContact(net.iGap.realm.RealmRoomMessageContact) ChatSendMessageUtil(net.iGap.module.ChatSendMessageUtil) ContactUtils(net.iGap.module.ContactUtils) RealmRoomMessage(net.iGap.realm.RealmRoomMessage) RealmAttachment(net.iGap.realm.RealmAttachment) HelperSaveFile(net.iGap.helper.HelperSaveFile) File(java.io.File) AttachFile(net.iGap.module.AttachFile) MessageObject(net.iGap.structs.MessageObject)

Example 9 with AttachmentObject

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);
    }
}
Also used : LinearLayout(android.widget.LinearLayout) NonNull(androidx.annotation.NonNull) UploadObject(net.iGap.module.upload.UploadObject) FrameLayout(android.widget.FrameLayout) LastSeenTimeUtil(net.iGap.module.LastSeenTimeUtil) Theme(net.iGap.module.Theme) G(net.iGap.G) HttpUploader(net.iGap.helper.upload.ApiBased.HttpUploader) RealmStoryProto(net.iGap.realm.RealmStoryProto) View(android.view.View) Canvas(android.graphics.Canvas) Log(android.util.Log) HelperImageBackColor(net.iGap.helper.HelperImageBackColor) MainStoryObject(net.iGap.story.MainStoryObject) ParamWithAvatarType(net.iGap.helper.avatar.ParamWithAvatarType) HelperCalander(net.iGap.helper.HelperCalander) MessageController(net.iGap.controllers.MessageController) Status(net.iGap.module.downloader.Status) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Downloader(net.iGap.module.downloader.Downloader) RealmStory(net.iGap.realm.RealmStory) Uploader(net.iGap.module.upload.Uploader) HelperLog(net.iGap.helper.HelperLog) FontIconTextView(net.iGap.module.FontIconTextView) List(java.util.List) TextView(android.widget.TextView) ProtoStoryUserAddNew(net.iGap.proto.ProtoStoryUserAddNew) ViewMaker.i_Dp(net.iGap.adapter.items.chat.ViewMaker.i_Dp) Paint(android.graphics.Paint) EventManager(net.iGap.observers.eventbus.EventManager) DownloadObject(net.iGap.module.downloader.DownloadObject) Context(android.content.Context) AttachmentObject(net.iGap.structs.AttachmentObject) ResourcesCompat(androidx.core.content.res.ResourcesCompat) ViewMaker.setTextSize(net.iGap.adapter.items.chat.ViewMaker.setTextSize) AccountManager(net.iGap.module.accountManager.AccountManager) StoryObject(net.iGap.story.StoryObject) ArrayList(java.util.ArrayList) LayoutCreator(net.iGap.helper.LayoutCreator) AvatarHandler(net.iGap.helper.avatar.AvatarHandler) ImageLoadingView(net.iGap.story.liststories.ImageLoadingView) MessageObject(net.iGap.structs.MessageObject) TextUtils(android.text.TextUtils) MaterialDesignTextView(net.iGap.module.MaterialDesignTextView) IconView(net.iGap.messenger.ui.components.IconView) CircleImageView(net.iGap.module.CircleImageView) File(java.io.File) Color(android.graphics.Color) Gravity(android.view.Gravity) Glide(com.bumptech.glide.Glide) TypedValue(android.util.TypedValue) ViewMaker(net.iGap.adapter.items.chat.ViewMaker) ProtoGlobal(net.iGap.proto.ProtoGlobal) MessageDataStorage(net.iGap.controllers.MessageDataStorage) R(net.iGap.R) DbManager(net.iGap.module.accountManager.DbManager) RealmStoryProto(net.iGap.realm.RealmStoryProto) AttachmentObject(net.iGap.structs.AttachmentObject) DownloadObject(net.iGap.module.downloader.DownloadObject) BitmapDrawable(android.graphics.drawable.BitmapDrawable) File(java.io.File)

Example 10 with AttachmentObject

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);
                        }
                }
            });
        }
    });
}
Also used : AttachmentObject(net.iGap.structs.AttachmentObject) DownloadObject(net.iGap.module.downloader.DownloadObject) OnProgress(net.iGap.messageprogress.OnProgress)

Aggregations

AttachmentObject (net.iGap.structs.AttachmentObject)13 File (java.io.File)7 DownloadObject (net.iGap.module.downloader.DownloadObject)7 TextView (android.widget.TextView)6 ProtoGlobal (net.iGap.proto.ProtoGlobal)6 View (android.view.View)5 LinearLayout (android.widget.LinearLayout)5 Context (android.content.Context)4 Color (android.graphics.Color)4 Gravity (android.view.Gravity)4 FrameLayout (android.widget.FrameLayout)4 NonNull (androidx.annotation.NonNull)4 ResourcesCompat (androidx.core.content.res.ResourcesCompat)4 List (java.util.List)4 G (net.iGap.G)4 R (net.iGap.R)4 HelperCalander (net.iGap.helper.HelperCalander)4 LayoutCreator (net.iGap.helper.LayoutCreator)4 AvatarHandler (net.iGap.helper.avatar.AvatarHandler)4 ParamWithAvatarType (net.iGap.helper.avatar.ParamWithAvatarType)4