headlines: fix positioning problems

This commit is contained in:
Andrew Dolgov 2015-05-11 12:30:12 +03:00
parent 675f77a59b
commit 9ee41fc190

View File

@ -98,6 +98,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
private int m_maxImageSize = 0; private int m_maxImageSize = 0;
private boolean m_compactLayoutMode = false; private boolean m_compactLayoutMode = false;
private int m_listPreviousVisibleItem; private int m_listPreviousVisibleItem;
private ListView m_list;
public ArticleList getSelectedArticles() { public ArticleList getSelectedArticles() {
ArticleList tmp = new ArticleList(); ArticleList tmp = new ArticleList();
@ -351,12 +352,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
} }
}); });
ListView list = (ListView)view.findViewById(R.id.headlines_list); m_list = (ListView)view.findViewById(R.id.headlines_list);
/* if (!m_compactLayoutMode) {
list.setDividerHeight(0);
list.setDivider(null);
} */
if (m_prefs.getBoolean("headlines_mark_read_scroll", false)) { if (m_prefs.getBoolean("headlines_mark_read_scroll", false)) {
WindowManager wm = (WindowManager) m_activity.getSystemService(Context.WINDOW_SERVICE); WindowManager wm = (WindowManager) m_activity.getSystemService(Context.WINDOW_SERVICE);
@ -367,21 +363,20 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
layout.setLayoutParams(new ListView.LayoutParams(ListView.LayoutParams.MATCH_PARENT, screenHeight)); layout.setLayoutParams(new ListView.LayoutParams(ListView.LayoutParams.MATCH_PARENT, screenHeight));
list.addFooterView(layout, null, false); m_list.addFooterView(layout, null, false);
} }
if (m_activity.isSmallScreen()) { if (m_activity.isSmallScreen()) {
View layout = inflater.inflate(R.layout.headlines_heading_spacer, list, false); View layout = inflater.inflate(R.layout.headlines_heading_spacer, m_list, false);
list.addHeaderView(layout); m_list.addHeaderView(layout);
} }
m_adapter = new ArticleListAdapter(getActivity(), R.layout.headlines_row, (ArrayList<Article>)m_articles); m_adapter = new ArticleListAdapter(getActivity(), R.layout.headlines_row, (ArrayList<Article>)m_articles);
list.setAdapter(m_adapter); m_list.setAdapter(m_adapter);
list.setOnItemClickListener(this); m_list.setOnItemClickListener(this);
list.setOnScrollListener(this); m_list.setOnScrollListener(this);
//list.setEmptyView(view.findViewById(R.id.no_headlines)); registerForContextMenu(m_list);
registerForContextMenu(list);
if (m_activity.isSmallScreen()) { if (m_activity.isSmallScreen()) {
m_activity.setTitle(m_feed.title); m_activity.setTitle(m_feed.title);
@ -499,14 +494,6 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
protected void onPostExecute(JsonElement result) { protected void onPostExecute(JsonElement result) {
if (isDetached() || !isAdded()) return; if (isDetached() || !isAdded()) return;
if (getView() != null) {
ListView list = (ListView)getView().findViewById(R.id.headlines_list);
/* if (list != null) {
list.setEmptyView(getView().findViewById(R.id.no_headlines));
} */
}
super.onPostExecute(result); super.onPostExecute(result);
if (isAdded()) { if (isAdded()) {
@ -1291,7 +1278,9 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
public Article getArticleAtPosition(int position) { public Article getArticleAtPosition(int position) {
try { try {
return m_adapter.getItem(position); return (Article) m_list.getItemAtPosition(position);
} catch (ClassCastException e) {
return null;
} catch (IndexOutOfBoundsException e) { } catch (IndexOutOfBoundsException e) {
return null; return null;
} catch (NullPointerException e) { } catch (NullPointerException e) {
@ -1366,20 +1355,20 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
public int getArticlePositionById(int id) { public int getArticlePositionById(int id) {
for (Article a : m_adapter.items) { for (Article a : m_adapter.items) {
if (a.id == id) { if (a.id == id) {
return m_adapter.getPosition(a); return m_adapter.getPosition(a) + m_list.getHeaderViewsCount();
} }
} }
return -1; return -1;
} }
public int getArticlePosition(Article article) { /* public int getArticlePosition(Article article) {
try { try {
return m_adapter.getPosition(article); return m_adapter.getPosition(article);
} catch (NullPointerException e) { } catch (NullPointerException e) {
return -1; return -1;
} }
} } */
public String getSearchQuery() { public String getSearchQuery() {
return m_searchQuery; return m_searchQuery;