package com.example.drinkingapp;

import java.util.ArrayList;
import java.util.Date;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;

public class Menu extends Activity implements OnClickListener {

	private Button tracking, assessment, visualize, settings, resources;
	private Intent goToThisPage;
	private DatabaseHandler db;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		//get database
		db = new DatabaseHandler(this);
		
		requestWindowFeature(Window.FEATURE_NO_TITLE);// full screen
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FULLSCREEN);
		setContentView(R.layout.menu);
		tracking = (Button) findViewById(R.id.bMenuTracking);
		assessment = (Button) findViewById(R.id.bMenuAssessment);
		visualize = (Button) findViewById(R.id.bMenuVisualize);
		settings = (Button) findViewById(R.id.bMenuSettings);
		resources = (Button) findViewById(R.id.bMenuResources);

		tracking.setOnClickListener(this);
		assessment.setOnClickListener(this);
		visualize.setOnClickListener(this);
		settings.setOnClickListener(this);
		resources.setOnClickListener(this);

	}

	@Override
	public void onClick(View arg0) {
		// TODO Auto-generated method stub
		switch (arg0.getId()) {
		case R.id.bMenuTracking:
			// goToThisPage = new Intent(Menu.this,Class.Tracking);
			goToThisPage = new Intent(Menu.this, DrinkCounter.class);
			startActivity(goToThisPage);
			break;
		case R.id.bMenuAssessment:
			Date date = new Date();
			ArrayList<DatabaseStore> drank = (ArrayList<DatabaseStore>)db.getVarValuesForDay("drank_last_night", date);
			goToThisPage = new Intent(Menu.this, Assessment.class);
			startActivity(goToThisPage);
			if (drank == null) {
				Intent drink_ques = new Intent(this, DailySurvey1.class);
				startActivityForResult(drink_ques,2);
			} 
			break;
		case R.id.bMenuVisualize:
			goToThisPage = new Intent(Menu.this, Visualize.class);
			startActivity(goToThisPage);
			break;
		case R.id.bMenuSettings:
			goToThisPage = new Intent(Menu.this, Settings.class);
			startActivity(goToThisPage);
			break;
		case R.id.bMenuResources:
			goToThisPage = new Intent(Menu.this, Resources.class);
			startActivity(goToThisPage);
			break;
		}

	}

	@Override
	protected void onActivityResult(int requectCode, int resultCode, Intent data){
		Date date = new Date();
		ArrayList<DatabaseStore> drank = (ArrayList<DatabaseStore>)db.getVarValuesForDay("drank_last_night", date);
		if (drank.equals("True")){
			//TODO: get to estimated value from the db if the user already answered.
			Intent how_many = new Intent(this, DrinkAssessment.class);
			startActivity(how_many);
		}		
	}
	
}

@@ -325,16 +325,84 @@
 .Button;
+%0Aimport android.widget.LinearLayout;%0Aimport android.widget.TextView;
 %0A%0Apublic
@@ -1948,98 +1948,12 @@
 e);%0A
+%0A
 %09%09%09
-goToThisPage = new Intent(Menu.this, Assessment.class);%0A%09%09%09startActivity(goToThisPage);
 %0A%09%09%09
@@ -2082,16 +2082,398 @@
 );%0A%09%09%09%7D 
+else %7B%0A%09%09%09%09ArrayList%3CDatabaseStore%3E assess = (ArrayList%3CDatabaseStore%3E)db.getVarValuesForDay(%22drink_assess%22, date);%0A%09%09%09%09goToThisPage = new Intent(Menu.this, Assessment.class);%0A%09%09%09%09startActivity(goToThisPage);%0A%09%09%09%09if(assess == null && drank.get(0).value.equals(%22True%22))%7B%0A%09%09%09%09%09Intent drink_assess = new Intent(this, DrinkAssessment.class);%0A%09%09%09%09%09startActivity(drink_assess);%0A%09%09%09%09%7D%0A%09%09%09%7D
 %0A%09%09%09brea
@@ -2919,17 +2919,17 @@
 nt reque
-c
+s
 tCode, i
@@ -3099,110 +3099,139 @@
 ;%0A%09%09
-if (drank.equals(%22True%22))%7B%0A%09%09%09//TODO: get to estimated value from the db if the user already answered.
+goToThisPage = new Intent(Menu.this, Assessment.class);%0A%09%09startActivity(goToThisPage);%0A%09%09%0A%09%09if (drank.get(0).value.equals(%22True%22))%7B
 %0A%09%09%09

Add DrinkAssessment into the menu flow