diff --git a/Alkitab/src/main/java/yuku/alkitab/base/sync/Sync.java b/Alkitab/src/main/java/yuku/alkitab/base/sync/Sync.java index 9f77c9d18..8bacd3ab0 100644 --- a/Alkitab/src/main/java/yuku/alkitab/base/sync/Sync.java +++ b/Alkitab/src/main/java/yuku/alkitab/base/sync/Sync.java @@ -15,9 +15,6 @@ import java.util.Comparator; import java.util.List; import java.util.concurrent.ConcurrentLinkedQueue; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import okhttp3.Call; import okhttp3.FormBody; @@ -202,7 +199,6 @@ public static boolean entitiesEqual(@NonNull final List> a_, @NonN } private static final ArrayMap syncUpdatesOngoingCounters = new ArrayMap<>(); - private static final ScheduledExecutorService syncExecutor = Executors.newSingleThreadScheduledExecutor(); private static final ConcurrentLinkedQueue syncSetNameQueue = new ConcurrentLinkedQueue<>(); /** @@ -241,32 +237,30 @@ public static synchronized void notifySyncNeeded(final String... syncSetNames) { } } - syncExecutor.schedule(() -> { + final List extraSyncSetNames = new ArrayList<>(); + synchronized (syncSetNameQueue) { while (true) { - final List extraSyncSetNames = new ArrayList<>(); - synchronized (syncSetNameQueue) { - final String extraSyncSetName = syncSetNameQueue.poll(); - if (extraSyncSetName == null) { - break; - } - extraSyncSetNames.add(extraSyncSetName); + final String extraSyncSetName = syncSetNameQueue.poll(); + if (extraSyncSetName == null) { + break; } + extraSyncSetNames.add(extraSyncSetName); + } + } - final Account account = SyncUtils.getOrCreateSyncAccount(); - final String authority = App.context.getString(R.string.sync_provider_authority); + final Account account = SyncUtils.getOrCreateSyncAccount(); + final String authority = App.context.getString(R.string.sync_provider_authority); - // make sure sync is enabled. - final boolean syncAutomatically = ContentResolver.getSyncAutomatically(account, authority); - if (!syncAutomatically) { - ContentResolver.setSyncAutomatically(account, authority, true); - } + // make sure sync is enabled. + final boolean syncAutomatically = ContentResolver.getSyncAutomatically(account, authority); + if (!syncAutomatically) { + ContentResolver.setSyncAutomatically(account, authority, true); + } - // request sync. - final Bundle extras = new Bundle(); - extras.putString(SyncAdapter.EXTRA_SYNC_SET_NAMES, App.getDefaultGson().toJson(extraSyncSetNames)); - ContentResolver.requestSync(account, authority, extras); - } - }, 5, TimeUnit.SECONDS); + // request sync. + final Bundle extras = new Bundle(); + extras.putString(SyncAdapter.EXTRA_SYNC_SET_NAMES, App.getDefaultGson().toJson(extraSyncSetNames)); + ContentResolver.requestSync(account, authority, extras); } /**