use of org.wordpress.android.fluxc.model.SiteModel in project WordPress-Android by wordpress-mobile.
the class StatsVisitorsAndViewsFragment method onBarTapped.
@Override
public void onBarTapped(int tappedBar) {
if (!isAdded()) {
return;
}
//AppLog.d(AppLog.T.STATS, " Tapped bar date " + mStatsDate[tappedBar]);
mSelectedBarGraphBarIndex = tappedBar;
updateUIBelowTheGraph(tappedBar);
if (!NetworkUtils.checkConnection(getActivity())) {
return;
}
// Update Stats here
String date = mStatsDate[tappedBar];
if (date == null) {
AppLog.w(AppLog.T.STATS, "A bar was tapped but a null date is received!!");
return;
}
//Calculate the correct end date for the selected period
String calculatedDate = null;
try {
SimpleDateFormat sdf;
Calendar c = Calendar.getInstance();
c.setFirstDayOfWeek(Calendar.MONDAY);
final Date parsedDate;
switch(getTimeframe()) {
case DAY:
calculatedDate = date;
break;
case WEEK:
// first four digits are the year
// followed by Wxx where xx is the month
// followed by Wxx where xx is the day of the month
// ex: 2013W07W22 = July 22, 2013
sdf = new SimpleDateFormat("yyyy'W'MM'W'dd");
//Calculate the end of the week
parsedDate = sdf.parse(date);
c.setTime(parsedDate);
// first day of this week
c.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
// last day of this week
c.add(Calendar.DAY_OF_WEEK, +6);
calculatedDate = StatsUtils.msToString(c.getTimeInMillis(), StatsConstants.STATS_INPUT_DATE_FORMAT);
break;
case MONTH:
sdf = new SimpleDateFormat("yyyy-MM");
//Calculate the end of the month
parsedDate = sdf.parse(date);
c.setTime(parsedDate);
// last day of this month
c.set(Calendar.DAY_OF_MONTH, c.getActualMaximum(Calendar.DAY_OF_MONTH));
calculatedDate = StatsUtils.msToString(c.getTimeInMillis(), StatsConstants.STATS_INPUT_DATE_FORMAT);
break;
case YEAR:
sdf = new SimpleDateFormat(StatsConstants.STATS_INPUT_DATE_FORMAT);
//Calculate the end of the week
parsedDate = sdf.parse(date);
c.setTime(parsedDate);
c.set(Calendar.MONTH, Calendar.DECEMBER);
c.set(Calendar.DAY_OF_MONTH, 31);
calculatedDate = StatsUtils.msToString(c.getTimeInMillis(), StatsConstants.STATS_INPUT_DATE_FORMAT);
break;
}
} catch (ParseException e) {
AppLog.e(AppLog.T.UTILS, e);
}
if (calculatedDate == null) {
AppLog.w(AppLog.T.STATS, "A call to request new stats stats is made but date received cannot be parsed!! " + date);
return;
}
// Update the data below the graph
if (mListener != null) {
// Should never be null
SiteModel site = mSiteStore.getSiteByLocalId(getLocalTableBlogID());
if (site != null && SiteUtils.isAccessibleViaWPComAPI(site)) {
mListener.onDateChanged(site.getSiteId(), getTimeframe(), calculatedDate);
}
}
AnalyticsUtils.trackWithSiteDetails(AnalyticsTracker.Stat.STATS_TAPPED_BAR_CHART, mSiteStore.getSiteByLocalId(getLocalTableBlogID()));
}
use of org.wordpress.android.fluxc.model.SiteModel in project WordPress-Android by wordpress-mobile.
the class StatsActivity method onSiteChanged.
// FluxC events
@SuppressWarnings("unused")
@Subscribe(threadMode = ThreadMode.MAIN)
public void onSiteChanged(OnSiteChanged event) {
// "Reload" current site from the db, would be smarter if the OnSiteChanged provided the list of changed sites.
SiteModel site = mSiteStore.getSiteByLocalId(mSite.getId());
if (site != null) {
mSite = site;
}
// Make sure the update site is accessible
checkIfSiteHasAccessibleStats(mSite);
// Refresh Stats
refreshStatsFromCurrentDate();
}
use of org.wordpress.android.fluxc.model.SiteModel in project WordPress-Android by wordpress-mobile.
the class StatsFollowersFragment method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Single background thread used to create the blogs list in BG
ThreadPoolExecutor blogsListCreatorExecutor = (ThreadPoolExecutor) Executors.newFixedThreadPool(1);
blogsListCreatorExecutor.submit(new Thread() {
@Override
public void run() {
// Read all the .com and jetpack sites and get the list of home URLs.
// This will be used later to check if the user is a member of followers blog marked as private.
List<SiteModel> sites = mSiteStore.getWPComAndJetpackSites();
for (SiteModel site : sites) {
if (site.getUrl() != null && site.getSiteId() != 0) {
String normURL = normalizeAndRemoveScheme(site.getUrl());
long blogID = site.getSiteId();
userBlogs.put(normURL, blogID);
}
}
}
});
}
use of org.wordpress.android.fluxc.model.SiteModel in project WordPress-Android by wordpress-mobile.
the class WPLegacyMigrationUtils method migrateSelfHostedSitesFromDeprecatedDB.
/**
* Copies existing self-hosted sites from a previous version of WPAndroid into FluxC's SiteStore.
* Any Jetpack sites are ignored - those connected to the logged-in WP.com account will be pulled through the
* REST API after migration. Other Jetpack sites will not be migrated.
* Existing sites are retained in the deprecated accounts table after migration.
*/
public static List<SiteModel> migrateSelfHostedSitesFromDeprecatedDB(Context context, Dispatcher dispatcher) {
List<SiteModel> siteList = getSelfHostedSitesFromDeprecatedDB(context.getApplicationContext());
if (siteList != null) {
AppLog.i(T.DB, "Starting migration of " + siteList.size() + " self-hosted sites to FluxC");
for (SiteModel siteModel : siteList) {
AppLog.i(T.DB, "Migrating self-hosted site with url: " + siteModel.getXmlRpcUrl() + " username: " + siteModel.getUsername());
dispatcher.dispatch(SiteActionBuilder.newUpdateSiteAction(siteModel));
}
}
return siteList;
}
use of org.wordpress.android.fluxc.model.SiteModel 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