admin
2020-07-14 7af22bf20c862c8ab2270cfeef8f3530f174ac9f
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
package com.yeshi.ec.rebate.myapplication.ui.mine;
 
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
 
import com.wpc.library.util.SingleToast;
import com.wpc.library.util.common.StringUtils;
import com.wpc.library.widget.ClearEditText;
import com.yeshi.ec.rebate.myapplication.BasicTextHttpResponseHandler;
import com.yeshi.ec.rebate.myapplication.R;
import com.yeshi.ec.rebate.myapplication.ShoppingApi;
import com.yeshi.ec.rebate.myapplication.ui.BaseActivity;
import com.yeshi.ec.rebate.myapplication.ui.invite.ShareBrowserActivity;
import com.yeshi.ec.rebate.myapplication.ui.dialog.AddZFBInfoDialog;
import com.yeshi.ec.rebate.myapplication.ui.dialog.AddZFBInfoDialog2;
 
import org.apache.http.Header;
import org.json.JSONObject;
 
/**
 * Created by weikou2015 on 2018/5/30.
 */
 
public class AddZhifuBaoAccountActivity extends BaseActivity implements View.OnClickListener {
 
    private TextView tv_top_left, tv_top_middle, tv_confirm;
    private ClearEditText et_real_name, et_zhifubao_account;
    private ImageView iv_addzfb_doubt;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setShowRecommend(false);
        setContentView(R.layout.activity_add_zhifubao_account);
        tv_top_left = findViewById(R.id.tv_top_bar_left);
        tv_top_middle = findViewById(R.id.tv_top_bar_middle);
        tv_confirm = findViewById(R.id.tv_confirm);
        et_real_name = findViewById(R.id.et_real_name);
        iv_addzfb_doubt = findViewById(R.id.iv_addzfb_doubt);
        et_zhifubao_account = findViewById(R.id.et_zhifubao_account_num);
        tv_top_left.setText("返回");
        String title = getIntent().getStringExtra("title");
        if (!StringUtils.isEmpty(title)) {
            tv_top_middle.setText(title);
            if (title.equalsIgnoreCase("修改账号")) {
                getZFBInfo();
            }
        } else {
            tv_top_middle.setText("添加账号");
        }
 
