admin
2021-05-13 4a8f1bec26519a25f073739534e653a4f7c9e11d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
package com.tejia.lijin.app.ui.dialog;
 
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
 
import com.bumptech.glide.Glide;
import com.wpc.library.util.SystemCommon;
import com.tejia.lijin.app.R;
import com.tejia.lijin.app.entity.GiftCoupon;
import com.tejia.lijin.app.ui.mine.MultipleContentPopUpsAdapter;
import com.tejia.lijin.app.util.ApkUtil;
import com.tejia.lijin.app.util.GlideCircleTransform;
 
 
/**
 * 10-免单券   11-奖励券   12-红包 弹窗
 */
public class CopyGiftDialog extends Dialog {
    public CopyGiftDialog(Context context) {
        super(context);
        this.setCancelable(false);
    }
 
    public CopyGiftDialog(Context context, int theme) {
        super(context, theme);
        this.setCancelable(false);
    }
 
    public static class Builder {
        private Context context;
        private GiftCoupon mGiftCoupon; //免单券 -奖励券  -红包 实体类
        private String positiveButtonText;
        private String negativeButtonText;
        private OnClickListener positiveButtonClickListener;
        private OnClickListener negativeButtonClickListener;
 
        public Builder(Context context) {
            this.context = context;
        }
 
        public Builder setMessage(GiftCoupon mGiftCoupon) {
            this.mGiftCoupon = mGiftCoupon;
            return this;
        }
 
        /**
         * Set the positive button resource and it's listener
         *
         * @param positiveButtonText
         * @return
         */
        public Builder setPositiveButton(int positiveButtonText,
                                         OnClickListener listener) {
            this.positiveButtonText = (String) context
                    .getText(positiveButtonText);
            this.positiveButtonClickListener = listener;
            return this;
        }
 
        public Builder setPositiveButton(String positiveButtonText,
                                         OnClickListener listener) {
            this.positiveButtonText = positiveButtonText;
            this.positiveButtonClickListener = listener;
            return this;
        }
 
        public Builder setNegativeButton(int negativeButtonText,
                                         OnClickListener listener) {
            this.negativeButtonText = (String) context
                    .getText(negativeButtonText);
            this.negativeButtonClickListener = listener;
            return this;
        }
 
        public Builder setNegativeButton(String negativeButtonText,
                                         OnClickListener listener) {
            this.negativeButtonText = negativeButtonText;
            this.negativeButtonClickListener = listener;
            return this;
        }
 
        public CopyLinkDialog create() {
            LayoutInflater inflater = (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            // instantiate the dialog with the custom Theme
            final CopyLinkDialog dialog = new CopyLinkDialog(context, R.style.Dialog1);
            View layout = inflater.inflate(R.layout.item_copy_gift, null);
            dialog.addContentView(layout, new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT));
 
            TextView popups_title = layout.findViewById(R.id.popups_title);//title
            ImageView popups_titleimg = layout.findViewById(R.id.popups_titleimg);//titleimg
            ImageView popups_close = layout.findViewById(R.id.popups_close);
            TextView popups_single = layout.findViewById(R.id.popups_single);//领取按钮
//            TextView popups_dual = layout.findViewById(R.id.popups_dual);//第二个按钮
            ListView listView = layout.findViewById(R.id.popups_listview);
            TextView popups_statetxt = layout.findViewById(R.id.popups_statetxt);//显示无效提示语
            popups_title.setText(mGiftCoupon.nickName);
            Glide.with(context).load(mGiftCoupon.portrait)
                    .transform(new GlideCircleTransform(context))
                    .placeholder(R.drawable.ic_goods_default)
                    .error(R.drawable.ic_goods_default)
                    .into(popups_titleimg);
            if (mGiftCoupon.state) { // 有效:确认领取   无效:知道了
                popups_single.setText("确认领取");
                MultipleContentPopUpsAdapter adapter = new MultipleContentPopUpsAdapter(context, mGiftCoupon.tips);
                listView.setAdapter(adapter);
            } else {
                popups_single.setText("知道了");
                listView.setVisibility(View.GONE);
                popups_statetxt.setVisibility(View.VISIBLE);
                popups_statetxt.setText(mGiftCoupon.tips.get(0));
            }
            ImageView popups_img = layout.findViewById(R.id.popups_img);//免单券
            if (mGiftCoupon.type == 10) { // 类型:10-免单券   11-奖励券   13-红包
                popups_img.setBackground(context.getResources().getDrawable(R.drawable.ic_freecoupon));
            } else if (mGiftCoupon.type == 11) {//奖励券
                popups_img.setBackground(context.getResources().getDrawable(R.drawable.ic_freereward));
            } else if (mGiftCoupon.type == 13) {//红包
                popups_img.setVisibility(View.GONE);
                RelativeLayout popups_imglayout = layout.findViewById(R.id.popups_imglayout);//红包布局
                popups_imglayout.setVisibility(View.VISIBLE);
                TextView popups_imgmoney = layout.findViewById(R.id.popups_imgmoney);
                popups_imgmoney.setText(mGiftCoupon.money);
            }
 
            // set the confirm button
 
            if (positiveButtonClickListener != null) {
                popups_single.setOnClickListener(new View.OnClickListener() {
                    public void onClick(View v) {
                        positiveButtonClickListener.onClick(dialog, DialogInterface.BUTTON_POSITIVE);
//                        setClipboardManager(clipboard);
                        ApkUtil.setEmptyClipboardManager(context);
                    }
                });
            }
            if (negativeButtonClickListener != null) {
//                popups_close.setVisibility(View.VISIBLE);//显示第二个按钮
                popups_close.setOnClickListener(new View.OnClickListener() {
                    public void onClick(View v) {
                        negativeButtonClickListener.onClick(dialog, DialogInterface.BUTTON_NEGATIVE);
                        ApkUtil.setEmptyClipboardManager(context);
                    }
                });
            }
            dialog.setContentView(layout);
 
            android.view.WindowManager.LayoutParams params = dialog.getWindow().getAttributes();
            params.width = (int) ((SystemCommon.getScreenWidth(context) * 19) / 25);
            params.height = android.view.WindowManager.LayoutParams.WRAP_CONTENT;
            dialog.getWindow().setAttributes(params);
            dialog.setCanceledOnTouchOutside(false);
            return dialog;
        }
 
 
    }
}