Search in sources :

Example 1 with AttachmentObject

use of net.iGap.structs.AttachmentObject in project iGap-Android by KianIranian-STDG.

the class MessageDataStorage method createForwardMessage.

public void createForwardMessage(final long destinationRoomId, final long newMessageId, MessageObject sourceMessage, boolean isMessage, DatabaseDelegate databaseDelegate) {
    storageQueue.postRunnable(() -> {
        FileLog.i(TAG, "createForwardMessage: " + destinationRoomId + " " + newMessageId);
        try {
            final RealmRoomMessage[] forwardedMessage = new RealmRoomMessage[1];
            MessageObject messageObject = null;
            RealmRoomMessage copyMessage = null;
            database.beginTransaction();
            if (isMessage && sourceMessage.forwardedMessage == null) {
                forwardedMessage[0] = database.createObject(RealmRoomMessage.class, newMessageId);
                forwardedMessage[0].setCreateTime(TimeUtils.currentLocalTime());
                forwardedMessage[0].setRoomId(destinationRoomId);
                forwardedMessage[0].setStatus(ProtoGlobal.RoomMessageStatus.SENDING.toString());
                forwardedMessage[0].setMessageType(ProtoGlobal.RoomMessageType.forNumber(sourceMessage.messageType));
                forwardedMessage[0].setMessage(sourceMessage.message);
                if (sourceMessage.attachment != null) {
                    AttachmentObject attObject = sourceMessage.attachment;
                    LocalFileType type = attObject.filePath == null ? LocalFileType.THUMBNAIL : LocalFileType.FILE;
                    String filePath = attObject.filePath != null ? attObject.filePath : attObject.thumbnailPath;
                    forwardedMessage[0].setAttachment(newMessageId, filePath, attObject.width, attObject.height, attObject.size, attObject.name, attObject.duration, attObject.token, type);
                }
                if (sourceMessage.contact != null) {
                    RoomContactObject contactObject = sourceMessage.contact;
                    ProtoGlobal.RoomMessageContact.Builder builder = ProtoGlobal.RoomMessageContact.newBuilder();
                    builder.setPhone(0, contactObject.phones.get(0));
                    builder.setFirstName(contactObject.firstName);
                    builder.setLastName(contactObject.lastName);
                    builder.setEmail(0, contactObject.emails.get(0));
                    RealmRoomMessageContact roomMessageContact = RealmRoomMessageContact.put(database, builder.build());
                    forwardedMessage[0].setRoomMessageContact(roomMessageContact);
                }
                forwardedMessage[0].setUserId(AccountManager.getInstance().getCurrentUser().getId());
                database.copyToRealmOrUpdate(forwardedMessage[0]);
                copyMessage = database.copyFromRealm(forwardedMessage[0]);
            } else {
                RealmRoomMessage roomMessage = database.where(RealmRoomMessage.class).equalTo("messageId", sourceMessage.id).findFirst();
                if (roomMessage != null) {
                    forwardedMessage[0] = database.createObject(RealmRoomMessage.class, newMessageId);
                    if (roomMessage.getForwardMessage() != null) {
                        forwardedMessage[0].setForwardMessage(roomMessage.getForwardMessage());
                        forwardedMessage[0].setHasMessageLink(roomMessage.getForwardMessage().getHasMessageLink());
                    } else {
                        forwardedMessage[0].setForwardMessage(roomMessage);
                        forwardedMessage[0].setHasMessageLink(roomMessage.getHasMessageLink());
                    }
                    forwardedMessage[0].setCreateTime(TimeUtils.currentLocalTime());
                    forwardedMessage[0].setMessageType(ProtoGlobal.RoomMessageType.TEXT);
                    forwardedMessage[0].setRoomId(destinationRoomId);
                    forwardedMessage[0].setStatus(ProtoGlobal.RoomMessageStatus.SENDING.toString());
                    forwardedMessage[0].setUserId(AccountManager.getInstance().getCurrentUser().getId());
                    copyMessage = database.copyFromRealm(forwardedMessage[0]);
                }
            }
            messageObject = MessageObject.create(copyMessage);
            RealmRoomMessage realmSourceMessage = database.where(RealmRoomMessage.class).equalTo("messageId", sourceMessage.id).findFirst();
            assert realmSourceMessage != null;
            RealmRoomMessage copyOfSource = database.copyFromRealm(realmSourceMessage);
            database.commitTransaction();
            MessageObject finalMessageObject = messageObject;
            RealmRoomMessage finalCopyMessage = copyMessage;
            G.runOnUiThread(() -> {
                databaseDelegate.run(finalMessageObject, finalCopyMessage, copyOfSource.getRoomId(), copyOfSource.getMessageId());
            });
        } catch (Exception e) {
            FileLog.e(e);
        }
    });
}
Also used : LocalFileType(net.iGap.module.enums.LocalFileType) RealmRoomMessageContact(net.iGap.realm.RealmRoomMessageContact) AttachmentObject(net.iGap.structs.AttachmentObject) RoomContactObject(net.iGap.structs.RoomContactObject) RealmRoomMessage(net.iGap.realm.RealmRoomMessage) MessageObject(net.iGap.structs.MessageObject) RealmRoomMessageContact(net.iGap.realm.RealmRoomMessageContact)

