From 7af22bf20c862c8ab2270cfeef8f3530f174ac9f Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期二, 14 七月 2020 18:37:30 +0800
Subject: [PATCH] '完善'

---
 MDShopping/src/main/java/com/yeshi/ec/rebate/myapplication/ui/mine/LoginActivity.java |  195 +++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 190 insertions(+), 5 deletions(-)

diff --git a/MDShopping/src/main/java/com/yeshi/ec/rebate/myapplication/ui/mine/LoginActivity.java b/MDShopping/src/main/java/com/yeshi/ec/rebate/myapplication/ui/mine/LoginActivity.java
index 3c18a57..70e0bc4 100644
--- a/MDShopping/src/main/java/com/yeshi/ec/rebate/myapplication/ui/mine/LoginActivity.java
+++ b/MDShopping/src/main/java/com/yeshi/ec/rebate/myapplication/ui/mine/LoginActivity.java
@@ -4,8 +4,11 @@
 import android.content.Intent;
 import android.content.SharedPreferences;
 import android.os.Bundle;
+import android.text.Editable;
+import android.text.TextWatcher;
 import android.util.Log;
 import android.view.View;
+import android.widget.EditText;
 import android.widget.ImageView;
 import android.widget.LinearLayout;
 import android.widget.TextView;
@@ -18,6 +21,7 @@
 import com.google.gson.GsonBuilder;
 import com.google.gson.reflect.TypeToken;
 import com.umeng.analytics.MobclickAgent;
+import com.wpc.library.util.GetManifestDataUtil;
 import com.wpc.library.util.common.StringUtils;
 import com.xiaomi.mipush.sdk.MiPushClient;
 import com.yeshi.ec.rebate.myapplication.BasicTextHttpResponseHandler;
@@ -28,12 +32,16 @@
 import com.yeshi.ec.rebate.myapplication.ui.dialog.ShapeLoadingDialog;
 import com.yeshi.ec.rebate.myapplication.ui.invite.ShareBrowserActivity;
 import com.yeshi.ec.rebate.myapplication.util.KeFuUtil;
+import com.yeshi.ec.rebate.myapplication.util.SystemParamsUtil;
 import com.yeshi.ec.rebate.myapplication.util.TopStatusSettings;
 import com.yeshi.ec.rebate.myapplication.util.umengCustomEvent.UserCustomEvent;
 import com.yeshi.ec.rebate.myapplication.util.user.UserUtil;
 
 import org.apache.http.Header;
 import org.json.JSONObject;
+
+import java.util.Timer;
+import java.util.TimerTask;
 
 import de.greenrobot.event.EventBus;
 
@@ -47,7 +55,7 @@
     public final static int TYPE_BIND = 2;//缁戝畾
     public final static int TYPE_BIND_WITHOUT_LOGINED = 3;//鏈櫥褰曠粦瀹�
     private ImageView iv_close, iv_contact_kefu, iv_login_tb;
-    private TextView tv_user_agreement, tv_privacy_policies;
+    private TextView tv_user_agreement, tv_privacy_policies, tv_login;
     LinearLayout ll_user_agreement;
     ShapeLoadingDialog pd;
     String uid;
@@ -56,20 +64,39 @@
     String key;//寰俊鐧诲綍灏氭湭缁戝畾鎵嬫満鏃跺洖浼犵殑鏍囪瘑
 
     private static String TAG = "LoginSelectActivity";
+    private LinearLayout ll_phone;
+    private TextView tv_send_code, tv_login_phone;
+    private EditText et_phone, et_code;
+
+    //璁剧疆瑙嗗浘
+    private void setView(boolean onlining) {
+        if (onlining) {
+            ll_phone.setVisibility(View.VISIBLE);
+            tv_login.setVisibility(View.GONE);
+        } else {
+            ll_phone.setVisibility(View.GONE);
+            tv_login.setVisibility(View.VISIBLE);
+        }
+    }
+
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_login);
-
         pd = new ShapeLoadingDialog.Builder(this).build();
-
         TopStatusSettings.setStatusViewAndDeepColorNoView(this);
-//        tv_user_agreement.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
         initData(getIntent());
         String from = getIntent().getStringExtra("from");
         UserCustomEvent.userLogin(this, StringUtils.isEmpty(from) ? "鍏跺畠" : from);
         EventBus.getDefault().register(this);
+        String onlining = "";
+        String channel = GetManifestDataUtil.getAppMetaData(this, "UMENG_CHANNEL");
+        if ("QQ".equalsIgnoreCase(channel)) {
+            onlining = SystemParamsUtil.getParam(this, "onlining");
+        }
+
+        setView("1".equalsIgnoreCase(onlining) ? true : false);
     }
 
     private void initData(Intent intent) {
@@ -77,6 +104,8 @@
         init(intent);
         addListener();
     }
