diff options
author | desperateCoder <echotodevnull@gmail.com> | 2021-04-09 19:57:31 +0300 |
---|---|---|
committer | Niedermann IT-Dienstleistungen <stefan-niedermann@users.noreply.github.com> | 2021-04-10 14:38:50 +0300 |
commit | e2ed2ebb2c669bd7ce1001d3c1a3ba1f055eb656 (patch) | |
tree | cbd7755ebeb43d6178620bf117e482d1b10e7034 /app/src/main/java | |
parent | e9b9c8f6358ee790dc80f448cce143741df164e9 (diff) |
#690 in-app upcoming cards: added method to get the needed data
Diffstat (limited to 'app/src/main/java')
2 files changed, 29 insertions, 3 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 ca2b90ec2..8b852d3e2 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 @@ -71,6 +71,7 @@ import it.niedermann.nextcloud.deck.model.widget.filter.dto.FilterWidgetCard; import it.niedermann.nextcloud.deck.model.widget.singlecard.SingleCardWidgetModel; import it.niedermann.nextcloud.deck.persistence.sync.adapters.db.util.LiveDataHelper; import it.niedermann.nextcloud.deck.persistence.sync.adapters.db.util.WrappedLiveData; +import it.niedermann.nextcloud.deck.ui.upcomingcards.UpcomingCardsAdapterItem; import it.niedermann.nextcloud.deck.ui.widget.singlecard.SingleCardWidget; import static androidx.lifecycle.Transformations.distinctUntilChanged; @@ -1252,11 +1253,26 @@ public class DataBaseAdapter { }).start(); } - public List<FilterWidgetCard> getCardsForFilterWidget(Integer filterWidgetId) { - return getCardsForFilterWidget(getFilterWidgetByIdDirectly(filterWidgetId)); + public LiveData<List<UpcomingCardsAdapterItem>> getCardsForUpcomingCard() { + LiveData<List<FullCard>> upcomingCardsLiveData = db.getCardDao().getUpcomingCards(); + return LiveDataHelper.postCustomValue(upcomingCardsLiveData, cardsResult -> { + List<UpcomingCardsAdapterItem> result = new ArrayList<>(cardsResult.size()); + Map<Long, Account> accountCache = new HashMap<>(); + for (FullCard fullCard : cardsResult) { + Board board = db.getBoardDao().getBoardByLocalCardIdDirectly(fullCard.getLocalId()); + Account account = accountCache.get(fullCard.getAccountId()); + if (account == null) { + account = db.getAccountDao().getAccountByIdDirectly(fullCard.getAccountId()); + accountCache.put(fullCard.getAccountId(), account); + } + result.add(new UpcomingCardsAdapterItem(fullCard, account, board.getLocalId(), board.getId(), board.isPermissionEdit())); + } + return result; + }); } - public List<FilterWidgetCard> getCardsForFilterWidget(@NonNull FilterWidget filterWidget) { + public List<FilterWidgetCard> getCardsForFilterWidget(@NonNull Integer filterWidgetId) { + FilterWidget filterWidget = getFilterWidgetByIdDirectly(filterWidgetId); FilterInformation filter = new FilterInformation(); Set<FullCard> cardsResult = new HashSet<>(); if (filterWidget.getDueType() != null) { 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 51fbc0d89..02073c23a 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 @@ -16,6 +16,16 @@ import it.niedermann.nextcloud.deck.model.full.FullCardWithProjects; @Dao public interface CardDao extends GenericDao<Card> { + @Query("SELECT c.* FROM card c " + + "join stack s on s.localId = c.stackId " + + "join board b on b.localId = s.boardId " + + "WHERE b.archived = 0 and c.archived = 0 and b.status <> 3 and s.status <> 3 and c.status <> 3 " + + "and (c.dueDate is not null or exists(select 1 from AccessControl ac where ac.boardId = b.localId and ac.status <> 3))" + + "and (exists(select 1 from JoinCardWithUser j where j.cardId = c.localId and j.userId in (select u.localId from user u where u.uid in (select uid from Account))) " + + "or not exists(select 1 from AccessControl ac where ac.boardId = b.localId and ac.status <> 3))" + + "ORDER BY c.dueDate asc") + LiveData<List<FullCard>> getUpcomingCards(); + @Query("SELECT * FROM card WHERE stackId = :localStackId order by `order`, createdAt asc") LiveData<List<Card>> getCardsForStack(final long localStackId); |