package com.example.diary;

import java.io.File;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class DiaryListActivity extends ListActivity {
	private String[] diaryList;
	private ArrayAdapter<String> adapter;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		diaryList = getFileList();
		setContentView(R.layout.diary_list);
		adapter = new ArrayAdapter<String>(this,
				  android.R.layout.simple_list_item_1, diaryList);
		setListAdapter(adapter);

	}

	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		String msg = "Position: " + position + " ID: " + id;
		Toast.makeText(this, msg, Toast.LENGTH_LONG).show();
		Intent diaryEdit = new Intent(this, DiaryActivity.class);
		diaryEdit.putExtra("FILENAME", diaryList[position]);
		startActivity(diaryEdit);
	}

	private String[] getFileList(){
		File diaryDir = getDir(DiaryActivity.DIARY_DIR, MODE_PRIVATE);
		String[] fileList = diaryDir.list();
		return fileList;
	}


}
