add experimental feed context menu
This commit is contained in:
parent
823ea28ff5
commit
ef38363cdc
@ -8,4 +8,8 @@
|
|||||||
android:id="@+id/browse_feeds"
|
android:id="@+id/browse_feeds"
|
||||||
android:title="@string/category_browse_feeds"/>
|
android:title="@string/category_browse_feeds"/>
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/catchup_category"
|
||||||
|
android:title="@string/catchup"/>
|
||||||
|
|
||||||
</menu>
|
</menu>
|
7
res/menu/feed_menu.xml
Normal file
7
res/menu/feed_menu.xml
Normal 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>
|
@ -32,6 +32,7 @@
|
|||||||
<string name="update_feeds">Refresh feeds</string>
|
<string name="update_feeds">Refresh feeds</string>
|
||||||
<string name="close_article">Close article</string>
|
<string name="close_article">Close article</string>
|
||||||
<string name="share_article">Share 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="sort_feeds_by_unread">Sort feeds by unread count</string>
|
||||||
<string name="load_more_articles">Load more...</string>
|
<string name="load_more_articles">Load more...</string>
|
||||||
<string name="show_all_articles">Show all articles</string>
|
<string name="show_all_articles">Show all articles</string>
|
||||||
|
@ -14,6 +14,7 @@ import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.ContextMenu;
|
import android.view.ContextMenu;
|
||||||
import android.view.ContextMenu.ContextMenuInfo;
|
import android.view.ContextMenu.ContextMenuInfo;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
@ -83,19 +84,25 @@ public class FeedCategoriesFragment extends Fragment implements OnItemClickListe
|
|||||||
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
|
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
|
||||||
FeedCategory cat = m_adapter.getItem(info.position);
|
FeedCategory cat = m_adapter.getItem(info.position);
|
||||||
|
|
||||||
|
Log.d(TAG, "onContextItemSelected=" + cat);
|
||||||
|
|
||||||
MainActivity activity = (MainActivity)getActivity();
|
MainActivity activity = (MainActivity)getActivity();
|
||||||
|
|
||||||
if (cat != null) {
|
if (cat != null) {
|
||||||
m_selectedCatId = cat.id;
|
|
||||||
m_adapter.notifyDataSetChanged();
|
|
||||||
|
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case R.id.browse_articles:
|
case R.id.browse_articles:
|
||||||
|
m_selectedCatId = cat.id;
|
||||||
|
m_adapter.notifyDataSetChanged();
|
||||||
activity.viewCategory(cat, true);
|
activity.viewCategory(cat, true);
|
||||||
break;
|
break;
|
||||||
case R.id.browse_feeds:
|
case R.id.browse_feeds:
|
||||||
|
m_selectedCatId = cat.id;
|
||||||
|
m_adapter.notifyDataSetChanged();
|
||||||
activity.viewCategory(cat, false);
|
activity.viewCategory(cat, false);
|
||||||
break;
|
break;
|
||||||
|
case R.id.catchup_category:
|
||||||
|
activity.catchupFeed(new Feed(cat.id, cat.title, true));
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,10 +38,14 @@ import android.os.Environment;
|
|||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.view.ContextMenu;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.view.ContextMenu.ContextMenuInfo;
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
|
import android.widget.AdapterView.AdapterContextMenuInfo;
|
||||||
import android.widget.AdapterView.OnItemClickListener;
|
import android.widget.AdapterView.OnItemClickListener;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.ImageView;
|
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
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
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.setAdapter(m_adapter);
|
||||||
list.setOnItemClickListener(this);
|
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);
|
m_enableFeedIcons = m_prefs.getBoolean("download_feed_icons", false);
|
||||||
|
|
||||||
if (m_feeds == null || m_feeds.size() == 0)
|
if (m_feeds == null || m_feeds.size() == 0)
|
||||||
|
@ -119,6 +119,33 @@ public class MainActivity extends FragmentActivity implements FeedsFragment.OnFe
|
|||||||
return tmp.replaceAll(",$", "");
|
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")
|
@SuppressWarnings("unchecked")
|
||||||
public void toggleArticlesMarked(final ArticleList articles) {
|
public void toggleArticlesMarked(final ArticleList articles) {
|
||||||
ApiRequest req = new ApiRequest(getApplicationContext());
|
ApiRequest req = new ApiRequest(getApplicationContext());
|
||||||
|
Loading…
Reference in New Issue
Block a user