Example 2 with AttachmentObject

use of net.iGap.structs.AttachmentObject in project iGap-Android by KianIranian-STDG.

the class StoryDisplayFragment method updateStory.

private void updateStory() {
    storyDisplayImage.setVisibility(View.VISIBLE);
    storyProgress.setVisibility(View.VISIBLE);
    storyVideoProgress.setVisibility(View.GONE);
    if (stories.get(counter).getTxt() == null || stories.get(counter).getTxt().trim().equals("") || stories.get(counter).getTxt().trim().isEmpty()) {
        captionRootView.setVisibility(View.GONE);
    } else if (stories.get(counter).getTxt() != null) {
        captionRootView.setVisibility(View.VISIBLE);
        if (stories.get(counter).getTxt().length() >= 100) {
            captionRootView.setTextSize(20);
        } else if (stories.get(counter).getTxt().length() >= 17) {
            captionRootView.setTextSize(28);
        } else {
            captionRootView.setTextSize(40);
        }
        captionRootView.setMovementMethod(ScrollingMovementMethod.getInstance());
        captionRootView.setText(stories.get(counter).getTxt());
    }
    storyTime.setText(LastSeenTimeUtil.computeTime(context, stories.get(counter).getUserId(), stories.get(counter).getStoryData() / 1000L, false, false));
    nickName.setText(stories.get(counter).getDisplayName());
    if (stories.get(counter).isRoom()) {
        chatIconTv.setVisibility(View.VISIBLE);
    } else {
        chatIconTv.setVisibility(View.GONE);
    }
    if (stories.get(counter).isVerified()) {
        verifyIconTv.setVisibility(View.VISIBLE);
    } else {
        verifyIconTv.setVisibility(View.GONE);
    }
    replyTo.setText(EmojiManager.getInstance().replaceEmoji(storyUser.getUserName(), replyTo.getPaint().getFontMetricsInt()) + " \u25CF " + context.getString(R.string.moments_string));
    replyCaption.setText(stories.get(counter).getTxt() != null ? stories.get(counter).getTxt() : "Photo");
    AttachmentObject attachmentObject = stories.get(counter).getAttachment();
    String path = attachmentObject.filePath != null ? attachmentObject.filePath : attachmentObject.thumbnailPath;
    if (stories.get(counter).getStoryId() != 0 && !getMessageDataStorage().isStorySeen(stories.get(counter).getStoryId())) {
        AbstractObject req = null;
        IG_RPC.Story_Add_View story_add_view = new IG_RPC.Story_Add_View();
        story_add_view.storyId = String.valueOf(stories.get(counter).getStoryId());
        req = story_add_view;
        getRequestManager().sendRequest(req, (response, error) -> {
            if (error == null) {
                IG_RPC.Res_Story_Add_View res = (IG_RPC.Res_Story_Add_View) response;
                getMessageDataStorage().storySetSeen(res.storyId);
            } else {
                storyVideoProgress.setVisibility(View.GONE);
            }
        });
    }
    if (counter == (stories.size() - 1) && !getMessageDataStorage().isAllStorySeen(storyUser.getRoomId() == 0, storyUser.getRoomId() == 0 ? storyUser.getUserId() : storyUser.getRoomId())) {
        getMessageDataStorage().storySetSeenAll(storyUser.getRoomId() == 0 ? storyUser.getUserId() : storyUser.getRoomId(), true, storyUser.getRoomId() == 0);
        int storyUnSeenCount = getMessageDataStorage().getUnSeenStoryCount();
        if (storyUnSeenCount > 0) {
            G.onUnreadChange.onChange(storyUnSeenCount, true);
        } else {
            G.onUnreadChange.onChange(0, true);
        }
        EventManager.getInstance(AccountManager.selectedAccount).postEvent(EventManager.STORY_ALL_SEEN);
    }
    File file = new File(path != null ? path : "");
    storyDisplayImage.setImageBitmap(null);
    if (file.exists()) {
        loadImage(path);
    } else {
        path = attachmentObject.thumbnailPath != null ? attachmentObject.thumbnailPath : "";
        file = new File(path);
        if (file.exists()) {
            Story story = stories.get(counter);
            if (story.getAttachment().filePath != null && (new File(story.getAttachment().filePath).exists())) {
                return;
            }
            Bitmap bitmap = AndroidUtils.blurImage(BitmapFactory.decodeFile(path));
            storyDisplayImage.setImageBitmap(bitmap);
        } else {
            ProtoFileDownload.FileDownload.Selector selector;
            if (attachmentObject.largeThumbnail != null) {
                selector = ProtoFileDownload.FileDownload.Selector.LARGE_THUMBNAIL;
                path = AndroidUtils.getFilePathWithCashId(attachmentObject.smallThumbnail.cacheId, attachmentObject.name, G.context.getExternalFilesDir(Environment.DIRECTORY_PICTURES).getAbsolutePath(), true);
                if (new File(path).exists()) {
                    Story story = stories.get(counter);
                    if (story.getAttachment().filePath != null && (new File(story.getAttachment().filePath).exists())) {
                        return;
                    }
                    Bitmap bitmap = AndroidUtils.blurImage(BitmapFactory.decodeFile(path));
                    storyDisplayImage.setImageBitmap(bitmap);
                } else {
                    DownloadObject downloadObject = DownloadObject.createForThumb(attachmentObject, ProtoGlobal.RoomMessageType.STORY.getNumber(), false);
                    if (downloadObject != null) {
                        downloadObject.downloadId = stories.get(counter).getStoryId();
                        getDownloader().download(downloadObject, selector, arg -> {
                            if (arg.status == Status.SUCCESS) {
                                if (arg.data != null) {
                                    String filePath = arg.data.getFilePath();
                                    Story story = stories.get(counter);
                                    if (story.getStoryId() == arg.data.getDownloadObject().downloadId) {
                                        if (story.getAttachment().filePath != null && (new File(story.getAttachment().filePath).exists())) {
                                            return;
                                        }
                                        Bitmap bitmap = AndroidUtils.blurImage(BitmapFactory.decodeFile(filePath));
                                        G.runOnUiThread(() -> storyDisplayImage.setImageBitmap(bitmap));
                                    }
                                }
                            }
                        });
                    }
                }
            } else if (attachmentObject.smallThumbnail != null) {
                selector = ProtoFileDownload.FileDownload.Selector.SMALL_THUMBNAIL;
                path = AndroidUtils.getFilePathWithCashId(attachmentObject.smallThumbnail.cacheId, attachmentObject.name, G.context.getExternalFilesDir(Environment.DIRECTORY_PICTURES).getAbsolutePath(), true);
                if (new File(path).exists()) {
                    Story story = stories.get(counter);
                    if (story.getAttachment().filePath != null && (new File(story.getAttachment().filePath).exists())) {
                        return;
                    }
                    Bitmap bitmap = AndroidUtils.blurImage(BitmapFactory.decodeFile(path));
                    storyDisplayImage.setImageBitmap(bitmap);
                } else {
                    DownloadObject downloadObject = DownloadObject.createForThumb(attachmentObject, ProtoGlobal.RoomMessageType.STORY.getNumber(), false);
                    if (downloadObject != null) {
                        downloadObject.downloadId = stories.get(counter).getStoryId();
                        getDownloader().download(downloadObject, selector, arg -> {
                            if (arg.status == Status.SUCCESS) {
                                if (arg.data != null) {
                                    String filePath = arg.data.getFilePath();
                                    Story story = stories.get(counter);
                                    if (story.getStoryId() == arg.data.getDownloadObject().downloadId) {
                                        if (story.getAttachment().filePath != null && (new File(story.getAttachment().filePath).exists())) {
                                            return;
                                        }
                                        Bitmap bitmap = AndroidUtils.blurImage(BitmapFactory.decodeFile(filePath));
                                        G.runOnUiThread(() -> storyDisplayImage.setImageBitmap(bitmap));
                                    }
                                }
                            }
                        });
                    }
                }
            }
        }
        DownloadObject object = DownloadObject.createForStory(attachmentObject, stories.get(counter).getStoryId(), true);
        if (object != null) {
            ProtoFileDownload.FileDownload.Selector imageSelector = ProtoFileDownload.FileDownload.Selector.FILE;
            Downloader.getInstance(AccountManager.selectedAccount).download(object, imageSelector, HttpRequest.PRIORITY.PRIORITY_HIGH, arg -> {
                if (arg.status == Status.SUCCESS && arg.data != null) {
                    String filepath = arg.data.getFilePath();
                    long downloadId = arg.data.getDownloadObject().downloadId;
                    Story story = stories.get(counter);
                    if (downloadId == story.getStoryId()) {
                        story.getAttachment().filePath = filepath;
                        G.runOnUiThread(() -> loadImage(filepath));
                    }
                }
            });
        }
    }
}
Also used : AnticipateInterpolator(android.view.animation.AnticipateInterpolator) Bundle(android.os.Bundle) ProgressBar(android.widget.ProgressBar) NonNull(androidx.annotation.NonNull) ProtoFileDownload(net.iGap.proto.ProtoFileDownload) FrameLayout(android.widget.FrameLayout) ImageView(android.widget.ImageView) LastSeenTimeUtil(net.iGap.module.LastSeenTimeUtil) Drawable(android.graphics.drawable.Drawable) AdditionalType(net.iGap.module.additionalData.AdditionalType) HelperFragment(net.iGap.helper.HelperFragment) HelperCalander(net.iGap.helper.HelperCalander) ScrollingMovementMethod(android.text.method.ScrollingMovementMethod) ChatSendMessageUtil(net.iGap.module.ChatSendMessageUtil) RealmRoom(net.iGap.realm.RealmRoom) BaseFragment(net.iGap.fragments.BaseFragment) Downloader(net.iGap.module.downloader.Downloader) StringRes(androidx.annotation.StringRes) FontIconTextView(net.iGap.module.FontIconTextView) Nullable(androidx.annotation.Nullable) SHP_SETTING(net.iGap.module.SHP_SETTING) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) EventManager(net.iGap.observers.eventbus.EventManager) AbstractObject(net.iGap.network.AbstractObject) DownloadObject(net.iGap.module.downloader.DownloadObject) SuggestedStickerAdapter(net.iGap.fragments.emoji.SuggestedStickerAdapter) EmojiManager(net.iGap.libs.emojiKeyboard.emoji.EmojiManager) LayerDrawable(android.graphics.drawable.LayerDrawable) AttachmentObject(net.iGap.structs.AttachmentObject) ViewMaker.setTextSize(net.iGap.adapter.items.chat.ViewMaker.setTextSize) Environment(android.os.Environment) AccountManager(net.iGap.module.accountManager.AccountManager) BitmapFactory(android.graphics.BitmapFactory) PlayerView(com.google.android.exoplayer2.ui.PlayerView) ViewUserDialogFragment(net.iGap.story.ViewUserDialogFragment) GradientDrawable(android.graphics.drawable.GradientDrawable) Toast(android.widget.Toast) LayoutCreator(net.iGap.helper.LayoutCreator) AvatarHandler(net.iGap.helper.avatar.AvatarHandler) StickerSettingFragment(net.iGap.fragments.emoji.remove.StickerSettingFragment) MessageObject(net.iGap.structs.MessageObject) TextUtils(android.text.TextUtils) RecyclerListView(net.iGap.module.customView.RecyclerListView) File(java.io.File) Gravity(android.view.Gravity) StructIGSticker(net.iGap.fragments.emoji.struct.StructIGSticker) EventEditText(net.iGap.module.customView.EventEditText) SharedPreferences(android.content.SharedPreferences) TypedValue(android.util.TypedValue) NotifyFrameLayout(net.iGap.libs.emojiKeyboard.NotifyFrameLayout) DbManager(net.iGap.module.accountManager.DbManager) EditText(android.widget.EditText) Rect(android.graphics.Rect) LinearLayout(android.widget.LinearLayout) AppUtils(net.iGap.module.AppUtils) StoryCell(net.iGap.story.storyviews.StoryCell) Animator(android.animation.Animator) Theme(net.iGap.module.Theme) G(net.iGap.G) RealmUserInfo(net.iGap.realm.RealmUserInfo) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Gson(com.google.gson.Gson) ActivityInfo(android.content.pm.ActivityInfo) View(android.view.View) KeyboardView(net.iGap.libs.emojiKeyboard.KeyboardView) RecyclerView(androidx.recyclerview.widget.RecyclerView) ParamWithAvatarType(net.iGap.helper.avatar.ParamWithAvatarType) Status(net.iGap.module.downloader.Status) ObjectAnimator(android.animation.ObjectAnimator) RealmStory(net.iGap.realm.RealmStory) DisplayMetrics(android.util.DisplayMetrics) ViewGroup(android.view.ViewGroup) Objects(java.util.Objects) List(java.util.List) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) TextView(android.widget.TextView) FragmentSettingAddStickers(net.iGap.fragments.emoji.add.FragmentSettingAddStickers) HttpRequest(net.iGap.module.downloader.HttpRequest) StickerRepository(net.iGap.repository.StickerRepository) Typeface(android.graphics.Typeface) Context(android.content.Context) AndroidUtils(net.iGap.module.AndroidUtils) KeyEvent(android.view.KeyEvent) ResourcesCompat(androidx.core.content.res.ResourcesCompat) TimeUtils(net.iGap.module.TimeUtils) RealmStickerItem(net.iGap.realm.RealmStickerItem) MotionEvent(android.view.MotionEvent) ExpandableTextView(net.iGap.story.ExpandableTextView) MODE_PRIVATE(android.content.Context.MODE_PRIVATE) AnimatorSet(android.animation.AnimatorSet) RealmRoomMessage(net.iGap.realm.RealmRoomMessage) EmojiView(net.iGap.libs.emojiKeyboard.EmojiView) IG_RPC(net.iGap.network.IG_RPC) ImageLoadingView(net.iGap.story.liststories.ImageLoadingView) RealmAdditional(net.iGap.realm.RealmAdditional) InsetDrawable(android.graphics.drawable.InsetDrawable) CircleImageView(net.iGap.module.CircleImageView) Color(android.graphics.Color) Glide(com.bumptech.glide.Glide) Bitmap(android.graphics.Bitmap) ProtoGlobal(net.iGap.proto.ProtoGlobal) R(net.iGap.R) RealmAttachment(net.iGap.realm.RealmAttachment) IG_RPC(net.iGap.network.IG_RPC) DownloadObject(net.iGap.module.downloader.DownloadObject) Bitmap(android.graphics.Bitmap) ProtoFileDownload(net.iGap.proto.ProtoFileDownload) AttachmentObject(net.iGap.structs.AttachmentObject) AbstractObject(net.iGap.network.AbstractObject) File(java.io.File) RealmStory(net.iGap.realm.RealmStory)

