diff options
author | desperateCoder <echotodevnull@gmail.com> | 2019-10-19 23:04:24 +0300 |
---|---|---|
committer | desperateCoder <echotodevnull@gmail.com> | 2019-10-19 23:23:09 +0300 |
commit | 0669feb66968d0a4ba0746ca010195a59438e1a5 (patch) | |
tree | 21119d9976160f9811ffa2903eeef07d3abe5f69 /app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters | |
parent | b6fb9053e0d993eefb961cde54ecde9250fbbd0d (diff) |
#189: unassign should now work offline, too
Diffstat (limited to 'app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters')
4 files changed, 45 insertions, 15 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 cf8281e8e..6cbac38b3 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 @@ -102,7 +102,8 @@ public class DataBaseAdapter { card.setLabels(db.getLabelDao().getLabelsByIdsDirectly(filteredIDs)); } if (card.getAssignedUserIDs() != null && !card.getAssignedUserIDs().isEmpty()){ - card.setAssignedUsers(db.getUserDao().getUsersByIdDirectly(card.getAssignedUserIDs())); + List<Long> filteredIDs = db.getJoinCardWithUserDao().filterDeleted(card.getLocalId(), card.getAssignedUserIDs()); + card.setAssignedUsers(db.getUserDao().getUsersByIdsDirectly(filteredIDs)); } } } @@ -176,11 +177,20 @@ public class DataBaseAdapter { } public void createJoinCardWithLabel(long localLabelId, long localCardId, DBStatus status) { - JoinCardWithLabel join = new JoinCardWithLabel(); - join.setCardId(localCardId); - join.setLabelId(localLabelId); - join.setStatus(status.getId()); - db.getJoinCardWithLabelDao().insert(join); + JoinCardWithLabel existing = db.getJoinCardWithLabelDao().getJoin(localLabelId, localCardId); + if (existing != null && existing.getStatusEnum() == DBStatus.LOCAL_DELETED){ + // readded! + existing.setStatusEnum(DBStatus.LOCAL_EDITED); + db.getJoinCardWithLabelDao().update(existing); + } else { + JoinCardWithLabel join = new JoinCardWithLabel(); + join.setCardId(localCardId); + join.setLabelId(localLabelId); + join.setStatus(status.getId()); + db.getJoinCardWithLabelDao().insert(join); + } + + } public void deleteJoinedLabelsForCard(long localCardId) { @@ -206,11 +216,18 @@ public class DataBaseAdapter { } public void createJoinCardWithUser(long localUserId, long localCardId, DBStatus status) { - JoinCardWithUser join = new JoinCardWithUser(); - join.setCardId(localCardId); - join.setUserId(localUserId); - join.setStatus(status.getId()); - db.getJoinCardWithUserDao().insert(join); + JoinCardWithUser existing = db.getJoinCardWithUserDao().getJoin(localUserId, localCardId); + if (existing != null && existing.getStatusEnum() == DBStatus.LOCAL_DELETED){ + // readded! + existing.setStatusEnum(DBStatus.LOCAL_EDITED); + db.getJoinCardWithUserDao().update(existing); + } else { + JoinCardWithUser join = new JoinCardWithUser(); + join.setCardId(localCardId); + join.setUserId(localUserId); + join.setStatus(status.getId()); + db.getJoinCardWithUserDao().insert(join); + } } public void deleteJoinedUsersForCard(long localCardId) { diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/JoinCardWithUserDao.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/JoinCardWithUserDao.java index 8cdf0c564..46554685f 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/JoinCardWithUserDao.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/JoinCardWithUserDao.java @@ -31,4 +31,7 @@ public interface JoinCardWithUserDao extends GenericDao<JoinCardWithUser> { "where cardId = (select c.localId from card c where c.accountId = :accountId and c.id = :remoteCardId) " + "and userId = (select u.localId from user u where u.accountId = :accountId and u.uid = :userUid)") void deleteJoinedUserForCardPhysicallyByRemoteIDs(Long accountId, Long remoteCardId, String userUid); + + @Query("select userId from joincardwithuser WHERE cardId = :localCardId and userId IN (:assignedUserIDs) and status <> 3") // not LOCAL_DELETED + List<Long> filterDeleted(long localCardId, List<Long> assignedUserIDs); }
\ No newline at end of file diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/LabelDao.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/LabelDao.java index 69dce3b9a..48016948f 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/LabelDao.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/LabelDao.java @@ -30,7 +30,10 @@ public interface LabelDao extends GenericDao<Label> { Label getLabelsByIdDirectly(final long localLabelID); @Query("SELECT l.* FROM label l WHERE accountId = :accountId" + - " AND NOT EXISTS (select 1 from joincardwithlabel jl where jl.labelId = l.localId and jl.cardId = :notYetAssignedToLocalCardId) " + + " AND NOT EXISTS (" + + "select 1 from joincardwithlabel jl where jl.labelId = l.localId " + + "and jl.cardId = :notYetAssignedToLocalCardId AND status <> 3" + // not LOCAL_DELETED + ") " + " AND boardId = :boardId and title LIKE :searchTerm") LiveData<List<Label>> searchLabelByTitle(final long accountId, final long boardId, final long notYetAssignedToLocalCardId, String searchTerm); @@ -40,7 +43,10 @@ public interface LabelDao extends GenericDao<Label> { @Query("SELECT l.* " + "FROM label l LEFT JOIN joincardwithlabel j ON j.labelId = l.localId " + "WHERE l.accountId = :accountId AND l.boardId = :boardId " + - "AND NOT EXISTS (select 1 from joincardwithlabel jl where jl.labelId = l.localId and jl.cardId = :notAssignedToLocalCardId) " + + "AND NOT EXISTS (" + + "select 1 from joincardwithlabel jl where jl.labelId = l.localId " + + "and jl.cardId = :notAssignedToLocalCardId AND status <> 3" + // not LOCAL_DELETED + ") " + "GROUP BY l.localId ORDER BY count(*) DESC " + "LIMIT :topX") LiveData<List<Label>> findProposalsForLabelsToAssign(long accountId, long boardId, long notAssignedToLocalCardId, int topX); diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/UserDao.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/UserDao.java index c0dd7b389..fe3b78826 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/UserDao.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/UserDao.java @@ -24,7 +24,7 @@ public interface UserDao extends GenericDao<User> { " AND NOT EXISTS (" + " select 1 from joincardwithuser ju" + " where ju.userId = u.localId" + - " and ju.cardId = :notYetAssignedToLocalCardId" + + " and ju.cardId = :notYetAssignedToLocalCardId AND status <> 3" + // not LOCAL_DELETED " )" + "and ( uid LIKE :searchTerm or displayname LIKE :searchTerm or primaryKey LIKE :searchTerm )") LiveData<List<User>> searchUserByUidOrDisplayName(final long accountId, final long notYetAssignedToLocalCardId, final String searchTerm); @@ -52,7 +52,7 @@ public interface UserDao extends GenericDao<User> { " AND NOT EXISTS (" + " select 1 from joincardwithuser ju" + " where ju.userId = u.localId" + - " and ju.cardId = :notAssignedToLocalCardId" + + " and ju.cardId = :notAssignedToLocalCardId AND status <> 3" + // not LOCAL_DELETED " )" + " AND" + " (" + @@ -96,4 +96,8 @@ public interface UserDao extends GenericDao<User> { ") DESC" + " LIMIT :topX") LiveData<List<User>> findProposalsForUsersToAssignForACL(long accountId, long boardId, int topX); + + + @Query("SELECT * FROM user WHERE localId IN (:userIDs) and status <> 3") // not LOCAL_DELETED + List<User> getUsersByIdsDirectly(List<Long> userIDs); }
\ No newline at end of file |