package es.npatarino.android.gotchallenge.view.activities;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.widget.ImageView;
import android.widget.TextView;

import java.io.IOException;
import java.net.URL;

import es.npatarino.android.gotchallenge.R;

public class DetailActivity extends AppCompatActivity {


    private static final String TAG = "DetailActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_detail);

        final ImageView ivp = (ImageView) findViewById(R.id.iv_photo);
        final TextView tvn = (TextView) findViewById(R.id.tv_name);
        final TextView tvd = (TextView) findViewById(R.id.tv_description);

        final String d = getIntent().getStringExtra("description");
        final String n = getIntent().getStringExtra("name");
        final String i = getIntent().getStringExtra("imageUrl");

        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        toolbar.setTitle(n);
        setSupportActionBar(toolbar);
        if (getSupportActionBar() != null) {
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        }

        new Thread(new Runnable() {
            @Override
            public void run() {
                URL url = null;
                try {
                    url = new URL(i);
                    final Bitmap bmp = BitmapFactory.decodeStream(url.openConnection().getInputStream());
                    DetailActivity.this.runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            ivp.setImageBitmap(bmp);
                            tvn.setText(n);
                            tvd.setText(d);
                        }
                    });
                } catch (IOException e) {
                    Log.e(TAG, e.getLocalizedMessage());
                }
            }
        }).start();
    }
}

@@ -57,79 +57,8 @@
 s;%0A%0A
-import android.graphics.Bitmap;%0Aimport android.graphics.BitmapFactory;%0A
 impo
@@ -79,16 +79,16 @@
 Bundle;%0A
+
 import a
@@ -174,33 +174,8 @@
 ar;%0A
-import android.util.Log;%0A
 impo
@@ -247,48 +247,36 @@
 ort 
-java.io.IOException;%0Aimport java.net.URL
+com.squareup.picasso.Picasso
 ;%0A%0Ai
@@ -1276,776 +1276,110 @@
     
-new Thread(new Runnable() %7B%0A            @Override%0A            public void run() %7B%0A                URL url = null;%0A                try %7B%0A                    url = new URL(i);%0A                    final Bitmap bmp = BitmapFactory.decodeStream(url.openConnection().getInputStream());%0A                    DetailActivity.this.runOnUiThread(new Runnable() %7B%0A                        @Override%0A                        public void run() %7B%0A                            ivp.setImageBitmap(bmp);%0A                            tvn.setText(n);%0A                            tvd.setText(d);%0A                        %7D%0A                    %7D);%0A                %7D catch (IOException e) %7B%0A                    Log.e(TAG, e.getLocalizedMessage());%0A                %7D%0A            %7D%0A        %7D).start(
+Picasso.with(getApplicationContext()).load(i).into(ivp);%0A        tvn.setText(n);%0A        tvd.setText(d
 );%0A 

replace thread for picasso in DetailActivity