Search in sources :

Example 1 with StatsError

use of org.wordpress.android.ui.stats.exceptions.StatsError 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);
    }
}
Also used : VolleyError(com.android.volley.VolleyError) VisitModel(org.wordpress.android.ui.stats.models.VisitModel) SiteModel(org.wordpress.android.fluxc.model.SiteModel) VisitsModel(org.wordpress.android.ui.stats.models.VisitsModel) StatsError(org.wordpress.android.ui.stats.exceptions.StatsError)

Aggregations

VolleyError (com.android.volley.VolleyError)1 SiteModel (org.wordpress.android.fluxc.model.SiteModel)1 StatsError (org.wordpress.android.ui.stats.exceptions.StatsError)1 VisitModel (org.wordpress.android.ui.stats.models.VisitModel)1 VisitsModel (org.wordpress.android.ui.stats.models.VisitsModel)1