package edu.alaska.gina.feeder.gina_puffinfeeder_android_viewer;

import android.app.Activity;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.*;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.octo.android.robospice.SpiceManager;
import com.octo.android.robospice.persistence.exception.SpiceException;
import com.octo.android.robospice.request.listener.RequestListener;
import com.octo.android.robospice.request.simple.BitmapRequest;

import java.io.File;


public class FullscreenImageViewerActivity extends Activity {
    private static final int UI_HIDE_OPTIONS = View.SYSTEM_UI_FLAG_LOW_PROFILE;
    SpiceManager manager = new SpiceManager(JsonSpiceService.class);
    private String url;

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

    @Override
    protected void onStart() {
        super.onStart();
        manager.start(this);
        this.findViewById(R.id.fullscreen_content).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                v.setSystemUiVisibility(UI_HIDE_OPTIONS);
            }
        });

        Bundle b = getIntent().getExtras();
        url = b.getString("image_url_" + b.getInt("position") + "_2");
        networkRequest();

        this.getWindow().getDecorView().setSystemUiVisibility(UI_HIDE_OPTIONS);
    }

    @Override
    protected void onStop() {
        manager.shouldStop();
        super.onStop();
    }

    private void networkRequest() {
        //String temp = "http://feeder.gina.alaska.edu/media/W1siZiIsIjIwMTQvMDYvMDIvMTNfMDlfNDZfMzUyX1NJUl8yMDE0MDYwMl8xMjUxX21hc2tlZC5qcGciXSxbInAiLCJ0aHVtYiIsIjIwMDB4MjAwMCJdXQ/SIR_20140602_1251_masked.jpg";
        BitmapRequest br = new BitmapRequest(url, new File(getCacheDir().getAbsolutePath() + "file.jpg"));

        manager.execute(br, new BitmapRequestListener());
    }

    private class BitmapRequestListener implements RequestListener<Bitmap> {
        @Override
        public void onRequestFailure(SpiceException e) {
            Toast.makeText(getBaseContext(), "Image Request Fail!", Toast.LENGTH_LONG).show();
        }

        @Override
        public void onRequestSuccess(Bitmap bitmap) {
            ((ImageView)findViewById(R.id.fullscreen_content)).setImageBitmap(bitmap);
        }
    }
}

@@ -1575,20 +1575,21 @@
  void on
-Stop
+Pause
 () %7B%0A   
@@ -1631,20 +1631,21 @@
 super.on
-Stop
+Pause
 ();%0A    
@@ -1655,250 +1655,144 @@
     
-priva
+@Override%0A    protec
 te
+d
  void 
-networkRequest() %7B%0A        //String temp = %22http://feeder.gina.alaska.edu/media/W1siZiIsIjIwMTQvMDYvMDIvMTNfMDlfNDZfMzUyX1NJUl8yMDE0MDYwMl8xMjUxX21hc2tlZC5qcGciXSxbInAiLCJ0aHVtYiIsIjIwMDB4MjAwMCJdXQ/SIR_20140602_1251_masked.jpg%22;
+onStop() %7B%0A        manager.shouldStop();%0A        super.onStop();%0A    %7D%0A%0A    private void networkRequest() %7B
 %0A   
@@ -1895,17 +1895,16 @@
 jpg%22));%0A
-%0A
         

Stop SpiceService on Pause