Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/stefan-niedermann/nextcloud-notes.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Niedermann <info@niedermann.it>2021-06-30 12:58:20 +0300
committerStefan Niedermann <info@niedermann.it>2021-06-30 12:58:20 +0300
commita7036c362cb6fda5d1c4c92198d0e9b4623272fc (patch)
tree619e6ff6f6636dd16f3fccdcc591472536c882c1 /app/src/main/java
parentf772be3f0a689db398d42ab3eea4a73c9a478727 (diff)
#1281 Prevent duplicate key exception
Use SingleThreadExecutor for performing remote synchronization tasks Signed-off-by: Stefan Niedermann <info@niedermann.it>
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesRepository.java11
1 files changed, 6 insertions, 5 deletions
diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesRepository.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesRepository.java
index 6d2b21c5..51eae0dc 100644
--- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesRepository.java
+++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/NotesRepository.java
@@ -34,7 +34,6 @@ import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@@ -86,6 +85,7 @@ public class NotesRepository {
private final ApiProvider apiProvider;
private final ExecutorService executor;
+ private final ExecutorService syncExecutor;
private final Context context;
private final NotesDatabase db;
private final String defaultNonEmptyTitle;
@@ -138,15 +138,16 @@ public class NotesRepository {
public static synchronized NotesRepository getInstance(@NonNull Context context) {
if (instance == null) {
- instance = new NotesRepository(context, NotesDatabase.getInstance(context.getApplicationContext()), Executors.newCachedThreadPool(), ApiProvider.getInstance());
+ instance = new NotesRepository(context, NotesDatabase.getInstance(context.getApplicationContext()), Executors.newCachedThreadPool(), Executors.newSingleThreadExecutor(), ApiProvider.getInstance());
}
return instance;
}
- private NotesRepository(@NonNull final Context context, @NonNull final NotesDatabase db, @NonNull final ExecutorService executor, @NonNull ApiProvider apiProvider) {
+ private NotesRepository(@NonNull final Context context, @NonNull final NotesDatabase db, @NonNull final ExecutorService executor, @NonNull final ExecutorService syncExecutor, @NonNull ApiProvider apiProvider) {
this.context = context.getApplicationContext();
this.db = db;
this.executor = executor;
+ this.syncExecutor = syncExecutor;
this.apiProvider = apiProvider;
this.defaultNonEmptyTitle = NoteUtil.generateNonEmptyNoteTitle("", this.context);
this.syncOnlyOnWifiKey = context.getApplicationContext().getResources().getString(R.string.pref_key_wifi_only);
@@ -548,7 +549,7 @@ public class NotesRepository {
private void updateDynamicShortcuts(long accountId) {
executor.submit(() -> {
if (SDK_INT >= android.os.Build.VERSION_CODES.N_MR1) {
- ShortcutManager shortcutManager = this.context.getSystemService(ShortcutManager.class);
+ final ShortcutManager shortcutManager = this.context.getSystemService(ShortcutManager.class);
if (shortcutManager != null) {
if (!shortcutManager.isRateLimitingActive()) {
List<ShortcutInfo> newShortcuts = new ArrayList<>();
@@ -828,7 +829,7 @@ public class NotesRepository {
syncTask.addCallbacks(account, callbacksPull.get(account.getId()));
callbacksPull.put(account.getId(), new ArrayList<>());
}
- executor.submit(syncTask);
+ syncExecutor.submit(syncTask);
} catch (NextcloudFilesAppAccountNotFoundException e) {
Log.e(TAG, "... Could not find " + SingleSignOnAccount.class.getSimpleName() + " for account name " + account.getAccountName());
e.printStackTrace();