diff options
author | desperateCoder <echotodevnull@gmail.com> | 2020-10-04 11:28:06 +0300 |
---|---|---|
committer | desperateCoder <echotodevnull@gmail.com> | 2020-10-04 11:28:29 +0300 |
commit | 16a0a85c60d72cb30721acd3576153000c60997e (patch) | |
tree | 3319a797c6371ed2dc676f52baa8229f93c575e3 /app/src/main/java/it/niedermann/nextcloud/deck/persistence | |
parent | b9b536011c648b841fa6f3928e15b7764e84b2d8 (diff) |
#663 implemented filtered archiving
Diffstat (limited to 'app/src/main/java/it/niedermann/nextcloud/deck/persistence')
4 files changed, 39 insertions, 25 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 fdcddc2da..f7dc2493e 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 @@ -644,7 +644,7 @@ public class SyncManager { stack.setBoardId(newBoardId); long createdStackId = dataBaseAdapter.createStack(targetAccountId, stack); if (cloneCards) { - List<FullCard> oldCards = dataBaseAdapter.getFullCardsForStackDirectly(originAccountId, oldStackId); + List<FullCard> oldCards = dataBaseAdapter.getFullCardsForStackDirectly(originAccountId, oldStackId, null); for (FullCard oldCard : oldCards) { Card newCard = oldCard.getCard(); newCard.setId(null); @@ -1131,7 +1131,6 @@ public class SyncManager { return liveData; } - // TODO use filterInformation https://github.com/stefan-niedermann/nextcloud-deck/issues/663 @AnyThread public WrappedLiveData<Void> archiveCardsInStack(long accountId, long stackLocalId, @NonNull FilterInformation filterInformation) { WrappedLiveData<Void> liveData = new WrappedLiveData<>(); @@ -1139,7 +1138,7 @@ public class SyncManager { Account account = dataBaseAdapter.getAccountByIdDirectly(accountId); FullStack stack = dataBaseAdapter.getFullStackByLocalIdDirectly(stackLocalId); Board board = dataBaseAdapter.getBoardByLocalIdDirectly(stack.getStack().getBoardId()); - List<FullCard> cards = dataBaseAdapter.getFullCardsForStackDirectly(accountId, stackLocalId); + List<FullCard> cards = dataBaseAdapter.getFullCardsForStackDirectly(accountId, stackLocalId, filterInformation); if (cards.size() > 0) { CountDownLatch latch = new CountDownLatch(cards.size()); for (FullCard card : cards) { @@ -1660,7 +1659,7 @@ public class SyncManager { public void reorder(long accountId, @NonNull FullCard movedCard, long newStackId, int newIndex) { doAsync(() -> { // read cards of new stack - List<FullCard> cardsOfNewStack = dataBaseAdapter.getFullCardsForStackDirectly(accountId, newStackId); + List<FullCard> cardsOfNewStack = dataBaseAdapter.getFullCardsForStackDirectly(accountId, newStackId, null); int newOrder = newIndex; if (cardsOfNewStack.size() > newIndex) { newOrder = cardsOfNewStack.get(newIndex).getCard().getOrder(); 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 549e1a0ae..17ab2a419 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 @@ -187,12 +187,39 @@ public class DataBaseAdapter { if (filter == null) { return LiveDataHelper.interceptLiveData(db.getCardDao().getFullCardsForStack(accountId, localStackId), this::filterRelationsForCard); } + return LiveDataHelper.interceptLiveData(db.getCardDao().getFilteredFullCardsForStack(getQueryForFilter(filter, accountId, localStackId)), this::filterRelationsForCard); + } + + private void fillSqlWithListValues(StringBuilder query, List<Object> args, @NonNull List<? extends IRemoteEntity> entities) { + for (int i = 0; i < entities.size(); i++) { + if (i > 0) { + query.append(", "); + } + query.append("?"); + args.add(entities.get(i).getLocalId()); + } + } + + @WorkerThread + public List<FullCard> getFullCardsForStackDirectly(long accountId, long localStackId, FilterInformation filter) { + if (filter == null) { + return db.getCardDao().getFullCardsForStackDirectly(accountId, localStackId); + } + List<Object> args = new ArrayList<>(); + args.add(accountId); + args.add(localStackId); + + return db.getCardDao().getFilteredFullCardsForStackDirectly(getQueryForFilter(filter, accountId, localStackId)); + } + + @AnyThread + private SimpleSQLiteQuery getQueryForFilter(FilterInformation filter, long accountId, long localStackId) { List<Object> args = new ArrayList<>(); - StringBuilder query = new StringBuilder("SELECT * FROM card c " + - "WHERE accountId = ? AND stackId = ? "); args.add(accountId); args.add(localStackId); + StringBuilder query = new StringBuilder("SELECT * FROM card c " + + "WHERE accountId = ? AND stackId = ? "); if (!filter.getLabels().isEmpty()) { query.append("and (exists(select 1 from joincardwithlabel j where c.localId = cardId and labelId in ("); @@ -242,23 +269,7 @@ public class DataBaseAdapter { } } query.append(" and status<>3 order by `order`, createdAt asc;"); - return LiveDataHelper.interceptLiveData(db.getCardDao().getFilteredFullCardsForStack(new SimpleSQLiteQuery(query.toString(), args.toArray())), this::filterRelationsForCard); - - } - - private void fillSqlWithListValues(StringBuilder query, List<Object> args, @NonNull List<? extends IRemoteEntity> entities) { - for (int i = 0; i < entities.size(); i++) { - if (i > 0) { - query.append(", "); - } - query.append("?"); - args.add(entities.get(i).getLocalId()); - } - } - - @WorkerThread - public List<FullCard> getFullCardsForStackDirectly(long accountId, long localStackId) { - return db.getCardDao().getFullCardsForStackDirectly(accountId, localStackId); + return new SimpleSQLiteQuery(query.toString(), args.toArray()); } @WorkerThread 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 d77a3b6b4..82bdf1b8d 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 @@ -37,11 +37,15 @@ public interface CardDao extends GenericDao<Card> { @Query("SELECT * FROM card WHERE accountId = :accountId AND archived = 0 AND stackId = :localStackId and status<>3 order by `order`, createdAt asc") LiveData<List<FullCard>> getFullCardsForStack(final long accountId, final long localStackId); - @Transaction // v not deleted! + @Transaction @RawQuery(observedEntities = Card.class) LiveData<List<FullCard>> getFilteredFullCardsForStack(SupportSQLiteQuery query); @Transaction + @RawQuery(observedEntities = Card.class) + List<FullCard> getFilteredFullCardsForStackDirectly(SupportSQLiteQuery query); + + @Transaction @Query("SELECT * FROM card WHERE accountId = :accountId AND stackId = :localStackId order by `order`, createdAt asc") List<FullCard> getFullCardsForStackDirectly(final long accountId, final long localStackId); 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 00c2f8bd6..376948d54 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 @@ -308,7 +308,7 @@ public class CardDataProvider extends AbstractSyncDataProvider<FullCard> { @Override public void handleDeletes(ServerAdapter serverAdapter, DataBaseAdapter dataBaseAdapter, long accountId, List<FullCard> entitiesFromServer) { - List<FullCard> localCards = dataBaseAdapter.getFullCardsForStackDirectly(accountId, stack.getLocalId()); + List<FullCard> localCards = dataBaseAdapter.getFullCardsForStackDirectly(accountId, stack.getLocalId(), null); List<FullCard> delta = findDelta(entitiesFromServer, localCards); for (FullCard cardToDelete : delta) { if (cardToDelete.getId() == null) { |