use of org.wordpress.android.ui.stats.models.PostViewsModel in project WordPress-Android by wordpress-mobile.
the class StatsSingleItemDetailsActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.stats_activity_single_post_details);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
}
// pull to refresh setup
mSwipeToRefreshHelper = new SwipeToRefreshHelper(this, (CustomSwipeRefreshLayout) findViewById(R.id.ptr_layout), new SwipeToRefreshHelper.RefreshListener() {
@Override
public void onRefreshStarted() {
if (!NetworkUtils.checkConnection(getBaseContext())) {
mSwipeToRefreshHelper.setRefreshing(false);
return;
}
refreshStats();
}
});
TextView mStatsForLabel = (TextView) findViewById(R.id.stats_summary_title);
mGraphContainer = (LinearLayout) findViewById(R.id.stats_bar_chart_fragment_container);
mStatsViewsLabel = (TextView) findViewById(R.id.stats_views_label);
mStatsViewsTotals = (TextView) findViewById(R.id.stats_views_totals);
mMonthsAndYearsModule = (LinearLayout) findViewById(R.id.stats_months_years_module);
mMonthsAndYearsHeader = (RelativeLayout) findViewById(R.id.stats_months_years_header);
mMonthsAndYearsList = (LinearLayout) findViewById(R.id.stats_months_years_list_linearlayout);
mMonthsAndYearsEmptyPlaceholder = (LinearLayout) findViewById(R.id.stats_months_years_empty_module_placeholder);
mAveragesModule = (LinearLayout) findViewById(R.id.stats_averages_module);
mAveragesHeader = (RelativeLayout) findViewById(R.id.stats_averages_list_header);
mAveragesList = (LinearLayout) findViewById(R.id.stats_averages_list_linearlayout);
mAveragesEmptyPlaceholder = (LinearLayout) findViewById(R.id.stats_averages_empty_module_placeholder);
mRecentWeeksModule = (LinearLayout) findViewById(R.id.stats_recent_weeks_module);
mRecentWeeksHeader = (RelativeLayout) findViewById(R.id.stats_recent_weeks_list_header);
mRecentWeeksList = (LinearLayout) findViewById(R.id.stats_recent_weeks_list_linearlayout);
mRecentWeeksEmptyPlaceholder = (LinearLayout) findViewById(R.id.stats_recent_weeks_empty_module_placeholder);
mYearsIdToExpandedMap = new SparseBooleanArray();
mAveragesIdToExpandedMap = new SparseBooleanArray();
mRecentWeeksIdToExpandedMap = new SparseBooleanArray();
setTitle(R.string.stats);
mOuterScrollView = (ScrollViewExt) findViewById(R.id.scroll_view_stats);
if (savedInstanceState != null) {
mRemoteItemID = savedInstanceState.getString(ARG_REMOTE_ITEM_ID);
mRemoteBlogID = savedInstanceState.getLong(ARG_REMOTE_BLOG_ID, 0);
mRemoteItemType = savedInstanceState.getString(ARG_REMOTE_ITEM_TYPE);
mItemTitle = savedInstanceState.getString(ARG_ITEM_TITLE);
mItemURL = savedInstanceState.getString(ARG_ITEM_URL);
mRestResponseParsed = (PostViewsModel) savedInstanceState.getSerializable(ARG_REST_RESPONSE);
mSelectedBarGraphIndex = savedInstanceState.getInt(ARG_SELECTED_GRAPH_BAR, -1);
mPrevNumberOfBarsGraph = savedInstanceState.getInt(ARG_PREV_NUMBER_OF_BARS, -1);
final int yScrollPosition = savedInstanceState.getInt(SAVED_STATS_SCROLL_POSITION);
if (yScrollPosition != 0) {
mOuterScrollView.postDelayed(new Runnable() {
public void run() {
if (!isFinishing()) {
mOuterScrollView.scrollTo(0, yScrollPosition);
}
}
}, StatsConstants.STATS_SCROLL_TO_DELAY);
}
if (savedInstanceState.containsKey(ARG_AVERAGES_EXPANDED_ROWS)) {
mAveragesIdToExpandedMap = savedInstanceState.getParcelable(ARG_AVERAGES_EXPANDED_ROWS);
}
if (savedInstanceState.containsKey(ARG_RECENT_EXPANDED_ROWS)) {
mRecentWeeksIdToExpandedMap = savedInstanceState.getParcelable(ARG_RECENT_EXPANDED_ROWS);
}
if (savedInstanceState.containsKey(ARG_YEARS_EXPANDED_ROWS)) {
mYearsIdToExpandedMap = savedInstanceState.getParcelable(ARG_YEARS_EXPANDED_ROWS);
}
} else if (getIntent() != null && getIntent().getExtras() != null) {
Bundle extras = getIntent().getExtras();
mRemoteItemID = extras.getString(ARG_REMOTE_ITEM_ID);
mRemoteBlogID = extras.getLong(ARG_REMOTE_BLOG_ID, 0);
mRemoteItemType = extras.getString(ARG_REMOTE_ITEM_TYPE);
mItemTitle = extras.getString(ARG_ITEM_TITLE);
mItemURL = extras.getString(ARG_ITEM_URL);
mRestResponseParsed = (PostViewsModel) extras.getSerializable(ARG_REST_RESPONSE);
mSelectedBarGraphIndex = extras.getInt(ARG_SELECTED_GRAPH_BAR, -1);
}
if (mRemoteBlogID == 0 || mRemoteItemID == null) {
Toast.makeText(this, R.string.stats_generic_error, Toast.LENGTH_LONG).show();
finish();
return;
}
if (savedInstanceState == null) {
AnalyticsUtils.trackWithSiteId(AnalyticsTracker.Stat.STATS_SINGLE_POST_ACCESSED, mRemoteBlogID);
}
// Setup the main top label that opens the post in the Reader where possible
if (mItemTitle != null || mItemURL != null) {
mStatsForLabel.setVisibility(View.VISIBLE);
mStatsForLabel.setText(mItemTitle != null ? mItemTitle : mItemURL);
// make the label clickable if the URL is available
if (mItemURL != null) {
mStatsForLabel.setTextColor(getResources().getColor(R.color.stats_link_text_color));
mStatsForLabel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final Context ctx = v.getContext();
StatsUtils.openPostInReaderOrInAppWebview(ctx, mRemoteBlogID, mRemoteItemID, mRemoteItemType, mItemURL);
}
});
} else {
mStatsForLabel.setTextColor(getResources().getColor(R.color.grey_darken_20));
}
} else {
mStatsForLabel.setVisibility(View.GONE);
}
}
use of org.wordpress.android.ui.stats.models.PostViewsModel in project WordPress-Android by wordpress-mobile.
the class RemoteTests method testPostDetails.
public void testPostDetails() throws Exception {
StatsRestRequestAbstractListener listener = new StatsRestRequestAbstractListener() {
@Override
void parseResponse(JSONObject response) throws JSONException {
PostViewsModel model = new PostViewsModel(response);
assertNotNull(model.getOriginalResponse());
assertEquals(model.getDate(), "2015-03-04");
assertEquals(model.getHighestMonth(), 278);
assertEquals(model.getHighestDayAverage(), 8);
assertEquals(model.getHighestWeekAverage(), 8);
assertNotNull(model.getDayViews());
assertEquals(model.getDayViews()[0].getViews(), 0);
assertEquals(model.getDayViews()[0].getPeriod(), "2014-06-04");
assertEquals(model.getDayViews()[model.getDayViews().length - 1].getViews(), 8);
assertEquals(model.getDayViews()[model.getDayViews().length - 1].getPeriod(), "2015-03-04");
assertNotNull(model.getYears().size());
assertEquals(model.getYears().size(), 2);
assertEquals(model.getYears().get(0).getTotal(), 1097);
assertEquals(model.getYears().get(0).getLabel(), "2014");
assertEquals(model.getYears().get(0).getMonths().size(), 7);
assertEquals(model.getYears().get(0).getMonths().get(0).getMonth(), "6");
assertEquals(model.getYears().get(1).getTotal(), 226);
assertEquals(model.getYears().get(1).getLabel(), "2015");
assertNotNull(model.getWeeks().size());
assertEquals(model.getWeeks().size(), 6);
assertNotNull(model.getAverages());
assertEquals(model.getAverages().size(), 2);
assertEquals(model.getAverages().get(0).getTotal(), 5);
assertEquals(model.getAverages().get(0).getLabel(), "2014");
}
};
mRestClient.makeRequest(Request.Method.POST, "https://public-api.wordpress.com/rest/v1.1/sites/123456/stats/post/123", null, listener, errListener);
}
Aggregations