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
167
168
169
170
171
172
173
174
package com.tejia.lijin.app.ui.dialog;
 
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Typeface;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;
import android.text.style.RelativeSizeSpan;
import android.text.style.StyleSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
 
import com.tejia.lijin.app.R;
import com.tejia.lijin.app.entity.recommendinfo.ConvertLinkInfo;
import com.tejia.lijin.app.entity.user.VIPUpgradedNotify;
import com.tejia.lijin.app.ui.invite.ShareBrowserActivity;
import com.tejia.lijin.app.util.downutil.StringUtils;
 
/**
 * 转链
 * Created by weikou2015 on 2017/2/28.
 */
 
public class VipUpgradedDialog extends Dialog {
 
    public VipUpgradedDialog(Context context) {
        super(context);
        this.setCancelable(false);
    }
 
    public VipUpgradedDialog(Context context, int theme) {
        super(context, theme);
        this.setCancelable(false);
    }
 
    public static class Builder {
        private ConvertLinkInfo convertLinkInfo;
        private Context context;
        private OnClickListener closeClickListener;
        private OnClickListener positiveClickListener;
        private VIPUpgradedNotify notifyData;
 
        public Builder(Context context) {
            this.context = context;
        }
 
 
        public VipUpgradedDialog create() {
            LayoutInflater inflater = (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            final VipUpgradedDialog dialog = new VipUpgradedDialog(context, R.style.Dialog1);
            View layout = inflater.inflate(R.layout.dialog_vip_upgraded, null);
 
            //设置值
            TextView tv_upgraded_desc = layout.findViewById(R.id.tv_upgraded_desc);
            tv_upgraded_desc.setText(String.format("成功由%s\n升级为%s", notifyData.getFromLevelName(), notifyData.getToLevelName()));
 
            TextView tv_day = layout.findViewById(R.id.tv_day);
            ImageView iv_level = layout.findViewById(R.id.iv_now_level);
            TextView tv_detail = layout.findViewById(R.id.tv_detail);
 
            //String text=
 
            int year = notifyData.getDay() / 365;
            int day = notifyData.getDay() % 365;
            int start1 = -1;
            int end1 = -1;
            int start2 = -1;
            int end2 = -1;
            String st = "共耗时";
 
            if (year > 0) {
                start1 = st.length();
                st += year + "年";
                end1 = st.length() - 1;
            }
            if (day > 0) {
                start2 = st.length();
                st += day + "天";
                end2 = st.length() - 1;
            }
 
            Spannable style = new SpannableString(st);
            ForegroundColorSpan redSpan = new ForegroundColorSpan(Color.parseColor("#FFE270"));
            RelativeSizeSpan sizeSpan = new RelativeSizeSpan(1.333f);
            if (start1 >= 0) {
                style.setSpan(redSpan, start1, end1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                style.setSpan(sizeSpan, start1, end1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                style.setSpan(new StyleSpan(Typeface.BOLD), start1, end1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
 
            if (start2 >= 0) {
                redSpan = new ForegroundColorSpan(Color.parseColor("#FFE270"));
                sizeSpan = new RelativeSizeSpan(1.333f);
                style.setSpan(redSpan, start2, end2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                style.setSpan(sizeSpan, start2, end2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                style.setSpan(new StyleSpan(Typeface.BOLD), start2, end2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
 
            tv_day.setText(style);
 
            int resourceId = 0;
            switch (notifyData.getToLevel()) {
                case "vipPre1":
                    resourceId = R.drawable.vippre1_highlight;
                    break;
                case "vipPre2":
                    resourceId = R.drawable.vippre2_highlight;
                    break;
                case "vip":
                    resourceId = R.drawable.vip_highlight;
                    break;
                case "tearcher":
                    resourceId = R.drawable.tearcher_highlight;
            }
 
            iv_level.setImageResource(resourceId);
 
            tv_detail.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (!StringUtils.isNullOrEmpty(notifyData.getDetailLink())) {
                        context.startActivity(new Intent(context, ShareBrowserActivity.class).putExtra("url", notifyData.getDetailLink()));
                    }
                    if (dialog.isShowing())
                        dialog.dismiss();
                    if (positiveClickListener != null)
                        positiveClickListener.onClick(dialog, 1);
                }
            });
            layout.findViewById(R.id.iv_close).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (dialog.isShowing())
                        dialog.dismiss();
                    if (closeClickListener != null)
                        closeClickListener.onClick(dialog, 1);
                }
            });
 
 
            dialog.addContentView(layout, new FrameLayout.LayoutParams(
                    FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT));
 
            android.view.WindowManager.LayoutParams params = dialog.getWindow().getAttributes();
            params.width = android.view.WindowManager.LayoutParams.MATCH_PARENT;
            params.height = android.view.WindowManager.LayoutParams.MATCH_PARENT;
            dialog.getWindow().setAttributes(params);
            dialog.setCanceledOnTouchOutside(false);
            return dialog;
        }
 
        public Builder setCloseClickListener(OnClickListener closeClickListener) {
            this.closeClickListener = closeClickListener;
            return this;
        }
 
        public Builder setPositiveClickListener(OnClickListener positiveClickListener) {
            this.positiveClickListener = positiveClickListener;
            return this;
        }
 
        public Builder setData(VIPUpgradedNotify notifyData) {
            this.notifyData = notifyData;
            return this;
        }
    }
}