remove special spacer hack, makes headlines buffer move on loading more headlines

This commit is contained in:
Andrew Dolgov 2015-09-15 20:08:46 +03:00
parent 97d5b5f6e1
commit deaae7ee1b

View File

@ -88,7 +88,6 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
public static final int HEADLINES_BUFFER_MAX = 500; public static final int HEADLINES_BUFFER_MAX = 500;
public static final int ARTICLE_SPECIAL_LOADMORE = -1; public static final int ARTICLE_SPECIAL_LOADMORE = -1;
public static final int ARTICLE_SPECIAL_SPACER = -2;
public static final int ARTICLE_SPECIAL_TOP_CHANGED = -3; public static final int ARTICLE_SPECIAL_TOP_CHANGED = -3;
private final String TAG = this.getClass().getSimpleName(); private final String TAG = this.getClass().getSimpleName();
@ -538,7 +537,6 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
if (result != null) { if (result != null) {
m_refreshInProgress = false; m_refreshInProgress = false;
m_articles.add(0, new Article(ARTICLE_SPECIAL_SPACER));
if (m_articles.indexOf(m_activeArticle) == -1) if (m_articles.indexOf(m_activeArticle) == -1)
m_activeArticle = null; m_activeArticle = null;
@ -702,8 +700,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
public static final int VIEW_SELECTED = 2; public static final int VIEW_SELECTED = 2;
public static final int VIEW_SELECTED_UNREAD = 3; public static final int VIEW_SELECTED_UNREAD = 3;
public static final int VIEW_LOADMORE = 4; public static final int VIEW_LOADMORE = 4;
public static final int VIEW_SPACER = 5; public static final int VIEW_TOP_CHANGED = 5;
public static final int VIEW_TOP_CHANGED = 6;
public static final int VIEW_COUNT = VIEW_TOP_CHANGED+1; public static final int VIEW_COUNT = VIEW_TOP_CHANGED+1;
@ -758,15 +755,10 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
public int getItemViewType(int position) { public int getItemViewType(int position) {
Article a = items.get(position); Article a = items.get(position);
// the special invisible SPACER is here because listview animations apparently glitch if there's only one headline loaded
// so we add an invisible second one i guess
if (a.id == ARTICLE_SPECIAL_LOADMORE) { if (a.id == ARTICLE_SPECIAL_LOADMORE) {
return VIEW_LOADMORE; return VIEW_LOADMORE;
} else if (a.id == ARTICLE_SPECIAL_TOP_CHANGED) { } else if (a.id == ARTICLE_SPECIAL_TOP_CHANGED) {
return VIEW_TOP_CHANGED; return VIEW_TOP_CHANGED;
} else if (a.id == ARTICLE_SPECIAL_SPACER) {
return VIEW_SPACER;
} else if (m_activeArticle != null && a.id == m_activeArticle.id && a.unread) { } else if (m_activeArticle != null && a.id == m_activeArticle.id && a.unread) {
return VIEW_SELECTED_UNREAD; return VIEW_SELECTED_UNREAD;
} else if (m_activeArticle != null && a.id == m_activeArticle.id) { } else if (m_activeArticle != null && a.id == m_activeArticle.id) {
@ -867,9 +859,6 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
case VIEW_LOADMORE: case VIEW_LOADMORE:
layoutId = R.layout.headlines_row_loadmore; layoutId = R.layout.headlines_row_loadmore;
break; break;
case VIEW_SPACER:
layoutId = R.layout.fragment_dummy;
break;
case VIEW_TOP_CHANGED: case VIEW_TOP_CHANGED:
layoutId = R.layout.headlines_row_top_changed; layoutId = R.layout.headlines_row_top_changed;
break; break;
@ -1382,11 +1371,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
} }
public ArticleList getAllArticles() { public ArticleList getAllArticles() {
ArticleList tmp = (ArticleList) m_articles.clone(); return (ArticleList) m_articles.clone();
tmp.remove(0);
return tmp;
} }
// if setting active doesn't make sense, scroll to whatever is passed to us // if setting active doesn't make sense, scroll to whatever is passed to us
@ -1550,7 +1535,6 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
public void setArticles(ArticleList articles) { public void setArticles(ArticleList articles) {
m_articles.clear(); m_articles.clear();
m_articles.add(0, new Article(ARTICLE_SPECIAL_SPACER));
m_articles.addAll(articles); m_articles.addAll(articles);
m_adapter.notifyDataSetChanged(); m_adapter.notifyDataSetChanged();
} }