From 7fe583c81654640585788738377ce7cf0271c283 Mon Sep 17 00:00:00 2001 From: 6543 <6543@noreply.gitea.io> Date: Thu, 2 Apr 2020 16:00:03 +0000 Subject: [PATCH] Move WebInterace Calls to own Interface (#338) optimize imports Merge branch 'master' into moveWebInteraceCalls-2-ownInterface Merge branch 'master' into moveWebInteraceCalls-2-ownInterface move WebInterface calls to own interface rename WEB api for getting PullDiff Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://gitea.com/gitnex/GitNex/pulls/338 Reviewed-by: M M Arif --- .../gitnex/activities/FileDiffActivity.java | 10 +++++----- .../org/mian/gitnex/clients/RetrofitClient.java | 5 +++++ .../mian/gitnex/interfaces/ApiInterface.java | 3 --- .../mian/gitnex/interfaces/WebInterface.java | 17 +++++++++++++++++ 4 files changed, 27 insertions(+), 8 deletions(-) create mode 100644 app/src/main/java/org/mian/gitnex/interfaces/WebInterface.java diff --git a/app/src/main/java/org/mian/gitnex/activities/FileDiffActivity.java b/app/src/main/java/org/mian/gitnex/activities/FileDiffActivity.java index ce22593d..f62891f3 100644 --- a/app/src/main/java/org/mian/gitnex/activities/FileDiffActivity.java +++ b/app/src/main/java/org/mian/gitnex/activities/FileDiffActivity.java @@ -72,18 +72,18 @@ public class FileDiffActivity extends BaseActivity { mProgressBar.setVisibility(View.VISIBLE); - String fileDiffName = tinyDb.getString("issueNumber")+".diff"; + String pullIndex = tinyDb.getString("issueNumber"); - getFileContents(tinyDb.getString("instanceUrlWithProtocol"), repoOwner, repoName, fileDiffName); + getPullDiffContent(tinyDb.getString("instanceUrlWithProtocol"), repoOwner, repoName, pullIndex); } - private void getFileContents(String instanceUrl, String owner, String repo, String filename) { + private void getPullDiffContent(String instanceUrl, String owner, String repo, String filename) { Call call = RetrofitClient .getInstance(instanceUrl, getApplicationContext()) - .getApiInterface() - .getFileDiffContents(owner, repo, filename); + .getWebInterface() + .getPullDiffContent(owner, repo, filename); call.enqueue(new Callback() { diff --git a/app/src/main/java/org/mian/gitnex/clients/RetrofitClient.java b/app/src/main/java/org/mian/gitnex/clients/RetrofitClient.java index c127c63c..2c97127b 100644 --- a/app/src/main/java/org/mian/gitnex/clients/RetrofitClient.java +++ b/app/src/main/java/org/mian/gitnex/clients/RetrofitClient.java @@ -3,6 +3,7 @@ package org.mian.gitnex.clients; import android.content.Context; import androidx.annotation.NonNull; import org.mian.gitnex.interfaces.ApiInterface; +import org.mian.gitnex.interfaces.WebInterface; import org.mian.gitnex.util.AppUtil; import java.io.File; import java.io.IOException; @@ -69,4 +70,8 @@ public class RetrofitClient { return retrofit.create(ApiInterface.class); } + public WebInterface getWebInterface() { + return retrofit.create(WebInterface.class); + } + } diff --git a/app/src/main/java/org/mian/gitnex/interfaces/ApiInterface.java b/app/src/main/java/org/mian/gitnex/interfaces/ApiInterface.java index 75cc3cdf..75aa0148 100644 --- a/app/src/main/java/org/mian/gitnex/interfaces/ApiInterface.java +++ b/app/src/main/java/org/mian/gitnex/interfaces/ApiInterface.java @@ -255,9 +255,6 @@ public interface ApiInterface { @GET("repos/{owner}/{repo}/pulls") // get repository pull requests Call> getPullRequests(@Header("Authorization") String token, @Path("owner") String owner, @Path("repo") String repo, @Query("page") int page, @Query("state") String state, @Query("limit") int limit); - @GET("{owner}/{repo}/pulls/{filename}") // get pull diff file contents - Call getFileDiffContents(@Path("owner") String owner, @Path("repo") String repo, @Path("filename") String fileName); - @POST("repos/{owner}/{repo}/pulls/{index}/merge") // merge a pull request Call mergePullRequest(@Header("Authorization") String token, @Path("owner") String ownerName, @Path("repo") String repoName, @Path("index") int index, @Body MergePullRequest jsonStr); diff --git a/app/src/main/java/org/mian/gitnex/interfaces/WebInterface.java b/app/src/main/java/org/mian/gitnex/interfaces/WebInterface.java new file mode 100644 index 00000000..21ace76e --- /dev/null +++ b/app/src/main/java/org/mian/gitnex/interfaces/WebInterface.java @@ -0,0 +1,17 @@ +package org.mian.gitnex.interfaces; + +import okhttp3.ResponseBody; +import retrofit2.Call; +import retrofit2.http.GET; +import retrofit2.http.Path; + +/** + * Author M M Arif + */ + +public interface WebInterface { + + @GET("{owner}/{repo}/pulls/{index}.diff") // get pull diff file contents + Call getPullDiffContent(@Path("owner") String owner, @Path("repo") String repo, @Path("index") String pullIndex); + +}