private void getUserAsyncTask() {
    loading = true;
    progressWheel.spin();
    startLoadingTime = System.currentTimeMillis();
    ApiClient.service.getUser(
        loginName,
        new Callback<Result<User>>() {

          private long getPostTime() {
            long postTime = 1000 - (System.currentTimeMillis() - startLoadingTime);
            if (postTime > 0) {
              return postTime;
            } else {
              return 0;
            }
          }

          @Override
          public void success(final Result<User> userResult, Response response) {
            HandlerUtils.postDelayed(
                new Runnable() {
                  @Override
                  public void run() {
                    if (!isFinishing()) {
                      updateUserInfoViews(userResult.getData());
                      adapter.update(userResult.getData());
                      githubUsername = userResult.getData().getGithubUsername();
                      progressWheel.setProgress(0);
                      loading = false;
                    }
                  }
                },
                getPostTime());
          }

          @Override
          public void failure(final RetrofitError error) {
            HandlerUtils.postDelayed(
                new Runnable() {
                  @Override
                  public void run() {
                    if (!isFinishing()) {
                      if (error.getResponse() != null && error.getResponse().getStatus() == 400) {
                        ToastUtils.with(UserDetailActivity.this).show(R.string.user_not_found);
                      } else {
                        ToastUtils.with(UserDetailActivity.this)
                            .show(R.string.data_load_faild_and_click_avatar_to_reload);
                      }
                    }
                    progressWheel.setProgress(0);
                    loading = false;
                  }
                },
                getPostTime());
          }
        });
  }
示例#2
0
 @OnClick(R.id.btn_login)
 public void login() {
   wheel.spin();
   final String name = etName.getText().toString().trim();
   final String pwd = etPwd.getText().toString().trim();
   if (TextUtils.isEmpty(name)) {
     HankkinUtils.showToast(LoginActivity.this, "用户名不能为空");
     return;
   }
   if (TextUtils.isEmpty(pwd)) {
     HankkinUtils.showToast(LoginActivity.this, "密码不能为空");
     return;
   }
   Person.loginByAccount(
       this,
       name,
       pwd,
       new LogInListener<Person>() {
         @Override
         public void done(Person person, BmobException e) {
           MySP.setPASSWoRD(LoginActivity.this, pwd);
           MySP.setUSERNAME(LoginActivity.this, name);
           wheel.stopSpinning();
           HankkinUtils.showToast(LoginActivity.this, "登录成功");
           Intent intent = new Intent(LoginActivity.this, MainShowActivity.class);
           startActivity(intent);
           finish();
           if (LoginActivity.instance != null) {
             LoginActivity.instance.finish();
           }
           if (PersonActivity.instance != null) {
             PersonActivity.instance.finish();
           }
           if (MainShowActivity.instance != null) {
             MainShowActivity.instance.finish();
           }
         }
       });
 }
  private void getUserAsyncTask() {
    loading = true;
    progressWheel.spin();
    ApiClient.service.getUser(
        loginName,
        new Callback<Result<User>>() {

          @Override
          public void success(Result<User> result, Response response) {
            if (!isFinishing()) {
              updateUserInfoViews(result.getData());
              adapter.update(result.getData());
              githubUsername = result.getData().getGithubUsername();
              progressWheel.setProgress(0);
              loading = false;
            }
          }

          @Override
          public void failure(RetrofitError error) {
            if (!isFinishing()) {
              if (error.getResponse() != null && error.getResponse().getStatus() == 404) {
                Toast.makeText(UserDetailActivity.this, R.string.user_not_found, Toast.LENGTH_SHORT)
                    .show();
              } else {
                Toast.makeText(
                        UserDetailActivity.this,
                        R.string.data_load_faild_and_click_avatar_to_reload,
                        Toast.LENGTH_SHORT)
                    .show();
              }
              progressWheel.setProgress(0);
              loading = false;
            }
          }
        });
  }