diff options
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 { |