diff options
author | desperateCoder <echotodevnull@gmail.com> | 2018-12-22 00:44:38 +0300 |
---|---|---|
committer | desperateCoder <echotodevnull@gmail.com> | 2018-12-22 00:44:38 +0300 |
commit | ad49ba195084f884f88e211e1f81765ac710ff52 (patch) | |
tree | e72d28e154f7d530c68c632a794e99bab2a6548e /app/src/main/java/it/niedermann/nextcloud | |
parent | 18a3805c1c7f785f46062d8df31205aef1a586cb (diff) |
More DAOs and refactoring
Diffstat (limited to 'app/src/main/java/it/niedermann/nextcloud')
46 files changed, 488 insertions, 316 deletions
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/DeckLog.java b/app/src/main/java/it/niedermann/nextcloud/deck/DeckLog.java index 56cf970c1..1c60b32f6 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/DeckLog.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/DeckLog.java @@ -6,7 +6,7 @@ public class DeckLog { public static void log(String message) { StackTraceElement caller = Thread.currentThread().getStackTrace()[3]; - String source = caller.getMethodName()+"() ("+caller.getFileName()+":"+caller.getLineNumber()+") -> "; + String source = caller.getMethodName() + "() (" + caller.getFileName() + ":" + caller.getLineNumber() + ") -> "; Log.d(DeckConsts.DEBUG_TAG, source + message); } } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/api/DeckAPI.java b/app/src/main/java/it/niedermann/nextcloud/deck/api/DeckAPI.java index 229d0553c..309365014 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/api/DeckAPI.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/api/DeckAPI.java @@ -19,63 +19,63 @@ import retrofit2.http.Path; public interface DeckAPI { - // ### BOARDS - @POST("boards") - Observable createBoard(@Body Board board); + // ### BOARDS + @POST("boards") + Observable createBoard(@Body Board board); - @GET("boards/{id}") - Observable<Board> getBoard(@Path("id") long id, @Header("If-Modified-Since") Date lastSync); + @GET("boards/{id}") + Observable<Board> getBoard(@Path("id") long id, @Header("If-Modified-Since") Date lastSync); - @GET("boards") - Observable<List<Board>> getBoards(@Header("If-Modified-Since") Date lastSync); + @GET("boards") + Observable<List<Board>> getBoards(@Header("If-Modified-Since") Date lastSync); - // ### Stacks - @POST("boards/{boardId}/stacks") - Observable createStack(@Path("boardId") long boardId, @Body Stack stack); + // ### Stacks + @POST("boards/{boardId}/stacks") + Observable createStack(@Path("boardId") long boardId, @Body Stack stack); - @PUT("boards/{boardId}/stacks/{stackId}") - Observable<Stack> updateStack(@Path("boardId") long boardId, @Path("stackId") long id, @Body Stack stack); + @PUT("boards/{boardId}/stacks/{stackId}") + Observable<Stack> updateStack(@Path("boardId") long boardId, @Path("stackId") long id, @Body Stack stack); - @DELETE("boards/{boardId}/stacks/{stackId}") - Observable<Stack> deleteStack(@Path("boardId") long boardId, @Path("stackId") long id); + @DELETE("boards/{boardId}/stacks/{stackId}") + Observable<Stack> deleteStack(@Path("boardId") long boardId, @Path("stackId") long id); - @GET("boards/{boardId}/stacks/{stackId}") - Observable<Stack> getStack(@Path("boardId") long boardId, @Path("stackId") long id, @Header("If-Modified-Since") Date lastSync); + @GET("boards/{boardId}/stacks/{stackId}") + Observable<Stack> getStack(@Path("boardId") long boardId, @Path("stackId") long id, @Header("If-Modified-Since") Date lastSync); - @GET("boards/{boardId}/stacks") - Observable<List<Stack>> getStacks(@Path("boardId") long boardId, @Header("If-Modified-Since") Date lastSync); + @GET("boards/{boardId}/stacks") + Observable<List<Stack>> getStacks(@Path("boardId") long boardId, @Header("If-Modified-Since") Date lastSync); - @GET("boards/{boardId}/stacks/archived") - Observable<List<Stack>> getArchivedStacks(@Path("boardId") long boardId, @Header("If-Modified-Since") Date lastSync); + @GET("boards/{boardId}/stacks/archived") + Observable<List<Stack>> getArchivedStacks(@Path("boardId") long boardId, @Header("If-Modified-Since") Date lastSync); - // ### Cards - @POST("boards/{boardId}/stacks/{stackId}/cards") - Observable createCard(@Path("boardId") long boardId, @Path("stackId") long stackId, @Body Card card); + // ### Cards + @POST("boards/{boardId}/stacks/{stackId}/cards") + Observable createCard(@Path("boardId") long boardId, @Path("stackId") long stackId, @Body Card card); - @PUT("boards/{boardId}/stacks/{stackId}/cards/{cardId}") - Observable<Card> updateCard(@Path("boardId") long boardId, @Path("stackId") long stackId, @Path("cardId") long cardId, @Body Card card); + @PUT("boards/{boardId}/stacks/{stackId}/cards/{cardId}") + Observable<Card> updateCard(@Path("boardId") long boardId, @Path("stackId") long stackId, @Path("cardId") long cardId, @Body Card card); - @DELETE("boards/{boardId}/stacks/{stackId}/cards/{cardId}") - Observable<Card> deleteCard(@Path("boardId") long boardId, @Path("stackId") long stackId, @Path("cardId") long cardId); + @DELETE("boards/{boardId}/stacks/{stackId}/cards/{cardId}") + Observable<Card> deleteCard(@Path("boardId") long boardId, @Path("stackId") long stackId, @Path("cardId") long cardId); - @GET("boards/{boardId}/stacks/{stackId}/cards/{cardId}") - Observable<Card> getCard(@Path("boardId") long boardId, @Path("stackId") long stackId, @Path("cardId") long cardId, @Header("If-Modified-Since") Date lastSync); + @GET("boards/{boardId}/stacks/{stackId}/cards/{cardId}") + Observable<Card> getCard(@Path("boardId") long boardId, @Path("stackId") long stackId, @Path("cardId") long cardId, @Header("If-Modified-Since") Date lastSync); - // ### LABELS - @GET("boards/{boardId}labels/{labelId}") - Observable<Label> getLabel(@Path("boardId") long boardId, @Path("labelId") long labelId, @Header("If-Modified-Since") Date lastSync); + // ### LABELS + @GET("boards/{boardId}labels/{labelId}") + Observable<Label> getLabel(@Path("boardId") long boardId, @Path("labelId") long labelId, @Header("If-Modified-Since") Date lastSync); - @PUT("boards/getBoards/{boardId}/labels/{labelId}") - Observable<Label> updateLabel(@Path("boardId") long boardId, @Path("labelId") long labelId, @Body Label label); + @PUT("boards/getBoards/{boardId}/labels/{labelId}") + Observable<Label> updateLabel(@Path("boardId") long boardId, @Path("labelId") long labelId, @Body Label label); - @POST("boards/getBoards/{boardId}/labels") - Observable<Label> createLabel(@Path("boardId") long boardId, @Body Label label); + @POST("boards/getBoards/{boardId}/labels") + Observable<Label> createLabel(@Path("boardId") long boardId, @Body Label label); - @DELETE("boards/getBoards/{boardId}/labels/{labelId}") - Observable<Label> deleteLabel(@Path("boardId") long boardId, @Path("labelId") long labelId); + @DELETE("boards/getBoards/{boardId}/labels/{labelId}") + Observable<Label> deleteLabel(@Path("boardId") long boardId, @Path("labelId") long labelId); } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/api/DeckAPI_SSO.java b/app/src/main/java/it/niedermann/nextcloud/deck/api/DeckAPI_SSO.java index 8e897d1cd..c5e7f6508 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/api/DeckAPI_SSO.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/api/DeckAPI_SSO.java @@ -41,11 +41,11 @@ public class DeckAPI_SSO implements DeckAPI { .setMethod(method) .setUrl(API_ENDPOINT + path) .setFollowRedirects(true); - if (lastSync!=null) { + if (lastSync != null) { String lastSyncHeader = API_FORMAT.format(lastSync); // omit Offset of timezone (e.g.: +01:00) if (lastSyncHeader.matches("^.*\\+[0-9]{2}:[0-9]{2}$")) { - lastSyncHeader = lastSyncHeader.substring(0, lastSyncHeader.length()-6); + lastSyncHeader = lastSyncHeader.substring(0, lastSyncHeader.length() - 6); } Log.d("deck lastSync", lastSyncHeader); @@ -57,19 +57,22 @@ public class DeckAPI_SSO implements DeckAPI { } return builder; } + private String buildEndpointPath(String path, Object... params) { String[] pathFragments = path.split("\\{[a-zA-Z0-9]*\\}"); StringBuffer sb = new StringBuffer(); int i = 0; - for (; i<pathFragments.length; i++) { + for (; i < pathFragments.length; i++) { sb.append(pathFragments[i]); sb.append(params.length > i ? params[i] : ""); } return sb.toString(); } + private NextcloudRequest.Builder buildRequest(String method, String path, Date lastSync, Object... params) { return buildRequest(method, buildEndpointPath(path, params), lastSync); } + private NextcloudRequest.Builder buildRequest(String method, String path, Object... params) { return buildRequest(method, path, null, params); } @@ -141,33 +144,33 @@ public class DeckAPI_SSO implements DeckAPI { @Override public Observable<Card> getCard(long boardId, long stackId, long cardId, Date lastSync) { - NextcloudRequest request = buildRequest(GET, "boards/{boardId}/stacks/{stackId}/cards/{cardId}",lastSync, boardId, stackId, cardId).build(); + NextcloudRequest request = buildRequest(GET, "boards/{boardId}/stacks/{stackId}/cards/{cardId}", lastSync, boardId, stackId, cardId).build(); return nextcloudAPI.performRequestObservable(Card.class, request); } @Override public Observable<Label> getLabel(long boardId, long labelId, Date lastSync) { - NextcloudRequest request = buildRequest(GET, "boards/"+boardId+"labels/"+labelId, lastSync).build(); + NextcloudRequest request = buildRequest(GET, "boards/" + boardId + "labels/" + labelId, lastSync).build(); return nextcloudAPI.performRequestObservable(Label.class, request); } @Override public Observable<Label> updateLabel(long boardId, long labelId, Label label) { - NextcloudRequest request = buildRequest(PUT, "boards/"+boardId+"/labels/"+labelId) + NextcloudRequest request = buildRequest(PUT, "boards/" + boardId + "/labels/" + labelId) .setRequestBody(GsonConfig.GetGson().toJson(label)).build(); return nextcloudAPI.performRequestObservable(Label.class, request); } @Override public Observable<Label> createLabel(long boardId, Label label) { - NextcloudRequest request = buildRequest(POST, "boards/"+boardId+"/labels") + NextcloudRequest request = buildRequest(POST, "boards/" + boardId + "/labels") .setRequestBody(GsonConfig.GetGson().toJson(label)).build(); return nextcloudAPI.performRequestObservable(Label.class, request); } @Override public Observable<Label> deleteLabel(long boardId, long labelId) { - NextcloudRequest request = buildRequest(DELETE, "boards/"+boardId+"/labels/"+labelId).build(); + NextcloudRequest request = buildRequest(DELETE, "boards/" + boardId + "/labels/" + labelId).build(); return nextcloudAPI.performRequestObservable(Board.class, request); } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/api/IResponseCallback.java b/app/src/main/java/it/niedermann/nextcloud/deck/api/IResponseCallback.java index 848cc8a70..899bec354 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/api/IResponseCallback.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/api/IResponseCallback.java @@ -18,31 +18,33 @@ public abstract class IResponseCallback<T> { public abstract void onError(Throwable throwable); - public void fillAccountIDs(T response){ - if (response != null){ - if (isListOfRemoteEntity(response)){ - fillAccountIDs((Collection<RemoteEntity>)response); - } else if (isRemoteEntity(response)){ - fillAccountIDs((RemoteEntity)response); + public void fillAccountIDs(T response) { + if (response != null) { + if (isListOfRemoteEntity(response)) { + fillAccountIDs((Collection<RemoteEntity>) response); + } else if (isRemoteEntity(response)) { + fillAccountIDs((RemoteEntity) response); } } } - private void fillAccountIDs(RemoteEntity response){ + + private void fillAccountIDs(RemoteEntity response) { response.setAccount(this.account); } - private void fillAccountIDs(Collection<RemoteEntity> response){ - for (RemoteEntity entity: response) { + + private void fillAccountIDs(Collection<RemoteEntity> response) { + for (RemoteEntity entity : response) { entity.setAccount(this.account); } } - private boolean isRemoteEntity(T response){ + private boolean isRemoteEntity(T response) { return response instanceof RemoteEntity; } - private boolean isListOfRemoteEntity(T response){ - if (response instanceof List){ - List<?> collection = (List)response; + private boolean isListOfRemoteEntity(T response) { + if (response instanceof List) { + List<?> collection = (List) response; return collection.size() > 0 && collection.get(0) instanceof RemoteEntity; } return false; diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/api/JsonToEntityParser.java b/app/src/main/java/it/niedermann/nextcloud/deck/api/JsonToEntityParser.java index 364f7b81c..73a3b3295 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/api/JsonToEntityParser.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/api/JsonToEntityParser.java @@ -29,7 +29,7 @@ public class JsonToEntityParser { } protected static <T> T parseJsonObject(JsonObject obj, Class<T> mType) { - if(mType == Board.class) { + if (mType == Board.class) { return (T) parseBoard(obj); } else if (mType == Card.class) { return (T) parseCard(obj); @@ -38,7 +38,7 @@ public class JsonToEntityParser { } else if (mType == Label.class) { return (T) parseLabel(obj); } - throw new IllegalArgumentException("unregistered type: "+mType.getCanonicalName()); + throw new IllegalArgumentException("unregistered type: " + mType.getCanonicalName()); } @@ -62,10 +62,10 @@ public class JsonToEntityParser { // stack.setDeletedAt(e.get("lastModified")) // TODO: parse date! // stack.setDeletedAt(e.get("createdAt")) // TODO: parse date! // stack.setDeletedAt(e.get("deletedAt")) // TODO: parse date! - if (e.has("labels") && !e.get("labels").isJsonNull()){ + if (e.has("labels") && !e.get("labels").isJsonNull()) { JsonArray labelsJson = e.getAsJsonArray("labels"); List<Label> labels = new ArrayList<>(); - for (JsonElement labelJson: labelsJson) { + for (JsonElement labelJson : labelsJson) { labels.add(parseLabel(labelJson.getAsJsonObject())); } card.setLabels(labels); @@ -78,11 +78,11 @@ public class JsonToEntityParser { card.setDueDate(getTimestamp(e.get("duedate"))); card.setCommentsUnread(e.get("commentsUnread").getAsInt()); JsonElement owner = e.get("owner"); - if (owner != null){ - if (owner.isJsonPrimitive()){//TODO: remove if, let only else! + if (owner != null) { + if (owner.isJsonPrimitive()) {//TODO: remove if, let only else! Log.d(DeckConsts.DEBUG_TAG, "owner is Primitive, skipping"); } else - card.setOwner(parseUser(owner.getAsJsonObject())); + card.setOwner(parseUser(owner.getAsJsonObject())); } card.setArchived(e.get("archived").getAsBoolean()); @@ -105,10 +105,10 @@ public class JsonToEntityParser { stack.setBoardId(e.get("boardId").getAsLong()); stack.setId(e.get("id").getAsLong()); stack.setOrder(e.get("order").getAsInt()); - if (e.has("cards")){ + if (e.has("cards")) { JsonArray cardsJson = e.getAsJsonArray("cards"); List<Card> cards = new ArrayList<>(); - for (JsonElement cardJson: cardsJson) { + for (JsonElement cardJson : cardsJson) { cards.add(parseCard(cardJson.getAsJsonObject())); } stack.setCards(cards); @@ -116,6 +116,7 @@ public class JsonToEntityParser { // stack.setDeletedAt(e.get("deletedAt")) // TODO: parse date! return stack; } + protected static Label parseLabel(JsonObject e) { DeckLog.log(e.toString()); Label label = new Label(); diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/api/NextcloudArrayDeserializer.java b/app/src/main/java/it/niedermann/nextcloud/deck/api/NextcloudArrayDeserializer.java index 395f76149..1ece1c1fe 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/api/NextcloudArrayDeserializer.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/api/NextcloudArrayDeserializer.java @@ -17,7 +17,7 @@ import java.util.List; * Created by david on 24.05.17. */ -public class NextcloudArrayDeserializer<T> implements JsonDeserializer<List<T>>{ +public class NextcloudArrayDeserializer<T> implements JsonDeserializer<List<T>> { protected final String mKey; protected final Class<T> mType; @@ -32,10 +32,10 @@ public class NextcloudArrayDeserializer<T> implements JsonDeserializer<List<T>>{ @Override public List<T> deserialize(final JsonElement json, final Type typeOfT, final JsonDeserializationContext context) throws JsonParseException { List<T> items = new ArrayList<>(); - if (json.isJsonArray()){ + if (json.isJsonArray()) { JsonArray jArr = json.getAsJsonArray(); - for(int i = 0; i < jArr.size(); i++) { + for (int i = 0; i < jArr.size(); i++) { JsonObject obj = jArr.get(i).getAsJsonObject(); items.add(JsonToEntityParser.parseJsonObject(obj, mType)); } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/api/NextcloudDeserializer.java b/app/src/main/java/it/niedermann/nextcloud/deck/api/NextcloudDeserializer.java index 42c402436..f323ed685 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/api/NextcloudDeserializer.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/api/NextcloudDeserializer.java @@ -1,22 +1,11 @@ package it.niedermann.nextcloud.deck.api; -import android.util.Log; - -import com.google.gson.JsonArray; import com.google.gson.JsonDeserializationContext; import com.google.gson.JsonDeserializer; import com.google.gson.JsonElement; -import com.google.gson.JsonObject; import com.google.gson.JsonParseException; import java.lang.reflect.Type; -import java.util.ArrayList; -import java.util.List; - -import it.niedermann.nextcloud.deck.model.Board; -import it.niedermann.nextcloud.deck.model.Card; -import it.niedermann.nextcloud.deck.model.Label; -import it.niedermann.nextcloud.deck.model.Stack; /** * Created by david on 24.05.17. diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/model/Account.java b/app/src/main/java/it/niedermann/nextcloud/deck/model/Account.java index d1d4f6276..2c7132a53 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/model/Account.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/model/Account.java @@ -19,6 +19,7 @@ public class Account implements Serializable { @NonNull private String name; + @Ignore public Account(Long id, @NonNull String name) { this.id = id; this.name = name; diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/model/Board.java b/app/src/main/java/it/niedermann/nextcloud/deck/model/Board.java index 7c794a8ec..691a96c27 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/model/Board.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/model/Board.java @@ -10,21 +10,21 @@ import it.niedermann.nextcloud.deck.model.interfaces.RemoteEntity; @Entity( inheritSuperIndices = true, - foreignKeys = {@ForeignKey(entity = User.class, parentColumns = "id", childColumns = "ownerId")} + foreignKeys = {@ForeignKey(entity = User.class, parentColumns = "localId", childColumns = "ownerId")} ) public class Board extends RemoteEntity { private String title; long ownerId; -// @ToOne(joinProperty = "ownerId") + // @ToOne(joinProperty = "ownerId") // private User owner; private String color; private boolean archived; -// @ToMany + // @ToMany // @JoinEntity(entity = JoinBoardWithLabel.class, sourceProperty = "boardId", targetProperty = "labelId") // private List<Label> labels = new ArrayList<>(); private String acl; -// @ToMany + // @ToMany // @JoinEntity(entity = JoinBoardWithPermission.class, sourceProperty = "boardId", targetProperty = "permissionId") // private List<Permission> permissions = new ArrayList<>(); // @ToMany @@ -54,10 +54,6 @@ public class Board extends RemoteEntity { this.lastModifiedLocal = lastModifiedLocal; } - public void setLocalId(Long localId) { - this.localId = localId; - } - public Long getId() { return id; } @@ -78,10 +74,6 @@ public class Board extends RemoteEntity { return archived; } - public void setArchived(boolean archived) { - this.archived = archived; - } - public String getAcl() { return acl; } @@ -106,14 +98,6 @@ public class Board extends RemoteEntity { this.deletedAt = deletedAt; } - public Long getLocalId() { - return localId; - } - - public void setLocalId(long localId) { - this.localId = localId; - } - public String getTitle() { return title; } @@ -134,11 +118,6 @@ public class Board extends RemoteEntity { this.status = status; } - public boolean getArchived() { - return this.archived; - } - - public int getStatus() { return this.status; } @@ -151,4 +130,7 @@ public class Board extends RemoteEntity { this.ownerId = ownerId; } + public void setArchived(boolean archived) { + this.archived = archived; + } } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/model/Card.java b/app/src/main/java/it/niedermann/nextcloud/deck/model/Card.java index 5a3e349e5..2d8cff0b7 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/model/Card.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/model/Card.java @@ -4,45 +4,40 @@ import android.arch.persistence.room.Entity; import android.arch.persistence.room.Index; import android.support.annotation.NonNull; -import java.util.ArrayList; import java.util.Date; -import java.util.List; import it.niedermann.nextcloud.deck.model.enums.DBStatus; import it.niedermann.nextcloud.deck.model.interfaces.RemoteEntity; -@Entity(inheritSuperIndices = true, indices = {@Index("accountId")}) +@Entity(inheritSuperIndices = true, indices = {@Index(value = "accountId", name = "card_acc")}) public class Card extends RemoteEntity { - private String title; private String description; @NonNull // @Index private long stackId; -// @ToOne(joinProperty = "stackId") + // @ToOne(joinProperty = "stackId") // protected Stack stack; private String type; - private Date lastModified; private Date createdAt; private Date deletedAt; -// @ToMany + // @ToMany // @JoinEntity(entity = JoinCardWithLabel.class, sourceProperty = "cardId", targetProperty = "labelId") // private List<Label> labels = new ArrayList<>(); // @ToMany // @JoinEntity(entity = JoinCardWithUser.class, sourceProperty = "cardId", targetProperty = "userId") - private List<User> assignedUsers = new ArrayList<>(); private String attachments; private int attachmentCount; private Long userId; -// @ToOne(joinProperty = "userId") + // @ToOne(joinProperty = "userId") // private User owner; // @Index @NonNull private int order; -// @Index + // @Index private boolean archived; private Date dueDate; private boolean notified; @@ -50,9 +45,6 @@ public class Card extends RemoteEntity { private int commentsUnread; - public void setAssignedUsers(List<User> assignedUsers) { - this.assignedUsers = assignedUsers; - } public boolean isNotified() { return notified; @@ -62,14 +54,6 @@ public class Card extends RemoteEntity { this.notified = notified; } - public Long getLocalId() { - return localId; - } - - public void setLocalId(Long localId) { - this.localId = localId; - } - public Long getId() { return id; } @@ -118,14 +102,6 @@ public class Card extends RemoteEntity { this.type = type; } - public Date getLastModified() { - return lastModified; - } - - public void setLastModified(Date lastModified) { - this.lastModified = lastModified; - } - public Date getCreatedAt() { return createdAt; } @@ -142,10 +118,6 @@ public class Card extends RemoteEntity { this.deletedAt = deletedAt; } - public void addAssignedUser(User user) { - this.assignedUsers.add(user); - } - public String getAttachments() { return attachments; } @@ -202,10 +174,6 @@ public class Card extends RemoteEntity { this.status = status; } - public boolean getArchived() { - return this.archived; - } - public int getStatus() { return this.status; } @@ -221,8 +189,4 @@ public class Card extends RemoteEntity { public int getOrder() { return this.order; } - - public boolean getNotified() { - return this.notified; - } } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/model/JoinBoardWithLabel.java b/app/src/main/java/it/niedermann/nextcloud/deck/model/JoinBoardWithLabel.java index c5973c1c0..4a058e127 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/model/JoinBoardWithLabel.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/model/JoinBoardWithLabel.java @@ -2,9 +2,10 @@ package it.niedermann.nextcloud.deck.model; import android.arch.persistence.room.Entity; import android.arch.persistence.room.ForeignKey; +import android.support.annotation.NonNull; @Entity( - primaryKeys = { "labelId", "boardId" }, + primaryKeys = {"labelId", "boardId"}, foreignKeys = { @ForeignKey(entity = Board.class, parentColumns = "localId", @@ -14,8 +15,10 @@ import android.arch.persistence.room.ForeignKey; childColumns = "labelId") }) public class JoinBoardWithLabel { - private Long labelId; + @NonNull private Long boardId; + @NonNull + private Long labelId; public Long getLabelId() { diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/model/JoinBoardWithPermission.java b/app/src/main/java/it/niedermann/nextcloud/deck/model/JoinBoardWithPermission.java index a811b7897..2f5b7b076 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/model/JoinBoardWithPermission.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/model/JoinBoardWithPermission.java @@ -2,19 +2,22 @@ package it.niedermann.nextcloud.deck.model; import android.arch.persistence.room.Entity; import android.arch.persistence.room.ForeignKey; +import android.support.annotation.NonNull; @Entity( - primaryKeys = { "permissionId", "boardId" }, + primaryKeys = {"permissionId", "boardId"}, foreignKeys = { @ForeignKey(entity = Board.class, - parentColumns = "id", + parentColumns = "localId", childColumns = "boardId"), @ForeignKey(entity = Permission.class, parentColumns = "id", childColumns = "permissionId") }) public class JoinBoardWithPermission { + @NonNull private Long permissionId; + @NonNull private Long boardId; public Long getPermissionId() { diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/model/JoinBoardWithUser.java b/app/src/main/java/it/niedermann/nextcloud/deck/model/JoinBoardWithUser.java index 97ab0a678..e24d98482 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/model/JoinBoardWithUser.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/model/JoinBoardWithUser.java @@ -2,9 +2,10 @@ package it.niedermann.nextcloud.deck.model; import android.arch.persistence.room.Entity; import android.arch.persistence.room.ForeignKey; +import android.support.annotation.NonNull; @Entity( - primaryKeys = { "userId", "boardId" }, + primaryKeys = {"userId", "boardId"}, foreignKeys = { @ForeignKey(entity = Board.class, parentColumns = "localId", @@ -14,7 +15,9 @@ import android.arch.persistence.room.ForeignKey; childColumns = "userId") }) public class JoinBoardWithUser { + @NonNull private Long userId; + @NonNull private Long boardId; public Long getUserId() { diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/model/JoinCardWithLabel.java b/app/src/main/java/it/niedermann/nextcloud/deck/model/JoinCardWithLabel.java index d21789ebf..af607191d 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/model/JoinCardWithLabel.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/model/JoinCardWithLabel.java @@ -2,9 +2,10 @@ package it.niedermann.nextcloud.deck.model; import android.arch.persistence.room.Entity; import android.arch.persistence.room.ForeignKey; +import android.support.annotation.NonNull; @Entity( - primaryKeys = { "labelId", "cardId" }, + primaryKeys = {"labelId", "cardId"}, foreignKeys = { @ForeignKey(entity = Label.class, parentColumns = "localId", @@ -14,7 +15,9 @@ import android.arch.persistence.room.ForeignKey; childColumns = "cardId") }) public class JoinCardWithLabel { + @NonNull private Long labelId; + @NonNull private Long cardId; public Long getLabelId() { diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/model/JoinCardWithUser.java b/app/src/main/java/it/niedermann/nextcloud/deck/model/JoinCardWithUser.java index 6fea1765b..c8ef6f9fa 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/model/JoinCardWithUser.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/model/JoinCardWithUser.java @@ -2,9 +2,10 @@ package it.niedermann.nextcloud.deck.model; import android.arch.persistence.room.Entity; import android.arch.persistence.room.ForeignKey; +import android.support.annotation.NonNull; @Entity( - primaryKeys = { "userId", "cardId" }, + primaryKeys = {"userId", "cardId"}, foreignKeys = { @ForeignKey(entity = User.class, parentColumns = "localId", @@ -14,7 +15,9 @@ import android.arch.persistence.room.ForeignKey; childColumns = "cardId") }) public class JoinCardWithUser { + @NonNull private Long userId; + @NonNull private Long cardId; public Long getUserId() { diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/model/JoinStackWithCard.java b/app/src/main/java/it/niedermann/nextcloud/deck/model/JoinStackWithCard.java index 3035cb04e..de09242ca 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/model/JoinStackWithCard.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/model/JoinStackWithCard.java @@ -2,9 +2,10 @@ package it.niedermann.nextcloud.deck.model; import android.arch.persistence.room.Entity; import android.arch.persistence.room.ForeignKey; +import android.support.annotation.NonNull; @Entity( - primaryKeys = { "stackId", "cardId" }, + primaryKeys = {"stackId", "cardId"}, foreignKeys = { @ForeignKey(entity = Stack.class, parentColumns = "localId", @@ -14,7 +15,9 @@ import android.arch.persistence.room.ForeignKey; childColumns = "cardId") }) public class JoinStackWithCard { + @NonNull private Long stackId; + @NonNull private Long cardId; public Long getStackId() { diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/model/Permission.java b/app/src/main/java/it/niedermann/nextcloud/deck/model/Permission.java index 341c6e9f4..f0c46787b 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/model/Permission.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/model/Permission.java @@ -18,10 +18,11 @@ public class Permission { this.id = id; } - public PermissionType getType(){ + public PermissionType getType() { return PermissionType.findById(id); } - public void setType(PermissionType type){ + + public void setType(PermissionType type) { this.id = type.getId(); } } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/model/enums/DBStatus.java b/app/src/main/java/it/niedermann/nextcloud/deck/model/enums/DBStatus.java index 8454b60ce..7fa9c30be 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/model/enums/DBStatus.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/model/enums/DBStatus.java @@ -41,7 +41,7 @@ public enum DBStatus { * @return The DBStatus fitting to the String. */ public static DBStatus findById(int id) { - for (DBStatus s : DBStatus.values()){ + for (DBStatus s : DBStatus.values()) { if (s.getId() == id) { return s; } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/model/enums/PermissionType.java b/app/src/main/java/it/niedermann/nextcloud/deck/model/enums/PermissionType.java index f8b34e9e4..49f10ef24 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/model/enums/PermissionType.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/model/enums/PermissionType.java @@ -10,12 +10,12 @@ public enum PermissionType { private long id; private String key; - PermissionType(long id, String key){ + PermissionType(long id, String key) { this.key = key; } public static PermissionType findByKey(String key) { - for (PermissionType s : PermissionType.values()){ + for (PermissionType s : PermissionType.values()) { if (s.getKey().equals(key)) { return s; } @@ -24,7 +24,7 @@ public enum PermissionType { } public static PermissionType findById(long key) { - for (PermissionType s : PermissionType.values()){ + for (PermissionType s : PermissionType.values()) { if (s.getId() == key) { return s; } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/model/full/FullCard.java b/app/src/main/java/it/niedermann/nextcloud/deck/model/full/FullCard.java new file mode 100644 index 000000000..856dbe3f2 --- /dev/null +++ b/app/src/main/java/it/niedermann/nextcloud/deck/model/full/FullCard.java @@ -0,0 +1,34 @@ +package it.niedermann.nextcloud.deck.model.full; + +import android.arch.persistence.room.Embedded; +import android.arch.persistence.room.Relation; + +import java.util.List; + +import it.niedermann.nextcloud.deck.model.Card; +import it.niedermann.nextcloud.deck.model.JoinCardWithLabel; +import it.niedermann.nextcloud.deck.model.Label; + +public class FullCard { + @Embedded + public Card card; + + @Relation(entity = JoinCardWithLabel.class, parentColumn = "localId", entityColumn = "labelId") + public List<Label> labels; + + public Card getCard() { + return card; + } + + public void setCard(Card card) { + this.card = card; + } + + public List<Label> getLabels() { + return labels; + } + + public void setLabels(List<Label> labels) { + this.labels = labels; + } +} diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/model/interfaces/RemoteEntity.java b/app/src/main/java/it/niedermann/nextcloud/deck/model/interfaces/RemoteEntity.java index bb2784e9d..6c283efe8 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/model/interfaces/RemoteEntity.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/model/interfaces/RemoteEntity.java @@ -7,7 +7,6 @@ import android.support.annotation.NonNull; import java.util.Date; -import it.niedermann.nextcloud.deck.model.Account; import it.niedermann.nextcloud.deck.model.enums.DBStatus; @Entity( diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sql/DataBaseConsts.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sql/DataBaseConsts.java index 521b6b015..67e32ecff 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sql/DataBaseConsts.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sql/DataBaseConsts.java @@ -224,7 +224,6 @@ public class DataBaseConsts { ");"; - public static final String[] ALL_TABLES = new String[]{ TABLE_ACCOUNTS, TABLE_OC_DECK_STACKS, @@ -240,7 +239,6 @@ public class DataBaseConsts { public static final String[] ALL_CREATE_INDICES = new String[]{ - "CREATE INDEX IF NOT EXISTS `deck_labels_board_id_index` ON `oc_deck_labels` (" + " `board_id`" + ")", 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 189639068..0d617939d 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 @@ -1,6 +1,7 @@ package it.niedermann.nextcloud.deck.persistence.sync; import android.app.Activity; +import android.arch.lifecycle.LiveData; import android.content.Context; import android.content.SharedPreferences; @@ -19,14 +20,13 @@ import it.niedermann.nextcloud.deck.model.Label; import it.niedermann.nextcloud.deck.model.Stack; import it.niedermann.nextcloud.deck.model.User; import it.niedermann.nextcloud.deck.model.interfaces.RemoteEntity; -import it.niedermann.nextcloud.deck.persistence.sync.adapters.db.DataBaseAdapter; import it.niedermann.nextcloud.deck.persistence.sync.adapters.IDataBasePersistenceAdapter; -import it.niedermann.nextcloud.deck.persistence.sync.adapters.db.IDatabaseOnlyAdapter; import it.niedermann.nextcloud.deck.persistence.sync.adapters.IPersistenceAdapter; import it.niedermann.nextcloud.deck.persistence.sync.adapters.ServerAdapter; +import it.niedermann.nextcloud.deck.persistence.sync.adapters.db.DataBaseAdapter; +import it.niedermann.nextcloud.deck.persistence.sync.adapters.db.IDatabaseOnlyAdapter; -public class SyncManager implements IDataBasePersistenceAdapter{ - +public class SyncManager implements IDataBasePersistenceAdapter { private IDatabaseOnlyAdapter dataBaseAdapter; @@ -34,18 +34,18 @@ public class SyncManager implements IDataBasePersistenceAdapter{ private Context applicationContext; private Activity sourceActivity; - public SyncManager(Context applicationContext, Activity sourceActivity){ + public SyncManager(Context applicationContext, Activity sourceActivity) { this.applicationContext = applicationContext.getApplicationContext(); this.sourceActivity = sourceActivity; dataBaseAdapter = new DataBaseAdapter(this.applicationContext); - this.serverAdapter = new ServerAdapter(this.applicationContext, sourceActivity); + this.serverAdapter = new ServerAdapter(this.applicationContext, sourceActivity); } - private void doAsync(Runnable r){ + private void doAsync(Runnable r) { new Thread(r).start(); } - public void synchronize(IResponseCallback<Boolean> responseCallback){ + public void synchronize(IResponseCallback<Boolean> responseCallback) { final long accountId = responseCallback.getAccount().getId(); doAsync(() -> { SharedPreferences lastSyncPref = applicationContext.getSharedPreferences( @@ -60,7 +60,7 @@ public class SyncManager implements IDataBasePersistenceAdapter{ public void onResponse(List<Board> response) { for (Board b : response) { Board existingBoard = dataBaseAdapter.getBoard(accountId, b.getId()); - if (existingBoard==null) { + if (existingBoard == null) { dataBaseAdapter.createBoard(accountId, b); } else { dataBaseAdapter.updateBoard(applyUpdatesFromRemote(existingBoard, b, accountId)); @@ -89,10 +89,10 @@ public class SyncManager implements IDataBasePersistenceAdapter{ serverAdapter.getStacks(accountId, board.getId(), new IResponseCallback<List<Stack>>(account) { @Override public void onResponse(List<Stack> response) { - for (Stack stack: response) { + for (Stack stack : response) { stack.setBoardId(syncedBoard.getLocalId()); Stack existingStack = dataBaseAdapter.getStack(accountId, syncedBoard.getLocalId(), stack.getId()); - if (existingStack==null) { + if (existingStack == null) { dataBaseAdapter.createStack(accountId, stack); } else { dataBaseAdapter.updateStack(applyUpdatesFromRemote(existingStack, stack, accountId)); @@ -105,21 +105,21 @@ public class SyncManager implements IDataBasePersistenceAdapter{ } - @Override public void onError(Throwable throwable) { responseCallback.onError(throwable); } }); } + private void synchronizeCardOf(final Stack stack, final Board syncedBoard, final IResponseCallback<Boolean> responseCallback) { //sync cards Account account = responseCallback.getAccount(); long accountId = account.getId(); Stack syncedStack = dataBaseAdapter.getStack(accountId, syncedBoard.getLocalId(), stack.getId()); - for (Card c :stack.getCards()){ - DeckLog.log("requesting Card: "+c.getTitle()); + for (Card c : stack.getCards()) { + DeckLog.log("requesting Card: " + c.getTitle()); serverAdapter.getCard(accountId, syncedBoard.getId(), syncedStack.getId(), c.getId(), new IResponseCallback<Card>(account) { @Override public void onResponse(Card card) { @@ -129,7 +129,7 @@ public class SyncManager implements IDataBasePersistenceAdapter{ card.setStack(syncedStack); card.setStackId(syncedStack.getLocalId()); Card existingCard = dataBaseAdapter.getCard(accountId, card.getId()); - if (existingCard==null) { + if (existingCard == null) { DeckLog.log("creating Card..."); dataBaseAdapter.createCard(accountId, card); } else { @@ -146,12 +146,12 @@ public class SyncManager implements IDataBasePersistenceAdapter{ dataBaseAdapter.deleteJoinedUsersForCard(existingCard.getLocalId()); for (User user : assignedUsers) { User existingUser = dataBaseAdapter.getUser(accountId, user.getId()); - if (existingUser == null){ - DeckLog.log("creating user: "+user.getUid()); + if (existingUser == null) { + DeckLog.log("creating user: " + user.getUid()); dataBaseAdapter.createUser(accountId, user); existingUser = dataBaseAdapter.getUser(accountId, user.getId()); } else { - DeckLog.log("updating user: "+user.getUid()); + DeckLog.log("updating user: " + user.getUid()); existingUser = applyUpdatesFromRemote(existingUser, user, accountId); dataBaseAdapter.updateUser(accountId, existingUser); } @@ -162,11 +162,11 @@ public class SyncManager implements IDataBasePersistenceAdapter{ dataBaseAdapter.deleteJoinedLabelsForCard(existingCard.getLocalId()); for (Label label : labels) { Label existingLabel = dataBaseAdapter.getLabel(accountId, label.getId()); - if (existingLabel == null){ - DeckLog.log("creating Label: "+label.getTitle()); + if (existingLabel == null) { + DeckLog.log("creating Label: " + label.getTitle()); dataBaseAdapter.createLabel(accountId, label); } else { - DeckLog.log("updating Label: "+label.getTitle()); + DeckLog.log("updating Label: " + label.getTitle()); existingLabel = applyUpdatesFromRemote(existingLabel, label, accountId); dataBaseAdapter.updateLabel(accountId, existingLabel); } @@ -186,15 +186,16 @@ public class SyncManager implements IDataBasePersistenceAdapter{ }); } } + private <T> IResponseCallback<T> wrapCallForUi(IResponseCallback<T> responseCallback) { Account account = responseCallback.getAccount(); - if (account == null || account.getId() == null){ + if (account == null || account.getId() == null) { throw new IllegalArgumentException("Bro. Please just give me a damn Account!"); } return new IResponseCallback<T>(responseCallback.getAccount()) { @Override public void onResponse(T response) { - sourceActivity.runOnUiThread(()->{ + sourceActivity.runOnUiThread(() -> { fillAccountIDs(response); responseCallback.onResponse(response); }); @@ -208,7 +209,7 @@ public class SyncManager implements IDataBasePersistenceAdapter{ } private <T extends RemoteEntity> T applyUpdatesFromRemote(T localEntity, T remoteEntity, Long accountId) { - if(!localEntity.getId().equals(remoteEntity.getId()) + if (!localEntity.getId().equals(remoteEntity.getId()) || !accountId.equals(localEntity.getAccount().getId())) { throw new IllegalArgumentException("IDs of Account or Entity are not matching! WTF are you doin?!"); } @@ -222,7 +223,7 @@ public class SyncManager implements IDataBasePersistenceAdapter{ } @Override - public Account createAccount(String accoutName) { + public LiveData<Account> createAccount(String accoutName) { return dataBaseAdapter.createAccount(accoutName); } @@ -237,12 +238,12 @@ public class SyncManager implements IDataBasePersistenceAdapter{ } @Override - public Account readAccount(long id) { + public LiveData<Account> readAccount(long id) { return dataBaseAdapter.readAccount(id); } @Override - public List<Account> readAccounts() { + public LiveData<List<Account>> readAccounts() { return dataBaseAdapter.readAccounts(); } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/IDataBasePersistenceAdapter.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/IDataBasePersistenceAdapter.java index c6b138b8c..2fa314acb 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/IDataBasePersistenceAdapter.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/IDataBasePersistenceAdapter.java @@ -1,20 +1,35 @@ package it.niedermann.nextcloud.deck.persistence.sync.adapters; +import android.arch.lifecycle.LiveData; + import java.util.List; +import it.niedermann.nextcloud.deck.api.IResponseCallback; import it.niedermann.nextcloud.deck.model.Account; +import it.niedermann.nextcloud.deck.model.Board; +import it.niedermann.nextcloud.deck.model.Stack; +import it.niedermann.nextcloud.deck.model.full.FullCard; public interface IDataBasePersistenceAdapter extends IPersistenceAdapter { boolean hasAccounts(); - Account createAccount(String accoutName); + LiveData<Account> createAccount(String accoutName); void deleteAccount(long id); void updateAccount(Account account); - Account readAccount(long id); + LiveData<Account> readAccount(long id); + + LiveData<List<Account>> readAccounts(); + + + void getStacks(long accountId, long boardId, IResponseCallback<LiveData<List<Stack>>> responseCallback); + + void getStack(long accountId, long boardId, long stackId, IResponseCallback<LiveData<Stack>> responseCallback); + + void getBoards(long accountId, IResponseCallback<LiveData<List<Board>>> responseCallback); - List<Account> readAccounts(); + void getCard(long accountId, long boardId, long stackId, long cardId, IResponseCallback<LiveData<FullCard>> responseCallback); } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/IPersistenceAdapter.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/IPersistenceAdapter.java index 10fe0f9bb..fc69b5fa2 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/IPersistenceAdapter.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/IPersistenceAdapter.java @@ -1,8 +1,5 @@ package it.niedermann.nextcloud.deck.persistence.sync.adapters; -import java.util.List; - -import it.niedermann.nextcloud.deck.api.IResponseCallback; import it.niedermann.nextcloud.deck.model.Board; import it.niedermann.nextcloud.deck.model.Card; import it.niedermann.nextcloud.deck.model.Stack; @@ -10,21 +7,23 @@ import it.niedermann.nextcloud.deck.model.Stack; public interface IPersistenceAdapter { //### STACKS - void getStacks(long accountId, long boardId, IResponseCallback<List<Stack>> responseCallback); - void getStack(long accountId, long boardId, long stackId, IResponseCallback<Stack> responseCallback); void createStack(long accountId, Stack stack); + void deleteStack(Stack stack); + void updateStack(Stack stack); //### BOARDS - void getBoards(long accountId, IResponseCallback<List<Board>> responseCallback); void createBoard(long accountId, Board board); + void deleteBoard(Board board); + void updateBoard(Board board); //### CARDS - void getCard(long accountId, long boardId, long stackId, long cardId, IResponseCallback<Card> responseCallback); void createCard(long accountId, Card card); + void deleteCard(Card card); + void updateCard(Card card); } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/ServerAdapter.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/ServerAdapter.java index a395c45f8..8a4de2ac0 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/ServerAdapter.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/ServerAdapter.java @@ -16,7 +16,7 @@ import it.niedermann.nextcloud.deck.model.Board; import it.niedermann.nextcloud.deck.model.Card; import it.niedermann.nextcloud.deck.model.Stack; -public class ServerAdapter implements IPersistenceAdapter { +public class ServerAdapter implements IPersistenceAdapter { private Context applicationContext; private ApiProvider provider; @@ -40,7 +40,7 @@ public class ServerAdapter implements IPersistenceAdapter { } @Override - public void getBoards(long accountId, IResponseCallback<List<Board>> responseCallback) { + public void getBoards(long accountId, List<Board> responseCallback) { RequestHelper.request(sourceActivity, provider, () -> provider.getAPI().getBoards(getLastSync()), responseCallback); } 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 b30309e19..fe68bbb20 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 @@ -1,38 +1,29 @@ package it.niedermann.nextcloud.deck.persistence.sync.adapters.db; -import android.arch.persistence.room.Room; +import android.arch.lifecycle.LiveData; import android.content.Context; -import org.greenrobot.greendao.query.QueryBuilder; - import java.util.List; import it.niedermann.nextcloud.deck.DeckLog; import it.niedermann.nextcloud.deck.api.IResponseCallback; import it.niedermann.nextcloud.deck.model.Account; import it.niedermann.nextcloud.deck.model.Board; -import it.niedermann.nextcloud.deck.model.BoardDao; import it.niedermann.nextcloud.deck.model.Card; -import it.niedermann.nextcloud.deck.model.CardDao; -import it.niedermann.nextcloud.deck.model.DaoSession; import it.niedermann.nextcloud.deck.model.JoinCardWithLabel; -import it.niedermann.nextcloud.deck.model.JoinCardWithLabelDao; import it.niedermann.nextcloud.deck.model.JoinCardWithUser; -import it.niedermann.nextcloud.deck.model.JoinCardWithUserDao; import it.niedermann.nextcloud.deck.model.JoinStackWithCard; -import it.niedermann.nextcloud.deck.model.JoinStackWithCardDao; import it.niedermann.nextcloud.deck.model.Label; -import it.niedermann.nextcloud.deck.model.LabelDao; import it.niedermann.nextcloud.deck.model.Stack; -import it.niedermann.nextcloud.deck.model.StackDao; import it.niedermann.nextcloud.deck.model.User; -import it.niedermann.nextcloud.deck.model.UserDao; -import it.niedermann.nextcloud.deck.persistence.DeckDaoSession; +import it.niedermann.nextcloud.deck.model.full.FullCard; +import it.niedermann.nextcloud.deck.persistence.sync.adapters.db.dao.CardDao; +import it.niedermann.nextcloud.deck.persistence.sync.adapters.db.dao.StackDao; public class DataBaseAdapter implements IDatabaseOnlyAdapter { - private interface DataAccessor <T> { + private interface DataAccessor<T> { T getData(); } @@ -42,37 +33,35 @@ public class DataBaseAdapter implements IDatabaseOnlyAdapter { public DataBaseAdapter(Context applicationContext) { this.applicationContext = applicationContext; - this.db = DeckDatabase.getInstance(applicationContext); + this.db = DeckDatabase.getInstance(applicationContext); } - private <T> void respond(IResponseCallback<T> responseCallback, DataAccessor<T> r){ + private <T> void respond(IResponseCallback<T> responseCallback, DataAccessor<T> r) { new Thread(() -> responseCallback.onResponse(r.getData())).start(); } @Override public boolean hasAccounts() { - return db.getAccountDao().countAccounts()>0; + return db.getAccountDao().countAccounts() > 0; } @Override - public Board getBoard(long accountId, long remoteId) { + public LiveData<Board> getBoard(long accountId, long remoteId) { return db.getBoardDao().getBoardByRemoteId(accountId, remoteId); } @Override - public Stack getStack(long accountId, long localBoardId, long remoteId) { - QueryBuilder<Stack> qb = db.getStackDao().queryBuilder(); - return qb.where(StackDao.Properties.AccountId.eq(accountId), StackDao.Properties.BoardId.eq(localBoardId), StackDao.Properties.Id.eq(remoteId)).unique(); + public LiveData<Stack> getStack(long accountId, long localBoardId, long remoteId) { + return db.getStackDao().getStackByRemoteId(accountId, localBoardId, remoteId); } @Override - public Card getCard(long accountId, long remoteId) { - QueryBuilder<Card> qb = db.getCardDao().queryBuilder(); - return qb.where(CardDao.Properties.AccountId.eq(accountId), CardDao.Properties.Id.eq(remoteId)).unique(); + public LiveData<Card> getCard(long accountId, long remoteId) { + return db.getCardDao().getCardByRemoteId(accountId, remoteId); } @Override - public User getUser(long accountId, long remoteId) { + public LiveData<User> getUser(long accountId, long remoteId) { return db.getUserDao().getUsersByRemoteId(accountId, remoteId); } @@ -90,8 +79,7 @@ public class DataBaseAdapter implements IDatabaseOnlyAdapter { @Override public Label getLabel(long accountId, long remoteId) { - QueryBuilder<Label> qb = db.getLabelDao().queryBuilder(); - return qb.where(LabelDao.Properties.AccountId.eq(accountId), LabelDao.Properties.Id.eq(remoteId)).unique(); + return db.getLabelDao().getLabelByRemoteId(accountId, remoteId); } @Override @@ -110,7 +98,7 @@ public class DataBaseAdapter implements IDatabaseOnlyAdapter { @Override public void deleteJoinedLabelsForCard(long localCardId) { - db.getJoinCardWithLabelDao().queryBuilder().where(JoinCardWithLabelDao.Properties.CardId.eq(localCardId)).buildDelete().executeDeleteWithoutDetachingEntities(); + db.getJoinCardWithLabelDao().deleteByCardId(localCardId); } @Override @@ -123,7 +111,7 @@ public class DataBaseAdapter implements IDatabaseOnlyAdapter { @Override public void deleteJoinedUsersForCard(long localCardId) { - db.getJoinCardWithUserDao().queryBuilder().where(JoinCardWithUserDao.Properties.CardId.eq(localCardId)).buildDelete().executeDeleteWithoutDetachingEntities(); + db.getJoinCardWithUserDao().deleteByCardId(localCardId); } @Override @@ -136,7 +124,7 @@ public class DataBaseAdapter implements IDatabaseOnlyAdapter { @Override public void deleteJoinedCardsForStack(long localStackId) { - db.getJoinStackWithCardDao().queryBuilder().where(JoinStackWithCardDao.Properties.StackId.eq(localStackId)).buildDelete().executeDeleteWithoutDetachingEntities(); + db.getJoinStackWithCardDao().deleteByStackId(localStackId); } @Override @@ -146,16 +134,16 @@ public class DataBaseAdapter implements IDatabaseOnlyAdapter { } @Override - public Account createAccount(String accoutName) { + public LiveData<Account> createAccount(String accoutName) { Account acc = new Account(); acc.setName(accoutName); long id = db.getAccountDao().insert(acc); - return db.getAccountDao().load(id); + return readAccount(id); } @Override public void deleteAccount(long id) { - db.getAccountDao().deleteByKey(id); + db.getAccountDao().deleteById(id); } @Override @@ -164,21 +152,18 @@ public class DataBaseAdapter implements IDatabaseOnlyAdapter { } @Override - public Account readAccount(long id) { - return db.getAccountDao().load(id); + public LiveData<Account> readAccount(long id) { + return db.getAccountDao().selectById(id); } @Override - public List<Account> readAccounts() { - return db.getAccountDao().loadAll(); + public LiveData<List<Account>> readAccounts() { + return db.getAccountDao().selectAll(); } @Override - public void getBoards(long accountId, IResponseCallback<List<Board>> responseCallback) { - QueryBuilder<Board> qb = db.getBoardDao().queryBuilder(); - respond(responseCallback, () -> qb.where( - BoardDao.Properties.AccountId.eq(accountId) - ).list()); + public void getBoards(long accountId, IResponseCallback<LiveData<List<Board>>> responseCallback) { + respond(responseCallback, () -> db.getBoardDao().getBoardsForAccount(accountId)); } @Override @@ -196,20 +181,15 @@ public class DataBaseAdapter implements IDatabaseOnlyAdapter { @Override public void updateBoard(Board board) { db.getBoardDao().update(board); - } @Override - public void getStacks(long accountId, long boardId, IResponseCallback<List<Stack>> responseCallback) { - QueryBuilder<Stack> qb = db.getStackDao().queryBuilder(); - respond(responseCallback, () -> qb.where( - StackDao.Properties.AccountId.eq(accountId), - StackDao.Properties.BoardId.eq(boardId) - ).list()); + public void getStacks(long accountId, long localBoardId, IResponseCallback<LiveData<List<Stack>>> responseCallback) { + respond(responseCallback, () -> db.getStackDao().getStacksForBoard(accountId, localBoardId)); } @Override - public void getStack(long accountId, long localBoardId, long stackId, IResponseCallback<Stack> responseCallback) { + public void getStack(long accountId, long localBoardId, long stackId, IResponseCallback<LiveData<Stack>> responseCallback) { QueryBuilder<Stack> qb = db.getStackDao().queryBuilder(); respond(responseCallback, () -> { Stack stack = qb.where( @@ -218,8 +198,8 @@ public class DataBaseAdapter implements IDatabaseOnlyAdapter { StackDao.Properties.LocalId.eq(stackId) ).unique(); // eager preload - for (Card c : stack.getCards()){ - DeckLog.log("labels for card "+c.getTitle()+": "+c.getLabels().size()); + for (Card c : stack.getCards()) { + DeckLog.log("labels for card " + c.getTitle() + ": " + c.getLabels().size()); c.getAssignedUsers(); c.getLabels(); } @@ -247,21 +227,21 @@ public class DataBaseAdapter implements IDatabaseOnlyAdapter { } @Override - public void getCard(long accountId, long boardId, long stackId, long cardId, IResponseCallback<Card> responseCallback) { + public void getCard(long accountId, long boardId, long stackId, long cardId, IResponseCallback<LiveData<FullCard>> responseCallback) { QueryBuilder<Card> qb = db.getCardDao().queryBuilder(); respond(responseCallback, () -> { - Card card = qb.where( - CardDao.Properties.AccountId.eq(accountId), - CardDao.Properties.StackId.eq(stackId), - CardDao.Properties.LocalId.eq(cardId) - ).unique(); - - //preload eager - card.getLabels(); - card.getAssignedUsers(); - DeckLog.log(card.getLabels().size()+""); - return card; - } + Card card = qb.where( + CardDao.Properties.AccountId.eq(accountId), + CardDao.Properties.StackId.eq(stackId), + CardDao.Properties.LocalId.eq(cardId) + ).unique(); + + //preload eager + card.getLabels(); + card.getAssignedUsers(); + DeckLog.log(card.getLabels().size() + ""); + return card; + } ); } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/DateTypeConverter.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/DateTypeConverter.java new file mode 100644 index 000000000..5605fe383 --- /dev/null +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/DateTypeConverter.java @@ -0,0 +1,18 @@ +package it.niedermann.nextcloud.deck.persistence.sync.adapters.db; + +import android.arch.persistence.room.TypeConverter; + +import java.util.Date; + +public class DateTypeConverter { + + @TypeConverter + public static Date toDate(Long value) { + return value == null ? null : new Date(value); + } + + @TypeConverter + public static Long toLong(Date value) { + return value == null ? null : value.getTime(); + } +}
\ No newline at end of file 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 92fe723a7..1c4ff801f 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 @@ -3,6 +3,7 @@ package it.niedermann.nextcloud.deck.persistence.sync.adapters.db; import android.arch.persistence.room.Database; import android.arch.persistence.room.Room; import android.arch.persistence.room.RoomDatabase; +import android.arch.persistence.room.TypeConverters; import android.content.Context; import it.niedermann.nextcloud.deck.model.Account; @@ -20,6 +21,16 @@ import it.niedermann.nextcloud.deck.model.Stack; import it.niedermann.nextcloud.deck.model.User; import it.niedermann.nextcloud.deck.persistence.sync.adapters.db.dao.AccountDao; import it.niedermann.nextcloud.deck.persistence.sync.adapters.db.dao.BoardDao; +import it.niedermann.nextcloud.deck.persistence.sync.adapters.db.dao.CardDao; +import it.niedermann.nextcloud.deck.persistence.sync.adapters.db.dao.JoinBoardWithLabelDao; +import it.niedermann.nextcloud.deck.persistence.sync.adapters.db.dao.JoinBoardWithPermissionDao; +import it.niedermann.nextcloud.deck.persistence.sync.adapters.db.dao.JoinBoardWithUserDao; +import it.niedermann.nextcloud.deck.persistence.sync.adapters.db.dao.JoinCardWithLabelDao; +import it.niedermann.nextcloud.deck.persistence.sync.adapters.db.dao.JoinCardWithUserDao; +import it.niedermann.nextcloud.deck.persistence.sync.adapters.db.dao.JoinStackWithCardDao; +import it.niedermann.nextcloud.deck.persistence.sync.adapters.db.dao.LabelDao; +import it.niedermann.nextcloud.deck.persistence.sync.adapters.db.dao.PermissionDao; +import it.niedermann.nextcloud.deck.persistence.sync.adapters.db.dao.StackDao; import it.niedermann.nextcloud.deck.persistence.sync.adapters.db.dao.UserDao; @Database( @@ -41,6 +52,7 @@ import it.niedermann.nextcloud.deck.persistence.sync.adapters.db.dao.UserDao; }, version = 1 ) +@TypeConverters({DateTypeConverter.class}) public abstract class DeckDatabase extends RoomDatabase { @@ -65,25 +77,25 @@ public abstract class DeckDatabase extends RoomDatabase { public abstract BoardDao getBoardDao(); -// public abstract CardDao getCardDao(); -// -// public abstract JoinBoardWithLabelDao getJoinBoardWithLabelDao(); -// -// public abstract JoinBoardWithPermissionDao getJoinBoardWithPermissionDao(); -// -// public abstract JoinBoardWithUserDao getJoinBoardWithUserDao(); -// -// public abstract JoinCardWithLabelDao getJoinCardWithLabelDao(); -// -// public abstract JoinCardWithUserDao getJoinCardWithUserDao(); -// -// public abstract JoinStackWithCardDao getJoinStackWithCardDao(); -// -// public abstract LabelDao getLabelDao(); -// -// public abstract PermissionDao getPermissionDao(); -// -// public abstract StackDao getStackDao(); + public abstract CardDao getCardDao(); + + public abstract JoinBoardWithLabelDao getJoinBoardWithLabelDao(); + + public abstract JoinBoardWithPermissionDao getJoinBoardWithPermissionDao(); + + public abstract JoinBoardWithUserDao getJoinBoardWithUserDao(); + + public abstract JoinCardWithLabelDao getJoinCardWithLabelDao(); + + public abstract JoinCardWithUserDao getJoinCardWithUserDao(); + + public abstract JoinStackWithCardDao getJoinStackWithCardDao(); + + public abstract LabelDao getLabelDao(); + + public abstract PermissionDao getPermissionDao(); + + public abstract StackDao getStackDao(); public abstract UserDao getUserDao(); }
\ No newline at end of file diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/IDatabaseOnlyAdapter.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/IDatabaseOnlyAdapter.java index 6a7a4cc83..2642a480e 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/IDatabaseOnlyAdapter.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/IDatabaseOnlyAdapter.java @@ -1,5 +1,7 @@ package it.niedermann.nextcloud.deck.persistence.sync.adapters.db; +import android.arch.lifecycle.LiveData; + import it.niedermann.nextcloud.deck.model.Board; import it.niedermann.nextcloud.deck.model.Card; import it.niedermann.nextcloud.deck.model.Label; @@ -8,12 +10,13 @@ import it.niedermann.nextcloud.deck.model.User; import it.niedermann.nextcloud.deck.persistence.sync.adapters.IDataBasePersistenceAdapter; public interface IDatabaseOnlyAdapter extends IDataBasePersistenceAdapter { - Board getBoard(long accountId, long remoteId); + LiveData<Board> getBoard(long accountId, long remoteId); + + LiveData<Stack> getStack(long accountId, long localBoardId, long remoteId); - Stack getStack(long accountId, long localBoardId, long remoteId); - Card getCard(long accountId, long remoteId); + LiveData<Card> getCard(long accountId, long remoteId); - User getUser(long accountId, long remoteId); + LiveData<User> getUser(long accountId, long remoteId); void createUser(long accountId, User user); @@ -22,11 +25,17 @@ public interface IDatabaseOnlyAdapter extends IDataBasePersistenceAdapter { Label getLabel(long accountId, long remoteId); void createLabel(long accountId, Label label); + void createJoinCardWithLabel(long localLabelId, long localCardId); + void deleteJoinedLabelsForCard(long localCardId); + void createJoinCardWithUser(long localUserId, long localCardId); + void deleteJoinedUsersForCard(long localCardId); + void createJoinStackWithCard(long localCardId, long localStackId); + void deleteJoinedCardsForStack(long localStackId); diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/AccountDao.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/AccountDao.java index 41cf2d74b..6c156612e 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/AccountDao.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/AccountDao.java @@ -1,23 +1,28 @@ package it.niedermann.nextcloud.deck.persistence.sync.adapters.db.dao; +import android.arch.lifecycle.LiveData; import android.arch.persistence.room.Dao; -import android.arch.persistence.room.Delete; -import android.arch.persistence.room.Insert; import android.arch.persistence.room.Query; -import android.arch.persistence.room.Update; -import java.util.Set; +import java.util.List; import it.niedermann.nextcloud.deck.model.Account; -import it.niedermann.nextcloud.deck.model.User; @Dao public interface AccountDao extends GenericDao<Account> { @Query("SELECT * FROM account") - Set<Account> getAccounts(); + LiveData<List<Account>> getAccounts(); @Query("SELECT count(*) FROM account") int countAccounts(); + @Query("DELETE from account where id = :id") + void deleteById(long id); + + @Query("SELECT * from account where id = :id") + LiveData<Account> selectById(long id); + + @Query("SELECT * from account") + LiveData<List<Account>> selectAll(); }
\ No newline at end of file diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/BoardDao.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/BoardDao.java index 155a51b00..690b26166 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/BoardDao.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/BoardDao.java @@ -1,24 +1,20 @@ package it.niedermann.nextcloud.deck.persistence.sync.adapters.db.dao; +import android.arch.lifecycle.LiveData; import android.arch.persistence.room.Dao; -import android.arch.persistence.room.Delete; -import android.arch.persistence.room.Insert; import android.arch.persistence.room.Query; -import android.arch.persistence.room.Update; import java.util.List; -import java.util.Set; import it.niedermann.nextcloud.deck.model.Board; -import it.niedermann.nextcloud.deck.model.User; @Dao public interface BoardDao extends GenericDao<Board> { @Query("SELECT * FROM board WHERE accountId = :accountId") - Set<Board> getBoardsForAccount(final long accountId); + LiveData<List<Board>> getBoardsForAccount(final long accountId); @Query("SELECT * FROM board WHERE accountId = :accountId and id = :remoteId") - Board getBoardByRemoteId(final long accountId, final long remoteId); + LiveData<Board> getBoardByRemoteId(final long accountId, final long remoteId); }
\ No newline at end of file diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/CardDao.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/CardDao.java new file mode 100644 index 000000000..2b7aa5c5a --- /dev/null +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/CardDao.java @@ -0,0 +1,20 @@ +package it.niedermann.nextcloud.deck.persistence.sync.adapters.db.dao; + +import android.arch.lifecycle.LiveData; +import android.arch.persistence.room.Dao; +import android.arch.persistence.room.Query; + +import java.util.List; + +import it.niedermann.nextcloud.deck.model.Card; + +@Dao +public interface CardDao extends GenericDao<Card> { + + @Query("SELECT * FROM card WHERE stackId = :localStackId") + LiveData<List<Card>> getCardsForStack(final long localStackId); + + @Query("SELECT * FROM card WHERE accountId = :accountId and id = :remoteId") + LiveData<Card> getCardByRemoteId(final long accountId, final long remoteId); + +}
\ No newline at end of file diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/GenericDao.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/GenericDao.java index 298ac51a3..7a96ac0c1 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/GenericDao.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/GenericDao.java @@ -4,14 +4,17 @@ import android.arch.persistence.room.Delete; import android.arch.persistence.room.Insert; import android.arch.persistence.room.Update; -public interface GenericDao <T>{ +public interface GenericDao<T> { @Insert long insert(T entity); + @Insert - long [] insert(T... entity); + long[] insert(T... entity); + @Update void update(T... entity); + @Delete void delete(T... entity); } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/JoinBoardWithLabelDao.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/JoinBoardWithLabelDao.java new file mode 100644 index 000000000..990ccd89b --- /dev/null +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/JoinBoardWithLabelDao.java @@ -0,0 +1,12 @@ +package it.niedermann.nextcloud.deck.persistence.sync.adapters.db.dao; + +import android.arch.persistence.room.Dao; +import android.arch.persistence.room.Query; + +import it.niedermann.nextcloud.deck.model.JoinBoardWithLabel; + +@Dao +public interface JoinBoardWithLabelDao extends GenericDao<JoinBoardWithLabel> { + @Query("DELETE FROM joinboardwithlabel WHERE boardId = :localId") + void deleteByBoardId(long localId); +}
\ No newline at end of file diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/JoinBoardWithPermissionDao.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/JoinBoardWithPermissionDao.java new file mode 100644 index 000000000..f4def3c2f --- /dev/null +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/JoinBoardWithPermissionDao.java @@ -0,0 +1,13 @@ +package it.niedermann.nextcloud.deck.persistence.sync.adapters.db.dao; + +import android.arch.persistence.room.Dao; +import android.arch.persistence.room.Query; + +import it.niedermann.nextcloud.deck.model.JoinBoardWithPermission; + +@Dao +public interface JoinBoardWithPermissionDao extends GenericDao<JoinBoardWithPermission> { + @Query("DELETE FROM joinboardwithpermission WHERE boardId = :localId") + void deleteByBoardId(long localId); + +}
\ No newline at end of file diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/JoinBoardWithUserDao.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/JoinBoardWithUserDao.java new file mode 100644 index 000000000..488b61e35 --- /dev/null +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/JoinBoardWithUserDao.java @@ -0,0 +1,13 @@ +package it.niedermann.nextcloud.deck.persistence.sync.adapters.db.dao; + +import android.arch.persistence.room.Dao; +import android.arch.persistence.room.Query; + +import it.niedermann.nextcloud.deck.model.JoinBoardWithUser; + +@Dao +public interface JoinBoardWithUserDao extends GenericDao<JoinBoardWithUser> { + @Query("DELETE FROM joinboardwithuser WHERE boardId = :localId") + void deleteByBoardId(long localId); + +}
\ No newline at end of file diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/JoinCardWithLabelDao.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/JoinCardWithLabelDao.java new file mode 100644 index 000000000..233ec95f7 --- /dev/null +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/JoinCardWithLabelDao.java @@ -0,0 +1,12 @@ +package it.niedermann.nextcloud.deck.persistence.sync.adapters.db.dao; + +import android.arch.persistence.room.Dao; +import android.arch.persistence.room.Query; + +import it.niedermann.nextcloud.deck.model.JoinCardWithLabel; + +@Dao +public interface JoinCardWithLabelDao extends GenericDao<JoinCardWithLabel> { + @Query("DELETE FROM joincardwithlabel WHERE cardId = :localId") + void deleteByCardId(long localId); +}
\ No newline at end of file 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 new file mode 100644 index 000000000..5316ef787 --- /dev/null +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/JoinCardWithUserDao.java @@ -0,0 +1,13 @@ +package it.niedermann.nextcloud.deck.persistence.sync.adapters.db.dao; + +import android.arch.persistence.room.Dao; +import android.arch.persistence.room.Query; + +import it.niedermann.nextcloud.deck.model.JoinCardWithUser; + +@Dao +public interface JoinCardWithUserDao extends GenericDao<JoinCardWithUser> { + @Query("DELETE FROM joincardwithuser WHERE cardId = :localId") + void deleteByCardId(long localId); + +}
\ No newline at end of file diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/JoinStackWithCardDao.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/JoinStackWithCardDao.java new file mode 100644 index 000000000..969b9ebb7 --- /dev/null +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/JoinStackWithCardDao.java @@ -0,0 +1,13 @@ +package it.niedermann.nextcloud.deck.persistence.sync.adapters.db.dao; + +import android.arch.persistence.room.Dao; +import android.arch.persistence.room.Query; + +import it.niedermann.nextcloud.deck.model.JoinStackWithCard; + +@Dao +public interface JoinStackWithCardDao extends GenericDao<JoinStackWithCard> { + @Query("DELETE FROM joinstackwithcard WHERE stackId = :localId") + void deleteByStackId(long localId); +} + 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 new file mode 100644 index 000000000..98b92cb1a --- /dev/null +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/LabelDao.java @@ -0,0 +1,17 @@ +package it.niedermann.nextcloud.deck.persistence.sync.adapters.db.dao; + +import android.arch.persistence.room.Dao; +import android.arch.persistence.room.Query; + +import it.niedermann.nextcloud.deck.model.Label; + +@Dao +public interface LabelDao extends GenericDao<Label> { + +// @Query("SELECT * FROM label WHERE stackId = :localStackId") +// LiveData<List<Label>> getLabelsForStack(final long localStackId); + + @Query("SELECT * FROM label WHERE accountId = :accountId and id = :remoteId") + Label getLabelByRemoteId(final long accountId, final long remoteId); + +}
\ No newline at end of file diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/PermissionDao.java b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/PermissionDao.java new file mode 100644 index 000000000..e7ae48edf --- /dev/null +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/PermissionDao.java @@ -0,0 +1,10 @@ +package it.niedermann.nextcloud.deck.persistence.sync.adapters.db.dao; + +import android.arch.persistence.room.Dao; + +import it.niedermann.nextcloud.deck.model.Permission; + +@Dao +public interface PermissionDao extends GenericDao<Permission> { +} + 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 new file mode 100644 index 000000000..4d803354f --- /dev/null +++ b/app/src/main/java/it/niedermann/nextcloud/deck/persistence/sync/adapters/db/dao/StackDao.java @@ -0,0 +1,20 @@ +package it.niedermann.nextcloud.deck.persistence.sync.adapters.db.dao; + +import android.arch.lifecycle.LiveData; +import android.arch.persistence.room.Dao; +import android.arch.persistence.room.Query; + +import java.util.List; + +import it.niedermann.nextcloud.deck.model.Stack; + +@Dao +public interface StackDao extends GenericDao<Stack> { + + @Query("SELECT * FROM stack WHERE accountId = :accountId AND boardId = :localBoardId") + LiveData<List<Stack>> getStacksForBoard(final long accountId, final long localBoardId); + + @Query("SELECT * FROM stack WHERE accountId = :accountId and boardId = :localBoardId and id = :remoteId") + LiveData<Stack> getStackByRemoteId(final long accountId, final long localBoardId, final long remoteId); + +}
\ No newline at end of file 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 5e8d38d38..4f06365da 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 @@ -1,13 +1,10 @@ package it.niedermann.nextcloud.deck.persistence.sync.adapters.db.dao; +import android.arch.lifecycle.LiveData; import android.arch.persistence.room.Dao; -import android.arch.persistence.room.Delete; -import android.arch.persistence.room.Insert; import android.arch.persistence.room.Query; -import android.arch.persistence.room.Update; import java.util.List; -import java.util.Set; import it.niedermann.nextcloud.deck.model.User; @@ -15,9 +12,9 @@ import it.niedermann.nextcloud.deck.model.User; public interface UserDao extends GenericDao<User> { @Query("SELECT * FROM user WHERE accountId = :accountId") - Set<User> getUsersForAccount(final long accountId); + LiveData<List<User>> getUsersForAccount(final long accountId); @Query("SELECT * FROM user WHERE accountId = :accountId and id = :remoteId") - User getUsersByRemoteId(final long accountId, final long remoteId); + LiveData<User> getUsersByRemoteId(final long accountId, final long remoteId); }
\ No newline at end of file diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/helper/dnd/IDragLeftRight.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/helper/dnd/IDragLeftRight.java index 058da7dba..ceaa9f5b3 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/helper/dnd/IDragLeftRight.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/helper/dnd/IDragLeftRight.java @@ -1,7 +1,8 @@ package it.niedermann.nextcloud.deck.ui.helper.dnd; -public interface IDragLeftRight <T> { +public interface IDragLeftRight<T> { void itemSwipedRight(T item); + void itemSwipedLeft(T item); } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/helper/dnd/IDragUpDown.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/helper/dnd/IDragUpDown.java index 73f0a001b..57758897a 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/helper/dnd/IDragUpDown.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/helper/dnd/IDragUpDown.java @@ -1,7 +1,8 @@ package it.niedermann.nextcloud.deck.ui.helper.dnd; -public interface IDragUpDown<T> { +public interface IDragUpDown<T> { void itemSwipedUp(T item); + void itemSwipedDown(T item); } |