implement default browsing of articles

This commit is contained in:
Andrew Dolgov 2012-09-19 16:59:08 +04:00
parent d733127fa1
commit d70e6463ad
9 changed files with 109 additions and 15 deletions

View File

@ -1,5 +1,9 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/browse_headlines"
android:title="@string/category_browse_headlines"/>
<item
android:id="@+id/browse_articles"
android:title="@string/category_browse_articles"/>

View File

@ -1,5 +1,13 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/browse_headlines"
android:title="@string/category_browse_headlines"/>
<item
android:id="@+id/browse_articles"
android:title="@string/category_browse_articles"/>
<item
android:id="@+id/catchup_feed"
android:title="@string/catchup"/>

View File

@ -17,5 +17,13 @@
<item>1</item>
<item>2</item>
</string-array>
<string-array name="pref_view_mode_names">
<item>@string/category_browse_headlines</item>
<item>@string/category_browse_articles</item>
</string-array>
<string-array name="pref_view_mode_values">
<item>HEADLINES</item>
<item>ARTICLES</item>
</string-array>
</resources>

View File

@ -131,4 +131,7 @@
<string name="update_headlines">Refresh</string>
<string name="attachment_share">Share</string>
<string name="error_network_unavailable">Error: network unavailable</string>
<string name="category_browse_headlines">Browse headlines</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>
</resources>

View File

@ -98,6 +98,15 @@
android:defaultValue="true"
android:key="justify_article_text"
android:title="@string/justify_article_text" />
<ListPreference
android:defaultValue="HEADLINES"
android:entries="@array/pref_view_mode_names"
android:entryValues="@array/pref_view_mode_values"
android:key="default_view_mode"
android:summary="@string/pref_default_view_mode_long"
android:title="@string/pref_default_view_mode" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/offline_mode" >

View File

@ -104,10 +104,11 @@ public class ArticlePager extends Fragment {
if (article != null) {
m_article = article;
if (article.unread) {
/* if (article.unread) {
article.unread = false;
m_activity.saveArticleUnread(article);
}
} */
m_listener.onArticleSelected(article, false);
//Log.d(TAG, "Page #" + position + "/" + m_adapter.getCount());
@ -147,6 +148,15 @@ public class ArticlePager extends Fragment {
if (result != null) {
m_adapter.notifyDataSetChanged();
if (m_article.id == 0) {
if (m_articles.size() > 0) {
Log.d(TAG, "blank id on refresh");
m_article = m_articles.get(0);
m_listener.onArticleSelected(m_article, false);
}
}
} else {
if (m_lastError == ApiError.LOGIN_FAILED) {
m_activity.login();

View File

@ -92,6 +92,15 @@ public class FeedCategoriesFragment extends Fragment implements OnItemClickListe
switch (item.getItemId()) {
case R.id.browse_articles:
if (true) {
FeedCategory cat = getCategoryAtPosition(info.position);
if (cat != null) {
m_activity.openFeedArticles(new Feed(cat.id, cat.title, true));
//setSelectedCategory(cat);
}
}
return true;
case R.id.browse_headlines:
if (true) {
FeedCategory cat = getCategoryAtPosition(info.position);
if (cat != null) {
@ -392,7 +401,15 @@ public class FeedCategoriesFragment extends Fragment implements OnItemClickListe
if (list != null) {
FeedCategory cat = (FeedCategory)list.getItemAtPosition(position);
m_activity.onCatSelected(cat);
if ("ARTICLES".equals(m_prefs.getString("default_view_mode", "HEADLINES")) &&
m_prefs.getBoolean("browse_cats_like_feeds", false)) {
m_activity.openFeedArticles(new Feed(cat.id, cat.title, true));
} else {
m_activity.onCatSelected(cat);
}
if (!m_activity.isSmallScreen())
m_selectedCat = cat;

View File

@ -68,7 +68,7 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
ap.setSearchQuery(intent.getStringExtra("searchQuery"));
setTitle(intent.getStringExtra("feedTitle"));
setTitle(feed.title);
} else {
if (feed != null) {
HeadlinesFragment hf = new HeadlinesFragment(feed);
@ -136,20 +136,14 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
}
}
public void onFeedSelected(Feed feed) {
GlobalState.getInstance().m_loadedArticles.clear();
if (isSmallScreen()) {
Intent intent = new Intent(FeedsActivity.this, FeedsActivity.class);
intent.putExtra("feed", feed);
startActivityForResult(intent, 0);
//HeadlinesFragment hf = new HeadlinesFragment(feed);
//ft.replace(R.id.feeds_fragment, hf, FRAG_HEADLINES);
//ft.addToBackStack(null);
} else {
FragmentTransaction ft = getSupportFragmentManager()
.beginTransaction();
@ -240,6 +234,22 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
initMenu();
}
public void openFeedArticles(Feed feed) {
if (isSmallScreen()) {
Intent intent = new Intent(FeedsActivity.this, FeedsActivity.class);
GlobalState.getInstance().m_activeFeed = feed;
GlobalState.getInstance().m_loadedArticles.clear();
intent.putExtra("feed", feed);
intent.putExtra("article", new Article());
startActivityForResult(intent, 0);
} else {
}
}
public void onArticleSelected(Article article, boolean open) {
if (article.unread) {
article.unread = false;
@ -252,7 +262,6 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
if (isSmallScreen()) {
Intent intent = new Intent(FeedsActivity.this, FeedsActivity.class);
intent.putExtra("feedTitle", hf.getFeed().title);
intent.putExtra("feed", hf.getFeed());
intent.putExtra("article", article);
intent.putExtra("searchQuery", hf.getSearchQuery());

View File

@ -20,6 +20,7 @@ import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import org.fox.ttrss.types.Article;
import org.fox.ttrss.types.Feed;
import org.fox.ttrss.types.FeedCategory;
import org.fox.ttrss.types.FeedList;
@ -136,6 +137,22 @@ public class FeedsFragment extends Fragment implements OnItemClickListener, OnSh
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item
.getMenuInfo();
switch (item.getItemId()) {
case R.id.browse_articles:
if (true) {
Feed feed = getFeedAtPosition(info.position);
if (feed != null) {
m_activity.openFeedArticles(feed);
}
}
return true;
case R.id.browse_headlines:
if (true) {
Feed feed = getFeedAtPosition(info.position);
if (feed != null) {
m_activity.onFeedSelected(feed);
}
}
return true;
case R.id.catchup_feed:
if (true) {
Feed feed = getFeedAtPosition(info.position);
@ -163,6 +180,11 @@ public class FeedsFragment extends Fragment implements OnItemClickListener, OnSh
if (feed != null)
menu.setHeaderTitle(feed.title);
if (!m_activity.isSmallScreen()) {
menu.findItem(R.id.browse_headlines).setVisible(false);
menu.findItem(R.id.browse_feeds).setVisible(false);
}
super.onCreateContextMenu(menu, v, menuInfo);
}
@ -239,8 +261,12 @@ public class FeedsFragment extends Fragment implements OnItemClickListener, OnSh
cat.title = feed.title;
m_activity.onCatSelected(cat);
} else {
m_activity.onFeedSelected(feed);
} else {
if ("ARTICLES".equals(m_prefs.getString("default_view_mode", "HEADLINES"))) {
m_activity.openFeedArticles(feed);
} else {
m_activity.onFeedSelected(feed);
}
}
if (!m_activity.isSmallScreen())