IprintAppRecord.java 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package epson.common;
  2. import android.content.Context;
  3. import android.content.SharedPreferences;
  4. import android.preference.PreferenceManager;
  5. import androidx.annotation.NonNull;
  6. /**
  7. * sp中用户确认隐私协议保存设置
  8. */
  9. public class IprintAppRecord {
  10. private static final String KEY_LICENSE_AGREE_TIME = "license_agree_time";
  11. private static final String KEY_LICENSE_AGREE_VERSION_CODE = "license_agree_version_code";
  12. private static final String KEY_LICENSE_SCREEN_SHOWN_PREF = "licenseScreenShown";
  13. /**
  14. * 用户是否同意了协议
  15. *
  16. * @param context
  17. * @return
  18. */
  19. public boolean getLicenseAgreementValue(@NonNull Context context) {
  20. return getLicensePreferences(context).getBoolean(KEY_LICENSE_SCREEN_SHOWN_PREF, false);
  21. }
  22. public int getLicenseAgreeVersionCode(@NonNull Context context) {
  23. return getLicensePreferences(context).getInt(KEY_LICENSE_AGREE_VERSION_CODE, 0);
  24. }
  25. public void setLicenseAgreement(@NonNull Context context, int i, boolean z) {
  26. 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();
  27. }
  28. public long getLicenseAgreeTime(@NonNull Context context) {
  29. return getLicensePreferences(context).getLong(KEY_LICENSE_AGREE_TIME, -1);
  30. }
  31. private SharedPreferences getLicensePreferences(@NonNull Context context) {
  32. return PreferenceManager.getDefaultSharedPreferences(context);
  33. }
  34. }