Example 3 with AttachmentObject

use of net.iGap.structs.AttachmentObject in project iGap-Android by KianIranian-STDG.

the class StoryCell method setData.

public void setData(MainStoryObject mainStoryObject, String color, Context context, boolean needDivider, CircleStatus status, ImageLoadingView.Status imageLoadingStatus, IconClicked iconClicked) {
    this.userId = mainStoryObject.userId;
    this.roomId = mainStoryObject.roomId;
    this.isVerified = mainStoryObject.isVerified;
    initView(context, needDivider, status, imageLoadingStatus, iconClicked, mainStoryObject.storyObjects.get(0).createdAt);
    circleImageLoading.setStatus(imageLoadingStatus);
    if (userId == AccountManager.getInstance().getCurrentUser().getId()) {
        topText.setText(context.getString(R.string.my_status));
    } else {
        if (roomId != 0) {
            channelIconTv.setVisibility(VISIBLE);
        }
        if (isVerified) {
            verifyIconTv.setVisibility(VISIBLE);
        }
        topText.setText(mainStoryObject.storyObjects.get(0).displayName != null ? mainStoryObject.storyObjects.get(0).displayName : "");
    }
    String name = HelperImageBackColor.getFirstAlphabetName(mainStoryObject.storyObjects.get(0).displayName != null ? mainStoryObject.storyObjects.get(0).displayName : "");
    if (circleImageLoading.getStatus() == ImageLoadingView.Status.FAILED) {
        bottomText.setText(context.getString(R.string.story_could_not_sent));
        bottomText.setTextColor(Color.RED);
        deleteIcon.setTextColor(Color.RED);
        addIcon.setTextColor(Color.RED);
        addIcon.setText(R.string.icon_error);
    } else if (circleImageLoading.getStatus() == ImageLoadingView.Status.LOADING) {
        bottomText.setText(context.getString(R.string.story_sending));
        deleteIcon.setTextColor(Theme.getInstance().getTitleTextColor(context));
    } else {
        bottomText.setText(LastSeenTimeUtil.computeTime(context, mainStoryObject.userId, mainStoryObject.storyObjects.get(0).createdAt / 1000L, false, false));
    }
    AttachmentObject attachment = mainStoryObject.storyObjects.get(0).attachmentObject;
    if (status == CircleStatus.LOADING_CIRCLE_IMAGE) {
        if (attachment != null && (attachment.thumbnailPath != null || attachment.filePath != null)) {
            try {
                Glide.with(G.context).load(attachment.filePath != null ? attachment.filePath : attachment.thumbnailPath).placeholder(new BitmapDrawable(context.getResources(), HelperImageBackColor.drawAlphabetOnPicture(LayoutCreator.dp(64), name, color))).into(circleImageLoading);
            } catch (Exception e) {
                Glide.with(G.context).load(new BitmapDrawable(context.getResources(), HelperImageBackColor.drawAlphabetOnPicture(LayoutCreator.dp(64), name, color))).into(circleImageLoading);
            }
        } else if (attachment != null) {
            Glide.with(G.context).load(new BitmapDrawable(context.getResources(), HelperImageBackColor.drawAlphabetOnPicture(LayoutCreator.dp(64), name, color))).into(circleImageLoading);
            DownloadObject object = DownloadObject.createForStory(attachment, storyId, true);
            if (object != null) {
                Downloader.getInstance(AccountManager.selectedAccount).download(object, arg -> {
                    if (arg.status == Status.SUCCESS && arg.data != null) {
                        String filepath = arg.data.getFilePath();
                        String downloadedFileToken = arg.data.getToken();
                        if (!(new File(filepath).exists())) {
                            HelperLog.getInstance().setErrorLog(new Exception("File Dont Exist After Download !!" + filepath));
                        }
                        if (arg.data.getDownloadObject().downloadId == storyId) {
                            DbManager.getInstance().doRealmTransaction(realm1 -> {
                                RealmStoryProto realmStoryProto = realm1.where(RealmStoryProto.class).equalTo("isForReply", false).equalTo("storyId", storyId).findFirst();
                                if (realmStoryProto != null) {
                                    realmStoryProto.getFile().setLocalFilePath(filepath);
                                }
                            });
                            G.runOnUiThread(() -> Glide.with(G.context).load(filepath).placeholder(new BitmapDrawable(context.getResources(), HelperImageBackColor.drawAlphabetOnPicture(LayoutCreator.dp(64), name, color))).into(circleImageLoading));
                        }
                    }
                });
            }
        } else {
            Glide.with(G.context).load(new BitmapDrawable(context.getResources(), HelperImageBackColor.drawAlphabetOnPicture(LayoutCreator.dp(64), name, color))).into(circleImageLoading);
        }
    }
}
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 4 with AttachmentObject

