diff --git a/res/menu/category_menu.xml b/res/menu/category_menu.xml index 59ff8f8c..a1e5f81b 100644 --- a/res/menu/category_menu.xml +++ b/res/menu/category_menu.xml @@ -8,4 +8,8 @@ android:id="@+id/browse_feeds" android:title="@string/category_browse_feeds"/> + + \ No newline at end of file diff --git a/res/menu/feed_menu.xml b/res/menu/feed_menu.xml new file mode 100644 index 00000000..ff58a881 --- /dev/null +++ b/res/menu/feed_menu.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/res/values/strings.xml b/res/values/strings.xml index c73be87f..8c80ddcf 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -32,6 +32,7 @@ Refresh feeds Close article Share article + Mark as read Sort feeds by unread count Load more... Show all articles diff --git a/src/org/fox/ttrss/FeedCategoriesFragment.java b/src/org/fox/ttrss/FeedCategoriesFragment.java index c2f4f298..a607403c 100644 --- a/src/org/fox/ttrss/FeedCategoriesFragment.java +++ b/src/org/fox/ttrss/FeedCategoriesFragment.java @@ -14,6 +14,7 @@ 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; @@ -83,19 +84,25 @@ public class FeedCategoriesFragment extends Fragment implements OnItemClickListe AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); FeedCategory cat = m_adapter.getItem(info.position); + Log.d(TAG, "onContextItemSelected=" + cat); + MainActivity activity = (MainActivity)getActivity(); if (cat != null) { - m_selectedCatId = cat.id; - m_adapter.notifyDataSetChanged(); - switch (item.getItemId()) { case R.id.browse_articles: + m_selectedCatId = cat.id; + m_adapter.notifyDataSetChanged(); activity.viewCategory(cat, true); break; case R.id.browse_feeds: + m_selectedCatId = cat.id; + m_adapter.notifyDataSetChanged(); activity.viewCategory(cat, false); break; + case R.id.catchup_category: + activity.catchupFeed(new Feed(cat.id, cat.title, true)); + break; } } diff --git a/src/org/fox/ttrss/FeedsFragment.java b/src/org/fox/ttrss/FeedsFragment.java index de30ed6e..370439d8 100644 --- a/src/org/fox/ttrss/FeedsFragment.java +++ b/src/org/fox/ttrss/FeedsFragment.java @@ -38,10 +38,14 @@ import android.os.Environment; import android.preference.PreferenceManager; import android.support.v4.app.Fragment; import android.util.Log; +import android.view.ContextMenu; import android.view.LayoutInflater; +import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; +import android.view.ContextMenu.ContextMenuInfo; import android.widget.AdapterView; +import android.widget.AdapterView.AdapterContextMenuInfo; import android.widget.AdapterView.OnItemClickListener; import android.widget.ArrayAdapter; import android.widget.ImageView; @@ -91,6 +95,36 @@ public class FeedsFragment extends Fragment implements OnItemClickListener, OnSh } } + + @Override + public void onCreateContextMenu(ContextMenu menu, View v, + ContextMenuInfo menuInfo) { + + getActivity().getMenuInflater().inflate(R.menu.feed_menu, menu); + super.onCreateContextMenu(menu, v, menuInfo); + + } + + @Override + public boolean onContextItemSelected(MenuItem item) { + AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); + Feed feed = m_adapter.getItem(info.position); + + MainActivity activity = (MainActivity)getActivity(); + + Log.d(TAG, "onContextItemSelected=" + feed); + + if (feed != null) { + switch (item.getItemId()) { + case R.id.catchup_feed: + activity.catchupFeed(feed); + break; + } + } + + return true; + } + @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { @@ -107,6 +141,11 @@ public class FeedsFragment extends Fragment implements OnItemClickListener, OnSh list.setAdapter(m_adapter); list.setOnItemClickListener(this); + // http://code.google.com/p/android/issues/detail?id=20065 + // categories fragment is displayed first, so it hogs the context menu events. thanks, google! + if (m_prefs.getBoolean("enable_cats", false)) + registerForContextMenu(list); + m_enableFeedIcons = m_prefs.getBoolean("download_feed_icons", false); if (m_feeds == null || m_feeds.size() == 0) diff --git a/src/org/fox/ttrss/MainActivity.java b/src/org/fox/ttrss/MainActivity.java index 133275fb..1fa4bfd8 100644 --- a/src/org/fox/ttrss/MainActivity.java +++ b/src/org/fox/ttrss/MainActivity.java @@ -119,6 +119,33 @@ public class MainActivity extends FragmentActivity implements FeedsFragment.OnFe return tmp.replaceAll(",$", ""); } + @SuppressWarnings("unchecked") + public void catchupFeed(final Feed feed) { + Log.d(TAG, "catchupFeed=" + feed); + + ApiRequest req = new ApiRequest(getApplicationContext()) { + protected void onPostExecute(JsonElement result) { + if (!m_enableCats || m_activeCategory != null) + refreshFeeds(); + else + refreshCategories(); + } + + }; + + @SuppressWarnings("serial") + HashMap map = new HashMap() { + { + put("sid", m_sessionId); + put("op", "catchupFeed"); + put("feed_id", String.valueOf(feed.id)); + if (feed.is_cat) put("is_cat", "1"); + } + }; + + req.execute(map); + } + @SuppressWarnings("unchecked") public void toggleArticlesMarked(final ArticleList articles) { ApiRequest req = new ApiRequest(getApplicationContext());