use of org.wordpress.android.fluxc.model.SiteModel in project WordPress-Android by wordpress-mobile.
the class WPMainActivity method initSelectedSite.
/**
* This should not be moved to a SiteUtils.getSelectedSite() or similar static method. We don't want
* this to be used globally like WordPress.getCurrentBlog() was used. The state is maintained by this
* Activity and the selected site parameter is passed along to other activities / fragments.
*/
public void initSelectedSite() {
int siteLocalId = AppPrefs.getSelectedSite();
if (siteLocalId != -1) {
// Site previously selected, use it
mSelectedSite = mSiteStore.getSiteByLocalId(siteLocalId);
// If saved site exist, then return, else (site has been removed?) try to select another site
if (mSelectedSite != null) {
return;
}
}
// Try to select the primary wpcom site
long siteId = mAccountStore.getAccount().getPrimarySiteId();
SiteModel primarySite = mSiteStore.getSiteBySiteId(siteId);
// Primary site found, select it
if (primarySite != null) {
setSelectedSite(primarySite);
return;
}
// Else select the first visible site in the list
List<SiteModel> sites = mSiteStore.getVisibleSites();
if (sites.size() != 0) {
setSelectedSite(sites.get(0));
return;
}
// Else select the first in the list
sites = mSiteStore.getSites();
if (sites.size() != 0) {
setSelectedSite(sites.get(0));
}
// Else no site selected
}
use of org.wordpress.android.fluxc.model.SiteModel in project WordPress-Android by wordpress-mobile.
the class NotificationsPendingDraftsReceiver method onReceive.
@Override
public void onReceive(Context context, Intent intent) {
((WordPress) context.getApplicationContext()).component().inject(this);
// for the case of being spanned after device restarts, get the latest drafts
// and check the lastUpdated
String action = intent.getAction();
if (action != null && action.equals("android.intent.action.BOOT_COMPLETED")) {
AppLog.i(AppLog.T.NOTIFS, "entering Pending Drafts Receiver from BOOT_COMPLETED");
// build notifications for existing local drafts
int siteLocalId = AppPrefs.getSelectedSite();
SiteModel site = mSiteStore.getSiteByLocalId(siteLocalId);
if (site != null) {
List<PostModel> draftPosts = mPostStore.getPostsForSite(site);
for (PostModel post : draftPosts) {
// reschedule next notifications for each local draft post we have, as we have
// just been rebooted
PendingDraftsNotificationsUtils.scheduleNextNotifications(context, post);
}
}
} else {
AppLog.i(AppLog.T.NOTIFS, "entering Pending Drafts Receiver from alarm");
// get extras from intent in order to build notification
buildNotificationForPostId(intent.getIntExtra(POST_ID_EXTRA, 0), context);
}
}
use of org.wordpress.android.fluxc.model.SiteModel in project WordPress-Android by wordpress-mobile.
the class NotificationsDetailActivity method showStatsActivityForSite.
public void showStatsActivityForSite(long siteId, NoteBlockRangeType rangeType) {
SiteModel site = mSiteStore.getSiteBySiteId(siteId);
if (site == null) {
// One way the site can be null: new site created, receive a notification from this site,
// but the site list is not yet updated in the app.
ToastUtils.showToast(this, R.string.blog_not_found);
return;
}
showStatsActivityForSite(site, rangeType);
}
use of org.wordpress.android.fluxc.model.SiteModel in project WordPress-Android by wordpress-mobile.
the class PersonDetailFragment method setupRoleContainerForCapability.
// Checks current user's capabilities to decide whether she can change the role or not
private void setupRoleContainerForCapability() {
SiteModel site = mSiteStore.getSiteByLocalId(mLocalTableBlogId);
boolean isCurrentUser = mCurrentUserId == mPersonId;
boolean canChangeRole = (site != null) && !isCurrentUser && site.getHasCapabilityPromoteUsers();
if (canChangeRole) {
mRoleContainer.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showRoleChangeDialog();
}
});
} else {
// Remove the selectableItemBackground if the user can't be edited
clearRoleContainerBackground();
// Change transparency to give a visual cue to the user that it's disabled
mRoleContainer.setAlpha(0.5f);
}
}
use of org.wordpress.android.fluxc.model.SiteModel in project WordPress-Android by wordpress-mobile.
the class RoleChangeDialogFragment method onCreateDialog.
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final SiteModel site = (SiteModel) getArguments().getSerializable(WordPress.SITE);
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.Calypso_AlertDialog);
builder.setTitle(R.string.role);
builder.setNegativeButton(R.string.cancel, null);
builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Role role = mRoleListAdapter.getSelectedRole();
Bundle args = getArguments();
if (args != null) {
long personID = args.getLong(PERSON_ID_TAG);
if (site != null) {
EventBus.getDefault().post(new RoleChangeEvent(personID, site.getId(), role));
}
}
}
});
if (mRoleListAdapter == null) {
final Role[] userRoles = Role.userRoles(site);
mRoleListAdapter = new RoleListAdapter(getActivity(), R.layout.role_list_row, userRoles);
}
if (savedInstanceState != null) {
Role savedRole = (Role) savedInstanceState.getSerializable(ROLE_TAG);
mRoleListAdapter.setSelectedRole(savedRole);
} else {
Bundle args = getArguments();
if (args != null) {
Role role = (Role) args.getSerializable(ROLE_TAG);
mRoleListAdapter.setSelectedRole(role);
}
}
builder.setAdapter(mRoleListAdapter, null);
return builder.create();
}
Aggregations