implement refreshing headlines in headlinesactivity

This commit is contained in:
Andrew Dolgov 2012-09-18 15:17:39 +04:00
parent 62622642b8
commit 46751e25b3
6 changed files with 45 additions and 15 deletions

View File

@ -26,7 +26,7 @@ public class ArticlePager extends Fragment {
private PagerAdapter m_adapter; private PagerAdapter m_adapter;
private HeadlinesEventListener m_onlineServices; private HeadlinesEventListener m_onlineServices;
private Article m_article; private Article m_article;
private ArticleList m_articles; private ArticleList m_articles = GlobalState.getInstance().m_loadedArticles;
private OnlineActivity m_activity; private OnlineActivity m_activity;
private String m_searchQuery = ""; private String m_searchQuery = "";
@ -73,7 +73,6 @@ public class ArticlePager extends Fragment {
View view = inflater.inflate(R.layout.article_pager, container, false); View view = inflater.inflate(R.layout.article_pager, container, false);
if (savedInstanceState != null) { if (savedInstanceState != null) {
m_articles = savedInstanceState.getParcelable("articles");
m_article = savedInstanceState.getParcelable("article"); m_article = savedInstanceState.getParcelable("article");
} }
@ -178,7 +177,6 @@ public class ArticlePager extends Fragment {
public void onSaveInstanceState(Bundle out) { public void onSaveInstanceState(Bundle out) {
super.onSaveInstanceState(out); super.onSaveInstanceState(out);
out.putParcelable("articles", m_articles);
out.putParcelable("article", m_article); out.putParcelable("article", m_article);
} }
@ -188,8 +186,6 @@ public class ArticlePager extends Fragment {
m_onlineServices = (HeadlinesEventListener)activity; m_onlineServices = (HeadlinesEventListener)activity;
m_activity = (OnlineActivity)activity; m_activity = (OnlineActivity)activity;
m_articles = GlobalState.getInstance().m_loadedArticles;
} }
@Override @Override
@ -212,5 +208,4 @@ public class ArticlePager extends Fragment {
pager.setCurrentItem(position); pager.setCurrentItem(position);
} }
} }

View File

@ -121,7 +121,11 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
m_menu.setGroupVisible(R.id.menu_group_headlines, hf != null && hf.isAdded() && hf.getSelectedArticles().size() == 0); m_menu.setGroupVisible(R.id.menu_group_headlines, hf != null && hf.isAdded() && hf.getSelectedArticles().size() == 0);
m_menu.setGroupVisible(R.id.menu_group_headlines_selection, hf != null && hf.isAdded() && hf.getSelectedArticles().size() != 0); m_menu.setGroupVisible(R.id.menu_group_headlines_selection, hf != null && hf.isAdded() && hf.getSelectedArticles().size() != 0);
m_menu.findItem(R.id.update_headlines).setVisible(hf != null && hf.isAdded()); if (isSmallScreen()) {
m_menu.findItem(R.id.update_headlines).setVisible(hf != null && hf.isAdded());
} else {
m_menu.findItem(R.id.update_headlines).setVisible(false);
}
MenuItem item = m_menu.findItem(R.id.show_feeds); MenuItem item = m_menu.findItem(R.id.show_feeds);
@ -204,9 +208,6 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
case R.id.update_feeds: case R.id.update_feeds:
refresh(); refresh();
return true; return true;
case R.id.update_headlines:
refresh();
return true;
default: default:
Log.d(TAG, "onOptionsItemSelected, unhandled id=" + item.getItemId()); Log.d(TAG, "onOptionsItemSelected, unhandled id=" + item.getItemId());
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
@ -285,4 +286,10 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
super.catchupFeed(feed); super.catchupFeed(feed);
refresh(); refresh();
} }
@Override
public void onHeadlinesLoaded() {
// TODO Auto-generated method stub
}
} }

View File

@ -70,6 +70,13 @@ public class HeadlinesActivity extends OnlineActivity implements HeadlinesEventL
} }
} }
@Override
protected void refresh() {
super.refresh();
}
@Override @Override
protected void loginSuccess() { protected void loginSuccess() {
Log.d(TAG, "loginSuccess"); Log.d(TAG, "loginSuccess");
@ -145,9 +152,6 @@ public class HeadlinesActivity extends OnlineActivity implements HeadlinesEventL
af.setActiveArticle(article); af.setActiveArticle(article);
// ft.replace(R.id.article_fragment, frag, FRAG_ARTICLE);
// ft.addToBackStack(null);
hf.notifyUpdated(); hf.notifyUpdated();
ft.commit(); ft.commit();
@ -161,4 +165,24 @@ public class HeadlinesActivity extends OnlineActivity implements HeadlinesEventL
initMenu(); initMenu();
} }
@Override
public void onHeadlinesLoaded() {
HeadlinesFragment hf = (HeadlinesFragment) getSupportFragmentManager().findFragmentByTag(FRAG_HEADLINES);
if (hf != null) {
Article article = hf.getAllArticles().get(0);
hf.setActiveArticle(article);
ArticlePager af = new ArticlePager(article);
FragmentTransaction ft = getSupportFragmentManager()
.beginTransaction();
ft.replace(R.id.article_fragment, af, FRAG_ARTICLE);
ft.commit();
}
}
} }

View File

@ -7,4 +7,5 @@ public interface HeadlinesEventListener {
void onArticleListSelectionChange(ArticleList m_selectedArticles); void onArticleListSelectionChange(ArticleList m_selectedArticles);
void onArticleSelected(Article article); void onArticleSelected(Article article);
void onArticleSelected(Article article, boolean open); void onArticleSelected(Article article, boolean open);
void onHeadlinesLoaded();
} }

View File

@ -357,6 +357,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
super.onPostExecute(result); super.onPostExecute(result);
m_refreshInProgress = false; m_refreshInProgress = false;
m_adapter.notifyDataSetChanged(); m_adapter.notifyDataSetChanged();
m_listener.onHeadlinesLoaded();
} }
}; };

View File

@ -665,6 +665,9 @@ public class OnlineActivity extends CommonActivity {
editArticleLabels(ap.getSelectedArticle()); editArticleLabels(ap.getSelectedArticle());
} }
return true; return true;
case R.id.update_headlines:
refresh();
return true;
default: default:
Log.d(TAG, "onOptionsItemSelected, unhandled id=" + item.getItemId()); Log.d(TAG, "onOptionsItemSelected, unhandled id=" + item.getItemId());
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
@ -1079,7 +1082,6 @@ public class OnlineActivity extends CommonActivity {
m_menu.findItem(R.id.set_labels).setEnabled(m_apiLevel >= 1); m_menu.findItem(R.id.set_labels).setEnabled(m_apiLevel >= 1);
m_menu.findItem(R.id.article_set_note).setEnabled(m_apiLevel >= 1); m_menu.findItem(R.id.article_set_note).setEnabled(m_apiLevel >= 1);
m_menu.findItem(R.id.update_headlines).setVisible(false);
MenuItem search = m_menu.findItem(R.id.search); MenuItem search = m_menu.findItem(R.id.search);
search.setEnabled(m_apiLevel >= 2); search.setEnabled(m_apiLevel >= 2);