diff options
Diffstat (limited to 'app/src/main/java/it/niedermann/nextcloud/deck')
11 files changed, 201 insertions, 30 deletions
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/api/ApiProvider.java b/app/src/main/java/it/niedermann/nextcloud/deck/api/ApiProvider.java index 3ea636d62..9d2b19ea4 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/api/ApiProvider.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/api/ApiProvider.java @@ -18,9 +18,11 @@ import retrofit2.NextcloudRetrofitApiBuilder; public class ApiProvider { - private static final String API_ENDPOINT = "/index.php/apps/deck/api/v1.0/"; + private static final String DECK_API_ENDPOINT = "/index.php/apps/deck/api/v1.0/"; + private static final String NC_API_ENDPOINT = "/ocs/v2.php/"; - private DeckAPI mApi; + private DeckAPI deckAPI; + private NextcloudServerAPI nextcloudAPI; private Context context; private SingleSignOnAccount ssoAccount; @@ -32,8 +34,8 @@ public class ApiProvider { try { setAccount(); NextcloudAPI nextcloudAPI = new NextcloudAPI(context, ssoAccount, GsonConfig.getGson(), callback); - //mApi = new DeckAPI_SSO(nextcloudAPI); - mApi = new NextcloudRetrofitApiBuilder(nextcloudAPI, API_ENDPOINT).create(DeckAPI.class); + deckAPI = new NextcloudRetrofitApiBuilder(nextcloudAPI, DECK_API_ENDPOINT).create(DeckAPI.class); + this.nextcloudAPI = new NextcloudRetrofitApiBuilder(nextcloudAPI, NC_API_ENDPOINT).create(NextcloudServerAPI.class); } catch (SSOException e) { DeckLog.logError(e); callback.onError(e); @@ -44,8 +46,12 @@ public class ApiProvider { ssoAccount = SingleAccountHelper.getCurrentSingleSignOnAccount(context); } - public DeckAPI getAPI() { - return mApi; + public DeckAPI getDeckAPI() { + return deckAPI; + } + + public NextcloudServerAPI getNextcloudAPI() { + return nextcloudAPI; } public String getServerUrl() throws NextcloudFilesAppAccountNotFoundException, NoCurrentAccountSelectedException { @@ -56,7 +62,7 @@ public class ApiProvider { } public String getApiPath(){ - return API_ENDPOINT; + return DECK_API_ENDPOINT; } public String getApiUrl() throws NextcloudFilesAppAccountNotFoundException, NoCurrentAccountSelectedException { diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/api/GsonConfig.java b/app/src/main/java/it/niedermann/nextcloud/deck/api/GsonConfig.java index 48d44c333..f796dfe16 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/api/GsonConfig.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/api/GsonConfig.java @@ -11,6 +11,7 @@ import it.niedermann.nextcloud.deck.model.Label; import it.niedermann.nextcloud.deck.model.full.FullBoard; import it.niedermann.nextcloud.deck.model.full.FullCard; import it.niedermann.nextcloud.deck.model.full.FullStack; +import it.niedermann.nextcloud.deck.model.ocs.Capabilities; /** * Created by david on 27.06.17. @@ -29,6 +30,8 @@ public class GsonConfig { Type label = new TypeToken<Label>() {}.getType(); Type stackList = new TypeToken<List<FullStack>>() {}.getType(); Type stack = new TypeToken<FullStack>() {}.getType(); + Type capabilities = new TypeToken<Capabilities>() {}.getType(); + Type capabilitiesList = new TypeToken<List<Capabilities>>() {}.getType(); return new GsonBuilder() .setDateFormat(DATE_PATTERN) @@ -41,6 +44,8 @@ public class GsonConfig { .registerTypeAdapter(label, new NextcloudDeserializer<>("label", Label.class)) .registerTypeAdapter(stackList, new NextcloudArrayDeserializer<>("stacks", FullStack.class)) .registerTypeAdapter(stack, new NextcloudDeserializer<>("stack", FullStack.class)) + .registerTypeAdapter(capabilitiesList, new NextcloudArrayDeserializer<>("capabilities", Capabilities.class)) + .registerTypeAdapter(capabilities, new NextcloudDeserializer<>("capability", Capabilities.class)) .create(); } 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 3dc853545..130d9aa22 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 @@ -27,6 +27,8 @@ import it.niedermann.nextcloud.deck.model.User; import it.niedermann.nextcloud.deck.model.full.FullBoard; import it.niedermann.nextcloud.deck.model.full.FullCard; import it.niedermann.nextcloud.deck.model.full.FullStack; +import it.niedermann.nextcloud.deck.model.ocs.Capabilities; +import it.niedermann.nextcloud.deck.model.ocs.Version; public class JsonToEntityParser { private static SimpleDateFormat formatter = new SimpleDateFormat(GsonConfig.DATE_PATTERN); @@ -44,6 +46,8 @@ public class JsonToEntityParser { return (T) parseStack(obj); } else if (mType == Label.class) { return (T) parseLabel(obj); + } else if (mType == Capabilities.class) { + return (T) parseCapabilities(obj); } throw new IllegalArgumentException("unregistered type: " + mType.getCanonicalName()); } @@ -230,6 +234,52 @@ public class JsonToEntityParser { return user; } + protected static Capabilities parseCapabilities(JsonObject e) { + DeckLog.log(e.toString()); + Capabilities capabilities = new Capabilities(); + + if (e.has("ocs")){ + JsonObject ocs = e.getAsJsonObject("ocs"); + if (ocs.has("data")) { + JsonObject data = ocs.getAsJsonObject("data"); + if (data.has("version")) { + JsonObject version = data.getAsJsonObject("version"); + int major = version.get("major").getAsInt(); + int minor = version.get("minor").getAsInt(); + int micro = version.get("micro").getAsInt(); + Version v = new Version(major, minor, micro); + capabilities.setNextcloudVersion(v); + } + + int major = 0, minor = 0, micro = 0; + if (data.has("capabilities")) { + JsonObject caps = data.getAsJsonObject("capabilities"); + if (caps.has("deck")) { + JsonObject deck = caps.getAsJsonObject("deck"); + if (deck.has("version")) { + String version = deck.get("version").getAsString(); + if (version != null && !version.trim().isEmpty()){ + String[] split = version.split("\\."); + if (split.length > 0){ + major = Integer.parseInt(split[0]); + if (split.length > 1) { + minor = Integer.parseInt(split[1]); + if (split.length > 2) { + micro = Integer.parseInt(split[2]); + } + } + } + } + } + } + } + capabilities.setDeckVersion(new Version(major, minor, micro)); + } + } + + return capabilities; + } + protected static FullStack parseStack(JsonObject e) { DeckLog.log(e.toString()); FullStack fullStack = new FullStack(); 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 4a5c6029c..3e18ae930 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 @@ -7,6 +7,8 @@ import com.google.gson.JsonParseException; import java.lang.reflect.Type; +import it.niedermann.nextcloud.deck.DeckLog; + /** * Created by david on 24.05.17. */ @@ -24,6 +26,7 @@ public class NextcloudDeserializer<T> implements JsonDeserializer<T> { @Override public T deserialize(final JsonElement json, final Type typeOfT, final JsonDeserializationContext context) throws JsonParseException { + DeckLog.log(json.toString()); return JsonToEntityParser.parseJsonObject(json.getAsJsonObject(), mType); } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/api/NextcloudServerAPI.java b/app/src/main/java/it/niedermann/nextcloud/deck/api/NextcloudServerAPI.java new file mode 100644 index 000000000..2d5da416d --- /dev/null +++ b/app/src/main/java/it/niedermann/nextcloud/deck/api/NextcloudServerAPI.java @@ -0,0 +1,12 @@ +package it.niedermann.nextcloud.deck.api; + + +import io.reactivex.Observable; +import it.niedermann.nextcloud.deck.model.ocs.Capabilities; +import retrofit2.http.GET; + +public interface NextcloudServerAPI { + + @GET("cloud/capabilities?format=json") + Observable<Capabilities> getCapabilities(); +} diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/api/RequestHelper.java b/app/src/main/java/it/niedermann/nextcloud/deck/api/RequestHelper.java index 3d91d2900..fcbe31acb 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/api/RequestHelper.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/api/RequestHelper.java @@ -12,7 +12,7 @@ public class RequestHelper { public static <T> void request(final Activity sourceActivity, final ApiProvider provider, final ObservableProvider<T> call, final IResponseCallback<T> callback){ - if (provider.getAPI() == null){ + if (provider.getDeckAPI() == null){ provider.initSsoApi(new NextcloudAPI.ApiConnectedListener() { @Override public void onConnected() { /* great, nothing to do. */} @Override 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 ec5b10a0d..13164ff60 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 @@ -48,7 +48,9 @@ public class Card extends AbstractRemoteEntity { @Ignore public Card(String title, String description, long stackId) { - + this.title = title; + this.description = description; + this.stackId = stackId; } public boolean isNotified() { diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/model/ocs/Capabilities.java b/app/src/main/java/it/niedermann/nextcloud/deck/model/ocs/Capabilities.java new file mode 100644 index 000000000..c4ad653a7 --- /dev/null +++ b/app/src/main/java/it/niedermann/nextcloud/deck/model/ocs/Capabilities.java @@ -0,0 +1,25 @@ +package it.niedermann.nextcloud.deck.model.ocs; + +public class Capabilities { + Version deckVersion; + Version nextcloudVersion; + + public Capabilities() { + } + + public Version getDeckVersion() { + return deckVersion; + } + + public void setDeckVersion(Version deckVersion) { + this.deckVersion = deckVersion; + } + + public Version getNextcloudVersion() { + return nextcloudVersion; + } + + public void setNextcloudVersion(Version nextcloudVersion) { + this.nextcloudVersion = nextcloudVersion; + } +} diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/model/ocs/Version.java b/app/src/main/java/it/niedermann/nextcloud/deck/model/ocs/Version.java new file mode 100644 index 000000000..c44d72b99 --- /dev/null +++ b/app/src/main/java/it/niedermann/nextcloud/deck/model/ocs/Version.java @@ -0,0 +1,59 @@ +package it.niedermann.nextcloud.deck.model.ocs; + +public class Version implements Comparable<Version>{ + private int major; + private int minor; + private int micro; + + public Version(int major, int minor, int micro) { + this.major = major; + this.minor = minor; + this.micro = micro; + } + + public int getMajor() { + return major; + } + + public void setMajor(int major) { + this.major = major; + } + + public int getMinor() { + return minor; + } + + public void setMinor(int minor) { + this.minor = minor; + } + + public int getMicro() { + return micro; + } + + public void setMicro(int micro) { + this.micro = micro; + } + + public boolean isGreaterOrEqualTo(Version v){ + return compareTo(v) >= 0; + } + + @Override + public int compareTo(Version o) { + if (o.getMajor() > getMajor()) { + return -1; + } else if (o.getMajor() < getMajor()) { + return 1; + } else if (o.getMinor() > getMinor()) { + return -1; + } else if (o.getMinor() < getMinor()) { + return 1; + } else if (o.getMicro() > getMicro()) { + return -1; + } else if (o.getMicro() < getMicro()) { + return 1; + } + return 0; + } +} 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 76984a5d1..d1aa8190e 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 @@ -25,6 +25,7 @@ import it.niedermann.nextcloud.deck.model.enums.DBStatus; import it.niedermann.nextcloud.deck.model.full.FullBoard; import it.niedermann.nextcloud.deck.model.full.FullCard; import it.niedermann.nextcloud.deck.model.full.FullStack; +import it.niedermann.nextcloud.deck.model.ocs.Capabilities; 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.util.WrappedLiveData; @@ -158,6 +159,10 @@ public class SyncManager { return dataBaseAdapter.readAccounts(); } + public void getServerVersion(IResponseCallback<Capabilities> callback){ + serverAdapter.getCapabilities(callback); + } + public LiveData<List<Board>> getBoards(long accountId) { return dataBaseAdapter.getBoards(accountId); } 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 b21eb2ce0..53c9aed37 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 @@ -29,6 +29,7 @@ import it.niedermann.nextcloud.deck.model.Stack; import it.niedermann.nextcloud.deck.model.full.FullBoard; import it.niedermann.nextcloud.deck.model.full.FullCard; import it.niedermann.nextcloud.deck.model.full.FullStack; +import it.niedermann.nextcloud.deck.model.ocs.Capabilities; import it.niedermann.nextcloud.deck.model.propagation.CardUpdate; import it.niedermann.nextcloud.deck.util.DateUtil; @@ -98,106 +99,109 @@ public class ServerAdapter { public void getBoards(IResponseCallback<List<FullBoard>> responseCallback) { RequestHelper.request(sourceActivity, provider, () -> - provider.getAPI().getBoards(true, getLastSyncDateFormatted(responseCallback.getAccount().getId())), + provider.getDeckAPI().getBoards(true, getLastSyncDateFormatted(responseCallback.getAccount().getId())), responseCallback); } + public void getCapabilities(IResponseCallback<Capabilities> responseCallback) { + ensureInternetConnection(); + RequestHelper.request(sourceActivity, provider, () -> provider.getNextcloudAPI().getCapabilities(), responseCallback); + } public void createBoard(Board board, IResponseCallback<FullBoard> responseCallback) { ensureInternetConnection(); - RequestHelper.request(sourceActivity, provider, () -> provider.getAPI().createBoard(board), responseCallback); + RequestHelper.request(sourceActivity, provider, () -> provider.getDeckAPI().createBoard(board), responseCallback); } public void deleteBoard(Board board, IResponseCallback<Void> responseCallback) { ensureInternetConnection(); - RequestHelper.request(sourceActivity, provider, () -> provider.getAPI().deleteBoard(board.getId()), responseCallback); + RequestHelper.request(sourceActivity, provider, () -> provider.getDeckAPI().deleteBoard(board.getId()), responseCallback); } public void updateBoard(Board board, IResponseCallback<FullBoard> responseCallback) { ensureInternetConnection(); - RequestHelper.request(sourceActivity, provider, () -> provider.getAPI().updateBoard(board.getId(), board), responseCallback); + RequestHelper.request(sourceActivity, provider, () -> provider.getDeckAPI().updateBoard(board.getId(), board), responseCallback); } public void getStacks(long boardId, IResponseCallback<List<FullStack>> responseCallback) { ensureInternetConnection(); - RequestHelper.request(sourceActivity, provider, () -> provider.getAPI().getStacks(boardId, getLastSyncDateFormatted(responseCallback.getAccount().getId())), responseCallback); + RequestHelper.request(sourceActivity, provider, () -> provider.getDeckAPI().getStacks(boardId, getLastSyncDateFormatted(responseCallback.getAccount().getId())), responseCallback); } public void getStack(long boardId, long stackId, IResponseCallback<FullStack> responseCallback) { - RequestHelper.request(sourceActivity, provider, () -> provider.getAPI().getStack(boardId, stackId, getLastSyncDateFormatted(responseCallback.getAccount().getId())), responseCallback); + RequestHelper.request(sourceActivity, provider, () -> provider.getDeckAPI().getStack(boardId, stackId, getLastSyncDateFormatted(responseCallback.getAccount().getId())), responseCallback); } public void createStack(Stack stack, IResponseCallback<FullStack> responseCallback) { ensureInternetConnection(); - RequestHelper.request(sourceActivity, provider, () -> provider.getAPI().createStack(stack.getBoardId(), stack), responseCallback); + RequestHelper.request(sourceActivity, provider, () -> provider.getDeckAPI().createStack(stack.getBoardId(), stack), responseCallback); } public void deleteStack(Stack stack, IResponseCallback<Void> responseCallback) { ensureInternetConnection(); - RequestHelper.request(sourceActivity, provider, () -> provider.getAPI().deleteStack(stack.getBoardId(), stack.getId()), responseCallback); + RequestHelper.request(sourceActivity, provider, () -> provider.getDeckAPI().deleteStack(stack.getBoardId(), stack.getId()), responseCallback); } public void updateStack(Stack stack, IResponseCallback<FullStack> responseCallback) { ensureInternetConnection(); - RequestHelper.request(sourceActivity, provider, () -> provider.getAPI().updateStack(stack.getBoardId(), stack.getId(), stack), responseCallback); + RequestHelper.request(sourceActivity, provider, () -> provider.getDeckAPI().updateStack(stack.getBoardId(), stack.getId(), stack), responseCallback); } public void getCard(long boardId, long stackId, long cardId, IResponseCallback<FullCard> responseCallback) { ensureInternetConnection(); - RequestHelper.request(sourceActivity, provider, () -> provider.getAPI().getCard(boardId, stackId, cardId, getLastSyncDateFormatted(responseCallback.getAccount().getId())), responseCallback); + RequestHelper.request(sourceActivity, provider, () -> provider.getDeckAPI().getCard(boardId, stackId, cardId, getLastSyncDateFormatted(responseCallback.getAccount().getId())), responseCallback); } public void createCard(long boardId, long stackId, Card card, IResponseCallback<FullCard> responseCallback) { ensureInternetConnection(); - RequestHelper.request(sourceActivity, provider, () -> provider.getAPI().createCard(boardId, stackId, card), responseCallback); + RequestHelper.request(sourceActivity, provider, () -> provider.getDeckAPI().createCard(boardId, stackId, card), responseCallback); } public void deleteCard(long boardId, long stackId, Card card, IResponseCallback<Void> responseCallback) { ensureInternetConnection(); - RequestHelper.request(sourceActivity, provider, () -> provider.getAPI().deleteCard(boardId, stackId, card.getId()), responseCallback); + RequestHelper.request(sourceActivity, provider, () -> provider.getDeckAPI().deleteCard(boardId, stackId, card.getId()), responseCallback); } public void updateCard(long boardId, long stackId, CardUpdate card, IResponseCallback<FullCard> responseCallback) { ensureInternetConnection(); - DeckLog.log("Update card!!" + card.toString()); DeckLog.printCurrentStacktrace(); - RequestHelper.request(sourceActivity, provider, () -> provider.getAPI().updateCard(boardId, stackId, card.getId(), card), responseCallback); + RequestHelper.request(sourceActivity, provider, () -> provider.getDeckAPI().updateCard(boardId, stackId, card.getId(), card), responseCallback); } public void assignUserToCard(long boardId, long stackId, long cardId, String userUID, IResponseCallback<Void> responseCallback){ ensureInternetConnection(); - RequestHelper.request(sourceActivity, provider, () -> provider.getAPI().assignUserToCard(boardId, stackId, cardId, userUID), responseCallback); + RequestHelper.request(sourceActivity, provider, () -> provider.getDeckAPI().assignUserToCard(boardId, stackId, cardId, userUID), responseCallback); } public void unassignUserFromCard(long boardId, long stackId, long cardId, String userUID, IResponseCallback<Void> responseCallback){ ensureInternetConnection(); - RequestHelper.request(sourceActivity, provider, () -> provider.getAPI().unassignUserFromCard(boardId, stackId, cardId, userUID), responseCallback); + RequestHelper.request(sourceActivity, provider, () -> provider.getDeckAPI().unassignUserFromCard(boardId, stackId, cardId, userUID), responseCallback); } public void assignLabelToCard(long boardId, long stackId, long cardId, long labelId, IResponseCallback<Void> responseCallback){ ensureInternetConnection(); - RequestHelper.request(sourceActivity, provider, () -> provider.getAPI().assignLabelToCard(boardId, stackId, cardId, labelId), responseCallback); + RequestHelper.request(sourceActivity, provider, () -> provider.getDeckAPI().assignLabelToCard(boardId, stackId, cardId, labelId), responseCallback); } public void unassignLabelFromCard(long boardId, long stackId, long cardId, long labelId, IResponseCallback<Void> responseCallback){ ensureInternetConnection(); - RequestHelper.request(sourceActivity, provider, () -> provider.getAPI().unassignLabelFromCard(boardId, stackId, cardId, labelId), responseCallback); + RequestHelper.request(sourceActivity, provider, () -> provider.getDeckAPI().unassignLabelFromCard(boardId, stackId, cardId, labelId), responseCallback); } // ## LABELS public void createLabel(long boardId, Label label, IResponseCallback<Label> responseCallback){ ensureInternetConnection(); - RequestHelper.request(sourceActivity, provider, () -> provider.getAPI().createLabel(boardId, label), responseCallback); + RequestHelper.request(sourceActivity, provider, () -> provider.getDeckAPI().createLabel(boardId, label), responseCallback); } public void deleteLabel(long boardId, Label label, IResponseCallback<Void> responseCallback){ ensureInternetConnection(); - RequestHelper.request(sourceActivity, provider, () -> provider.getAPI().deleteLabel(boardId, label.getId()), responseCallback); + RequestHelper.request(sourceActivity, provider, () -> provider.getDeckAPI().deleteLabel(boardId, label.getId()), responseCallback); } public void updateLabel(long boardId, Label label, IResponseCallback<Label> responseCallback){ ensureInternetConnection(); - RequestHelper.request(sourceActivity, provider, () -> provider.getAPI().updateLabel(boardId, label.getId(), label), responseCallback); + RequestHelper.request(sourceActivity, provider, () -> provider.getDeckAPI().updateLabel(boardId, label.getId(), label), responseCallback); } } |