implement view_loadmore as a listview footer instead of a pseudo-article

This commit is contained in:
Andrew Dolgov 2016-04-14 09:05:53 +03:00
parent f267359f63
commit 657366879c
2 changed files with 26 additions and 15 deletions

View File

@ -90,7 +90,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
public static final int HEADLINES_REQUEST_SIZE = 30;
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_TOP_CHANGED = -3;
private final String TAG = this.getClass().getSimpleName();
@ -117,6 +117,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
private int m_listPreviousVisibleItem;
private ListView m_list;
private ImageLoader m_imageLoader = ImageLoader.getInstance();
private View m_listLoadingView;
public ArticleList getSelectedArticles() {
ArticleList tmp = new ArticleList();
@ -441,7 +442,10 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
}
});
if (m_prefs.getBoolean("headlines_mark_read_scroll", false)) {
m_listLoadingView = inflater.inflate(R.layout.headlines_row_loadmore, m_list, false);
m_list.addFooterView(m_listLoadingView, null, false);
if (m_prefs.getBoolean("headlines_mark_read_scroll", false)) {
WindowManager wm = (WindowManager) m_activity.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
int screenHeight = display.getHeight();
@ -558,6 +562,8 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
if (m_swipeLayout != null) m_swipeLayout.setRefreshing(true);
m_listLoadingView.setVisibility(View.INVISIBLE);
/* if (!m_feed.equals(Application.getInstance().m_activeFeed)) {
append = false;
} */
@ -618,6 +624,8 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
m_list.smoothScrollToPosition(0);
}
m_listLoadingView.setVisibility(m_amountLoaded == HEADLINES_REQUEST_SIZE ? View.VISIBLE : View.GONE);
} else {
if (m_lastError == ApiError.LOGIN_FAILED) {
m_activity.login(true);
@ -763,8 +771,8 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
public static final int VIEW_UNREAD = 1;
public static final int VIEW_SELECTED = 2;
public static final int VIEW_SELECTED_UNREAD = 3;
public static final int VIEW_LOADMORE = 4;
public static final int VIEW_TOP_CHANGED = 5;
//public static final int VIEW_LOADMORE = 4;
public static final int VIEW_TOP_CHANGED = 4;
public static final int VIEW_COUNT = VIEW_TOP_CHANGED+1;
@ -819,9 +827,9 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
public int getItemViewType(int position) {
Article a = items.get(position);
if (a.id == ARTICLE_SPECIAL_LOADMORE) {
return VIEW_LOADMORE;
} else if (a.id == ARTICLE_SPECIAL_TOP_CHANGED) {
/*if (a.id == ARTICLE_SPECIAL_LOADMORE) {
return VIEW_LOADMORE; */
if (a.id == ARTICLE_SPECIAL_TOP_CHANGED) {
return VIEW_TOP_CHANGED;
} else if (m_activeArticle != null && a.id == m_activeArticle.id && a.unread) {
return VIEW_SELECTED_UNREAD;
@ -919,9 +927,9 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
int layoutId = m_compactLayoutMode ? R.layout.headlines_row_compact : R.layout.headlines_row;
switch (getItemViewType(position)) {
case VIEW_LOADMORE:
/*case VIEW_LOADMORE:
layoutId = R.layout.headlines_row_loadmore;
break;
break;*/
case VIEW_TOP_CHANGED:
layoutId = R.layout.headlines_row_top_changed;
break;
@ -1570,7 +1578,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
if (!m_refreshInProgress && m_articles.findById(ARTICLE_SPECIAL_LOADMORE) != null && firstVisibleItem + visibleItemCount == m_articles.size()) {
if (!m_refreshInProgress && /*m_articles.findById(ARTICLE_SPECIAL_LOADMORE) != null &&*/ firstVisibleItem + visibleItemCount == m_articles.size()) {
refresh(true);
}

View File

@ -32,6 +32,7 @@ public class HeadlinesRequest extends ApiRequest {
protected boolean m_firstIdChanged = false;
protected int m_firstId = 0;
protected int m_amountLoaded = 0;
public HeadlinesRequest(Context context, OnlineActivity activity, final Feed feed, ArticleList articles) {
super(context);
@ -86,12 +87,14 @@ public class HeadlinesRequest extends ApiRequest {
m_articles.remove(0);
}
if (m_articles.get(m_articles.size()-1).id == HeadlinesFragment.ARTICLE_SPECIAL_LOADMORE) {
/*if (m_articles.get(m_articles.size()-1).id == HeadlinesFragment.ARTICLE_SPECIAL_LOADMORE) {
m_articles.remove(m_articles.size()-1); // remove previous placeholder
}
}*/
}
m_amountLoaded = articles.size();
for (Article f : articles)
if (!m_articles.containsId(f.id)) {
f.collectMediaInfo();
@ -99,10 +102,10 @@ public class HeadlinesRequest extends ApiRequest {
m_articles.add(f);
}
if (articles.size() == HEADLINES_REQUEST_SIZE) {
/*if (articles.size() == HEADLINES_REQUEST_SIZE) {
Article placeholder = new Article(HeadlinesFragment.ARTICLE_SPECIAL_LOADMORE);
m_articles.add(placeholder);
}
}*/
/* if (m_articles.size() == 0)
m_activity.setLoadingStatus(R.string.no_headlines_to_display, false);