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

View File

@ -104,19 +104,40 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
if (m_slidingMenu != null) if (m_slidingMenu != null)
m_slidingMenu.showMenu(); m_slidingMenu.showMenu();
Intent i = getIntent(); final Intent i = getIntent();
boolean shortcutMode = i.getBooleanExtra("shortcut_mode", false); boolean shortcutMode = i.getBooleanExtra("shortcut_mode", false);
Log.d(TAG, "is_shortcut_mode: " + shortcutMode); Log.d(TAG, "is_shortcut_mode: " + shortcutMode);
if (shortcutMode) { if (shortcutMode) {
int feedId = i.getIntExtra("feed_id", 0); LoginRequest lr = new LoginRequest(this, false, new OnLoginFinishedListener() {
boolean isCat = i.getBooleanExtra("feed_is_cat", false);
String feedTitle = i.getStringExtra("feed_title");
Feed tmpFeed = new Feed(feedId, feedTitle, isCat); @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");
onFeedSelected(tmpFeed); Feed tmpFeed = new Feed(feedId, feedTitle, isCat);
onFeedSelected(tmpFeed);
}
@Override
public void OnLoginFailed() {
login();
}
});
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); m_pullToRefreshAttacher.setRefreshing(true);

View File

@ -429,7 +429,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
} else { } else {
if (m_lastError == ApiError.LOGIN_FAILED) { if (m_lastError == ApiError.LOGIN_FAILED) {
m_activity.login(); m_activity.login(true);
} else { } else {
m_activity.setLoadingStatus(getErrorMessage(), false); m_activity.setLoadingStatus(getErrorMessage(), false);
} }

View File

@ -74,6 +74,11 @@ public class OnlineActivity extends CommonActivity {
protected PullToRefreshAttacher m_pullToRefreshAttacher; protected PullToRefreshAttacher m_pullToRefreshAttacher;
protected abstract class OnLoginFinishedListener {
public abstract void OnLoginSuccess();
public abstract void OnLoginFailed();
};
private BroadcastReceiver m_broadcastReceiver = new BroadcastReceiver() { private BroadcastReceiver m_broadcastReceiver = new BroadcastReceiver() {
@Override @Override
public void onReceive(Context content, Intent intent) { public void onReceive(Context content, Intent intent) {
@ -406,10 +411,14 @@ public class OnlineActivity extends CommonActivity {
} }
public void login() { public void login() {
login(false); login(false, null);
} }
public void login(boolean refresh) { public void login(boolean refresh) {
login(refresh, null);
}
public void login(boolean refresh, OnLoginFinishedListener listener) {
if (m_prefs.getString("ttrss_url", "").trim().length() == 0) { if (m_prefs.getString("ttrss_url", "").trim().length() == 0) {
setLoadingStatus(R.string.login_need_configure, false); setLoadingStatus(R.string.login_need_configure, false);
@ -437,7 +446,7 @@ public class OnlineActivity extends CommonActivity {
} else { } else {
setLoadingStatus(R.string.login_in_progress, true); 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>() { HashMap<String, String> map = new HashMap<String, String>() {
{ {
@ -1635,12 +1644,14 @@ public class OnlineActivity extends CommonActivity {
refresh(true); refresh(true);
} }
private class LoginRequest extends ApiRequest { protected class LoginRequest extends ApiRequest {
boolean m_refreshAfterLogin = false; boolean m_refreshAfterLogin = false;
OnLoginFinishedListener m_listener;
public LoginRequest(Context context, boolean refresh) { public LoginRequest(Context context, boolean refresh, OnLoginFinishedListener listener) {
super(context); super(context);
m_refreshAfterLogin = refresh; m_refreshAfterLogin = refresh;
m_listener = listener;
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@ -1662,7 +1673,11 @@ public class OnlineActivity extends CommonActivity {
setApiLevel(apiLevel.getAsInt()); setApiLevel(apiLevel.getAsInt());
Log.d(TAG, "Received API level: " + getApiLevel()); Log.d(TAG, "Received API level: " + getApiLevel());
loginSuccess(m_refreshAfterLogin); if (m_listener != null) {
m_listener.OnLoginSuccess();
} else {
loginSuccess(m_refreshAfterLogin);
}
} else { } 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 // Unknown method means old tt-rss, in that case we assume API 0 and continue
setLoadingStatus(getErrorMessage(), false); setLoadingStatus(getErrorMessage(), false);
loginFailure();
if (m_listener != null) {
m_listener.OnLoginFailed();
} else {
loginFailure();
}
return; return;
} }