Skip to content

Commit

Permalink
Limit the amount of group data we load to MAX_ITEMS so that we don’t …
Browse files Browse the repository at this point in the history
…spawn too many async tasks. Fixes #411.
  • Loading branch information
roundhill committed Dec 9, 2013
1 parent 32f3d3c commit 878f721
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/org/wordpress/android/ui/stats/StatsCursorTreeFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.CursorTreeAdapter;
import android.widget.ExpandableListView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.actionbarsherlock.app.SherlockFragment;

import org.wordpress.android.R;
import org.wordpress.android.WordPress;
import org.wordpress.android.util.Utils;

/**
* A fragment that appears as a 'page' in the {@link StatsAbsPagedViewFragment}. Similar to {@link StatsCursorFragment},
Expand All @@ -48,7 +46,7 @@
*/
public class StatsCursorTreeFragment extends SherlockFragment implements LoaderManager.LoaderCallbacks<Cursor>, StatsCursorLoaderCallback {

private static final int MAX_ITEMS_ON_TABLET = 10;
private static final int MAX_ITEMS = 10;
private static final int LOADER_URI_GROUP_INDEX = -1;

private static final String ARGS_GROUP_URI = "ARGS_GROUP_URI";
Expand Down Expand Up @@ -175,19 +173,20 @@ public void onLoadFinished(Loader<Cursor> loader, Cursor data) {

// cursor is for groups
if (loader.getId() == LOADER_URI_GROUP_INDEX) {

// start loaders on children
while (data.moveToNext()) {
for (int i = 0; i < Math.min(data.getCount(), MAX_ITEMS); i++) {
data.moveToPosition(i);
String groupId = data.getString(data.getColumnIndex("groupId"));
long date = data.getLong(data.getColumnIndex("date"));

Bundle bundle = new Bundle();
bundle.putString(StatsCursorLoaderCallback.BUNDLE_GROUP_ID, groupId);
bundle.putLong(StatsCursorLoaderCallback.BUNDLE_DATE, date);

getLoaderManager().restartLoader(data.getPosition(), bundle, StatsCursorTreeFragment.this);
}


mCallback.onCursorLoaded(getGroupUri(), data);

Expand Down Expand Up @@ -235,7 +234,7 @@ private void reloadLinearLayout() {
mLinearLayout.removeAllViews();

// limit number of items to show otherwise it would cause performance issues on the linearlayout
int groupCount = Math.min(mAdapter.getGroupCount(), MAX_ITEMS_ON_TABLET);
int groupCount = Math.min(mAdapter.getGroupCount(), MAX_ITEMS);
for (int i = 0; i < groupCount; i++) {

boolean isExpanded = mGroupIdToExpandedMap.get(i);
Expand Down

0 comments on commit 878f721

Please sign in to comment.