diff options
author | desperateCoder <echotodevnull@gmail.com> | 2020-12-10 19:04:38 +0300 |
---|---|---|
committer | desperateCoder <echotodevnull@gmail.com> | 2020-12-10 19:04:38 +0300 |
commit | 23579a2fb6e75b6458d1dbc06e6c24549c77172d (patch) | |
tree | 101093ba072d687bf4ef0f2b1a965755c0bfb6ec | |
parent | 285abea226ec30e0b5df9be924e3682a15e5a630 (diff) |
#597 filter widget: refactored db
6 files changed, 42 insertions, 103 deletions
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/model/widget/filter/FilterWidget.java b/app/src/main/java/it/niedermann/nextcloud/deck/model/widget/filter/FilterWidget.java index 7d93e2858..989c787cf 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/model/widget/filter/FilterWidget.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/model/widget/filter/FilterWidget.java @@ -12,11 +12,10 @@ public class FilterWidget { @PrimaryKey(autoGenerate = true) private Long id; - @Ignore - private List<FilterWidgetAccount> accounts; + private int dueType; @Ignore - private List<FilterWidgetDue> dues; + private List<FilterWidgetAccount> accounts; @Ignore private List<FilterWidgetSort> sorts; @@ -37,14 +36,6 @@ public class FilterWidget { this.id = id; } - public List<FilterWidgetDue> getDues() { - return dues; - } - - public void setDues(List<FilterWidgetDue> dues) { - this.dues = dues; - } - public List<FilterWidgetSort> getSorts() { return sorts; } @@ -53,6 +44,14 @@ public class FilterWidget { this.sorts = sorts; } + public int getDueType() { + return dueType; + } + + public void setDueType(int dueType) { + this.dueType = dueType; + } + @Override public boolean equals(Object o) { if (this == o) return true; 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 94ab14e08..146812765 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 @@ -39,14 +39,14 @@ public class FilterWidgetBoard { private List<FilterWidgetStack> stacks; @Ignore - private List<FilterWidgetLabel> tags; + private List<FilterWidgetLabel> labels; - public List<FilterWidgetLabel> getTags() { - return tags; + public List<FilterWidgetLabel> getLabels() { + return labels; } - public void setTags(List<FilterWidgetLabel> tags) { - this.tags = tags; + public void setLabels(List<FilterWidgetLabel> labels) { + this.labels = labels; } public List<FilterWidgetStack> getStacks() { diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/model/widget/filter/FilterWidgetDue.java b/app/src/main/java/it/niedermann/nextcloud/deck/model/widget/filter/FilterWidgetDue.java deleted file mode 100644 index bf954328e..000000000 --- a/app/src/main/java/it/niedermann/nextcloud/deck/model/widget/filter/FilterWidgetDue.java +++ /dev/null @@ -1,70 +0,0 @@ -package it.niedermann.nextcloud.deck.model.widget.filter; - -import androidx.room.Entity; -import androidx.room.ForeignKey; -import androidx.room.Index; -import androidx.room.PrimaryKey; - -@Entity( - indices = { - @Index(value = "filterWidgetId", name = "unique_idx_FilterWidgetDue_filterWidgetId", unique = true), - }, - foreignKeys = { - @ForeignKey( - entity = FilterWidget.class, - parentColumns = "id", - childColumns = "filterWidgetId", onDelete = ForeignKey.CASCADE - ) - } -) -public class FilterWidgetDue { - - @PrimaryKey(autoGenerate = true) - private Long id; - private Long filterWidgetId; - private int dueType; - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public Long getFilterWidgetId() { - return filterWidgetId; - } - - public void setFilterWidgetId(Long filterWidgetId) { - this.filterWidgetId = filterWidgetId; - } - - public int getDueType() { - return dueType; - } - - public void setDueType(int dueType) { - this.dueType = dueType; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - FilterWidgetDue that = (FilterWidgetDue) o; - - if (dueType != that.dueType) return false; - if (id != null ? !id.equals(that.id) : that.id != null) return false; - return filterWidgetId != null ? filterWidgetId.equals(that.filterWidgetId) : that.filterWidgetId == null; - } - - @Override - public int hashCode() { - int result = id != null ? id.hashCode() : 0; - result = 31 * result + (filterWidgetId != null ? filterWidgetId.hashCode() : 0); - result = 31 * result + dueType; - return result; - } -} 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 eecce4d05..0238c848c 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 @@ -47,6 +47,11 @@ import it.niedermann.nextcloud.deck.model.relations.UserInBoard; import it.niedermann.nextcloud.deck.model.relations.UserInGroup; import it.niedermann.nextcloud.deck.model.widget.filter.FilterWidget; import it.niedermann.nextcloud.deck.model.widget.filter.FilterWidgetAccount; +import it.niedermann.nextcloud.deck.model.widget.filter.FilterWidgetBoard; +import it.niedermann.nextcloud.deck.model.widget.filter.FilterWidgetLabel; +import it.niedermann.nextcloud.deck.model.widget.filter.FilterWidgetSort; +import it.niedermann.nextcloud.deck.model.widget.filter.FilterWidgetStack; +import it.niedermann.nextcloud.deck.model.widget.filter.FilterWidgetUser; 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; @@ -1058,6 +1063,28 @@ public class DataBaseAdapter { public Long createFilterWidget(FilterWidget filterWidget) { long widgetId = db.getFilterWidgetDao().insert(filterWidget); for (FilterWidgetAccount account : filterWidget.getAccounts()) { + account.setFilterWidgetId(widgetId); + long accountId = db.getFilterWidgetAccountDao().insert(account); + for (FilterWidgetUser user : account.getUsers()) { + user.setFilterAccountId(accountId); + db.getFilterWidgetUserDao().insert(user); + } + for (FilterWidgetBoard board : account.getBoards()) { + board.setFilterAccountId(accountId); + long boardId = db.getFilterWidgetBoardDao().insert(board); + for (FilterWidgetStack stack : board.getStacks()) { + stack.setFilterBoardId(boardId); + db.getFilterWidgetStackDao().insert(stack); + } + for (FilterWidgetLabel label : board.getLabels()) { + label.setFilterBoardId(boardId); + db.getFilterWidgetLabelDao().insert(label); + } + } + } + for (FilterWidgetSort sort : filterWidget.getSorts()) { + sort.setFilterWidgetId(widgetId); + db.getFilterWidgetSortDao().insert(sort); } return widgetId; } 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 d4a9705e7..b795488f4 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 @@ -45,7 +45,6 @@ import it.niedermann.nextcloud.deck.model.relations.UserInGroup; import it.niedermann.nextcloud.deck.model.widget.filter.FilterWidget; import it.niedermann.nextcloud.deck.model.widget.filter.FilterWidgetAccount; import it.niedermann.nextcloud.deck.model.widget.filter.FilterWidgetBoard; -import it.niedermann.nextcloud.deck.model.widget.filter.FilterWidgetDue; import it.niedermann.nextcloud.deck.model.widget.filter.FilterWidgetLabel; import it.niedermann.nextcloud.deck.model.widget.filter.FilterWidgetSort; import it.niedermann.nextcloud.deck.model.widget.filter.FilterWidgetStack; @@ -79,7 +78,6 @@ import it.niedermann.nextcloud.deck.persistence.sync.adapters.db.dao.widgets.Sta import it.niedermann.nextcloud.deck.persistence.sync.adapters.db.dao.widgets.filter.FilterWidgetAccountDao; import it.niedermann.nextcloud.deck.persistence.sync.adapters.db.dao.widgets.filter.FilterWidgetBoardDao; import it.niedermann.nextcloud.deck.persistence.sync.adapters.db.dao.widgets.filter.FilterWidgetDao; -import it.niedermann.nextcloud.deck.persistence.sync.adapters.db.dao.widgets.filter.FilterWidgetDueDao; import it.niedermann.nextcloud.deck.persistence.sync.adapters.db.dao.widgets.filter.FilterWidgetLabelDao; import it.niedermann.nextcloud.deck.persistence.sync.adapters.db.dao.widgets.filter.FilterWidgetSortDao; import it.niedermann.nextcloud.deck.persistence.sync.adapters.db.dao.widgets.filter.FilterWidgetStackDao; @@ -118,7 +116,6 @@ import it.niedermann.nextcloud.deck.persistence.sync.adapters.db.dao.widgets.fil FilterWidgetStack.class, FilterWidgetLabel.class, FilterWidgetUser.class, - FilterWidgetDue.class, FilterWidgetSort.class, }, exportSchema = false, @@ -425,7 +422,6 @@ public abstract class DeckDatabase extends RoomDatabase { database.execSQL("CREATE TABLE `FilterWidget` (`id` INTEGER PRIMARY KEY AUTOINCREMENT)"); 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 `FilterWidgetDue` (`id` INTEGER PRIMARY KEY AUTOINCREMENT, `filterWidgetId` INTEGER, `dueType` INTEGER NOT NULL, FOREIGN KEY(`filterWidgetId`) REFERENCES `FilterWidget`(`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 )"); @@ -441,7 +437,6 @@ public abstract class DeckDatabase extends RoomDatabase { database.execSQL("CREATE INDEX `idx_FilterWidgetStack_stackId` ON `FilterWidgetStack` (`stackId`)"); database.execSQL("CREATE INDEX `idx_FilterWidgetUser_filterAccountId` ON `FilterWidgetUser` (`filterAccountId`)"); database.execSQL("CREATE INDEX `idx_FilterWidgetUser_userId` ON `FilterWidgetUser` (`userId`)"); - database.execSQL("CREATE UNIQUE INDEX `unique_idx_FilterWidgetDue_filterWidgetId` ON `FilterWidgetDue` (`filterWidgetId`)"); database.execSQL("CREATE INDEX `unique_idx_FilterWidgetSort_filterWidgetId_criteria` ON `FilterWidgetSort` (`filterWidgetId`, `criteria`)"); database.execSQL("CREATE INDEX `unique_idx_FilterWidgetSort_filterWidgetId_ruleOrder` ON `FilterWidgetSort` (`filterWidgetId`, `ruleOrder`)"); @@ -574,8 +569,6 @@ public abstract class DeckDatabase extends RoomDatabase { public abstract FilterWidgetUserDao getFilterWidgetUserDao(); - public abstract FilterWidgetDueDao getFilterWidgetDueDao(); - public abstract FilterWidgetSortDao getFilterWidgetSortDao(); }
\ No newline at end of file diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/widgets/filter/FilterWidgetDueDao.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/widgets/filter/FilterWidgetDueDao.java deleted file mode 100644 index f3941da70..000000000 --- a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/widgets/filter/FilterWidgetDueDao.java +++ /dev/null @@ -1,10 +0,0 @@ -package it.niedermann.nextcloud.deck.persistence.sync.adapters.db.dao.widgets.filter; - -import androidx.room.Dao; - -import it.niedermann.nextcloud.deck.model.widget.filter.FilterWidgetDue; -import it.niedermann.nextcloud.deck.persistence.sync.adapters.db.dao.GenericDao; - -@Dao -public interface FilterWidgetDueDao extends GenericDao<FilterWidgetDue> { -} |