Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit the amount of group data we load to MAX_ITEMS so that we don’t sp... #419

Merged
merged 3 commits into from
Dec 10, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/org/wordpress/android/datasets/StatsClickGroupsTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.net.Uri;

import org.wordpress.android.models.StatsClickGroup;
import org.wordpress.android.ui.stats.StatsActivity;
import org.wordpress.android.ui.stats.StatsTimeframe;

/**
Expand Down Expand Up @@ -87,12 +88,12 @@ public static ContentValues getContentValues(StatsClickGroup item) {
@Override
public Cursor query(SQLiteDatabase database, Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {

String sort = NAME + "." + Columns.TOTAL + " DESC, " + NAME + "." + Columns.NAME + " ASC";
String sort = NAME + "." + Columns.TOTAL + " DESC, " + NAME + "." + Columns.NAME + " ASC LIMIT " + StatsActivity.STATS_GROUP_MAX_ITEMS;

String timeframe = uri.getQueryParameter("timeframe");
if (timeframe == null)
return super.query(database, uri, projection, selection, selectionArgs, sort);

// get the latest for "Today", and the next latest for "Yesterday"
if (timeframe.equals(StatsTimeframe.TODAY.name())) {
return database.rawQuery("SELECT * FROM " + NAME +", " +
Expand Down
3 changes: 2 additions & 1 deletion src/org/wordpress/android/datasets/StatsGeoviewsTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.net.Uri;

import org.wordpress.android.models.StatsGeoview;
import org.wordpress.android.ui.stats.StatsActivity;
import org.wordpress.android.ui.stats.StatsTimeframe;

/**
Expand Down Expand Up @@ -77,7 +78,7 @@ public static ContentValues getContentValues(StatsGeoview item) {
@Override
public Cursor query(SQLiteDatabase database, Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {

String sort = NAME + "." + Columns.VIEWS + " DESC, " + NAME + "." + Columns.COUNTRY + " ASC";
String sort = NAME + "." + Columns.VIEWS + " DESC, " + NAME + "." + Columns.COUNTRY + " ASC LIMIT " + StatsActivity.STATS_GROUP_MAX_ITEMS;

String timeframe = uri.getQueryParameter("timeframe");
if (timeframe == null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package org.wordpress.android.datasets;

import java.util.LinkedHashMap;
import java.util.Map;

import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;

import org.wordpress.android.models.StatsReferrerGroup;
import org.wordpress.android.ui.stats.StatsActivity;
import org.wordpress.android.ui.stats.StatsTimeframe;

import java.util.LinkedHashMap;
import java.util.Map;

/**
* A database table to represent groups in the stats for referrers.
* A group may or may not have children.
Expand Down Expand Up @@ -88,7 +89,7 @@ public static ContentValues getContentValues(StatsReferrerGroup item) {
@Override
public Cursor query(SQLiteDatabase database, Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {

String sort = NAME + "." + Columns.TOTAL + " DESC, " + NAME + "." + Columns.NAME + " ASC";
String sort = NAME + "." + Columns.TOTAL + " DESC, " + NAME + "." + Columns.NAME + " ASC LIMIT " + StatsActivity.STATS_GROUP_MAX_ITEMS;

String timeframe = uri.getQueryParameter("timeframe");
if (timeframe == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.net.Uri;

import org.wordpress.android.models.StatsSearchEngineTerm;
import org.wordpress.android.ui.stats.StatsActivity;
import org.wordpress.android.ui.stats.StatsTimeframe;

/**
Expand Down Expand Up @@ -73,7 +74,7 @@ public static ContentValues getContentValues(StatsSearchEngineTerm item) {

@Override
public Cursor query(SQLiteDatabase database, Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
String sort = NAME + "." + Columns.VIEWS + " DESC, " + NAME + "." + Columns.SEARCH + " ASC";
String sort = NAME + "." + Columns.VIEWS + " DESC, " + NAME + "." + Columns.SEARCH + " ASC LIMIT " + StatsActivity.STATS_GROUP_MAX_ITEMS;

String timeframe = uri.getQueryParameter("timeframe");
if (timeframe == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.net.Uri;

import org.wordpress.android.models.StatsTopPostsAndPages;
import org.wordpress.android.ui.stats.StatsActivity;
import org.wordpress.android.ui.stats.StatsTimeframe;

/**
Expand Down Expand Up @@ -79,7 +80,7 @@ public static ContentValues getContentValues(StatsTopPostsAndPages item) {

@Override
public Cursor query(SQLiteDatabase database, Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
String sort = NAME + "." + Columns.VIEWS + " DESC, " + NAME + "." + Columns.TITLE + " ASC";
String sort = NAME + "." + Columns.VIEWS + " DESC, " + NAME + "." + Columns.TITLE + " ASC LIMIT " + StatsActivity.STATS_GROUP_MAX_ITEMS;

String timeframe = uri.getQueryParameter("timeframe");
if (timeframe == null)
Expand Down
3 changes: 3 additions & 0 deletions src/org/wordpress/android/ui/stats/StatsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@
*/
public class StatsActivity extends WPActionBarActivity {

// Max number of rows to show in a stats fragment
public static final int STATS_GROUP_MAX_ITEMS = 10;

private static final String SAVED_NAV_POSITION = "SAVED_NAV_POSITION";
private static final String SAVED_WP_LOGIN_STATE = "SAVED_WP_LOGIN_STATE";
private static final int REQUEST_JETPACK = 7000;
Expand Down
5 changes: 1 addition & 4 deletions src/org/wordpress/android/ui/stats/StatsCursorFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.ListView;
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}.
Expand All @@ -41,7 +39,6 @@
*/
public class StatsCursorFragment extends SherlockFragment implements LoaderManager.LoaderCallbacks<Cursor> {

private static final int MAX_ITEMS_ON_TABLET = 10;
private static final String ARGS_URI = "ARGS_URI";
private static final String ARGS_ENTRY_LABEL = "ARGS_ENTRY_LABEL";
private static final String ARGS_TOTALS_LABEL = "ARGS_TOTALS_LABEL";
Expand Down Expand Up @@ -164,7 +161,7 @@ private void reloadLinearLayout() {
mLinearLayout.removeAllViews();

// limit number of items to show otherwise it would cause performance issues on the linearlayout
int count = Math.min(mAdapter.getCount(), MAX_ITEMS_ON_TABLET);
int count = Math.min(mAdapter.getCount(), StatsActivity.STATS_GROUP_MAX_ITEMS);
for (int i = 0; i < count; i++) {
View view = mAdapter.getView(i, null, mLinearLayout);
if (i % 2 == 1)
Expand Down
14 changes: 5 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,9 +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 LOADER_URI_GROUP_INDEX = -1;

private static final String ARGS_GROUP_URI = "ARGS_GROUP_URI";
private static final String ARGS_CHILDREN_URI = "ARGS_CHILDREN_URI";
private static final String ARGS_ENTRY_LABEL = "ARGS_ENTRY_LABEL";
Expand Down Expand Up @@ -175,19 +171,19 @@ 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()) {
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 +231,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(), StatsActivity.STATS_GROUP_MAX_ITEMS);
for (int i = 0; i < groupCount; i++) {

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