package com.app.simplitend.appblocking;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;

public class MySharedPref {
    private static final String APP_SHARED_PREFS = "AppBlock";
    private SharedPreferences appSharedPrefs;
    private SharedPreferences.Editor prefsEditor;

    public MySharedPref(Context activity) {
        this.appSharedPrefs = activity.getSharedPreferences(APP_SHARED_PREFS,
                Activity.MODE_PRIVATE);
        this.prefsEditor = appSharedPrefs.edit();
    }

    public String getPrefsValue(String value) {
        return appSharedPrefs.getString(value, "");
    }

    public void savePrefsValue(String key, String Value) {
        prefsEditor.putString(key, Value);
        prefsEditor.commit();
    }

    public String getString(String value) {
        return appSharedPrefs.getString(value, "");
    }

    public void saveString(String key, String Value) {
        prefsEditor.putString(key, Value);
        prefsEditor.commit();
    }

    public Boolean checkKey(String Key) {
        if (appSharedPrefs.contains(Key))
            return true;
        else
            return false;
    }

    public void removeKey(String key){
        appSharedPrefs.edit().remove(key).apply();
    }

    public Set<String> getArrayList(String key) {
        return appSharedPrefs.getStringSet(key, null);
    }

    public void setArrayList(String key, ArrayList<String> list) {
        Set<String> set = new HashSet<>(list);
        prefsEditor.putStringSet(key, set);
        prefsEditor.apply();
    }


    public void setArrayList(String key, Set<String> appList) {
        prefsEditor.putStringSet(key, appList);
        prefsEditor.apply();
    }
}