force login when starting in shortcut mode to prevent blank fragments

This commit is contained in:
Andrew Dolgov 2014-01-16 16:07:30 +04:00
parent 025f6aca5f
commit 8f38f2f7a3
4 changed files with 61 additions and 19 deletions

View File

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.fox.ttrss"
android:versionCode="228"
android:versionName="1.32" >
android:versionCode="229"
android:versionName="1.33" >
<uses-sdk
android:minSdkVersion="8"

View File

@ -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");
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();
}
});
Feed tmpFeed = new Feed(feedId, feedTitle, isCat);
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);

View File

@ -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);
}

View File

@ -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;
}