Search in sources :

Example 1 with ImageLoadingView

use of net.iGap.story.liststories.ImageLoadingView in project iGap-Android by KianIranian-STDG.

the class StoryCell method initView.

public void initView(Context context, boolean needDivider, CircleStatus status, ImageLoadingView.Status imageLoadingStatus, IconClicked iconClicked, long createTime) {
    removeAllViews();
    if (G.themeColor == Theme.DARK) {
        setBackground(Theme.getSelectorDrawable(Theme.getInstance().getDividerColor(context)));
    } else {
        setBackgroundColor(Color.WHITE);
    }
    this.status = status;
    this.needDivider = needDivider;
    this.iconClicked = iconClicked;
    this.context = context;
    setWillNotDraw(!needDivider);
    View view;
    switch(this.status) {
        case CIRCLE_IMAGE:
            circleImage = new CircleImageView(getContext());
            circleImage.setLayoutParams(LayoutCreator.createFrame(56, 56, (isRtl ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL, isRtl ? 0 : padding, 8, isRtl ? padding : 0, 8));
            view = circleImage;
            break;
        case LOADING_CIRCLE_IMAGE:
            circleImageLoading = new ImageLoadingView(context);
            circleImageLoading.setStatus(imageLoadingStatus);
            circleImageLoading.setLayoutParams(LayoutCreator.createFrame(72, 72, (isRtl ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL, isRtl ? 0 : 8, 8, isRtl ? 8 : 0, 8));
            view = circleImageLoading;
            break;
        default:
            throw new IllegalStateException("Unexpected value: " + this.status);
    }
    addView(view);
    addIcon = new MaterialDesignTextView(context);
    addIcon.setText(R.string.icon_add_whit_circle);
    addIcon.setTextColor(getResources().getColor(R.color.green));
    addIcon.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
    addIcon.setGravity(isRtl ? Gravity.LEFT : Gravity.RIGHT);
    addView(addIcon, LayoutCreator.createFrame(18, 18, (isRtl ? Gravity.RIGHT : Gravity.LEFT) | Gravity.BOTTOM, isRtl ? 0 : padding, 8, isRtl ? padding : 0, 8));
    topViewRootView = new LinearLayout(context);
    topViewRootView.setOrientation(LinearLayout.HORIZONTAL);
    topViewRootView.setGravity(Gravity.CENTER);
    addView(topViewRootView, LayoutCreator.createFrame(LayoutCreator.WRAP_CONTENT, LayoutCreator.WRAP_CONTENT, (isRtl ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, isRtl ? padding : ((padding * 2) + 56), 11.5f, isRtl ? ((padding * 2) + 56) : padding, 0));
    channelIconTv = new FontIconTextView(getContext());
    setTextSize(channelIconTv, R.dimen.dp14);
    channelIconTv.setText(R.string.icon_channel);
    channelIconTv.setTextColor(Theme.getInstance().getAccentColor(channelIconTv.getContext()));
    channelIconTv.setVisibility(GONE);
    topViewRootView.addView(channelIconTv, LayoutCreator.createLinear(LayoutCreator.WRAP_CONTENT, LayoutCreator.WRAP_CONTENT, Gravity.CENTER));
    topText = new TextView(context);
    topText.setSingleLine();
    topText.setTypeface(ResourcesCompat.getFont(getContext(), R.font.main_font_bold));
    ViewMaker.setTextSize(topText, R.dimen.dp15);
    topText.setSingleLine(true);
    topText.setEllipsize(TextUtils.TruncateAt.END);
    topText.setTextColor(Theme.getInstance().getSendMessageTextColor(topText.getContext()));
    topText.setGravity((isRtl ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
    topViewRootView.addView(topText, LayoutCreator.createLinear(LayoutCreator.WRAP_CONTENT, LayoutCreator.WRAP_CONTENT, Gravity.CENTER, !isRtl && roomId != 0 && userId != AccountManager.getInstance().getCurrentUser().getId() ? 4 : 0, 0, isRtl && roomId != 0 && userId != AccountManager.getInstance().getCurrentUser().getId() ? 4 : 0, 0));
    verifyIconTv = new FontIconTextView(getContext());
    verifyIconTv.setTextColor(getContext().getResources().getColor(R.color.verify_color));
    verifyIconTv.setText(R.string.icon_blue_badge);
    setTextSize(verifyIconTv, R.dimen.standardTextSize);
    verifyIconTv.setVisibility(GONE);
    topViewRootView.addView(verifyIconTv, LayoutCreator.createLinear(LayoutCreator.WRAP_CONTENT, LayoutCreator.WRAP_CONTENT, Gravity.CENTER, !isRtl && roomId != 0 && userId != AccountManager.getInstance().getCurrentUser().getId() ? 4 : 0, 0, isRtl && roomId != 0 && userId != AccountManager.getInstance().getCurrentUser().getId() ? 4 : 0, 0));
    middleText = new TextView(context);
    middleText.setSingleLine();
    middleText.setTypeface(ResourcesCompat.getFont(getContext(), R.font.main_font_bold));
    ViewMaker.setTextSize(middleText, R.dimen.dp15);
    middleText.setSingleLine(true);
    middleText.setEllipsize(TextUtils.TruncateAt.END);
    middleText.setTextColor(Theme.getInstance().getPrimaryTextColor(context));
    middleText.setGravity((isRtl ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL);
    middleText.setVisibility(GONE);
    addView(middleText, LayoutCreator.createFrame(LayoutCreator.WRAP_CONTENT, LayoutCreator.WRAP_CONTENT, (isRtl ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL, isRtl ? padding : ((padding * 2) + 56), 0, isRtl ? ((padding * 2) + 56) : padding, 0));
    bottomText = new TextView(context);
    bottomText.setSingleLine();
    ViewMaker.setTypeFace(bottomText);
    ViewMaker.setTextSize(bottomText, R.dimen.dp13);
    bottomText.setGravity((isRtl ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
    bottomText.setTextColor(Color.GRAY);
    addView(bottomText, LayoutCreator.createFrame(LayoutCreator.WRAP_CONTENT, LayoutCreator.WRAP_CONTENT, (isRtl ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, isRtl ? padding : ((padding * 2) + 56), 34.5f, isRtl ? ((padding * 2) + 56) : padding, 0));
    icon = new IconView(getContext());
    icon.setTypeface(ResourcesCompat.getFont(context, R.font.font_icons));
    icon.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
    addView(icon, LayoutCreator.createFrame(LayoutCreator.WRAP_CONTENT, LayoutCreator.WRAP_CONTENT, (isRtl ? Gravity.LEFT : Gravity.RIGHT) | Gravity.CENTER_VERTICAL, padding, 0, padding, 0));
    icon2 = new IconView(getContext());
    icon2.setTypeface(ResourcesCompat.getFont(context, R.font.font_icons));
    icon2.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
    addView(icon2, LayoutCreator.createFrame(LayoutCreator.WRAP_CONTENT, LayoutCreator.WRAP_CONTENT, (isRtl ? Gravity.LEFT : Gravity.RIGHT) | Gravity.CENTER_VERTICAL, isRtl ? (padding + 30) : padding, 0, isRtl ? padding : (30 + padding), 0));
    LinearLayout iconsRootView = new LinearLayout(getContext());
    iconsRootView.setOrientation(LinearLayout.HORIZONTAL);
    iconsRootView.setGravity(Gravity.CENTER);
    addView(iconsRootView, LayoutCreator.createFrame(LayoutCreator.WRAP_CONTENT, LayoutCreator.WRAP_CONTENT, (isRtl ? Gravity.LEFT : Gravity.RIGHT) | Gravity.CENTER_VERTICAL, isRtl ? 0 : 8, 8, isRtl ? 8 : 0, 8));
    uploadIcon = new MaterialDesignTextView(getContext());
    uploadIcon.setTypeface(ResourcesCompat.getFont(context, R.font.font_icons));
    uploadIcon.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 23);
    uploadIcon.setText(R.string.icon_upload);
    uploadIcon.setVisibility(GONE);
    uploadIcon.setTextColor(Theme.getInstance().getSendMessageTextColor(uploadIcon.getContext()));
    uploadIcon.setGravity(Gravity.CENTER);
    uploadIcon.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if ((circleImageLoading.getStatus() == ImageLoadingView.Status.FAILED && isFromMyStatus && !isRoom) || (circleImageLoading.getStatus() == ImageLoadingView.Status.FAILED && isFromMyStatus && isRoom && mode == 1)) {
                deleteIcon.setVisibility(GONE);
                uploadIcon.setVisibility(GONE);
                middleText.setTextColor(Theme.getInstance().getTitleTextColor(context));
                middleText.setText(context.getString(R.string.story_sending));
                circleImageLoading.setStatus(ImageLoadingView.Status.LOADING);
                StoryObject realmStoryProto;
                if (fileToken != null) {
                    realmStoryProto = MessageDataStorage.getInstance(AccountManager.selectedAccount).getStoryWithFileToken(fileToken);
                } else {
                    realmStoryProto = MessageDataStorage.getInstance(AccountManager.selectedAccount).getStoryWithUploadId(uploadId);
                }
                if (realmStoryProto != null && realmStoryProto.fileToken != null) {
                    MessageDataStorage.getInstance(AccountManager.selectedAccount).updateStoryStatus(realmStoryProto.id, MessageObject.STATUS_SENDING);
                    List<ProtoStoryUserAddNew.StoryAddRequest> storyAddRequests = new ArrayList<>();
                    ProtoStoryUserAddNew.StoryAddRequest.Builder storyAddRequest = ProtoStoryUserAddNew.StoryAddRequest.newBuilder();
                    storyAddRequest.setToken(realmStoryProto.fileToken);
                    storyAddRequest.setCaption(realmStoryProto.caption);
                    storyAddRequests.add(storyAddRequest.build());
                    if (isRoom) {
                        MessageController.getInstance(AccountManager.selectedAccount).addMyRoomStory(storyAddRequests, roomId);
                    } else {
                        MessageController.getInstance(AccountManager.selectedAccount).addMyStory(storyAddRequests);
                    }
                } else if (realmStoryProto != null && !Uploader.getInstance().isCompressingOrUploading(String.valueOf(realmStoryProto.id))) {
                    MessageDataStorage.getInstance(AccountManager.selectedAccount).updateStoryStatus(realmStoryProto.id, MessageObject.STATUS_SENDING);
                    HttpUploader.isStoryUploading = true;
                    Uploader.getInstance().upload(UploadObject.createForStory(realmStoryProto.id, realmStoryProto.attachmentObject.filePath, null, realmStoryProto.caption, ProtoGlobal.RoomMessageType.STORY));
                }
                EventManager.getInstance(AccountManager.selectedAccount).postEvent(EventManager.STORY_SENDING);
            } else {
                deleteStory.deleteStory(StoryCell.this, storyId, roomId, isRoom);
            }
        }
    });
    deleteIcon = new MaterialDesignTextView(getContext());
    deleteIcon.setTypeface(ResourcesCompat.getFont(context, R.font.font_icons));
    deleteIcon.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 23);
    deleteIcon.setText(R.string.icon_other_horizontal_dots);
    deleteIcon.setVisibility(GONE);
    deleteIcon.setTextColor(Theme.getInstance().getSendMessageTextColor(deleteIcon.getContext()));
    deleteIcon.setGravity(Gravity.CENTER);
    deleteIcon.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            deleteStory.deleteStory(StoryCell.this, storyId, roomId, isRoom);
        }
    });
    iconsRootView.addView(uploadIcon, LayoutCreator.createLinear(72, 72, Gravity.CENTER_VERTICAL));
    iconsRootView.addView(deleteIcon, LayoutCreator.createLinear(72, 72, Gravity.CENTER_VERTICAL));
    if (status == CircleStatus.LOADING_CIRCLE_IMAGE) {
        setOnClickListener(v -> {
            deleteStory.onStoryClick(this);
        });
        circleImageLoading.setOnClickListener(v -> {
            deleteStory.onStoryClick(this);
        });
    }
}
Also used : IconView(net.iGap.messenger.ui.components.IconView) MainStoryObject(net.iGap.story.MainStoryObject) StoryObject(net.iGap.story.StoryObject) FontIconTextView(net.iGap.module.FontIconTextView) View(android.view.View) FontIconTextView(net.iGap.module.FontIconTextView) TextView(android.widget.TextView) ImageLoadingView(net.iGap.story.liststories.ImageLoadingView) MaterialDesignTextView(net.iGap.module.MaterialDesignTextView) IconView(net.iGap.messenger.ui.components.IconView) CircleImageView(net.iGap.module.CircleImageView) CircleImageView(net.iGap.module.CircleImageView) MaterialDesignTextView(net.iGap.module.MaterialDesignTextView) ImageLoadingView(net.iGap.story.liststories.ImageLoadingView) FontIconTextView(net.iGap.module.FontIconTextView) TextView(android.widget.TextView) MaterialDesignTextView(net.iGap.module.MaterialDesignTextView) List(java.util.List) ArrayList(java.util.ArrayList) ProtoStoryUserAddNew(net.iGap.proto.ProtoStoryUserAddNew) LinearLayout(android.widget.LinearLayout)

Example 2 with ImageLoadingView

use of net.iGap.story.liststories.ImageLoadingView in project iGap-Android by KianIranian-STDG.

the class StoryCell method setStatus.

public void setStatus(CircleStatus status) {
    this.status = status;
    View view;
    switch(this.status) {
        case CIRCLE_IMAGE:
            if (circleImage == null) {
                circleImage = new CircleImageView(getContext());
                circleImage.setLayoutParams(LayoutCreator.createFrame(56, 56, (isRtl ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL, isRtl ? 0 : padding, 8, isRtl ? padding : 0, 8));
                addView(circleImage, 0);
            } else {
                circleImage.setVisibility(VISIBLE);
            }
            if (circleImageLoading != null) {
                circleImageLoading.setVisibility(GONE);
            }
            break;
        case LOADING_CIRCLE_IMAGE:
            if (circleImage != null) {
                circleImage.setVisibility(GONE);
            }
            if (circleImageLoading == null) {
                circleImageLoading = new ImageLoadingView(context);
                circleImageLoading.setLayoutParams(LayoutCreator.createFrame(72, 72, (isRtl ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL, isRtl ? 0 : 8, 8, isRtl ? 8 : 0, 8));
                addView(circleImageLoading, 0);
            } else {
                circleImageLoading.setVisibility(VISIBLE);
            }
            break;
        default:
            throw new IllegalStateException("Unexpected value: " + this.status);
    }
}
Also used : CircleImageView(net.iGap.module.CircleImageView) ImageLoadingView(net.iGap.story.liststories.ImageLoadingView) View(android.view.View) FontIconTextView(net.iGap.module.FontIconTextView) TextView(android.widget.TextView) ImageLoadingView(net.iGap.story.liststories.ImageLoadingView) MaterialDesignTextView(net.iGap.module.MaterialDesignTextView) IconView(net.iGap.messenger.ui.components.IconView) CircleImageView(net.iGap.module.CircleImageView)

Aggregations

View (android.view.View)2 TextView (android.widget.TextView)2 IconView (net.iGap.messenger.ui.components.IconView)2 CircleImageView (net.iGap.module.CircleImageView)2 FontIconTextView (net.iGap.module.FontIconTextView)2 MaterialDesignTextView (net.iGap.module.MaterialDesignTextView)2 ImageLoadingView (net.iGap.story.liststories.ImageLoadingView)2 LinearLayout (android.widget.LinearLayout)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ProtoStoryUserAddNew (net.iGap.proto.ProtoStoryUserAddNew)1 MainStoryObject (net.iGap.story.MainStoryObject)1 StoryObject (net.iGap.story.StoryObject)1