use of net.iGap.structs.AttachmentObject in project iGap-Android by KianIranian-STDG.

the class ShowMediaListener method getFilePath.

public String getFilePath(MessageObject messageObject) {
    String result = "";
    AttachmentObject at = messageObject.forwardedMessage != null ? messageObject.forwardedMessage.attachment : messageObject.attachment;
    if (at != null) {
        if (at.filePath != null)
            result = at.filePath;
    }
    int messageType = messageObject.forwardedMessage != null ? messageObject.forwardedMessage.messageType : messageObject.messageType;
    if (result.length() < 1) {
        String mimeType = DownloadObject.extractMime(at.name);
        String path = AndroidUtils.suitableAppFilePath(ProtoGlobal.RoomMessageType.forNumber(messageType));
        result = new File(path + "/" + at.cacheId + "_" + mimeType).getAbsolutePath();
        return result;
    }
    return result;
}
Also used : AttachmentObject(net.iGap.structs.AttachmentObject) HelperDownloadFile(net.iGap.helper.HelperDownloadFile) File(java.io.File) HelperSaveFile(net.iGap.helper.HelperSaveFile)

Example 5 with AttachmentObject

use of net.iGap.structs.AttachmentObject in project iGap-Android by KianIranian-STDG.

the class DownloadObject method createForStory.

