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();
|
}
|
}
|
});
|
}
|
}
|