package ca.six.todo.home;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
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.view.View;
import android.view.Menu;
import android.view.MenuItem;

import java.util.List;

import ca.six.todo.R;
import ca.six.todo.add_task.AddTaskActivity;
import ca.six.todo.model.Task;
import ca.six.util.L;

// TODO generic to make presenter follow the Activity's life cycle
public class HomeActivity extends AppCompatActivity {
    private HomePresenter presenter;
    private RecyclerView rv;
    private HomeAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);
        final HomeActivity self = this;
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(new Intent(self, AddTaskActivity.class));
            }
        });

        rv = (RecyclerView) findViewById(R.id.rvHome);
        rv.setLayoutManager( new LinearLayoutManager(this));
        adapter = new HomeAdapter();
        rv.setAdapter(this.adapter);

        presenter = new HomePresenter(this);
        presenter.getTasks();
    }

    public void showTasks(List<Task> tasks) {
        adapter.data = tasks;
        adapter.notifyDataSetChanged();
        L.d(" size = "+tasks.size());
    }
}

@@ -1368,16 +1368,25 @@
 Activity
+ForResult
 (new Int
@@ -1417,16 +1417,20 @@
 y.class)
+, 21
 );%0A     
@@ -1883,11 +1883,218 @@
 );%0A    %7D
+%0A%0A    @Override%0A    protected void onActivityResult(int requestCode, int resultCode, Intent data) %7B%0A        if(requestCode == 21 && resultCode == RESULT_OK)%7B%0A            presenter.getTasks();%0A        %7D%0A    %7D
 %0A%7D%0A

add AddTask***