diff --git a/src/org/fox/ttrss/HeadlinesFragment.java b/src/org/fox/ttrss/HeadlinesFragment.java index e8a58dd5..aec82aeb 100644 --- a/src/org/fox/ttrss/HeadlinesFragment.java +++ b/src/org/fox/ttrss/HeadlinesFragment.java @@ -478,7 +478,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener, ListView list = (ListView)getView().findViewById(R.id.headlines); if (list != null) { - int position = m_adapter.getPosition(m_articleOps.getSelectedArticle()); + int position = m_adapter.getPosition(getArticleById(id)); list.setSelection(position); } } @@ -500,6 +500,14 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener, public Article getArticleAtPosition(int position) { return m_adapter.getItem(position); } + + public Article getArticleById(int id) { + for (Article a : m_articles) { + if (a.id == id) + return a; + } + return null; + } public ArticleList getUnreadArticles() { ArticleList tmp = new ArticleList(); @@ -521,4 +529,9 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener, // no-op } + public int getActiveArticleId() { + return m_activeArticleId; + } + + } diff --git a/src/org/fox/ttrss/MainActivity.java b/src/org/fox/ttrss/MainActivity.java index 0ede0c83..36389430 100644 --- a/src/org/fox/ttrss/MainActivity.java +++ b/src/org/fox/ttrss/MainActivity.java @@ -1272,9 +1272,70 @@ public class MainActivity extends FragmentActivity implements FeedsFragment.OnFe return null; } + @Override + public boolean dispatchKeyEvent(KeyEvent event) { + int action = event.getAction(); + int keyCode = event.getKeyCode(); + switch (keyCode) { + case KeyEvent.KEYCODE_VOLUME_DOWN: + if (action == KeyEvent.ACTION_DOWN) { + HeadlinesFragment hf = (HeadlinesFragment)getSupportFragmentManager().findFragmentById(R.id.headlines_fragment); + + if (hf != null && m_activeFeed != null) { + Article base = hf.getArticleById(hf.getActiveArticleId()); + + Article next = base != null ? getRelativeArticle(base, RelativeArticle.AFTER) : hf.getArticleAtPosition(0); + + if (next != null) { + hf.setActiveArticleId(next.id); + + boolean combinedMode = m_prefs.getBoolean("combined_mode", false); + + if (combinedMode || m_selectedArticle == null) { + next.unread = false; + saveArticleUnread(next); + } else { + openArticle(next, 0); + } + } + } + } + return true; + case KeyEvent.KEYCODE_VOLUME_UP: + if (action == KeyEvent.ACTION_UP) { + HeadlinesFragment hf = (HeadlinesFragment)getSupportFragmentManager().findFragmentById(R.id.headlines_fragment); + + if (hf != null && m_activeFeed != null) { + Article base = hf.getArticleById(hf.getActiveArticleId()); + + Article prev = base != null ? getRelativeArticle(base, RelativeArticle.BEFORE) : hf.getArticleAtPosition(0); + + if (prev != null) { + hf.setActiveArticleId(prev.id); + + boolean combinedMode = m_prefs.getBoolean("combined_mode", false); + + if (combinedMode || m_selectedArticle == null) { + prev.unread = false; + saveArticleUnread(prev); + } else { + openArticle(prev, 0); + } + } + } + + } + return true; + default: + return super.dispatchKeyEvent(event); + } + } + @Override public void onCatSelected(FeedCategory cat) { Log.d(TAG, "onCatSelected"); - viewCategory(cat, m_prefs.getBoolean("browse_cats_like_feeds", false)); + boolean browse = m_prefs.getBoolean("browse_cats_like_feeds", false); + + viewCategory(cat, browse && cat.id >= 0); } } \ No newline at end of file