+
+    Timer timer = null;
 
     @Override
     protected void onNewIntent(Intent intent) {
@@ -89,6 +118,11 @@
         鍒濆鍖栨帶浠�
          */
     private void init(Intent intent) {
+        ll_phone = findViewById(R.id.ll_phone);
+        tv_send_code = findViewById(R.id.tv_send_code);
+        tv_login_phone = findViewById(R.id.tv_login_phone);
+        et_phone = findViewById(R.id.et_phone);
+        et_code = findViewById(R.id.et_code);
         iv_close = findViewById(R.id.iv_close);
         iv_contact_kefu = findViewById(R.id.iv_contact_kefu);
         tv_user_agreement = findViewById(R.id.tv_user_agreement);
@@ -96,14 +130,80 @@
         tv_privacy_policies = findViewById(R.id.tv_privacy_policies);
         iv_login_tb = findViewById(R.id.iv_login_tb);
         ll_user_agreement = findViewById(R.id.ll_user_agreement);
-        findViewById(R.id.tv_login).setOnClickListener(this);
+        tv_login = findViewById(R.id.tv_login);
+        tv_login.setOnClickListener(this);
         iv_login_tb.setOnClickListener(this);
         SharedPreferences sp = getSharedPreferences("user", MODE_PRIVATE);
         sp.edit().putBoolean("first", true).commit();
         uid = intent.getStringExtra("uid");
         key = intent.getStringExtra("key");
         getUserConfig();
+
+        tv_login_phone.setOnClickListener(this);
+        tv_send_code.setOnClickListener(this);
+
+        et_code.addTextChangedListener(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) {
+                setSetLoginPhoneState();
+            }
+        });
+
+
+        et_phone.addTextChangedListener(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) {
+                setSendCodeState();
+                setSetLoginPhoneState();
+            }
+        });
+        setSendCodeState();
+        setSetLoginPhoneState();
     }
+
+    private void setSetLoginPhoneState() {
+        //鏄墜鏈哄彿鐮�
+        if (StringUtils.isMobileNumber(et_phone.getText() + "") && et_code.getText() != null && !StringUtils.isEmpty(et_code.getText() + "")) {
+            tv_login_phone.setBackgroundResource(R.drawable.shape_mobile_login_light);
+            tv_login_phone.setEnabled(true);
+        } else {
+            tv_login_phone.setBackgroundResource(R.drawable.shape_mobile_login);
+            tv_login_phone.setEnabled(false);
+        }
+    }
+
+    private void setSendCodeState() {
+        if (StringUtils.isMobileNumber(et_phone.getText() + "") && lastTime == 0) {
+            tv_send_code.setEnabled(true);
+            tv_send_code.setTextColor(getResources().getColor(R.color.theme));
+        } else {
+            tv_send_code.setEnabled(false);
+            tv_send_code.setTextColor(getResources().getColor(R.color.gray));
+        }
+    }
+
+
+    int lastTime = 0;
 
     /*
      *娣诲姞鐩戝惉
@@ -173,9 +273,94 @@
                         }
                     });
                 break;
+
+            case R.id.tv_send_code://鍙戦�侀獙璇佺爜
+                if (timer != null) {
+                    timer.cancel();
+                    timer = null;
+                }
+                Toast.makeText(this, "楠岃瘉鐮佸凡鍙戦�侊紝璇锋敞鎰忔煡鏀�", Toast.LENGTH_SHORT);
+                lastTime = 60;
+                setSendCodeState();
+                timer = new Timer();
+                timer.schedule(new TimerTask() {
+                    @Override
+                    public void run() {
+                        tv_send_code.post(new Runnable() {
+                            @Override
+                            public void run() {
+                                if (lastTime > 0) {
+                                    lastTime--;
+                                    tv_send_code.setText(lastTime + "s閲嶅彂");
+                                    if (lastTime <= 0) {
+                                        lastTime = 0;
+                                        setSendCodeState();
+                                        timer.cancel();
+                                        tv_send_code.setText("鍙戦�侀獙璇佺爜");
+                                    }
+                                }
+                            }
+                        });
+                    }
+                }, 0, 1000);
+
+
+                break;
+
+            case R.id.tv_login_phone://鐧诲綍
+                loginPhone();
+                break;
         }
     }
 
+    private void loginPhone() {
+        ShoppingApi.loginNew(getApplicationContext(), et_code.getText() + "", et_phone.getText() + "", "", "1", new BasicTextHttpResponseHandler() {
+            @Override
+            public void onStart() {
+                super.onStart();
+                if (!pd.isShowing())
+                    pd.show();
+            }
+
+            @Override
+            public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
+                if (jsonObject.optString("code").equalsIgnoreCase("0")) {
+                    Gson gson = new GsonBuilder().serializeNulls().create();
+                    JSONObject data = jsonObject.optJSONObject("data");
+                    final UserInfo info = gson.fromJson(data.optJSONObject("userInfo").toString(), new TypeToken<UserInfo>() {
+                    }.getType());
+                    SharedPreferences sp = getSharedPreferences("user", MODE_PRIVATE);
+                    SharedPreferences.Editor editor = sp.edit();
+                    editor.putBoolean("isLogin", true);
+                    editor.putBoolean("isFirstInput", false);
+                    editor.putString("uid", info.getId());
+                    editor.putString("openid", info.getOpenid());
+                    editor.putString("portrait", info.getPortrait());
+                    editor.commit();
+
+                    MiPushClient.setAlias(getApplicationContext(), info.getId(), null);
+
+                    //淇濆瓨閭�璇风爜
+                    String inviteCode = data.optString("inviteCode");
+                    UserUtil.setInviteCode(getApplicationContext(), inviteCode, info.getId());
+                    Toast.makeText(getApplicationContext(), "鎭枩浣狅紝鐧诲綍鎴愬姛", Toast.LENGTH_SHORT).show();
+                    setResult(100);
+                    finish();
+                } else {
+                    Toast.makeText(getApplicationContext(), jsonObject.optString("msg"), Toast.LENGTH_SHORT).show();
+                }
+            }
+
+            @Override
+            public void onFinish() {
+                super.onFinish();
+                if (pd.isShowing())
+                    pd.dismiss();
+            }
+        });
+
+    }
+
 
     private void login(Session session) {
         String userData = new Gson().toJson(session);

--
Gitblit v1.8.0