Search in sources :

Example 6 with SiteModel

use of org.wordpress.android.fluxc.model.SiteModel in project WordPress-Android by wordpress-mobile.

the class HelpshiftHelper method getPlanTags.

@NonNull
private Set<String> getPlanTags(@NonNull SiteStore siteStore) {
    Set<String> tags = new HashSet<>();
    for (SiteModel site : siteStore.getSites()) {
        if (site.getPlanId() == 0) {
            // Skip unknown plans, missing or unknown plan ID is 0
            continue;
        }
        String tag = String.format(Locale.US, "plan:%d", site.getPlanId());
        tags.add(tag);
    }
    return tags;
}
Also used : SiteModel(org.wordpress.android.fluxc.model.SiteModel) HashSet(java.util.HashSet) NonNull(android.support.annotation.NonNull)

Example 7 with SiteModel

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;
}
Also used : SiteModel(org.wordpress.android.fluxc.model.SiteModel)

Example 8 with SiteModel

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()));
}
Also used : Calendar(java.util.Calendar) SiteModel(org.wordpress.android.fluxc.model.SiteModel) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 9 with SiteModel

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();
}
Also used : SiteModel(org.wordpress.android.fluxc.model.SiteModel) Subscribe(org.greenrobot.eventbus.Subscribe)

Example 10 with SiteModel

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);
                }
            }
        }
    });
}
Also used : List(java.util.List) SiteModel(org.wordpress.android.fluxc.model.SiteModel) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Aggregations

SiteModel (org.wordpress.android.fluxc.model.SiteModel)40 Intent (android.content.Intent)7 Subscribe (org.greenrobot.eventbus.Subscribe)5 View (android.view.View)4 Bundle (android.os.Bundle)3 TextView (android.widget.TextView)3 VolleyError (com.android.volley.VolleyError)3 ArrayList (java.util.ArrayList)3 JSONObject (org.json.JSONObject)3 AlertDialog (android.app.AlertDialog)2 Context (android.content.Context)2 DialogInterface (android.content.DialogInterface)2 ImageView (android.widget.ImageView)2 ScrollView (android.widget.ScrollView)2 RestRequest (com.wordpress.rest.RestRequest)2 CommentModel (org.wordpress.android.fluxc.model.CommentModel)2 PostModel (org.wordpress.android.fluxc.model.PostModel)2 WPNetworkImageView (org.wordpress.android.widgets.WPNetworkImageView)2 SuppressLint (android.annotation.SuppressLint)1 Activity (android.app.Activity)1