Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/stefan-niedermann/nextcloud-deck.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/DataBaseAdapter.java')
-rw-r--r--app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/DataBaseAdapter.java90
1 files changed, 69 insertions, 21 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 fe8492c88..f0e33a0e7 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
@@ -3,6 +3,8 @@ package it.niedermann.nextcloud.deck.persistence.sync.adapters.db;
import android.content.Context;
import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.annotation.WorkerThread;
import androidx.lifecycle.LiveData;
import androidx.sqlite.db.SimpleSQLiteQuery;
@@ -36,8 +38,8 @@ import it.niedermann.nextcloud.deck.model.internal.FilterInformation;
import it.niedermann.nextcloud.deck.model.ocs.Activity;
import it.niedermann.nextcloud.deck.model.ocs.comment.DeckComment;
import it.niedermann.nextcloud.deck.model.ocs.comment.Mention;
-import it.niedermann.nextcloud.deck.model.widget.singlecard.SingleCardWidgetModel;
import it.niedermann.nextcloud.deck.model.ocs.comment.full.FullDeckComment;
+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.widget.singlecard.SingleCardWidget;
@@ -123,7 +125,7 @@ public class DataBaseAdapter {
return db.getCardDao().getFullCardByLocalIdDirectly(accountId, localId);
}
- public void filterRelationsForCard(FullCard card) {
+ public void filterRelationsForCard(@Nullable FullCard card) {
if (card != null) {
if (card.getLabels() != null && !card.getLabels().isEmpty()) {
List<Long> filteredIDs = db.getJoinCardWithLabelDao().filterDeleted(card.getLocalId(), getLocalIDs(card.getLabels()));
@@ -136,7 +138,7 @@ public class DataBaseAdapter {
}
}
- private <T> List<Long> getLocalIDs(List<? extends AbstractRemoteEntity> remoteEntityList) {
+ private <T> List<Long> getLocalIDs(@NonNull List<? extends AbstractRemoteEntity> remoteEntityList) {
ArrayList<Long> ids = new ArrayList<>(remoteEntityList.size());
for (AbstractRemoteEntity entity : remoteEntityList) {
ids.add(entity.getLocalId());
@@ -144,7 +146,7 @@ public class DataBaseAdapter {
return ids;
}
- public void readRelationsForACL(List<AccessControl> acl) {
+ public void readRelationsForACL(@Nullable List<AccessControl> acl) {
if (acl != null) {
for (AccessControl accessControl : acl) {
readRelationsForACL(accessControl);
@@ -152,7 +154,7 @@ public class DataBaseAdapter {
}
}
- public void readRelationsForACL(AccessControl acl) {
+ public void readRelationsForACL(@Nullable AccessControl acl) {
if (acl != null) {
if (acl.getUserId() != null) {
acl.setUser(db.getUserDao().getUserByLocalIdDirectly(acl.getUserId()));
@@ -160,7 +162,7 @@ public class DataBaseAdapter {
}
}
- private void filterRelationsForCard(List<FullCard> card) {
+ private void filterRelationsForCard(@Nullable List<FullCard> card) {
if (card == null) {
return;
}
@@ -169,6 +171,7 @@ public class DataBaseAdapter {
}
}
+ @WorkerThread
public Card getCardByRemoteIdDirectly(long accountId, long remoteId) {
return db.getCardDao().getCardByRemoteIdDirectly(accountId, remoteId);
}
@@ -221,7 +224,7 @@ public class DataBaseAdapter {
}
- private void fillSqlWithListValues(StringBuilder query, List<Object> args, List<? extends IRemoteEntity> entities) {
+ private void fillSqlWithListValues(StringBuilder query, List<Object> args, @NonNull List<? extends IRemoteEntity> entities) {
for (int i = 0; i < entities.size(); i++) {
if (i > 0) {
query.append(", ");
@@ -231,10 +234,12 @@ public class DataBaseAdapter {
}
}
+ @WorkerThread
public List<FullCard> getFullCardsForStackDirectly(long accountId, long localStackId) {
return db.getCardDao().getFullCardsForStackDirectly(accountId, localStackId);
}
+ @WorkerThread
public User getUserByUidDirectly(long accountId, String uid) {
return db.getUserDao().getUserByUidDirectly(accountId, uid);
}
@@ -254,11 +259,12 @@ public class DataBaseAdapter {
return distinctUntilChanged(db.getLabelDao().getLabelByRemoteId(accountId, remoteId));
}
+ @WorkerThread
public Label getLabelByRemoteIdDirectly(long accountId, long remoteId) {
return db.getLabelDao().getLabelByRemoteIdDirectly(accountId, remoteId);
}
- public long createLabel(long accountId, Label label) {
+ public long createLabel(long accountId, @NonNull Label label) {
label.setAccountId(accountId);
return db.getLabelDao().insert(label);
}
@@ -356,7 +362,6 @@ public class DataBaseAdapter {
return LiveDataHelper.wrapInLiveData(() -> {
long id = db.getAccountDao().insert(account);
return readAccountDirectly(id);
-
});
}
@@ -377,6 +382,7 @@ public class DataBaseAdapter {
// return distinctUntilChanged(db.getAccountDao().getAccountByName(name));
}
+ @WorkerThread
public Account readAccountDirectly(long id) {
return db.getAccountDao().getAccountByIdDirectly(id);
}
@@ -396,7 +402,7 @@ public class DataBaseAdapter {
return distinctUntilChanged(db.getBoardDao().getBoardsWithEditPermissionsForAccount(accountId));
}
- public WrappedLiveData<Board> createBoard(long accountId, Board board) {
+ public WrappedLiveData<Board> createBoard(long accountId, @NonNull Board board) {
return LiveDataHelper.wrapInLiveData(() -> {
board.setAccountId(accountId);
long id = db.getBoardDao().insert(board);
@@ -405,7 +411,8 @@ public class DataBaseAdapter {
});
}
- public long createBoardDirectly(long accountId, Board board) {
+ @WorkerThread
+ public long createBoardDirectly(long accountId, @NonNull Board board) {
board.setAccountId(accountId);
return db.getBoardDao().insert(board);
}
@@ -428,6 +435,7 @@ public class DataBaseAdapter {
return distinctUntilChanged(db.getStackDao().getFullStacksForBoard(accountId, localBoardId));
}
+ @WorkerThread
public List<FullStack> getFullStacksForBoardDirectly(long accountId, long localBoardId) {
return db.getStackDao().getFullStacksForBoardDirectly(accountId, localBoardId);
}
@@ -455,6 +463,7 @@ public class DataBaseAdapter {
db.getStackDao().update(stack);
}
+ @WorkerThread
public Card getCardByLocalIdDirectly(long accountId, long localCardId) {
return db.getCardDao().getCardByLocalIdDirectly(accountId, localCardId);
}
@@ -463,10 +472,12 @@ public class DataBaseAdapter {
return LiveDataHelper.interceptLiveData(db.getCardDao().getFullCardByLocalId(accountId, localCardId), this::filterRelationsForCard);
}
+ @WorkerThread
public List<FullCard> getLocallyChangedCardsDirectly(long accountId) {
return db.getCardDao().getLocallyChangedCardsDirectly(accountId);
}
+ @WorkerThread
public List<FullCard> getLocallyChangedCardsByLocalStackIdDirectly(long accountId, long localStackId) {
return db.getCardDao().getLocallyChangedCardsByLocalStackIdDirectly(accountId, localStackId);
}
@@ -493,7 +504,7 @@ public class DataBaseAdapter {
db.getCardDao().delete(card);
}
- public void updateCard(Card card, boolean setStatus) {
+ public void updateCard(@NonNull Card card, boolean setStatus) {
markAsEditedIfNeeded(card, setStatus);
db.getCardDao().update(card);
if (db.getSingleCardWidgetModelDao().containsCardLocalId(card.getLocalId())) {
@@ -502,19 +513,22 @@ public class DataBaseAdapter {
}
}
- public long createAccessControl(long accountId, AccessControl entity) {
+ public long createAccessControl(long accountId, @NonNull AccessControl entity) {
entity.setAccountId(accountId);
return db.getAccessControlDao().insert(entity);
}
+ @WorkerThread
public AccessControl getAccessControlByRemoteIdDirectly(long accountId, Long id) {
return db.getAccessControlDao().getAccessControlByRemoteIdDirectly(accountId, id);
}
- public LiveData<List<AccessControl>> getAccessControlByLocalBoardId(long accountId, Long id) {
- return LiveDataHelper.interceptLiveData(db.getAccessControlDao().getAccessControlByLocalBoardId(accountId, id), (acl) -> {
- readRelationsForACL(acl);
- });
+ public LiveData<List<AccessControl>> getAccessControlByLocalBoardId(long accountId, Long localBoardId) {
+ return LiveDataHelper.interceptLiveData(db.getAccessControlDao().getAccessControlByLocalBoardId(accountId, localBoardId), this::readRelationsForACL);
+ }
+
+ public List<AccessControl> getAccessControlByLocalBoardIdDirectly(long accountId, Long localBoardId) {
+ return db.getAccessControlDao().getAccessControlByLocalBoardIdDirectly(accountId, localBoardId);
}
public void updateAccessControl(AccessControl entity, boolean setStatus) {
@@ -535,6 +549,7 @@ public class DataBaseAdapter {
return distinctUntilChanged(db.getBoardDao().getFullBoardById(accountId, localId));
}
+ @WorkerThread
public Board getBoardByLocalIdDirectly(long localId) {
return db.getBoardDao().getBoardByIdDirectly(localId);
}
@@ -582,34 +597,38 @@ public class DataBaseAdapter {
return db.getLabelDao().findProposalsForLabelsToAssign(accountId, boardId, notAssignedToLocalCardId);
}
-
+ @WorkerThread
public Attachment getAttachmentByRemoteIdDirectly(long accountId, Long id) {
return db.getAttachmentDao().getAttachmentByRemoteIdDirectly(accountId, id);
}
+ @WorkerThread
public Attachment getAttachmentByLocalIdDirectly(long accountId, Long id) {
return db.getAttachmentDao().getAttachmentByLocalIdDirectly(accountId, id);
}
+ @WorkerThread
public List<Attachment> getAttachmentsForLocalCardIdDirectly(long accountId, Long localCardId) {
return db.getAttachmentDao().getAttachmentsForLocalCardIdDirectly(accountId, localCardId);
}
+ @WorkerThread
public List<Attachment> getLocallyChangedAttachmentsByLocalCardIdDirectly(long accountId, Long localCardId) {
return db.getAttachmentDao().getLocallyChangedAttachmentsByLocalCardIdDirectly(accountId, localCardId);
}
+ @WorkerThread
public List<Attachment> getLocallyChangedAttachmentsDirectly(long accountId) {
return db.getAttachmentDao().getLocallyChangedAttachmentsDirectly(accountId);
}
- public long createAttachment(long accountId, Attachment attachment) {
+ public long createAttachment(long accountId, @NonNull Attachment attachment) {
attachment.setAccountId(accountId);
attachment.setCreatedAt(new Date());
return db.getAttachmentDao().insert(attachment);
}
- public void updateAttachment(long accountId, Attachment attachment, boolean setStatus) {
+ public void updateAttachment(long accountId, @NonNull Attachment attachment, boolean setStatus) {
markAsEditedIfNeeded(attachment, setStatus);
attachment.setAccountId(accountId);
db.getAttachmentDao().update(attachment);
@@ -625,20 +644,23 @@ public class DataBaseAdapter {
}
}
- private void validateSearchTerm(String searchTerm) {
+ private void validateSearchTerm(@Nullable String searchTerm) {
if (searchTerm == null || searchTerm.trim().length() < 1) {
throw new IllegalArgumentException("please provide a proper search term! \"" + searchTerm + "\" doesn't seem right...");
}
}
+ @WorkerThread
public Account getAccountByIdDirectly(long accountId) {
return db.getAccountDao().getAccountByIdDirectly(accountId);
}
+ @WorkerThread
public List<Account> getAllAccountsDirectly() {
return db.getAccountDao().getAllAccountsDirectly();
}
+ @WorkerThread
public User getUserByLocalIdDirectly(long localUserId) {
return db.getUserDao().getUserByLocalIdDirectly(localUserId);
}
@@ -651,6 +673,7 @@ public class DataBaseAdapter {
db.getJoinCardWithLabelDao().setDbStatus(localCardId, localLabelId, status);
}
+ @WorkerThread
public Label getLabelByLocalIdDirectly(long localLabelId) {
return db.getLabelDao().getLabelsByIdDirectly(localLabelId);
}
@@ -679,10 +702,16 @@ public class DataBaseAdapter {
return db.getLabelDao().getLocallyChangedLabelsDirectly(accountId);
}
+ @WorkerThread
public Board getBoardByLocalCardIdDirectly(long localCardId) {
return db.getBoardDao().getBoardByLocalCardIdDirectly(localCardId);
}
+ @WorkerThread
+ public FullBoard getFullBoardByLocalCardIdDirectly(long localCardId) {
+ return db.getBoardDao().getFullBoardByLocalCardIdDirectly(localCardId);
+ }
+
public JoinCardWithLabel getJoinCardWithLabel(Long localLabelId, Long localCardId) {
return db.getJoinCardWithLabelDao().getJoin(localLabelId, localCardId);
}
@@ -724,6 +753,7 @@ public class DataBaseAdapter {
return db.getActivityDao().insert(activity);
}
+ @WorkerThread
public Activity getActivityByRemoteIdDirectly(long accountId, long remoteActivityId) {
return db.getActivityDao().getActivityByRemoteIdDirectly(accountId, remoteActivityId);
}
@@ -764,10 +794,12 @@ public class DataBaseAdapter {
});
}
+ @WorkerThread
public DeckComment getCommentByRemoteIdDirectly(long accountId, Long remoteCommentId) {
return db.getCommentDao().getCommentByRemoteIdDirectly(accountId, remoteCommentId);
}
+ @WorkerThread
public DeckComment getCommentByLocalIdDirectly(long accountId, Long localCommentId) {
return db.getCommentDao().getCommentByLocalIdDirectly(accountId, localCommentId);
}
@@ -791,6 +823,7 @@ public class DataBaseAdapter {
}
}
+ @WorkerThread
public List<DeckComment> getLocallyChangedCommentsByLocalCardIdDirectly(long accountId, long localCardId) {
return db.getCommentDao().getLocallyChangedCommentsByLocalCardIdDirectly(accountId, localCardId);
}
@@ -803,6 +836,7 @@ public class DataBaseAdapter {
return db.getMentionDao().insert(mention);
}
+ @WorkerThread
public List<DeckComment> getCommentByLocalCardIdDirectly(Long localCardId) {
return db.getCommentDao().getCommentByLocalCardIdDirectly(localCardId);
}
@@ -811,6 +845,7 @@ public class DataBaseAdapter {
return db.getCardDao().getCardsWithLocallyChangedCommentsDirectly(accountId);
}
+ @WorkerThread
public Long getLocalStackIdByRemoteStackIdDirectly(long accountId, Long stackId) {
return db.getStackDao().getLocalStackIdByRemoteStackIdDirectly(accountId, stackId);
}
@@ -827,6 +862,7 @@ public class DataBaseAdapter {
return db.getJoinCardWithLabelDao().countCardsWithLabel(localLabelId);
}
+ @WorkerThread
public Label getLabelByBoardIdAndTitleDirectly(long boardId, String title) {
return db.getLabelDao().getLabelByBoardIdAndTitleDirectly(boardId, title);
}
@@ -839,9 +875,12 @@ public class DataBaseAdapter {
return LiveDataHelper.postCustomValue(distinctUntilChanged(db.getBoardDao().countArchivedBoards(accountId)), data -> data != null && data > 0);
}
+ @WorkerThread
public Long getRemoteCommentIdForLocalIdDirectly(Long localCommentId) {
return db.getCommentDao().getRemoteCommentIdForLocalIdDirectly(localCommentId);
}
+
+ @WorkerThread
public Long getLocalCommentIdForRemoteIdDirectly(long accountId, Long remoteCommentId) {
return db.getCommentDao().getLocalCommentIdForRemoteIdDirectly(accountId, remoteCommentId);
}
@@ -851,6 +890,7 @@ public class DataBaseAdapter {
// Widgets
// -------------------
+ @WorkerThread
public long createSingleCardWidget(int widgetId, long accountId, long boardLocalId, long cardLocalId) {
SingleCardWidgetModel model = new SingleCardWidgetModel();
model.setWidgetId(widgetId);
@@ -873,4 +913,12 @@ public class DataBaseAdapter {
model.setWidgetId(widgetId);
db.getSingleCardWidgetModelDao().delete(model);
}
+
+ public LiveData<List<Account>> readAccountsForHostWithReadAccessToBoard(String host, long boardRemoteId) {
+ return db.getAccountDao().readAccountsForHostWithReadAccessToBoard("%"+host+"%", boardRemoteId);
+ }
+
+ public List<Account> readAccountsForHostWithReadAccessToBoardDirectly(String host, long boardRemoteId) {
+ return db.getAccountDao().readAccountsForHostWithReadAccessToBoardDirectly("%"+host+"%", boardRemoteId);
+ }
}