From 980b5696e34b7025cd62d829fa9032bc864c2ab6 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 29 Nov 2011 13:02:16 +0300 Subject: [PATCH] implement browsing categories like feeds --- res/menu/category_menu.xml | 11 ++++ res/values/strings.xml | 4 +- res/xml/preferences.xml | 2 + src/org/fox/ttrss/Feed.java | 11 +++- src/org/fox/ttrss/FeedCategoriesFragment.java | 42 ++++++++++++- src/org/fox/ttrss/HeadlinesFragment.java | 3 + src/org/fox/ttrss/MainActivity.java | 59 +++++++++++++------ 7 files changed, 109 insertions(+), 23 deletions(-) create mode 100644 res/menu/category_menu.xml diff --git a/res/menu/category_menu.xml b/res/menu/category_menu.xml new file mode 100644 index 00000000..d437a0ca --- /dev/null +++ b/res/menu/category_menu.xml @@ -0,0 +1,11 @@ + + + + + + + \ No newline at end of file diff --git a/res/values/strings.xml b/res/values/strings.xml index 2bd63ab7..6f2f0a8c 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -52,8 +52,8 @@ Close category No feeds to display No headlines to display - - Error: %1$s + Browse categories like feeds + You can long-tap on a category to override this setting No error Error: Unknown error (see log) diff --git a/res/xml/preferences.xml b/res/xml/preferences.xml index dff4afdf..6c397f24 100644 --- a/res/xml/preferences.xml +++ b/res/xml/preferences.xml @@ -27,6 +27,8 @@ + diff --git a/src/org/fox/ttrss/Feed.java b/src/org/fox/ttrss/Feed.java index de1e8602..0582d406 100644 --- a/src/org/fox/ttrss/Feed.java +++ b/src/org/fox/ttrss/Feed.java @@ -11,6 +11,13 @@ public class Feed implements Comparable, Parcelable { boolean has_icon; int cat_id; int last_updated; + boolean is_cat; + + public Feed(int id, String title, boolean is_cat) { + this.id = id; + this.title = title; + this.is_cat = is_cat; + } public Feed(Parcel in) { readFromParcel(in); @@ -37,7 +44,8 @@ public class Feed implements Comparable, Parcelable { out.writeInt(unread); out.writeInt(has_icon ? 1 : 0); out.writeInt(cat_id); - out.writeInt(last_updated); + out.writeInt(last_updated); + out.writeInt(is_cat ? 1 : 0); } public void readFromParcel(Parcel in) { @@ -48,6 +56,7 @@ public class Feed implements Comparable, Parcelable { has_icon = in.readInt() == 1; cat_id = in.readInt(); last_updated = in.readInt(); + is_cat = in.readInt() == 1; } @SuppressWarnings("rawtypes") diff --git a/src/org/fox/ttrss/FeedCategoriesFragment.java b/src/org/fox/ttrss/FeedCategoriesFragment.java index 409f6e13..ea9c433a 100644 --- a/src/org/fox/ttrss/FeedCategoriesFragment.java +++ b/src/org/fox/ttrss/FeedCategoriesFragment.java @@ -14,10 +14,15 @@ import android.content.SharedPreferences.OnSharedPreferenceChangeListener; import android.os.Bundle; import android.preference.PreferenceManager; import android.support.v4.app.Fragment; +import android.util.Log; +import android.view.ContextMenu; +import android.view.ContextMenu.ContextMenuInfo; import android.view.LayoutInflater; +import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; +import android.widget.AdapterView.AdapterContextMenuInfo; import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.ImageView; @@ -65,6 +70,39 @@ public class FeedCategoriesFragment extends Fragment implements OnItemClickListe } + @Override + public void onCreateContextMenu(ContextMenu menu, View v, + ContextMenuInfo menuInfo) { + + getActivity().getMenuInflater().inflate(R.menu.category_menu, menu); + super.onCreateContextMenu(menu, v, menuInfo); + + } + + @Override + public boolean onContextItemSelected(MenuItem item) { + AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); + FeedCategory cat = m_adapter.getItem(info.position); + + MainActivity activity = (MainActivity)getActivity(); + + if (cat != null) { + m_selectedCatId = cat.id; + m_adapter.notifyDataSetChanged(); + + switch (item.getItemId()) { + case R.id.browse_articles: + activity.viewCategory(cat, true); + break; + case R.id.browse_feeds: + activity.viewCategory(cat, false); + break; + } + } + + return true; + } + @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (savedInstanceState != null) { @@ -78,6 +116,7 @@ public class FeedCategoriesFragment extends Fragment implements OnItemClickListe m_adapter = new FeedCategoryListAdapter(getActivity(), R.layout.feeds_row, (ArrayList)m_cats); list.setAdapter(m_adapter); list.setOnItemClickListener(this); + registerForContextMenu(list); if (m_cats == null || m_cats.size() == 0) refresh(false); @@ -297,7 +336,8 @@ public class FeedCategoriesFragment extends Fragment implements OnItemClickListe @Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { - // TODO Auto-generated method stub + + sortCats(); } diff --git a/src/org/fox/ttrss/HeadlinesFragment.java b/src/org/fox/ttrss/HeadlinesFragment.java index defd5ee0..63fa52f9 100644 --- a/src/org/fox/ttrss/HeadlinesFragment.java +++ b/src/org/fox/ttrss/HeadlinesFragment.java @@ -105,6 +105,7 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener { final String sessionId = ((MainActivity)getActivity()).getSessionId(); final boolean showUnread = ((MainActivity)getActivity()).getUnreadArticlesOnly(); + final boolean isCat = m_feed.is_cat; int skip = 0; if (append) { @@ -131,6 +132,8 @@ public class HeadlinesFragment extends Fragment implements OnItemClickListener { put("offset", String.valueOf(0)); put("view_mode", showUnread ? "adaptive" : "all_articles"); put("skip", String.valueOf(fskip)); + + if (isCat) put("is_cat", "true"); } }; diff --git a/src/org/fox/ttrss/MainActivity.java b/src/org/fox/ttrss/MainActivity.java index 02677b38..66066465 100644 --- a/src/org/fox/ttrss/MainActivity.java +++ b/src/org/fox/ttrss/MainActivity.java @@ -378,12 +378,19 @@ public class MainActivity extends FragmentActivity implements FeedsFragment.OnFe findViewById(R.id.main).setAnimation(AnimationUtils.loadAnimation(this, R.anim.slide_right)); } - findViewById(R.id.headlines_fragment).setVisibility(View.GONE); - findViewById(R.id.feeds_fragment).setVisibility(View.VISIBLE); - - m_activeFeed = null; + if (m_activeFeed.is_cat) { + findViewById(R.id.headlines_fragment).setVisibility(View.GONE); + findViewById(R.id.cats_fragment).setVisibility(View.VISIBLE); + + refreshCategories(); + } else { + findViewById(R.id.headlines_fragment).setVisibility(View.GONE); + findViewById(R.id.feeds_fragment).setVisibility(View.VISIBLE); + + refreshFeeds(); + } + m_activeFeed = null; initMainMenu(); - refreshFeeds(); } else if (m_activeCategory != null) { if (m_compatMode) { @@ -756,7 +763,6 @@ public class MainActivity extends FragmentActivity implements FeedsFragment.OnFe @Override public void onFeedSelected(Feed feed) { - Log.d(TAG, "Selected feed: " + feed.toString()); viewFeed(feed, false); } @@ -788,19 +794,34 @@ public class MainActivity extends FragmentActivity implements FeedsFragment.OnFe } } - public void viewCategory(FeedCategory cat) { - m_activeCategory = cat; + public void viewCategory(FeedCategory cat, boolean openAsFeed) { + + if (!openAsFeed) { + findViewById(R.id.cats_fragment).setVisibility(View.GONE); + findViewById(R.id.feeds_fragment).setVisibility(View.VISIBLE); + + m_activeCategory = cat; + + FeedsFragment frag = new FeedsFragment(); + FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); + ft.replace(R.id.feeds_fragment, frag); + ft.commit(); + } else { + findViewById(R.id.cats_fragment).setVisibility(View.GONE); + findViewById(R.id.headlines_fragment).setVisibility(View.VISIBLE); + + m_activeFeed = new Feed(cat.id, cat.title, true); + + HeadlinesFragment frag = new HeadlinesFragment(); + + FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); + ft.replace(R.id.headlines_fragment, frag); + ft.commit(); + + } + initMainMenu(); - - findViewById(R.id.cats_fragment).setVisibility(View.GONE); - findViewById(R.id.feeds_fragment).setVisibility(View.VISIBLE); - - FeedsFragment frag = new FeedsFragment(); - - FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); - ft.replace(R.id.feeds_fragment, frag); - ft.commit(); } public void openArticle(Article article, int compatAnimation) { @@ -934,7 +955,7 @@ public class MainActivity extends FragmentActivity implements FeedsFragment.OnFe @Override public void onCatSelected(FeedCategory cat) { - m_activeCategory = cat; - viewCategory(cat); + Log.d(TAG, "onCatSelected"); + viewCategory(cat, m_prefs.getBoolean("browse_cats_like_feeds", false)); } } \ No newline at end of file