diff options
Diffstat (limited to 'app/src/main')
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()); + } + } } |