/*
 * Copyright (c) 2017 CMPUT301F17T15. This project is distributed under the MIT license.
 */

package com.cmput301.cia.activities;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;

import com.cmput301.cia.R;
import com.cmput301.cia.models.HabitEvent;

/**
 * created by Tinghui.
 * on 11/8/2017.
 */

public class HabitEventViewActivity extends AppCompatActivity {

    public static final String ID_INDEX = "Index";
    public static final String RETURNED_INDEX = "Index", RETURNED_EVENT = "Event", RETURNED_DELETED = "Deleted";

    private TextView habitEventName;
    private TextView habitEventDate;
    private TextView habitEventLocation;
    private TextView habitEventPhoto;
    TextView habitEventComment;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_habit_event_view);
        /**
         * display habit event information.
         */
        habitEventName = (TextView) findViewById(R.id.EventName);
        habitEventDate = (TextView) findViewById(R.id.EventDate);
        habitEventLocation = (TextView) findViewById(R.id.EventLocation);
        habitEventPhoto = (TextView) findViewById(R.id.EventPhoto);
        habitEventComment = (TextView) findViewById(R.id.EventComment);

        HabitEvent habitevent = (HabitEvent) getIntent().getSerializableExtra("HabitEvent");

        habitEventName.setText(habitevent.getTittle());
        habitEventDate.setText(habitevent.getDate().toString());

        if (habitevent.getLocation() != null)
            habitEventLocation.setText(habitevent.getLocation().toString());
        habitEventPhoto.setText(habitevent.getBase64EncodedPhoto());
        habitEventComment.setText(habitevent.getComment());

    }

    /**
     * the following three function basic on createhabitEventActivity.
     * Handles the save button being clicked
     * @param view
     */
    public void onSaveClicked(View view){
        finishActivity(false);
    }

    /**
     * Handles the delete button being clicked
     * @param view
     */
    public void onDeleteClicked(View view){
        finishActivity(true);
    }

    /**
     * End this activity after the user clicks on either "Edit" or "Delete"
     * Adds data to the intent object if the user selects "Save"
     * @param deleted whether the Delete button was clicked or not
     */
    private void finishActivity(boolean deleted){
        Intent intent = new Intent();
        if (deleted) {

        }
        

        
    }
}

@@ -128,16 +128,45 @@
 ities;%0A%0A
+import android.app.Activity;%0A
 import a
@@ -289,16 +289,48 @@
 w.View;%0A
+import android.widget.EditText;%0A
 import a
@@ -861,24 +861,32 @@
 to;%0A    
+private Edit
 Text
-View
  habitEv
@@ -898,16 +898,45 @@
 mment;%0A%0A
+    private String habitId;%0A%0A
 %0A    @Ov
@@ -1167,24 +1167,113 @@
          */%0A
+        Intent intent = getIntent();%0A        habitId = intent.getStringExtra(ID_INDEX);%0A%0A
         habi
@@ -1559,32 +1559,32 @@
 tComment = (
+Edit
 Text
-View
 ) findViewBy
@@ -1592,19 +1592,18 @@
 d(R.id.E
-ven
+di
 tComment
@@ -2811,16 +2811,147 @@
 eted) %7B%0A
+            intent.putExtra(%22INDEX%22, ID_INDEX);%0A            setResult(RESULT_OK, intent);%0A            finish();%0A            return;
 %0A       
@@ -2953,24 +2953,25 @@
       %7D%0A
+%0A
         
 %0A%0A      
@@ -2962,26 +2962,306 @@
         
-%0A%0A        
+String comment = ((EditText)findViewById(R.id.EditComment)).getText().toString();%0A        HabitEvent event = new HabitEvent(comment);%0A        intent.putExtra(RETURNED_INDEX, event);%0A        intent.putExtra(ID_INDEX, habitId);%0A        setResult(Activity.RESULT_OK, intent);%0A        finish();
 %0A    %7D%0A%7D

add control ability of delete and edit for habit event view