package com.maxiee.attitude.ui;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.widget.TextView;

import com.maxiee.attitude.R;
import com.maxiee.attitude.database.api.GetOneEventApi;
import com.maxiee.attitude.model.Event;
import com.maxiee.attitude.ui.adapter.ThoughtTimeaxisAdapter;

import org.json.JSONException;

/**
 * Created by maxiee on 15-6-13.
 */
public class EventDetailActivity extends AppCompatActivity {

    private Event mEvent;

    private TextView mTvEvent;
    private RecyclerView mRecyclerView;

    public static final String EXTRA_NAME = "id";

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

        Intent intent = getIntent();
        final int id = intent.getIntExtra(EXTRA_NAME, -1);

        final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        mTvEvent = (TextView) findViewById(R.id.tv_event);
        mRecyclerView = (RecyclerView) findViewById(R.id.recyclerview);

        try {
            mEvent =  new GetOneEventApi(this, id).exec();
            mTvEvent.setText(mEvent.getmEvent());
            mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
            mRecyclerView.setAdapter(new ThoughtTimeaxisAdapter(mEvent.getmThoughts()));
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
}

@@ -83,16 +83,75 @@
 Bundle;%0A
+import android.support.design.widget.FloatingActionButton;%0A
 import a
@@ -359,16 +359,42 @@
 il.Log;%0A
+import android.view.View;%0A
 import a
@@ -605,16 +605,71 @@
 Adapter;
+%0Aimport com.maxiee.attitude.ui.dialog.NewThoughtDialog;
 %0A%0Aimport
@@ -894,16 +894,82 @@
 lerView;
+%0A    private ThoughtTimeaxisAdapter mAdapter;%0A    private int mId;
 %0A%0A    pu
@@ -1234,19 +1234,10 @@
     
-final int i
+mI
 d = 
@@ -1638,17 +1638,18 @@
 i(this, 
-i
+mI
 d).exec(
@@ -1793,84 +1793,961 @@
    m
-RecyclerView.setAdapter(new ThoughtTimeaxisAdapter(mEvent.getmThoughts()));%0A
+Adapter = new ThoughtTimeaxisAdapter(mEvent.getmThoughts());%0A            mRecyclerView.setAdapter(mAdapter);%0A        %7D catch (JSONException e) %7B%0A            e.printStackTrace();%0A        %7D%0A%0A        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);%0A        fab.setOnClickListener(new View.OnClickListener() %7B%0A            @Override%0A            public void onClick(View v) %7B%0A                NewThoughtDialog dialog = new NewThoughtDialog(EventDetailActivity.this, mId);%0A                dialog.setOnAddFinishedListener(new NewThoughtDialog.OnAddFinishedListener() %7B%0A                    @Override%0A                    public void update() %7B%0A                        try %7B%0A                            mEvent = new GetOneEventApi(EventDetailActivity.this, mId).exec();%0A                            mAdapter = new ThoughtTimeaxisAdapter(mEvent.getmThoughts());%0A                            mRecyclerView.setAdapter(mAdapter);%0A                
     
@@ -2782,32 +2782,48 @@
 ) %7B%0A            
+     
+           
 e.printStackTrac
@@ -2835,17 +2835,132 @@
         
-%7D
+                %7D%0A                    %7D%0A                %7D);%0A                dialog.show();%0A            %7D%0A        %7D);
 %0A    %7D%0A%7D

handle fab click to open dialog to add new thought.