/** Do login */
  private void doLogin() {

    String strPassword = edtPassword.getText().toString();
    String strEmail = edtEmail.getText().toString().toLowerCase();
    CustomPreferences.setPreferences(Constants.PREF_USERNAME, strEmail);
    CustomPreferences.setPreferences(Constants.PREF_PASSWORD, strPassword);
    final LoadingDialog dialog = LoadingDialog.show(this);
    new UserApi()
        .getInterface()
        .doLogin()
        .enqueue(
            new Callback<UserEntity>() {
              @Override
              public void onResponse(Response<UserEntity> response, Retrofit retrofit) {

                finishLogin(response);
                Utilities.dismissDialog(dialog);
              }

              @Override
              public void onFailure(Throwable t) {

                finishLogin(null);
                Utilities.dismissDialog(dialog);
              }
            });
  }
  /**
   * Finish login
   *
   * @param response response
   */
  private void finishLogin(Response<UserEntity> response) {

    if (response == null || response.body() == null) {

      CustomPreferences.setPreferences(Constants.PREF_USERNAME, "");
      CustomPreferences.setPreferences(Constants.PREF_PASSWORD, "");
      CustomPreferences.setPreferences(Constants.PREF_USER_ID, 0l);
      CustomPreferences.setPreferences(Constants.PREF_ACC_ID, 0l);
      Utilities.showAlertDialog(
          LoginActivity.this,
          getString(R.string.login_fail),
          getString(R.string.try_again),
          getString(R.string.ok),
          "",
          null,
          null,
          false);
      edtPassword.setText("");
      edtPassword.requestFocus();
      return;
    }

    CustomPreferences.setPreferences(Constants.PREF_USER_ID, response.body().getId());
    CustomPreferences.setPreferences(Constants.PREF_ACC_ID, response.body().getAccountId());
    startActivity(new Intent(this, MainActivity.class));
    finish();
  }