package net.heartshield.prevent;

import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;

import net.heartshield.data.AppInfo;

/**
 * @author David Madl (git@abanbytes.eu)
 * @date 2017-05-14
 */
public class DevSettingsActivity extends Activity {
    private AppInfo mAppInfo;
    private MediaPlayer mPlayer;

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

        mAppInfo = AppInfo.getInstance(this);

        mPlayer = MediaPlayer.create(this, R.raw.beep);

        // load DevSettings
        AppInfo.DevSettings devSettings = mAppInfo.devSettings;
        ((CheckBox) findViewById(R.id.useTestServer)).setChecked(devSettings.useTestServer);
        ((CheckBox) findViewById(R.id.useMockData)).setChecked(devSettings.useMockData);
        ((CheckBox) findViewById(R.id.skipDialogs)).setChecked(devSettings.skipDialogs);
        ((CheckBox) findViewById(R.id.showPersonalTracking)).setChecked(devSettings.showPersonalTracking);
        ((CheckBox) findViewById(R.id.showHeightDialog)).setChecked(devSettings.showHeightDialog);
    }

    public void save(View view) {
        // set DevSettings
        AppInfo.DevSettings devSettings = mAppInfo.devSettings;
        devSettings.useTestServer = ((CheckBox) findViewById(R.id.useTestServer)).isChecked();
        devSettings.useMockData = ((CheckBox) findViewById(R.id.useMockData)).isChecked();
        devSettings.skipDialogs = ((CheckBox) findViewById(R.id.skipDialogs)).isChecked();
        devSettings.showPersonalTracking = ((CheckBox) findViewById(R.id.showPersonalTracking)).isChecked();
        devSettings.showHeightDialog = ((CheckBox) findViewById(R.id.showHeightDialog)).isChecked();
        mAppInfo.saveDevSettings(this);

        // return to Home
        Intent intent = new Intent(DevSettingsActivity.this, HomeActivity.class);
        startActivity(intent);
    }
    public void cancel(View view) {
        Intent intent = new Intent(DevSettingsActivity.this, HomeActivity.class);
        startActivity(intent);
    }

    public void cameraTest(View view) {
        Intent intent = new Intent(DevSettingsActivity.this, CameraTestActivity.class);
        startActivity(intent);
    }

    public void beep(View view) {
        mPlayer.start();
    }
}
