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 HeadlinesEventListener m_onlineServices;
private Article m_article;
private ArticleList m_articles;
private ArticleList m_articles = GlobalState.getInstance().m_loadedArticles;
private OnlineActivity m_activity;
private String m_searchQuery = "";
@ -73,7 +73,6 @@ public class ArticlePager extends Fragment {
View view = inflater.inflate(R.layout.article_pager, container, false);
if (savedInstanceState != null) {
m_articles = savedInstanceState.getParcelable("articles");
m_article = savedInstanceState.getParcelable("article");
}
@ -178,7 +177,6 @@ public class ArticlePager extends Fragment {
public void onSaveInstanceState(Bundle out) {
super.onSaveInstanceState(out);
out.putParcelable("articles", m_articles);
out.putParcelable("article", m_article);
}
@ -188,8 +186,6 @@ public class ArticlePager extends Fragment {
m_onlineServices = (HeadlinesEventListener)activity;
m_activity = (OnlineActivity)activity;
m_articles = GlobalState.getInstance().m_loadedArticles;
}
@Override
@ -212,5 +208,4 @@ public class ArticlePager extends Fragment {
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_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);
@ -204,9 +208,6 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
case R.id.update_feeds:
refresh();
return true;
case R.id.update_headlines:
refresh();
return true;
default:
Log.d(TAG, "onOptionsItemSelected, unhandled id=" + item.getItemId());
return super.onOptionsItemSelected(item);
@ -285,4 +286,10 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
super.catchupFeed(feed);
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
protected void loginSuccess() {
Log.d(TAG, "loginSuccess");
@ -144,9 +151,6 @@ public class HeadlinesActivity extends OnlineActivity implements HeadlinesEventL
ArticlePager af = (ArticlePager) getSupportFragmentManager().findFragmentByTag(FRAG_ARTICLE);
af.setActiveArticle(article);
// ft.replace(R.id.article_fragment, frag, FRAG_ARTICLE);
// ft.addToBackStack(null);
hf.notifyUpdated();
@ -161,4 +165,24 @@ public class HeadlinesActivity extends OnlineActivity implements HeadlinesEventL
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 onArticleSelected(Article article);
void onArticleSelected(Article article, boolean open);
void onHeadlinesLoaded();
}

View File

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

View File

@ -664,7 +664,10 @@ public class OnlineActivity extends CommonActivity {
if (ap != null && ap.getSelectedArticle() != null) {
editArticleLabels(ap.getSelectedArticle());
}
return true;
return true;
case R.id.update_headlines:
refresh();
return true;
default:
Log.d(TAG, "onOptionsItemSelected, unhandled id=" + item.getItemId());
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.article_set_note).setEnabled(m_apiLevel >= 1);
m_menu.findItem(R.id.update_headlines).setVisible(false);
MenuItem search = m_menu.findItem(R.id.search);
search.setEnabled(m_apiLevel >= 2);