diff options
author | desperateCoder <echotodevnull@gmail.com> | 2020-12-11 16:37:28 +0300 |
---|---|---|
committer | desperateCoder <echotodevnull@gmail.com> | 2020-12-11 16:37:28 +0300 |
commit | 7dd068cc733b1589dd3d6a86c9ebf1021c24c981 (patch) | |
tree | 7996fafc98ae7d47a75fda94ee898e5a1c085da9 /app/src/main | |
parent | 5b04770b6d0b7aac72c96f94da278d290bd68b64 (diff) |
#597 filter widget: read by id
Diffstat (limited to 'app/src/main')
12 files changed, 74 insertions, 12 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 cea2741f6..60f431d7b 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 @@ -4,6 +4,7 @@ import androidx.room.Entity; import androidx.room.Ignore; import androidx.room.PrimaryKey; +import java.util.ArrayList; import java.util.List; @Entity() @@ -15,10 +16,10 @@ public class FilterWidget { private Integer dueType; @Ignore - private List<FilterWidgetAccount> accounts; + private List<FilterWidgetAccount> accounts = new ArrayList<>(); @Ignore - private List<FilterWidgetSort> sorts; + private List<FilterWidgetSort> sorts = new ArrayList<>(); public List<FilterWidgetAccount> getAccounts() { return accounts; 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 e8f2b99c1..8ebdc65a5 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 @@ -6,6 +6,7 @@ import androidx.room.Ignore; import androidx.room.Index; import androidx.room.PrimaryKey; +import java.util.ArrayList; import java.util.List; import it.niedermann.nextcloud.deck.model.Account; @@ -36,10 +37,10 @@ public class FilterWidgetAccount { private Long accountId; @Ignore - private List<FilterWidgetBoard> boards; + private List<FilterWidgetBoard> boards = new ArrayList<>(); @Ignore - private List<FilterWidgetUser> users; + private List<FilterWidgetUser> users = new ArrayList<>(); public void setBoards(List<FilterWidgetBoard> boards) { this.boards = boards; 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 146812765..473d5c486 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 @@ -6,6 +6,7 @@ import androidx.room.Ignore; import androidx.room.Index; import androidx.room.PrimaryKey; +import java.util.ArrayList; import java.util.List; import it.niedermann.nextcloud.deck.model.Board; @@ -36,10 +37,10 @@ public class FilterWidgetBoard { private Long boardId; @Ignore - private List<FilterWidgetStack> stacks; + private List<FilterWidgetStack> stacks = new ArrayList<>(); @Ignore - private List<FilterWidgetLabel> labels; + private List<FilterWidgetLabel> labels = new ArrayList<>(); public List<FilterWidgetLabel> getLabels() { return labels; 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 84779e478..49cde67f7 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 @@ -1942,7 +1942,7 @@ public class SyncManager { public void createFilterWidget(@NonNull FilterWidget filterWidget, @NonNull IResponseCallback<Long> callback) { doAsync(() -> { try { - Long filterWidgetId = dataBaseAdapter.createFilterWidget(filterWidget); + Long filterWidgetId = dataBaseAdapter.createFilterWidgetDirectly(filterWidget); callback.onResponse(filterWidgetId); } catch (Throwable t) { callback.onError(t); @@ -1954,19 +1954,29 @@ public class SyncManager { public void updateFilterWidget(@NonNull FilterWidget filterWidget, @NonNull IResponseCallback<Boolean> callback) { doAsync(() -> { try { - dataBaseAdapter.updateFilterWidget(filterWidget); + dataBaseAdapter.updateFilterWidgetDirectly(filterWidget); callback.onResponse(Boolean.TRUE); } catch (Throwable t) { callback.onError(t); } }); } + @AnyThread + public void getFilterWidget(@NonNull Long filterWidgetId, @NonNull IResponseCallback<FilterWidget> callback) { + doAsync(() -> { + try { + callback.onResponse(dataBaseAdapter.getFilterWidgetByIdDirectly(filterWidgetId)); + } catch (Throwable t) { + callback.onError(t); + } + }); + } @AnyThread public void deleteFilterWidget(@NonNull Long filterWidgetId, @NonNull IResponseCallback<Boolean> callback) { doAsync(() -> { try { - dataBaseAdapter.deleteFilterWidget(filterWidgetId); + dataBaseAdapter.deleteFilterWidgetDirectly(filterWidgetId); callback.onResponse(Boolean.TRUE); } catch (Throwable t) { callback.onError(t); 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 36c9bffb1..d60709fb7 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 @@ -1060,7 +1060,7 @@ public class DataBaseAdapter { return db.getStackWidgetModelDao().getStackWidgetByAppWidgetIdDirectly(appWidgetId); } - public Long createFilterWidget(FilterWidget filterWidget) { + public Long createFilterWidgetDirectly(FilterWidget filterWidget) { long widgetId = db.getFilterWidgetDao().insert(filterWidget); filterWidget.setId(widgetId); insertFilterWidgetDecendants(filterWidget); @@ -1095,17 +1095,33 @@ public class DataBaseAdapter { } } - public void deleteFilterWidget(Long filterWidgetId) { + public void deleteFilterWidgetDirectly(Long filterWidgetId) { db.getFilterWidgetDao().delete(filterWidgetId); } - public void updateFilterWidget(FilterWidget filterWidget) { + public void updateFilterWidgetDirectly(FilterWidget filterWidget) { db.getFilterWidgetSortDao().deleteByFilterWidgetId(filterWidget.getId()); db.getFilterWidgetAccountDao().deleteByFilterWidgetId(filterWidget.getId()); db.getFilterWidgetDao().update(filterWidget); insertFilterWidgetDecendants(filterWidget); } + public FilterWidget getFilterWidgetByIdDirectly(Long filterWidgetId) { + FilterWidget filterWidget = db.getFilterWidgetDao().getFilterWidgetByIdDirectly(filterWidgetId); + filterWidget.setSorts(db.getFilterWidgetSortDao().getFilterWidgetSortByFilterWidgetIdDirectly(filterWidgetId)); + filterWidget.setAccounts(db.getFilterWidgetAccountDao().getFilterWidgetAccountsByFilterWidgetIdDirectly(filterWidgetId)); + for (FilterWidgetAccount account : filterWidget.getAccounts()) { + account.setBoards(db.getFilterWidgetBoardDao().getFilterWidgetBoardsByFilterWidgetAccountIdDirectly(account.getId())); + account.setUsers(db.getFilterWidgetUserDao().getFilterWidgetUsersByFilterWidgetAccountIdDirectly(account.getId())); + for (FilterWidgetBoard board : account.getBoards()) { + board.setLabels(db.getFilterWidgetLabelDao().getFilterWidgetLabelsByFilterWidgetBoardIdDirectly(board.getId())); + board.setStacks(db.getFilterWidgetStackDao().getFilterWidgetStacksByFilterWidgetBoardIdDirectly(board.getId())); + } + } + + return filterWidget; + } + public List<FilterWidgetCard> getCardsForFilterWidget(Long filterWidgetId) { // TODO throw new UnsupportedOperationException("Not yet implemented"); diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/widgets/filter/FilterWidgetAccountDao.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/widgets/filter/FilterWidgetAccountDao.java index 772bef866..845deba44 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/widgets/filter/FilterWidgetAccountDao.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/widgets/filter/FilterWidgetAccountDao.java @@ -3,6 +3,8 @@ package it.niedermann.nextcloud.deck.persistence.sync.adapters.db.dao.widgets.fi import androidx.room.Dao; import androidx.room.Query; +import java.util.List; + import it.niedermann.nextcloud.deck.model.widget.filter.FilterWidgetAccount; import it.niedermann.nextcloud.deck.persistence.sync.adapters.db.dao.GenericDao; @@ -10,4 +12,7 @@ import it.niedermann.nextcloud.deck.persistence.sync.adapters.db.dao.GenericDao; public interface FilterWidgetAccountDao extends GenericDao<FilterWidgetAccount> { @Query("DELETE FROM FilterWidgetAccount WHERE filterWidgetId = :filterWidgetId") void deleteByFilterWidgetId (Long filterWidgetId); + + @Query("select * FROM FilterWidgetAccount WHERE filterWidgetId = :filterWidgetId") + List<FilterWidgetAccount> getFilterWidgetAccountsByFilterWidgetIdDirectly(Long filterWidgetId); } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/widgets/filter/FilterWidgetBoardDao.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/widgets/filter/FilterWidgetBoardDao.java index 731ec1b41..e71c1b51e 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/widgets/filter/FilterWidgetBoardDao.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/widgets/filter/FilterWidgetBoardDao.java @@ -1,10 +1,15 @@ package it.niedermann.nextcloud.deck.persistence.sync.adapters.db.dao.widgets.filter; import androidx.room.Dao; +import androidx.room.Query; + +import java.util.List; import it.niedermann.nextcloud.deck.model.widget.filter.FilterWidgetBoard; import it.niedermann.nextcloud.deck.persistence.sync.adapters.db.dao.GenericDao; @Dao public interface FilterWidgetBoardDao extends GenericDao<FilterWidgetBoard> { + @Query("SELECT * FROM FilterWidgetBoard where filterAccountId = :filterWidgetAccountId") + List<FilterWidgetBoard> getFilterWidgetBoardsByFilterWidgetAccountIdDirectly(Long filterWidgetAccountId); } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/widgets/filter/FilterWidgetDao.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/widgets/filter/FilterWidgetDao.java index 9ade30145..e63250047 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/widgets/filter/FilterWidgetDao.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/widgets/filter/FilterWidgetDao.java @@ -10,4 +10,7 @@ import it.niedermann.nextcloud.deck.persistence.sync.adapters.db.dao.GenericDao; public interface FilterWidgetDao extends GenericDao<FilterWidget> { @Query("DELETE FROM filterwidget WHERE id = :filterWidgetId") void delete (Long filterWidgetId); + + @Query("SELECT * FROM FilterWidget where id = :filterWidgetId") + FilterWidget getFilterWidgetByIdDirectly(Long filterWidgetId); } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/widgets/filter/FilterWidgetLabelDao.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/widgets/filter/FilterWidgetLabelDao.java index 963e1f5b1..61ed01545 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/widgets/filter/FilterWidgetLabelDao.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/widgets/filter/FilterWidgetLabelDao.java @@ -1,10 +1,15 @@ package it.niedermann.nextcloud.deck.persistence.sync.adapters.db.dao.widgets.filter; import androidx.room.Dao; +import androidx.room.Query; + +import java.util.List; import it.niedermann.nextcloud.deck.model.widget.filter.FilterWidgetLabel; import it.niedermann.nextcloud.deck.persistence.sync.adapters.db.dao.GenericDao; @Dao public interface FilterWidgetLabelDao extends GenericDao<FilterWidgetLabel> { + @Query("SELECT * FROM FilterWidgetLabel where filterBoardId = :filterWidgetBoardId") + List<FilterWidgetLabel> getFilterWidgetLabelsByFilterWidgetBoardIdDirectly(Long filterWidgetBoardId); } 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 fb9d4ca9c..0520ac433 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 @@ -3,6 +3,8 @@ package it.niedermann.nextcloud.deck.persistence.sync.adapters.db.dao.widgets.fi import androidx.room.Dao; import androidx.room.Query; +import java.util.List; + import it.niedermann.nextcloud.deck.model.widget.filter.FilterWidgetSort; import it.niedermann.nextcloud.deck.persistence.sync.adapters.db.dao.GenericDao; @@ -10,4 +12,7 @@ import it.niedermann.nextcloud.deck.persistence.sync.adapters.db.dao.GenericDao; public interface FilterWidgetSortDao extends GenericDao<FilterWidgetSort> { @Query("DELETE FROM FilterWidgetSort WHERE filterWidgetId = :filterWidgetId") void deleteByFilterWidgetId (Long filterWidgetId); + + @Query("select * FROM FilterWidgetSort WHERE filterWidgetId = :filterWidgetId") + List<FilterWidgetSort> getFilterWidgetSortByFilterWidgetIdDirectly(Long filterWidgetId); } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/widgets/filter/FilterWidgetStackDao.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/widgets/filter/FilterWidgetStackDao.java index e12425dc2..fd79a3ba9 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/widgets/filter/FilterWidgetStackDao.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/widgets/filter/FilterWidgetStackDao.java @@ -1,10 +1,15 @@ package it.niedermann.nextcloud.deck.persistence.sync.adapters.db.dao.widgets.filter; import androidx.room.Dao; +import androidx.room.Query; + +import java.util.List; import it.niedermann.nextcloud.deck.model.widget.filter.FilterWidgetStack; import it.niedermann.nextcloud.deck.persistence.sync.adapters.db.dao.GenericDao; @Dao public interface FilterWidgetStackDao extends GenericDao<FilterWidgetStack> { + @Query("SELECT * FROM FilterWidgetStack where filterBoardId = :filterWidgetBoardId") + List<FilterWidgetStack> getFilterWidgetStacksByFilterWidgetBoardIdDirectly(Long filterWidgetBoardId); } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/widgets/filter/FilterWidgetUserDao.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/widgets/filter/FilterWidgetUserDao.java index b48d9790a..6b44103e9 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/widgets/filter/FilterWidgetUserDao.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/widgets/filter/FilterWidgetUserDao.java @@ -1,10 +1,15 @@ package it.niedermann.nextcloud.deck.persistence.sync.adapters.db.dao.widgets.filter; import androidx.room.Dao; +import androidx.room.Query; + +import java.util.List; import it.niedermann.nextcloud.deck.model.widget.filter.FilterWidgetUser; import it.niedermann.nextcloud.deck.persistence.sync.adapters.db.dao.GenericDao; @Dao public interface FilterWidgetUserDao extends GenericDao<FilterWidgetUser> { + @Query("SELECT * FROM FilterWidgetUser where filterAccountId = :filterWidgetAccountId") + List<FilterWidgetUser> getFilterWidgetUsersByFilterWidgetAccountIdDirectly(Long filterWidgetAccountId); } |