package com.sparkwing.localview;

import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.view.Gravity;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.TextView;

import com.facebook.drawee.drawable.ProgressBarDrawable;
import com.facebook.drawee.generic.GenericDraweeHierarchy;
import com.facebook.drawee.generic.GenericDraweeHierarchyBuilder;
import com.facebook.drawee.view.SimpleDraweeView;

/**
 * Created by zachfreeman on 9/19/15.
 */
public class PhotoFullScreenActivity extends AppCompatActivity {
    private static final String TAG = PhotoFullScreenActivity.class.getSimpleName();

    private SimpleDraweeView mFullImageView;
    private TextView mTitleTextView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_photo_full_view);

        ActionBar actionBar = getSupportActionBar();
        actionBar.setDisplayHomeAsUpEnabled(true);

        Bundle bundle = getIntent().getExtras();
        FlickrPhoto flickrPhoto = bundle.getParcelable(FlickrPhoto.BUNDLE_KEY);

        setupFullImageView(flickrPhoto);
        boolean tabletSize = getResources().getBoolean(R.bool.isTablet);
        if (tabletSize) {
            setupTitleTextView(flickrPhoto);
        }

    }

    protected void setupFullImageView(FlickrPhoto flickrPhoto) {
        mFullImageView = (SimpleDraweeView) findViewById(R.id.fullImageView);
        GenericDraweeHierarchyBuilder draweeHierarchyBuilder = new GenericDraweeHierarchyBuilder(getResources());
        GenericDraweeHierarchy draweeHierarchy = draweeHierarchyBuilder
                .setProgressBarImage(new ProgressBarDrawable())
                .build();
        mFullImageView.setHierarchy(draweeHierarchy);

        String bigImageUrl = flickrPhoto.getBigImageUrl();

        Uri uri = Uri.parse(bigImageUrl);
        mFullImageView.setImageURI(uri);

        Animation slideAnimation = AnimationUtils.loadAnimation(this, R.anim.slide);
        mFullImageView.startAnimation(slideAnimation);
    }

    protected void setupTitleTextView(FlickrPhoto flickrPhoto) {
        mTitleTextView = (TextView)findViewById(R.id.titleText);
        String titleComment = flickrPhoto.getTitleComment();
        mTitleTextView.setText(titleComment);
        mTitleTextView.setGravity(Gravity.CENTER);
    }
}



@@ -46,39 +46,128 @@
 oid.
-net.Uri;%0Aimport android.os.Bund
+graphics.drawable.Animatable;%0Aimport android.net.Uri;%0Aimport android.os.Bundle;%0Aimport android.support.annotation.Nullab
 le;%0A
@@ -400,24 +400,164 @@
 t.TextView;%0A
+import android.widget.Toast;%0A%0Aimport com.facebook.drawee.backends.pipeline.Fresco;%0Aimport com.facebook.drawee.controller.ControllerListener;
 %0Aimport com.
@@ -723,24 +723,80 @@
 chyBuilder;%0A
+import com.facebook.drawee.interfaces.DraweeController;%0A
 import com.f
@@ -943,16 +943,46 @@
 ctivity 
+implements ControllerListener 
 %7B%0A    pr
@@ -1139,24 +1139,56 @@
 leTextView;%0A
+    Animation mSlideAnimation;%0A%0A
     @Overrid
@@ -1294,64 +1294,284 @@
 e);%0A
-        setContentView(R.layout.activity_photo_full_view
+%0A        mSlideAnimation = AnimationUtils.loadAnimation(this, R.anim.slide);%0A        setContentView(R.layout.activity_photo_full_view);%0A        mFullImageView = (SimpleDraweeView) findViewById(R.id.fullImageView);%0A        mTitleTextView = (TextView)findViewById(R.id.titleText
 );%0A%0A
@@ -2073,24 +2073,25 @@
 hoto) %7B%0A
+%0A
         
 mFullIma
@@ -2086,77 +2086,102 @@
     
-mFullImageView = (SimpleDraweeView) findViewById(R.id.fullImageView);
+String bigImageUrl = flickrPhoto.getBigImageUrl();%0A        Uri uri = Uri.parse(bigImageUrl);%0A%0A
 %0A   
@@ -2508,24 +2508,25 @@
 rchy);%0A%0A
+%0A
         
 String b
@@ -2521,284 +2521,225 @@
     
-String bigImageUrl = flickrPhoto.getBigImageUrl();%0A%0A        Uri uri = Uri.parse(bigImageUrl);%0A        mFullImageView.setImageURI(uri);%0A%0A        Animation slideAnimation = AnimationUtils.loadAnimation(this, R.anim.slide);%0A        mFullImageView.startAnimation(slideAnimation
+DraweeController controller = Fresco.newDraweeControllerBuilder()%0A                .setUri(uri)%0A                .setControllerListener(this)%0A                .build();%0A        mFullImageView.setController(controller
 );%0A
+%0A
     
@@ -2810,72 +2810,8 @@
 ) %7B%0A
-        mTitleTextView = (TextView)findViewById(R.id.titleText);
 %0A   
@@ -2970,13 +2970,871 @@
 );%0A    %7D
+%0A%0A    //region ControllerListener implementation methods%0A    @Override%0A    public void onSubmit(String s, Object o) %7B%0A%0A    %7D%0A%0A    @Override%0A    public void onFinalImageSet(%0A            String id,%0A            @Nullable Object imageInfo,%0A            @Nullable Animatable animatable) %7B%0A        if (imageInfo == null) %7B%0A            return;%0A        %7D else %7B%0A            mFullImageView.startAnimation(mSlideAnimation);%0A        %7D%0A    %7D%0A%0A    @Override%0A    public void onIntermediateImageSet(String s, @Nullable Object o) %7B%0A%0A    %7D%0A%0A    @Override%0A    public void onIntermediateImageFailed(String s, Throwable throwable) %7B%0A%0A    %7D%0A%0A    @Override%0A    public void onFailure(String s, Throwable throwable) %7B%0A        Toast.makeText(this, %22Photo Download Failure%22, Toast.LENGTH_LONG).show();%0A    %7D%0A%0A    @Override%0A    public void onRelease(String s) %7B%0A%0A    %7D%0A    //endregion%0A%0A
 %0A%7D%0A%0A%0A

Add ControllerListener implementation to full image view