admin
2021-07-08 1764c1784a4cf1a6afd25fcf1a0eef6187a84218
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
package com.tejia.lijin.app.ui.dialog;
 
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.text.method.ScrollingMovementMethod;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;
import android.widget.Toast;
 
import com.wpc.library.util.SystemCommon;
import com.tejia.lijin.app.BasicTextHttpResponseHandler;
import com.tejia.lijin.app.R;
import com.tejia.lijin.app.ShoppingApi;
import com.tejia.lijin.app.entity.TaoBaoGoodsBrief;
import com.tejia.lijin.app.entity.recommendinfo.ConvertLinkInfo;
import com.tejia.lijin.app.entity.recommendinfo.JumpUnit;
import com.tejia.lijin.app.util.JumpActivityUtil;
import com.tejia.lijin.app.util.clipboard.ClipboardUtil;
import com.tejia.lijin.app.util.user.UserUtil;
 
import org.apache.http.Header;
import org.json.JSONObject;
 
/**
 * 转链
 * Created by weikou2015 on 2017/2/28.
 */
 
public class ConvertLinkDialog extends Dialog {
 
    public ConvertLinkDialog(Context context) {
        super(context);
        this.setCancelable(false);
    }
 
    public ConvertLinkDialog(Context context, int theme) {
        super(context, theme);
        this.setCancelable(false);
    }
 
    public static class Builder {
        private Activity context;
        private TaoBaoGoodsBrief taoBaoGoodsBrief;
        private String positiveButtonText;
        private String negativeButtonText;
        private OnClickListener positiveButtonClickListener;
        private OnClickListener negativeButtonClickListener;
        private int type = 0;//默认为0
 
        private ConvertLinkInfo convertLinkInfo;
 
        public Builder(Activity context) {
            this.context = context;
        }
 
        public Builder setMessage(TaoBaoGoodsBrief taoBaoGoodsBrief) {
            this.taoBaoGoodsBrief = taoBaoGoodsBrief;
            return this;
        }
 
        public Builder setType(int type) {/**判断是否未加入淘宝联盟*/
            this.type = type;
            return this;
        }
 
        public Builder setConvertLinkInfo(ConvertLinkInfo convertLinkInfo) {/**判断是否未加入淘宝联盟*/
            this.convertLinkInfo = convertLinkInfo;
            return this;
        }
 
        private void clearClipBoard() {
            ClipboardUtil.emptyClipboard(context);
 
        }
 
        public ConvertLinkDialog create() {
            LayoutInflater inflater = (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            final ConvertLinkDialog dialog = new ConvertLinkDialog(context, R.style.Dialog1);
            View layout = inflater.inflate(R.layout.item_convert_link, null);
            dialog.addContentView(layout, new FrameLayout.LayoutParams(
                    FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT));
            layout.findViewById(R.id.iv_cancle).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (dialog != null && dialog.isShowing())
                        dialog.dismiss();
                    clearClipBoard();
                }
            });
 
            TextView tv_go = layout.findViewById(R.id.tv_go);
            TextView tv_convert = layout.findViewById(R.id.tv_convert);
            TextView tv_title = layout.findViewById(R.id.tv_title);
            TextView tv_state_desc = layout.findViewById(R.id.tv_state_desc);
            final TextView tv_text = layout.findViewById(R.id.tv_text);
            tv_text.setMovementMethod(ScrollingMovementMethod.getInstance());
            tv_text.setHighlightColor(context.getResources().getColor(android.R.color.transparent));
            //设置按钮背景
            dialog.setContentView(layout);
            //赋值
            tv_title.setText(convertLinkInfo.getTitle());
            tv_text.setText(convertLinkInfo.getText());
            if (convertLinkInfo.getState() == ConvertLinkInfo.STATE_CONVERT) {
                tv_go.setVisibility(View.VISIBLE);
                tv_convert.setVisibility(View.GONE);
                tv_go.setText("转链");
                tv_go.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        clearClipBoard();
                        toConvert(tv_text.getText() + "", convertLinkInfo.getConvert(), new IConvertResult() {
                            @Override
                            public void onSuccess() {
                                if (dialog.isShowing())
                                    dialog.dismiss();
                            }
                        });
                    }
                });
            } else if (convertLinkInfo.getState() == ConvertLinkInfo.STATE_CONVERT_VIEW) {
                tv_go.setVisibility(View.VISIBLE);
                tv_convert.setVisibility(View.VISIBLE);
                tv_convert.setText("转链");
                tv_go.setText("去看看");
                tv_convert.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        clearClipBoard();
                        toConvert(tv_text.getText() + "", convertLinkInfo.getConvert(), new IConvertResult() {
                            @Override
                            public void onSuccess() {
                                if (dialog.isShowing())
                                    dialog.dismiss();
                            }
                        });
                    }
                });
                tv_go.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        clearClipBoard();
                        JumpActivityUtil.jumpPage(context, convertLinkInfo.getView().getJumpDetail(), convertLinkInfo.getView().getParams());
                        if (dialog.isShowing())
                            dialog.dismiss();
                    }
                });
            } else if (convertLinkInfo.getState() == ConvertLinkInfo.STATE_GUESS_LIKE) {
                tv_go.setVisibility(View.VISIBLE);
                tv_convert.setVisibility(View.GONE);
                tv_go.setText("猜你喜欢");
                tv_go.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        clearClipBoard();
                        JumpActivityUtil.jumpPage(context, convertLinkInfo.getGuessLike().getJumpDetail(), convertLinkInfo.getGuessLike().getParams());
                        if (dialog.isShowing())
                            dialog.dismiss();
                    }
                });
            }
 
            tv_state_desc.setText(convertLinkInfo.getStateDesc());
 
            android.view.WindowManager.LayoutParams params = dialog.getWindow().getAttributes();
            params.width = (int) ((SystemCommon.getScreenWidth(context) * 19) / 23);
            params.height = android.view.WindowManager.LayoutParams.WRAP_CONTENT;
            dialog.getWindow().setAttributes(params);
            dialog.setCanceledOnTouchOutside(false);
            return dialog;
        }
 
        ShapeLoadingDialog pd = null;
 
        private void toConvert(String text, final JumpUnit jump, final IConvertResult result) {
            if (pd == null) {
                pd = new ShapeLoadingDialog.Builder(context).build();
            }
            if (!pd.isShowing())
                pd.show();
 
            Long uid = UserUtil.getUid(context);
            ShoppingApi.setConvertLinkDoc(context, text, uid, new BasicTextHttpResponseHandler() {
                @Override
                public void onStart() {
                    super.onStart();
                }
 
                @Override
                public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
                    if (jsonObject.optInt("code") == 0) {
                        result.onSuccess();
                        JumpActivityUtil.jumpPage(context, jump.getJumpDetail(), jump.getParams());
                    } else {
                        Toast.makeText(context, jsonObject.optString("msg"), Toast.LENGTH_SHORT).show();
                    }
                }
 
                @Override
                public void onFinish() {
                    super.onFinish();
                    if (pd.isShowing())
                        pd.dismiss();
                }
            });
        }
 
        interface IConvertResult {
            public void onSuccess();
        }
    }
}