package de.frajul.endlessroll.main.screens;

import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ToggleButton;

import de.frajul.endlessroll.R;
import de.frajul.endlessroll.main.GameActivity;
import de.frajul.endlessroll.views.TopBar;

/**
 * Created by Julian on 10.09.2017.
 */

public class SettingsScreen extends Screen<LinearLayout> implements View.OnClickListener {

    private TopBar topBar;
    private ToggleButton soundToggle;
    private Button resetButton;

    public SettingsScreen(GameActivity gameActivity) {
        super(ScreenType.SETTINGS, gameActivity, R.layout.settings);
        topBar = super.createTopBar(R.id.settings_topbar);
        soundToggle = (ToggleButton) layout.findViewById(R.id.settings_soundtoggle);
        soundToggle.setOnClickListener(this);
        resetButton = (Button) layout.findViewById(R.id.settings_reset);
        resetButton.setOnClickListener(this);
    }

    @Override
    public void prepareToBeShown() {
        topBar.update();
        soundToggle.setChecked(gameActivity.getSoundManager().isSoundOn());
        resetButton.setEnabled(super.caller != ScreenType.GAME);
    }

    @Override
    public void onBackKeyDown() {
        flipToCaller();
    }

    @Override
    public void onClick(View v) {
        if (v.equals(soundToggle)) {
            gameActivity.getSoundManager().setSoundOn(soundToggle.isChecked());
        } else if (v.equals(resetButton)) {
            gameActivity.resetData();
        }
    }
}
