StoreReview.java 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package com.epson.mobilephone.common;
  2. import android.content.Context;
  3. import android.content.SharedPreferences;
  4. import java.text.SimpleDateFormat;
  5. import java.util.Date;
  6. import java.util.Locale;
  7. public class StoreReview {
  8. private static final String STORE_REVIEW_DATE_KEY = "iprint.storereview.date";
  9. private static final String STORE_REVIEW_REFS_NAME = "iprint.storereview";
  10. private static final int STORE_REVIEW_SHOW_TIME = 2;
  11. private static final String STORE_REVIEW_TASK_COUNT_KEY = "iprint.storereview.taskcount";
  12. public boolean checkPrintSuccessCount(@NonNull Context context) {
  13. int loadTaskCount = loadTaskCount(context) + 1;
  14. if (loadTaskCount <= 2) {
  15. saveTaskCount(context, loadTaskCount);
  16. }
  17. if (loadTaskCount == 2) {
  18. return true;
  19. }
  20. return false;
  21. }
  22. public void resetTaskCount(@NonNull Context context) {
  23. SharedPreferences.Editor edit = getLocalSharedPreferences(context).edit();
  24. edit.putInt(STORE_REVIEW_TASK_COUNT_KEY, 0);
  25. edit.apply();
  26. }
  27. private SharedPreferences getLocalSharedPreferences(@NonNull Context context) {
  28. return context.getSharedPreferences(STORE_REVIEW_REFS_NAME, 0);
  29. }
  30. private void saveTaskCount(@NonNull Context context, int i) {
  31. SharedPreferences.Editor edit = getLocalSharedPreferences(context).edit();
  32. edit.putInt(STORE_REVIEW_TASK_COUNT_KEY, i);
  33. edit.apply();
  34. }
  35. private int loadTaskCount(@NonNull Context context) {
  36. return getLocalSharedPreferences(context).getInt(STORE_REVIEW_TASK_COUNT_KEY, 0);
  37. }
  38. private void saveDate(@NonNull Context context) {
  39. SharedPreferences.Editor edit = getLocalSharedPreferences(context).edit();
  40. edit.putString(STORE_REVIEW_DATE_KEY, new SimpleDateFormat("yyyyMMddHHmmss", Locale.getDefault()).format(new Date()));
  41. edit.apply();
  42. }
  43. }