|
|
@@ -8,80 +8,166 @@ import android.text.TextWatcher;
|
|
|
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.LoginController;
|
|
|
+import com.sheep.gamegroup.util.ChannelContent;
|
|
|
+import com.sheep.gamegroup.util.DataUtil;
|
|
|
+import com.sheep.gamegroup.util.FastJsonUtils;
|
|
|
+import com.sheep.gamegroup.util.PreferenceUtils;
|
|
|
import com.sheep.gamegroup.util.StringUtils;
|
|
|
+import com.sheep.gamegroup.util.TestUtil;
|
|
|
+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 com.umeng.socialize.UMAuthListener;
|
|
|
+import com.umeng.socialize.UMShareAPI;
|
|
|
+import com.umeng.socialize.bean.SHARE_MEDIA;
|
|
|
+
|
|
|
+import java.util.Map;
|
|
|
|
|
|
import butterknife.BindView;
|
|
|
import butterknife.OnClick;
|
|
|
+import io.reactivex.android.schedulers.AndroidSchedulers;
|
|
|
+import io.reactivex.schedulers.Schedulers;
|
|
|
+
|
|
|
+import static com.sheep.gamegroup.util.UMConfigUtils.Event.LOGIN_QQ;
|
|
|
+import static com.sheep.gamegroup.util.UMConfigUtils.Event.LOGIN_WX;
|
|
|
|
|
|
/**
|
|
|
* A simple {@link Fragment} subclass.
|
|
|
*/
|
|
|
-public class FindAccountFgt extends BaseFragment {
|
|
|
-
|
|
|
- private LoginController mController;
|
|
|
+public class AbsLoginFgt extends BaseFragment {
|
|
|
|
|
|
- @BindView(R.id.phone_number_box)
|
|
|
- EditText phoneNumberBox;
|
|
|
- @BindView(R.id.text_delete_btn)
|
|
|
- ImageView textDeleteBtn;
|
|
|
+ protected LoginController mController;
|
|
|
|
|
|
- public FindAccountFgt() {
|
|
|
+ public AbsLoginFgt() {
|
|
|
// Required empty public constructor
|
|
|
}
|
|
|
|
|
|
- public static FindAccountFgt newInstance(LoginController controller) {
|
|
|
- FindAccountFgt fragment = new FindAccountFgt();
|
|
|
+ public static AbsLoginFgt newInstance(LoginController controller) {
|
|
|
+ AbsLoginFgt fragment = new AbsLoginFgt();
|
|
|
fragment.mController = controller;
|
|
|
return fragment;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public int getLayoutId() {
|
|
|
- return R.layout.fragment_find_account;
|
|
|
+ return 0;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onViewCreated() {
|
|
|
- phoneNumberBox.addTextChangedListener(new TextWatcher() {
|
|
|
- @Override
|
|
|
- public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
+ @OnClick(R.id.wx_login_btn)
|
|
|
+ public void doWxLogin(View v) {
|
|
|
+ LOGIN_WX.onEvent();
|
|
|
+ UMShareAPI.get(SheepApp.getInstance()).doOauthVerify(getActivity(), SHARE_MEDIA.WEIXIN, new ThirdpartAuthListener("微信") {
|
|
|
@Override
|
|
|
- public void onTextChanged(CharSequence s, int start, int before, int count) {
|
|
|
- textDeleteBtn.setVisibility(TextUtils.isEmpty(s) ? View.GONE : View.VISIBLE);
|
|
|
- }
|
|
|
+ public void onComplete(SHARE_MEDIA platform, int action, Map<String, String> data) {
|
|
|
+ JSONObject j = new JSONObject();
|
|
|
+ j.put("code", data.get("access_token"));
|
|
|
+ j.put("username", data.get("openid"));
|
|
|
+ j.put("scope", ChannelContent.getInstance().getChannel_name());
|
|
|
+ PreferenceUtils.setPrefString(SheepApp.getInstance(), UMConfigUtils.LOGIN_TYPE, UMConfigUtils.Source.WECHAT);
|
|
|
+ SheepApp.getInstance().getNetComponent().getApiService()
|
|
|
+ .LoginByWX(j)
|
|
|
+ .subscribeOn(Schedulers.io())
|
|
|
+ .observeOn(AndroidSchedulers.mainThread())
|
|
|
+ .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
|
|
|
+ @Override
|
|
|
+ public void onError(BaseMessage baseMessage) {
|
|
|
+ G.shortToast("微信登录失败 请检查网络是否正常");
|
|
|
+ hideProgress();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onNext(BaseMessage baseMessage) {
|
|
|
+ hideProgress();
|
|
|
+ if (baseMessage != null) {
|
|
|
+ LoginEntity loginEty = FastJsonUtils.toBean(JSONObject.toJSONString(baseMessage.getData()), LoginEntity.class);
|
|
|
+ SpUtils.saveToken(SheepApp.getInstance(), loginEty.getToken());
|
|
|
+ DataUtil.getInstance().initUserEntity(loginEty.getUser());
|
|
|
+ mController.whenLoginSuccess(LoginController.PLATFORM_WX, loginEty);
|
|
|
+ TestUtil.saveUser(loginEty);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
- @Override
|
|
|
- public void afterTextChanged(Editable s) {
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
+ @OnClick(R.id.qq_login_btn)
|
|
|
+ public void doQQLogin(View v) {
|
|
|
+ LOGIN_QQ.onEvent();
|
|
|
+ UMShareAPI.get(SheepApp.getInstance()).doOauthVerify(getActivity(), SHARE_MEDIA.QQ, new ThirdpartAuthListener("QQ") {
|
|
|
+ public void onComplete(SHARE_MEDIA platform, int action, Map<String, String> data) {
|
|
|
+ JSONObject j = new JSONObject();
|
|
|
+ j.put("code", data.get("access_token"));
|
|
|
+ j.put("username", data.get("openid"));
|
|
|
+ j.put("scope", ChannelContent.getInstance().getChannel_name());
|
|
|
+ PreferenceUtils.setPrefString(SheepApp.getInstance(), UMConfigUtils.LOGIN_TYPE, UMConfigUtils.Source.QQ);
|
|
|
+ SheepApp.getInstance().getNetComponent().getApiService()
|
|
|
+ .LoginByQQ(j)
|
|
|
+ .subscribeOn(Schedulers.io())
|
|
|
+ .observeOn(AndroidSchedulers.mainThread())
|
|
|
+ .subscribe(new SheepSubscriber<BaseMessage>(SheepApp.getInstance()) {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onError(BaseMessage baseMessage) {
|
|
|
+ G.shortToast("QQ登录失败 请检查网络是否正常");
|
|
|
+ hideProgress();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onNext(BaseMessage baseMessage) {
|
|
|
+ hideProgress();
|
|
|
+ if (baseMessage != null) {
|
|
|
+ LoginEntity loginEty = FastJsonUtils.toBean(JSONObject.toJSONString(baseMessage.getData()), LoginEntity.class);
|
|
|
+ SpUtils.saveToken(SheepApp.getInstance(), loginEty.getToken());
|
|
|
+ DataUtil.getInstance().initUserEntity(loginEty.getUser());
|
|
|
+ mController.whenLoginSuccess(LoginController.PLATFORM_QQ, loginEty);
|
|
|
+ TestUtil.saveUser(loginEty);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- @OnClick(R.id.send_captcha_btn)
|
|
|
- public void doSendCaptcha(View v) {
|
|
|
- String phoneNum = phoneNumberBox.getText().toString().trim();
|
|
|
- if (TextUtils.isEmpty(phoneNum)) {
|
|
|
- G.shortToast("请输入手机号");
|
|
|
- return;
|
|
|
+ protected abstract class ThirdpartAuthListener implements UMAuthListener {
|
|
|
+
|
|
|
+ private String platformName;
|
|
|
+
|
|
|
+ public ThirdpartAuthListener(String platformName) {
|
|
|
+ this.platformName = platformName;
|
|
|
}
|
|
|
- if (!StringUtils.isMobile(phoneNum)) {
|
|
|
- G.shortToast("手机号有误");
|
|
|
- return;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onStart(SHARE_MEDIA platform) {
|
|
|
+ showProgress();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onError(SHARE_MEDIA platform, int action, Throwable t) {
|
|
|
+ G.shortToast(platformName + "授权失败 请检查网络是否正常");
|
|
|
+ hideProgress();
|
|
|
}
|
|
|
- mController.whenGoValidCaptcha(phoneNumberBox.getText().toString());
|
|
|
- }
|
|
|
|
|
|
- @OnClick(R.id.text_delete_btn)
|
|
|
- public void doDeleteText(View v) {
|
|
|
- phoneNumberBox.setText("");
|
|
|
+ @Override
|
|
|
+ public void onCancel(SHARE_MEDIA platform, int action) {
|
|
|
+ hideProgress();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
}
|