diff options
author | desperateCoder <echotodevnull@gmail.com> | 2019-03-22 22:29:17 +0300 |
---|---|---|
committer | desperateCoder <echotodevnull@gmail.com> | 2019-03-22 22:30:30 +0300 |
commit | 4595babf7383ce0e932e3ec05f9ef56a90abc48e (patch) | |
tree | 1a23d2219afd63ab676367f26e466f81a99d94c7 /app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync | |
parent | 659e15921a5d680d57915714be6b8e656979124e (diff) |
create stacks working.
Diffstat (limited to 'app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync')
3 files changed, 30 insertions, 14 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 b45a99eeb..a75f3c417 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 @@ -32,6 +32,7 @@ import it.niedermann.nextcloud.deck.persistence.sync.adapters.db.util.WrappedLiv import it.niedermann.nextcloud.deck.persistence.sync.helpers.DataPropagationHelper; import it.niedermann.nextcloud.deck.persistence.sync.helpers.SyncHelper; import it.niedermann.nextcloud.deck.persistence.sync.helpers.providers.BoardDataProvider; +import it.niedermann.nextcloud.deck.persistence.sync.helpers.providers.StackDataProvider; import it.niedermann.nextcloud.deck.persistence.sync.util.DateUtil; public class SyncManager { @@ -156,19 +157,22 @@ public class SyncManager { } public void createBoard(long accountId, Board board) { - FullBoard fullBoard = new FullBoard(); - board.setOwnerId(1); // FIXME - fullBoard.setBoard(board); - fullBoard.setAccountId(accountId); - Account dummyAccount = new Account(accountId); - doAsync(() -> - new DataPropagationHelper(serverAdapter, dataBaseAdapter).createEntity(new BoardDataProvider() ,fullBoard, new IResponseCallback<FullBoard>(dummyAccount) { + doAsync(() -> { + Account account = dataBaseAdapter.getAccountByIdDirectly(accountId); + User owner = dataBaseAdapter.getUserByUidDirectly(accountId, account.getUserName()); + FullBoard fullBoard = new FullBoard(); + board.setOwnerId(owner.getLocalId()); + fullBoard.setOwner(owner); + fullBoard.setBoard(board); + board.setAccountId(accountId); + fullBoard.setAccountId(accountId); + new DataPropagationHelper(serverAdapter, dataBaseAdapter).createEntity(new BoardDataProvider() ,fullBoard, new IResponseCallback<FullBoard>(account) { @Override public void onResponse(FullBoard response) { DeckLog.log(response.toString()); } - }) - ); + }); + }); } public void deleteBoard(Board board) { @@ -206,9 +210,20 @@ public class SyncManager { } public void createStack(long accountId, Stack stack) { - //TODO: Tell the server doAsync(() -> { - dataBaseAdapter.createStack(accountId, stack); + Account account = dataBaseAdapter.getAccountByIdDirectly(accountId); + FullBoard board = dataBaseAdapter.getFullBoardByRemoteIdDirectly(accountId, stack.getBoardId()); + FullStack fullStack = new FullStack(); + stack.setAccountId(accountId); + stack.setBoardId(board.getLocalId()); + fullStack.setStack(stack); + fullStack.setAccountId(accountId); + new DataPropagationHelper(serverAdapter, dataBaseAdapter).createEntity(new StackDataProvider(null, board) ,fullStack, new IResponseCallback<FullStack>(account) { + @Override + public void onResponse(FullStack response) { + DeckLog.log(response.toString()); + } + }); }); } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/ServerAdapter.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/ServerAdapter.java index 2ae29112c..5cbfdcbec 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/ServerAdapter.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/ServerAdapter.java @@ -124,9 +124,9 @@ public class ServerAdapter { RequestHelper.request(sourceActivity, provider, () -> provider.getAPI().getStack(boardId, stackId, getLastSyncDateFormatted()), responseCallback); } - public void createStack(Stack stack) { + public void createStack(Stack stack, IResponseCallback<FullStack> responseCallback) { ensureInternetConnection(); - + RequestHelper.request(sourceActivity, provider, () -> provider.getAPI().createStack(stack.getBoardId(), stack), responseCallback); } public void deleteStack(Stack stack) { 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 c3d80c1b9..51f0f2c21 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 @@ -57,7 +57,8 @@ public class StackDataProvider extends AbstractSyncDataProvider<FullStack> { @Override public void createOnServer(ServerAdapter serverAdapter, long accountId, IResponseCallback<FullStack> responder, FullStack entity) { - // TODO: implement + entity.getStack().setBoardId(board.getId()); + serverAdapter.createStack(entity.getStack(), responder); } @Override |