diff options
author | Artur <desperateCoder@users.noreply.github.com> | 2019-03-12 19:05:14 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-12 19:05:14 +0300 |
commit | 7b08bc2368e3eb8fb92ea28ecb967895f41f4380 (patch) | |
tree | d5e8f8fc4703d5e9302748d32c0cbd5acd34d943 | |
parent | 9bb6435de276da6498f9903d9778b6b1b0964b46 (diff) | |
parent | 833ed60c68442886248da0b80f54707a6c717e48 (diff) |
Merge pull request #37 from stefan-niedermann/upsync
Upsync
15 files changed, 247 insertions, 78 deletions
diff --git a/.gitignore b/.gitignore index a6debc2ba..ac5af8493 100644 --- a/.gitignore +++ b/.gitignore @@ -34,13 +34,7 @@ captures/ # IntelliJ *.iml -.idea/workspace.xml -.idea/stacks.xml -.idea/gradle.xml -.idea/assetWizardSettings.xml -.idea/dictionaries -.idea/libraries -.idea/caches +.idea # Keystore files # Uncomment the following line if you do not want to check your keystore files in. diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/model/enums/DBStatus.java b/app/src/main/java/it/niedermann/nextcloud/deck/model/enums/DBStatus.java index 7fa9c30be..6629af018 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/model/enums/DBStatus.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/model/enums/DBStatus.java @@ -7,19 +7,19 @@ package it.niedermann.nextcloud.deck.model.enums; public enum DBStatus { /** - * VOID means, that the Note was not modified locally + * UP_TO_DATE means, that the Note was not modified locally */ UP_TO_DATE(1), /** - * LOCAL_EDITED means that a Note was created and/or changed since the last successful synchronization. + * LOCAL_EDITED means that a Note was changed since the last successful synchronization. * If it was newly created, then REMOTE_ID is 0 */ LOCAL_EDITED(2), /** * LOCAL_DELETED means that the Note was deleted locally, but this information was not yet synchronized. - * Therefore, the Note have to be kept locally until the synchronization has succeeded. + * Therefore, the Note has to be kept locally until the synchronization has succeeded. * However, Notes with this status should not be displayed in the UI. */ LOCAL_DELETED(3); 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 390c2adb9..d9435010e 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 @@ -1,13 +1,13 @@ package it.niedermann.nextcloud.deck.persistence.sync; import android.app.Activity; -import androidx.lifecycle.LiveData; import android.content.Context; import android.content.SharedPreferences; import java.util.Date; import java.util.List; +import androidx.lifecycle.LiveData; import it.niedermann.nextcloud.deck.DeckConsts; import it.niedermann.nextcloud.deck.DeckLog; import it.niedermann.nextcloud.deck.R; @@ -48,7 +48,6 @@ public class SyncManager { } public void synchronize(IResponseCallback<Boolean> responseCallback) { - final long accountId = responseCallback.getAccount().getId(); doAsync(() -> { SharedPreferences lastSyncPref = applicationContext.getSharedPreferences( applicationContext.getString(R.string.shared_preference_last_sync), Context.MODE_PRIVATE); @@ -56,19 +55,38 @@ public class SyncManager { Date lastSyncDate = new Date(lastSync); Date now = new Date(); - new SyncHelper(serverAdapter, dataBaseAdapter, new IResponseCallback<Boolean>(responseCallback.getAccount()) { + BoardDataProvider boardDataProvider = new BoardDataProvider(); + final SyncHelper syncHelper = new SyncHelper(serverAdapter, dataBaseAdapter, lastSyncDate); + + IResponseCallback<Boolean> callback = new IResponseCallback<Boolean>(responseCallback.getAccount()) { @Override public void onResponse(Boolean response) { - //TODO activate when done dev -// lastSyncPref.edit().putLong(LAST_SYNC_KEY, now.getTime()).apply(); - responseCallback.onResponse(response); + syncHelper.setResponseCallback(new IResponseCallback<Boolean>(account) { + @Override + public void onResponse(Boolean response) { + // TODO activate when done dev + // lastSyncPref.edit().putLong(LAST_SYNC_KEY, now.getTime()).apply(); + responseCallback.onResponse(response); + } + @Override + public void onError(Throwable throwable) { + super.onError(throwable); + responseCallback.onError(throwable); + } + }); + syncHelper.doUpSyncFor(boardDataProvider); } @Override public void onError(Throwable throwable) { + super.onError(throwable); responseCallback.onError(throwable); } - }).doSyncFor(new BoardDataProvider()); + }; + + syncHelper.setResponseCallback(callback); + + syncHelper.doSyncFor(boardDataProvider); }); } @@ -141,7 +159,6 @@ public class SyncManager { @Override public void onResponse(FullBoard response) { DeckLog.log(response.toString()); - } @Override @@ -155,12 +172,12 @@ public class SyncManager { public void deleteBoard(Board board) { //TODO: Tell the server - dataBaseAdapter.deleteBoard(board); + dataBaseAdapter.deleteBoard(board, true); } public void updateBoard(Board board) { //TODO: Tell the server - dataBaseAdapter.updateBoard(board); + dataBaseAdapter.updateBoard(board, true); } public LiveData<List<FullStack>> getStacksForBoard(long accountId, long localBoardId) { @@ -180,7 +197,7 @@ public class SyncManager { } public void updateAccessControl(AccessControl entity) { - dataBaseAdapter.updateAccessControl(entity); + dataBaseAdapter.updateAccessControl(entity, true); } public LiveData<FullBoard> getFullBoardById(Long accountId, Long localId) { @@ -194,12 +211,12 @@ public class SyncManager { public void deleteStack(Stack stack) { //TODO: Tell the server - dataBaseAdapter.deleteStack(stack); + dataBaseAdapter.deleteStack(stack, true); } public void updateStack(Stack stack) { //TODO: Tell the server - dataBaseAdapter.updateStack(stack); + dataBaseAdapter.updateStack(stack, true); } @@ -219,17 +236,14 @@ public class SyncManager { public void deleteCard(Card card) { //TODO: Tell the server - dataBaseAdapter.deleteCard(card); + dataBaseAdapter.deleteCard(card, true); } public void updateCard(Card card) { - Date now = new Date(); //TODO: Tell the server doAsync(()->{ - card.setLastModifiedLocal(now); - card.setLastModified(now); - dataBaseAdapter.updateCard(card); + dataBaseAdapter.updateCard(card, true); }); } @@ -240,12 +254,12 @@ public class SyncManager { public void deleteLabel(Label label) { //TODO: Tell the server - dataBaseAdapter.deleteLabel(label); + dataBaseAdapter.deleteLabel(label, true); } public void updateLabel(Label label) { //TODO: Tell the server - dataBaseAdapter.updateLabel(label); + dataBaseAdapter.updateLabel(label, true); } public void assignLabelToBoard(long localLabelId, long localBoardId) { @@ -291,7 +305,7 @@ public class SyncManager { } public void updateUser(long accountId, User user) { - dataBaseAdapter.updateUser(accountId, user); + dataBaseAdapter.updateUser(accountId, user, true); } public LiveData<List<FullStack>> getStacks(long accountId, long localBoardId) { 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 9cbc23688..5dbc4e545 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 @@ -1,10 +1,11 @@ package it.niedermann.nextcloud.deck.persistence.sync.adapters.db; -import androidx.lifecycle.LiveData; import android.content.Context; +import java.util.Date; import java.util.List; +import androidx.lifecycle.LiveData; import it.niedermann.nextcloud.deck.model.AccessControl; import it.niedermann.nextcloud.deck.model.Account; import it.niedermann.nextcloud.deck.model.Attachment; @@ -16,9 +17,11 @@ import it.niedermann.nextcloud.deck.model.JoinCardWithUser; import it.niedermann.nextcloud.deck.model.Label; import it.niedermann.nextcloud.deck.model.Stack; import it.niedermann.nextcloud.deck.model.User; +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; +import it.niedermann.nextcloud.deck.model.interfaces.AbstractRemoteEntity; import it.niedermann.nextcloud.deck.persistence.sync.adapters.db.util.LiveDataHelper; public class DataBaseAdapter { @@ -29,6 +32,18 @@ public class DataBaseAdapter { this.db = DeckDatabase.getInstance(applicationContext); } + private <T extends AbstractRemoteEntity> void markAsEditedIfNeeded(T entity, boolean setStatus) { + if (!setStatus) return; + entity.setStatusEnum(DBStatus.LOCAL_EDITED); + entity.setLastModifiedLocal(new Date()); // now. + } + + private <T extends AbstractRemoteEntity> void markAsDeletedIfNeeded(T entity, boolean setStatus) { + if (!setStatus) return; + entity.setStatusEnum(DBStatus.LOCAL_DELETED); + entity.setLastModifiedLocal(new Date()); // now. + } + public LiveData<Boolean> hasAccounts(){ return LiveDataHelper.postCustomValue(db.getAccountDao().countAccounts(), data -> data != null && data > 0); } @@ -98,7 +113,8 @@ public class DataBaseAdapter { return db.getUserDao().insert(user); } - public void updateUser(long accountId, User user) { + public void updateUser(long accountId, User user, boolean setStatus) { + markAsEditedIfNeeded(user, setStatus); user.setAccountId(accountId); db.getUserDao().update(user); } @@ -149,12 +165,14 @@ public class DataBaseAdapter { db.getJoinBoardWithLabelDao().deleteByBoardId(localBoardId); } - public void updateLabel(Label label) { + public void updateLabel(Label label, boolean setStatus) { + markAsEditedIfNeeded(label, setStatus); db.getLabelDao().update(label); } - public void deleteLabel(Label label) { - db.getLabelDao().delete(label); + public void deleteLabel(Label label, boolean setStatus) { + markAsDeletedIfNeeded(label, setStatus); + db.getLabelDao().update(label); } public LiveData<Account> createAccount(String accoutName) { @@ -205,11 +223,13 @@ public class DataBaseAdapter { return db.getBoardDao().insert(board); } - public void deleteBoard(Board board) { - db.getBoardDao().delete(board); + public void deleteBoard(Board board, boolean setStatus) { + markAsDeletedIfNeeded(board, setStatus); + db.getBoardDao().update(board); } - public void updateBoard(Board board) { + public void updateBoard(Board board, boolean setStatus) { + markAsEditedIfNeeded(board, setStatus); db.getBoardDao().update(board); } @@ -226,11 +246,13 @@ public class DataBaseAdapter { return db.getStackDao().insert(stack); } - public void deleteStack(Stack stack) { - db.getStackDao().delete(stack); + public void deleteStack(Stack stack, boolean setStatus) { + markAsDeletedIfNeeded(stack, setStatus); + db.getStackDao().update(stack); } - public void updateStack(Stack stack) { + public void updateStack(Stack stack, boolean setStatus) { + markAsEditedIfNeeded(stack, setStatus); db.getStackDao().update(stack); } @@ -243,11 +265,13 @@ public class DataBaseAdapter { return db.getCardDao().insert(card); } - public void deleteCard(Card card) { - db.getCardDao().delete(card); + public void deleteCard(Card card, boolean setStatus) { + markAsDeletedIfNeeded(card, setStatus); + db.getCardDao().update(card); } - public void updateCard(Card card) { + public void updateCard(Card card, boolean setStatus) { + markAsEditedIfNeeded(card, setStatus); db.getCardDao().update(card); } @@ -260,7 +284,8 @@ public class DataBaseAdapter { return db.getAccessControlDao().getAccessControlByRemoteIdDirectly(accountId, id); } - public void updateAccessControl(AccessControl entity) { + public void updateAccessControl(AccessControl entity, boolean setStatus) { + markAsEditedIfNeeded(entity, setStatus); db.getAccessControlDao().update(entity); } @@ -299,7 +324,8 @@ public class DataBaseAdapter { return db.getAttachmentDao().insert(attachment); } - public void updateAttachment(long accountId, Attachment attachment) { + public void updateAttachment(long accountId, Attachment attachment, boolean setStatus) { + markAsEditedIfNeeded(attachment, setStatus); attachment.setAccountId(accountId); db.getAttachmentDao().update(attachment); } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/BoardDao.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/BoardDao.java index 25fa42a69..82e3d01d8 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/BoardDao.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/BoardDao.java @@ -30,6 +30,12 @@ public interface BoardDao extends GenericDao<Board> { FullBoard getFullBoardByRemoteIdDirectly(long accountId, long remoteId); @Transaction + @Query("SELECT * FROM board WHERE accountId = :accountId and (id is null or lastModified <> lastModifiedLocal)") + FullBoard getLocallyChangedBoardsDirectly(long accountId); + + @Transaction @Query("SELECT * FROM board WHERE accountId = :accountId and localId = :localId") LiveData<FullBoard> getFullBoardById(final long accountId, final long localId); + + }
\ No newline at end of file diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/CardDao.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/CardDao.java index 0b8e4a907..441abc3e3 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/CardDao.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/CardDao.java @@ -19,7 +19,6 @@ public interface CardDao extends GenericDao<Card> { @Query("SELECT * FROM card WHERE accountId = :accountId and id = :remoteId") LiveData<Card> getCardByRemoteId(final long accountId, final long remoteId); - @Transaction @Query("SELECT * FROM card WHERE accountId = :accountId and id = :remoteId") FullCard getFullCardByRemoteIdDirectly(final long accountId, final long remoteId); diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/SyncHelper.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/SyncHelper.java index 43b7ab487..dc2220069 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/SyncHelper.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/SyncHelper.java @@ -1,10 +1,12 @@ package it.niedermann.nextcloud.deck.persistence.sync.helpers; +import java.util.Date; import java.util.List; import it.niedermann.nextcloud.deck.DeckLog; import it.niedermann.nextcloud.deck.api.IResponseCallback; import it.niedermann.nextcloud.deck.model.Account; +import it.niedermann.nextcloud.deck.model.enums.DBStatus; import it.niedermann.nextcloud.deck.model.interfaces.IRemoteEntity; import it.niedermann.nextcloud.deck.persistence.sync.adapters.ServerAdapter; import it.niedermann.nextcloud.deck.persistence.sync.adapters.db.DataBaseAdapter; @@ -17,16 +19,15 @@ public class SyncHelper { private Account account; private long accountId; private IResponseCallback<Boolean> responseCallback; - private boolean syncChangedSomething = false; + private Date lastSync; - public SyncHelper(ServerAdapter serverAdapter, DataBaseAdapter dataBaseAdapter, IResponseCallback<Boolean> responseCallback) { + public SyncHelper(ServerAdapter serverAdapter, DataBaseAdapter dataBaseAdapter, Date lastSync) { this.serverAdapter = serverAdapter; this.dataBaseAdapter = dataBaseAdapter; - this.responseCallback = responseCallback; - this.account = responseCallback.getAccount(); - accountId = account.getId(); + this.lastSync = lastSync; } + // Sync Server -> App public <T extends IRemoteEntity> void doSyncFor(final IDataProvider<T> provider){ provider.getAllFromServer(serverAdapter, accountId, new IResponseCallback<List<T>>(account) { @Override @@ -35,18 +36,23 @@ public class SyncHelper { for (T entityFromServer : response) { entityFromServer.setAccountId(accountId); T existingEntity = provider.getSingleFromDB(dataBaseAdapter, accountId, entityFromServer); + if (existingEntity == null) { provider.createInDB(dataBaseAdapter, accountId, entityFromServer); - syncChangedSomething = true; } else { - provider.updateInDB(dataBaseAdapter, accountId, applyUpdatesFromRemote(existingEntity, entityFromServer, accountId)); - syncChangedSomething = true; //TODO: only if no diff! + if (existingEntity.getStatus() != DBStatus.UP_TO_DATE.getId()){ + DeckLog.log("Conflicting changes on entity: "+existingEntity); + // TODO: what to do? + } else { + provider.updateInDB(dataBaseAdapter, accountId, applyUpdatesFromRemote(existingEntity, entityFromServer, accountId)); + } } existingEntity = provider.getSingleFromDB(dataBaseAdapter, accountId, entityFromServer); provider.goDeeper(SyncHelper.this, existingEntity, entityFromServer); } - provider.doneAll(responseCallback, syncChangedSomething); } + + provider.doneAll(responseCallback, Boolean.TRUE); } @Override @@ -54,7 +60,44 @@ public class SyncHelper { DeckLog.logError(throwable); responseCallback.onError(throwable); } - }); + }, lastSync); + } + + // Sync App -> Server + public <T extends IRemoteEntity> void doUpSyncFor(IDataProvider<T> provider){ + List<T> allFromDB = provider.getAllFromDB(dataBaseAdapter, accountId, lastSync); + if (allFromDB != null && !allFromDB.isEmpty()) { + for (T entity : allFromDB) { + IResponseCallback<T> updateCallback = new IResponseCallback<T>(account) { + @Override + public void onResponse(T response) { + provider.updateInDB(dataBaseAdapter, accountId, applyUpdatesFromRemote(entity, response, accountId)); + provider.goDeeperForUpSync(SyncHelper.this, entity, response); + } + + @Override + public void onError(Throwable throwable) { + super.onError(throwable); + responseCallback.onError(throwable); + } + }; + if (entity.getId()!=null) { + if (entity.getStatusEnum() == DBStatus.LOCAL_DELETED) { + provider.deleteOnServer(serverAdapter, accountId, new IResponseCallback<T>(account) { + @Override + public void onResponse(T response) { + provider.deleteInDB(dataBaseAdapter, accountId, response); + } + }, entity); + } else { + provider.updateOnServer(serverAdapter, accountId, updateCallback, entity); + } + } else { + provider.createOnServer(serverAdapter, accountId, updateCallback, entity); + } + } + } + } public void fixRelations(IRelationshipProvider relationshipProvider) { @@ -70,4 +113,10 @@ public class SyncHelper { remoteEntity.setLocalId(localEntity.getLocalId()); return remoteEntity; } + + public void setResponseCallback(IResponseCallback<Boolean> callback) { + this.responseCallback = callback; + this.account = responseCallback.getAccount(); + accountId = account.getId(); + } } 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 21376aaa3..48b19c952 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 @@ -1,5 +1,6 @@ package it.niedermann.nextcloud.deck.persistence.sync.helpers.providers; +import java.util.Date; import java.util.List; import it.niedermann.nextcloud.deck.api.IResponseCallback; @@ -18,7 +19,7 @@ public class AccessControlDataProvider implements IDataProvider<AccessControl> { } @Override - public void getAllFromServer(ServerAdapter serverAdapter, long accountId, IResponseCallback<List<AccessControl>> responder) { + public void getAllFromServer(ServerAdapter serverAdapter, long accountId, IResponseCallback<List<AccessControl>> responder, Date lastSync) { responder.onResponse(acl); } @@ -41,14 +42,14 @@ public class AccessControlDataProvider implements IDataProvider<AccessControl> { } else { entity.setUserId(user.getLocalId()); entity.getUser().setLocalId(user.getLocalId()); - dataBaseAdapter.updateUser(accountId, entity.getUser()); + dataBaseAdapter.updateUser(accountId, entity.getUser(), false); } } @Override public void updateInDB(DataBaseAdapter dataBaseAdapter, long accountId, AccessControl entity) { prepareUser(dataBaseAdapter, accountId, entity); - dataBaseAdapter.updateAccessControl(entity); + dataBaseAdapter.updateAccessControl(entity, false); } @Override @@ -76,4 +77,14 @@ public class AccessControlDataProvider implements IDataProvider<AccessControl> { public void deleteOnServer(ServerAdapter serverAdapter, long accountId, IResponseCallback<AccessControl> callback, AccessControl entity) { } + + @Override + public List<AccessControl> getAllFromDB(DataBaseAdapter dataBaseAdapter, long accountId, Date lastSync) { + return null; + } + + @Override + public void goDeeperForUpSync(SyncHelper syncHelper, AccessControl entity, AccessControl response) { + + } } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/providers/AttachmentDataProvider.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/providers/AttachmentDataProvider.java index d9047be49..b23c389ee 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/providers/AttachmentDataProvider.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/providers/AttachmentDataProvider.java @@ -1,5 +1,6 @@ package it.niedermann.nextcloud.deck.persistence.sync.helpers.providers; +import java.util.Date; import java.util.List; import it.niedermann.nextcloud.deck.api.IResponseCallback; @@ -20,7 +21,7 @@ public class AttachmentDataProvider implements IDataProvider<Attachment> { } @Override - public void getAllFromServer(ServerAdapter serverAdapter, long accountId, IResponseCallback<List<Attachment>> responder) { + public void getAllFromServer(ServerAdapter serverAdapter, long accountId, IResponseCallback<List<Attachment>> responder, Date lastSync) { responder.onResponse(attachments); } @@ -38,7 +39,7 @@ public class AttachmentDataProvider implements IDataProvider<Attachment> { @Override public void updateInDB(DataBaseAdapter dataBaseAdapter, long accountId, Attachment attachment) { attachment.setCardId(card.getCard().getLocalId()); - dataBaseAdapter.updateAttachment(accountId, attachment); + dataBaseAdapter.updateAttachment(accountId, attachment, false); } @@ -66,4 +67,14 @@ public class AttachmentDataProvider implements IDataProvider<Attachment> { public void deleteOnServer(ServerAdapter serverAdapter, long accountId, IResponseCallback<Attachment> callback, Attachment entity) { } + + @Override + public List<Attachment> getAllFromDB(DataBaseAdapter dataBaseAdapter, long accountId, Date lastSync) { + return null; + } + + @Override + public void goDeeperForUpSync(SyncHelper syncHelper, Attachment entity, Attachment response) { + + } } 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 69cd82b57..95f1e4b30 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 @@ -1,5 +1,6 @@ package it.niedermann.nextcloud.deck.persistence.sync.helpers.providers; +import java.util.Date; import java.util.List; import it.niedermann.nextcloud.deck.api.IResponseCallback; @@ -12,7 +13,7 @@ import it.niedermann.nextcloud.deck.persistence.sync.helpers.SyncHelper; public class BoardDataProvider implements IDataProvider<FullBoard> { @Override - public void getAllFromServer(ServerAdapter serverAdapter, long accountId, IResponseCallback<List<FullBoard>> responder) { + public void getAllFromServer(ServerAdapter serverAdapter, long accountId, IResponseCallback<List<FullBoard>> responder, Date lastSync) { serverAdapter.getBoards(responder); } @@ -34,7 +35,7 @@ public class BoardDataProvider implements IDataProvider<FullBoard> { if (owner == null){ dataBaseAdapter.createUser(accountId, remoteOwner); } else { - dataBaseAdapter.updateUser(accountId, remoteOwner); + dataBaseAdapter.updateUser(accountId, remoteOwner, false); } owner = dataBaseAdapter.getUserByUidDirectly(accountId, remoteOwner.getUid()); entity.getBoard().setOwnerId(owner.getLocalId()); @@ -44,7 +45,7 @@ public class BoardDataProvider implements IDataProvider<FullBoard> { @Override public void updateInDB(DataBaseAdapter dataBaseAdapter, long accountId, FullBoard entity) { handleOwner(dataBaseAdapter, accountId, entity); - dataBaseAdapter.updateBoard(entity.getBoard()); + dataBaseAdapter.updateBoard(entity.getBoard(), false); } @Override @@ -72,13 +73,23 @@ public class BoardDataProvider implements IDataProvider<FullBoard> { } @Override + public List<FullBoard> getAllFromDB(DataBaseAdapter dataBaseAdapter, long accountId, Date lastSync) { + return null; + } + + @Override + public void goDeeperForUpSync(SyncHelper syncHelper, FullBoard entity, FullBoard response) { + syncHelper.doUpSyncFor(new StackDataProvider(entity)); + } + + @Override public void updateOnServer(ServerAdapter serverAdapter, long accountId, IResponseCallback<FullBoard> callback, FullBoard entity) { serverAdapter.updateBoard(entity.getBoard()); } @Override public void deleteInDB(DataBaseAdapter dataBaseAdapter, long accountId, FullBoard fullBoard) { - + dataBaseAdapter.deleteBoard(fullBoard.getBoard(), false); } @Override 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 a2f4fb569..2966de9d1 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 @@ -1,6 +1,7 @@ package it.niedermann.nextcloud.deck.persistence.sync.helpers.providers; import java.util.ArrayList; +import java.util.Date; import java.util.List; import it.niedermann.nextcloud.deck.api.IResponseCallback; @@ -24,7 +25,7 @@ public class CardDataProvider implements IDataProvider<FullCard> { } @Override - public void getAllFromServer(ServerAdapter serverAdapter, long accountId, IResponseCallback<List<FullCard>> responder) { + public void getAllFromServer(ServerAdapter serverAdapter, long accountId, IResponseCallback<List<FullCard>> responder, Date lastSync) { List<FullCard> result = new ArrayList<>(); if (stack.getCards() == null || stack.getCards().isEmpty()){ @@ -68,7 +69,7 @@ public class CardDataProvider implements IDataProvider<FullCard> { dataBaseAdapter.createUser(accountId, user); } else { user.setLocalId(u.getLocalId()); - dataBaseAdapter.updateUser(accountId, user); + dataBaseAdapter.updateUser(accountId, user, false); } u = dataBaseAdapter.getUserByUidDirectly(accountId, user.getUid()); @@ -80,7 +81,7 @@ public class CardDataProvider implements IDataProvider<FullCard> { @Override public void updateInDB(DataBaseAdapter dataBaseAdapter, long accountId, FullCard entity) { fixRelations(dataBaseAdapter, accountId, entity); - dataBaseAdapter.updateCard(entity.getCard()); + dataBaseAdapter.updateCard(entity.getCard(), false); } @Override @@ -115,4 +116,14 @@ public class CardDataProvider implements IDataProvider<FullCard> { public void deleteOnServer(ServerAdapter serverAdapter, long accountId, IResponseCallback<FullCard> callback, FullCard entity) { } + + @Override + public List<FullCard> getAllFromDB(DataBaseAdapter dataBaseAdapter, long accountId, Date lastSync) { + return null; + } + + @Override + public void goDeeperForUpSync(SyncHelper syncHelper, FullCard entity, FullCard response) { + + } } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/providers/IDataProvider.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/providers/IDataProvider.java index 805ea98fb..c41b85210 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/providers/IDataProvider.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/providers/IDataProvider.java @@ -1,5 +1,6 @@ package it.niedermann.nextcloud.deck.persistence.sync.helpers.providers; +import java.util.Date; import java.util.List; import it.niedermann.nextcloud.deck.api.IResponseCallback; @@ -9,8 +10,7 @@ import it.niedermann.nextcloud.deck.persistence.sync.adapters.db.DataBaseAdapter import it.niedermann.nextcloud.deck.persistence.sync.helpers.SyncHelper; public interface IDataProvider <T extends IRemoteEntity> { - void getAllFromServer(ServerAdapter serverAdapter, long accountId, IResponseCallback<List<T>> responder); - + void getAllFromServer(ServerAdapter serverAdapter, long accountId, IResponseCallback<List<T>> responder, Date lastSync); T getSingleFromDB(DataBaseAdapter dataBaseAdapter, long accountId, T entity); @@ -31,4 +31,8 @@ public interface IDataProvider <T extends IRemoteEntity> { default void doneAll(IResponseCallback<Boolean> responseCallback, boolean syncChangedSomething){ // do nothing! Only BoardDataProvider should overwrite this! } + + List<T> getAllFromDB(DataBaseAdapter dataBaseAdapter, long accountId, Date lastSync); + + void goDeeperForUpSync(SyncHelper syncHelper, T entity, T response); } 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 e4113bbe6..b93ac23ae 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 @@ -1,5 +1,6 @@ package it.niedermann.nextcloud.deck.persistence.sync.helpers.providers; +import java.util.Date; import java.util.List; import it.niedermann.nextcloud.deck.api.IResponseCallback; @@ -17,7 +18,7 @@ public class LabelDataProvider implements IDataProvider<Label> { } @Override - public void getAllFromServer(ServerAdapter serverAdapter, long accountId, IResponseCallback<List<Label>> responder) { + public void getAllFromServer(ServerAdapter serverAdapter, long accountId, IResponseCallback<List<Label>> responder, Date lastSync) { responder.onResponse(labels); } @@ -33,7 +34,7 @@ public class LabelDataProvider implements IDataProvider<Label> { @Override public void updateInDB(DataBaseAdapter dataBaseAdapter, long accountId, Label entity) { - dataBaseAdapter.updateLabel(entity); + dataBaseAdapter.updateLabel(entity, false); } @Override @@ -58,6 +59,16 @@ public class LabelDataProvider implements IDataProvider<Label> { } @Override + public List<Label> getAllFromDB(DataBaseAdapter dataBaseAdapter, long accountId, Date lastSync) { + return null; + } + + @Override + public void goDeeperForUpSync(SyncHelper syncHelper, Label entity, Label response) { + + } + + @Override public void updateOnServer(ServerAdapter serverAdapter, long accountId, IResponseCallback<Label> callback, Label 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 f7113eba8..9d0653fc7 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 @@ -1,5 +1,6 @@ package it.niedermann.nextcloud.deck.persistence.sync.helpers.providers; +import java.util.Date; import java.util.List; import it.niedermann.nextcloud.deck.api.IResponseCallback; @@ -18,7 +19,7 @@ public class StackDataProvider implements IDataProvider<FullStack> { } @Override - public void getAllFromServer(ServerAdapter serverAdapter, long accountId, IResponseCallback<List<FullStack>> responder) { + public void getAllFromServer(ServerAdapter serverAdapter, long accountId, IResponseCallback<List<FullStack>> responder, Date lastSync) { serverAdapter.getStacks(board.getId(), responder); } @@ -36,7 +37,7 @@ public class StackDataProvider implements IDataProvider<FullStack> { @Override public void updateInDB(DataBaseAdapter dataBaseAdapter, long accountId, FullStack entity) { entity.getStack().setBoardId(board.getLocalId()); - dataBaseAdapter.updateStack(entity.getStack()); + dataBaseAdapter.updateStack(entity.getStack(), false); } @Override @@ -66,6 +67,16 @@ public class StackDataProvider implements IDataProvider<FullStack> { } @Override + public List<FullStack> getAllFromDB(DataBaseAdapter dataBaseAdapter, long accountId, Date lastSync) { + return null; + } + + @Override + public void goDeeperForUpSync(SyncHelper syncHelper, FullStack entity, FullStack response) { + + } + + @Override public void updateOnServer(ServerAdapter serverAdapter, long accountId, IResponseCallback<FullStack> callback, FullStack entity) { } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/providers/UserDataProvider.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/providers/UserDataProvider.java index 462f43df3..f0ba9a976 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/providers/UserDataProvider.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/providers/UserDataProvider.java @@ -1,5 +1,6 @@ package it.niedermann.nextcloud.deck.persistence.sync.helpers.providers; +import java.util.Date; import java.util.List; import it.niedermann.nextcloud.deck.api.IResponseCallback; @@ -26,7 +27,7 @@ public class UserDataProvider implements IDataProvider<User> { } @Override - public void getAllFromServer(ServerAdapter serverAdapter, long accountId, IResponseCallback<List<User>> responder) { + public void getAllFromServer(ServerAdapter serverAdapter, long accountId, IResponseCallback<List<User>> responder, Date lastSync) { responder.onResponse(users); } @@ -42,7 +43,7 @@ public class UserDataProvider implements IDataProvider<User> { @Override public void updateInDB(DataBaseAdapter dataBaseAdapter, long accountId, User entity) { - dataBaseAdapter.updateUser(accountId, entity); + dataBaseAdapter.updateUser(accountId, entity, false); } @Override @@ -67,6 +68,16 @@ public class UserDataProvider implements IDataProvider<User> { } @Override + public List<User> getAllFromDB(DataBaseAdapter dataBaseAdapter, long accountId, Date lastSync) { + return null; + } + + @Override + public void goDeeperForUpSync(SyncHelper syncHelper, User entity, User response) { + + } + + @Override public void updateOnServer(ServerAdapter serverAdapter, long accountId, IResponseCallback<User> callback, User entity) { } |