SubscribeSucDialog.java 3.96 KB
package com.cnlive.goldenline.ui.widget;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.support.annotation.NonNull;
import android.support.annotation.StyleRes;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import android.widget.TextView;

import com.cnlive.goldenline.R;
import com.cnlive.goldenline.ui.activity.MyTicketActivity;

import java.util.Locale;

/**
 * description: 显示购票成功的dialog
 * Created by Sivin on 2017/4/14.
 */
@SuppressWarnings("unused")
public class SubscribeSucDialog extends Dialog {
    private Context mContext;

    private int mTicketNum;

    private String mTicketTitle;

    private String mTicketTime;

    private int layoutId;

    private boolean mCancel;

    private boolean mCanJump = true;


    public SubscribeSucDialog setContext(Context context) {
        mContext = context;
        return this;
    }

    public SubscribeSucDialog setTicketNum(int ticketNum) {
        mTicketNum = ticketNum;
        return this;
    }

    public SubscribeSucDialog setTicketTitle(String ticketTitle) {
        mTicketTitle = ticketTitle;
        return this;
    }

    public SubscribeSucDialog setTicketTime(String ticketTime) {
        mTicketTime = ticketTime;
        return this;
    }

    public SubscribeSucDialog setLayoutId(int layoutId) {
        this.layoutId = layoutId;
        return this;
    }

    public SubscribeSucDialog setCancel(boolean cancel) {
        mCancel = cancel;
        return this;
    }

    public SubscribeSucDialog setCanJump(boolean mCanJump) {
        this.mCanJump = mCanJump;
        return this;
    }

    public SubscribeSucDialog(@NonNull Context context) {
        this(context,0);
    }

    public SubscribeSucDialog(@NonNull Context context, @StyleRes int themeResId) {
        super(context, themeResId);
        mContext = context;
    }

    public SubscribeSucDialog build() {

        LayoutInflater inflater = LayoutInflater.from(mContext);
        View contentView = inflater.inflate(layoutId, null);
        this.setContentView(contentView);

        Window window = getWindow();
        if (window != null)
            window.setBackgroundDrawable(null);

        setCancelable(mCancel);
        setCanceledOnTouchOutside(false);


        TextView tipsTv = (TextView) contentView.findViewById(R.id.id_second_title);
        SpannableString spannableStr = new SpannableString(String.format(Locale.CHINA, "您购买的 %d张 入场券已到账", mTicketNum));
        ForegroundColorSpan colorSpan = new ForegroundColorSpan(Color.parseColor("#f6e2ce"));
        spannableStr.setSpan(colorSpan, 0, spannableStr.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
        ForegroundColorSpan colorSpan2 = new ForegroundColorSpan(Color.parseColor("#ffffff"));
        spannableStr.setSpan(colorSpan2, 5, 7, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
        tipsTv.setText(spannableStr);

        TextView ticketTimeTv = (TextView) contentView.findViewById(R.id.id_ticket_time);
        ticketTimeTv.setText(mTicketTime);

        ImageView closeBtn = (ImageView) contentView.findViewById(R.id.id_close);

        closeBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });

        TextView jumpTv = (TextView) contentView.findViewById(R.id.jump_to_my_ticket);
        jumpTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MyTicketActivity.startActivity(mContext);
            }
        });

        jumpTv.setVisibility(mCanJump ? View.VISIBLE : View.GONE);

        TextView ticketTitle = (TextView) contentView.findViewById(R.id.id_main_title);
        ticketTitle.setText(mTicketTitle);

        return this;
    }


}