|
@@ -1,20 +1,76 @@
|
|
|
package com.ynstkz.shitu.android.activity;
|
|
|
|
|
|
+import android.app.ProgressDialog;
|
|
|
import android.os.Bundle;
|
|
|
import android.support.annotation.Nullable;
|
|
|
+import android.view.View;
|
|
|
+import android.widget.ImageView;
|
|
|
+import android.widget.RelativeLayout;
|
|
|
+import android.widget.TextView;
|
|
|
|
|
|
+import com.common.library.okhttp.callback.Callback;
|
|
|
+import com.google.gson.Gson;
|
|
|
import com.ynstkz.shitu.android.R;
|
|
|
+import com.ynstkz.shitu.android.base.BaseBean;
|
|
|
import com.ynstkz.shitu.android.base.TitleBarActivity;
|
|
|
+import com.ynstkz.shitu.android.bean.BindInfoBean;
|
|
|
+import com.ynstkz.shitu.android.data.RequestGroup;
|
|
|
+import com.ynstkz.shitu.android.helper.UmengLoginHelper;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+import butterknife.Bind;
|
|
|
+import okhttp3.Call;
|
|
|
+import okhttp3.Response;
|
|
|
|
|
|
/**
|
|
|
* 作者:fuchangle on 2018/2/12 10:52
|
|
|
*/
|
|
|
|
|
|
-public class BindThreeAccountActivity extends TitleBarActivity{
|
|
|
+public class BindThreeAccountActivity extends TitleBarActivity {
|
|
|
+
|
|
|
+ @Bind(R.id.tv_title)
|
|
|
+ TextView tvTitle;
|
|
|
+ @Bind(R.id.view_title)
|
|
|
+ RelativeLayout viewTitle;
|
|
|
+ @Bind(R.id.iv_weixin_icon)
|
|
|
+ ImageView ivWeixinIcon;
|
|
|
+ @Bind(R.id.tv_weixin_state)
|
|
|
+ TextView tvWeixinState;
|
|
|
+ @Bind(R.id.iv_weixin_go)
|
|
|
+ ImageView ivWeixinGo;
|
|
|
+ @Bind(R.id.rl_weixin)
|
|
|
+ RelativeLayout rlWeixin;
|
|
|
+ @Bind(R.id.iv_qq_icon)
|
|
|
+ ImageView ivQqIcon;
|
|
|
+ @Bind(R.id.tv_qq_state)
|
|
|
+ TextView tvQqState;
|
|
|
+ @Bind(R.id.iv_qq_go)
|
|
|
+ ImageView ivQqGo;
|
|
|
+ @Bind(R.id.rl_qq)
|
|
|
+ RelativeLayout rlQq;
|
|
|
+ @Bind(R.id.iv_sina_icon)
|
|
|
+ ImageView ivSinaIcon;
|
|
|
+ @Bind(R.id.tv_sina_state)
|
|
|
+ TextView tvSinaState;
|
|
|
+ @Bind(R.id.iv_sina_go)
|
|
|
+ ImageView ivSinaGo;
|
|
|
+ @Bind(R.id.rl_sina)
|
|
|
+ RelativeLayout rlSina;
|
|
|
+
|
|
|
+ private boolean isBindQQ;
|
|
|
+ private boolean isBindWx;
|
|
|
+ private boolean isBindWb;
|
|
|
+
|
|
|
+ private ProgressDialog progressDialog;
|
|
|
|
|
|
@Override
|
|
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
|
|
super.onCreate(savedInstanceState);
|
|
|
+ initView();
|
|
|
+ initData();
|
|
|
+ setListener();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -22,5 +78,227 @@ public class BindThreeAccountActivity extends TitleBarActivity{
|
|
|
return R.layout.activity_bindthreeaccount;
|
|
|
}
|
|
|
|
|
|
+ private void initView(){
|
|
|
+ tvTitle.setText("绑定账号");
|
|
|
+ }
|
|
|
+
|
|
|
+ private void initData(){
|
|
|
+
|
|
|
+ getThirdInfo();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void setListener(){
|
|
|
+ //qq
|
|
|
+ rlQq.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View view) {
|
|
|
+ if(isBindQQ){
|
|
|
+ thirdUnBind(LoginActivity.KEY_QQ);
|
|
|
+ } else {
|
|
|
+ threeAuthorization(UmengLoginHelper.QQ);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ //wx
|
|
|
+ rlWeixin.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View view) {
|
|
|
+ if(isBindWx){
|
|
|
+ thirdUnBind(LoginActivity.KEY_WEIXIN);
|
|
|
+ } else {
|
|
|
+ threeAuthorization(UmengLoginHelper.WX);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ //sina
|
|
|
+ rlSina.setOnClickListener(new View.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(View view) {
|
|
|
+ if(isBindWb){
|
|
|
+ thirdUnBind(LoginActivity.KEY_SINA);
|
|
|
+ } else {
|
|
|
+ threeAuthorization(UmengLoginHelper.SINA);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取用户绑定信息
|
|
|
+ */
|
|
|
+ private void getThirdInfo(){
|
|
|
+
|
|
|
+ RequestGroup.getThirdInfo(new Callback() {
|
|
|
+ @Override
|
|
|
+ public Object parseNetworkResponse(Response response, int id) throws Exception {
|
|
|
+ return new Gson().fromJson(response.body().string(), BindInfoBean.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onError(Call call, Exception e, int id) {
|
|
|
+ showToast(getString(R.string.error_msg));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onResponse(Object response, int id) {
|
|
|
+ BindInfoBean bindInfoBean = (BindInfoBean)response;
|
|
|
+ if(bindInfoBean != null){
|
|
|
+ if("200".equals(bindInfoBean.getCode())){
|
|
|
+ if(bindInfoBean.getData() != null){
|
|
|
+ initBindInfo(bindInfoBean.getData());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ showToast(bindInfoBean.getMsg());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 初始化绑定信息
|
|
|
+ * @param listDatas
|
|
|
+ */
|
|
|
+ private void initBindInfo(List<BindInfoBean.DataBean> listDatas){
|
|
|
+
|
|
|
+ isBindQQ = false;
|
|
|
+ isBindWx = false;
|
|
|
+ isBindWb = false;
|
|
|
+
|
|
|
+ tvQqState.setText("未绑定");
|
|
|
+ tvWeixinState.setText("未绑定");
|
|
|
+ tvSinaState.setText("未绑定");
|
|
|
+
|
|
|
+ if(listDatas == null || listDatas.size() == 0){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ for(BindInfoBean.DataBean dataBean :listDatas){
|
|
|
+ switch (dataBean.getThirdType()) {
|
|
|
+ case LoginActivity.KEY_QQ :
|
|
|
+ isBindQQ = true;
|
|
|
+ tvQqState.setText("已绑定");
|
|
|
+ break;
|
|
|
+ case LoginActivity.KEY_WEIXIN :
|
|
|
+ isBindWx = true;
|
|
|
+ tvWeixinState.setText("已绑定");
|
|
|
+ break;
|
|
|
+ case LoginActivity.KEY_SINA :
|
|
|
+ isBindWb = true;
|
|
|
+ tvSinaState.setText("已绑定");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *第三方授权
|
|
|
+ */
|
|
|
+ private void threeAuthorization(final String type){
|
|
|
+
|
|
|
+ progressDialog = new ProgressDialog(this);
|
|
|
+ progressDialog.setMessage("正在请求授权...");
|
|
|
+ progressDialog.show();
|
|
|
+
|
|
|
+ UmengLoginHelper mLogin = new UmengLoginHelper(BindThreeAccountActivity.this, new UmengLoginHelper.Callback() {
|
|
|
+ @Override
|
|
|
+ public void onComplete(Map<String, String> data) {
|
|
|
+ if(type.equals(UmengLoginHelper.QQ)){
|
|
|
+ thirdBind(data.get("uid"), LoginActivity.KEY_QQ);
|
|
|
+ } else if (type.equals(UmengLoginHelper.WX)){
|
|
|
+ thirdBind(data.get("uid"), LoginActivity.KEY_WEIXIN);
|
|
|
+ } else if (type.equals(UmengLoginHelper.SINA)) {
|
|
|
+ thirdBind(data.get("uid"), LoginActivity.KEY_SINA);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onError() {
|
|
|
+ if(progressDialog != null){
|
|
|
+ progressDialog.dismiss();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onCancel() {
|
|
|
+ if(progressDialog != null){
|
|
|
+ progressDialog.dismiss();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ mLogin.oAuth(type);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 三方账号绑定
|
|
|
+ * @param thirdId
|
|
|
+ * @param thirdType
|
|
|
+ */
|
|
|
+ private void thirdBind(String thirdId, String thirdType) {
|
|
|
+
|
|
|
+ if(progressDialog != null){
|
|
|
+ progressDialog.setMessage("正在绑定...");
|
|
|
+ }
|
|
|
+
|
|
|
+ RequestGroup.thirdBind(thirdId, thirdType, new Callback() {
|
|
|
+ @Override
|
|
|
+ public Object parseNetworkResponse(Response response, int id) throws Exception {
|
|
|
+ return new Gson().fromJson(response.body().string(), BaseBean.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onError(Call call, Exception e, int id) {
|
|
|
+ showToast(e.getMessage());
|
|
|
+ if(progressDialog != null){
|
|
|
+ progressDialog.dismiss();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onResponse(Object response, int id) {
|
|
|
+ if(progressDialog != null){
|
|
|
+ progressDialog.dismiss();
|
|
|
+ }
|
|
|
+ BaseBean baseBean = (BaseBean) response;
|
|
|
+ if (baseBean != null) {
|
|
|
+ if ("200".equals(baseBean.getCode())) {
|
|
|
+ getThirdInfo();
|
|
|
+ }
|
|
|
+ showToast(baseBean.getMsg());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 解绑
|
|
|
+ * @param thirdType
|
|
|
+ */
|
|
|
+ private void thirdUnBind(String thirdType){
|
|
|
+
|
|
|
+ RequestGroup.thirdUnBind(thirdType, new Callback() {
|
|
|
+ @Override
|
|
|
+ public Object parseNetworkResponse(Response response, int id) throws Exception {
|
|
|
+ return new Gson().fromJson(response.body().string(), BaseBean.class);
|
|
|
+ }
|
|
|
|
|
|
+ @Override
|
|
|
+ public void onError(Call call, Exception e, int id) {
|
|
|
+ showToast(e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onResponse(Object response, int id) {
|
|
|
+ BaseBean baseBean = (BaseBean) response;
|
|
|
+ if (baseBean != null) {
|
|
|
+ if ("200".equals(baseBean.getCode())) {
|
|
|
+ getThirdInfo();
|
|
|
+ }
|
|
|
+ showToast(baseBean.getMsg());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|