mirror of
https://github.com/viq/NewsBlur.git
synced 2025-09-18 21:43:31 +00:00
Added passing of intelligence level between main view and feed item list.
This commit is contained in:
parent
f925f1c054
commit
039978c71c
6 changed files with 53 additions and 27 deletions
|
@ -13,6 +13,7 @@ import com.actionbarsherlock.view.Window;
|
|||
import com.newsblur.R;
|
||||
import com.newsblur.database.FeedProvider;
|
||||
import com.newsblur.domain.Feed;
|
||||
import com.newsblur.fragment.FeedIntelligenceSelectorFragment;
|
||||
import com.newsblur.fragment.ItemListFragment;
|
||||
import com.newsblur.fragment.SyncUpdateFragment;
|
||||
import com.newsblur.service.SyncService;
|
||||
|
@ -21,12 +22,14 @@ import com.newsblur.view.StateToggleButton.StateChangedListener;
|
|||
public class ItemsList extends SherlockFragmentActivity implements SyncUpdateFragment.SyncUpdateFragmentInterface, StateChangedListener {
|
||||
|
||||
public static final String EXTRA_FEED = "feedId";
|
||||
public static final String EXTRA_STATE = "currentIntelligenceState";
|
||||
private ItemListFragment itemListFragment;
|
||||
private FragmentManager fragmentManager;
|
||||
private final String FRAGMENT_TAG = "itemListFragment";
|
||||
private SyncUpdateFragment syncFragment;
|
||||
private FeedIntelligenceSelectorFragment intelligenceSelectorFragment;
|
||||
private String feedId;
|
||||
private String TAG = "ItemsList";
|
||||
private int currentState;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle bundle) {
|
||||
|
@ -36,20 +39,23 @@ public class ItemsList extends SherlockFragmentActivity implements SyncUpdateFra
|
|||
setContentView(R.layout.activity_itemslist);
|
||||
fragmentManager = getSupportFragmentManager();
|
||||
feedId = getIntent().getStringExtra(EXTRA_FEED);
|
||||
|
||||
currentState = getIntent().getIntExtra(EXTRA_STATE, 0);
|
||||
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
final Uri feedUri = FeedProvider.FEEDS_URI.buildUpon().appendPath(feedId).build();
|
||||
Feed feed = Feed.fromCursor(getContentResolver().query(feedUri, null, null, null, null));
|
||||
setTitle(feed.title);
|
||||
|
||||
itemListFragment = (ItemListFragment) fragmentManager.findFragmentByTag(FRAGMENT_TAG);
|
||||
|
||||
itemListFragment = (ItemListFragment) fragmentManager.findFragmentByTag(ItemListFragment.FRAGMENT_TAG);
|
||||
intelligenceSelectorFragment = (FeedIntelligenceSelectorFragment) fragmentManager.findFragmentByTag(FeedIntelligenceSelectorFragment.FRAGMENT_TAG);
|
||||
intelligenceSelectorFragment.setState(currentState);
|
||||
|
||||
if (itemListFragment == null && feedId != null) {
|
||||
itemListFragment = ItemListFragment.newInstance(feedId);
|
||||
itemListFragment = ItemListFragment.newInstance(feedId, currentState);
|
||||
itemListFragment.setRetainInstance(true);
|
||||
FragmentTransaction listTransaction = fragmentManager.beginTransaction();
|
||||
listTransaction.add(R.id.activity_itemlist_container, itemListFragment, FRAGMENT_TAG);
|
||||
listTransaction.add(R.id.activity_itemlist_container, itemListFragment, ItemListFragment.FRAGMENT_TAG);
|
||||
listTransaction.commit();
|
||||
}
|
||||
|
||||
|
|
|
@ -12,10 +12,13 @@ import com.newsblur.view.StateToggleButton.StateChangedListener;
|
|||
|
||||
public class FeedIntelligenceSelectorFragment extends Fragment implements StateChangedListener {
|
||||
|
||||
public static final String FRAGMENT_TAG = "feedIntelligenceSelector";
|
||||
private StateToggleButton button;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
View v = inflater.inflate(R.layout.fragment_intelligenceselector, null);
|
||||
StateToggleButton button = (StateToggleButton) v.findViewById(R.id.fragment_intelligence_statebutton);
|
||||
button = (StateToggleButton) v.findViewById(R.id.fragment_intelligence_statebutton);
|
||||
button.setStateListener(this);
|
||||
return v;
|
||||
}
|
||||
|
@ -24,5 +27,9 @@ public class FeedIntelligenceSelectorFragment extends Fragment implements StateC
|
|||
public void changedState(int state) {
|
||||
((StateChangedListener) getActivity()).changedState(state);
|
||||
}
|
||||
|
||||
public void setState(int state) {
|
||||
button.setState(state);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -39,14 +39,16 @@ public class FolderFeedListFragment extends Fragment implements OnGroupClickList
|
|||
private FolderTreeViewBinder viewBinder;
|
||||
private int leftBound, rightBound;
|
||||
private APIManager apiManager;
|
||||
|
||||
private int currentState = AppConstants.STATE_SOME;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
resolver = getActivity().getContentResolver();
|
||||
apiManager = new APIManager(getActivity());
|
||||
|
||||
Cursor cursor = resolver.query(FeedProvider.FOLDERS_URI, null, null, new String[] { FeedProvider.FOLDER_INTELLIGENCE_ALL }, null);
|
||||
|
||||
Cursor cursor = resolver.query(FeedProvider.FOLDERS_URI, null, null, new String[] { FeedProvider.FOLDER_INTELLIGENCE_SOME }, null);
|
||||
viewBinder = new FolderTreeViewBinder();
|
||||
|
||||
leftBound = UIUtils.convertDPsToPixels(getActivity(), 20);
|
||||
|
@ -126,7 +128,8 @@ public class FolderFeedListFragment extends Fragment implements OnGroupClickList
|
|||
public void changeState(int state) {
|
||||
String selection = null;
|
||||
viewBinder.setState(state);
|
||||
|
||||
currentState = state;
|
||||
|
||||
switch (state) {
|
||||
case (AppConstants.STATE_ALL):
|
||||
selection = FeedProvider.FOLDER_INTELLIGENCE_ALL;
|
||||
|
@ -138,7 +141,7 @@ public class FolderFeedListFragment extends Fragment implements OnGroupClickList
|
|||
selection = FeedProvider.FOLDER_INTELLIGENCE_BEST;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
folderAdapter.currentState = selection;
|
||||
Cursor cursor = resolver.query(FeedProvider.FOLDERS_URI, null, null, new String[] { selection }, null);
|
||||
folderAdapter.setGroupCursor(cursor);
|
||||
|
@ -161,6 +164,7 @@ public class FolderFeedListFragment extends Fragment implements OnGroupClickList
|
|||
Cursor childCursor = folderAdapter.getChild(groupPosition, childPosition);
|
||||
String feedId = childCursor.getString(childCursor.getColumnIndex(DatabaseConstants.FEED_ID));
|
||||
intent.putExtra(ItemsList.EXTRA_FEED, feedId);
|
||||
intent.putExtra(ItemsList.EXTRA_STATE, currentState);
|
||||
getActivity().startActivity(intent);
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -29,14 +29,17 @@ import com.newsblur.view.ItemViewBinder;
|
|||
public class ItemListFragment extends Fragment implements LoaderManager.LoaderCallbacks<Cursor>, OnItemClickListener {
|
||||
|
||||
private static final String TAG = "itemListFragment";
|
||||
public static final String FRAGMENT_TAG = "itemListFragment";
|
||||
private ContentResolver contentResolver;
|
||||
private String feedId;
|
||||
public static int ITEMLIST_LOADER = 0x01;
|
||||
private SimpleCursorAdapter adapter;
|
||||
private Uri storiesUri;
|
||||
private int currentState;
|
||||
|
||||
public ItemListFragment(final String feedId) {
|
||||
public ItemListFragment(final String feedId, final int currentState) {
|
||||
this.feedId = feedId;
|
||||
this.currentState = currentState;
|
||||
}
|
||||
|
||||
public ItemListFragment() {
|
||||
|
@ -48,8 +51,8 @@ public class ItemListFragment extends Fragment implements LoaderManager.LoaderCa
|
|||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
public static ItemListFragment newInstance(final String feedId) {
|
||||
return new ItemListFragment(feedId);
|
||||
public static ItemListFragment newInstance(final String feedId, int currentState) {
|
||||
return new ItemListFragment(feedId, currentState);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -59,7 +62,7 @@ public class ItemListFragment extends Fragment implements LoaderManager.LoaderCa
|
|||
|
||||
contentResolver = getActivity().getContentResolver();
|
||||
storiesUri = FeedProvider.STORIES_URI.buildUpon().appendPath(feedId).build();
|
||||
Cursor cursor = contentResolver.query(storiesUri, null, null, null, null);
|
||||
Cursor cursor = contentResolver.query(storiesUri, null, getSelectionFromState(currentState), null, null);
|
||||
|
||||
String[] groupFrom = new String[] { DatabaseConstants.STORY_TITLE, DatabaseConstants.STORY_AUTHORS, DatabaseConstants.STORY_READ, DatabaseConstants.STORY_SHORTDATE, DatabaseConstants.STORY_INTELLIGENCE_AUTHORS };
|
||||
int[] groupTo = new int[] { R.id.row_item_title, R.id.row_item_author, R.id.row_item_title, R.id.row_item_date, R.id.row_item_sidebar };
|
||||
|
@ -78,7 +81,7 @@ public class ItemListFragment extends Fragment implements LoaderManager.LoaderCa
|
|||
@Override
|
||||
public Loader<Cursor> onCreateLoader(int loaderId, Bundle bundle) {
|
||||
Uri uri = FeedProvider.STORIES_URI.buildUpon().appendPath(feedId).build();
|
||||
CursorLoader cursorLoader = new CursorLoader(getActivity(), uri, null, null, null, null);
|
||||
CursorLoader cursorLoader = new CursorLoader(getActivity(), uri, null, getSelectionFromState(currentState), null, null);
|
||||
return cursorLoader;
|
||||
}
|
||||
|
||||
|
@ -108,8 +111,13 @@ public class ItemListFragment extends Fragment implements LoaderManager.LoaderCa
|
|||
}
|
||||
|
||||
public void changeState(int state) {
|
||||
final String selection = getSelectionFromState(state);
|
||||
Cursor cursor = contentResolver.query(storiesUri, null, selection, null, null);
|
||||
adapter.swapCursor(cursor);
|
||||
}
|
||||
|
||||
private String getSelectionFromState(int state) {
|
||||
String selection = null;
|
||||
|
||||
switch (state) {
|
||||
case (AppConstants.STATE_ALL):
|
||||
selection = "";
|
||||
|
@ -121,9 +129,7 @@ public class ItemListFragment extends Fragment implements LoaderManager.LoaderCa
|
|||
selection = FeedProvider.STORY_INTELLIGENCE_BEST;
|
||||
break;
|
||||
}
|
||||
|
||||
Cursor cursor = contentResolver.query(storiesUri, null, selection, null, null);
|
||||
adapter.swapCursor(cursor);
|
||||
return selection;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ import com.newsblur.util.AppConstants;
|
|||
|
||||
public class FolderTreeViewBinder implements ViewBinder {
|
||||
|
||||
private int currentState = AppConstants.STATE_ALL;
|
||||
private int currentState = AppConstants.STATE_SOME;
|
||||
|
||||
@Override
|
||||
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
|
||||
|
|
|
@ -13,7 +13,7 @@ import com.newsblur.util.UIUtils;
|
|||
|
||||
public class StateToggleButton extends LinearLayout implements OnClickListener {
|
||||
|
||||
private int CURRENT_STATE = AppConstants.STATE_ALL;
|
||||
private int CURRENT_STATE = AppConstants.STATE_SOME;
|
||||
|
||||
private Context context;
|
||||
private StateChangedListener stateChangedListener;
|
||||
|
@ -61,7 +61,7 @@ public class StateToggleButton extends LinearLayout implements OnClickListener {
|
|||
this.addView(imageStateTwo);
|
||||
this.addView(imageStateThree);
|
||||
|
||||
changeState(CURRENT_STATE);
|
||||
setState(CURRENT_STATE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -70,6 +70,13 @@ public class StateToggleButton extends LinearLayout implements OnClickListener {
|
|||
}
|
||||
|
||||
public void changeState(final int state) {
|
||||
setState(state);
|
||||
if (stateChangedListener != null) {
|
||||
stateChangedListener.changedState(CURRENT_STATE);
|
||||
}
|
||||
}
|
||||
|
||||
public void setState(final int state) {
|
||||
switch (state) {
|
||||
case AppConstants.STATE_ALL:
|
||||
imageStateOne.setAlpha(255);
|
||||
|
@ -89,10 +96,6 @@ public class StateToggleButton extends LinearLayout implements OnClickListener {
|
|||
}
|
||||
|
||||
CURRENT_STATE = state;
|
||||
|
||||
if (stateChangedListener != null) {
|
||||
stateChangedListener.changedState(CURRENT_STATE);
|
||||
}
|
||||
}
|
||||
|
||||
public interface StateChangedListener {
|
||||
|
|
Loading…
Add table
Reference in a new issue