reimplement going between articles with volume keys, bump version

This commit is contained in:
Andrew Dolgov 2012-09-23 21:14:01 +04:00
parent 193b107c80
commit c6225cd16e
8 changed files with 116 additions and 36 deletions

View File

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.fox.ttrss"
android:versionCode="106"
android:versionName="0.8.5" >
android:versionCode="107"
android:versionName="0.8.6" >
<uses-sdk
android:minSdkVersion="8"

View File

@ -135,4 +135,6 @@
<string name="pref_default_view_mode">Default feed view</string>
<string name="pref_default_view_mode_long">Which feed view to open by default on smartphones</string>
<string name="donate_thanks">Donation found, thank you for support!</string>
<string name="use_volume_keys">Use volume buttons</string>
<string name="use_volume_keys_long">Switch between articles with hardware volume buttons</string>
</resources>

View File

@ -2,21 +2,18 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<PreferenceCategory android:title="@string/connection" >
<EditTextPreference
android:key="login"
android:singleLine="true"
android:summary="@string/login_summary"
android:title="@string/login" >
</EditTextPreference>
<EditTextPreference
android:key="password"
android:password="true"
android:singleLine="true"
android:title="@string/password" >
</EditTextPreference>
<EditTextPreference
android:hint="@string/default_url"
android:inputType="textUri"
@ -31,16 +28,13 @@
android:key="ssl_trust_any"
android:title="@string/ssl_trust_any" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/http_authentication" >
<EditTextPreference
android:key="http_login"
android:singleLine="true"
android:summary="@string/http_login_summary"
android:title="@string/login" >
</EditTextPreference>
<EditTextPreference
android:key="http_password"
android:password="true"
@ -48,9 +42,9 @@
android:title="@string/password" >
</EditTextPreference>
</PreferenceCategory>
<PreferenceCategory android:key="category_look_and_feel" android:title="@string/look_and_feel" >
<PreferenceCategory
android:key="category_look_and_feel"
android:title="@string/look_and_feel" >
<ListPreference
android:defaultValue="THEME_DARK"
android:entries="@array/pref_theme_names"
@ -58,7 +52,6 @@
android:key="theme"
android:summary="@string/pref_theme_long"
android:title="@string/pref_theme" />
<ListPreference
android:defaultValue="0"
android:entries="@array/pref_font_size_names"
@ -70,29 +63,28 @@
android:defaultValue="false"
android:key="sort_feeds_by_unread"
android:title="@string/sort_feeds_by_unread" />
<CheckBoxPreference
android:defaultValue="false"
android:key="download_feed_icons"
android:title="@string/download_feed_icons" />
<CheckBoxPreference
android:defaultValue="false"
android:key="enable_cats"
android:title="@string/enable_cats" />
<CheckBoxPreference
android:defaultValue="false"
android:key="browse_cats_like_feeds"
android:dependency="enable_cats"
android:key="browse_cats_like_feeds"
android:summary="@string/browse_cats_like_feeds_summary"
android:title="@string/browse_cats_like_feeds" />
<!-- <CheckBoxPreference
<!--
<CheckBoxPreference
android:defaultValue="false"
android:key="combined_mode"
android:summary="@string/combined_mode_summary"
android:title="@string/combined_mode" /> -->
android:title="@string/combined_mode" />
-->
<CheckBoxPreference
android:defaultValue="true"
@ -107,19 +99,20 @@
android:summary="@string/pref_default_view_mode_long"
android:title="@string/pref_default_view_mode" />
<CheckBoxPreference
android:defaultValue="false"
android:key="use_volume_keys"
android:summary="@string/use_volume_keys_long"
android:title="@string/use_volume_keys" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/offline_mode" >
<CheckBoxPreference
android:defaultValue="false"
android:key="offline_image_cache_enabled"
android:summary="@string/offline_image_cache_enabled_summary"
android:title="@string/offline_image_cache_enabled" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/debugging" >
<CheckBoxPreference
android:defaultValue="false"
android:key="transport_debugging"

View File

