LoggerRecord.java 1.6 KB

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