package com.anggastudio.printama;

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

public class Pref {
    private Pref() {
        // empty constructor
    }

    private static final String PREF_NAME = "printama_prefs";
    static final String SAVED_DEVICE = "bonded_device";
    static final String IS_PRINTER_3INCH = "is_printer_3inch";
    private static Pref instance;

    private SharedPreferences prefs;


    private static SharedPreferences sharedPreferences;

    private Pref(Context context) {
        prefs = context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
    }
    public static void init(Context context) {
        if (context == null) return;
        sharedPreferences = context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
    }

    static String getString(String key) {
        if (sharedPreferences == null) return null;
        return sharedPreferences.getString(key, "");
    }

    static void setString(String key, String value) {
        if (sharedPreferences == null) return;
        if (value == null) value = "";
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString(key, value);
        editor.apply();
    }

    static boolean getBoolean(String key) {
        if (sharedPreferences == null) return false;
        return sharedPreferences.getBoolean(key, false);
    }

    static void setBoolean(String key, boolean value) {
        if (sharedPreferences == null) return;
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putBoolean(key, value);
        editor.apply();
    }
}
