diff options
author | desperateCoder <echotodevnull@gmail.com> | 2021-04-09 21:16:10 +0300 |
---|---|---|
committer | Niedermann IT-Dienstleistungen <stefan-niedermann@users.noreply.github.com> | 2021-04-10 14:38:50 +0300 |
commit | b630a63f0133223c8d5d9266224f4ffae5b64ec0 (patch) | |
tree | 5f451980979f63e39c09f695c201cf36fc4724a2 /app/src/main/java/it/niedermann/nextcloud | |
parent | ec169382d41f5c12f62dc33e6469b6e26830c7da (diff) |
#690 use same logic for widgets
Diffstat (limited to 'app/src/main/java/it/niedermann/nextcloud')
2 files changed, 31 insertions, 18 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 59fde4a10..49face983 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 @@ -14,6 +14,8 @@ import androidx.annotation.WorkerThread; import androidx.lifecycle.LiveData; import androidx.sqlite.db.SimpleSQLiteQuery; +import org.jetbrains.annotations.NotNull; + import java.time.Instant; import java.util.ArrayList; import java.util.Collection; @@ -1255,21 +1257,28 @@ public class DataBaseAdapter { public LiveData<List<UpcomingCardsAdapterItem>> getCardsForUpcomingCard() { LiveData<List<FullCard>> upcomingCardsLiveData = db.getCardDao().getUpcomingCards(); - return LiveDataHelper.postCustomValue(upcomingCardsLiveData, cardsResult -> { - filterRelationsForCard(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 LiveDataHelper.postCustomValue(upcomingCardsLiveData, this::cardResultsToUpcomingCardsAdapterItems); + } + + public List<UpcomingCardsAdapterItem> getCardsForUpcomingCardForWidget() { + return cardResultsToUpcomingCardsAdapterItems(db.getCardDao().getUpcomingCardsDirectly()); + } + + @NotNull + private List<UpcomingCardsAdapterItem> cardResultsToUpcomingCardsAdapterItems(List<FullCard> cardsResult) { + filterRelationsForCard(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); } - return result; - }); + result.add(new UpcomingCardsAdapterItem(fullCard, account, board.getLocalId(), board.getId(), board.isPermissionEdit())); + } + return result; } public List<FilterWidgetCard> getCardsForFilterWidget(@NonNull Integer filterWidgetId) { 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 9a7b88499..b475e66e9 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,16 +16,14 @@ import it.niedermann.nextcloud.deck.model.full.FullCardWithProjects; @Dao public interface CardDao extends GenericDao<Card> { - @Transaction - @Query("SELECT c.* FROM card c " + + String QUERY_UPCOMING_CARDS = "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 (not exists(select 1 from AccessControl ac where ac.boardId = b.localId and ac.status <> 3) " + "or 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 a.userName from Account a))))" + - "ORDER BY c.dueDate asc") - LiveData<List<FullCard>> getUpcomingCards(); + "ORDER BY c.dueDate asc"; @Query("SELECT * FROM card WHERE stackId = :localStackId order by `order`, createdAt asc") LiveData<List<Card>> getCardsForStack(final long localStackId); @@ -108,5 +106,11 @@ public interface CardDao extends GenericDao<Card> { "and archived = 0") List<FullCard> getFullCardsForNonSharedBoardsWithDueDateForUpcomingCardsWidgetDirectly(List<Long> accountIds); + @Transaction + @Query(QUERY_UPCOMING_CARDS) + LiveData<List<FullCard>> getUpcomingCards(); + @Transaction + @Query(QUERY_UPCOMING_CARDS) + List<FullCard> getUpcomingCardsDirectly(); }
\ No newline at end of file |