LoggerRecord.java 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package com.epson.iprint.prtlogger;
  2. import android.content.Context;
  3. import android.content.SharedPreferences;
  4. public class LoggerRecord {
  5. private static final String ANALYTICS_PREFS_NAME = "logger6_3";
  6. private static final String PREFS_KEY_LOGGER_ANSWER = "answer";
  7. private static final String PREFS_KEY_LOGGER_VERSION = "logger_version";
  8. private static LoggerRecord sLoggerRecord;
  9. public static synchronized LoggerRecord getInstance() {
  10. LoggerRecord loggerRecord;
  11. synchronized (LoggerRecord.class) {
  12. if (sLoggerRecord == null) {
  13. sLoggerRecord = new LoggerRecord();
  14. }
  15. loggerRecord = sLoggerRecord;
  16. }
  17. return loggerRecord;
  18. }
  19. @VisibleForTesting
  20. static void replaceInstance(LoggerRecord loggerRecord) {
  21. sLoggerRecord = loggerRecord;
  22. }
  23. public int getInvitationVersion(@NonNull Context context) {
  24. return getPreferences(context).getInt(PREFS_KEY_LOGGER_VERSION, 0);
  25. }
  26. public void setInvitationVersion(@NonNull Context context, int i) {
  27. getPreferences(context).edit().putInt(PREFS_KEY_LOGGER_VERSION, i).apply();
  28. }
  29. public void setAnswer(@NonNull Context context, boolean z) {
  30. getPreferences(context).edit().putBoolean(PREFS_KEY_LOGGER_ANSWER, z).apply();
  31. }
  32. public boolean getAnswer(@NonNull Context context) {
  33. return getPreferences(context).getBoolean(PREFS_KEY_LOGGER_ANSWER, false);
  34. }
  35. private SharedPreferences getPreferences(@NonNull Context context) {
  36. return context.getSharedPreferences(ANALYTICS_PREFS_NAME, 0);
  37. }
  38. }