use of org.wordpress.android.ui.stats.models.VisitModel in project WordPress-Android by wordpress-mobile.
the class StatsSingleItemDetailsActivity method updateUI.
private void updateUI() {
if (isFinishing()) {
return;
}
final VisitModel[] dataToShowOnGraph = getDataToShowOnGraph();
if (dataToShowOnGraph == null || dataToShowOnGraph.length == 0) {
setupEmptyUI();
return;
}
final String[] horLabels = new String[dataToShowOnGraph.length];
String[] mStatsDate = new String[dataToShowOnGraph.length];
GraphView.GraphViewData[] views = new GraphView.GraphViewData[dataToShowOnGraph.length];
for (int i = 0; i < dataToShowOnGraph.length; i++) {
int currentItemValue = dataToShowOnGraph[i].getViews();
views[i] = new GraphView.GraphViewData(i, currentItemValue);
String currentItemStatsDate = dataToShowOnGraph[i].getPeriod();
horLabels[i] = StatsUtils.parseDate(currentItemStatsDate, StatsConstants.STATS_INPUT_DATE_FORMAT, StatsConstants.STATS_OUTPUT_DATE_MONTH_SHORT_DAY_SHORT_FORMAT);
mStatsDate[i] = currentItemStatsDate;
}
GraphViewSeries mCurrentSeriesOnScreen = new GraphViewSeries(views);
mCurrentSeriesOnScreen.getStyle().color = getResources().getColor(R.color.stats_bar_graph_main_series);
mCurrentSeriesOnScreen.getStyle().highlightColor = getResources().getColor(R.color.stats_bar_graph_main_series_highlight);
mCurrentSeriesOnScreen.getStyle().outerhighlightColor = getResources().getColor(R.color.stats_bar_graph_outer_highlight);
mCurrentSeriesOnScreen.getStyle().padding = DisplayUtils.dpToPx(this, 5);
StatsBarGraph mGraphView;
if (mGraphContainer.getChildCount() >= 1 && mGraphContainer.getChildAt(0) instanceof GraphView) {
mGraphView = (StatsBarGraph) mGraphContainer.getChildAt(0);
} else {
mGraphContainer.removeAllViews();
mGraphView = new StatsBarGraph(this);
mGraphContainer.addView(mGraphView);
}
mGraphView.removeAllSeries();
mGraphView.addSeries(mCurrentSeriesOnScreen);
//mGraphView.getGraphViewStyle().setNumHorizontalLabels(getNumOfHorizontalLabels(dataToShowOnGraph.length));
mGraphView.getGraphViewStyle().setNumHorizontalLabels(dataToShowOnGraph.length);
mGraphView.getGraphViewStyle().setMaxColumnWidth(DisplayUtils.dpToPx(this, StatsConstants.STATS_GRAPH_BAR_MAX_COLUMN_WIDTH_DP));
mGraphView.setHorizontalLabels(horLabels);
mGraphView.setGestureListener(this);
// Only happens on 720DP tablets
if (mPrevNumberOfBarsGraph != -1 && mPrevNumberOfBarsGraph != dataToShowOnGraph.length) {
mSelectedBarGraphIndex = dataToShowOnGraph.length - 1;
} else {
mSelectedBarGraphIndex = (mSelectedBarGraphIndex != -1) ? mSelectedBarGraphIndex : dataToShowOnGraph.length - 1;
}
mGraphView.highlightBar(mSelectedBarGraphIndex);
mPrevNumberOfBarsGraph = dataToShowOnGraph.length;
setMainViewsLabel(StatsUtils.parseDate(mStatsDate[mSelectedBarGraphIndex], StatsConstants.STATS_INPUT_DATE_FORMAT, StatsConstants.STATS_OUTPUT_DATE_MONTH_LONG_DAY_SHORT_FORMAT), dataToShowOnGraph[mSelectedBarGraphIndex].getViews());
showHideEmptyModulesIndicator(false);
mMonthsAndYearsList.setVisibility(View.VISIBLE);
List<PostViewsModel.Year> years = mRestResponseParsed.getYears();
MonthsAndYearsListAdapter monthsAndYearsListAdapter = new MonthsAndYearsListAdapter(this, years, mRestResponseParsed.getHighestMonth());
StatsUIHelper.reloadGroupViews(this, monthsAndYearsListAdapter, mYearsIdToExpandedMap, mMonthsAndYearsList);
mAveragesList.setVisibility(View.VISIBLE);
List<PostViewsModel.Year> averages = mRestResponseParsed.getAverages();
MonthsAndYearsListAdapter averagesListAdapter = new MonthsAndYearsListAdapter(this, averages, mRestResponseParsed.getHighestDayAverage());
StatsUIHelper.reloadGroupViews(this, averagesListAdapter, mAveragesIdToExpandedMap, mAveragesList);
mRecentWeeksList.setVisibility(View.VISIBLE);
List<PostViewsModel.Week> recentWeeks = mRestResponseParsed.getWeeks();
RecentWeeksListAdapter recentWeeksListAdapter = new RecentWeeksListAdapter(this, recentWeeks, mRestResponseParsed.getHighestWeekAverage());
StatsUIHelper.reloadGroupViews(this, recentWeeksListAdapter, mRecentWeeksIdToExpandedMap, mRecentWeeksList);
}
use of org.wordpress.android.ui.stats.models.VisitModel in project WordPress-Android by wordpress-mobile.
the class StatsService method updateWidgetsUI.
// Call an updates on the installed widgets if the blog is the primary, the endpoint is Visits
// the timeframe is DAY or INSIGHTS, and the date = TODAY
private void updateWidgetsUI(long siteId, final StatsEndpointsEnum endpointName, StatsTimeframe timeframe, String date, int pageRequested, Serializable responseObjectModel) {
if (pageRequested != -1) {
return;
}
if (endpointName != StatsEndpointsEnum.VISITS) {
return;
}
if (timeframe != StatsTimeframe.DAY && timeframe != StatsTimeframe.INSIGHTS) {
return;
}
SiteModel site = mSiteStore.getSiteBySiteId(siteId);
// make sure the data is for the current date
if (!date.equals(StatsUtils.getCurrentDateTZ(site))) {
return;
}
if (responseObjectModel == null) {
// TODO What we want to do here?
return;
}
if (!StatsWidgetProvider.isBlogDisplayedInWidget(siteId)) {
AppLog.d(AppLog.T.STATS, "The blog with remoteID " + siteId + " is NOT displayed in any widget. Stats Service doesn't call an update of the widget.");
return;
}
if (responseObjectModel instanceof VisitsModel) {
VisitsModel visitsModel = (VisitsModel) responseObjectModel;
if (visitsModel.getVisits() == null || visitsModel.getVisits().size() == 0) {
return;
}
List<VisitModel> visits = visitsModel.getVisits();
VisitModel data = visits.get(visits.size() - 1);
StatsWidgetProvider.updateWidgets(getApplicationContext(), site, data);
} else if (responseObjectModel instanceof VolleyError) {
VolleyError error = (VolleyError) responseObjectModel;
StatsWidgetProvider.updateWidgets(getApplicationContext(), site, mSiteStore, error);
} else if (responseObjectModel instanceof StatsError) {
StatsError statsError = (StatsError) responseObjectModel;
StatsWidgetProvider.updateWidgets(getApplicationContext(), site, mSiteStore, statsError);
}
}
Aggregations