diff options
author | desperateCoder <echotodevnull@gmail.com> | 2020-09-08 16:25:57 +0300 |
---|---|---|
committer | desperateCoder <echotodevnull@gmail.com> | 2020-09-08 16:25:57 +0300 |
commit | 4fef187b63e2198216364fa317ac621ef61243df (patch) | |
tree | 43e676417c4d05e688c887e70af8e07b8bb36634 /app/src/main/java/it/niedermann/nextcloud/deck/persistence | |
parent | 488beb4b4dfaa546f3dcd6b3d9d5183a94ef94da (diff) |
#608 WIP, NPE gone but creating cards doubles them...
Diffstat (limited to 'app/src/main/java/it/niedermann/nextcloud/deck/persistence')
10 files changed, 123 insertions, 68 deletions
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/SyncManager.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/SyncManager.java index 9466deca0..832fd776a 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/SyncManager.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/SyncManager.java @@ -613,13 +613,13 @@ public class SyncManager { List<AccessControl> aclList = originalBoard.getParticipants(); for (AccessControl acl : aclList) { acl.setLocalId(null); + acl.setId(null); acl.setBoardId(newBoardId); - acl.setUserId(newOwner.getLocalId()); dataBaseAdapter.createAccessControl(targetAccountId, acl); } } - Map<Long, Long> oldToNewLabelIdsDictionary = isSameAccount ? null : new HashMap<>(); + Map<Long, Long> oldToNewLabelIdsDictionary = new HashMap<>(); for (Label label : originalBoard.getLabels()) { Long oldLocalId = label.getLocalId(); @@ -628,10 +628,8 @@ public class SyncManager { label.setAccountId(targetAccountId); label.setStatusEnum(DBStatus.LOCAL_EDITED); label.setBoardId(newBoardId); - long newLocalId = dataBaseAdapter.createLabel(targetAccountId, label); - if (!isSameAccount) { - oldToNewLabelIdsDictionary.put(oldLocalId, newLocalId); - } + long newLocalId = dataBaseAdapter.createLabelDirectly(targetAccountId, label); + oldToNewLabelIdsDictionary.put(oldLocalId, newLocalId); } List<Stack> oldStacks = originalBoard.getStacks(); @@ -653,11 +651,13 @@ public class SyncManager { newCard.setStackId(createdStackId); newCard.setAccountId(targetAccountId); newCard.setStatusEnum(DBStatus.LOCAL_EDITED); - long createdCardId = dataBaseAdapter.createCard(targetAccountId, newCard); + long createdCardId = dataBaseAdapter.createCardDirectly(targetAccountId, newCard); if (oldCard.getLabels() != null) { for (Label oldLabel : oldCard.getLabels()) { - Long newLabelId = isSameAccount ? oldLabel.getLocalId() : oldToNewLabelIdsDictionary.get(oldLabel.getLocalId()); - dataBaseAdapter.createJoinCardWithLabel(newLabelId, createdCardId, DBStatus.LOCAL_EDITED); + Long newLabelId = oldToNewLabelIdsDictionary.get(oldLabel.getLocalId()); + if (newLabelId != null) { + dataBaseAdapter.createJoinCardWithLabel(newLabelId, createdCardId, DBStatus.LOCAL_EDITED); + } else DeckLog.error("ID of created Label is null! Skipping assignment of \"" + oldLabel.getTitle() + "\"..."); } } if (isSameAccount && oldCard.getAssignedUsers() != null) { @@ -1041,7 +1041,7 @@ public class SyncManager { card.getCard().setAccountId(accountId); card.getCard().setStatusEnum(DBStatus.LOCAL_EDITED); card.getCard().setOrder(dataBaseAdapter.getHighestCardOrderInStack(localStackId) + 1); - long localCardId = dataBaseAdapter.createCard(accountId, card.getCard()); + long localCardId = dataBaseAdapter.createCardDirectly(accountId, card.getCard()); card.getCard().setLocalId(localCardId); List<User> assignedUsers = card.getAssignedUsers(); diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/DataBaseAdapter.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/DataBaseAdapter.java index 9e240909d..c659bb548 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/DataBaseAdapter.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/DataBaseAdapter.java @@ -266,17 +266,20 @@ public class DataBaseAdapter { return db.getUserDao().getUserByUidDirectly(accountId, uid); } + @WorkerThread public long createUser(long accountId, User user) { user.setAccountId(accountId); return db.getUserDao().insert(user); } + @WorkerThread public void updateUser(long accountId, User user, boolean setStatus) { markAsEditedIfNeeded(user, setStatus); user.setAccountId(accountId); db.getUserDao().update(user); } + @AnyThread public LiveData<Label> getLabelByRemoteId(long accountId, long remoteId) { return distinctUntilChanged(db.getLabelDao().getLabelByRemoteId(accountId, remoteId)); } @@ -286,7 +289,8 @@ public class DataBaseAdapter { return db.getLabelDao().getLabelByRemoteIdDirectly(accountId, remoteId); } - public long createLabel(long accountId, @NonNull Label label) { + @WorkerThread + public long createLabelDirectly(long accountId, @NonNull Label label) { label.setAccountId(accountId); return db.getLabelDao().insert(label); } @@ -545,7 +549,7 @@ public class DataBaseAdapter { } @WorkerThread - public long createCard(long accountId, Card card) { + public long createCardDirectly(long accountId, Card card) { card.setAccountId(accountId); long newCardId = db.getCardDao().insert(card); @@ -816,8 +820,8 @@ public class DataBaseAdapter { return db.getJoinCardWithLabelDao().getRemoteIdsForJoin(localCardId, localLabelId); } - public List<JoinCardWithUser> getAllDeletedUserJoinsWithRemoteIDs() { - return db.getJoinCardWithUserDao().getDeletedJoinsWithRemoteIDs(); + public List<JoinCardWithUser> getAllChangedUserJoinsWithRemoteIDs() { + return db.getJoinCardWithUserDao().getChangedJoinsWithRemoteIDs(); } public void deleteJoinedLabelForCardPhysicallyByRemoteIDs(Long accountId, Long remoteCardId, Long remoteLabelId) { diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/JoinCardWithUserDao.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/JoinCardWithUserDao.java index 46554685f..9d8e2cf9d 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/JoinCardWithUserDao.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/JoinCardWithUserDao.java @@ -25,7 +25,7 @@ public interface JoinCardWithUserDao extends GenericDao<JoinCardWithUser> { "inner join card c on j.cardId = c.localId " + "inner join user u on j.userId = u.localId " + "WHERE j.status <> 1") // not UP_TO_DATE - List<JoinCardWithUser> getDeletedJoinsWithRemoteIDs(); + List<JoinCardWithUser> getChangedJoinsWithRemoteIDs(); @Query("delete from joincardwithuser " + "where cardId = (select c.localId from card c where c.accountId = :accountId and c.id = :remoteCardId) " + diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/providers/AccessControlDataProvider.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/providers/AccessControlDataProvider.java index 36e5d9522..aab3aeb09 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/providers/AccessControlDataProvider.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/providers/AccessControlDataProvider.java @@ -14,6 +14,7 @@ import it.niedermann.nextcloud.deck.model.ocs.user.GroupMemberUIDs; import it.niedermann.nextcloud.deck.model.ocs.user.OcsUser; import it.niedermann.nextcloud.deck.persistence.sync.adapters.ServerAdapter; import it.niedermann.nextcloud.deck.persistence.sync.adapters.db.DataBaseAdapter; +import it.niedermann.nextcloud.deck.persistence.sync.helpers.util.AsyncUtil; public class AccessControlDataProvider extends AbstractSyncDataProvider<AccessControl> { @@ -29,32 +30,29 @@ public class AccessControlDataProvider extends AbstractSyncDataProvider<AccessCo @Override public void getAllFromServer(ServerAdapter serverAdapter, DataBaseAdapter dataBaseAdapter, long accountId, IResponseCallback<List<AccessControl>> responder, Date lastSync) { - CountDownLatch latch = new CountDownLatch(acl.size()); - for (AccessControl accessControl : acl) { - if (accessControl.getType() == TYPE_GROUP) { - serverAdapter.searchGroupMembers(accessControl.getUser().getUid(), new IResponseCallback<GroupMemberUIDs>(responder.getAccount()) { - @Override - public void onResponse(GroupMemberUIDs response) { - accessControl.setGroupMemberUIDs(response); - if (response.getUids().size() > 0) { - ensureGroupMembersInDB(getAccount(), dataBaseAdapter, serverAdapter, response); + AsyncUtil.awaitAsyncWork(acl.size(), latch -> { + for (AccessControl accessControl : acl) { + if (accessControl.getType() == TYPE_GROUP) { + serverAdapter.searchGroupMembers(accessControl.getUser().getUid(), new IResponseCallback<GroupMemberUIDs>(responder.getAccount()) { + @Override + public void onResponse(GroupMemberUIDs response) { + accessControl.setGroupMemberUIDs(response); + if (response.getUids().size() > 0) { + ensureGroupMembersInDB(getAccount(), dataBaseAdapter, serverAdapter, response); + } + latch.countDown(); } - latch.countDown(); - } - @Override - public void onError(Throwable throwable) { - super.onError(throwable); - latch.countDown(); - } - }); - } else latch.countDown(); - } - try { - latch.await(); - } catch (InterruptedException e) { - DeckLog.logError(e); - } + @Override + public void onError(Throwable throwable) { + super.onError(throwable); + latch.countDown(); + } + }); + } else latch.countDown(); + } + }); + responder.onResponse(acl); } @@ -137,6 +135,7 @@ public class AccessControlDataProvider extends AbstractSyncDataProvider<AccessCo @Override public void updateInDB(DataBaseAdapter dataBaseAdapter, long accountId, AccessControl entity, boolean setStatus) { prepareUser(dataBaseAdapter, accountId, entity); + entity.setBoardId(board.getLocalId()); dataBaseAdapter.updateAccessControl(entity, setStatus); handleGroupMemberships(dataBaseAdapter, entity); } @@ -150,6 +149,9 @@ public class AccessControlDataProvider extends AbstractSyncDataProvider<AccessCo public void createOnServer(ServerAdapter serverAdapter, DataBaseAdapter dataBaseAdapter, long accountId, IResponseCallback<AccessControl> responder, AccessControl entity) { AccessControl acl = new AccessControl(entity); acl.setBoardId(board.getBoard().getId()); + if (acl.getUser() == null && acl.getUserId() != null) { + acl.setUser(dataBaseAdapter.getUserByLocalIdDirectly(acl.getUserId())); + } serverAdapter.createAccessControl(board.getBoard().getId(), acl, responder); } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/providers/BoardDataProvider.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/providers/BoardDataProvider.java index 2f5629474..747502f26 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/providers/BoardDataProvider.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/providers/BoardDataProvider.java @@ -6,9 +6,7 @@ import java.util.Date; import java.util.HashSet; import java.util.List; import java.util.Set; -import java.util.concurrent.CountDownLatch; -import it.niedermann.nextcloud.deck.DeckLog; import it.niedermann.nextcloud.deck.api.IResponseCallback; import it.niedermann.nextcloud.deck.model.AccessControl; import it.niedermann.nextcloud.deck.model.Board; @@ -19,6 +17,7 @@ import it.niedermann.nextcloud.deck.model.full.FullStack; import it.niedermann.nextcloud.deck.persistence.sync.adapters.ServerAdapter; import it.niedermann.nextcloud.deck.persistence.sync.adapters.db.DataBaseAdapter; import it.niedermann.nextcloud.deck.persistence.sync.helpers.SyncHelper; +import it.niedermann.nextcloud.deck.persistence.sync.helpers.util.AsyncUtil; public class BoardDataProvider extends AbstractSyncDataProvider<FullBoard> { @@ -122,17 +121,13 @@ public class BoardDataProvider extends AbstractSyncDataProvider<FullBoard> { public void goDeeperForUpSync(SyncHelper syncHelper, ServerAdapter serverAdapter, DataBaseAdapter dataBaseAdapter, IResponseCallback<Boolean> callback) { Long accountId = callback.getAccount().getId(); List<Label> locallyChangedLabels = dataBaseAdapter.getLocallyChangedLabels(accountId); - CountDownLatch countDownLatch = new CountDownLatch(locallyChangedLabels.size()); - for (Label label : locallyChangedLabels) { - Board board = dataBaseAdapter.getBoardByLocalIdDirectly(label.getBoardId()); - label.setBoardId(board.getId()); - syncHelper.doUpSyncFor(new LabelDataProvider(this, board, Collections.singletonList(label)), countDownLatch); - } - try { - countDownLatch.await(); - } catch (InterruptedException e) { - DeckLog.logError(e); - } + AsyncUtil.awaitAsyncWork(locallyChangedLabels.size(), (countDownLatch) -> { + for (Label label : locallyChangedLabels) { + Board board = dataBaseAdapter.getBoardByLocalIdDirectly(label.getBoardId()); + label.setBoardId(board.getId()); + syncHelper.doUpSyncFor(new LabelDataProvider(this, board, Collections.singletonList(label)), countDownLatch); + } + }); List<Long> localBoardIDsWithChangedACL = dataBaseAdapter.getBoardIDsOfLocallyChangedAccessControl(accountId); for (Long boardId : localBoardIDsWithChangedACL) { @@ -151,7 +146,11 @@ public class BoardDataProvider extends AbstractSyncDataProvider<FullBoard> { if (added) { FullBoard board = dataBaseAdapter.getFullBoardByLocalIdDirectly(accountId, boardId); locallyChangedStack.getStack().setBoardId(board.getId()); - syncHelper.doUpSyncFor(new StackDataProvider(this, board)); + //TODO: maybe better with waits? shouldn't change anything, since the added flag should prevent concurrency... +// AsyncUtil.awaitAsyncWork(1, (countDownLatch) -> { +// syncHelper.doUpSyncFor(new StackDataProvider(this, board), countDownLatch); + syncHelper.doUpSyncFor(new StackDataProvider(this, board)); +// }); } } } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/providers/CardDataProvider.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/providers/CardDataProvider.java index 9d7284fe7..4c7cc4b57 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/providers/CardDataProvider.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/providers/CardDataProvider.java @@ -70,7 +70,7 @@ public class CardDataProvider extends AbstractSyncDataProvider<FullCard> { @Override public long createInDB(DataBaseAdapter dataBaseAdapter, long accountId, FullCard entity) { fixRelations(dataBaseAdapter, accountId, entity); - return dataBaseAdapter.createCard(accountId, entity.getCard()); + return dataBaseAdapter.createCardDirectly(accountId, entity.getCard()); } protected CardUpdate toCardUpdate(FullCard card) { @@ -150,7 +150,9 @@ public class CardDataProvider extends AbstractSyncDataProvider<FullCard> { @Override public void createOnServer(ServerAdapter serverAdapter, DataBaseAdapter dataBaseAdapter, long accountId, IResponseCallback<FullCard> responder, FullCard entity) { entity.getCard().setStackId(stack.getId()); - serverAdapter.createCard(board.getId(), stack.getId(), entity.getCard(), responder); +// if (board != null && stack != null && board.getId() != null && stack.getId() != null) { + serverAdapter.createCard(board.getId(), stack.getId(), entity.getCard(), responder); +// } else DeckLog.error("Skipped card creation due to missing remote ID"); } @Override @@ -230,9 +232,14 @@ public class CardDataProvider extends AbstractSyncDataProvider<FullCard> { } } - List<JoinCardWithUser> deletedUsers = dataBaseAdapter.getAllDeletedUserJoinsWithRemoteIDs(); - for (JoinCardWithUser deletedUser : deletedUsers) { - Card card = dataBaseAdapter.getCardByRemoteIdDirectly(account.getId(), deletedUser.getCardId()); + List<JoinCardWithUser> changedUsers = dataBaseAdapter.getAllChangedUserJoinsWithRemoteIDs(); + for (JoinCardWithUser changedUser : changedUsers) { + // not already known to server? + if (changedUser.getCardId() == null) { + //skip for now + continue; + } + Card card = dataBaseAdapter.getCardByRemoteIdDirectly(account.getId(), changedUser.getCardId()); if (this.stack == null) { stack = dataBaseAdapter.getFullStackByLocalIdDirectly(card.getStackId()); } else { @@ -244,16 +251,16 @@ public class CardDataProvider extends AbstractSyncDataProvider<FullCard> { } else { board = this.board; } - User user = dataBaseAdapter.getUserByLocalIdDirectly(deletedUser.getUserId()); - if (deletedUser.getStatusEnum() == DBStatus.LOCAL_DELETED) { - serverAdapter.unassignUserFromCard(board.getId(), stack.getId(), deletedUser.getCardId(), user.getUid(), new IResponseCallback<Void>(account) { + User user = dataBaseAdapter.getUserByLocalIdDirectly(changedUser.getUserId()); + if (changedUser.getStatusEnum() == DBStatus.LOCAL_DELETED) { + serverAdapter.unassignUserFromCard(board.getId(), stack.getId(), changedUser.getCardId(), user.getUid(), new IResponseCallback<Void>(account) { @Override public void onResponse(Void response) { - dataBaseAdapter.deleteJoinedUserForCardPhysicallyByRemoteIDs(account.getId(), deletedUser.getCardId(), user.getUid()); + dataBaseAdapter.deleteJoinedUserForCardPhysicallyByRemoteIDs(account.getId(), changedUser.getCardId(), user.getUid()); } }); - } else if (deletedUser.getStatusEnum() == DBStatus.LOCAL_EDITED) { - serverAdapter.assignUserToCard(board.getId(), stack.getId(), deletedUser.getCardId(), user.getUid(), new IResponseCallback<Void>(account) { + } else if (changedUser.getStatusEnum() == DBStatus.LOCAL_EDITED) { + serverAdapter.assignUserToCard(board.getId(), stack.getId(), changedUser.getCardId(), user.getUid(), new IResponseCallback<Void>(account) { @Override public void onResponse(Void response) { dataBaseAdapter.setStatusForJoinCardWithUser(card.getLocalId(), user.getLocalId(), DBStatus.UP_TO_DATE.getId()); diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/providers/LabelDataProvider.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/providers/LabelDataProvider.java index 7510d9be3..90d633bce 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/providers/LabelDataProvider.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/providers/LabelDataProvider.java @@ -45,7 +45,7 @@ public class LabelDataProvider extends AbstractSyncDataProvider<Label> { updateInDB(dataBaseAdapter, accountId, entity, false); return entity.getLocalId(); } else { - return dataBaseAdapter.createLabel(accountId, entity); + return dataBaseAdapter.createLabelDirectly(accountId, entity); } } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/providers/StackDataProvider.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/providers/StackDataProvider.java index a3c123afd..7901cfedf 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/providers/StackDataProvider.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/providers/StackDataProvider.java @@ -15,6 +15,7 @@ import it.niedermann.nextcloud.deck.model.full.FullStack; import it.niedermann.nextcloud.deck.persistence.sync.adapters.ServerAdapter; import it.niedermann.nextcloud.deck.persistence.sync.adapters.db.DataBaseAdapter; import it.niedermann.nextcloud.deck.persistence.sync.helpers.SyncHelper; +import it.niedermann.nextcloud.deck.persistence.sync.helpers.util.AsyncUtil; public class StackDataProvider extends AbstractSyncDataProvider<FullStack> { private FullBoard board; @@ -110,9 +111,14 @@ public class StackDataProvider extends AbstractSyncDataProvider<FullStack> { boolean added = syncedStacks.add(stackId); if (added) { FullStack stack = dataBaseAdapter.getFullStackByLocalIdDirectly(stackId); - Board board = dataBaseAdapter.getBoardByLocalIdDirectly(stack.getStack().getBoardId()); - changedCard.getCard().setStackId(stack.getId()); - syncHelper.doUpSyncFor(new CardDataProvider(this, board, stack)); + // already synced and known to server? + if (stack.getStack().getId() != null) { + AsyncUtil.awaitAsyncWork(1, latch -> { + Board board = dataBaseAdapter.getBoardByLocalIdDirectly(stack.getStack().getBoardId()); + changedCard.getCard().setStackId(stack.getId()); + syncHelper.doUpSyncFor(new CardDataProvider(this, board, stack), latch); + }); + } } } } else { diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/providers/partial/BoardWithStacksAndLabelsUpSyncDataProvider.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/providers/partial/BoardWithStacksAndLabelsUpSyncDataProvider.java index 278971a9d..3416e1b89 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/providers/partial/BoardWithStacksAndLabelsUpSyncDataProvider.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/providers/partial/BoardWithStacksAndLabelsUpSyncDataProvider.java @@ -5,6 +5,7 @@ import java.util.Date; import java.util.List; import it.niedermann.nextcloud.deck.api.IResponseCallback; +import it.niedermann.nextcloud.deck.model.Label; import it.niedermann.nextcloud.deck.model.full.FullBoard; import it.niedermann.nextcloud.deck.persistence.sync.adapters.ServerAdapter; import it.niedermann.nextcloud.deck.persistence.sync.adapters.db.DataBaseAdapter; @@ -20,6 +21,21 @@ public class BoardWithStacksAndLabelsUpSyncDataProvider extends BoardDataProvide } @Override + public void updateInDB(DataBaseAdapter dataBaseAdapter, long accountId, FullBoard entity, boolean setStatus) { + //merge labels (created at board creation) + if (entity!= null && entity.getLabels() != null) { + for (Label label : entity.getLabels()) { + Label existing = dataBaseAdapter.getLabelByBoardIdAndTitleDirectly(board.getLocalId(), label.getTitle()); + if (existing != null) { + existing.setId(label.getId()); + dataBaseAdapter.updateLabel(existing, false); + } + } + } + super.updateInDB(dataBaseAdapter, accountId, entity, setStatus); + } + + @Override public List<FullBoard> getAllChangedFromDB(DataBaseAdapter dataBaseAdapter, long accountId, Date lastSync) { return Collections.singletonList(board); } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/util/AsyncUtil.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/util/AsyncUtil.java new file mode 100644 index 000000000..faabda163 --- /dev/null +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/util/AsyncUtil.java @@ -0,0 +1,21 @@ +package it.niedermann.nextcloud.deck.persistence.sync.helpers.util; + +import java.util.concurrent.CountDownLatch; + +import it.niedermann.nextcloud.deck.DeckLog; + +public class AsyncUtil { + public interface LatchCallback { + void doWork(CountDownLatch latch); + } + + public static void awaitAsyncWork(int count, LatchCallback worker){ + CountDownLatch countDownLatch = new CountDownLatch(count); + worker.doWork(countDownLatch); + try { + countDownLatch.await(); + } catch (InterruptedException e) { + DeckLog.logError(e); + } + } +} |