wjc
2025-03-13 03b946c13bbc7deb79a91412af5b135cc3bd0fb2
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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
package com.hdl.photovoltaic.ui.me;
 
 
import android.os.Bundle;
import android.os.CountDownTimer;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
 
import com.hdl.linkpm.sdk.core.exception.HDLException;
import com.hdl.photovoltaic.R;
import com.hdl.photovoltaic.base.CustomBaseActivity;
import com.hdl.photovoltaic.config.UserConfigManage;
import com.hdl.photovoltaic.databinding.ActivityBindPhoneBinding;
import com.hdl.photovoltaic.listener.CloudCallBeak;
import com.hdl.photovoltaic.other.HdlAccountLogic;
import com.hdl.photovoltaic.other.HdlCommonLogic;
import com.hdl.photovoltaic.other.HdlLogLogic;
import com.hdl.photovoltaic.other.HdlThreadLogic;
import com.sahooz.library.countrypicker.Country;
import com.sahooz.library.countrypicker.CountryPickerFragment;
import com.sahooz.library.countrypicker.PickCountryCallback;
 
/**
 * 修改绑定手机号的界面
 */
public class BindPhoneActivity extends CustomBaseActivity {
 
    private ActivityBindPhoneBinding viewBinding;
 
    @Override
    public Object getContentView() {
        viewBinding = ActivityBindPhoneBinding.inflate(getLayoutInflater());
        return viewBinding.getRoot();
    }
 
    @Override
    public void onBindView(Bundle savedInstanceState) {
        setStatusBarTranslucent();
        getWindow().setNavigationBarColor(getColor(R.color.text_FF000000));
        //初始化
        initView();
        //初始化界面监听器
        initEvent();
 
    }
 
