diff options
author | Andrew Dolgov <[email protected]> | 2017-05-31 16:33:36 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2017-05-31 16:33:36 +0300 |
commit | f5bb189bf5958af0d7f1db109a48e8342f5f8847 (patch) | |
tree | fdfcb615367b16cb930018802b555d7a18bc27f0 | |
parent | 8d58fa8af8167da8a316427ae9a47d26a8a33f1e (diff) |
move some apirequest shared stuff to apicommon
3 files changed, 50 insertions, 86 deletions
diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/ApiCommon.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/ApiCommon.java index e2cc4174..b7308000 100644 --- a/org.fox.ttrss/src/main/java/org/fox/ttrss/ApiCommon.java +++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/ApiCommon.java @@ -1,6 +1,7 @@ package org.fox.ttrss; import android.os.Build; +import android.util.Log; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; @@ -12,15 +13,58 @@ import javax.net.ssl.SSLSession; import javax.net.ssl.TrustManager; import javax.net.ssl.X509TrustManager; -/** - * Created by andrew on 31.05.2017. - */ - public class ApiCommon { + public static final String TAG = "ApiCommon"; + public enum ApiError { NO_ERROR, HTTP_UNAUTHORIZED, HTTP_FORBIDDEN, HTTP_NOT_FOUND, HTTP_SERVER_ERROR, HTTP_OTHER_ERROR, SSL_REJECTED, SSL_HOSTNAME_REJECTED, PARSE_ERROR, IO_ERROR, OTHER_ERROR, API_DISABLED, API_UNKNOWN, LOGIN_FAILED, INVALID_URL, API_INCORRECT_USAGE, NETWORK_UNAVAILABLE, API_UNKNOWN_METHOD } + public static int getErrorMessage(ApiError error) { + switch (error) { + case NO_ERROR: + return R.string.error_unknown; + case HTTP_UNAUTHORIZED: + return R.string.error_http_unauthorized; + case HTTP_FORBIDDEN: + return R.string.error_http_forbidden; + case HTTP_NOT_FOUND: + return R.string.error_http_not_found; + case HTTP_SERVER_ERROR: + return R.string.error_http_server_error; + case HTTP_OTHER_ERROR: + return R.string.error_http_other_error; + case SSL_REJECTED: + return R.string.error_ssl_rejected; + case SSL_HOSTNAME_REJECTED: + return R.string.error_ssl_hostname_rejected; + case PARSE_ERROR: + return R.string.error_parse_error; + case IO_ERROR: + return R.string.error_io_error; + case OTHER_ERROR: + return R.string.error_other_error; + case API_DISABLED: + return R.string.error_api_disabled; + case API_UNKNOWN: + return R.string.error_api_unknown; + case API_UNKNOWN_METHOD: + return R.string.error_api_unknown_method; + case LOGIN_FAILED: + return R.string.error_login_failed; + case INVALID_URL: + return R.string.error_invalid_api_url; + case API_INCORRECT_USAGE: + return R.string.error_api_incorrect_usage; + case NETWORK_UNAVAILABLE: + return R.string.error_network_unavailable; + default: + Log.d(TAG, "getErrorMessage: unknown error code=" + error); + return R.string.error_unknown; + } + + } + public static void trustAllHosts(boolean trustAnyCert, boolean trustAnyHost) { try { if (trustAnyCert) { diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/ApiLoader.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/ApiLoader.java index d483129b..414a8a9d 100644 --- a/org.fox.ttrss/src/main/java/org/fox/ttrss/ApiLoader.java +++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/ApiLoader.java @@ -75,47 +75,7 @@ public class ApiLoader extends AsyncTaskLoader<JsonElement> { } public int getErrorMessage() { - switch (m_lastError) { - case NO_ERROR: - return R.string.error_unknown; - case HTTP_UNAUTHORIZED: - return R.string.error_http_unauthorized; - case HTTP_FORBIDDEN: - return R.string.error_http_forbidden; - case HTTP_NOT_FOUND: - return R.string.error_http_not_found; - case HTTP_SERVER_ERROR: - return R.string.error_http_server_error; - case HTTP_OTHER_ERROR: - return R.string.error_http_other_error; - case SSL_REJECTED: - return R.string.error_ssl_rejected; - case SSL_HOSTNAME_REJECTED: - return R.string.error_ssl_hostname_rejected; - case PARSE_ERROR: - return R.string.error_parse_error; - case IO_ERROR: - return R.string.error_io_error; - case OTHER_ERROR: - return R.string.error_other_error; - case API_DISABLED: - return R.string.error_api_disabled; - case API_UNKNOWN: - return R.string.error_api_unknown; - case API_UNKNOWN_METHOD: - return R.string.error_api_unknown_method; - case LOGIN_FAILED: - return R.string.error_login_failed; - case INVALID_URL: - return R.string.error_invalid_api_url; - case API_INCORRECT_USAGE: - return R.string.error_api_incorrect_usage; - case NETWORK_UNAVAILABLE: - return R.string.error_network_unavailable; - default: - Log.d(TAG, "getErrorMessage: unknown error code=" + m_lastError); - return R.string.error_unknown; - } + return ApiCommon.getErrorMessage(m_lastError); } public ApiError getLastError() { diff --git a/org.fox.ttrss/src/main/java/org/fox/ttrss/ApiRequest.java b/org.fox.ttrss/src/main/java/org/fox/ttrss/ApiRequest.java index b001e012..ab52a0c3 100644 --- a/org.fox.ttrss/src/main/java/org/fox/ttrss/ApiRequest.java +++ b/org.fox.ttrss/src/main/java/org/fox/ttrss/ApiRequest.java @@ -65,47 +65,7 @@ public class ApiRequest extends AsyncTask<HashMap<String,String>, Integer, JsonE } public int getErrorMessage() { - switch (m_lastError) { - case NO_ERROR: - return R.string.error_unknown; - case HTTP_UNAUTHORIZED: - return R.string.error_http_unauthorized; - case HTTP_FORBIDDEN: - return R.string.error_http_forbidden; - case HTTP_NOT_FOUND: - return R.string.error_http_not_found; - case HTTP_SERVER_ERROR: - return R.string.error_http_server_error; - case HTTP_OTHER_ERROR: - return R.string.error_http_other_error; - case SSL_REJECTED: - return R.string.error_ssl_rejected; - case SSL_HOSTNAME_REJECTED: - return R.string.error_ssl_hostname_rejected; - case PARSE_ERROR: - return R.string.error_parse_error; - case IO_ERROR: - return R.string.error_io_error; - case OTHER_ERROR: - return R.string.error_other_error; - case API_DISABLED: - return R.string.error_api_disabled; - case API_UNKNOWN: - return R.string.error_api_unknown; - case API_UNKNOWN_METHOD: - return R.string.error_api_unknown_method; - case LOGIN_FAILED: - return R.string.error_login_failed; - case INVALID_URL: - return R.string.error_invalid_api_url; - case API_INCORRECT_USAGE: - return R.string.error_api_incorrect_usage; - case NETWORK_UNAVAILABLE: - return R.string.error_network_unavailable; - default: - Log.d(TAG, "getErrorMessage: unknown error code=" + m_lastError); - return R.string.error_unknown; - } + return ApiCommon.getErrorMessage(m_lastError); } @Override |