switch between articles using volume buttons
This commit is contained in:
parent
4cf1ca7c57
commit
6a8878f980
@ -478,7 +478,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
|
|||||||
ListView list = (ListView)getView().findViewById(R.id.headlines);
|
ListView list = (ListView)getView().findViewById(R.id.headlines);
|
||||||
|
|
||||||
if (list != null) {
|
if (list != null) {
|
||||||
int position = m_adapter.getPosition(m_articleOps.getSelectedArticle());
|
int position = m_adapter.getPosition(getArticleById(id));
|
||||||
list.setSelection(position);
|
list.setSelection(position);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -500,6 +500,14 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
|
|||||||
public Article getArticleAtPosition(int position) {
|
public Article getArticleAtPosition(int position) {
|
||||||
return m_adapter.getItem(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() {
|
public ArticleList getUnreadArticles() {
|
||||||
ArticleList tmp = new ArticleList();
|
ArticleList tmp = new ArticleList();
|
||||||
@ -521,4 +529,9 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener,
|
|||||||
// no-op
|
// no-op
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getActiveArticleId() {
|
||||||
|
return m_activeArticleId;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1272,9 +1272,70 @@ public class MainActivity extends FragmentActivity implements FeedsFragment.OnFe
|
|||||||
return null;
|
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
|
@Override
|
||||||
public void onCatSelected(FeedCategory cat) {
|
public void onCatSelected(FeedCategory cat) {
|
||||||
Log.d(TAG, "onCatSelected");
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user