diff options
author | cyBerta <cyberta@riseup.net> | 2018-01-11 14:59:56 +0100 |
---|---|---|
committer | cyBerta <cyberta@riseup.net> | 2018-01-11 14:59:56 +0100 |
commit | 1e94e6e1403d97e47119318bd43b173ef20658b1 (patch) | |
tree | 2f37b74f259915d1b04facd0d0f59856f112f8b8 | |
parent | 0105cb76e1fc6b59d42dff3059d5bb9548dab372 (diff) |
#8773 code review fixes
4 files changed, 11 insertions, 10 deletions
diff --git a/app/build.gradle b/app/build.gradle index b894af38..52c64ab7 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -81,7 +81,7 @@ dependencies { provided 'com.squareup.dagger:dagger-compiler:1.2.2' compile 'com.github.pedrovgs:renderers:1.5' compile 'com.intellij:annotations:12.0' - compile 'com.google.code.gson:gson:2.7' + compile 'com.google.code.gson:gson:2.8.2' compile 'com.squareup.okhttp3:okhttp:3.9.0' compile 'mbanje.kurt:fabbutton:1.1.4' compile "com.android.support:support-core-utils:26.1.0" diff --git a/app/src/main/java/se/leap/bitmaskclient/Provider.java b/app/src/main/java/se/leap/bitmaskclient/Provider.java index ae07bc25..60b1b93c 100644 --- a/app/src/main/java/se/leap/bitmaskclient/Provider.java +++ b/app/src/main/java/se/leap/bitmaskclient/Provider.java @@ -234,7 +234,7 @@ public final class Provider implements Parcelable { public boolean equals(Object o) { if (o instanceof Provider) { Provider p = (Provider) o; - return p.getMainUrl().getDomain().equals(getMainUrl().getDomain()); + return p.getDomain().equals(getDomain()); } else return false; } @@ -253,7 +253,7 @@ public final class Provider implements Parcelable { @Override public int hashCode() { - return getMainUrl().getDomain().hashCode(); + return getDomain().hashCode(); } @Override @@ -261,6 +261,7 @@ public final class Provider implements Parcelable { return new Gson().toJson(this); } + //TODO: write a test for marshalling! private Provider(Parcel in) { try { mainUrl.setUrl(new URL(in.readString())); diff --git a/app/src/main/java/se/leap/bitmaskclient/ProviderApiConnector.java b/app/src/main/java/se/leap/bitmaskclient/ProviderApiConnector.java index 439fb5e2..af79a95e 100644 --- a/app/src/main/java/se/leap/bitmaskclient/ProviderApiConnector.java +++ b/app/src/main/java/se/leap/bitmaskclient/ProviderApiConnector.java @@ -50,6 +50,7 @@ public class ProviderApiConnector { Request request = requestBuilder.build(); Response response = okHttpClient.newCall(request).execute(); + //response code 401: already logged out if (response.isSuccessful() || response.code() == 401) { return true; } @@ -77,11 +78,10 @@ public class ProviderApiConnector { Request.Builder requestBuilder = new Request.Builder() .url(url) .method(request_method, jsonBody); - if (headerArgs != null) { - for (Pair<String, String> keyValPair : headerArgs) { - requestBuilder.addHeader(keyValPair.first, keyValPair.second); - } + for (Pair<String, String> keyValPair : headerArgs) { + requestBuilder.addHeader(keyValPair.first, keyValPair.second); } + //TODO: move to getHeaderArgs()? String locale = Locale.getDefault().getLanguage() + Locale.getDefault().getCountry(); requestBuilder.addHeader("Accept-Language", locale); diff --git a/app/src/main/java/se/leap/bitmaskclient/ProviderApiManagerBase.java b/app/src/main/java/se/leap/bitmaskclient/ProviderApiManagerBase.java index cc005fcd..9f5fdc2d 100644 --- a/app/src/main/java/se/leap/bitmaskclient/ProviderApiManagerBase.java +++ b/app/src/main/java/se/leap/bitmaskclient/ProviderApiManagerBase.java @@ -510,13 +510,13 @@ public abstract class ProviderApiManagerBase { return requestJsonFromServer(url, request_method, jsonString, null, okHttpClient); } - protected String sendGetStringToServer(String url, List<Pair<String, String>> headerArgs, OkHttpClient okHttpClient) { + protected String sendGetStringToServer(@NonNull String url, @NonNull List<Pair<String, String>> headerArgs, @NonNull OkHttpClient okHttpClient) { return requestStringFromServer(url, "GET", null, headerArgs, okHttpClient); } - private JSONObject requestJsonFromServer(String url, String request_method, String jsonString, List<Pair<String, String>> headerArgs, @NonNull OkHttpClient okHttpClient) { + private JSONObject requestJsonFromServer(@NonNull String url, @NonNull String request_method, String jsonString, @NonNull List<Pair<String, String>> headerArgs, @NonNull OkHttpClient okHttpClient) { JSONObject responseJson; String plain_response = requestStringFromServer(url, request_method, jsonString, headerArgs, okHttpClient); @@ -530,7 +530,7 @@ public abstract class ProviderApiManagerBase { } - private String requestStringFromServer(String url, String request_method, String jsonString, List<Pair<String, String>> headerArgs, @NonNull OkHttpClient okHttpClient) { + private String requestStringFromServer(@NonNull String url, @NonNull String request_method, String jsonString, @NonNull List<Pair<String, String>> headerArgs, @NonNull OkHttpClient okHttpClient) { String plainResponseBody = null; try { |