mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-09-18 21:50:56 +00:00
Switch social feed story list to correctly use loaders.
This commit is contained in:
parent
0e29f201ae
commit
1d441cc1e8
6 changed files with 43 additions and 63 deletions
|
@ -32,10 +32,6 @@ import com.newsblur.view.StateToggleButton.StateChangedListener;
|
|||
public abstract class ItemsList extends NbActivity implements StateChangedListener, StoryOrderChangedListener, ReadFilterChangedListener, DefaultFeedViewChangedListener {
|
||||
|
||||
public static final String EXTRA_STATE = "currentIntelligenceState";
|
||||
public static final String EXTRA_BLURBLOG_USERNAME = "blurblogName";
|
||||
public static final String EXTRA_BLURBLOG_USERID = "blurblogId";
|
||||
public static final String EXTRA_BLURBLOG_USER_ICON = "userIcon";
|
||||
public static final String EXTRA_BLURBLOG_TITLE = "blurblogTitle";
|
||||
private static final String STORY_ORDER = "storyOrder";
|
||||
private static final String READ_FILTER = "readFilter";
|
||||
private static final String DEFAULT_FEED_VIEW = "defaultFeedView";
|
||||
|
|
|
@ -9,6 +9,7 @@ import android.view.MenuInflater;
|
|||
import android.widget.Toast;
|
||||
|
||||
import com.newsblur.R;
|
||||
import com.newsblur.domain.SocialFeed;
|
||||
import com.newsblur.fragment.FeedItemListFragment;
|
||||
import com.newsblur.fragment.SocialFeedItemListFragment;
|
||||
import com.newsblur.util.DefaultFeedView;
|
||||
|
@ -21,21 +22,19 @@ import com.newsblur.util.StoryOrder;
|
|||
|
||||
public class SocialFeedItemsList extends ItemsList {
|
||||
|
||||
private String userIcon, userId, username, title;
|
||||
public static final String EXTRA_SOCIAL_FEED = "blurblogTitle";
|
||||
|
||||
private SocialFeed socialFeed;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle bundle) {
|
||||
socialFeed = (SocialFeed) getIntent().getSerializableExtra(EXTRA_SOCIAL_FEED);
|
||||
super.onCreate(bundle);
|
||||
|
||||
username = getIntent().getStringExtra(EXTRA_BLURBLOG_USERNAME);
|
||||
userIcon = getIntent().getStringExtra(EXTRA_BLURBLOG_USER_ICON );
|
||||
userId = getIntent().getStringExtra(EXTRA_BLURBLOG_USERID);
|
||||
title = getIntent().getStringExtra(EXTRA_BLURBLOG_TITLE);
|
||||
|
||||
setTitle(title);
|
||||
setTitle(socialFeed.feedTitle);
|
||||
|
||||
if (itemListFragment == null) {
|
||||
itemListFragment = SocialFeedItemListFragment.newInstance(userId, username, currentState, getDefaultFeedView());
|
||||
itemListFragment = SocialFeedItemListFragment.newInstance(socialFeed, currentState, getDefaultFeedView());
|
||||
itemListFragment.setRetainInstance(true);
|
||||
FragmentTransaction listTransaction = fragmentManager.beginTransaction();
|
||||
listTransaction.add(R.id.activity_itemlist_container, itemListFragment, SocialFeedItemListFragment.class.getName());
|
||||
|
@ -45,7 +44,7 @@ public class SocialFeedItemsList extends ItemsList {
|
|||
|
||||
@Override
|
||||
protected FeedSet createFeedSet() {
|
||||
return FeedSet.singleSocialFeed(getIntent().getStringExtra(EXTRA_BLURBLOG_USERID), getIntent().getStringExtra(EXTRA_BLURBLOG_USERNAME));
|
||||
return FeedSet.singleSocialFeed(socialFeed.userId, socialFeed.username);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -58,32 +57,32 @@ public class SocialFeedItemsList extends ItemsList {
|
|||
|
||||
@Override
|
||||
protected StoryOrder getStoryOrder() {
|
||||
return PrefsUtils.getStoryOrderForFeed(this, userId);
|
||||
return PrefsUtils.getStoryOrderForFeed(this, socialFeed.userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateStoryOrderPreference(StoryOrder newValue) {
|
||||
PrefsUtils.setStoryOrderForFeed(this, userId, newValue);
|
||||
PrefsUtils.setStoryOrderForFeed(this, socialFeed.userId, newValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateReadFilterPreference(ReadFilter newValue) {
|
||||
PrefsUtils.setReadFilterForFeed(this, userId, newValue);
|
||||
PrefsUtils.setReadFilterForFeed(this, socialFeed.userId, newValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReadFilter getReadFilter() {
|
||||
return PrefsUtils.getReadFilterForFeed(this, userId);
|
||||
return PrefsUtils.getReadFilterForFeed(this, socialFeed.userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DefaultFeedView getDefaultFeedView() {
|
||||
return PrefsUtils.getDefaultFeedViewForFeed(this, userId);
|
||||
return PrefsUtils.getDefaultFeedViewForFeed(this, socialFeed.userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void defaultFeedViewChanged(DefaultFeedView value) {
|
||||
PrefsUtils.setDefaultFeedViewForFeed(this, userId, value);
|
||||
PrefsUtils.setDefaultFeedViewForFeed(this, socialFeed.userId, value);
|
||||
if (itemListFragment != null) {
|
||||
itemListFragment.setDefaultFeedView(value);
|
||||
}
|
||||
|
|
|
@ -4,10 +4,14 @@ import android.content.ContentValues;
|
|||
import android.database.Cursor;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import com.newsblur.database.DatabaseConstants;
|
||||
|
||||
public class SocialFeed {
|
||||
public class SocialFeed implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 0L;
|
||||
|
||||
public String username;
|
||||
|
||||
|
|
|
@ -59,13 +59,13 @@ public class FeedItemListFragment extends ItemListFragment implements OnItemClic
|
|||
itemList = (ListView) v.findViewById(R.id.itemlistfragment_list);
|
||||
setupBezelSwipeDetector(itemList);
|
||||
itemList.setEmptyView(v.findViewById(R.id.empty_view));
|
||||
itemList.setOnItemClickListener(this);
|
||||
itemList.setOnCreateContextMenuListener(this);
|
||||
itemList.setOnScrollListener(this);
|
||||
if (adapter != null) {
|
||||
// normally the list gets set up when the adapter is created, but sometimes
|
||||
// onCreateView gets re-called.
|
||||
itemList.setAdapter(adapter);
|
||||
itemList.setOnItemClickListener(this);
|
||||
itemList.setOnCreateContextMenuListener(this);
|
||||
}
|
||||
|
||||
getLoaderManager().initLoader(ITEMLIST_LOADER , null, this);
|
||||
|
@ -81,8 +81,6 @@ public class FeedItemListFragment extends ItemListFragment implements OnItemClic
|
|||
adapter = new FeedItemsAdapter(getActivity(), feed, R.layout.row_item, cursor, groupFrom, groupTo, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
|
||||
adapter.setViewBinder(new FeedItemViewBinder(getActivity()));
|
||||
itemList.setAdapter(adapter);
|
||||
itemList.setOnItemClickListener(this);
|
||||
itemList.setOnCreateContextMenuListener(this);
|
||||
}
|
||||
super.onLoadFinished(loader, cursor);
|
||||
}
|
||||
|
|
|
@ -248,10 +248,7 @@ public class FolderListFragment extends NbFragment implements OnGroupClickListen
|
|||
if (groupPosition == 0) {
|
||||
SocialFeed socialFeed = adapter.getSocialFeed(childName);
|
||||
Intent intent = new Intent(getActivity(), SocialFeedItemsList.class);
|
||||
intent.putExtra(ItemsList.EXTRA_BLURBLOG_USER_ICON, socialFeed.photoUrl);
|
||||
intent.putExtra(ItemsList.EXTRA_BLURBLOG_USERNAME, socialFeed.username);
|
||||
intent.putExtra(ItemsList.EXTRA_BLURBLOG_TITLE, socialFeed.feedTitle);
|
||||
intent.putExtra(ItemsList.EXTRA_BLURBLOG_USERID, socialFeed.userId);
|
||||
intent.putExtra(SocialFeedItemsList.EXTRA_SOCIAL_FEED, socialFeed);
|
||||
intent.putExtra(ItemsList.EXTRA_STATE, currentState);
|
||||
getActivity().startActivity(intent);
|
||||
} else {
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.newsblur.fragment;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.CursorLoader;
|
||||
import android.content.Intent;
|
||||
import android.content.Loader;
|
||||
|
@ -21,7 +20,6 @@ import com.newsblur.activity.ItemsList;
|
|||
import com.newsblur.activity.Reading;
|
||||
import com.newsblur.activity.SocialFeedReading;
|
||||
import com.newsblur.database.DatabaseConstants;
|
||||
import com.newsblur.database.FeedProvider;
|
||||
import com.newsblur.database.MultipleFeedItemsAdapter;
|
||||
import com.newsblur.domain.SocialFeed;
|
||||
import com.newsblur.util.DefaultFeedView;
|
||||
|
@ -31,46 +29,21 @@ import com.newsblur.view.SocialItemViewBinder;
|
|||
|
||||
public class SocialFeedItemListFragment extends ItemListFragment implements OnItemClickListener {
|
||||
|
||||
private ContentResolver contentResolver;
|
||||
private String userId, username;
|
||||
private Uri storiesUri;
|
||||
private SocialFeed socialFeed;
|
||||
|
||||
private Uri socialFeedUri;
|
||||
private String[] groupFroms;
|
||||
private int[] groupTos;
|
||||
private ListView itemList;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
socialFeed = (SocialFeed) getArguments().getSerializable("social_feed");
|
||||
super.onCreate(savedInstanceState);
|
||||
userId = getArguments().getString("userId");
|
||||
username = getArguments().getString("username");
|
||||
contentResolver = getActivity().getContentResolver();
|
||||
storiesUri = FeedProvider.SOCIALFEED_STORIES_URI.buildUpon().appendPath(userId).build();
|
||||
|
||||
socialFeedUri = FeedProvider.SOCIAL_FEEDS_URI.buildUpon().appendPath(userId).build();
|
||||
socialFeed = SocialFeed.fromCursor(contentResolver.query(socialFeedUri, null, null, null, null));
|
||||
|
||||
Uri uri = FeedProvider.SOCIALFEED_STORIES_URI.buildUpon().appendPath(userId).build();
|
||||
Cursor cursor = dbHelper.getStoriesCursor(getFeedSet(), currentState);
|
||||
|
||||
groupFroms = new String[] { DatabaseConstants.STORY_TITLE, DatabaseConstants.FEED_FAVICON_URL, DatabaseConstants.FEED_TITLE, DatabaseConstants.STORY_SHORT_CONTENT, DatabaseConstants.STORY_TIMESTAMP, DatabaseConstants.STORY_AUTHORS, DatabaseConstants.STORY_INTELLIGENCE_AUTHORS};
|
||||
groupTos = new int[] { R.id.row_item_title, R.id.row_item_feedicon, R.id.row_item_feedtitle, R.id.row_item_content, R.id.row_item_date, R.id.row_item_author, R.id.row_item_sidebar};
|
||||
|
||||
adapter = new MultipleFeedItemsAdapter(getActivity(), R.layout.row_socialitem, cursor, groupFroms, groupTos, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
|
||||
adapter.setViewBinder(new SocialItemViewBinder(getActivity()));
|
||||
|
||||
getLoaderManager().initLoader(ITEMLIST_LOADER , null, this);
|
||||
|
||||
}
|
||||
|
||||
public static SocialFeedItemListFragment newInstance(final String userId, final String username, StateFilter currentState, final DefaultFeedView defaultFeedView) {
|
||||
public static SocialFeedItemListFragment newInstance(SocialFeed socialFeed, StateFilter currentState, DefaultFeedView defaultFeedView) {
|
||||
SocialFeedItemListFragment fragment = new SocialFeedItemListFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putSerializable("currentState", currentState);
|
||||
args.putString("userId", userId);
|
||||
args.putString("username", username);
|
||||
args.putSerializable("social_feed", socialFeed);
|
||||
args.putSerializable("defaultFeedView", defaultFeedView);
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
|
@ -82,21 +55,34 @@ public class SocialFeedItemListFragment extends ItemListFragment implements OnIt
|
|||
itemList = (ListView) v.findViewById(R.id.itemlistfragment_list);
|
||||
setupBezelSwipeDetector(itemList);
|
||||
itemList.setEmptyView(v.findViewById(R.id.empty_view));
|
||||
|
||||
itemList.setOnScrollListener(this);
|
||||
itemList.setAdapter(adapter);
|
||||
itemList.setOnScrollListener(this);
|
||||
itemList.setOnItemClickListener(this);
|
||||
if (adapter != null) {
|
||||
itemList.setAdapter(adapter);
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
|
||||
if ((adapter == null) && (cursor != null)) {
|
||||
String[] groupFroms = new String[] { DatabaseConstants.STORY_TITLE, DatabaseConstants.FEED_FAVICON_URL, DatabaseConstants.FEED_TITLE, DatabaseConstants.STORY_SHORT_CONTENT, DatabaseConstants.STORY_TIMESTAMP, DatabaseConstants.STORY_AUTHORS, DatabaseConstants.STORY_INTELLIGENCE_AUTHORS};
|
||||
int[] groupTos = new int[] { R.id.row_item_title, R.id.row_item_feedicon, R.id.row_item_feedtitle, R.id.row_item_content, R.id.row_item_date, R.id.row_item_author, R.id.row_item_sidebar};
|
||||
adapter = new MultipleFeedItemsAdapter(getActivity(), R.layout.row_socialitem, cursor, groupFroms, groupTos, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
|
||||
adapter.setViewBinder(new SocialItemViewBinder(getActivity()));
|
||||
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(), SocialFeedReading.class);
|
||||
i.putExtra(Reading.EXTRA_FEEDSET, getFeedSet());
|
||||
i.putExtra(Reading.EXTRA_USERID, userId);
|
||||
i.putExtra(Reading.EXTRA_USERNAME, username);
|
||||
i.putExtra(Reading.EXTRA_USERID, socialFeed.userId);
|
||||
i.putExtra(Reading.EXTRA_USERNAME, socialFeed.username);
|
||||
i.putExtra(Reading.EXTRA_POSITION, position);
|
||||
i.putExtra(ItemsList.EXTRA_STATE, currentState);
|
||||
i.putExtra(Reading.EXTRA_DEFAULT_FEED_VIEW, defaultFeedView);
|
||||
|
|
Loading…
Add table
Reference in a new issue