package se.chalmers.watchme.activity;

import java.io.Serializable;

import se.chalmers.watchme.R;
import android.os.Bundle;
import android.app.ListActivity;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ArrayAdapter;

public class MainActivity extends ListActivity {
	
	public static final int ADD_MOVIE_REQUEST = 1;
	
	private ArrayAdapter<Serializable> moviesAdapter;
	

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        this.moviesAdapter = new ArrayAdapter<Serializable>(this, android.R.layout.simple_list_item_1);
        setListAdapter(this.moviesAdapter);
    }
    
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    	if(requestCode == ADD_MOVIE_REQUEST && resultCode == RESULT_OK) {
    		this.moviesAdapter.add(data.getSerializableExtra("movie"));
    	}
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
    
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        
        Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
        intent.setClass(this, AddMovieActivity.class);
        
        startActivityForResult(intent, ADD_MOVIE_REQUEST);
        
        return true;
    }
}

@@ -92,16 +92,56 @@
 chme.R;%0A
+import se.chalmers.watchme.model.Movie;%0A
 import a
@@ -158,16 +158,16 @@
 Bundle;%0A
-
 import a
@@ -278,16 +278,136 @@
 nuItem;%0A
+import android.view.View;%0Aimport android.widget.AdapterView;%0Aimport android.widget.AdapterView.OnItemLongClickListener;%0A
 import a
@@ -907,16 +907,104 @@
 apter);%0A
+        %0A        this.getListView().setOnItemLongClickListener(new OnDeleteListener());%0A
     %7D%0A  
@@ -1684,32 +1684,32 @@
 UEST);%0A        %0A
-
         return t
@@ -1719,10 +1719,327 @@
 ;%0A    %7D%0A
+    %0A    %0A    private class OnDeleteListener implements OnItemLongClickListener %7B%0A    %09public boolean onItemLongClick(AdapterView%3C?%3E parent, View view, int position, long id) %7B%0A%09%09%09%0A%09%09%09Movie movie = (Movie) getListView().getItemAtPosition(position);%0A%09%09%09moviesAdapter.remove(movie);%0A%09%09%09%0A%09%09%09return true;%0A%09%09%7D%0A    %09%0A    %7D%0A
 %7D%0A

Add feature to remove movies from list.