Browse Source

bug fixed

hanjing 7 years ago
parent
commit
0c3f54e5ba

+ 24 - 0
app/src/main/java/com/sheep/gamegroup/model/api/ApiService.java

@@ -168,6 +168,30 @@ public interface ApiService {
     Observable<BaseMessage> bindWeixin(@Query("code") String code);
 
     /**
+     * 绑定账号
+     */
+    @PUT("app/user/bind_username/")
+    Observable<BaseMessage> bindAccount(@Body JSONObject jsonObject);
+
+    /**
+     * 手机号召回密码:1.获取验证码
+     */
+    @POST("app/user/bind_resetpass1/")
+    Observable<BaseMessage> resetPass4Captcha(@Body JSONObject jsonObject);
+
+    /**
+     * 手机号召回密码:2.验证验证码
+     */
+    @POST("app/user/bind_resetpass2/")
+    Observable<BaseMessage> resetPass4Valid(@Body JSONObject jsonObject);
+
+    /**
+     * 手机号召回密码:3.设置新密码
+     */
+    @POST("app/user/bind_resetpass3/")
+    Observable<BaseMessage> resetPass4New(@Body JSONObject jsonObject);
+
+    /**
      * 获取任务记录列表
      */
     @GET("app/accepted_task/")

+ 17 - 2
app/src/main/java/com/sheep/gamegroup/module/login/ChangePasswordAct.java

@@ -8,11 +8,14 @@ import android.support.v4.app.FragmentTransaction;
 import com.alibaba.fastjson.JSONObject;
 import com.sheep.gamegroup.absBase.BaseActivity;
 import com.sheep.gamegroup.model.entity.BaseMessage;
+import com.sheep.gamegroup.model.entity.UserEntity;
 import com.sheep.gamegroup.model.util.SheepSubscriber;
 import com.sheep.gamegroup.module.login.controller.ChangePasswordController;
+import com.sheep.gamegroup.module.login.fragments.BindAccountFgt;
 import com.sheep.gamegroup.module.login.fragments.NewPasswordFgt;
 import com.sheep.gamegroup.module.login.fragments.OldPasswordFgt;
 import com.sheep.gamegroup.module.login.fragments.SignInFgt;
+import com.sheep.gamegroup.util.DataUtil;
 import com.sheep.jiuyan.samllsheep.R;
 import com.sheep.jiuyan.samllsheep.SheepApp;
 import com.sheep.jiuyan.samllsheep.utils.G;
@@ -34,8 +37,14 @@ public class ChangePasswordAct extends BaseActivity implements ChangePasswordCon
     public void initView() {
         TitleBarUtils.getInstance().setShowOrHide(this, true);
         TitleBarUtils.getInstance().setTitleBack(this).setTitle(this, "设置密码");
-        OldPasswordFgt fgt = OldPasswordFgt.newInstance(this);
-        showFragment("设置密码", fgt);
+        UserEntity user = DataUtil.getInstance().getUserEntity();
+        if(user.getSet_password()==0){
+            BindAccountFgt fgt = BindAccountFgt.newInstance(this);
+            showFragment("绑定登录名密码", fgt);
+        } else {
+            OldPasswordFgt fgt = OldPasswordFgt.newInstance(this);
+            showFragment("设置密码", fgt);
+        }
     }
 
     @Override
@@ -86,6 +95,12 @@ public class ChangePasswordAct extends BaseActivity implements ChangePasswordCon
                 });
     }
 
