package it.integry.integrywmsnative.gest.settings;

import android.content.Context;
import android.os.Bundle;

import androidx.appcompat.widget.AppCompatTextView;
import androidx.preference.PreferenceFragmentCompat;

import java.util.ArrayList;

import it.integry.integrywmsnative.R;
import it.integry.integrywmsnative.core.interfaces.ITitledFragment;

public class MainSettingsFragment extends PreferenceFragmentCompat implements ITitledFragment {

    private final ArrayList<Runnable> onPreDestroyList = new ArrayList<>();

    @Override
    public void onCreateActionBar(AppCompatTextView titleText, Context context) {
        titleText.setText(context.getText(R.string.settings_category).toString());
    }

    @Override
    public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
        setPreferencesFromResource(R.xml.app_preferences, rootKey);
    }

    @Override
    public void addOnPreDestroy(Runnable onPreDestroy) {
        onPreDestroyList.add(onPreDestroy);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();

        for (Runnable onPreDestroy :
                onPreDestroyList) {
            onPreDestroy.run();
        }
    }
}
