diff options
author | desperateCoder <echotodevnull@gmail.com> | 2020-12-13 16:58:03 +0300 |
---|---|---|
committer | desperateCoder <echotodevnull@gmail.com> | 2020-12-13 16:58:03 +0300 |
commit | 58ac12886cb5b53adacc08da9ccc833f232c6518 (patch) | |
tree | c1e5c4da1aa637cb35c397f453be557535341f0b /app | |
parent | 6452d9d1c1dda04e67d2e2e490911a35b7c6b96f (diff) |
#597 filter widget: actually select the cards by filter information WIP
Diffstat (limited to 'app')
8 files changed, 82 insertions, 18 deletions
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/model/enums/EDueType.java b/app/src/main/java/it/niedermann/nextcloud/deck/model/enums/EDueType.java index 5241ae763..52895a376 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/model/enums/EDueType.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/model/enums/EDueType.java @@ -8,17 +8,33 @@ import androidx.annotation.StringRes; import it.niedermann.nextcloud.deck.R; public enum EDueType { - NO_FILTER(R.string.filter_no_filter), - OVERDUE(R.string.filter_overdue), - TODAY(R.string.filter_today), - WEEK(R.string.filter_week), - MONTH(R.string.filter_month), - NO_DUE(R.string.filter_no_due); + NO_FILTER(1, R.string.filter_no_filter), + OVERDUE(2, R.string.filter_overdue), + TODAY(3, R.string.filter_today), + WEEK(4, R.string.filter_week), + MONTH(5, R.string.filter_month), + NO_DUE(6, R.string.filter_no_due); private int value; + private int id; - EDueType(@StringRes int value) { + EDueType(@NonNull int id, @StringRes int value) { this.value = value; + this.id = id; + } + + public int getId() { + return id; + } + + + public static EDueType findById(int id) { + for (EDueType s : EDueType.values()) { + if (s.getId() == id) { + return s; + } + } + throw new IllegalArgumentException("unknown EDueType key"); } @NonNull diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/model/widget/filter/FilterWidgetAccount.java b/app/src/main/java/it/niedermann/nextcloud/deck/model/widget/filter/FilterWidgetAccount.java index 8ebdc65a5..c309213d2 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/model/widget/filter/FilterWidgetAccount.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/model/widget/filter/FilterWidgetAccount.java @@ -35,6 +35,7 @@ public class FilterWidgetAccount { private Long id; private Long filterWidgetId; private Long accountId; + private boolean includeNoUser = true; @Ignore private List<FilterWidgetBoard> boards = new ArrayList<>(); @@ -82,6 +83,14 @@ public class FilterWidgetAccount { this.accountId = accountId; } + public boolean isIncludeNoUser() { + return includeNoUser; + } + + public void setIncludeNoUser(boolean includeNoUser) { + this.includeNoUser = includeNoUser; + } + @Override public boolean equals(Object o) { if (this == o) return true; @@ -89,10 +98,14 @@ public class FilterWidgetAccount { FilterWidgetAccount that = (FilterWidgetAccount) o; + if (includeNoUser != that.includeNoUser) return false; if (id != null ? !id.equals(that.id) : that.id != null) return false; if (filterWidgetId != null ? !filterWidgetId.equals(that.filterWidgetId) : that.filterWidgetId != null) return false; - return accountId != null ? accountId.equals(that.accountId) : that.accountId == null; + if (accountId != null ? !accountId.equals(that.accountId) : that.accountId != null) + return false; + if (boards != null ? !boards.equals(that.boards) : that.boards != null) return false; + return users != null ? users.equals(that.users) : that.users == null; } @Override @@ -100,6 +113,9 @@ public class FilterWidgetAccount { int result = id != null ? id.hashCode() : 0; result = 31 * result + (filterWidgetId != null ? filterWidgetId.hashCode() : 0); result = 31 * result + (accountId != null ? accountId.hashCode() : 0); + result = 31 * result + (includeNoUser ? 1 : 0); + result = 31 * result + (boards != null ? boards.hashCode() : 0); + result = 31 * result + (users != null ? users.hashCode() : 0); return result; } } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/model/widget/filter/FilterWidgetBoard.java b/app/src/main/java/it/niedermann/nextcloud/deck/model/widget/filter/FilterWidgetBoard.java index 473d5c486..d2f1d24fe 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/model/widget/filter/FilterWidgetBoard.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/model/widget/filter/FilterWidgetBoard.java @@ -35,6 +35,7 @@ public class FilterWidgetBoard { private Long id; private Long filterAccountId; private Long boardId; + private boolean includeNoLabel = true; @Ignore private List<FilterWidgetStack> stacks = new ArrayList<>(); @@ -82,6 +83,14 @@ public class FilterWidgetBoard { this.boardId = boardId; } + public boolean isIncludeNoLabel() { + return includeNoLabel; + } + + public void setIncludeNoLabel(boolean includeNoLabel) { + this.includeNoLabel = includeNoLabel; + } + @Override public boolean equals(Object o) { if (this == o) return true; @@ -89,10 +98,13 @@ public class FilterWidgetBoard { FilterWidgetBoard that = (FilterWidgetBoard) o; + if (includeNoLabel != that.includeNoLabel) return false; if (id != null ? !id.equals(that.id) : that.id != null) return false; if (filterAccountId != null ? !filterAccountId.equals(that.filterAccountId) : that.filterAccountId != null) return false; - return boardId != null ? boardId.equals(that.boardId) : that.boardId == null; + if (boardId != null ? !boardId.equals(that.boardId) : that.boardId != null) return false; + if (stacks != null ? !stacks.equals(that.stacks) : that.stacks != null) return false; + return labels != null ? labels.equals(that.labels) : that.labels == null; } @Override @@ -100,6 +112,9 @@ public class FilterWidgetBoard { int result = id != null ? id.hashCode() : 0; result = 31 * result + (filterAccountId != null ? filterAccountId.hashCode() : 0); result = 31 * result + (boardId != null ? boardId.hashCode() : 0); + result = 31 * result + (includeNoLabel ? 1 : 0); + result = 31 * result + (stacks != null ? stacks.hashCode() : 0); + result = 31 * result + (labels != null ? labels.hashCode() : 0); return result; } } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/model/widget/filter/FilterWidgetSort.java b/app/src/main/java/it/niedermann/nextcloud/deck/model/widget/filter/FilterWidgetSort.java index 1b032d73e..43fbdfe12 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/model/widget/filter/FilterWidgetSort.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/model/widget/filter/FilterWidgetSort.java @@ -24,7 +24,7 @@ public class FilterWidgetSort { @PrimaryKey(autoGenerate = true) private Long id; private Long filterWidgetId; - private boolean direction; + private boolean direction = true; private int criteria; private int ruleOrder; @@ -44,12 +44,19 @@ public class FilterWidgetSort { this.filterWidgetId = filterWidgetId; } - public boolean isDirection() { + public boolean isDirectionAscending() { return direction; } + public boolean isDirectionDescending() { + return !direction; + } + + public void setDirectionAscending() { + direction = true; + } - public void setDirection(boolean direction) { - this.direction = direction; + public void setDirectionDescending() { + direction = false; } public int getCriteria() { 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 d535929d3..5b0bb298c 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 @@ -1145,18 +1145,22 @@ public class DataBaseAdapter { public List<FilterWidgetCard> getCardsForFilterWidget(Long filterWidgetId) { FilterWidget filterWidget = getFilterWidgetByIdDirectly(filterWidgetId); FilterInformation filter = new FilterInformation(); + List<FullCard> cardsResult = new ArrayList<>(); List<Long> accounts = new ArrayList<>(); List<Long> stacks = new ArrayList<>(); for (FilterWidgetAccount account : filterWidget.getAccounts()) { accounts.add(account.getId()); if (account.getBoards().isEmpty()) { - + filter + cardsResult.addAll(db.getCardDao().getFilteredFullCardsForStackDirectly(getQueryForFilter(filter, accounts, stacks))); } else { } } + if (filterWidget.getDueType()!=null) { + filter.setDueType(EDueType.findById(filterWidget.getDueType())); + } else filter.setDueType(EDueType.NO_FILTER); - List<FullCard> cardsResult = db.getCardDao().getFilteredFullCardsForStackDirectly(getQueryForFilter(filter, accounts, stacks)); filterRelationsForCard(cardsResult); List<FilterWidgetCard> result = new ArrayList<>(cardsResult.size()); diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/DeckDatabase.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/DeckDatabase.java index 764a05948..f77f3ef09 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/DeckDatabase.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/DeckDatabase.java @@ -420,8 +420,8 @@ public abstract class DeckDatabase extends RoomDatabase { @Override public void migrate(SupportSQLiteDatabase database) { database.execSQL("CREATE TABLE `FilterWidget` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `dueType` INTEGER)"); - database.execSQL("CREATE TABLE `FilterWidgetAccount` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `filterWidgetId` INTEGER, `accountId` INTEGER, FOREIGN KEY(`accountId`) REFERENCES `Account`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`filterWidgetId`) REFERENCES `FilterWidget`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )"); - database.execSQL("CREATE TABLE `FilterWidgetBoard` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `filterAccountId` INTEGER, `boardId` INTEGER, FOREIGN KEY(`boardId`) REFERENCES `Board`(`localId`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`filterAccountId`) REFERENCES `FilterWidgetAccount`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )"); + database.execSQL("CREATE TABLE `FilterWidgetAccount` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `filterWidgetId` INTEGER, `accountId` INTEGER, `includeNoUser` INTEGER NOT NULL, FOREIGN KEY(`accountId`) REFERENCES `Account`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`filterWidgetId`) REFERENCES `FilterWidget`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )"); + database.execSQL("CREATE TABLE `FilterWidgetBoard` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `filterAccountId` INTEGER, `boardId` INTEGER, `includeNoLabel` INTEGER NOT NULL, FOREIGN KEY(`boardId`) REFERENCES `Board`(`localId`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`filterAccountId`) REFERENCES `FilterWidgetAccount`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )"); database.execSQL("CREATE TABLE `FilterWidgetLabel` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `filterBoardId` INTEGER, `labelId` INTEGER, FOREIGN KEY(`labelId`) REFERENCES `Label`(`localId`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`filterBoardId`) REFERENCES `FilterWidgetBoard`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )"); database.execSQL("CREATE TABLE `FilterWidgetSort` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `filterWidgetId` INTEGER, `direction` INTEGER NOT NULL, `criteria` INTEGER NOT NULL, `ruleOrder` INTEGER NOT NULL, FOREIGN KEY(`filterWidgetId`) REFERENCES `FilterWidget`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )"); database.execSQL("CREATE TABLE `FilterWidgetStack` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `filterBoardId` INTEGER, `stackId` INTEGER, FOREIGN KEY(`stackId`) REFERENCES `Stack`(`localId`) ON UPDATE NO ACTION ON DELETE CASCADE , FOREIGN KEY(`filterBoardId`) REFERENCES `FilterWidgetBoard`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )"); diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/StackDao.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/StackDao.java index feb7e453b..4c52263ec 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/StackDao.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/StackDao.java @@ -38,6 +38,12 @@ public interface StackDao extends GenericDao<Stack> { @Query("SELECT * FROM stack WHERE accountId = :accountId and localId = :localId") LiveData<FullStack> getFullStack(long accountId, long localId); + @Query("SELECT localId FROM stack WHERE accountId = :accountId") + List<Long> getLocalStackIdsByAccountIdDirectly(long accountId); + + @Query("SELECT localId FROM stack WHERE boardId = :localBoardId") + List<Long> getLocalStackIdsByLocalBoardIdDirectly(long localBoardId); + @Transaction @Query("SELECT * FROM stack WHERE accountId = :accountId and boardId = :localBoardId and (status<>1 or id is null or lastModified <> lastModifiedLocal)") List<FullStack> getLocallyChangedStacksForBoardDirectly(long accountId, long localBoardId); diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/widgets/filter/FilterWidgetSortDao.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/widgets/filter/FilterWidgetSortDao.java index 0520ac433..526943050 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/widgets/filter/FilterWidgetSortDao.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/widgets/filter/FilterWidgetSortDao.java @@ -13,6 +13,6 @@ public interface FilterWidgetSortDao extends GenericDao<FilterWidgetSort> { @Query("DELETE FROM FilterWidgetSort WHERE filterWidgetId = :filterWidgetId") void deleteByFilterWidgetId (Long filterWidgetId); - @Query("select * FROM FilterWidgetSort WHERE filterWidgetId = :filterWidgetId") + @Query("select * FROM FilterWidgetSort WHERE filterWidgetId = :filterWidgetId order by ruleOrder asc") List<FilterWidgetSort> getFilterWidgetSortByFilterWidgetIdDirectly(Long filterWidgetId); } |