improve logging in again if session is lost

This commit is contained in:
Andrew Dolgov 2012-09-21 10:44:30 +04:00
parent a82aeb29e4
commit b9bd5e89b1
6 changed files with 36 additions and 15 deletions

View File

@ -127,7 +127,7 @@ public class ArticlePager extends Fragment {
} }
@SuppressWarnings({ "unchecked", "serial" }) @SuppressWarnings({ "unchecked", "serial" })
private void refresh(boolean append) { protected void refresh(boolean append) {
m_activity.setLoadingStatus(R.string.blank, true); m_activity.setLoadingStatus(R.string.blank, true);
m_activity.setProgressBarVisibility(true); m_activity.setProgressBarVisibility(true);
@ -160,7 +160,7 @@ public class ArticlePager extends Fragment {
} 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.toast(getErrorMessage()); m_activity.toast(getErrorMessage());
//setLoadingStatus(getErrorMessage(), false); //setLoadingStatus(getErrorMessage(), false);

View File

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

View File

@ -234,16 +234,17 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
} }
@Override @Override
protected void loginSuccess() { protected void loginSuccess(boolean refresh) {
setLoadingStatus(R.string.blank, false); setLoadingStatus(R.string.blank, false);
findViewById(R.id.loading_container).setVisibility(View.GONE); findViewById(R.id.loading_container).setVisibility(View.GONE);
initMenu(); initMenu();
if (refresh) refresh();
} }
@Override @Override
public void onSaveInstanceState(Bundle out) { public void onSaveInstanceState(Bundle out) {
super.onSaveInstanceState(out); super.onSaveInstanceState(out);
} }
@Override @Override
@ -281,6 +282,8 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
if (isSmallScreen()) { if (isSmallScreen()) {
//GlobalState.getInstance().m_loadedArticles.clear();
Intent intent = new Intent(FeedsActivity.this, FeedsActivity.class); Intent intent = new Intent(FeedsActivity.this, FeedsActivity.class);
intent.putExtra("feed", hf.getFeed()); intent.putExtra("feed", hf.getFeed());
intent.putExtra("article", article); intent.putExtra("article", article);

View File

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

View File

@ -97,13 +97,15 @@ public class HeadlinesActivity extends OnlineActivity implements HeadlinesEventL
} }
@Override @Override
protected void loginSuccess() { protected void loginSuccess(boolean refresh) {
Log.d(TAG, "loginSuccess"); Log.d(TAG, "loginSuccess");
setLoadingStatus(R.string.blank, false); setLoadingStatus(R.string.blank, false);
findViewById(R.id.loading_container).setVisibility(View.GONE); findViewById(R.id.loading_container).setVisibility(View.GONE);
initMenu(); initMenu();
if (refresh) refresh();
} }
@Override @Override

View File

@ -377,6 +377,10 @@ public class OnlineActivity extends CommonActivity {
} }
public void login() { public void login() {
login(false);
}
public void login(boolean refresh) {
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);
@ -403,7 +407,7 @@ public class OnlineActivity extends CommonActivity {
} else { } else {
LoginRequest ar = new LoginRequest(getApplicationContext()); LoginRequest ar = new LoginRequest(getApplicationContext(), refresh);
HashMap<String, String> map = new HashMap<String, String>() { HashMap<String, String> map = new HashMap<String, String>() {
{ {
@ -419,7 +423,7 @@ public class OnlineActivity extends CommonActivity {
} }
} }
protected void loginSuccess() { protected void loginSuccess(boolean refresh) {
setLoadingStatus(R.string.blank, false); setLoadingStatus(R.string.blank, false);
findViewById(R.id.loading_container).setVisibility(View.GONE); findViewById(R.id.loading_container).setVisibility(View.GONE);
@ -697,7 +701,9 @@ public class OnlineActivity extends CommonActivity {
} }
return true; return true;
case R.id.update_headlines: case R.id.update_headlines:
refresh(); if (hf != null) {
hf.refresh(false);
}
return true; return true;
default: default:
Log.d(TAG, "onOptionsItemSelected, unhandled id=" + item.getItemId()); Log.d(TAG, "onOptionsItemSelected, unhandled id=" + item.getItemId());
@ -865,7 +871,7 @@ public class OnlineActivity extends CommonActivity {
if (getSessionId() == null) { if (getSessionId() == null) {
login(); login();
} else { } else {
loginSuccess(); loginSuccess(false);
} }
} }
@ -1206,6 +1212,12 @@ public class OnlineActivity extends CommonActivity {
if (hf != null) { if (hf != null) {
hf.refresh(false); hf.refresh(false);
} }
ArticlePager af = (ArticlePager) getSupportFragmentManager().findFragmentByTag(FRAG_ARTICLE);
if (af != null) {
af.refresh(false);
}
} }
} }
@ -1214,8 +1226,11 @@ public class OnlineActivity extends CommonActivity {
} }
private class LoginRequest extends ApiRequest { private class LoginRequest extends ApiRequest {
public LoginRequest(Context context) { boolean m_refreshAfterLogin = false;
public LoginRequest(Context context, boolean refresh) {
super(context); super(context);
m_refreshAfterLogin = refresh;
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@ -1248,7 +1263,8 @@ public class OnlineActivity extends CommonActivity {
Log.d(TAG, "Received API level: " + getApiLevel()); Log.d(TAG, "Received API level: " + getApiLevel());
loginSuccess(); loginSuccess(m_refreshAfterLogin);
return; return;
} }
}; };