@ -256,4 +256,26 @@ public class ArticlePager extends Fragment {
pager.setCurrentItem(position);
}
}
public void selectArticle(boolean next) {
if (m_article != null) {
int position = m_articles.indexOf(m_article);
if (next)
position++;
else
position--;
try {
Article tmp = m_articles.get(position);
if (tmp != null) {
setActiveArticle(tmp);
}
} catch (IndexOutOfBoundsException e) {
// do nothing
}
}
}
}

View File

@ -31,6 +31,7 @@ import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.ActionMode;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
@ -1031,6 +1032,26 @@ public class OnlineActivity extends CommonActivity {
return intent;
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (m_prefs.getBoolean("use_volume_keys", false)) {
ArticlePager ap = (ArticlePager) getSupportFragmentManager().findFragmentByTag(FRAG_ARTICLE);
if (ap != null && ap.isAdded()) {
switch (keyCode) {
case KeyEvent.KEYCODE_VOLUME_UP:
ap.selectArticle(false);
return true;
case KeyEvent.KEYCODE_VOLUME_DOWN:
ap.selectArticle(true);
return true;
}
}
}
return super.onKeyDown(keyCode, event);
}
@SuppressWarnings("unchecked")
public void catchupFeed(final Feed feed) {
Log.d(TAG, "catchupFeed=" + feed);

View File

@ -19,6 +19,7 @@ import android.preference.PreferenceManager;
import android.provider.BaseColumns;
import android.util.Log;
import android.view.ActionMode;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
@ -495,6 +496,26 @@ public class OfflineActivity extends CommonActivity {
return c;
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (m_prefs.getBoolean("use_volume_keys", false)) {
OfflineArticlePager ap = (OfflineArticlePager) getSupportFragmentManager().findFragmentByTag(FRAG_ARTICLE);
if (ap != null && ap.isAdded()) {
switch (keyCode) {
case KeyEvent.KEYCODE_VOLUME_UP:
ap.selectArticle(false);
return true;
case KeyEvent.KEYCODE_VOLUME_DOWN:
ap.selectArticle(true);
return true;
}
}
}
return super.onKeyDown(keyCode, event);
}
protected Cursor getFeedById(int feedId) {
Cursor c = getReadableDb().query("feeds", null,
BaseColumns._ID + "=?",

View File

@ -1,6 +1,7 @@
package org.fox.ttrss.offline;
import org.fox.ttrss.R;
import org.fox.ttrss.types.Article;
import android.app.Activity;
import android.database.Cursor;
@ -206,21 +207,41 @@ public class OfflineArticlePager extends Fragment {
public void setArticleId(int articleId) {
m_articleId = articleId;
m_cursor.moveToFirst();
int position = 0;
while (!m_cursor.isLast()) {
if (m_cursor.getInt(m_cursor.getColumnIndex(BaseColumns._ID)) == m_articleId) {
position = m_cursor.getPosition();
break;
}
m_cursor.moveToNext();
}
int position = getArticleIdPosition(articleId);
ViewPager pager = (ViewPager) getView().findViewById(R.id.article_pager);
pager.setCurrentItem(position);
}
public int getArticleIdPosition(int articleId) {
m_cursor.moveToFirst();
while (!m_cursor.isLast()) {
if (m_cursor.getInt(m_cursor.getColumnIndex(BaseColumns._ID)) == articleId) {
return m_cursor.getPosition();
}
m_cursor.moveToNext();
}
return -1;
}
public void selectArticle(boolean next) {
int position = getArticleIdPosition(m_articleId);
if (position != -1) {
if (next)
position++;
else
position--;
Log.d(TAG, "pos=" + position);
if (m_cursor.moveToPosition(position)) {
setArticleId(m_cursor.getInt(m_cursor.getColumnIndex(BaseColumns._ID)));
}
}
}
}

View File

@ -661,7 +661,7 @@ public class OfflineHeadlinesFragment extends Fragment implements OnItemClickLis
return i;
}
return 0;
return -1;
}
public int getArticleCount() {