properly restore fragment states on resume/rotate

This commit is contained in:
Andrew Dolgov 2015-02-10 16:04:23 +03:00
parent 7604bb30e5
commit c00b9e724e
4 changed files with 13 additions and 5 deletions

View File

@ -80,6 +80,7 @@ public class ArticlePager extends Fragment {
if (savedInstanceState != null) {
m_article = savedInstanceState.getParcelable("article");
m_articles = ((HeadlinesActivity)m_activity).m_articles;
m_feed = savedInstanceState.getParcelable("feed");
}

View File

@ -478,7 +478,7 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == HEADLINES_REQUEST) {
if (requestCode == HEADLINES_REQUEST && data != null) {
//GlobalState.getInstance().m_activeArticle = null;
//ArrayList<Article> tmp = data.getParcelableArrayListExtra("articles");

View File

@ -20,7 +20,7 @@ import org.fox.ttrss.types.Feed;
public class HeadlinesActivity extends OnlineActivity implements HeadlinesEventListener {
private final String TAG = this.getClass().getSimpleName();
private ArticleList m_articles = new ArticleList();
protected ArticleList m_articles = new ArticleList();
protected SharedPreferences m_prefs;
private Article m_activeArticle;
@ -49,8 +49,7 @@ public class HeadlinesActivity extends OnlineActivity implements HeadlinesEventL
}
if (savedInstanceState != null) {
//
m_articles = savedInstanceState.getParcelable("articles");
} else {
Intent i = getIntent();
@ -146,6 +145,8 @@ public class HeadlinesActivity extends OnlineActivity implements HeadlinesEventL
public void onSaveInstanceState(Bundle out) {
super.onSaveInstanceState(out);
out.putParcelable("articles", m_articles);
GlobalState.getInstance().save(out);
}

View File

@ -301,7 +301,13 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
if (savedInstanceState != null) {
m_feed = savedInstanceState.getParcelable("feed");
if (! (m_activity instanceof HeadlinesActivity)) {
m_articles = savedInstanceState.getParcelable("articles");
} else {
m_articles = ((HeadlinesActivity)m_activity).m_articles;
}
m_activeArticle = savedInstanceState.getParcelable("activeArticle");
m_selectedArticles = savedInstanceState.getParcelable("selectedArticles");
m_searchQuery = (String) savedInstanceState.getCharSequence("searchQuery");