package com.example.blu.toys.activity;

import android.content.Intent;
import android.os.Bundle;
import android.widget.SeekBar;
import android.widget.Switch;

import com.example.blu.toys.R;
import com.example.blu.toys.app.AppManager;
import com.example.blu.toys.utils.SpUtils;
import com.example.blu.toys.view.TypefaceTextView;

import butterknife.BindView;
import butterknife.OnClick;

//设置
public class SelectTimerActivity extends BaseActivity {


	@BindView(R.id.back_but)
	TypefaceTextView backBut;
	@BindView(R.id.will)
	TypefaceTextView will;
	@BindView(R.id.alarm_switch)
	Switch alarmSwitch;
	@BindView(R.id.music_switch)
	Switch musicSwitch;
	@BindView(R.id.green_switch)
	Switch greenSwitch;
	@BindView(R.id.brightness_bar)
	SeekBar brightnessBar;

	@Override
	public int getLayout() {
		return R.layout.activity_select_timer;
	}

	@Override
	public void init(Bundle savedInstanceState) {

		SpUtils spUtils = SpUtils.getSpUtils(this);

		spUtils.getSPValue("close",1);
		spUtils.getSPValue("open",10);
		int alarm = spUtils.getSPValue("alarm", 1);
		int green = spUtils.getSPValue("green", 1);
		int brightness = spUtils.getSPValue("brightness", 50);

		//数据回显
		alarmSwitch.setChecked(alarm == 1 ? true : false);
		greenSwitch.setChecked(green == 1 ? true : false);
		brightnessBar.setProgress(brightness);


		alarmSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
			if (isChecked) {
				spUtils.putSPValue("alarm", 1);
			} else {
				spUtils.putSPValue("alarm", 0);
			}
		});

		musicSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
			startActivity(new Intent(SelectTimerActivity.this, MusicActivity.class));
		});

		greenSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
			if (isChecked) {
				spUtils.putSPValue("green", 1);
			} else {
				spUtils.putSPValue("green", 0);
			}
		});

		brightnessBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
			@Override
			public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
				spUtils.putSPValue("brightness", progress);
			}

			@Override
			public void onStartTrackingTouch(SeekBar seekBar) {

			}

			@Override
			public void onStopTrackingTouch(SeekBar seekBar) {

			}
		});


	}

	@Override
	public void initData() {

	}


	@OnClick(R.id.back_but)
	public void onViewClicked() {
		AppManager.getInstance().finishActivity();
	}
}