@Override
    protected void onPreExecute() {
      super.onPreExecute();

      ProgressWheel wheel = new ProgressWheel(getApplicationContext());
      wheel.setBarColor(Color.BLUE);

      intent = new Intent(getApplicationContext(), MainActivity.class);
    }
  @Override
  public void onBlocksLoaded(Response response) {
    Logger.v("Response code:", "Response Code: " + response.getResponseCode() + response.getBody());
    try {

      Gson gson = new Gson();

      if (response.getResponseCode() == 200) {
        BlocksList blocksList = gson.fromJson(response.getBody(), BlocksList.class);
        mBlocks = blocksList.getBlocks();
        BlocksAdapter blocksAdapter = new BlocksAdapter(mBlocks, this);
        mRecyclerView.setAdapter(blocksAdapter);
        mRecyclerView.setVisibility(View.VISIBLE);
        mProgressWheel.setVisibility(View.GONE);
        mConnectionContainer.setVisibility(View.GONE);
        mFragmentLoader.onFragmentLoaded();
      } else {
        onBlocksLoadFailed(response);
      }

    } catch (Exception e) {
      e.printStackTrace();
      couldNotLoadBlocks();
    }
  }
  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());
          }
        });
  }
Exemplo n.º 4
0
  /**
   * Registers the user with the given data at the server
   *
   * @param firstName the user's first name
   * @param lastName the user's last name
   * @param email the user's registerEmail address
   * @param password the user's password
   */
  private void registerUser(
      final String firstName, final String lastName, final String email, final String password) {

    // UI: Disable register button and show progress bar
    registerButton.setEnabled(false);
    registerProgressBar.setVisibility(View.VISIBLE);

    // Create a new user on the server
    UserDescription userDescription = new UserDescription(email, firstName, lastName, password);
    usersResource
        .registerUser(userDescription)
        .compose(new DefaultTransformer<User>())
        .subscribe(
            new Action1<User>() {

              @Override
              public void call(User user) {
                // REGISTER SUCCESS

                // UI: Hide progress bar
                registerProgressBar.setVisibility(View.GONE);

                Timber.i("Successfully registered user with registerEmail " + user.getEmail());

                // Finally log the user in locally and start the main app
                loginAndRedirect(user, password);
              }
            },
            new CrashCallback(
                this,
                "failed to register user",
                new Action1<Throwable>() {
                  @Override
                  public void call(Throwable throwable) {
                    // UI: Re-enable register button and hide progress bar
                    registerButton.setEnabled(true);
                    registerProgressBar.setVisibility(View.GONE);

                    Response response = ((RetrofitError) throwable).getResponse();

                    String message;
                    if (response != null && response.getStatus() == 409) { // Conflict
                      message = getString(R.string.registration_error_conflict);
                    } else {
                      message = getString(R.string.registration_error_general);
                    }

                    // Show an error message
                    Toast.makeText(LoginActivity.this, message, Toast.LENGTH_LONG).show();
                    Timber.e("Registration failed with error:\n" + throwable.getMessage());
                  }
                }));
  }
Exemplo n.º 5
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;
            }
          }
        });
  }
Exemplo n.º 7
0
 private void initViews() {
   wheel.stopSpinning();
 }
Exemplo n.º 8
0
  /**
   * Logs a user in by connecting to the server and checking the given registerEmail and password
   *
   * @param email the user's registerEmail address
   * @param password the user's password
   */
  private void loginUser(final String email, final String password) {
    // UI: Show progress bar, disable login button
    loginButton.setEnabled(false);
    loginProgressBar.setVisibility(View.VISIBLE);
    loginErrorTextView.setVisibility(View.GONE);

    // Create new adapter to set "custom" auth header (user not officially logged in yet)
    UsersResource usersResource =
        new RestAdapter.Builder()
            .setEndpoint(getString(R.string.server_address))
            .setRequestInterceptor(
                new RequestInterceptor() {
                  @Override
                  public void intercept(RequestFacade request) {
                    AccountManager.addAuthorizationHeader(email, password, request);
                  }
                })
            .setConverter(new JacksonConverter())
            .build()
            .create(UsersResource.class);

    // Make the actual call to the server to receive the correct user object
    usersResource
        .getUser()
        .compose(new DefaultTransformer<User>())
        .subscribe(
            new Action1<User>() {

              @Override
              public void call(User user) {
                // LOGIN SUCCESS
                Timber.d("Successful Login as " + user.getFirstName() + " " + user.getLastName());
                // UI: Hide progress bar
                loginProgressBar.setVisibility(View.GONE);

                // Finally log the user in locally and start the main app
                loginAndRedirect(user, password);
              }
            },
            new CrashCallback(this, "failed to get user") {

              @Override
              public void call(Throwable throwable) {
                super.call(throwable);
                // ERROR

                // UI: Hide progress bar, enable login button again
                loginProgressBar.setVisibility(View.GONE);
                loginButton.setEnabled(true);

                Response response = ((RetrofitError) throwable).getResponse();

                if (response != null && response.getStatus() == 401) { // Not Authorized
                  // Show error message for invalid login
                  loginErrorTextView.setVisibility(View.VISIBLE);
                } else {
                  // Show an error for general errors e.g. connection issues
                  String errorMessage = LoginActivity.this.getString(R.string.login_error_general);
                  Toast.makeText(LoginActivity.this, errorMessage, Toast.LENGTH_LONG).show();
                }

                Timber.e("Logging the user in failed with error:\n" + throwable.getMessage());
              }
            });
  }
 private void onRetryButtonClicked() {
   mNoInternetLL.setVisibility(View.GONE);
   mProgressWheel.setVisibility(View.VISIBLE);
   loadBlocks();
 }
 private void onNoInternet() {
   mConnectionContainer.setVisibility(View.VISIBLE);
   mNoInternetLL.setVisibility(View.VISIBLE);
   mProgressWheel.setVisibility(View.GONE);
   mRecyclerView.setVisibility(View.GONE);
 }
 private void configureProgressBar() {
   progress = (ProgressWheel) findViewById(R.id.progress_wheel);
   progress.setOnTouchListener((v, event) -> true);
 }
 @Override
 public void hideProgress() {
   inProgress = false;
   progress.setVisibility(View.GONE);
 }
 @Override
 public void showProgress() {
   inProgress = true;
   progress.setVisibility(View.VISIBLE);
 }