Ejemplo n.º 1
0
  public void loginByiHealthID(
      final Context context,
      String userName,
      final String password,
      final LogicCallbackInterface callback) {
    this.mCallback = callback;
    InputModelUser inputModelUser = new InputModelUser();
    inputModelUser.setUserName(userName);
    inputModelUser.setPassword(password);
    AJKCloudMethod.getInstance()
        .loginUserInfo(
            context,
            inputModelUser,
            new CloudCallback<OutputModelUserLogin>() {
              @Override
              public void onSuccess(ArrayList<OutputModelUserLogin> list) {
                // Toast.makeText(context, "login successfully", Toast.LENGTH_LONG).show();
                if (context == null) {
                  return;
                }
                AJKLog.i(TAG, "login successfully");
                final ArrayList<Data_UserToken> tokenList = new ArrayList<Data_UserToken>();
                final ArrayList<Data_UserInfo> infoList = new ArrayList<Data_UserInfo>();
                for (int i = 0; i < list.size(); i++) {
                  Data_UserToken data_userToken = new Data_UserToken();
                  data_userToken.setiHealthID(list.get(i).getUn());
                  AJKLog.i(TAG, "un = " + list.get(i).getUn());
                  data_userToken.setAccessToken(list.get(i).getAccessToken());
                  data_userToken.setRefreshToken(list.get(i).getRefreshToken());
                  tokenList.add(data_userToken);

                  Data_UserInfo data_userInfo = new Data_UserInfo();
                  data_userInfo.setWeight(list.get(i).getWeight());
                  data_userInfo.setGender(list.get(i).getGender());
                  data_userInfo.setBirthDay(list.get(i).getBirthDay());
                  data_userInfo.setName(list.get(i).getName());
                  data_userInfo.setHeight(list.get(i).getHeight());
                  data_userInfo.setLogo(list.get(i).getLogo());
                  data_userInfo.setLogoTS(list.get(i).getLogoTS());
                  data_userInfo.setUserId(list.get(i).getUserId());
                  data_userInfo.setUserName(list.get(i).getUn());
                  infoList.add(data_userInfo);

                  new UserTokenLogic(context)
                      .saveUserTokenData(
                          tokenList,
                          new LogicListener() {
                            @Override
                            public <T> void onSuccess(T model) {
                              AJKLog.i(TAG, "saveUserTokenData success");

                              new UserInfoLogic(context)
                                  .saveUserInfoData(
                                      infoList,
                                      new LogicListener() {
                                        @Override
                                        public <T> void onSuccess(T model) {
                                          AJKLog.i(TAG, "saveUserInfoData success");
                                          UserConfig.getInstance()
                                              .setConfigCurrentUser(
                                                  context, tokenList.get(0).getiHealthID());
                                          UserConfig.getInstance()
                                              .setConfigUserID(
                                                  context, infoList.get(0).getUserId());
                                          UserConfig.getInstance()
                                              .setConfigPassword(context, password);
                                          AJKLog.i(
                                              TAG,
                                              UserConfig.getInstance()
                                                  .getConfigCurrentUser(context));
                                          AJKLog.i(
                                              TAG,
                                              UserConfig.getInstance().getConfigUserID(context)
                                                  + "");
                                          mCallback.onSuccess("");
                                        }

                                        @Override
                                        public <T> void onFailure(T model) {
                                          AJKLog.i(TAG, "saveUserInfoData fail");
                                          mCallback.onFailure("", "");
                                        }
                                      },
                                      myHandler);
                            }

                            @Override
                            public <T> void onFailure(T model) {
                              AJKLog.i(TAG, "saveUserTokenData fail");
                              mCallback.onFailure("", "");
                            }
                          },
                          myHandler);
                }
              }

              @Override
              public void onFailure(String backNum, String str) {
                if (context == null) {
                  return;
                }
                AJKLog.i(TAG, "login failed");
                ErrorCodeHandler.getInstance().handleLoginErrorCode(context, backNum);
                mCallback.onFailure(backNum, str);
              }
            });
  }
Ejemplo n.º 2
0
  public void registerAccount(
      final Context context,
      final String userName,
      final String password,
      final String nickName,
      LogicCallbackInterface callback) {
    this.mCallback = callback;
    InputModelUser inputModelUser = new InputModelUser();
    inputModelUser.setUserName(userName);
    inputModelUser.setName(nickName);
    inputModelUser.setPassword(password);
    inputModelUser.setBirthDay(-1362332800);
    inputModelUser.setGender(-1);
    inputModelUser.setHeight(0);
    inputModelUser.setWeight(0.0f);
    inputModelUser.setLogo("");
    inputModelUser.setLogoTS(0);
    AJKCloudMethod.getInstance()
        .registerUserInfo(
            context,
            inputModelUser,
            new CloudCallback<OutputModelUser>() {
              @Override
              public void onSuccess(ArrayList<OutputModelUser> list) {
                if (context == null) {
                  return;
                }
                ArrayList<Data_UserToken> tokenList = new ArrayList<Data_UserToken>();
                final ArrayList<Data_UserInfo> infoList = new ArrayList<Data_UserInfo>();
                AJKLog.i(TAG, "regist account success");
                for (int i = 0; i < list.size(); i++) {
                  if (list.get(i).getIsReg().equals("1")) {
                    Data_UserToken data_userToken = new Data_UserToken();
                    data_userToken.setAccessToken(list.get(i).getAccessToken());
                    data_userToken.setiHealthID(list.get(i).getiHealthId());
                    data_userToken.setRefreshToken(list.get(i).getRefreshToken());
                    tokenList.add(data_userToken);

                    Data_UserInfo data_userInfo = new Data_UserInfo();
                    data_userInfo.setUserName(userName);
                    data_userInfo.setName(nickName);
                    data_userInfo.setUserId(list.get(i).getUserId());
                    data_userInfo.setGender(-1);
                    data_userInfo.setBirthDay(-1362332800); // 给一个1930年1月1日之前的值)
                    data_userInfo.setHeight(0);
                    data_userInfo.setWeight(0.0f);
                    data_userInfo.setLogoTS(0);
                    data_userInfo.setLogo("");
                    infoList.add(data_userInfo);

                    new UserTokenLogic(context)
                        .saveUserTokenData(
                            tokenList,
                            new LogicListener() {
                              @Override
                              public <T> void onSuccess(T model) {
                                new UserInfoLogic(context)
                                    .saveUserInfoData(
                                        infoList,
                                        new LogicListener() {
                                          @Override
                                          public <T> void onSuccess(T model) {
                                            mCallback.onSuccess("");
                                          }

                                          @Override
                                          public <T> void onFailure(T model) {
                                            mCallback.onFailure("", "");
                                          }
                                        },
                                        myHandler);
                              }

                              @Override
                              public <T> void onFailure(T model) {
                                mCallback.onFailure("", "");
                              }
                            },
                            myHandler);

                  } else {
                    mCallback.onFailure("", "");
                    AJKLog.i(TAG, "Modify user info fail");
                  }
                }
              }

              @Override
              public void onFailure(String backNum, String str) {
                AJKLog.i(TAG, "regist account failed");
                if (context == null) {
                  return;
                }
                ErrorCodeHandler.getInstance().handleRegisterErrorCode(context, backNum);
                mCallback.onFailure(backNum, str);
              }
            });
  }