Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.udacity.sandwichclub;
- import android.content.Intent;
- import android.os.Bundle;
- import android.support.v7.app.AppCompatActivity;
- import android.widget.ImageView;
- import android.widget.TextView;
- import android.widget.Toast;
- import com.squareup.picasso.Picasso;
- import com.udacity.sandwichclub.model.Sandwich;
- import com.udacity.sandwichclub.utils.JsonUtils;
- import org.json.JSONException;
- public class DetailActivity extends AppCompatActivity {
- public static final String EXTRA_POSITION = "extra_position";
- private static final int DEFAULT_POSITION = -1;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_detail);
- // Intent intent = getIntent();
- // if (intent == null) {
- // closeOnError();
- // }
- Intent intent = getIntent();
- if (intent.hasExtra("main")){
- Toast.makeText(this, "welcome", Toast.LENGTH_SHORT).show();
- }
- ImageView ingredientIV = findViewById(R.id.image_iv);
- int position = intent.getIntExtra("main", DEFAULT_POSITION);
- if (position == DEFAULT_POSITION) {
- // EXTRA_POSITION not found in intent
- closeOnError();
- return;
- }
- String[] sandwiches = getResources().getStringArray(R.array.sandwich_details);
- String json = sandwiches[position];
- Sandwich sandwich = JsonUtils.parseSandwichJson(json);
- if (sandwich == null) {
- // Sandwich data unavailable
- // closeOnError();
- return;
- }
- populateUI();
- Picasso.with(this)
- .load(sandwich.getImage())
- .into(ingredientIV);
- setTitle(sandwich.getMainName());
- }
- private void closeOnError() {
- finish();
- Toast.makeText(this, R.string.detail_error_message, Toast.LENGTH_SHORT).show();
- }
- private void populateUI() {
- }
- }
Add Comment
Please, Sign In to add comment