<commit_before>package fi.vincit.babyschedule.activities;

import utils.BabyEvent;
import utils.ScheduleDatabase;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.ListView;
import fi.vincit.babyschedule.R;
import fi.vincit.babyschedule.adapters.AllEventsListAdapter;

public class AllEventsList extends ListActivity 
							implements View.OnCreateContextMenuListener {
	
	private AllEventsListAdapter mListAdapter;
	
	@Override
	public void onCreate(Bundle b) {
		Log.d("Babyschedule", "Single action onCreate()");
    	super.onCreate(b);
    	
    	ScheduleDatabase.open(getApplicationContext());            
    	
    	setTitle("List of all events");    
    	
    	mListAdapter = new AllEventsListAdapter(ScheduleDatabase.getAllDbActionsSortedByDate());
    	setListAdapter(mListAdapter);
    	
    	registerForContextMenu(getListView());
	}
	
	@Override
    public void onListItemClick(ListView l, View v, int position, long id) {
		v.performLongClick();
    }
	
	@Override
    public void onStart() {
    	super.onStart();
    	mListAdapter.setActionsList(ScheduleDatabase.getAllDbActionsSortedByDate());
    }
	
	@Override
    public void onResume() {
    	super.onResume();
    	mListAdapter.setActionsList(ScheduleDatabase.getAllDbActionsSortedByDate());
    }
	
	@Override
	public void onCreateContextMenu(ContextMenu menu, View v,
									ContextMenuInfo menuInfo) {
		super.onCreateContextMenu(menu, v, menuInfo);
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.listcontextmenu, menu);
	}
	
	@Override
	public boolean onContextItemSelected(MenuItem item) {
		AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
		BabyEvent event = (BabyEvent)info.targetView.getTag();
		switch (item.getItemId()) {
		case R.id.delete_activity:			
			ScheduleDatabase.deleteEntryBasedOnDate(event.getActionDate());
			mListAdapter.setActionsList(ScheduleDatabase.getAllDbActionsSortedByDate());
			return true;
		case R.id.edit_activity:
			openEditViewForEvent(event);
			return true;
		default:
			return super.onContextItemSelected(item);
		}<commit_msg>-Bugfix: if go to sleep is deleted from list, also the corresponding wake up is deleted<commit_after>package fi.vincit.babyschedule.activities;

import java.util.Date;

import utils.BabyEvent;
import utils.ScheduleDatabase;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.ListView;
import fi.vincit.babyschedule.R;
import fi.vincit.babyschedule.adapters.AllEventsListAdapter;

public class AllEventsList extends ListActivity 
							implements View.OnCreateContextMenuListener {
	
	private AllEventsListAdapter mListAdapter;
	
	@Override
	public void onCreate(Bundle b) {
		Log.d("Babyschedule", "Single action onCreate()");
    	super.onCreate(b);
    	
    	ScheduleDatabase.open(getApplicationContext());            
    	
    	setTitle("List of all events");    
    	
    	mListAdapter = new AllEventsListAdapter(ScheduleDatabase.getAllDbActionsSortedByDate());
    	setListAdapter(mListAdapter);
    	
    	registerForContextMenu(getListView());
	}
	
	@Override
    public void onListItemClick(ListView l, View v, int position, long id) {
		v.performLongClick();
    }
	
	@Override
    public void onStart() {
    	super.onStart();
    	mListAdapter.setActionsList(ScheduleDatabase.getAllDbActionsSortedByDate());
    }
	
	@Override
    public void onResume() {
    	super.onResume();
    	mListAdapter.setActionsList(ScheduleDatabase.getAllDbActionsSortedByDate());
    }
	
	@Override
	public void onCreateContextMenu(ContextMenu menu, View v,
									ContextMenuInfo menuInfo) {
		super.onCreateContextMenu(menu, v, menuInfo);
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.listcontextmenu, menu);
	}
	
	@Override
	public boolean onContextItemSelected(MenuItem item) {
		AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
		BabyEvent event = (BabyEvent)info.targetView.getTag();
		switch (item.getItemId()) {
		case R.id.delete_activity:			
			ScheduleDatabase.deleteEntryBasedOnDate(event.getActionDate());
			if( event.getActionName().equals(getString(R.string.go_to_nap)) ||
				event.getActionName().equals(getString(R.string.go_to_nap)) ) {
				Date wokeupDate = ScheduleDatabase.getWakeUpDateFromSleepDate(event.getActionDate());
				ScheduleDatabase.deleteEntryBasedOnDate(wokeupDate);
			}
			mListAdapter.setActionsList(ScheduleDatabase.getAllDbActionsSortedByDate());
			return true;
		case R.id.edit_activity:
			openEditViewForEvent(event);
			return true;
		default:
			return super.onContextItemSelected(item);
		}
{'fraction_non_alphanumeric': 0.09578544061302682, 'fraction_numerical': 0.0, 'mean_word_length': 4.82051282051282, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5324816', 'n_tokens_mistral': 1709, 'n_tokens_neox': 1546, 'n_words': 286}