use of org.wordpress.android.fluxc.model.SiteModel in project WordPress-Android by wordpress-mobile.
the class PostUploadService method onPostUploaded.
@SuppressWarnings("unused")
@Subscribe(threadMode = ThreadMode.MAIN)
public void onPostUploaded(OnPostUploaded event) {
SiteModel site = mSiteStore.getSiteByLocalId(event.post.getLocalSiteId());
if (event.isError()) {
AppLog.e(T.EDITOR, "Post upload failed. " + event.error.type + ": " + event.error.message);
mPostUploadNotifier.updateNotificationError(event.post, site, buildErrorMessage(event.post, event.error), false);
mFirstPublishPosts.remove(event.post.getId());
} else {
mPostUploadNotifier.cancelNotification(event.post);
boolean isFirstTimePublish = mFirstPublishPosts.remove(event.post.getId());
mPostUploadNotifier.updateNotificationSuccess(event.post, site, isFirstTimePublish);
}
finishUpload();
}
use of org.wordpress.android.fluxc.model.SiteModel in project WordPress-Android by wordpress-mobile.
the class AccountSettingsFragment method changePrimaryBlogPreference.
private void changePrimaryBlogPreference(long siteRemoteId) {
mPrimarySitePreference.setValue(String.valueOf(siteRemoteId));
SiteModel site = mSiteStore.getSiteBySiteId(siteRemoteId);
if (site != null) {
mPrimarySitePreference.setSummary(StringUtils.unescapeHTML(SiteUtils.getSiteNameOrHomeURL(site)));
mPrimarySitePreference.refreshAdapter();
}
}
use of org.wordpress.android.fluxc.model.SiteModel in project WordPress-Android by wordpress-mobile.
the class MySiteFragment method refreshSelectedSiteDetails.
private void refreshSelectedSiteDetails() {
if (!isAdded()) {
return;
}
SiteModel site = getSelectedSite();
if (site == null) {
mScrollView.setVisibility(View.GONE);
mFabView.setVisibility(View.GONE);
mNoSiteView.setVisibility(View.VISIBLE);
// if the screen height is too short, we can just hide the drake illustration
Activity activity = getActivity();
boolean drakeVisibility = DisplayUtils.getDisplayPixelHeight(activity) >= 500;
if (drakeVisibility) {
mNoSiteDrakeImageView.setVisibility(View.VISIBLE);
} else {
mNoSiteDrakeImageView.setVisibility(View.GONE);
}
return;
}
mScrollView.setVisibility(View.VISIBLE);
mNoSiteView.setVisibility(View.GONE);
toggleAdminVisibility(site);
int themesVisibility = ThemeBrowserActivity.isAccessible(getSelectedSite()) ? View.VISIBLE : View.GONE;
mLookAndFeelHeader.setVisibility(themesVisibility);
mThemesContainer.setVisibility(themesVisibility);
// show settings for all self-hosted to expose Delete Site
boolean isAdminOrSelfHosted = site.getHasCapabilityManageOptions() || !SiteUtils.isAccessibleViaWPComAPI(site);
mSettingsView.setVisibility(isAdminOrSelfHosted ? View.VISIBLE : View.GONE);
mPeopleView.setVisibility(site.getHasCapabilityListUsers() ? View.VISIBLE : View.GONE);
// if either people or settings is visible, configuration header should be visible
int settingsVisibility = (isAdminOrSelfHosted || site.getHasCapabilityListUsers()) ? View.VISIBLE : View.GONE;
mConfigurationHeader.setVisibility(settingsVisibility);
mBlavatarImageView.setImageUrl(SiteUtils.getSiteIconUrl(site, mBlavatarSz), WPNetworkImageView.ImageType.BLAVATAR);
String homeUrl = SiteUtils.getHomeURLOrHostName(site);
String blogTitle = SiteUtils.getSiteNameOrHomeURL(site);
mBlogTitleTextView.setText(blogTitle);
mBlogSubtitleTextView.setText(homeUrl);
// Hide the Plan item if the Plans feature is not available for this blog
String planShortName = site.getPlanShortName();
if (!TextUtils.isEmpty(planShortName) && site.getHasCapabilityManageOptions()) {
if (site.isWPCom() || site.isAutomatedTransfer()) {
mCurrentPlanNameTextView.setText(planShortName);
mPlanContainer.setVisibility(View.VISIBLE);
} else {
// TODO: Support Jetpack plans
mPlanContainer.setVisibility(View.GONE);
}
} else {
mPlanContainer.setVisibility(View.GONE);
}
// Do not show pages menu item to Collaborators.
int pageVisibility = site.isSelfHostedAdmin() || site.getHasCapabilityEditPages() ? View.VISIBLE : View.GONE;
mPageView.setVisibility(pageVisibility);
}
use of org.wordpress.android.fluxc.model.SiteModel in project WordPress-Android by wordpress-mobile.
the class SitePickerActivity method updateVisibilityOfSitesOnRemote.
private void updateVisibilityOfSitesOnRemote(List<SiteModel> siteList) {
// Example json format for the request: {"sites":{"100001":{"visible":false}}}
JSONObject jsonObject = new JSONObject();
try {
JSONObject sites = new JSONObject();
for (SiteModel siteModel : siteList) {
JSONObject visible = new JSONObject();
visible.put("visible", siteModel.isVisible());
sites.put(Long.toString(siteModel.getSiteId()), visible);
}
jsonObject.put("sites", sites);
} catch (JSONException e) {
AppLog.e(AppLog.T.API, "Could not build me/sites json object");
}
if (jsonObject.length() == 0) {
return;
}
WordPress.getRestClientUtilsV1_1().post("me/sites", jsonObject, null, new RestRequest.Listener() {
@Override
public void onResponse(JSONObject response) {
AppLog.v(AppLog.T.API, "Site visibility successfully updated");
}
}, new RestRequest.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
AppLog.e(AppLog.T.API, "An error occurred while updating site visibility: " + volleyError);
}
});
}
use of org.wordpress.android.fluxc.model.SiteModel in project WordPress-Android by wordpress-mobile.
the class WPMainActivity method onSiteChanged.
@SuppressWarnings("unused")
@Subscribe(threadMode = ThreadMode.MAIN)
public void onSiteChanged(OnSiteChanged event) {
// "Reload" selected site from the db, would be smarter if the OnSiteChanged provided the list of changed sites.
if (getSelectedSite() == null && mSiteStore.hasSite()) {
setSelectedSite(mSiteStore.getSites().get(0));
}
if (getSelectedSite() == null) {
return;
}
SiteModel site = mSiteStore.getSiteByLocalId(getSelectedSite().getId());
if (site != null) {
if (site.isJetpackConnected() && !TextUtils.isEmpty(site.getPassword())) {
// The user added a Jetpack-connected site as a self-hosted site - this isn't supported
if (!mAccountStore.hasAccessToken()) {
// Ask user to sign in to WordPress.com to access their Jetpack site
Intent signInIntent = new Intent(this, SignInActivity.class);
signInIntent.putExtra(SignInActivity.EXTRA_JETPACK_SITE_AUTH, site.getId());
signInIntent.putExtra(SignInActivity.EXTRA_JETPACK_MESSAGE_AUTH, getString(R.string.jetpack_use_com_account));
startActivityForResult(signInIntent, SignInActivity.REQUEST_CODE);
finish();
} else {
// Remove the site and send the user back to the site list
ToastUtils.showToast(this, R.string.jetpack_different_com_account, ToastUtils.Duration.LONG);
mDispatcher.dispatch(SiteActionBuilder.newRemoveSiteAction(site));
}
return;
}
mSelectedSite = site;
}
}
Aggregations