package epson.common;

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

import androidx.annotation.NonNull;


public class IprintAppRecord {
    private static final String KEY_LICENSE_AGREE_TIME = "license_agree_time";
    private static final String KEY_LICENSE_AGREE_VERSION_CODE = "license_agree_version_code";
    private static final String KEY_LICENSE_SCREEN_SHOWN_PREF = "licenseScreenShown";

    public boolean getLicenseAgreementValue(@NonNull Context context) {
        return getLicensePreferences(context).getBoolean(KEY_LICENSE_SCREEN_SHOWN_PREF, false);
    }

    public int getLicenseAgreeVersionCode(@NonNull Context context) {
        return getLicensePreferences(context).getInt(KEY_LICENSE_AGREE_VERSION_CODE, 0);
    }

    public void setLicenseAgreement(@NonNull Context context, int i, boolean z) {
        getLicensePreferences(context).edit().putInt(KEY_LICENSE_AGREE_VERSION_CODE, i).putBoolean(KEY_LICENSE_SCREEN_SHOWN_PREF, z).putLong(KEY_LICENSE_AGREE_TIME, System.currentTimeMillis()).apply();
    }

    public long getLicenseAgreeTime(@NonNull Context context) {
        return getLicensePreferences(context).getLong(KEY_LICENSE_AGREE_TIME, -1);
    }

    private SharedPreferences getLicensePreferences(@NonNull Context context) {
        return PreferenceManager.getDefaultSharedPreferences(context);
    }
}
