use of org.wordpress.android.ui.stats.StatsTimeframe in project WordPress-Android by wordpress-mobile.
the class StatsService method onStartCommand.
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (intent == null) {
AppLog.e(T.STATS, "StatsService was killed and restarted with a null intent.");
// if this service's process is killed while it is started (after returning from onStartCommand(Intent, int, int)),
// then leave it in the started state but don't retain this delivered intent.
// Later the system will try to re-create the service.
// Because it is in the started state, it will guarantee to call onStartCommand(Intent, int, int) after creating the new service instance;
// if there are not any pending start commands to be delivered to the service, it will be called with a null intent object.
stopRefresh();
return START_NOT_STICKY;
}
final long siteId = intent.getLongExtra(ARG_BLOG_ID, 0);
if (siteId == 0) {
AppLog.e(T.STATS, "StatsService was started with siteid == 0");
return START_NOT_STICKY;
}
int[] sectionFromIntent = intent.getIntArrayExtra(ARG_SECTION);
if (sectionFromIntent == null || sectionFromIntent.length == 0) {
// No sections to update
AppLog.e(T.STATS, "StatsService was started without valid sections info");
return START_NOT_STICKY;
}
final StatsTimeframe period;
if (intent.hasExtra(ARG_PERIOD)) {
period = (StatsTimeframe) intent.getSerializableExtra(ARG_PERIOD);
} else {
period = StatsTimeframe.DAY;
}
final String requestedDate;
if (intent.getStringExtra(ARG_DATE) == null) {
AppLog.w(T.STATS, "StatsService is started with a NULL date on this blogID - " + siteId + ". Using current date.");
SiteModel site = mSiteStore.getSiteBySiteId(siteId);
requestedDate = StatsUtils.getCurrentDateTZ(site);
} else {
requestedDate = intent.getStringExtra(ARG_DATE);
}
final int maxResultsRequested = intent.getIntExtra(ARG_MAX_RESULTS, DEFAULT_NUMBER_OF_RESULTS);
final int pageRequested = intent.getIntExtra(ARG_PAGE_REQUESTED, -1);
this.mServiceStartId = startId;
for (int i = 0; i < sectionFromIntent.length; i++) {
final StatsEndpointsEnum currentSectionsToUpdate = StatsEndpointsEnum.values()[sectionFromIntent[i]];
singleThreadNetworkHandler.submit(new Thread() {
@Override
public void run() {
startTasks(siteId, period, requestedDate, currentSectionsToUpdate, maxResultsRequested, pageRequested);
}
});
}
return START_NOT_STICKY;
}
Aggregations