diff --git a/src/main/java/com/alorma/github/sdk/bean/dto/response/GitTreeEntry.java b/src/main/java/com/alorma/github/sdk/bean/dto/response/GitTreeEntry.java index d892a293..b95a30eb 100644 --- a/src/main/java/com/alorma/github/sdk/bean/dto/response/GitTreeEntry.java +++ b/src/main/java/com/alorma/github/sdk/bean/dto/response/GitTreeEntry.java @@ -1,9 +1,23 @@ package com.alorma.github.sdk.bean.dto.response; -public class GitTreeEntry extends ShaUrl{ +import android.support.annotation.NonNull; + +public class GitTreeEntry extends ShaUrl implements Comparable{ public String path; public String mode; public int size; public GitTreeType type; + + + @Override + public int compareTo(@NonNull GitTreeEntry another) { + if (another.type == type) { + return path.compareTo(another.path); + } else if (another.type == GitTreeType.tree) { + return 1; + } else { + return another.path.compareTo(path); + } + } } diff --git a/src/main/java/com/alorma/github/sdk/security/InterceptingListOkClient.java b/src/main/java/com/alorma/github/sdk/security/InterceptingListOkClient.java deleted file mode 100644 index 6ce2b2f0..00000000 --- a/src/main/java/com/alorma/github/sdk/security/InterceptingListOkClient.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.alorma.github.sdk.security; - -import com.alorma.gitskarios.core.client.BaseListClient; -import com.alorma.gitskarios.core.client.PaginationLink; -import com.alorma.gitskarios.core.client.RelType; -import com.squareup.okhttp.OkHttpClient; -import java.io.IOException; -import retrofit.client.Header; -import retrofit.client.OkClient; -import retrofit.client.Request; -import retrofit.client.Response; - -public class InterceptingListOkClient extends OkClient { - - private BaseListClient baseClient; - - public InterceptingListOkClient(OkHttpClient client, BaseListClient baseClient) { - super(client); - this.baseClient = baseClient; - } - - @Override - public Response execute(Request request) throws IOException { - - Response response = super.execute(request); - try { - for (Header header : response.getHeaders()) { - if (header.getName().equals("Link")) { - String[] parts = header.getValue().split(","); - for (String part : parts) { - PaginationLink bottomPaginationLink = new PaginationLink(part); - if (bottomPaginationLink.rel == RelType.last) { - baseClient.last = bottomPaginationLink.uri; - baseClient.lastPage = bottomPaginationLink.page; - } else if (bottomPaginationLink.rel == RelType.next) { - baseClient.next = bottomPaginationLink.uri; - baseClient.nextPage = bottomPaginationLink.page; - } - } - - } - } - } catch (Exception e) { - e.printStackTrace(); - } - - return response; - } - -} diff --git a/src/main/java/com/alorma/github/sdk/services/client/GithubListClient.java b/src/main/java/com/alorma/github/sdk/services/client/GithubListClient.java index 509b1aee..44be90e4 100644 --- a/src/main/java/com/alorma/github/sdk/services/client/GithubListClient.java +++ b/src/main/java/com/alorma/github/sdk/services/client/GithubListClient.java @@ -1,14 +1,11 @@ package com.alorma.github.sdk.services.client; import android.content.Context; -import android.support.annotation.Nullable; import android.util.Log; import com.alorma.github.sdk.security.GitHub; -import com.alorma.github.sdk.security.InterceptingListOkClient; import com.alorma.gitskarios.core.ApiClient; import com.alorma.gitskarios.core.client.BaseListClient; import com.alorma.gitskarios.core.client.StoreCredentials; -import com.squareup.okhttp.OkHttpClient; public abstract class GithubListClient extends BaseListClient { @@ -36,10 +33,4 @@ public void log(String message) { public String getAcceptHeader() { return "application/vnd.github.v3.json"; } - - @Nullable - @Override - protected InterceptingListOkClient getInterceptor() { - return new InterceptingListOkClient(new OkHttpClient(), this); - } } diff --git a/src/main/java/com/alorma/github/sdk/services/git/GetGitTreeClient.java b/src/main/java/com/alorma/github/sdk/services/git/GetGitTreeClient.java index ca707860..a2b19d46 100644 --- a/src/main/java/com/alorma/github/sdk/services/git/GetGitTreeClient.java +++ b/src/main/java/com/alorma/github/sdk/services/git/GetGitTreeClient.java @@ -10,6 +10,7 @@ public class GetGitTreeClient extends GithubClient { private final RepoInfo info; + private String sha; private final boolean recursive; public GetGitTreeClient(Context context, RepoInfo repoInfo, boolean recursive) { @@ -18,15 +19,28 @@ public GetGitTreeClient(Context context, RepoInfo repoInfo, boolean recursive) { this.recursive = recursive; } + public GetGitTreeClient(Context context, RepoInfo repoInfo, String sha, boolean recursive) { + super(context); + this.info = repoInfo; + this.sha = sha; + this.recursive = recursive; + } + @Override protected Observable getApiObservable(RestAdapter restAdapter) { GitDataService gitDataService = restAdapter.create(GitDataService.class); - if (recursive) { - return gitDataService - .repoTreeRecursive(info.owner, info.name, info.branch); + if (sha == null) { + if (recursive) { + return gitDataService.repoTreeRecursive(info.owner, info.name, info.branch); + } else { + return gitDataService.repoTree(info.owner, info.name, info.branch); + } } else { - return gitDataService - .repoTree(info.owner, info.name, info.branch); + if (recursive) { + return gitDataService.repoTreeRecursive(info.owner, info.name, sha); + } else { + return gitDataService.repoTree(info.owner, info.name, sha); + } } } } diff --git a/src/main/java/com/alorma/github/sdk/services/git/GitDataService.java b/src/main/java/com/alorma/github/sdk/services/git/GitDataService.java index 9afc7a0e..ac00a1b3 100644 --- a/src/main/java/com/alorma/github/sdk/services/git/GitDataService.java +++ b/src/main/java/com/alorma/github/sdk/services/git/GitDataService.java @@ -23,7 +23,7 @@ public interface GitDataService { @GET("/repos/{owner}/{repo}/git/refs") void repoReferences(@Path("owner") String owner, @Path("repo") String name, @Query("page") int page, Callback> callback); - //Sync + //Syncx @GET("/repos/{owner}/{repo}/git/{ref}") Observable repoReference(@Path("owner") String owner, @Path("repo") String name, @Path(value = "ref", encode = false) String ref);