        et_real_name.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
 
            }
 
            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
 
            }
 
            @Override
            public void afterTextChanged(Editable s) {
                try {
                    if (StringUtils.isEmpty(s.toString()) || StringUtils.isEmpty(et_zhifubao_account.getText().toString())) {
                        tv_confirm.setBackgroundResource(R.drawable.shape_mobile_login);
                        tv_confirm.setEnabled(false);
                    } else {
                        tv_confirm.setBackgroundResource(R.drawable.shape_mobile_login_light);
                        tv_confirm.setEnabled(true);
                    }
                } catch (NumberFormatException e) {
                    e.printStackTrace();
                }
            }
        });
        et_zhifubao_account.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
 
            }
 
            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
 
            }
 
            @Override
            public void afterTextChanged(Editable s) {
                try {
                    if (StringUtils.isEmpty(s.toString()) || StringUtils.isEmpty(et_real_name.getText().toString())) {
                        tv_confirm.setBackgroundResource(R.drawable.shape_mobile_login);
                        tv_confirm.setEnabled(false);
                    } else {
                        tv_confirm.setBackgroundResource(R.drawable.shape_mobile_login_light);
                        tv_confirm.setEnabled(true);
                    }
                } catch (NumberFormatException e) {
                    e.printStackTrace();
                }
            }
        });
 
        tv_top_left.setOnClickListener(this);
        tv_confirm.setOnClickListener(this);
        iv_addzfb_doubt.setOnClickListener(this);
 
        getRelativeLink();
    }
 
    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tv_top_bar_left:
                finish();
                break;
            case R.id.iv_addzfb_doubt:
                if (!StringUtils.isEmpty(alipayHelp)) {
                    Intent intent = new Intent(AddZhifuBaoAccountActivity.this, ShareBrowserActivity.class);
                    intent.putExtra("url", alipayHelp);
                    startActivity(intent);
                }
                break;
            case R.id.tv_confirm:
                if (StringUtils.isEmpty(et_real_name.getText().toString())) {
//                    SingleToast.showToast(AddZhifuBaoAccountActivity.this, "真实姓名不能为空");
                    Toast.makeText(AddZhifuBaoAccountActivity.this, "真实姓名不能为空", Toast.LENGTH_SHORT).show();
                    break;
                }
                if (StringUtils.isEmpty(et_zhifubao_account.getText().toString())) {
//                    SingleToast.showToast(AddZhifuBaoAccountActivity.this, "支付宝账号不能为空");
                    Toast.makeText(AddZhifuBaoAccountActivity.this, "支付宝账号不能为空", Toast.LENGTH_SHORT).show();
                    break;
                }
 
                AddZFBInfoDialog2.Builder builder = new AddZFBInfoDialog2.Builder(AddZhifuBaoAccountActivity.this);
                builder.setTitle("验证账号").setMessage("为验证您的提现账号准确性,系统将会自动打款0.1元到提现账号中。")
                        .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                addAccount();
                                dialogInterface.dismiss();
                            }
                        }).setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        dialogInterface.dismiss();
                    }
                }).create().show();
                break;
            default:
                break;
        }
    }
 
    private void getZFBInfo() {
        ShoppingApi.getZFBInfo(this, getSharedPreferences("user", MODE_PRIVATE).getString("uid", "0"), new BasicTextHttpResponseHandler() {
            @Override
            public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
                if (jsonObject.optString("code").equalsIgnoreCase("0")) {
                    et_zhifubao_account.setText(jsonObject.optJSONObject("data").optString("account"));
                    et_real_name.setText(jsonObject.optJSONObject("data").optString("name"));
                }
            }
 
            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
                super.onFailure(statusCode, headers, responseString, throwable);
            }
        });
    }
 
    String alipayHelp;
    String alipayBindFailReason;
 
    private void getRelativeLink() {
        ShoppingApi.getRelativeLink(this, new BasicTextHttpResponseHandler() {
            @Override
            public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
                if (jsonObject.optString("code").equalsIgnoreCase("0")) {
                    alipayHelp = jsonObject.optJSONObject("data").optString("alipayHelp");
                    alipayBindFailReason = jsonObject.optJSONObject("data").optString("alipayBindFailReason");
                }
            }
 
            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
                super.onFailure(statusCode, headers, responseString, throwable);
            }
        });
    }
 
    private void addAccount() {
        ShoppingApi.addZhifubaoAccount(AddZhifuBaoAccountActivity.this, getSharedPreferences("user", MODE_PRIVATE).getString("uid", "0"),
                et_real_name.getText().toString(), et_zhifubao_account.getText().toString(), new BasicTextHttpResponseHandler() {
                    @Override
                    public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
                        if (jsonObject.optString("code").equalsIgnoreCase("0")) {
                            AddZFBInfoDialog.Builder builder = new AddZFBInfoDialog.Builder(AddZhifuBaoAccountActivity.this);
                            builder.setTitle("验证账号").setMessage(jsonObject.optString("msg"))
                                    .setPositiveButton("知道了", new DialogInterface.OnClickListener() {
                                        @Override
                                        public void onClick(DialogInterface dialogInterface, int i) {
                                            dialogInterface.dismiss();
                                            finish();
                                        }
                                    }).create().show();
                        } else if (jsonObject.optString("code").equalsIgnoreCase("1")) {
                            AddZFBInfoDialog2.Builder builder = new AddZFBInfoDialog2.Builder(AddZhifuBaoAccountActivity.this);
                            builder.setTitle("验证账号").setMessage(jsonObject.optString("msg"))
                                    .setPositiveButton("知道了", new DialogInterface.OnClickListener() {
                                        @Override
                                        public void onClick(DialogInterface dialogInterface, int i) {
                                            dialogInterface.dismiss();
 
                                        }
                                    }).setNegativeButton("原因?", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    dialogInterface.dismiss();
                                    Intent intent = new Intent(AddZhifuBaoAccountActivity.this, ShareBrowserActivity.class);
                                    intent.putExtra("url", alipayBindFailReason);
                                    startActivity(intent);
                                }
                            }).create().show();
                        } else if (jsonObject.optString("code").equalsIgnoreCase("2")) {
                            AddZFBInfoDialog.Builder builder = new AddZFBInfoDialog.Builder(AddZhifuBaoAccountActivity.this);
                            builder.setTitle("验证账号").setMessage(jsonObject.optString("msg"))
                                    .setPositiveButton("知道了", new DialogInterface.OnClickListener() {
                                        @Override
                                        public void onClick(DialogInterface dialogInterface, int i) {
                                            dialogInterface.dismiss();
                                        }
                                    }).create().show();
                        } else {
                            AddZFBInfoDialog.Builder builder = new AddZFBInfoDialog.Builder(AddZhifuBaoAccountActivity.this);
                            builder.setTitle("验证账号结果").setMessage(jsonObject.optString("msg"))
                                    .setPositiveButton("知道了", new DialogInterface.OnClickListener() {
                                        @Override
                                        public void onClick(DialogInterface dialogInterface, int i) {
                                            dialogInterface.dismiss();
                                        }
                                    }).create().show();
                        }
                    }
                });
    }
}