Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.futsal.skripsi.futsal;
- import android.app.Activity;
- import android.app.ProgressDialog;
- import android.content.Intent;
- import android.os.Bundle;
- import android.support.v7.app.AppCompatActivity;
- import android.util.Log;
- import android.view.Menu;
- import android.view.View;
- import android.widget.AdapterView;
- import android.widget.ImageView;
- import android.widget.ListView;
- import android.widget.Toast;
- import com.android.volley.Request;
- import com.android.volley.Response;
- import com.android.volley.VolleyError;
- import com.android.volley.toolbox.JsonObjectRequest;
- import com.google.android.gms.common.api.GoogleApiClient;
- import com.squareup.picasso.Picasso;
- import org.json.JSONArray;
- import org.json.JSONObject;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- public class PilihTempat extends AppCompatActivity {
- // Log tag
- private static final String TAG = PilihTempat.class.getSimpleName();
- int sukses;
- String url = "carilapangan.php";
- private ProgressDialog pDialog;
- private List<Lapangan> lapanganList = new ArrayList<Lapangan>();
- private List<Lapangan> lapanganList2 = new ArrayList<Lapangan>();
- private ListView listView;
- private CustomListAdapter adapter;
- Utilities util = new Utilities();
- String tanggal, dari, durasi, hari, jam, harga;
- /**
- * ATTENTION: This was auto-generated to implement the App Indexing API.
- * See https://g.co/AppIndexing/AndroidStudio for more information.
- */
- private GoogleApiClient client;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_pilih_tempat);
- url = util.getUrlPhp(url);
- Bundle extras = getIntent().getExtras();
- tanggal = extras.getString("tgl_main");
- dari = extras.getString("jam_mulai");
- durasi = extras.getString("durasi");
- hari = extras.getString("id_hari");
- jam = extras.getString("id_jam");
- pDialog = new ProgressDialog(this);
- // Showing progress dialog before making http request
- pDialog.setMessage("Loading...");
- pDialog.show();
- lapangan();
- listView = (ListView) findViewById(R.id.list);
- adapter = new CustomListAdapter(this, lapanganList);
- listView.setAdapter(adapter);
- listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
- @Override
- public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
- Lapangan lapangan = new Lapangan();
- lapangan = lapanganList.get(position);
- String idl = lapangan.getIdLapangan();
- for (int i = 0; i < lapanganList.size(); i++) {
- Lapangan lap = lapanganList.get(i);
- String idlap = lap.getIdLapangan();
- if (idlap.equals(idl)) {
- System.out.println("idl: " + idl + ", " + "idlap: " + idlap);
- String gambar = lap.getThumbnailUrl();
- String nama = lap.getNama();
- String idLokasi = lapangan.getIdLokasi();
- String idHari = lap.getIdHari();
- String idJam = lap.getIdJam();
- String latitude = lapangan.getLat();
- String longitude = lapangan.getLng();
- String harga = lap.getHarga();
- System.out.println("nama: " + nama + ", " + "idjam: " + idJam + ", " + "harga: " + harga);
- // Intent intent = new Intent(getApplicationContext(), DetailTempat.class);
- // intent.putExtra("nama", nama);
- // intent.putExtra("gambar", gambar);
- // intent.putExtra("idLokasi", idLokasi);
- // intent.putExtra("idLapangan", idl);
- // intent.putExtra("idHari", idHari);
- // intent.putExtra("idJam", idJam);
- // intent.putExtra("latitude", latitude);
- // intent.putExtra("longitude", longitude);
- // intent.putExtra("harga", harga);
- // intent.putExtra("durasi", durasi);
- // intent.putExtra("tgl_main", tanggal);
- // intent.putExtra("jam_mulai", dari);
- // startActivity(intent);
- }
- }
- // String gambar = lapangan.getThumbnailUrl();
- // String nama = lapangan.getNama();
- // String idl = lapangan.getId();
- // String idHari = lapangan.getIdHari();
- // String idJam = lapangan.getIdJam();
- // String latitude = lapangan.getLat();
- // String longitude = lapangan.getLng();
- // String harga = lapangan.getHarga();
- // System.out.println("nama lap: " + nama);
- // Intent intent = new Intent(getApplicationContext(), DetailTempat.class);
- // intent.putExtra("nama", nama);
- // intent.putExtra("gambar", gambar);
- // intent.putExtra("id", idl);
- // intent.putExtra("idHari", idHari);
- // intent.putExtra("idJam", idJam);
- // intent.putExtra("latitude", latitude);
- // intent.putExtra("longitude", longitude);
- // intent.putExtra("harga", harga);
- // intent.putExtra("durasi", durasi);
- // intent.putExtra("tgl_main", tanggal);
- // intent.putExtra("jam_mulai", dari);
- // startActivity(intent);
- }
- });
- }
- @Override
- public void onDestroy() {
- super.onDestroy();
- hidePDialog();
- }
- private void hidePDialog() {
- if (pDialog != null) {
- pDialog.dismiss();
- pDialog = null;
- }
- }
- private void lapangan() {
- Map<String, String> params = new HashMap<String, String>();
- params.put("tgl_main", tanggal);
- params.put("jam_mulai", dari);
- params.put("durasi", durasi);
- System.out.println("Params: " + tanggal + "," + dari + "," + durasi);
- System.out.println("Requesting...");
- CustomRequest jsonObj = new CustomRequest(Request.Method.POST, url, params, new Response.Listener<JSONObject>() {
- @Override
- public void onResponse(JSONObject response) {
- try {
- Log.d("Response: ", response.toString());
- sukses = response.getInt("sukses");
- System.out.println("Sukses: " + sukses);
- if (sukses == 1) {
- JSONArray lokasi = response.getJSONArray("lapangan");
- for (int i = 0; i < lokasi.length(); i++) {
- JSONObject l = (JSONObject) lokasi.get(i);
- Lapangan lapangan = new Lapangan();
- String nama = l.getString("nama_lapangan");
- String alamat = l.getString("alamat_futsal");
- String gambar = l.getString("gambar");
- String gbr = util.getUrl() + gambar;
- String idl = l.getString("id_lapangan");
- String idLokasi = l.getString("id_lokasi");
- // String idHari = l.getString("id_hari");
- String idJam = l.getString("id_jam");
- String lat = l.getString("latitude");
- String lng = l.getString("longitude");
- String harga = l.getString("harga");
- lapangan.setNama(nama);
- lapangan.setAlamat(alamat);
- lapangan.setThumbnailUrl(gbr);
- lapangan.setId_lapangan(idl);
- lapangan.setId_lokasi(idLokasi);
- // lapangan.setIdHari(idHari);
- lapangan.setIdJam(idJam);
- lapangan.setLat(lat);
- lapangan.setLng(lng);
- lapangan.setHarga(harga);
- lapanganList.add(lapangan);
- }
- // untuk cek
- // for (int j = 0; j < lapanganList.size(); j++) {
- // Lapangan lp = new Lapangan();
- // lp = lapanganList.get(j);
- // String namal = lp.getNama();
- // String alamatl = lp.getAlamat();
- // String gambarl = lp.getThumbnailUrl();
- // String idl = lp.getId();
- // System.out.println("lapanganList: " + j + gambarl + "," + namal + "," + alamatl + "," + idl);
- // }
- fillLapangan();
- pDialog.hide();
- } else {
- Toast.makeText(getApplicationContext(), "Error!", Toast.LENGTH_LONG).show();
- pDialog.hide();
- }
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- pDialog.hide();
- Toast.makeText(getApplicationContext(), "Error!" + e.toString(), Toast.LENGTH_LONG).show();
- }
- }
- }, new Response.ErrorListener() {
- @Override
- public void onErrorResponse(VolleyError response) {
- Log.d("Response: ", response.toString());
- }
- });
- AppController.getInstance().addToRequestQueue(jsonObj);
- }
- public void fillLapangan() {
- String idx = null;
- for (int i = 0; i < lapanganList.size(); i++){
- Lapangan lapangan2 = new Lapangan();
- Lapangan lap = lapanganList.get(i);
- String id = lap.getIdLapangan();
- System.out.println("id: " + id);
- if (id.equals(idx)){
- System.out.println("id = idx");
- continue;
- } else {
- idx = id;
- String nama = lap.getNama();
- String alamat = lap.getAlamat();
- String gambar = lap.getThumbnailUrl();
- String harga = lap.getHarga();
- System.out.println("id: " + id + ", " + "idx: " + idx + ", " + "nama: " + nama + ", " + "alamat: " + alamat);
- lapangan2.setNama(nama);
- lapangan2.setAlamat(alamat);
- lapangan2.setThumbnailUrl(gambar);
- lapangan2.setHarga(harga);
- lapanganList2.add(lapangan2);
- }
- }
- adapter = new CustomListAdapter(this, lapanganList2);
- listView.setAdapter(adapter);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement