Search in sources :

Example 16 with SiteModel

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

Example 17 with SiteModel

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

Example 18 with SiteModel

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

Example 19 with SiteModel

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);
    }
}
Also used : SiteModel(org.wordpress.android.fluxc.model.SiteModel) WPNetworkImageView(org.wordpress.android.widgets.WPNetworkImageView) TextView(android.widget.TextView) View(android.view.View)

Example 20 with SiteModel

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();
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) Bundle(android.os.Bundle) SiteModel(org.wordpress.android.fluxc.model.SiteModel) Role(org.wordpress.android.models.Role)

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