+    @Override
+    public void whenBindAccount() {
+        G.shortToast("绑定登录名成功");
+        finish();
+    }
+
     private void showFragment(String tag, Fragment fragment) {
         FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
         transaction.replace(R.id.fragment_container, fragment, tag);

+ 1 - 1
app/src/main/java/com/sheep/gamegroup/module/login/ReLoginNameAct.java

@@ -37,7 +37,7 @@ public class ReLoginNameAct extends BaseActivity {
         TitleBarUtils.getInstance()
                 .setShowOrHide(this, true)
                 .setTitleFinish(this)
-                .setTitle(this, "修改用户名");
+                .setTitle(this, "修改登录名");
         String name = getIntent().getStringExtra("name");
         if (!TextUtils.isEmpty(name)) {
             loginNameBox.setText(name);

+ 2 - 0
app/src/main/java/com/sheep/gamegroup/module/login/controller/ChangePasswordController.java

@@ -6,4 +6,6 @@ public interface ChangePasswordController {
 
     void whenComplete(String newPwd);
 
+    void whenBindAccount();
+
 }

+ 138 - 0
app/src/main/java/com/sheep/gamegroup/module/login/fragments/BindAccountFgt.java

@@ -0,0 +1,138 @@
+package com.sheep.gamegroup.module.login.fragments;
+
+
+import android.support.v4.app.Fragment;
+import android.text.TextUtils;
+import android.text.method.HideReturnsTransformationMethod;
+import android.text.method.PasswordTransformationMethod;
+import android.view.View;
+import android.widget.EditText;
+import android.widget.ImageView;
+import android.widget.TextView;
+
+import com.alibaba.fastjson.JSONObject;
+import com.sheep.gamegroup.model.entity.BaseMessage;
+import com.sheep.gamegroup.model.entity.LoginEntity;
+import com.sheep.gamegroup.model.util.SheepSubscriber;
+import com.sheep.gamegroup.module.login.controller.ChangePasswordController;
+import com.sheep.gamegroup.module.login.controller.LoginController;
+import com.sheep.gamegroup.util.CommonUtil;
+import com.sheep.gamegroup.util.DataUtil;
+import com.sheep.gamegroup.util.PreferenceUtils;
+import com.sheep.gamegroup.util.StringUtils;
+import com.sheep.gamegroup.util.UMConfigUtils;
+import com.sheep.jiuyan.samllsheep.R;
+import com.sheep.jiuyan.samllsheep.SheepApp;
+import com.sheep.jiuyan.samllsheep.base.BaseFragment;
+import com.sheep.jiuyan.samllsheep.utils.G;
+import com.sheep.jiuyan.samllsheep.utils.SpUtils;
+
+import butterknife.BindView;
+import butterknife.OnClick;
+import io.reactivex.android.schedulers.AndroidSchedulers;
+import io.reactivex.schedulers.Schedulers;
+
+/**
+ * A simple {@link Fragment} subclass.
+ */
+public class BindAccountFgt extends BaseFragment {
+
+    private ChangePasswordController mController;
+
+    @BindView(R.id.user_name_box)
+    EditText userNameBox;
+    @BindView(R.id.password_box)
+    EditText passwordBox;
+    @BindView(R.id.show_hide_pwd_btn)
+    ImageView showHidePwdBtn;
+    @BindView(R.id.sheep_num_view)
+    TextView sheepNumView;
+
+    public BindAccountFgt() {
+        // Required empty public constructor
+    }
+
+    public static BindAccountFgt newInstance(ChangePasswordController controller) {
+
+        BindAccountFgt fragment = new BindAccountFgt();
+        fragment.mController = controller;
+        return fragment;
+    }
+
+    @Override
+    public int getLayoutId() {
+        return R.layout.fragment_bind_account;
+    }
+
+    @Override
+    public void onViewCreated() {
+        sheepNumView.append(DataUtil.getInstance().getUserEntity().getInvitation_code());
+    }
+
+    @OnClick(R.id.show_hide_pwd_btn)
+    public void doShowHidePwd(View v) {
+        showHidePwdBtn.setSelected(!showHidePwdBtn.isSelected());
+        showHidePwdBtn.setImageResource(showHidePwdBtn.isSelected() ? R.mipmap.pwd_show : R.mipmap.pwd_hide);
+        if (showHidePwdBtn.isSelected()) {
+            //如果选中,显示密码
+            passwordBox.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
+        } else {
+            //否则隐藏密码
+            passwordBox.setTransformationMethod(PasswordTransformationMethod.getInstance());
+        }
+        passwordBox.setSelection(passwordBox.getText().toString().length());
+    }
+
+    @OnClick(R.id.bind_btn)
+    public void doBind(View v) {
+        if (!validate()) return;
+        JSONObject jsonObject = new JSONObject();
+        jsonObject.put("user_name", userNameBox.getText().toString().trim());
+        jsonObject.put("password", passwordBox.getText().toString().trim());
+        SheepApp.getInstance().getNetComponent().getApiService().bindAccount(jsonObject)
+                .subscribeOn(Schedulers.io())
+                .observeOn(AndroidSchedulers.mainThread())
+                .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
+                    @Override
+                    public void onError(BaseMessage baseMessage) {
+                        hideProgress();
+                        G.shortToast(baseMessage);
+                    }
+
+                    @Override
+                    public void onNext(BaseMessage baseMessage) {
+                        hideProgress();
+                        if (baseMessage == null) {
+                            return;
+                        }
+
+                        CommonUtil.getInstance().updateUserInfo(entiry -> {
+                            mController.whenBindAccount();
+                        });
+                    }
+                });
+    }
+
+    private boolean validate() {
+        String username = userNameBox.getText().toString().trim();
+        String password = passwordBox.getText().toString().trim();
+        if (TextUtils.isEmpty(username)) {
+            G.shortToast("请输入用户名");
+            return false;
+        }
+        if (TextUtils.isEmpty(password)) {
+            G.shortToast("请输入密码");
+            return false;
+        }
+        if (!StringUtils.isUserName(username)) {
+            G.shortToast("用户名只能包含英文、数字、._-@符号,长度4-20");
+            return false;
+        }
+        if (!StringUtils.isPassword(password)) {
+            G.shortToast("密码只能包含英文、数字、_.-@$!*%符号,长度6-16");
+            return false;
+        }
+        return true;
+    }
+
+}

+ 14 - 4
app/src/main/java/com/sheep/gamegroup/module/login/fragments/SignInFgt.java

@@ -96,7 +96,7 @@ public class SignInFgt extends AbsLoginFgt {
         // Required empty public constructor
     }
 
-    public static SignInFgt newInstance(LoginController controller){
+    public static SignInFgt newInstance(LoginController controller) {
         return newInstance(controller, LoginController.PLATFORM_PHONE);
     }
 
@@ -116,9 +116,19 @@ public class SignInFgt extends AbsLoginFgt {
     public void onViewCreated() {
         TestUtil.testChange(getActivity(), testChange);
         TestUtil.testChangeUser(getActivity(), testChangeUser);
-        forAccountPwdContainer.setVisibility(View.GONE);
-        forPhoneContainer.setVisibility(View.VISIBLE);
-        loginTypeToggle.setSelected(true);
+        if (loginType == LoginController.PLATFORM_PHONE) {
+            forAccountPwdContainer.setVisibility(View.GONE);
+            forPhoneContainer.setVisibility(View.VISIBLE);
+            loginTypeToggle.setSelected(true);
+            loginTypeToggleIcon.setImageResource(R.mipmap.login_account);
+            loginTypeToggleText.setText("账号登录");
+        } else {
+            forAccountPwdContainer.setVisibility(View.VISIBLE);
+            forPhoneContainer.setVisibility(View.GONE);
+            loginTypeToggle.setSelected(false);
+            loginTypeToggleIcon.setImageResource(R.mipmap.login_phone);
+            loginTypeToggleText.setText("一键登录");
+        }
     }
 
     @OnClick(R.id.login_btn)

+ 1 - 1
app/src/main/java/com/sheep/gamegroup/module/login/fragments/WelcomeFgt.java

@@ -52,7 +52,7 @@ public class WelcomeFgt extends AbsLoginFgt {
 
     @OnClick({R.id.login_btn, R.id.login_type_toggle})
     public void doToLogin(View v) {
-        mController.whenToLogin(LoginController.PLATFORM_PHONE);
+        mController.whenToLogin(LoginController.PLATFORM_ACCOUNT);
     }
 
     @OnClick(R.id.register_btn)

+ 66 - 0
app/src/main/res/layout/fragment_bind_account.xml

@@ -0,0 +1,66 @@
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:orientation="vertical"
+    android:padding="@dimen/content_padding_24">
+
+    <TextView
+        android:id="@+id/sheep_num_view"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_marginTop="50dp"
+        android:gravity="center"
+        android:text="当前绵羊号:"
+        android:textColor="@color/gray_4"
+        android:textSize="14sp"
+        android:textStyle="bold" />
+
+    <LinearLayout
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_marginTop="30dp"
+        android:orientation="vertical">
+
+        <EditText
+            android:id="@+id/user_name_box"
+            style="@style/login_edit_style"
+            android:maxLength="20"
+            android:hint="请输入登录名(唯一性)" />
+
+        <View style="@style/login_separetor_line_style" />
+
+        <LinearLayout
+            android:orientation="horizontal"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content">
+
+            <EditText
+                android:id="@+id/password_box"
+                android:layout_weight="1"
+                style="@style/login_edit_style"
+                android:layout_below="@+id/user_name_box"
+                android:hint="请输入登录密码(6-16位)"
+                android:inputType="textPassword"
+                android:lines="1"
+                android:maxLength="16" />
+            <ImageView
+                android:id="@+id/show_hide_pwd_btn"
+                android:src="@mipmap/pwd_hide"
+                android:layout_marginTop="26dp"
+                android:tint="@color/bg_line"
+                android:padding="7dp"
+                android:layout_width="30dp"
+                android:layout_height="30dp" />
+        </LinearLayout>
+
+        <View style="@style/login_separetor_line_style" />
+    </LinearLayout>
+
+    <Button
+        android:id="@+id/bind_btn"
+        style="@style/login_theme_round_button"
+        android:layout_marginTop="50dp"
+        android:text="提交" />
+
+</LinearLayout>