package com.example.applock.allmanager;

import android.content.Context;
import android.content.SharedPreferences;

import com.example.applock.value.MyAllValues;

public class Datamanager {
    private static SharedPreferences sharedPreferences;
    private static SharedPreferences.Editor shareditor;
    public static void init(Context context){
        if(sharedPreferences == null){
            sharedPreferences = context.getSharedPreferences(MyAllValues.OWN_NAME,Context.MODE_PRIVATE);
        }
        if (shareditor == null){
            shareditor = sharedPreferences.edit();
        }
    }
    public static void setTopKey(String topKey){
        shareditor.putString(MyAllValues.SP_TOP_KEY,topKey);
        shareditor.apply();
    }
    public static String getTopKey(){
        return sharedPreferences.getString(MyAllValues.SP_TOP_KEY,"");
    }
    public static void resetKeyCount() {
        MyAllValues.OP_COUNT = 0;
        shareditor.putInt(MyAllValues.SP_KEY_COUNT, MyAllValues.OP_COUNT);
        shareditor.apply();
    }
    public static void setOpCount() {
        MyAllValues.OP_COUNT = MyAllValues.OP_COUNT + 1;
        shareditor.putInt(MyAllValues.SP_KEY_OP_COUNT, MyAllValues.OP_COUNT);
        shareditor.apply();
    }

    public static void resetOpCount() {
        MyAllValues.OP_COUNT = 0;
        shareditor.putInt(MyAllValues.SP_KEY_OP_COUNT, MyAllValues.OP_COUNT);
        shareditor.apply();
    }

    public static int getOpCount() {
        return sharedPreferences.getInt(MyAllValues.SP_KEY_OP_COUNT, MyAllValues.OP_COUNT);
    }
}
