package org.foi.androidworkshop.activities;

import org.foi.androidworkshop.R;
import org.foi.androidworkshop.adapters.ListAdapter;
import org.foi.androidworkshop.models.MusicAlbum;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

public class ListActivity extends BaseActivity {

    private RecyclerView recyclerView;
    private LinearLayoutManager layoutManager;
    private List<MusicAlbum> musicAlbums;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_list);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        musicAlbums = generateListData();
        initRecyclerView();
    }

    private void initRecyclerView() {
        recyclerView = (RecyclerView) findViewById(R.id.rvListActivity);

        layoutManager = new LinearLayoutManager(getBaseContext());

        recyclerView.setHasFixedSize(true);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setAdapter(new ListAdapter(musicAlbums, this));
    }

    private List<MusicAlbum> generateListData() {
        List<MusicAlbum> ret = new ArrayList<>();

        ret.add(new MusicAlbum("https://upload.wikimedia.org/wikipedia/en/9/92/Fungus_amongus.jpg", "Incubus", "Fungus Amongus", 1995));
        ret.add(new MusicAlbum("https://upload.wikimedia.org/wikipedia/en/4/4f/Incubus_Science.jpg", "Incubus", "S.C.I.E.N.C.E.", 1997));
        ret.add(new MusicAlbum("https://upload.wikimedia.org/wikipedia/en/6/68/Incubus_-_Morning_View.jpg", "Incubus", "Morning View", 2001));
        ret.add(new MusicAlbum("https://upload.wikimedia.org/wikipedia/en/8/8d/ACrowLeftoftheMurderIncubus.jpg", "Incubus", "A Crow Left After the Murder", 2004));
        ret.add(new MusicAlbum("https://upload.wikimedia.org/wikipedia/en/0/0f/Incubus_-_Light_Grenades.jpg", "Incubus", "Light Grenades", 2006));
        ret.add(new MusicAlbum("https://upload.wikimedia.org/wikipedia/en/2/22/If_not_now_when_album_cover.jpg", "Incubus", "If Not Now, When?", 2011));

        return ret;
    }
}

@@ -302,16 +302,46 @@
 lerView;
+%0Aimport android.view.MenuItem;
 %0A%0Aimport
@@ -2232,11 +2232,343 @@
 t;%0A    %7D
+%0A%0A    @Override%0A    public boolean onOptionsItemSelected(MenuItem item) %7B%0A        int id = item.getItemId();%0A        switch (id) %7B%0A            case android.R.id.home:%0A                onBackPressed();%0A                break;%0A            default:%0A                break;%0A        %7D%0A        return super.onOptionsItemSelected(item);%0A    %7D
 %0A%7D%0A

Add back button event handler in ListActivity