Пример #1
0
  public void userLogin(View view) {
    if (validateForm()) {

      enableProgress(true, View.VISIBLE);

      final StringRequest postRequest =
          new StringRequest(
              Request.Method.POST,
              LOGIN_ACCESS_URL,
              new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {

                  JSONObject jsonResponse;

                  try {
                    jsonResponse = new JSONObject(response);

                    if (jsonResponse.getInt("result") == 1) {
                      enableProgress(false, View.GONE);
                      Aluno aluno =
                          MyApplication.getWritableDatabase()
                              .alunoByEmail(emailLogin.getText().toString());

                      prefs.setName(aluno.getNome());
                      prefs.setEmail(aluno.getEmail());
                      prefs.setOld(true);

                      if (!getUpdatedServidor()) {
                        registerUser(aluno.getAlunoIdServidor());

                        if (ConnectionUtils.hasConnection(LoginActivity.this)) {
                          DataHelper.sincronizarDados();
                        }
                      }

                      startActivity(new Intent(LoginActivity.this, MainActivity.class));
                      finish();

                    } else {
                      enableProgress(false, View.GONE);
                      Snackbar.make(
                              findViewById(android.R.id.content),
                              R.string.txt_login_invalido,
                              Snackbar.LENGTH_LONG)
                          .show();
                    }

                  } catch (JSONException e) {
                    e.printStackTrace();
                  }
                }
              },
              new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                  enableProgress(false, View.GONE);
                  Log.d("Error.Response", error.getMessage());
                }
              }) {
            @Override
            protected Map<String, String> getParams() {

              String salt = "Random$SaltValue#WithSpecialCharacters12@$@4&#%^$*";
              String password =
                  PasswordEncryptionUtil.md5(passwordLogin.getText().toString().concat(salt));

              Map<String, String> params = new HashMap<>();
              params.put(EMAIL_PARAM, emailLogin.getText().toString());
              params.put(PASSWORD_PARAM, password);

              return params;
            }
          };

      VolleySingleton.getInstance().getRequestQueue().add(postRequest);
    }
  }
Пример #2
0
 public TaskLoadMateriais() {
   volleySingleton = VolleySingleton.getInstance();
   requestQueue = volleySingleton.getRequestQueue();
 }
Пример #3
0
 public TaskRateDisciplina() {
   volleySingleton = VolleySingleton.getInstance();
 }