various session handling fixes; try to reload headlines when
shared application data has been erased
This commit is contained in:
parent
8f88419419
commit
7abd056146
@ -2,6 +2,7 @@ package org.fox.ttrss;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.fox.ttrss.ApiRequest.ApiError;
|
||||
import org.fox.ttrss.types.Article;
|
||||
import org.fox.ttrss.types.ArticleList;
|
||||
import org.fox.ttrss.types.Feed;
|
||||
@ -29,6 +30,7 @@ public class ArticlePager extends Fragment {
|
||||
private ArticleList m_articles = GlobalState.getInstance().m_loadedArticles;
|
||||
private OnlineActivity m_activity;
|
||||
private String m_searchQuery = "";
|
||||
private Feed m_feed;
|
||||
|
||||
private class PagerAdapter extends FragmentStatePagerAdapter {
|
||||
|
||||
@ -58,10 +60,11 @@ public class ArticlePager extends Fragment {
|
||||
super();
|
||||
}
|
||||
|
||||
public ArticlePager(Article article) {
|
||||
public ArticlePager(Article article, Feed feed) {
|
||||
super();
|
||||
|
||||
m_article = article;
|
||||
m_feed = feed;
|
||||
}
|
||||
|
||||
public void setSearchQuery(String searchQuery) {
|
||||
@ -74,6 +77,7 @@ public class ArticlePager extends Fragment {
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
m_article = savedInstanceState.getParcelable("article");
|
||||
m_feed = savedInstanceState.getParcelable("feed");
|
||||
}
|
||||
|
||||
m_adapter = new PagerAdapter(getActivity().getSupportFragmentManager());
|
||||
@ -111,7 +115,7 @@ public class ArticlePager extends Fragment {
|
||||
|
||||
if (m_activity.isSmallScreen() && position == m_adapter.getCount() - 5) {
|
||||
Log.d(TAG, "loading more articles...");
|
||||
loadMoreArticles();
|
||||
refresh(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -121,27 +125,43 @@ public class ArticlePager extends Fragment {
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "serial" })
|
||||
private void loadMoreArticles() {
|
||||
private void refresh(boolean append) {
|
||||
m_activity.setLoadingStatus(R.string.blank, true);
|
||||
|
||||
if (!m_feed.equals(GlobalState.getInstance().m_activeFeed)) {
|
||||
append = false;
|
||||
}
|
||||
|
||||
HeadlinesRequest req = new HeadlinesRequest(getActivity().getApplicationContext(), m_activity) {
|
||||
protected void onPostExecute(JsonElement result) {
|
||||
super.onPostExecute(result);
|
||||
m_adapter.notifyDataSetChanged();
|
||||
|
||||
if (result != null) {
|
||||
m_adapter.notifyDataSetChanged();
|
||||
} else {
|
||||
if (m_lastError == ApiError.LOGIN_FAILED) {
|
||||
m_activity.login();
|
||||
} else {
|
||||
m_activity.toast(getErrorMessage());
|
||||
//setLoadingStatus(getErrorMessage(), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
final Feed feed = GlobalState.getInstance().m_activeFeed;
|
||||
final Feed feed = m_feed;
|
||||
|
||||
final String sessionId = m_activity.getSessionId();
|
||||
final boolean showUnread = m_activity.getUnreadArticlesOnly();
|
||||
int skip = 0;
|
||||
|
||||
for (Article a : m_articles) {
|
||||
if (a.unread) ++skip;
|
||||
}
|
||||
if (append) {
|
||||
for (Article a : m_articles) {
|
||||
if (a.unread) ++skip;
|
||||
}
|
||||
|
||||
if (skip == 0) skip = m_articles.size();
|
||||
if (skip == 0) skip = m_articles.size();
|
||||
}
|
||||
|
||||
final int fskip = skip;
|
||||
|
||||
@ -178,6 +198,7 @@ public class ArticlePager extends Fragment {
|
||||
super.onSaveInstanceState(out);
|
||||
|
||||
out.putParcelable("article", m_article);
|
||||
out.putParcelable("feed", m_feed);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -192,6 +213,13 @@ public class ArticlePager extends Fragment {
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
||||
if (m_articles.size() == 0 || !m_feed.equals(GlobalState.getInstance().m_activeFeed)) {
|
||||
refresh(false);
|
||||
GlobalState.getInstance().m_activeFeed = m_feed;
|
||||
} else {
|
||||
m_adapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
m_activity.initMenu();
|
||||
}
|
||||
|
||||
|
@ -61,29 +61,29 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
|
||||
|
||||
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
|
||||
|
||||
if (feed != null) {
|
||||
HeadlinesFragment hf = new HeadlinesFragment(feed);
|
||||
ft.replace(R.id.feeds_fragment, hf, FRAG_HEADLINES);
|
||||
|
||||
setTitle(feed.title);
|
||||
}
|
||||
|
||||
if (cat != null) {
|
||||
FeedsFragment ff = new FeedsFragment(cat);
|
||||
ft.replace(R.id.feeds_fragment, ff, FRAG_FEEDS);
|
||||
|
||||
setTitle(cat.title);
|
||||
}
|
||||
|
||||
if (article != null) {
|
||||
Article original = GlobalState.getInstance().m_loadedArticles.findById(article.id);
|
||||
|
||||
ArticlePager ap = new ArticlePager(original != null ? original : article);
|
||||
ArticlePager ap = new ArticlePager(original != null ? original : article, feed);
|
||||
ft.replace(R.id.feeds_fragment, ap, FRAG_ARTICLE);
|
||||
|
||||
ap.setSearchQuery(intent.getStringExtra("searchQuery"));
|
||||
|
||||
setTitle(intent.getStringExtra("feedTitle"));
|
||||
} else {
|
||||
if (feed != null) {
|
||||
HeadlinesFragment hf = new HeadlinesFragment(feed);
|
||||
ft.replace(R.id.feeds_fragment, hf, FRAG_HEADLINES);
|
||||
|
||||
setTitle(feed.title);
|
||||
}
|
||||
|
||||
if (cat != null) {
|
||||
FeedsFragment ff = new FeedsFragment(cat);
|
||||
ft.replace(R.id.feeds_fragment, ff, FRAG_FEEDS);
|
||||
|
||||
setTitle(cat.title);
|
||||
}
|
||||
}
|
||||
|
||||
ft.commit();
|
||||
@ -254,6 +254,7 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
|
||||
intent.putExtra("apiLevel", m_apiLevel);
|
||||
|
||||
intent.putExtra("feedTitle", hf.getFeed().title);
|
||||
intent.putExtra("feed", hf.getFeed());
|
||||
intent.putExtra("article", article);
|
||||
intent.putExtra("searchQuery", hf.getSearchQuery());
|
||||
|
||||
|
@ -49,7 +49,7 @@ public class HeadlinesActivity extends OnlineActivity implements HeadlinesEventL
|
||||
String searchQuery = i.getStringExtra("searchQuery");
|
||||
|
||||
HeadlinesFragment hf = new HeadlinesFragment(feed, article);
|
||||
ArticlePager af = new ArticlePager(hf.getArticleById(article.id));
|
||||
ArticlePager af = new ArticlePager(hf.getArticleById(article.id), feed);
|
||||
|
||||
hf.setSearchQuery(searchQuery);
|
||||
af.setSearchQuery(searchQuery);
|
||||
@ -171,7 +171,7 @@ public class HeadlinesActivity extends OnlineActivity implements HeadlinesEventL
|
||||
|
||||
hf.setActiveArticle(article);
|
||||
|
||||
ArticlePager af = new ArticlePager(article);
|
||||
ArticlePager af = new ArticlePager(article, hf.getFeed());
|
||||
|
||||
FragmentTransaction ft = getSupportFragmentManager()
|
||||
.beginTransaction();
|
||||
|
@ -11,6 +11,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import org.fox.ttrss.ApiRequest.ApiError;
|
||||
import org.fox.ttrss.types.Article;
|
||||
import org.fox.ttrss.types.ArticleList;
|
||||
import org.fox.ttrss.types.Attachment;
|
||||
@ -365,9 +366,18 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
|
||||
HeadlinesRequest req = new HeadlinesRequest(getActivity().getApplicationContext(), m_activity) {
|
||||
protected void onPostExecute(JsonElement result) {
|
||||
super.onPostExecute(result);
|
||||
m_refreshInProgress = false;
|
||||
m_adapter.notifyDataSetChanged();
|
||||
m_listener.onHeadlinesLoaded(fappend);
|
||||
|
||||
if (result != null) {
|
||||
m_refreshInProgress = false;
|
||||
m_adapter.notifyDataSetChanged();
|
||||
m_listener.onHeadlinesLoaded(fappend);
|
||||
} else {
|
||||
if (m_lastError == ApiError.LOGIN_FAILED) {
|
||||
m_activity.login();
|
||||
} else {
|
||||
setLoadingStatus(getErrorMessage(), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -1203,6 +1203,10 @@ public class OnlineActivity extends CommonActivity {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
setLoadingStatus(getErrorMessage(), false);
|
||||
loginFailure();
|
||||
return;
|
||||
}
|
||||
|
||||
Log.d(TAG, "Received API level: " + m_apiLevel);
|
||||
|
Loading…
Reference in New Issue
Block a user