From 695feaf0cdbeedeee5888bdf7e52914e1af6287a Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sat, 29 Sep 2012 11:59:04 +0400 Subject: [PATCH] handle api_level returned by login --- src/org/fox/ttrss/OnlineActivity.java | 80 +++++++++++++++------------ 1 file changed, 46 insertions(+), 34 deletions(-) diff --git a/src/org/fox/ttrss/OnlineActivity.java b/src/org/fox/ttrss/OnlineActivity.java index f8abb5e5..636535e4 100644 --- a/src/org/fox/ttrss/OnlineActivity.java +++ b/src/org/fox/ttrss/OnlineActivity.java @@ -1264,50 +1264,62 @@ public class OnlineActivity extends CommonActivity { if (result != null) { try { JsonObject content = result.getAsJsonObject(); + if (content != null) { setSessionId(content.get("session_id").getAsString()); + + JsonElement apiLevel = content.get("api_level"); GlobalState.getInstance().m_canUseProgress = m_canUseProgress; - + Log.d(TAG, "Authenticated! canUseProgress=" + m_canUseProgress); - ApiRequest req = new ApiRequest(m_context) { - protected void onPostExecute(JsonElement result) { - setApiLevel(0); + if (apiLevel != null) { + setApiLevel(apiLevel.getAsInt()); + Log.d(TAG, "Received API level: " + getApiLevel()); + + loginSuccess(m_refreshAfterLogin); + + } else { - if (result != null) { - try { - setApiLevel(result.getAsJsonObject().get("level").getAsInt()); - } catch (Exception e) { - e.printStackTrace(); + ApiRequest req = new ApiRequest(m_context) { + protected void onPostExecute(JsonElement result) { + setApiLevel(0); + + if (result != null) { + try { + setApiLevel(result.getAsJsonObject().get("level").getAsInt()); + } catch (Exception e) { + e.printStackTrace(); + } + } else if (m_lastError != ApiError.API_UNKNOWN_METHOD) { + // Unknown method means old tt-rss, in that case we assume API 0 and continue + + setLoadingStatus(getErrorMessage(), false); + loginFailure(); + return; } - } else if (m_lastError != ApiError.API_UNKNOWN_METHOD) { - // Unknown method means old tt-rss, in that case we assume API 0 and continue - - setLoadingStatus(getErrorMessage(), false); - loginFailure(); + + Log.d(TAG, "Received API level: " + getApiLevel()); + + loginSuccess(m_refreshAfterLogin); + return; } - - Log.d(TAG, "Received API level: " + getApiLevel()); - - loginSuccess(m_refreshAfterLogin); - - return; - } - }; - - @SuppressWarnings("serial") - HashMap map = new HashMap() { - { - put("sid", getSessionId()); - put("op", "getApiLevel"); - } - }; - - req.execute(map); - - setLoadingStatus(R.string.loading_message, true); + }; + + @SuppressWarnings("serial") + HashMap map = new HashMap() { + { + put("sid", getSessionId()); + put("op", "getApiLevel"); + } + }; + + req.execute(map); + + setLoadingStatus(R.string.loading_message, true); + } return; }