diff options
author | stefan-niedermann <info@niedermann.it> | 2019-09-15 16:19:28 +0300 |
---|---|---|
committer | stefan-niedermann <info@niedermann.it> | 2019-09-15 16:19:28 +0300 |
commit | a78a2bcef238ce8f6eca2f316c8884d003602069 (patch) | |
tree | b4d5a81a6c4608e326ebbd5465f5426b6ab04114 /app | |
parent | d72272622d77ea00e45fd5ca017329f0d2d7974d (diff) |
Handle remote deletes for cards
Diffstat (limited to 'app')
3 files changed, 27 insertions, 2 deletions
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 2dd90ff35..2e7e46d15 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 @@ -123,6 +123,10 @@ public class DataBaseAdapter { return LiveDataHelper.interceptLiveData(db.getCardDao().getFullCardsForStack(accountId, localStackId), this::readRelationsForCard); } + public List<FullCard> getFullCardsForStackDirectly(long accountId, long localStackId) { + return db.getCardDao().getFullCardsForStackDirectly(accountId, localStackId); + } + public User getUserByUidDirectly(long accountId, String uid) { return db.getUserDao().getUserByUidDirectly(accountId, uid); } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/providers/AbstractSyncDataProvider.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/providers/AbstractSyncDataProvider.java index f70b50679..1a5fe7034 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/providers/AbstractSyncDataProvider.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/providers/AbstractSyncDataProvider.java @@ -31,8 +31,20 @@ public abstract class AbstractSyncDataProvider<T extends IRemoteEntity> { } protected List<T> findDelta(List<T> entitiesFromServer, List<T> localEntities){ - //TODO implement - return null; + List<T> delta = new ArrayList<>(); + for (T localEntity : localEntities) { + boolean found = false; + for (T remoteEntity : entitiesFromServer) { + if (remoteEntity.getId().equals(localEntity.getId())) { + found = true; + break; + } + } + if (!found){ + delta.add(localEntity); + } + } + return delta; } public void addChild(AbstractSyncDataProvider<?> child) { 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 8eb4530bf..987f8f073 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 @@ -224,4 +224,13 @@ public class CardDataProvider extends AbstractSyncDataProvider<FullCard> { } callback.onResponse(Boolean.TRUE); } + + @Override + public void handleDeletes(ServerAdapter serverAdapter, DataBaseAdapter dataBaseAdapter, long accountId, List<FullCard> entitiesFromServer) { + List<FullCard> localCards = dataBaseAdapter.getFullCardsForStackDirectly(accountId, stack.getLocalId()); + List<FullCard> delta = findDelta(entitiesFromServer, localCards); + for (FullCard cardToDelete : delta) { + dataBaseAdapter.deleteCardPhysically(cardToDelete.getCard()); + } + } } |