package com.example.habitrack;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import java.util.Calendar;

public class HabitEventDetailsActivity extends AppCompatActivity {
    private Integer htID = -1;
    private Integer heID = -1;
    Button editButton;
    TextView heTypeView;
    TextView heDateView;
    EditText heCommentView;
    ImageView heImageView;
    String typeName;
    String eventName;
    String heComment;
    Calendar heDate;
    String heImage;
    String newComment;
    HabitTypeController htc = new HabitTypeController(this);
    HabitEventController he = new HabitEventController(this);
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_habit_event_details);
        Intent intent = getIntent();
        htID = intent.getIntExtra("habitTypeID", -1);
        heID = intent.getIntExtra("habitEventID", -1);
        typeName = htc.getHabitType(htID).getTitle();
        heDate = he.getHabitEvent(heID).getDate();
        heComment = he.getHabitEvent(heID).getComment();
        heImage = he.getHabitEvent(heID).getPhoto();
        eventName = he.getHabitEventTitle(heID);

        heTypeView = (TextView) findViewById(R.id.textView4);
        heDateView = (TextView) findViewById(R.id.eventDate);
        heCommentView = (EditText) findViewById(R.id.editText11);
        heImageView = (ImageView) findViewById(R.id.imageView2);
        editButton = (Button) findViewById(R.id.editHe);

        Log.d("titles","this is the title "+ eventName);
        heTypeView.setText(eventName);
        heDateView.setText(heDate.toString());
        heCommentView.setText(heComment);

        editButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                newComment = heCommentView.getText().toString();
                he.getHabitEvent(heID).setComment(newComment);
                Toast.makeText(getApplicationContext(), "Applying Edits",
                        Toast.LENGTH_SHORT).show();
            }
        });








    }
}

@@ -56,16 +56,48 @@
 Intent;%0A
+import android.graphics.Bitmap;%0A
 import a
@@ -114,16 +114,16 @@
 Bundle;%0A
-
 import a
@@ -397,16 +397,64 @@
 alendar;
+%0Aimport java.util.concurrent.ExecutionException;
 %0A%0Apublic
@@ -801,18 +801,48 @@
  String 
-h
 e
+ncodedImage;%0A    Bitmap decoded
 Image;%0A 
@@ -1476,26 +1476,31 @@
 ();%0A        
-h
 e
+ncoded
 Image = he.g
@@ -1515,26 +1515,376 @@
 vent
-(heID).getPhoto();
+EncodedPhoto(heID);%0A        ImageHandler.Decompressor decompressor = new ImageHandler.Decompressor();%0A        decompressor.execute(encodedImage);%0A        try %7B%0A            decodedImage = decompressor.get();%0A        %7D catch (InterruptedException e) %7B%0A            e.printStackTrace();%0A        %7D catch (ExecutionException e) %7B%0A            e.printStackTrace();%0A        %7D%0A%0A
 %0A   
@@ -2185,16 +2185,16 @@
 View2);%0A
-
         
@@ -2241,16 +2241,66 @@
 editHe);
+%0A        heImageView.setImageBitmap(decodedImage);
 %0A%0A      

set imageview to display actual image of the event if present