From 8f38f2f7a3e95ee824f9f7694dec7f6204ca819e Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Thu, 16 Jan 2014 16:07:30 +0400 Subject: [PATCH] force login when starting in shortcut mode to prevent blank fragments --- AndroidManifest.xml | 4 +-- src/org/fox/ttrss/FeedsActivity.java | 37 +++++++++++++++++++----- src/org/fox/ttrss/HeadlinesFragment.java | 4 +-- src/org/fox/ttrss/OnlineActivity.java | 35 +++++++++++++++++----- 4 files changed, 61 insertions(+), 19 deletions(-) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 7076cc1a..73ef10ea 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -1,8 +1,8 @@ + android:versionCode="229" + android:versionName="1.33" > map = new HashMap() { + { + put("op", "login"); + put("user", m_prefs.getString("login", "").trim()); + put("password", m_prefs.getString("password", "").trim()); + } + }; + + lr.execute(map); } m_pullToRefreshAttacher.setRefreshing(true); diff --git a/src/org/fox/ttrss/HeadlinesFragment.java b/src/org/fox/ttrss/HeadlinesFragment.java index e4495081..7145f51b 100644 --- a/src/org/fox/ttrss/HeadlinesFragment.java +++ b/src/org/fox/ttrss/HeadlinesFragment.java @@ -321,7 +321,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener, if (m_activeArticle != null) { setActiveArticle(m_activeArticle); } - + if (m_articles.size() == 0 || !m_feed.equals(GlobalState.getInstance().m_activeFeed)) { if (m_activity.getSupportFragmentManager().findFragmentByTag(CommonActivity.FRAG_ARTICLE) == null) { refresh(false); @@ -429,7 +429,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener, } else { if (m_lastError == ApiError.LOGIN_FAILED) { - m_activity.login(); + m_activity.login(true); } else { m_activity.setLoadingStatus(getErrorMessage(), false); } diff --git a/src/org/fox/ttrss/OnlineActivity.java b/src/org/fox/ttrss/OnlineActivity.java index d82c92cf..1169c9c9 100644 --- a/src/org/fox/ttrss/OnlineActivity.java +++ b/src/org/fox/ttrss/OnlineActivity.java @@ -74,6 +74,11 @@ public class OnlineActivity extends CommonActivity { protected PullToRefreshAttacher m_pullToRefreshAttacher; + protected abstract class OnLoginFinishedListener { + public abstract void OnLoginSuccess(); + public abstract void OnLoginFailed(); + }; + private BroadcastReceiver m_broadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context content, Intent intent) { @@ -406,10 +411,14 @@ public class OnlineActivity extends CommonActivity { } public void login() { - login(false); + login(false, null); } - + public void login(boolean refresh) { + login(refresh, null); + } + + public void login(boolean refresh, OnLoginFinishedListener listener) { if (m_prefs.getString("ttrss_url", "").trim().length() == 0) { setLoadingStatus(R.string.login_need_configure, false); @@ -437,7 +446,7 @@ public class OnlineActivity extends CommonActivity { } else { setLoadingStatus(R.string.login_in_progress, true); - LoginRequest ar = new LoginRequest(getApplicationContext(), refresh); + LoginRequest ar = new LoginRequest(getApplicationContext(), refresh, listener); HashMap map = new HashMap() { { @@ -1635,12 +1644,14 @@ public class OnlineActivity extends CommonActivity { refresh(true); } - private class LoginRequest extends ApiRequest { + protected class LoginRequest extends ApiRequest { boolean m_refreshAfterLogin = false; + OnLoginFinishedListener m_listener; - public LoginRequest(Context context, boolean refresh) { + public LoginRequest(Context context, boolean refresh, OnLoginFinishedListener listener) { super(context); m_refreshAfterLogin = refresh; + m_listener = listener; } @SuppressWarnings("unchecked") @@ -1662,7 +1673,11 @@ public class OnlineActivity extends CommonActivity { setApiLevel(apiLevel.getAsInt()); Log.d(TAG, "Received API level: " + getApiLevel()); - loginSuccess(m_refreshAfterLogin); + if (m_listener != null) { + m_listener.OnLoginSuccess(); + } else { + loginSuccess(m_refreshAfterLogin); + } } else { @@ -1680,7 +1695,13 @@ public class OnlineActivity extends CommonActivity { // Unknown method means old tt-rss, in that case we assume API 0 and continue setLoadingStatus(getErrorMessage(), false); - loginFailure(); + + if (m_listener != null) { + m_listener.OnLoginFailed(); + } else { + loginFailure(); + } + return; }