package com.example.jmastermind.Events;

import android.content.SharedPreferences;
import android.widget.CompoundButton;

import androidx.appcompat.app.AppCompatActivity;
import androidx.preference.PreferenceManager;

public class CanVoidEvent implements CompoundButton.OnCheckedChangeListener {
    private AppCompatActivity context;
    private SharedPreferences sp;
    private SharedPreferences.Editor edit;
    private String CAN_VOID = "canVoid";

    /**
     * Event relie a la CheckBox du menu permettant d'enregistrer dans les prefereneces si oui ou non le pion vide est autorise.
     * @param context Le contexte.
     * */
    public CanVoidEvent(AppCompatActivity context) {
       this.context = context;
       this.sp = PreferenceManager.getDefaultSharedPreferences(this.context);
       this.edit = this.sp.edit();
       this.edit.putBoolean(CAN_VOID, false);
       this.edit.apply();
    }

    @Override
    public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
        this.edit.putBoolean(CAN_VOID, b);
        this.edit.apply();
    }
}
