diff options
author | desperateCoder <echotodevnull@gmail.com> | 2019-06-17 20:03:57 +0300 |
---|---|---|
committer | desperateCoder <echotodevnull@gmail.com> | 2019-06-17 20:03:57 +0300 |
commit | 8217c5ab59bc33a6eeba7c5b68789d8d6d413835 (patch) | |
tree | 7d04fcd1f80c46417cfd6a01a1e4bfbe3f451120 /app/src/main/java/it | |
parent | 6df11e839fa51027c959c14f52ddfe51523b28d9 (diff) |
#94 WIP...
Diffstat (limited to 'app/src/main/java/it')
8 files changed, 153 insertions, 19 deletions
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/api/DeckAPI.java b/app/src/main/java/it/niedermann/nextcloud/deck/api/DeckAPI.java index f512e7f7b..1148457f9 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/api/DeckAPI.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/api/DeckAPI.java @@ -12,6 +12,7 @@ import it.niedermann.nextcloud.deck.model.Stack; 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.propagation.CardUpdate; import retrofit2.http.Body; import retrofit2.http.DELETE; import retrofit2.http.Field; @@ -72,7 +73,7 @@ public interface DeckAPI { Observable<FullCard> createCard(@Path("boardId") long boardId, @Path("stackId") long stackId, @Body Card card); @PUT("boards/{boardId}/stacks/{stackId}/cards/{cardId}") - Observable<FullCard> updateCard(@Path("boardId") long boardId, @Path("stackId") long stackId, @Path("cardId") long cardId, @Body Card card); + Observable<FullCard> updateCard(@Path("boardId") long boardId, @Path("stackId") long stackId, @Path("cardId") long cardId, @Body CardUpdate card); @FormUrlEncoded @PUT("boards/{boardId}/stacks/{stackId}/cards/{cardId}/assignLabel") diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/model/propagation/CardUpdate.java b/app/src/main/java/it/niedermann/nextcloud/deck/model/propagation/CardUpdate.java new file mode 100644 index 000000000..1f83d2718 --- /dev/null +++ b/app/src/main/java/it/niedermann/nextcloud/deck/model/propagation/CardUpdate.java @@ -0,0 +1,39 @@ +package it.niedermann.nextcloud.deck.model.propagation; + +import it.niedermann.nextcloud.deck.model.Card; +import it.niedermann.nextcloud.deck.model.User; +import it.niedermann.nextcloud.deck.model.full.FullCard; + +public class CardUpdate extends Card { + + User owner; + + public CardUpdate(FullCard card) { + super(); + setTitle(card.getCard().getTitle()); + setDescription(card.getCard().getDescription()); + setStackId(card.getCard().getStackId()); + setType(card.getCard().getType()); + setCreatedAt(card.getCard().getCreatedAt()); + setDeletedAt(card.getCard().getDeletedAt()); + setAttachmentCount(card.getCard().getAttachmentCount()); + setUserId(card.getCard().getUserId()); + setOrder(card.getCard().getOrder()); + setArchived(card.getCard().isArchived()); + setDueDate(card.getCard().getDueDate()); + setNotified(card.getCard().isNotified()); + setOverdue(card.getCard().getOverdue()); + setCommentsUnread(card.getCard().getCommentsUnread()); + setAccountId(card.getAccountId()); + setId(card.getId()); + setLocalId(card.getLocalId()); + } + + public User getOwner() { + return owner; + } + + public void setOwner(User owner) { + this.owner = owner; + } +} 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 698b432cc..65ecd0ea5 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 @@ -301,19 +301,58 @@ public class SyncManager { return liveData; } - public void deleteCard(Card card) { - //TODO: Tell the server - dataBaseAdapter.deleteCard(card, true); + public MutableLiveData<FullCard> deleteCard(Card card) { + MutableLiveData<FullCard> liveData = new MutableLiveData<>(); + doAsync(() -> { + FullCard fullCard = dataBaseAdapter.getFullCardByLocalIdDirectly(card.getAccountId(), card.getLocalId()); + if (fullCard== null) { + throw new IllegalArgumentException("card to update does not exist."); + } + Account account = dataBaseAdapter.getAccountByIdDirectly(card.getAccountId()); + FullStack stack = dataBaseAdapter.getFullStackByLocalIdDirectly(card.getStackId()); + Board board = dataBaseAdapter.getBoardByLocalIdDirectly(stack.getStack().getBoardId()); + new DataPropagationHelper(serverAdapter, dataBaseAdapter).deleteEntity(new CardDataProvider(null, board, stack) ,fullCard, new IResponseCallback<FullCard>(account) { + @Override + public void onResponse(FullCard response) { + liveData.postValue(response); + } + }); + }); + return liveData; + } + public MutableLiveData<FullCard> archiveCard(Card card) { + card.setArchived(true); + return updateCard(card); } - public void updateCard(Card card) { - //TODO: Tell the server - doAsync(()->{ - Card existingCard = dataBaseAdapter.getCardByRemoteIdDirectly(card.getAccountId(), card.getId()); - if (!existingCard.equals(card)){ - dataBaseAdapter.updateCard(card, true); + public MutableLiveData<FullCard> updateCard(Card card) { + MutableLiveData<FullCard> liveData = new MutableLiveData<>(); + doAsync(() -> { + FullCard fullCard = dataBaseAdapter.getFullCardByLocalIdDirectly(card.getAccountId(), card.getLocalId()); + if (fullCard== null) { + throw new IllegalArgumentException("card to update does not exist."); } + Account account = dataBaseAdapter.getAccountByIdDirectly(card.getAccountId()); + FullStack stack = dataBaseAdapter.getFullStackByLocalIdDirectly(card.getStackId()); + Board board = dataBaseAdapter.getBoardByLocalIdDirectly(stack.getStack().getBoardId()); + fullCard.setCard(card); + new DataPropagationHelper(serverAdapter, dataBaseAdapter).updateEntity(new CardDataProvider(null, board, stack) ,fullCard, new IResponseCallback<FullCard>(account) { + @Override + public void onResponse(FullCard response) { + liveData.postValue(response); + } + }); }); + return liveData; + + + //TODO: Tell the server +// doAsync(()->{ +// Card existingCard = dataBaseAdapter.getCardByRemoteIdDirectly(card.getAccountId(), card.getId()); +// if (!existingCard.equals(card)){ +// dataBaseAdapter.updateCard(card, true); +// } +// }); } public long createLabel(long accountId, Label label) { 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 5a272c8e9..a3b92b1b8 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 @@ -29,6 +29,7 @@ import it.niedermann.nextcloud.deck.model.Stack; 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.propagation.CardUpdate; import it.niedermann.nextcloud.deck.util.DateUtil; public class ServerAdapter { @@ -158,7 +159,7 @@ public class ServerAdapter { RequestHelper.request(sourceActivity, provider, () -> provider.getAPI().deleteCard(boardId, stackId, card.getId()), responseCallback); } - public void updateCard(long boardId, long stackId, Card card, IResponseCallback<FullCard> responseCallback) { + public void updateCard(long boardId, long stackId, CardUpdate card, IResponseCallback<FullCard> responseCallback) { ensureInternetConnection(); RequestHelper.request(sourceActivity, provider, () -> provider.getAPI().updateCard(boardId, stackId, card.getId(), card), responseCallback); } 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 a05e76c15..8714966a1 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 @@ -12,14 +12,15 @@ import it.niedermann.nextcloud.deck.model.Label; import it.niedermann.nextcloud.deck.model.User; import it.niedermann.nextcloud.deck.model.full.FullCard; import it.niedermann.nextcloud.deck.model.full.FullStack; +import it.niedermann.nextcloud.deck.model.propagation.CardUpdate; import it.niedermann.nextcloud.deck.persistence.sync.adapters.ServerAdapter; import it.niedermann.nextcloud.deck.persistence.sync.adapters.db.DataBaseAdapter; import it.niedermann.nextcloud.deck.persistence.sync.helpers.SyncHelper; public class CardDataProvider extends AbstractSyncDataProvider<FullCard> { - private Board board; - private FullStack stack; + protected Board board; + protected FullStack stack; public CardDataProvider(AbstractSyncDataProvider<?> parent, Board board, FullStack stack) { super(parent); @@ -63,7 +64,13 @@ public class CardDataProvider extends AbstractSyncDataProvider<FullCard> { return dataBaseAdapter.createCard(accountId, entity.getCard()); } - private void fixRelations(DataBaseAdapter dataBaseAdapter, long accountId, FullCard entity) { + protected CardUpdate toCardUpdate(FullCard card){ + CardUpdate c = new CardUpdate(card); + c.setOwner(card.getOwner().get(0)); + return c; + } + + protected void fixRelations(DataBaseAdapter dataBaseAdapter, long accountId, FullCard entity) { entity.getCard().setStackId(stack.getLocalId()); if (entity.getOwner() != null && !entity.getOwner().isEmpty()){ User user = entity.getOwner().get(0); @@ -117,7 +124,7 @@ public class CardDataProvider extends AbstractSyncDataProvider<FullCard> { @Override public void updateOnServer(ServerAdapter serverAdapter, long accountId, IResponseCallback<FullCard> callback, FullCard entity) { - serverAdapter.updateCard(board.getId(), stack.getId(), entity.getCard(), callback); + serverAdapter.updateCard(board.getId(), stack.getId(), toCardUpdate(entity), callback); } @Override diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/providers/CardPropagationDataProvider.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/providers/CardPropagationDataProvider.java new file mode 100644 index 000000000..26e489ea7 --- /dev/null +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/helpers/providers/CardPropagationDataProvider.java @@ -0,0 +1,37 @@ +package it.niedermann.nextcloud.deck.persistence.sync.helpers.providers; + +import it.niedermann.nextcloud.deck.api.IResponseCallback; +import it.niedermann.nextcloud.deck.model.Board; +import it.niedermann.nextcloud.deck.model.full.FullCard; +import it.niedermann.nextcloud.deck.model.full.FullStack; +import it.niedermann.nextcloud.deck.persistence.sync.adapters.ServerAdapter; +import it.niedermann.nextcloud.deck.persistence.sync.adapters.db.DataBaseAdapter; + +public class CardPropagationDataProvider extends CardDataProvider { + + public CardPropagationDataProvider(AbstractSyncDataProvider<?> parent, Board board, FullStack stack) { + super(parent, board, stack); + } + + + @Override + public void updateInDB(DataBaseAdapter dataBaseAdapter, long accountId, FullCard entity) { + fixRelations(dataBaseAdapter, accountId, entity); + dataBaseAdapter.updateCard(entity.getCard(), true); + } + + @Override + public void updateOnServer(ServerAdapter serverAdapter, long accountId, IResponseCallback<FullCard> callback, FullCard entity) { + serverAdapter.updateCard(board.getId(), stack.getId(), toCardUpdate(entity), callback); + } + + @Override + public void deleteInDB(DataBaseAdapter dataBaseAdapter, long accountId, FullCard fullCard) { + dataBaseAdapter.deleteCard(fullCard.getCard(), true); + } + + @Override + public void deleteOnServer(ServerAdapter serverAdapter, long accountId, IResponseCallback<Void> callback, FullCard entity) { + serverAdapter.deleteCard(board.getId(), stack.getId(), entity.getCard(), callback); + } +} diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/CardAdapter.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/CardAdapter.java index 23bc409ee..ebc003916 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/CardAdapter.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/card/CardAdapter.java @@ -42,6 +42,7 @@ import it.niedermann.nextcloud.deck.model.Card; import it.niedermann.nextcloud.deck.model.Label; import it.niedermann.nextcloud.deck.model.User; import it.niedermann.nextcloud.deck.model.full.FullCard; +import it.niedermann.nextcloud.deck.persistence.sync.SyncManager; import it.niedermann.nextcloud.deck.ui.EditActivity; import it.niedermann.nextcloud.deck.ui.helper.dnd.DraggedCardLocalState; import it.niedermann.nextcloud.deck.util.ColorUtil; @@ -64,10 +65,12 @@ public class CardAdapter extends RecyclerView.Adapter<CardAdapter.CardViewHolder private Context context; private List<FullCard> cardList = new LinkedList<>(); private SingleSignOnAccount account; + private SyncManager syncManager; private long boardId; - public CardAdapter(long boardId) { + public CardAdapter(long boardId, SyncManager syncManager) { this.boardId = boardId; + this.syncManager = syncManager; } @NonNull @@ -314,18 +317,21 @@ public class CardAdapter extends RecyclerView.Adapter<CardAdapter.CardViewHolder } private boolean optionsItemSelected(MenuItem item, FullCard card) { - Toast.makeText(context, "Not implemented yet", Toast.LENGTH_SHORT).show(); switch (item.getItemId()) { case R.id.action_card_assign: { + Toast.makeText(context, "Not implemented yet", Toast.LENGTH_SHORT).show(); return true; } case R.id.action_card_unassign: { + Toast.makeText(context, "Not implemented yet", Toast.LENGTH_SHORT).show(); return true; } case R.id.action_card_archive: { + syncManager.archiveCard(card.getCard()); return true; } case R.id.action_card_delete: { + syncManager.deleteCard(card.getCard()); return true; } } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/stack/StackFragment.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/stack/StackFragment.java index 6aa6ae12e..01da756da 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/stack/StackFragment.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/stack/StackFragment.java @@ -72,10 +72,14 @@ public class StackFragment extends Fragment { stackId = getArguments().getLong(KEY_STACK_ID); account = (Account) getArguments().getSerializable(KEY_ACCOUNT); + syncManager = new SyncManager(getActivity()); initRecyclerView(); if (getActivity() != null) { - syncManager = new SyncManager(getActivity()); + if (syncManager == null){ + syncManager = new SyncManager(getActivity()); + initRecyclerView(); + } swipeRefreshLayout.setOnRefreshListener(() -> { syncManager.synchronize(new IResponseCallback<Boolean>(account) { @@ -117,7 +121,7 @@ public class StackFragment extends Fragment { } private void initRecyclerView() { - adapter = new CardAdapter(boardId); + adapter = new CardAdapter(boardId, syncManager); recyclerView.setAdapter(adapter); recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); // ItemTouchHelper touchHelper = new CardItemTouchHelper(adapter); |