package de.tudarmstadt.informatik.hostage.sync.tracing;

import de.tudarmstadt.informatik.hostage.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.widget.TextView;

/**
 * Starts a synchronization service and shows the progress of the synchronization.
 * @author Lars Pandikow
 */
public class TracingSyncActivity extends Activity implements TracingSyncResultReciever.Receiver{
	
	TextView mInfoText;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_nfc);
		mInfoText = (TextView) findViewById(R.id.nfc_text_view);
		mInfoText.setText("Uploading Records...");
		
		TracingSyncResultReciever mReceiver = new TracingSyncResultReciever(new Handler());
        mReceiver.setReceiver(this);
        
		Intent intent = new Intent(this, TracingSyncService.class);
		intent.setAction(TracingSyncService.ACTION_START_SYNC);
		intent.putExtra(TracingSyncService.EXTRA_RECEIVER, mReceiver);
		startService(intent);
	}

	@Override
	public void onReceiveResult(int resultCode, Bundle resultData) {
        switch (resultCode) {
        case TracingSyncService.SYNC_COMPLETE:
        	mInfoText.setText("Information is up to date!");
            break;        
        case TracingSyncService.RECORD_UPLOADED:      
        	mInfoText.setText("Uploading Records...(" + resultData.getInt(TracingSyncService.UPLOAD_PROGRESS) + "/"+ resultData.getInt(TracingSyncService.UPLOAD_SIZE) + ")");
        break;
    }
		
	}	
	
}
