StoreReview.java 1.9 KB

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