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"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.fox.ttrss" package="org.fox.ttrss"
android:versionCode="106" android:versionCode="107"
android:versionName="0.8.5" > android:versionName="0.8.6" >
<uses-sdk <uses-sdk
android:minSdkVersion="8" 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">Default feed view</string>
<string name="pref_default_view_mode_long">Which feed view to open by default on smartphones</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="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> </resources>

View File

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

View File

@ -256,4 +256,26 @@ public class ArticlePager extends Fragment {
pager.setCurrentItem(position); 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.preference.PreferenceManager;
import android.util.Log; import android.util.Log;
import android.view.ActionMode; import android.view.ActionMode;
import android.view.KeyEvent;
import android.view.Menu; import android.view.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
import android.view.MenuItem; import android.view.MenuItem;
@ -1031,6 +1032,26 @@ public class OnlineActivity extends CommonActivity {
return intent; 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") @SuppressWarnings("unchecked")
public void catchupFeed(final Feed feed) { public void catchupFeed(final Feed feed) {
Log.d(TAG, "catchupFeed=" + feed); Log.d(TAG, "catchupFeed=" + feed);

View File

@ -19,6 +19,7 @@ import android.preference.PreferenceManager;
import android.provider.BaseColumns; import android.provider.BaseColumns;
import android.util.Log; import android.util.Log;
import android.view.ActionMode; import android.view.ActionMode;
import android.view.KeyEvent;
import android.view.Menu; import android.view.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
import android.view.MenuItem; import android.view.MenuItem;
@ -495,6 +496,26 @@ public class OfflineActivity extends CommonActivity {
return c; 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) { protected Cursor getFeedById(int feedId) {
Cursor c = getReadableDb().query("feeds", null, Cursor c = getReadableDb().query("feeds", null,
BaseColumns._ID + "=?", BaseColumns._ID + "=?",

View File

@ -1,6 +1,7 @@
package org.fox.ttrss.offline; package org.fox.ttrss.offline;
import org.fox.ttrss.R; import org.fox.ttrss.R;
import org.fox.ttrss.types.Article;
import android.app.Activity; import android.app.Activity;
import android.database.Cursor; import android.database.Cursor;
@ -206,21 +207,41 @@ public class OfflineArticlePager extends Fragment {
public void setArticleId(int articleId) { public void setArticleId(int articleId) {
m_articleId = articleId; m_articleId = articleId;
m_cursor.moveToFirst(); int position = getArticleIdPosition(articleId);
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();
}
ViewPager pager = (ViewPager) getView().findViewById(R.id.article_pager); ViewPager pager = (ViewPager) getView().findViewById(R.id.article_pager);
pager.setCurrentItem(position); 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 i;
} }
return 0; return -1;
} }
public int getArticleCount() { public int getArticleCount() {