Mahmoudsobhy_1ali

Untitled

Apr 20th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. package com.udacity.sandwichclub;
  2.  
  3. import android.content.Intent;
  4. import android.os.Bundle;
  5. import android.support.v7.app.AppCompatActivity;
  6. import android.widget.ImageView;
  7. import android.widget.TextView;
  8. import android.widget.Toast;
  9.  
  10. import com.squareup.picasso.Picasso;
  11. import com.udacity.sandwichclub.model.Sandwich;
  12. import com.udacity.sandwichclub.utils.JsonUtils;
  13.  
  14. import org.json.JSONException;
  15.  
  16. public class DetailActivity extends AppCompatActivity {
  17.  
  18. public static final String EXTRA_POSITION = "extra_position";
  19. private static final int DEFAULT_POSITION = -1;
  20.  
  21. @Override
  22. protected void onCreate(Bundle savedInstanceState) {
  23. super.onCreate(savedInstanceState);
  24. setContentView(R.layout.activity_detail);
  25.  
  26. // Intent intent = getIntent();
  27. // if (intent == null) {
  28. // closeOnError();
  29. // }
  30. Intent intent = getIntent();
  31. if (intent.hasExtra("main")){
  32. Toast.makeText(this, "welcome", Toast.LENGTH_SHORT).show();
  33. }
  34.  
  35. ImageView ingredientIV = findViewById(R.id.image_iv);
  36.  
  37. int position = intent.getIntExtra("main", DEFAULT_POSITION);
  38. if (position == DEFAULT_POSITION) {
  39. // EXTRA_POSITION not found in intent
  40. closeOnError();
  41. return;
  42. }
  43.  
  44. String[] sandwiches = getResources().getStringArray(R.array.sandwich_details);
  45. String json = sandwiches[position];
  46. Sandwich sandwich = JsonUtils.parseSandwichJson(json);
  47. if (sandwich == null) {
  48. // Sandwich data unavailable
  49. // closeOnError();
  50. return;
  51. }
  52.  
  53. populateUI();
  54. Picasso.with(this)
  55. .load(sandwich.getImage())
  56. .into(ingredientIV);
  57. setTitle(sandwich.getMainName());
  58. }
  59.  
  60. private void closeOnError() {
  61. finish();
  62. Toast.makeText(this, R.string.detail_error_message, Toast.LENGTH_SHORT).show();
  63. }
  64.  
  65. private void populateUI() {
  66.  
  67. }
  68. }
Add Comment
Please, Sign In to add comment