예제 #1
0
    @Override
    protected Usuario doInBackground(Void... params) {
      ArrayList<NameValuePair> dataToSend = new ArrayList<NameValuePair>();
      dataToSend.add(new BasicNameValuePair("c1", usuario.getId()));
      dataToSend.add(new BasicNameValuePair("c2", usuario.getSenha()));

      HttpParams httpRequestParams = new BasicHttpParams();
      HttpConnectionParams.setConnectionTimeout(httpRequestParams, CONNECTION_TIMEOUT);
      HttpConnectionParams.setSoTimeout(httpRequestParams, CONNECTION_TIMEOUT);

      HttpClient client = new DefaultHttpClient(httpRequestParams);
      HttpPost post = new HttpPost(SERVER_ADDRESS + "tbl_usuario/FetchUserData.php");

      Usuario returnedUser = null;

      try {
        post.setEntity(new UrlEncodedFormEntity(dataToSend));
        HttpResponse httpResponse = client.execute(post);

        HttpEntity entity = httpResponse.getEntity();
        String result = EntityUtils.toString(entity);
        JSONObject jObject = new JSONObject(result);

        // status = 1 -> OK
        // status = 0 -> AtivarConta
        if (jObject.length() != 0) {
          String nome = jObject.getString("nome");
          String email = jObject.getString("email");
          int idade = jObject.getInt("idade");
          int status = jObject.getInt("status");

          returnedUser =
              new Usuario(usuario.getId(), nome, usuario.getSenha(), email, idade, status);
        }
      } catch (Exception e) {
        e.printStackTrace();
        Log.v("ServerRequest - doinbackground", "e: " + e);
      }

      return returnedUser;
    }
예제 #2
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    this.inflatedView = inflater.inflate(R.layout.fragment_search_list_view, container, false);

    listView = (ListView) inflatedView.findViewById(R.id.search_list_view);

    uls = new UserLocalStore(getActivity());
    usuario = new Usuario(uls.getLoggedInUser().getId());
    usdDao = new UsuarioSeriadoDAO();

    try {
      idSeriados = usdDao.listarFavoritos(usuario);
      seriadoDao = new SeriadoDAO();
      // Custom List View
      seriados = new ArrayList<Seriado>();
      alTitulos = new ArrayList<String>();
      adapter = new ItensAdapterLVSeriados(getActivity(), R.layout.row_list_search_seriado);
      if (!idSeriados.get(0).equals("0")) {
        listAdapter = new ArrayList<ItemListViewCustom>();
        for (int i = 0; i < idSeriados.size(); i++) {
          seriado = new Seriado(Integer.parseInt(idSeriados.get(i)));
          alTempEpisod = seriadoDao.listarTempEpisodById(seriado);
          objItem =
              new ItemListViewCustom(
                  R.drawable.ic_launcher,
                  alTempEpisod.get(0),
                  "Temporada(s): " + alTempEpisod.get(1),
                  "Episódio(s): " + alTempEpisod.get(2));
          seriados.add(seriado);
          alTitulos.add(alTempEpisod.get(0));

          listAdapter.add(objItem);
          adapter.add(listAdapter.get(i));
        }
        listView.setAdapter(adapter);
        listView.setOnItemClickListener(
            new OnItemClickListener() {

              @Override
              public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                startActivity(
                    new Intent(getActivity(), MainActivity.class)
                        .putExtra("SearchSeriadoId", idSeriados.get(position)));
              }
            });
      } else {
        semResultados();
      }

      listView.setAdapter(adapter);

    } catch (Exception e) {
      usuario.alertDialogOK("Erro", "Erro, por favor tente novamente.", getActivity());
      Log.w("Erro do Try", "erro = " + e);
    }

    // Context Menu
    registerForContextMenu(listView);

    return inflatedView;
  }