mirror of
https://github.com/nextcloud/notes-android.git
synced 2024-11-22 21:06:09 +03:00
#1167 Use retrofit also for capabilities endpoint
Fix API v0.2 compatibility
This commit is contained in:
parent
647f2c00d5
commit
0d9eb364f5
2 changed files with 30 additions and 40 deletions
|
@ -6,9 +6,11 @@ import android.util.Log;
|
|||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.google.gson.annotations.Expose;
|
||||
import com.nextcloud.android.sso.api.NextcloudAPI;
|
||||
import com.nextcloud.android.sso.api.ParsedResponse;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
|
@ -70,7 +72,7 @@ public class NotesAPI {
|
|||
if (ApiVersion.API_VERSION_1_0.equals(usedApiVersion)) {
|
||||
return notesAPI_1_0.createNote(note);
|
||||
} else if (ApiVersion.API_VERSION_0_2.equals(usedApiVersion)) {
|
||||
return notesAPI_0_2.createNote(note);
|
||||
return notesAPI_0_2.createNote(new Note_0_2(note));
|
||||
} else {
|
||||
throw new UnsupportedOperationException("Used API version " + usedApiVersion + " does not support createNote().");
|
||||
}
|
||||
|
@ -80,7 +82,7 @@ public class NotesAPI {
|
|||
if (ApiVersion.API_VERSION_1_0.equals(usedApiVersion)) {
|
||||
return notesAPI_1_0.editNote(note, remoteId);
|
||||
} else if (ApiVersion.API_VERSION_0_2.equals(usedApiVersion)) {
|
||||
return notesAPI_0_2.editNote(note, remoteId);
|
||||
return notesAPI_0_2.editNote(new Note_0_2(note), remoteId);
|
||||
} else {
|
||||
throw new UnsupportedOperationException("Used API version " + usedApiVersion + " does not support editNote().");
|
||||
}
|
||||
|
@ -95,4 +97,28 @@ public class NotesAPI {
|
|||
throw new UnsupportedOperationException("Used API version " + usedApiVersion + " does not support createNote().");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link ApiVersion#API_VERSION_0_2} didn't have a separate <code>title</code> property.
|
||||
*/
|
||||
static class Note_0_2 {
|
||||
@Expose
|
||||
public final String category;
|
||||
@Expose
|
||||
public final Calendar modified;
|
||||
@Expose
|
||||
public final String content;
|
||||
@Expose
|
||||
public final boolean favorite;
|
||||
|
||||
private Note_0_2(Note note) {
|
||||
if (note == null) {
|
||||
throw new IllegalArgumentException(Note.class.getSimpleName() + " can not be converted to " + Note_0_2.class.getSimpleName() + " because it is null.");
|
||||
}
|
||||
this.category = note.getCategory();
|
||||
this.modified = note.getModified();
|
||||
this.content = note.getContent();
|
||||
this.favorite = note.getFavorite();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
package it.niedermann.owncloud.notes.persistence.sync;
|
||||
|
||||
|
||||
import com.google.gson.annotations.Expose;
|
||||
import com.nextcloud.android.sso.api.ParsedResponse;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
|
@ -27,46 +25,12 @@ public interface NotesAPI_0_2 {
|
|||
@GET("notes")
|
||||
Observable<ParsedResponse<List<Note>>> getNotes(@Query(value = "pruneBefore") long lastModified, @Header("If-None-Match") String lastETag);
|
||||
|
||||
default Call<Note> createNote(@Body Note note) {
|
||||
return createNote(new Note_0_2(note));
|
||||
}
|
||||
|
||||
@POST("notes")
|
||||
Call<Note> createNote(@Body Note_0_2 note);
|
||||
Call<Note> createNote(@Body NotesAPI.Note_0_2 note);
|
||||
|
||||
@PUT("notes/{remoteId}")
|
||||
Call<Note> editNote(@Body Note note, @Path("remoteId") long remoteId);
|
||||
Call<Note> editNote(@Body NotesAPI.Note_0_2 note, @Path("remoteId") long remoteId);
|
||||
|
||||
@DELETE("notes/{remoteId}")
|
||||
Call<Void> deleteNote(@Path("remoteId") long noteId);
|
||||
|
||||
class Note_0_2 {
|
||||
@Expose
|
||||
public final long id;
|
||||
@Expose
|
||||
public final String title;
|
||||
@Expose
|
||||
public final String category;
|
||||
@Expose
|
||||
public final Calendar modified;
|
||||
@Expose
|
||||
public final String content;
|
||||
@Expose
|
||||
public final boolean favorite;
|
||||
@Expose
|
||||
public final String etag;
|
||||
|
||||
private Note_0_2(Note note) {
|
||||
if (note == null) {
|
||||
throw new IllegalArgumentException(Note.class.getSimpleName() + " can not be converted to " + Note_0_2.class.getSimpleName() + " because it is null.");
|
||||
}
|
||||
this.id = note.getRemoteId();
|
||||
this.title = note.getTitle();
|
||||
this.category = note.getCategory();
|
||||
this.modified = note.getModified();
|
||||
this.content = note.getContent();
|
||||
this.favorite = note.getFavorite();
|
||||
this.etag = note.getETag();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue