package cz.uhk.fim.dragonboatassistant.app;

import java.util.Calendar;
import java.util.concurrent.TimeUnit;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import cz.uhk.fim.dragonboatassistant.R;
import cz.uhk.fim.dragonboatassistant.util.Converter;

public class OverviewActivity extends Activity {
	
	Converter secsToMinsConverter;
	
	TextView dateText;
	TextView timeText;
	TextView distText;
	TextView speedText;
	TextView avgSpeedText;
	TextView tiltText;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_overview);
		
		dateText = (TextView) findViewById(R.id.dateView);
		timeText = (TextView) findViewById(R.id.timeView);
		distText = (TextView) findViewById(R.id.distView);
		speedText = (TextView) findViewById(R.id.speedView);
		avgSpeedText = (TextView) findViewById(R.id.avgSpeedView);
		tiltText = (TextView) findViewById(R.id.tiltView);
		
		dateText.setTextSize(18);
		timeText.setTextSize(18);
		distText.setTextSize(18);
		speedText.setTextSize(18);
		avgSpeedText.setTextSize(18);
		tiltText.setTextSize(18);
		
		secsToMinsConverter = new Converter(TimeUnit.SECONDS, TimeUnit.MINUTES);
		
	}
	
	@Override
	protected void onStart() {
		super.onStart();
		Calendar cal = Calendar.getInstance();
		long secs = getIntent().getLongExtra("time", 0);
		long mins = secsToMinsConverter.convertTime(secs);
		if (mins > 0) secs = (secs - (60*mins));
		float dist = getIntent().getFloatExtra("distance", 0);
		float maxSpeed = getIntent().getFloatExtra("maxSpeed", 0);
		float avgSpeed = getIntent().getFloatExtra("avgSpeed", 0);
		
		dateText.setText(cal.get(Calendar.DAY_OF_MONTH) + "." + (cal.get(Calendar.MONTH)+1) + 
				"." + cal.get(Calendar.YEAR));
		timeText.setText("Celkový čas:  " + mins + "m " + secs + "s");
		distText.setText("Celková vzdálenost:  " + String.format("%.2f", dist/1000) + "km");
		speedText.setText("Maximální rychlost:  " + String.format("%.1f", maxSpeed*3.6) + "km/h");
		avgSpeedText.setText("Průměrná rychlost:  " + String.format("%.1f", avgSpeed*3.6) + "km/h");
		tiltText.setText("Doba ve spr. náklonu:  " + getIntent().getLongExtra("tilt", 0) + "%");
	}
}
