diff options
author | Andrew Dolgov <[email protected]> | 2014-01-16 16:07:30 +0400 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2014-01-16 16:07:30 +0400 |
commit | 8f38f2f7a3e95ee824f9f7694dec7f6204ca819e (patch) | |
tree | 9a9098bfcbbcbb1e95e141d05dab3972d376288c /src/org | |
parent | 025f6aca5f9ec275c99e618ff0ecd619bb9f5b0e (diff) |
force login when starting in shortcut mode to prevent blank fragments
Diffstat (limited to 'src/org')
-rw-r--r-- | src/org/fox/ttrss/FeedsActivity.java | 37 | ||||
-rw-r--r-- | src/org/fox/ttrss/HeadlinesFragment.java | 4 | ||||
-rw-r--r-- | src/org/fox/ttrss/OnlineActivity.java | 35 |
3 files changed, 59 insertions, 17 deletions
diff --git a/src/org/fox/ttrss/FeedsActivity.java b/src/org/fox/ttrss/FeedsActivity.java index 9682a31f..2e1a55e5 100644 --- a/src/org/fox/ttrss/FeedsActivity.java +++ b/src/org/fox/ttrss/FeedsActivity.java @@ -50,7 +50,7 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe .getDefaultSharedPreferences(getApplicationContext()); setAppTheme(m_prefs); - + super.onCreate(savedInstanceState); setContentView(R.layout.headlines); @@ -104,19 +104,40 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe if (m_slidingMenu != null) m_slidingMenu.showMenu(); - Intent i = getIntent(); + final Intent i = getIntent(); boolean shortcutMode = i.getBooleanExtra("shortcut_mode", false); Log.d(TAG, "is_shortcut_mode: " + shortcutMode); if (shortcutMode) { - int feedId = i.getIntExtra("feed_id", 0); - boolean isCat = i.getBooleanExtra("feed_is_cat", false); - String feedTitle = i.getStringExtra("feed_title"); - - Feed tmpFeed = new Feed(feedId, feedTitle, isCat); + LoginRequest lr = new LoginRequest(this, false, new OnLoginFinishedListener() { + + @Override + public void OnLoginSuccess() { + int feedId = i.getIntExtra("feed_id", 0); + boolean isCat = i.getBooleanExtra("feed_is_cat", false); + String feedTitle = i.getStringExtra("feed_title"); + + Feed tmpFeed = new Feed(feedId, feedTitle, isCat); + + onFeedSelected(tmpFeed); + } + + @Override + public void OnLoginFailed() { + login(); + } + }); - onFeedSelected(tmpFeed); + HashMap<String, String> map = new HashMap<String, String>() { + { + 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<String, String> map = new HashMap<String, String>() { { @@ -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; } |