public static DownloadObject createForStory(AttachmentObject attachment, long storyId, boolean big) {
    if (attachment == null) {
        return null;
    }
    final AttachmentObject thumbnail = big ? attachment.largeThumbnail : attachment.smallThumbnail;
    if (thumbnail == null || thumbnail.cacheId == null) {
        return null;
    }
    DownloadObject struct = new DownloadObject();
    struct.selector = big ? FILE_VALUE : SMALL_THUMBNAIL_VALUE;
    struct.key = createKey(String.valueOf(thumbnail.cacheId), struct.selector);
    struct.mainCacheId = attachment.cacheId;
    struct.fileToken = attachment.token;
    struct.fileName = attachment.name;
    struct.fileSize = attachment.largeThumbnail.size;
    struct.mimeType = struct.extractMime(struct.fileName);
    struct.priority = HttpRequest.PRIORITY.PRIORITY_MEDIUM;
    struct.downloadId = storyId;
    String filePath = null;
    if (big) {
        filePath = suitableAppFilePath(ProtoGlobal.RoomMessageType.STORY);
    } else {
        filePath = AndroidUtils.getFilePathWithCashId(attachment.cacheId, attachment.name, G.DIR_IMAGE_USER, true);
    }
    struct.destFile = new File(filePath + "/" + struct.mainCacheId + "_" + struct.mimeType);
    struct.tempFile = new File(G.context.getCacheDir() + "/" + struct.key);
    struct.messageType = ProtoGlobal.RoomMessageType.STORY;
    if (struct.tempFile.exists()) {
        struct.offset = struct.tempFile.length();
        if (struct.offset > 0 && struct.fileSize > 0) {
            struct.progress = (int) ((struct.offset * 100) / struct.fileSize);
        }
    }
    return struct;
}
Also used : AttachmentObject(net.iGap.structs.AttachmentObject) File(java.io.File)

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