Search in sources :

Example 1 with SiteRecord

use of org.wordpress.android.ui.main.SitePickerAdapter.SiteRecord in project WordPress-Android by wordpress-mobile.

the class SitePickerActivity method saveHiddenSites.

private void saveHiddenSites(Set<SiteRecord> changeSet) {
    boolean skippedCurrentSite = false;
    String currentSiteName = null;
    SiteList hiddenSites = getAdapter().getHiddenSites();
    List<SiteModel> siteList = new ArrayList<>();
    for (SiteRecord siteRecord : changeSet) {
        SiteModel siteModel = mSiteStore.getSiteByLocalId(siteRecord.localId);
        if (hiddenSites.contains(siteRecord)) {
            if (siteRecord.localId == mCurrentLocalId) {
                skippedCurrentSite = true;
                currentSiteName = siteRecord.getBlogNameOrHomeURL();
                continue;
            }
            siteModel.setIsVisible(false);
            // Remove stats data for hidden sites
            StatsTable.deleteStatsForBlog(this, siteRecord.localId);
        } else {
            siteModel.setIsVisible(true);
        }
        // Save the site
        mDispatcher.dispatch(SiteActionBuilder.newUpdateSiteAction(siteModel));
        siteList.add(siteModel);
    }
    updateVisibilityOfSitesOnRemote(siteList);
    // let user know the current site wasn't hidden
    if (skippedCurrentSite) {
        String cantHideCurrentSite = getString(R.string.site_picker_cant_hide_current_site);
        ToastUtils.showToast(this, String.format(cantHideCurrentSite, currentSiteName), ToastUtils.Duration.LONG);
    }
}
Also used : SiteList(org.wordpress.android.ui.main.SitePickerAdapter.SiteList) SiteRecord(org.wordpress.android.ui.main.SitePickerAdapter.SiteRecord) ArrayList(java.util.ArrayList) SiteModel(org.wordpress.android.fluxc.model.SiteModel)

Aggregations

ArrayList (java.util.ArrayList)1 SiteModel (org.wordpress.android.fluxc.model.SiteModel)1 SiteList (org.wordpress.android.ui.main.SitePickerAdapter.SiteList)1 SiteRecord (org.wordpress.android.ui.main.SitePickerAdapter.SiteRecord)1