Preference.java 1.1 KB

12345678910111213141516171819202122232425262728
  1. package com.chinaappsremover.utils;
  2. import com.chinaappsremover.AppController;
  3. import static com.chinaappsremover.AppController.getInstance;
  4. public class Preference {
  5. private static final Long MIN_SYNC_DURATION = 1000L * 60 * 60 * 12; // 12Hours
  6. private static final String KEY_LAST_SYNC_MILLS = "last_sync_mills";
  7. private static final String KEY_FIRST_RUN = "db_initialized";
  8. public static boolean shouldRefreshData() {
  9. Long lastSyncedMills = getInstance().getDefaultPreference().getLong(KEY_LAST_SYNC_MILLS, 0L);
  10. return System.currentTimeMillis() >= lastSyncedMills + MIN_SYNC_DURATION;
  11. }
  12. public static void updateLastSyncMills() {
  13. getInstance().getDefaultPreference().edit().putLong(KEY_LAST_SYNC_MILLS, System.currentTimeMillis()).apply();
  14. }
  15. public static boolean isDbInitialized() {
  16. return AppController.getInstance().getDefaultPreference().getBoolean(KEY_FIRST_RUN, true);
  17. }
  18. public static void setDbInitialized() {
  19. AppController.getInstance().getDefaultPreference().edit().putBoolean(KEY_FIRST_RUN, false).apply();
  20. }
  21. }