package fishrungames.bashgid.core;

import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import fishrungames.bashgid.MainActivity;
import fishrungames.bashgid.core.JournalManager.JournalSemiFullData;

public class DatabaseGetJournalTask extends AsyncTask<Bundle, Integer, Long>
{

	JournalSemiFullData journal = null;
	
	public Handler mHandler;

	protected Long doInBackground(Bundle... queryArr)
	{
		
		String journalName = queryArr[0].getString("journalName");
		
		String startAfterArticleName = queryArr[0].getString("startAfterArticleName");
	
		int count = queryArr[0].getInt("count", 0);
		
		journal = MainActivity.getInstance().journalDataSource.GetJournalSemiFullData(journalName, startAfterArticleName, count);
		
		return (long) 0;
	}

	protected void onProgressUpdate(Integer... progress)
	{
		Message completeMessage = mHandler.obtainMessage(MainActivity.DATABASE_GET_JOURNAL_STATE_UPDATE, journal);

		completeMessage.sendToTarget();

	}

	protected void onPostExecute(Long result)
	{
		Message completeMessage = mHandler.obtainMessage(MainActivity.DATABASE_GET_JOURNAL_STATE_FINISHED, journal);

		completeMessage.sendToTarget();
	}
}