Modified freebitco.in scr


SUBMITTED BY: mollamolla

DATE: Sept. 15, 2016, 12:09 a.m.

UPDATED: Sept. 17, 2016, 5:58 a.m.

FORMAT: Text only

SIZE: 6.5 kB

HITS: 1785

  1. public class ListViewActivity extends Activity {
  2. // Log tag
  3. private static final String TAG = ListViewActivity.class.getSimpleName();
  4. // change here url of server api
  5. private static final String url = "https://comida-95724.herokuapp.com/api/v1/restaurants/get_featured_restaurants";
  6. private ProgressDialog pDialog;
  7. private List<Movie> movieList = new ArrayList<Movie>();
  8. private ListView listView;
  9. private CustomListAdapter adapter;
  10. @Override
  11. protected void onCreate(Bundle savedInstanceState) {
  12. super.onCreate(savedInstanceState);
  13. setContentView(R.layout.activity_listview);
  14. listView = (ListView) findViewById(R.id.list);
  15. adapter = new CustomListAdapter(this, movieList);
  16. listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  17. @Override
  18. public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
  19. Movie movie = movieList.get(position);
  20. Intent intent = new Intent(ListViewActivity.this, SecondActivity.class);
  21. intent.putExtra("name", movie.getName());
  22. intent.putExtra("average_ratings", movie.getAverage_ratings());
  23. intent.putExtra("full_address", movie.getAddress());
  24. intent.putExtra("image_url", movie.getThumbnailUrl());
  25. intent.putExtra("cuisine",movie.getCuisine());
  26. intent.putExtra("cost",movie.getCost());
  27. startActivity(intent);
  28. /* listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  29. @Override
  30. public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
  31. Movie movie = movieList.get(position);
  32. // retrieve from movie whatever you want
  33. movie.getName();
  34. Intent intent = new Intent(ListViewActivity.this,SecondActivity.class);
  35. TextView name = (TextView) findViewById(R.id.name);
  36. // name.setText(movie.getName());
  37. intent.putExtra("name",movie.getName());
  38. intent.putExtra("url",movie.getThumbnailUrl());
  39. intent.putExtra("rating",movie.getAverage_ratings());
  40. intent.putExtra("add",movie.getAddress());
  41. intent.putExtra("cusine",movie.getCuisine());
  42. startActivity(intent);*/
  43. /*intent.putExtra("name",movie.getName());
  44. String name1 = intent.getStringExtra("name");
  45. name.setText(name1);
  46. startActivity(intent);
  47. intent.putExtra("param1",movie.getName());
  48. intent.putExtra("param2",movie.getName());
  49. intent.putExtra("param3",movie.getName());*/
  50. //Toast.makeText(getApplicationContext(),"Name: "+movie.getName(), Toast.LENGTH_LONG).show();
  51. }
  52. });
  53. listView.setAdapter(adapter);
  54. pDialog = new ProgressDialog(this);
  55. // Showing progress dialog before making http request
  56. pDialog.setMessage("Please Keep patience.Its loading...");
  57. pDialog.show();
  58. // changing action bar color
  59. //getActionBar().setBackgroundDrawable(
  60. // new ColorDrawable(Color.parseColor("#1b1b1b")));
  61. // Creating volley request obj
  62. JsonArrayRequest movieReq = new JsonArrayRequest(url,
  63. new Response.Listener<JSONArray>() {
  64. @Override
  65. public void onResponse(JSONArray response) {
  66. Log.d(TAG, response.toString());
  67. hidePDialog();
  68. // Parsing json
  69. for (int i = 0; i < response.length(); i++) {
  70. try {
  71. JSONObject obj = response.getJSONObject(i);
  72. Movie movie = new Movie();
  73. //movie.setTitle(obj.getString("title"));
  74. movie.setName(obj.getString("name"));
  75. //movie.setThumbnailUrl(obj.getString("image"));
  76. movie.setThumbnailUrl(obj.getString("org_image_url"));
  77. movie.setAverage_ratings(obj.getString("average_ratings"));
  78. movie.setCuisine(obj.getString("cuisine"));
  79. movie.setAddress(obj.getJSONObject("address").getString("area"));
  80. // movie.setAddress(obj.getJSONObject("address").getString("full_address"));
  81. movie.setCost(obj.getString("cost"));
  82. //movie.setYear(obj.getInt("releaseYear"));
  83. // Genre is json array
  84. /*JSONArray genreArry = obj.getJSONArray("genre");
  85. ArrayList<String> genre = new ArrayList<String>();
  86. for (int j = 0; j < genreArry.length(); j++) {
  87. genre.add((String) genreArry.get(j));
  88. }
  89. movie.setGenre(genre);*/
  90. // adding movie to movies array
  91. movieList.add(movie);
  92. } catch (JSONException e) {
  93. e.printStackTrace();
  94. }
  95. }
  96. // notifying list adapter about data changes
  97. // so that it renders the list view with updated data
  98. adapter.notifyDataSetChanged();
  99. }
  100. }, new Response.ErrorListener() {
  101. @Override
  102. public void onErrorResponse(VolleyError error) {
  103. VolleyLog.d(TAG, "Error: " + error.getMessage());
  104. hidePDialog();
  105. }
  106. });
  107. // Adding request to request queue
  108. AppController.getInstance().addToRequestQueue(movieReq);
  109. }
  110. @Override
  111. public void onDestroy() {
  112. super.onDestroy();
  113. hidePDialog();
  114. }
  115. private void hidePDialog() {
  116. if (pDialog != null) {
  117. pDialog.dismiss();
  118. pDialog = null;
  119. }
  120. }
  121. }

comments powered by Disqus