package com.codepath.apps.restclienttemplate;

import android.os.AsyncTask;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;

import com.codepath.apps.restclienttemplate.models.SampleModel;
import com.codepath.apps.restclienttemplate.models.SampleModelDao;
import com.codepath.oauth.OAuthLoginActionBarActivity;

public class LoginActivity extends OAuthLoginActionBarActivity<RestClient> {

	SampleModelDao sampleModelDao;

	AsyncTask<SampleModel, Void, Void> task = new AsyncTask<SampleModel, Void, Void>() {
		@Override
		protected Void doInBackground(SampleModel... sampleModels) {
			sampleModelDao.insertModel(sampleModels);
			return null;
		};
	};

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_login);

		final SampleModel sampleModel = new SampleModel();
		sampleModel.setName("CodePath");

		sampleModelDao = ((RestApplication) getApplicationContext()).getMyDatabase().sampleModelDao();

		task.execute(sampleModel);
	}


	// Inflate the menu; this adds items to the action bar if it is present.
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.login, menu);
		return true;
	}

	// OAuth authenticated successfully, launch primary authenticated activity
	// i.e Display application "homepage"
	@Override
	public void onLoginSuccess() {
		// Intent i = new Intent(this, PhotosActivity.class);
		// startActivity(i);
	}

	// OAuth authentication flow failed, handle the error
	// i.e Display an error dialog or toast
	@Override
	public void onLoginFailure(Exception e) {
		e.printStackTrace();
	}

	// Click handler method for the button used to start OAuth flow
	// Uses the client to initiate OAuth authorization
	// This should be tied to a button used to login
	public void loginToRest(View view) {
		getClient().connect();
	}

}

@@ -449,240 +449,9 @@
 ao;%0A
-%0A%09AsyncTask%3CSampleModel, Void, Void%3E task = new AsyncTask%3CSampleModel, Void, Void%3E() %7B%0A%09%09@Override%0A%09%09protected Void doInBackground(SampleModel... sampleModels) %7B%0A%09%09%09sampleModelDao.insertModel(sampleModels);%0A%09%09%09return null;%0A%09%09%7D;%0A%09%7D;%0A
+%09
 %0A%09@O
@@ -783,17 +783,22 @@
 o();%0A%0A%09%09
-t
+AsyncT
 ask.exec
@@ -801,27 +801,122 @@
 execute(
-sampleModel
+new Runnable() %7B%0A%09%09%09@Override%0A%09%09%09public void run() %7B%0A%09%09%09%09sampleModelDao.insertModel(sampleModel);%0A%09%09%09%7D%0A%09%09%7D
 );%0A%09%7D%0A%0A%0A

simplify AsyncTask to avoid needing to parameterize it