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

@ -126,8 +126,8 @@ public class ArticlePager extends Fragment {
return view;
}
@SuppressWarnings({ "unchecked", "serial" })
private void refresh(boolean append) {
@SuppressWarnings({ "unchecked", "serial" })
protected void refresh(boolean append) {
m_activity.setLoadingStatus(R.string.blank, true);
m_activity.setProgressBarVisibility(true);
@ -160,7 +160,7 @@ public class ArticlePager extends Fragment {
} else {
if (m_lastError == ApiError.LOGIN_FAILED) {
m_activity.login();
m_activity.login(true);
} else {
m_activity.toast(getErrorMessage());
//setLoadingStatus(getErrorMessage(), false);

View File

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

View File

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

View File

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

View File

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

View File

@ -377,6 +377,10 @@ public class OnlineActivity extends CommonActivity {
}
public void login() {
login(false);
}
public void login(boolean refresh) {
if (m_prefs.getString("ttrss_url", "").trim().length() == 0) {
setLoadingStatus(R.string.login_need_configure, false);
@ -403,7 +407,7 @@ public class OnlineActivity extends CommonActivity {
} else {
LoginRequest ar = new LoginRequest(getApplicationContext());
LoginRequest ar = new LoginRequest(getApplicationContext(), refresh);
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);
findViewById(R.id.loading_container).setVisibility(View.GONE);
@ -697,7 +701,9 @@ public class OnlineActivity extends CommonActivity {
}
return true;
case R.id.update_headlines:
refresh();
if (hf != null) {
hf.refresh(false);
}
return true;
default:
Log.d(TAG, "onOptionsItemSelected, unhandled id=" + item.getItemId());
@ -865,7 +871,7 @@ public class OnlineActivity extends CommonActivity {
if (getSessionId() == null) {
login();
} else {
loginSuccess();
loginSuccess(false);
}
}
@ -1206,6 +1212,12 @@ public class OnlineActivity extends CommonActivity {
if (hf != null) {
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 {
public LoginRequest(Context context) {
boolean m_refreshAfterLogin = false;
public LoginRequest(Context context, boolean refresh) {
super(context);
m_refreshAfterLogin = refresh;
}
@SuppressWarnings("unchecked")
@ -1248,7 +1263,8 @@ public class OnlineActivity extends CommonActivity {
Log.d(TAG, "Received API level: " + getApiLevel());
loginSuccess();
loginSuccess(m_refreshAfterLogin);
return;
}
};