mirror of
https://github.com/viq/NewsBlur.git
synced 2025-09-18 21:43:31 +00:00
Merge pull request #658 from manderson23/mark
Android: Global Shared Stories
This commit is contained in:
commit
b400cc079b
17 changed files with 358 additions and 51 deletions
|
@ -77,6 +77,9 @@
|
|||
|
||||
<activity
|
||||
android:name=".activity.AllSharedStoriesItemsList" />
|
||||
|
||||
<activity
|
||||
android:name=".activity.GlobalSharedStoriesItemsList" />
|
||||
|
||||
<activity
|
||||
android:name=".activity.FolderItemsList" />
|
||||
|
@ -95,6 +98,9 @@
|
|||
|
||||
<activity
|
||||
android:name=".activity.AllSharedStoriesReading"/>
|
||||
|
||||
<activity
|
||||
android:name=".activity.GlobalSharedStoriesReading"/>
|
||||
|
||||
<activity
|
||||
android:name=".activity.FolderReading"/>
|
||||
|
|
BIN
clients/android/NewsBlur/res/drawable/ak_icon_global.png
Normal file
BIN
clients/android/NewsBlur/res/drawable/ak_icon_global.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.4 KiB |
|
@ -0,0 +1,42 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
style="?selectorFolderBackground" >
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/row_everything_icon"
|
||||
android:layout_width="19dp"
|
||||
android:layout_height="19dp"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_marginLeft="12dp"
|
||||
android:layout_marginRight="12dp"
|
||||
android:contentDescription="@string/description_row_folder_icon"
|
||||
android:src="@drawable/ak_icon_global" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/row_everythingtext"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_toRightOf="@id/row_everything_icon"
|
||||
android:paddingBottom="10dp"
|
||||
android:paddingTop="10dp"
|
||||
android:text="@string/global_shared_stories"
|
||||
style="?selectorRowFeedName"
|
||||
android:textSize="14dp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:layout_alignParentTop="true"
|
||||
style="?folderBorderTop" />
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:layout_alignParentBottom="true"
|
||||
style="?folderBorderBottom" />
|
||||
|
||||
</RelativeLayout>
|
|
@ -40,6 +40,7 @@
|
|||
|
||||
<string name="all_stories_row_title">ALL STORIES</string>
|
||||
<string name="all_shared_stories">ALL SHARED STORIES</string>
|
||||
<string name="global_shared_stories">GLOBAL SHARED STORIES</string>
|
||||
<string name="saved_stories_row_title">SAVED STORIES</string>
|
||||
<string name="saved_stories_title">Saved Stories</string>
|
||||
|
||||
|
|
|
@ -0,0 +1,93 @@
|
|||
package com.newsblur.activity;
|
||||
|
||||
import android.app.FragmentTransaction;
|
||||
import android.content.ContentResolver;
|
||||
import android.os.Bundle;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
|
||||
import com.newsblur.R;
|
||||
import com.newsblur.fragment.GlobalSharedStoriesItemListFragment;
|
||||
import com.newsblur.util.DefaultFeedView;
|
||||
import com.newsblur.util.FeedSet;
|
||||
import com.newsblur.util.PrefConstants;
|
||||
import com.newsblur.util.PrefsUtils;
|
||||
import com.newsblur.util.ReadFilter;
|
||||
import com.newsblur.util.StoryOrder;
|
||||
|
||||
public class GlobalSharedStoriesItemsList extends ItemsList {
|
||||
|
||||
private ContentResolver resolver;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle bundle) {
|
||||
super.onCreate(bundle);
|
||||
|
||||
setTitle(getResources().getString(R.string.global_shared_stories));
|
||||
|
||||
resolver = getContentResolver();
|
||||
|
||||
itemListFragment = (GlobalSharedStoriesItemListFragment) fragmentManager.findFragmentByTag(GlobalSharedStoriesItemListFragment.class.getName());
|
||||
if (itemListFragment == null) {
|
||||
itemListFragment = GlobalSharedStoriesItemListFragment.newInstance(getDefaultFeedView(), currentState);
|
||||
itemListFragment.setRetainInstance(true);
|
||||
FragmentTransaction listTransaction = fragmentManager.beginTransaction();
|
||||
listTransaction.add(R.id.activity_itemlist_container, itemListFragment, GlobalSharedStoriesItemListFragment.class.getName());
|
||||
listTransaction.commit();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FeedSet createFeedSet() {
|
||||
return FeedSet.globalShared();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markItemListAsRead() {
|
||||
; // This activity has no mark-as-read action
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
MenuInflater inflater = getMenuInflater();
|
||||
inflater.inflate(R.menu.allsocialstories_itemslist, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DefaultFeedView getDefaultFeedView() {
|
||||
return PrefsUtils.getDefaultFeedViewForFolder(this, PrefConstants.GLOBAL_SHARED_STORIES_FOLDER_NAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void defaultFeedViewChanged(DefaultFeedView value) {
|
||||
PrefsUtils.setDefaultFeedViewForFolder(this, PrefConstants.GLOBAL_SHARED_STORIES_FOLDER_NAME, value);
|
||||
if (itemListFragment != null) {
|
||||
itemListFragment.setDefaultFeedView(value);
|
||||
}
|
||||
}
|
||||
|
||||
// Story order and read filter are fixed for global shared stories
|
||||
|
||||
@Override
|
||||
public StoryOrder getStoryOrder() {
|
||||
return StoryOrder.NEWEST;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateStoryOrderPreference(StoryOrder newValue) {
|
||||
// Not supported for global shared stories
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateReadFilterPreference(ReadFilter newValue) {
|
||||
// Not supported for global shared stories
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReadFilter getReadFilter() {
|
||||
return ReadFilter.UNREAD;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package com.newsblur.activity;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.Menu;
|
||||
|
||||
import com.newsblur.R;
|
||||
import com.newsblur.database.MixedFeedsReadingAdapter;
|
||||
|
||||
public class GlobalSharedStoriesReading extends Reading {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceBundle) {
|
||||
super.onCreate(savedInstanceBundle);
|
||||
|
||||
setTitle(getResources().getString(R.string.global_shared_stories));
|
||||
readingAdapter = new MixedFeedsReadingAdapter(getFragmentManager(), defaultFeedView, null);
|
||||
|
||||
getLoaderManager().initLoader(0, null, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
super.onCreateOptionsMenu(menu);
|
||||
menu.removeItem(R.id.menu_reading_markunread);
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -253,7 +253,8 @@ public abstract class Reading extends NbActivity implements OnPageChangeListener
|
|||
* Query the DB for the current unreadcount for this view.
|
||||
*/
|
||||
private int getUnreadCount() {
|
||||
if (fs.isAllSaved()) return 0; // saved stories doesn't have unreads
|
||||
// saved stories and global shared stories don't have unreads
|
||||
if (fs.isAllSaved() || fs.isGlobalShared()) return 0;
|
||||
return FeedUtils.dbHelper.getUnreadCount(fs, currentState);
|
||||
}
|
||||
|
||||
|
|
|
@ -655,6 +655,7 @@ public class BlurDatabaseHelper {
|
|||
q.append(" FROM " + DatabaseConstants.SOCIALFEED_STORY_MAP_TABLE);
|
||||
q.append(DatabaseConstants.JOIN_STORIES_ON_SOCIALFEED_MAP);
|
||||
q.append(DatabaseConstants.JOIN_FEEDS_ON_STORIES);
|
||||
q.append(DatabaseConstants.JOIN_SOCIAL_FEEDS_ON_SOCIALFEED_MAP);
|
||||
DatabaseConstants.appendStorySelectionGroupOrder(q, readFilter, order, stateFilter, DatabaseConstants.STORY_TABLE + "." + DatabaseConstants.STORY_ID);
|
||||
return rawQuery(q.toString(), null, cancellationSignal);
|
||||
|
||||
|
@ -668,6 +669,14 @@ public class BlurDatabaseHelper {
|
|||
q.append(" ORDER BY " + DatabaseConstants.STARRED_STORY_ORDER);
|
||||
return rawQuery(q.toString(), null, cancellationSignal);
|
||||
|
||||
} else if (fs.isGlobalShared()) {
|
||||
|
||||
StringBuilder q = new StringBuilder(DatabaseConstants.MULTIFEED_STORIES_QUERY_BASE);
|
||||
q.append(" FROM " + DatabaseConstants.SOCIALFEED_STORY_MAP_TABLE);
|
||||
q.append(DatabaseConstants.JOIN_STORIES_ON_SOCIALFEED_MAP);
|
||||
q.append(DatabaseConstants.JOIN_FEEDS_ON_STORIES);
|
||||
DatabaseConstants.appendStorySelectionGroupOrder(q, readFilter, order, stateFilter, DatabaseConstants.STORY_TABLE + "." + DatabaseConstants.STORY_ID);
|
||||
return rawQuery(q.toString(), null, cancellationSignal);
|
||||
} else {
|
||||
throw new IllegalStateException("Asked to get stories for FeedSet of unknown type.");
|
||||
}
|
||||
|
|
|
@ -325,6 +325,9 @@ public class DatabaseConstants {
|
|||
public static final String JOIN_STORIES_ON_SOCIALFEED_MAP =
|
||||
" INNER JOIN " + STORY_TABLE + " ON " + STORY_TABLE + "." + STORY_ID + " = " + SOCIALFEED_STORY_MAP_TABLE + "." + SOCIALFEED_STORY_STORYID;
|
||||
|
||||
public static final String JOIN_SOCIAL_FEEDS_ON_SOCIALFEED_MAP =
|
||||
" INNER JOIN " + SOCIALFEED_TABLE + " ON " + SOCIALFEED_TABLE + "." + SOCIAL_FEED_ID + " = " + SOCIALFEED_STORY_MAP_TABLE + "." + SOCIALFEED_STORY_USER_ID;
|
||||
|
||||
public static final String STARRED_STORY_ORDER = STORY_STARRED_DATE + " DESC";
|
||||
|
||||
/**
|
||||
|
|
|
@ -26,6 +26,7 @@ import com.newsblur.R;
|
|||
import com.newsblur.activity.AllSharedStoriesItemsList;
|
||||
import com.newsblur.activity.AllStoriesItemsList;
|
||||
import com.newsblur.activity.FolderItemsList;
|
||||
import com.newsblur.activity.GlobalSharedStoriesItemsList;
|
||||
import com.newsblur.activity.NewsBlurApplication;
|
||||
import static com.newsblur.database.DatabaseConstants.getStr;
|
||||
import com.newsblur.domain.Feed;
|
||||
|
@ -39,7 +40,10 @@ import com.newsblur.util.StateFilter;
|
|||
*/
|
||||
public class FolderListAdapter extends BaseExpandableListAdapter {
|
||||
|
||||
private enum GroupType { ALL_SHARED_STORIES, ALL_STORIES, FOLDER, SAVED_STORIES }
|
||||
public static final int GLOBAL_SHARED_STORIES_GROUP_POSITION = 0;
|
||||
public static final int ALL_SHARED_STORIES_GROUP_POSITION = 1;
|
||||
|
||||
private enum GroupType { GLOBAL_SHARED_STORIES, ALL_SHARED_STORIES, ALL_STORIES, FOLDER, SAVED_STORIES }
|
||||
private enum ChildType { SOCIAL_FEED, FEED }
|
||||
|
||||
private Cursor socialFeedCursor;
|
||||
|
@ -69,7 +73,17 @@ public class FolderListAdapter extends BaseExpandableListAdapter {
|
|||
@Override
|
||||
public synchronized View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
|
||||
View v = convertView;
|
||||
if (groupPosition == 0) {
|
||||
if (groupPosition == GLOBAL_SHARED_STORIES_GROUP_POSITION) {
|
||||
v = inflater.inflate(R.layout.row_global_shared_stories, null, false);
|
||||
((TextView) v.findViewById(R.id.row_everythingtext)).setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent i = new Intent(context, GlobalSharedStoriesItemsList.class);
|
||||
i.putExtra(GlobalSharedStoriesItemsList.EXTRA_STATE, currentState);
|
||||
((Activity) context).startActivityForResult(i, Activity.RESULT_OK);
|
||||
}
|
||||
});
|
||||
} else if (groupPosition == ALL_SHARED_STORIES_GROUP_POSITION) {
|
||||
v = inflater.inflate(R.layout.row_all_shared_stories, null, false);
|
||||
((TextView) v.findViewById(R.id.row_everythingtext)).setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
|
@ -115,7 +129,7 @@ public class FolderListAdapter extends BaseExpandableListAdapter {
|
|||
if (convertView == null) {
|
||||
v = inflater.inflate((isExpanded) ? R.layout.row_folder_collapsed : R.layout.row_folder_collapsed, parent, false);
|
||||
}
|
||||
final String folderName = activeFolderNames.get(groupPosition-1);
|
||||
final String folderName = activeFolderNames.get(convertGroupPositionToActiveFolderIndex(groupPosition));
|
||||
TextView folderTitle = ((TextView) v.findViewById(R.id.row_foldername));
|
||||
folderTitle.setText(folderName.toUpperCase());
|
||||
folderTitle.setOnClickListener(new OnClickListener() {
|
||||
|
@ -127,7 +141,8 @@ public class FolderListAdapter extends BaseExpandableListAdapter {
|
|||
((Activity) context).startActivity(i);
|
||||
}
|
||||
});
|
||||
bindCountViews(v, neutCounts.get(groupPosition-1), posCounts.get(groupPosition-1), false);
|
||||
int countPosition = convertGroupPositionToActiveFolderIndex(groupPosition);
|
||||
bindCountViews(v, neutCounts.get(countPosition), posCounts.get(countPosition), false);
|
||||
v.findViewById(R.id.row_foldersums).setVisibility(isExpanded ? View.INVISIBLE : View.VISIBLE);
|
||||
ImageView folderIconView = ((ImageView) v.findViewById(R.id.row_folder_icon));
|
||||
if ( folderIconView != null ) {
|
||||
|
@ -144,7 +159,7 @@ public class FolderListAdapter extends BaseExpandableListAdapter {
|
|||
@Override
|
||||
public synchronized View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
|
||||
View v;
|
||||
if (groupPosition == 0) {
|
||||
if (groupPosition == ALL_SHARED_STORIES_GROUP_POSITION) {
|
||||
socialFeedCursor.moveToPosition(childPosition);
|
||||
if (convertView == null) {
|
||||
v = inflater.inflate(R.layout.row_socialfeed, parent, false);
|
||||
|
@ -169,7 +184,7 @@ public class FolderListAdapter extends BaseExpandableListAdapter {
|
|||
posCounter.setVisibility(View.GONE);
|
||||
}
|
||||
} else {
|
||||
Feed f = activeFolderChildren.get(groupPosition-1).get(childPosition);
|
||||
Feed f = activeFolderChildren.get(convertGroupPositionToActiveFolderIndex(groupPosition)).get(childPosition);
|
||||
if (convertView == null) {
|
||||
v = inflater.inflate(R.layout.row_feed, parent, false);
|
||||
} else {
|
||||
|
@ -197,49 +212,57 @@ public class FolderListAdapter extends BaseExpandableListAdapter {
|
|||
|
||||
@Override
|
||||
public String getGroup(int groupPosition) {
|
||||
return activeFolderNames.get(groupPosition - 1);
|
||||
return activeFolderNames.get(convertGroupPositionToActiveFolderIndex(groupPosition));
|
||||
}
|
||||
|
||||
private int convertGroupPositionToActiveFolderIndex(int groupPosition) {
|
||||
// Global and social feeds are shown above the named folders so the groupPosition
|
||||
// needs to be adjusted to index into the active folders lists.
|
||||
return groupPosition - 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getGroupCount() {
|
||||
// in addition to the real folders returned by the /reader/feeds API, there are virtual folders
|
||||
// for social feeds and saved stories
|
||||
// for global shared stories, social feeds and saved stories
|
||||
if (activeFolderNames == null) return 0;
|
||||
return (activeFolderNames.size() + 2);
|
||||
return (activeFolderNames.size() + 3);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getGroupId(int groupPosition) {
|
||||
if (groupPosition == 0) {
|
||||
// the social folder doesn't have an ID, so just give it a really huge one
|
||||
// Global shared, all shared and saved stories don't have IDs so give them a really
|
||||
// huge one.
|
||||
if (groupPosition == GLOBAL_SHARED_STORIES_GROUP_POSITION) {
|
||||
return Long.MAX_VALUE;
|
||||
} else if (groupPosition == ALL_SHARED_STORIES_GROUP_POSITION) {
|
||||
return Long.MAX_VALUE-1;
|
||||
} else if (isRowSavedStories(groupPosition)) {
|
||||
// neither does the saved stories row, give it another
|
||||
return (Long.MAX_VALUE-1);
|
||||
return Long.MAX_VALUE-2;
|
||||
} else {
|
||||
return activeFolderNames.get(groupPosition-1).hashCode();
|
||||
return activeFolderNames.get(convertGroupPositionToActiveFolderIndex(groupPosition)).hashCode();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getChildrenCount(int groupPosition) {
|
||||
if (groupPosition == 0) {
|
||||
if (groupPosition == ALL_SHARED_STORIES_GROUP_POSITION) {
|
||||
if (socialFeedCursor == null) return 0;
|
||||
return socialFeedCursor.getCount();
|
||||
} else if (isRowSavedStories(groupPosition)) {
|
||||
return 0; // this row never has children
|
||||
} else if (isRowSavedStories(groupPosition) || groupPosition == GLOBAL_SHARED_STORIES_GROUP_POSITION) {
|
||||
return 0; // these rows never have children
|
||||
} else {
|
||||
return activeFolderChildren.get(groupPosition-1).size();
|
||||
return activeFolderChildren.get(convertGroupPositionToActiveFolderIndex(groupPosition)).size();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getChild(int groupPosition, int childPosition) {
|
||||
if (groupPosition == 0) {
|
||||
if (groupPosition == ALL_SHARED_STORIES_GROUP_POSITION) {
|
||||
socialFeedCursor.moveToPosition(childPosition);
|
||||
return getStr(socialFeedCursor, DatabaseConstants.SOCIAL_FEED_ID);
|
||||
} else {
|
||||
return activeFolderChildren.get(groupPosition-1).get(childPosition).feedId;
|
||||
return activeFolderChildren.get(convertGroupPositionToActiveFolderIndex(groupPosition)).get(childPosition).feedId;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -251,12 +274,14 @@ public class FolderListAdapter extends BaseExpandableListAdapter {
|
|||
public String getGroupName(int groupPosition) {
|
||||
// these "names" aren't actually what is used to render the row, but are used
|
||||
// by the fragment for tracking row identity to save open/close preferences
|
||||
if (groupPosition == 0) {
|
||||
if (groupPosition == ALL_SHARED_STORIES_GROUP_POSITION) {
|
||||
return "[ALL_SHARED_STORIES]";
|
||||
} else if (isRowSavedStories(groupPosition)) {
|
||||
} else if (groupPosition == GLOBAL_SHARED_STORIES_GROUP_POSITION) {
|
||||
return "[GLOBAL_SHARED_STORIES]";
|
||||
} else if (isRowSavedStories(groupPosition)) {
|
||||
return "[SAVED_STORIES]";
|
||||
} else {
|
||||
return activeFolderNames.get(groupPosition-1);
|
||||
return activeFolderNames.get(convertGroupPositionToActiveFolderIndex(groupPosition));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -275,7 +300,7 @@ public class FolderListAdapter extends BaseExpandableListAdapter {
|
|||
* it is located at the bottom of the set rather than the top.
|
||||
*/
|
||||
public boolean isRowSavedStories(int groupPosition) {
|
||||
return ( groupPosition > activeFolderNames.size() );
|
||||
return ( groupPosition > (activeFolderNames.size() + 1) );
|
||||
}
|
||||
|
||||
public void setSocialFeedCursor(Cursor cursor) {
|
||||
|
@ -384,9 +409,11 @@ public class FolderListAdapter extends BaseExpandableListAdapter {
|
|||
|
||||
@Override
|
||||
public int getGroupType(int groupPosition) {
|
||||
if (groupPosition == 0) {
|
||||
return GroupType.ALL_SHARED_STORIES.ordinal();
|
||||
} else if (isFolderRoot(groupPosition)) {
|
||||
if (groupPosition == GLOBAL_SHARED_STORIES_GROUP_POSITION) {
|
||||
return GroupType.GLOBAL_SHARED_STORIES.ordinal();
|
||||
} else if (groupPosition == ALL_SHARED_STORIES_GROUP_POSITION) {
|
||||
return GroupType.ALL_SHARED_STORIES.ordinal();
|
||||
} else if (isFolderRoot(groupPosition)) {
|
||||
return GroupType.ALL_STORIES.ordinal();
|
||||
} else if (isRowSavedStories(groupPosition)) {
|
||||
return GroupType.SAVED_STORIES.ordinal();
|
||||
|
@ -397,7 +424,7 @@ public class FolderListAdapter extends BaseExpandableListAdapter {
|
|||
|
||||
@Override
|
||||
public int getChildType(int groupPosition, int childPosition) {
|
||||
if (groupPosition == 0) {
|
||||
if (groupPosition == ALL_SHARED_STORIES_GROUP_POSITION) {
|
||||
return ChildType.SOCIAL_FEED.ordinal();
|
||||
} else {
|
||||
return ChildType.FEED.ordinal();
|
||||
|
|
|
@ -196,7 +196,7 @@ public class FolderListFragment extends NbFragment implements OnGroupClickListen
|
|||
if (item.getItemId() == R.id.menu_delete_feed) {
|
||||
String folderName = adapter.getGroup(groupPosition);
|
||||
DialogFragment deleteFeedFragment;
|
||||
if (groupPosition == 0) {
|
||||
if (groupPosition == FolderListAdapter.ALL_SHARED_STORIES_GROUP_POSITION) {
|
||||
deleteFeedFragment = DeleteFeedFragment.newInstance(adapter.getSocialFeed(adapter.getChild(groupPosition, childPosition)), folderName);
|
||||
} else {
|
||||
deleteFeedFragment = DeleteFeedFragment.newInstance(adapter.getFeed(adapter.getChild(groupPosition, childPosition)), folderName);
|
||||
|
@ -205,7 +205,7 @@ public class FolderListFragment extends NbFragment implements OnGroupClickListen
|
|||
return true;
|
||||
} else if (item.getItemId() == R.id.menu_mark_feed_as_read) {
|
||||
String feedId = adapter.getChild(groupPosition, childPosition);
|
||||
if (groupPosition == 0) {
|
||||
if (groupPosition == FolderListAdapter.ALL_SHARED_STORIES_GROUP_POSITION) {
|
||||
SocialFeed socialFeed = adapter.getSocialFeed(feedId);
|
||||
FeedUtils.markFeedsRead(FeedSet.singleSocialFeed(socialFeed.userId, socialFeed.username), null, null, getActivity());
|
||||
} else {
|
||||
|
@ -261,7 +261,7 @@ public class FolderListFragment extends NbFragment implements OnGroupClickListen
|
|||
@Override
|
||||
public boolean onChildClick(ExpandableListView list, View childView, int groupPosition, int childPosition, long id) {
|
||||
String childName = adapter.getChild(groupPosition, childPosition);
|
||||
if (groupPosition == 0) {
|
||||
if (groupPosition == FolderListAdapter.ALL_SHARED_STORIES_GROUP_POSITION) {
|
||||
SocialFeed socialFeed = adapter.getSocialFeed(childName);
|
||||
Intent intent = new Intent(getActivity(), SocialFeedItemsList.class);
|
||||
intent.putExtra(SocialFeedItemsList.EXTRA_SOCIAL_FEED, socialFeed);
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
package com.newsblur.fragment;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.Loader;
|
||||
import android.database.Cursor;
|
||||
import android.os.Bundle;
|
||||
import android.view.ContextMenu;
|
||||
import android.view.ContextMenu.ContextMenuInfo;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
|
||||
import com.newsblur.R;
|
||||
import com.newsblur.activity.FeedReading;
|
||||
import com.newsblur.activity.GlobalSharedStoriesReading;
|
||||
import com.newsblur.activity.ItemsList;
|
||||
import com.newsblur.activity.Reading;
|
||||
import com.newsblur.database.DatabaseConstants;
|
||||
import com.newsblur.database.MultipleFeedItemsAdapter;
|
||||
import com.newsblur.util.DefaultFeedView;
|
||||
import com.newsblur.util.StateFilter;
|
||||
import com.newsblur.view.SocialItemViewBinder;
|
||||
|
||||
public class GlobalSharedStoriesItemListFragment extends ItemListFragment {
|
||||
|
||||
public static ItemListFragment newInstance(DefaultFeedView defaultFeedView, StateFilter currentState) {
|
||||
ItemListFragment fragment = new GlobalSharedStoriesItemListFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putSerializable("defaultFeedView", defaultFeedView);
|
||||
args.putSerializable("currentState", currentState);
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
|
||||
if ((adapter == null) && (cursor != null)) {
|
||||
String[] groupFrom = new String[] { DatabaseConstants.STORY_TITLE, DatabaseConstants.STORY_SHORT_CONTENT, DatabaseConstants.STORY_AUTHORS, DatabaseConstants.STORY_TIMESTAMP, DatabaseConstants.SUM_STORY_TOTAL, DatabaseConstants.FEED_TITLE };
|
||||
int[] groupTo = new int[] { R.id.row_item_title, R.id.row_item_content, R.id.row_item_author, R.id.row_item_date, R.id.row_item_sidebar, R.id.row_item_feedtitle };
|
||||
adapter = new MultipleFeedItemsAdapter(getActivity(), R.layout.row_socialitem, cursor, groupFrom, groupTo, true);
|
||||
adapter.setViewBinder(new SocialItemViewBinder(getActivity(), true));
|
||||
itemList.setAdapter(adapter);
|
||||
}
|
||||
super.onLoadFinished(loader, cursor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
if (getActivity().isFinishing()) return;
|
||||
Intent i = new Intent(getActivity(), GlobalSharedStoriesReading.class);
|
||||
i.putExtra(Reading.EXTRA_FEEDSET, getFeedSet());
|
||||
i.putExtra(FeedReading.EXTRA_POSITION, position);
|
||||
i.putExtra(Reading.EXTRA_DEFAULT_FEED_VIEW, defaultFeedView);
|
||||
i.putExtra(ItemsList.EXTRA_STATE, currentState);
|
||||
startActivity(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
|
||||
super.onCreateContextMenu(menu, v, menuInfo);
|
||||
menu.removeItem(R.id.menu_mark_story_as_read);
|
||||
menu.removeItem(R.id.menu_mark_story_as_unread);
|
||||
menu.removeItem(R.id.menu_mark_newer_stories_as_read);
|
||||
menu.removeItem(R.id.menu_mark_older_stories_as_read);
|
||||
}
|
||||
|
||||
}
|
|
@ -76,6 +76,7 @@ public class APIConstants {
|
|||
public static final String PARAMETER_ORDER = "order";
|
||||
public static final String PARAMETER_READ_FILTER = "read_filter";
|
||||
public static final String PARAMETER_INCLUDE_TIMESTAMPS = "include_timestamps";
|
||||
public static final String PARAMETER_GLOBAL_FEED = "global_feed";
|
||||
|
||||
public static final String VALUE_PREFIX_SOCIAL = "social:";
|
||||
public static final String VALUE_ALLSOCIAL = "river:blurblogs"; // the magic value passed to the mark-read API for all social feeds
|
||||
|
|
|
@ -294,6 +294,9 @@ public class APIManager {
|
|||
uri = Uri.parse(APIConstants.URL_SHARED_RIVER_STORIES);
|
||||
} else if (fs.isAllSaved()) {
|
||||
uri = Uri.parse(APIConstants.URL_STARRED_STORIES);
|
||||
} else if (fs.isGlobalShared()) {
|
||||
uri = Uri.parse(APIConstants.URL_SHARED_RIVER_STORIES);
|
||||
values.put(APIConstants.PARAMETER_GLOBAL_FEED, Boolean.TRUE.toString());
|
||||
} else {
|
||||
throw new IllegalStateException("Asked to get stories for FeedSet of unknown type.");
|
||||
}
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
package com.newsblur.util;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.util.Pair;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collections;
|
||||
|
@ -10,11 +8,8 @@ import java.util.HashMap;
|
|||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import com.newsblur.network.APIConstants;
|
||||
|
||||
/**
|
||||
* A subset of one, several, or all NewsBlur feeds or social feeds. Used to encapsulate the
|
||||
* complexity of the fact that social feeds are special and requesting a river of feeds is not
|
||||
|
@ -31,6 +26,7 @@ public class FeedSet implements Serializable {
|
|||
private boolean isAllNormal;
|
||||
private boolean isAllSocial;
|
||||
private boolean isAllSaved;
|
||||
private boolean isGlobalShared;
|
||||
|
||||
private String folderName;
|
||||
|
||||
|
@ -38,9 +34,9 @@ public class FeedSet implements Serializable {
|
|||
* Construct a new set of feeds. Only one of the arguments may be non-null or true. Specify an empty
|
||||
* set to request all of a given type.
|
||||
*/
|
||||
private FeedSet(Set<String> feeds, Map<String,String> socialFeeds, boolean allSaved) {
|
||||
private FeedSet(Set<String> feeds, Map<String,String> socialFeeds, boolean allSaved, boolean globalShared) {
|
||||
|
||||
if ( booleanCardinality( (feeds != null), (socialFeeds != null), allSaved ) > 1 ) {
|
||||
if ( booleanCardinality( (feeds != null), (socialFeeds != null), allSaved, globalShared ) > 1 ) {
|
||||
throw new IllegalArgumentException("at most one type of feed may be specified");
|
||||
}
|
||||
|
||||
|
@ -71,6 +67,11 @@ public class FeedSet implements Serializable {
|
|||
return;
|
||||
}
|
||||
|
||||
if (globalShared) {
|
||||
isGlobalShared = true;
|
||||
return;
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException("no type of feed specified");
|
||||
}
|
||||
|
||||
|
@ -80,7 +81,7 @@ public class FeedSet implements Serializable {
|
|||
public static FeedSet singleFeed(String feedId) {
|
||||
Set<String> feedIds = new HashSet<String>(1);
|
||||
feedIds.add(feedId);
|
||||
return new FeedSet(feedIds, null, false);
|
||||
return new FeedSet(feedIds, null, false, false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -89,7 +90,7 @@ public class FeedSet implements Serializable {
|
|||
public static FeedSet singleSocialFeed(String userId, String username) {
|
||||
Map<String,String> socialFeedIds = new HashMap<String,String>(1);
|
||||
socialFeedIds.put(userId, username);
|
||||
return new FeedSet(null, socialFeedIds, false);
|
||||
return new FeedSet(null, socialFeedIds, false, false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -101,35 +102,42 @@ public class FeedSet implements Serializable {
|
|||
for (String id : userIds) {
|
||||
socialFeedIds.put(id, "");
|
||||
}
|
||||
return new FeedSet(null, socialFeedIds, false);
|
||||
return new FeedSet(null, socialFeedIds, false, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience constructor for all (non-social) feeds.
|
||||
*/
|
||||
public static FeedSet allFeeds() {
|
||||
return new FeedSet(Collections.EMPTY_SET, null, false);
|
||||
return new FeedSet(Collections.EMPTY_SET, null, false, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience constructor for saved stories feed.
|
||||
*/
|
||||
public static FeedSet allSaved() {
|
||||
return new FeedSet(null, null, true);
|
||||
return new FeedSet(null, null, true, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience constructor for global shared stories feed.
|
||||
*/
|
||||
public static FeedSet globalShared() {
|
||||
return new FeedSet(null, null, false, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience constructor for all shared/social feeds.
|
||||
*/
|
||||
public static FeedSet allSocialFeeds() {
|
||||
return new FeedSet(null, Collections.EMPTY_MAP, false);
|
||||
return new FeedSet(null, Collections.EMPTY_MAP, false, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience constructor for a folder.
|
||||
*/
|
||||
public static FeedSet folder(String folderName, Set<String> feedIds) {
|
||||
FeedSet fs = new FeedSet(feedIds, null, false);
|
||||
FeedSet fs = new FeedSet(feedIds, null, false, false);
|
||||
fs.setFolderName(folderName);
|
||||
return fs;
|
||||
}
|
||||
|
@ -175,6 +183,10 @@ public class FeedSet implements Serializable {
|
|||
return this.isAllSaved;
|
||||
}
|
||||
|
||||
public boolean isGlobalShared() {
|
||||
return this.isGlobalShared;
|
||||
}
|
||||
|
||||
public void setFolderName(String folderName) {
|
||||
this.folderName = folderName;
|
||||
}
|
||||
|
@ -204,16 +216,18 @@ public class FeedSet implements Serializable {
|
|||
s.append("|");
|
||||
}
|
||||
s.append(isAllSaved);
|
||||
s.append("|");
|
||||
s.append(isGlobalShared);
|
||||
return s.toString();
|
||||
}
|
||||
|
||||
public static FeedSet fromCompactSerial(String s) {
|
||||
String[] fields = TextUtils.split(s, "\\|");
|
||||
if ((fields.length != 4) || (!fields[0].equals("FS"))) throw new IllegalArgumentException("invalid compact form");
|
||||
if ((fields.length != 5) || (!fields[0].equals("FS"))) throw new IllegalArgumentException("invalid compact form");
|
||||
if (! fields[1].equals(COM_SER_NUL)) {
|
||||
HashSet<String> feeds = new HashSet<String>();
|
||||
for (String id : TextUtils.split(fields[1], ",")) feeds.add(id);
|
||||
return new FeedSet(feeds, null, false);
|
||||
return new FeedSet(feeds, null, false, false);
|
||||
}
|
||||
if (! fields[2].equals(COM_SER_NUL)) {
|
||||
HashMap<String,String> socialFeeds = new HashMap<String,String>();
|
||||
|
@ -222,10 +236,13 @@ public class FeedSet implements Serializable {
|
|||
if (kv.length != 2) throw new IllegalArgumentException("invalid compact form");
|
||||
socialFeeds.put(kv[0], kv[1]);
|
||||
}
|
||||
return new FeedSet(null, socialFeeds, false);
|
||||
return new FeedSet(null, socialFeeds, false, false);
|
||||
}
|
||||
if (fields[3].equals(Boolean.TRUE.toString())) {
|
||||
return new FeedSet(null, null, true);
|
||||
return new FeedSet(null, null, true, false);
|
||||
}
|
||||
if (fields[4].equals(Boolean.TRUE.toString())) {
|
||||
return new FeedSet(null, null, false, true);
|
||||
}
|
||||
throw new IllegalArgumentException("invalid compact form");
|
||||
}
|
||||
|
@ -247,6 +264,7 @@ public class FeedSet implements Serializable {
|
|||
if ( isAllNormal && s.isAllNormal ) return true;
|
||||
if ( isAllSocial && s.isAllSocial ) return true;
|
||||
if ( isAllSaved && s.isAllSaved ) return true;
|
||||
if ( isGlobalShared && s.isGlobalShared ) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -256,6 +274,7 @@ public class FeedSet implements Serializable {
|
|||
if (isAllNormal) return 11;
|
||||
if (isAllSocial) return 12;
|
||||
if (isAllSaved) return 13;
|
||||
if (isGlobalShared) return 14;
|
||||
|
||||
int result = 17;
|
||||
if (feeds != null) result = 31 * result + feeds.hashCode();
|
||||
|
|
|
@ -33,7 +33,8 @@ public class PrefConstants {
|
|||
public static final String FOLDER_READ_FILTER_PREFIX = "folder_read_filter_";
|
||||
public static final String ALL_STORIES_FOLDER_NAME = "all_stories";
|
||||
public static final String ALL_SHARED_STORIES_FOLDER_NAME = "all_shared_stories";
|
||||
|
||||
public static final String GLOBAL_SHARED_STORIES_FOLDER_NAME = "global_shared_stories";
|
||||
|
||||
public static final String DEFAULT_STORY_ORDER = "default_story_order";
|
||||
public static final String DEFAULT_READ_FILTER = "default_read_filter";
|
||||
|
||||
|
|
|
@ -373,6 +373,10 @@ public class PrefsUtils {
|
|||
return getStoryOrderForFolder(context, PrefConstants.SAVED_STORIES_FOLDER_NAME);
|
||||
}
|
||||
|
||||
if (fs.isGlobalShared()) {
|
||||
return StoryOrder.NEWEST;
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException( "unknown type of feed set" );
|
||||
}
|
||||
|
||||
|
@ -401,6 +405,10 @@ public class PrefsUtils {
|
|||
return getReadFilterForFolder(context, PrefConstants.SAVED_STORIES_FOLDER_NAME);
|
||||
}
|
||||
|
||||
if (fs.isGlobalShared()) {
|
||||
return ReadFilter.UNREAD;
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException( "unknown type of feed set" );
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue