package fruitiex.arcwatch;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.graphics.Color;

public class Values {
    SharedPreferences sharedPref;
    Context appContext;
    public Values(Context c) {
        appContext = c;
        sharedPref = c.getSharedPreferences(c.getString(R.string.app_name), Context.MODE_PRIVATE);
    }
    public int getColor(String element) {
        Resources res = appContext.getResources();
        int r = sharedPref.getInt(element + "R", res.getInteger(res.getIdentifier(element + "R", "integer", appContext.getPackageName())));
        int g = sharedPref.getInt(element + "G", res.getInteger(res.getIdentifier(element + "G", "integer", appContext.getPackageName())));
        int b = sharedPref.getInt(element + "B", res.getInteger(res.getIdentifier(element + "B", "integer", appContext.getPackageName())));

        return Color.rgb(r, g, b);
    }
    public boolean getBoolean(String element) {
        Resources res = appContext.getResources();

        // NOTE: for some reason getBool doesn't want to play ball, so here's this hack instead.
        return sharedPref.getInt(element, res.getInteger(res.getIdentifier(element, "integer", appContext.getPackageName()))) == 1;
    }
    public void setBoolean(String element, boolean value) {
        SharedPreferences.Editor editor = sharedPref.edit();

        editor.putInt(element, value ? 1 : 0);

        editor.commit();
        WatchFace.resetColors();
    }
    public void setColor(String element, int color) {
        SharedPreferences.Editor editor = sharedPref.edit();

        editor.putInt(element + "R", Color.red(color));
        editor.putInt(element + "G", Color.green(color));
        editor.putInt(element + "B", Color.blue(color));

        editor.commit();
        WatchFace.resetColors();
    }
    public void resetValues() {
        SharedPreferences.Editor editor = sharedPref.edit();

        editor.clear();
        editor.commit();
        WatchFace.resetColors();
    }
}

@@ -1472,38 +1472,37 @@
 %0A        editor.
-commit
+apply
 ();%0A        Watc
@@ -1823,38 +1823,37 @@
 %0A        editor.
-commit
+apply
 ();%0A        Watc
@@ -2016,14 +2016,13 @@
 tor.
-commit
+apply
 ();%0A

switch to editor.apply() to silence a warning