properly restore state when going back from headlinesactivity

This commit is contained in:
Andrew Dolgov 2012-09-16 22:13:32 +04:00
parent 306a0bf4c9
commit c580d8225a
5 changed files with 30 additions and 15 deletions

View File

@ -39,11 +39,6 @@
<group android:id="@+id/menu_group_headlines" > <group android:id="@+id/menu_group_headlines" >
<item
android:id="@+id/go_offline"
android:icon="@drawable/ic_menu_cloud"
android:title="@string/go_offline"/>
<item <item
android:id="@+id/search" android:id="@+id/search"
android:actionViewClass="android.widget.SearchView" android:actionViewClass="android.widget.SearchView"

View File

@ -123,7 +123,7 @@ public class ArticlePager extends Fragment {
m_onlineServices = (HeadlinesEventListener)activity; m_onlineServices = (HeadlinesEventListener)activity;
m_articles = TinyApplication.getInstance().m_articles; m_articles = TinyApplication.getInstance().m_loadedArticles;
} }
@Override @Override

View File

@ -135,6 +135,13 @@ private final String TAG = this.getClass().getSimpleName();
@Override @Override
public void onArticleSelected(Article article, boolean open) { public void onArticleSelected(Article article, boolean open) {
if (article.unread) {
article.unread = false;
saveArticleUnread(article);
}
//TinyApplication.getInstance().m_activeArticle = article;
if (open) { if (open) {
FragmentTransaction ft = getSupportFragmentManager() FragmentTransaction ft = getSupportFragmentManager()
.beginTransaction(); .beginTransaction();
@ -145,11 +152,14 @@ private final String TAG = this.getClass().getSimpleName();
ft.replace(R.id.article_fragment, frag, FRAG_ARTICLE); ft.replace(R.id.article_fragment, frag, FRAG_ARTICLE);
//ft.addToBackStack(null); //ft.addToBackStack(null);
hf.notifyUpdated();
ft.commit(); ft.commit();
} else { } else {
HeadlinesFragment hf = (HeadlinesFragment) getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES); HeadlinesFragment hf = (HeadlinesFragment) getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES);
if (hf != null) hf.setActiveArticle(article); hf.setActiveArticle(article);
initMenu(); initMenu();
} }

View File

@ -75,7 +75,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
private SharedPreferences m_prefs; private SharedPreferences m_prefs;
private ArticleListAdapter m_adapter; private ArticleListAdapter m_adapter;
private ArticleList m_articles = TinyApplication.getInstance().m_articles; private ArticleList m_articles = TinyApplication.getInstance().m_loadedArticles;
private ArticleList m_selectedArticles = new ArticleList(); private ArticleList m_selectedArticles = new ArticleList();
private HeadlinesEventListener m_listener; private HeadlinesEventListener m_listener;
@ -295,9 +295,17 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
public void onResume() { public void onResume() {
super.onResume(); super.onResume();
if (m_articles.size() == 0 || !m_feed.equals(TinyApplication.getInstance().m_feed)) { /* if (TinyApplication.getInstance().m_activeArticle != null) {
m_activeArticle = TinyApplication.getInstance().m_activeArticle;
notifyUpdated();
TinyApplication.getInstance().m_activeArticle = null;
} */
if (m_articles.size() == 0 || !m_feed.equals(TinyApplication.getInstance().m_activeFeed)) {
refresh(false); refresh(false);
TinyApplication.getInstance().m_feed = m_feed; TinyApplication.getInstance().m_activeFeed = m_feed;
} else {
notifyUpdated();
} }
m_activity.initMenu(); m_activity.initMenu();
@ -329,7 +337,11 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
m_listener.onArticleSelected(article); m_listener.onArticleSelected(article);
} }
m_activeArticle = article; // only set active article when it makes sense (in HeadlinesActivity)
if (getActivity().findViewById(R.id.article_fragment) != null) {
m_activeArticle = article;
}
m_adapter.notifyDataSetChanged(); m_adapter.notifyDataSetChanged();
} }
} }

View File

@ -1,6 +1,5 @@
package org.fox.ttrss; package org.fox.ttrss;
import org.fox.ttrss.types.Article;
import org.fox.ttrss.types.ArticleList; import org.fox.ttrss.types.ArticleList;
import org.fox.ttrss.types.Feed; import org.fox.ttrss.types.Feed;
@ -9,9 +8,8 @@ import android.app.Application;
public class TinyApplication extends Application { public class TinyApplication extends Application {
private static TinyApplication m_singleton; private static TinyApplication m_singleton;
public ArticleList m_articles = new ArticleList(); public ArticleList m_loadedArticles = new ArticleList();
public Feed m_feed; public Feed m_activeFeed;
public Article m_selectedArticle;
public static TinyApplication getInstance(){ public static TinyApplication getInstance(){
return m_singleton; return m_singleton;