add experimental feed context menu

This commit is contained in:
Andrew Dolgov 2011-11-29 15:40:23 +03:00
parent 823ea28ff5
commit ef38363cdc
6 changed files with 88 additions and 3 deletions

View File

@ -8,4 +8,8 @@
android:id="@+id/browse_feeds"
android:title="@string/category_browse_feeds"/>
<item
android:id="@+id/catchup_category"
android:title="@string/catchup"/>
</menu>

7
res/menu/feed_menu.xml Normal file
View File

@ -0,0 +1,7 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/catchup_feed"
android:title="@string/catchup"/>
</menu>

View File

@ -32,6 +32,7 @@
<string name="update_feeds">Refresh feeds</string>
<string name="close_article">Close article</string>
<string name="share_article">Share article</string>
<string name="catchup">Mark as read</string>
<string name="sort_feeds_by_unread">Sort feeds by unread count</string>
<string name="load_more_articles">Load more...</string>
<string name="show_all_articles">Show all articles</string>

View File

@ -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;
}
}

View File

@ -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)

View File

@ -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<String,String> map = new HashMap<String,String>() {
{
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());