    private void initEvent() {
 
        viewBinding.toolbarTopRl.topBackLl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                setResult(20);
                finish();
            }
        });
        viewBinding.bindAreaParentRl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                selectArea();
            }
        });
 
        viewBinding.bindPhoneVerificationCodeRl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                sendVerification();
            }
        });
 
        viewBinding.bindPhoneClearIv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                viewBinding.bindPhoneEt.setText("");
            }
        });
 
        //输入账号
        viewBinding.bindPhoneEt.addTextChangedListener(accountTextWatcher);
        //输入验证码
        viewBinding.changePhoneVerificationEt.addTextChangedListener(verificationCodeTextWatcher);
        viewBinding.bindPhoneTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (isEnabled()) {
                    String phoneStr = viewBinding.bindPhoneEt.getText().toString();
                    String verificationStr = viewBinding.changePhoneVerificationEt.getText().toString();
                    HdlAccountLogic.getInstance().bindingAccount_C(phoneStr, "", verificationStr, new CloudCallBeak<Boolean>() {
                        @Override
                        public void onSuccess(Boolean obj) {
                            UserConfigManage.getInstance().setBingPhone(phoneStr);
                            UserConfigManage.getInstance().Save();
                            setResult(20);
                            finish();
                        }
 
                        @Override
                        public void onFailure(HDLException e) {
                            HdlThreadLogic.tipFlashingBox(_mActivity, false, e.getMsg(), e.getCode());
                        }
                    });
                }
            }
        });
 
    }
 
    private void initView() {
        if (UserConfigManage.getInstance().isZh()) {
            viewBinding.bindAreaTv.setText(getText(R.string.home_chinese_mainland));
            viewBinding.bindAreaNumberTv.setText("+86");
        } else {
            viewBinding.bindAreaTv.setText(getText(R.string.iraq));
            viewBinding.bindAreaNumberTv.setText("+964");
        }
        viewBinding.toolbarTopRl.topTitleTv.setText(R.string.set_change_bind_phone_number);
        viewBinding.toolbarTopRl.topBackLl.setVisibility(View.VISIBLE);
 
        checkClearIconShowOrNot(viewBinding.bindPhoneEt.getText().toString());
        try {
            Country.load(this);
        } catch (Exception e) {
            e.printStackTrace();
        }
        HdlCommonLogic.getInstance().setSpan(viewBinding.bindPhoneVerificationTv, viewBinding.bindPhoneVerificationTv.getText().toString(), true, null);
    }
 
    /**
     * 国家手机号区号弹窗
     */
    private void selectArea() {
        CountryPickerFragment dialog = new CountryPickerFragment(this, new PickCountryCallback() {
            @Override
            public void onPick(Country country) {
                if (country.flag != 0)
                    viewBinding.bindAreaTv.setText(country.translate);
                String code = "+" + country.code;
                viewBinding.bindAreaNumberTv.setText(code);
            }
        });
        dialog.show();
        dialog.setDialogSize();
    }
 
    /**
     * 发送验证码指令
     */
    private void sendVerification() {
 
        String account = viewBinding.bindPhoneEt.getText().toString();
        if (TextUtils.isEmpty(account)) {
            HdlThreadLogic.tipFlashingBox(this, false, getString(R.string.home_login_phone_null), -1);
            return;
        }
        HdlAccountLogic.getInstance().sendVerifyCode(true, account, viewBinding.bindAreaNumberTv.getText().toString(), 3, new CloudCallBeak<Boolean>() {
            @Override
            public void onSuccess(Boolean obj) {
                countDownTimer.start();
            }
 
            @Override
            public void onFailure(HDLException e) {
                HdlThreadLogic.tipFlashingBox(_mActivity, false, e.getMsg(), e.getCode());
                HdlLogLogic.print(e.getMessage(), e.getCode(), true);
            }
        });
 
    }
 
    /**
     * 初始化手机号计时器
     */
    CountDownTimer countDownTimer = new CountDownTimer(60 * 1000, 1000) {
        @Override
        public void onTick(long millisUntilFinished) {
            long time = (millisUntilFinished / 1000);
            String str = time + "s" + getString(R.string.home_login_psw_verification_repeater);
            viewBinding.bindPhoneVerificationTv.setText(str);
            viewBinding.bindPhoneVerificationTv.setEnabled(false);
 
        }
 
        @Override
        public void onFinish() {
            viewBinding.bindPhoneVerificationTv.setText(getString(R.string.home_login_verification_regain));
            viewBinding.bindPhoneVerificationTv.setEnabled(true);
 
 
        }
    };
 
    /**
     * 检测清除图标是否显示
     */
    private void checkClearIconShowOrNot(String s) {
        if (s.replace(" ", "").length() > 0) {
            if (viewBinding.bindPhoneClearIv.getVisibility() == View.GONE) {
                viewBinding.bindPhoneClearIv.setVisibility(View.VISIBLE);
            }
        } else {
            if (viewBinding.bindPhoneClearIv.getVisibility() == View.VISIBLE) {
                viewBinding.bindPhoneClearIv.setVisibility(View.GONE);
            }
        }
    }
 
    /**
     * 校验确认按钮是否启用
     */
    private boolean isEnabled() {
        String account = viewBinding.bindPhoneEt.getText().toString().replace(" ", "");
        String verificationCode = viewBinding.changePhoneVerificationEt.getText().toString().replace(" ", "");
        boolean isEnabled = account.length() > 0 && verificationCode.length() > 0;
        if (isEnabled) {
            viewBinding.bindPhoneTv.setTextColor(getColor(R.color.text_E6FFFFFF));
        } else {
            viewBinding.bindPhoneTv.setTextColor(getColor(R.color.text_66FFFFFF));
        }
        viewBinding.bindPhoneTv.setEnabled(isEnabled);
        return isEnabled;
 
    }
 
 
    /**
     * 本地校验
     */
    private boolean isLocalCheck() {
        String phoneStr = viewBinding.bindPhoneEt.getText().toString();
        String verificationStr = viewBinding.changePhoneVerificationEt.getText().toString();
        if (TextUtils.isEmpty(phoneStr)) {
            HdlThreadLogic.tipFlashingBox(this, false, getString(R.string.home_login_phone_null), -1);
            return false;
        }
        if (TextUtils.isEmpty(verificationStr)) {
            HdlThreadLogic.tipFlashingBox(this, false, getString(R.string.home_login_null_verification_code), -1);
            return false;
        }
        return true;
 
    }
 
    /**
     * 输入账号
     */
    private final TextWatcher accountTextWatcher = new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
 
        }
 
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }
 
        @Override
        public void afterTextChanged(Editable s) {
            checkClearIconShowOrNot(s.toString());
            isEnabled();
        }
    };
 
    /**
     * 输入验证码
     */
    private final TextWatcher verificationCodeTextWatcher = new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
 
        }
 
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }
 
        @Override
        public void afterTextChanged(Editable s) {
            isEnabled();
        }
    };
 
    @Override
    protected void onDestroy() {
        super.onDestroy();
        Country.destroy();
        if (countDownTimer != null) {
            countDownTimer.cancel();
            countDownTimer = null;
        }
        viewBinding.bindPhoneEt.removeTextChangedListener(accountTextWatcher);
        viewBinding.changePhoneVerificationEt.removeTextChangedListener(verificationCodeTextWatcher);
 
    }
 
    /**
     * 物理按键返回事件
     */
    @Override
    public void onBackPressed() {
        setResult(20);
        super.onBackPressed();
    }
}