diff options
author | desperateCoder <echotodevnull@gmail.com> | 2019-09-20 21:57:25 +0300 |
---|---|---|
committer | desperateCoder <echotodevnull@gmail.com> | 2019-09-20 21:57:25 +0300 |
commit | 973139b2762fdbfb1fb061de914c7cace4897cf7 (patch) | |
tree | 4544385958531a34bf571ab8b8b108059c8390c1 /app/src | |
parent | a448f3e7624d2a67b312c222cb311cb62d27f5bb (diff) |
downsync: remove remote deleted stacks
Diffstat (limited to 'app/src')
4 files changed, 46 insertions, 2 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 c6966d5ff..0270b1fb5 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 @@ -234,7 +234,7 @@ public class SyncManager { } public LiveData<List<FullStack>> getStacksForBoard(long accountId, long localBoardId) { - return dataBaseAdapter.getStacks(accountId, localBoardId); + return dataBaseAdapter.getFullStacksForBoard(accountId, localBoardId); } public LiveData<FullStack> getStack(long accountId, long localStackId) { 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 a4d079fe7..4996f29e1 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 @@ -286,10 +286,14 @@ public class DataBaseAdapter { db.getBoardDao().update(board); } - public LiveData<List<FullStack>> getStacks(long accountId, long localBoardId) { + public LiveData<List<FullStack>> getFullStacksForBoard(long accountId, long localBoardId) { return LiveDataHelper.onlyIfChanged(db.getStackDao().getFullStacksForBoard(accountId, localBoardId)); } + public List<FullStack> getFullStacksForBoardDirectly(long accountId, long localBoardId) { + return db.getStackDao().getFullStacksForBoardDirectly(accountId, localBoardId); + } + public LiveData<FullStack> getStack(long accountId, long localStackId) { return LiveDataHelper.onlyIfChanged(db.getStackDao().getFullStack(accountId, localStackId)); } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/StackDao.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/StackDao.java index 534773f0f..553a67d95 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/StackDao.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/StackDao.java @@ -49,4 +49,8 @@ public interface StackDao extends GenericDao<Stack> { @Transaction @Query("SELECT * FROM stack WHERE accountId = :accountId and (status<>1 or id is null or lastModified <> lastModifiedLocal)") List<FullStack> getLocallyChangedStacksDirectly(long accountId); + + @Transaction + @Query("SELECT * FROM stack WHERE accountId = :accountId AND boardId = :localBoardId and status<>3 and (deletedAt is null or deletedAt = 0) order by `order` asc") + List<FullStack> getFullStacksForBoardDirectly(long accountId, long localBoardId); }
\ No newline at end of file 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 80e36f477..797b0add8 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 @@ -7,8 +7,11 @@ import java.util.List; import java.util.Set; import it.niedermann.nextcloud.deck.api.IResponseCallback; +import it.niedermann.nextcloud.deck.exceptions.OfflineException; +import it.niedermann.nextcloud.deck.model.Account; import it.niedermann.nextcloud.deck.model.Board; import it.niedermann.nextcloud.deck.model.Card; +import it.niedermann.nextcloud.deck.model.enums.DBStatus; import it.niedermann.nextcloud.deck.model.full.FullBoard; import it.niedermann.nextcloud.deck.model.full.FullCard; import it.niedermann.nextcloud.deck.model.full.FullStack; @@ -120,4 +123,37 @@ public class StackDataProvider extends AbstractSyncDataProvider<FullStack> { public void updateOnServer(ServerAdapter serverAdapter, DataBaseAdapter dataBaseAdapter, long accountId, IResponseCallback<FullStack> callback, FullStack entity) { serverAdapter.updateStack(entity.getStack(), callback); } + + @Override + public void handleDeletes(ServerAdapter serverAdapter, DataBaseAdapter dataBaseAdapter, long accountId, List<FullStack> entitiesFromServer) { + List<FullStack> localStacks = dataBaseAdapter.getFullStacksForBoardDirectly(accountId, board.getLocalId()); + List<FullStack> delta = findDelta(entitiesFromServer, localStacks); + for (FullStack stackToDelete : delta) { + if (stackToDelete.getStatus() == DBStatus.LOCAL_MOVED.getId()){ + if (stackToDelete.getId() == null){ + // not pushed up yet so: + continue; + } else { + //only delete, if the card isn't availible on server anymore. + serverAdapter.getStack(board.getId(), stackToDelete.getId(), new IResponseCallback<FullStack>(new Account(accountId)){ + @Override + public void onResponse(FullStack response) { + // do not delete, it's still there and was just moved! + } + + @Override + public void onError(Throwable throwable) { + if (!(throwable instanceof OfflineException)) { + // most likely permission denied, therefore deleted + dataBaseAdapter.deleteStackPhysically(stackToDelete.getStack()); + } + } + }); + } + + continue; + } + dataBaseAdapter.deleteStackPhysically(stackToDelete.getStack()); + } + } } |