Search in sources :

Example 31 with SiteModel

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

the class ReaderPostActions method bumpPageViewForPost.

public static void bumpPageViewForPost(SiteStore siteStore, ReaderPost post) {
    if (post == null) {
        return;
    }
    // don't bump stats for posts in sites the current user is an admin of, unless
    // this is a private post since we count views for private posts from owner or member
    SiteModel site = siteStore.getSiteBySiteId(post.blogId);
    // site will be null here if the user is not the owner or a member of the site
    if (site != null && !post.isPrivate) {
        AppLog.d(T.READER, "skipped bump page view - user is admin");
        return;
    }
    Response.Listener<String> listener = new Response.Listener<String>() {

        @Override
        public void onResponse(String response) {
            AppLog.d(T.READER, "bump page view succeeded");
        }
    };
    Response.ErrorListener errorListener = new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError volleyError) {
            AppLog.e(T.READER, volleyError);
            AppLog.w(T.READER, "bump page view failed");
        }
    };
    Request request = new StringRequest(Request.Method.GET, getTrackingPixelForPost(post), listener, errorListener) {

        @Override
        public Map<String, String> getHeaders() throws AuthFailureError {
            // call will fail without correct refer(r)er
            Map<String, String> headers = new HashMap<>();
            headers.put("Referer", TRACKING_REFERRER);
            return headers;
        }
    };
    WordPress.sRequestQueue.add(request);
}
Also used : Response(com.android.volley.Response) VolleyError(com.android.volley.VolleyError) UpdateResultListener(org.wordpress.android.ui.reader.actions.ReaderActions.UpdateResultListener) HashMap(java.util.HashMap) StringRequest(com.android.volley.toolbox.StringRequest) RestRequest(com.wordpress.rest.RestRequest) StringRequest(com.android.volley.toolbox.StringRequest) Request(com.android.volley.Request) SiteModel(org.wordpress.android.fluxc.model.SiteModel)

Example 32 with SiteModel

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

the class WordPress method migrateSelfHostedSites.

private void migrateSelfHostedSites() {
    if (!AppPrefs.wereSelfHostedSitesMigratedToFluxC()) {
        List<SiteModel> siteList = WPLegacyMigrationUtils.migrateSelfHostedSitesFromDeprecatedDB(this, mDispatcher);
        if (siteList != null && !siteList.isEmpty()) {
            AppLog.i(T.DB, "Finished migrating " + siteList.size() + " self-hosted sites - fetching site info");
            AppPrefs.setSelfHostedSitesMigratedToFluxC(true);
            mRemainingSelfHostedSitesToFetch = siteList.size();
            for (SiteModel siteModel : siteList) {
                mDispatcher.dispatch(SiteActionBuilder.newFetchSiteAction(siteModel));
            }
            return;
        } else {
            AppLog.i(T.DB, "No self-hosted sites to migrate");
            AppPrefs.setSelfHostedSitesMigratedToFluxC(true);
        }
    } else {
        AppLog.i(T.DB, "Self-hosted sites have already been migrated");
    }
    migrateDrafts();
}
Also used : SiteModel(org.wordpress.android.fluxc.model.SiteModel)

Example 33 with SiteModel

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

the class WPLegacyMigrationUtils method getSelfHostedSitesFromDeprecatedDB.

static List<SiteModel> getSelfHostedSitesFromDeprecatedDB(Context context) {
    List<SiteModel> siteList = new ArrayList<>();
    try {
        SQLiteDatabase db = context.openOrCreateDatabase(DEPRECATED_DATABASE_NAME, 0, null);
        String[] fields = new String[] { "username", "password", "url", "homeURL", "blogId", "api_blogid", "isAdmin" };
        // To exclude the jetpack sites we need to check for empty password
        String byString = String.format("dotcomFlag=0 AND NOT(dotcomFlag=0 AND password='%s')", encryptPassword(""));
        Cursor c = db.query(DEPRECATED_BLOGS_TABLE, fields, byString, null, null, null, null);
        int numRows = c.getCount();
        c.moveToFirst();
        for (int i = 0; i < numRows; i++) {
            long apiBlogId = StringUtils.stringToLong(c.getString(5));
            if (apiBlogId > 0) {
                // If the api_blogid field is set, that's probably a Jetpack site that is not connected to the main
                // account, so we want to skip it.
                c.moveToNext();
                continue;
            }
            String username = c.getString(0);
            String encryptedPwd = c.getString(1);
            String xmlrpcUrl = c.getString(2);
            if (TextUtils.isEmpty(username)) {
                AppLog.d(T.DB, "Found a self-hosted site with no username - skipping it.");
                c.moveToNext();
                continue;
            }
            if (TextUtils.isEmpty(xmlrpcUrl)) {
                AppLog.d(T.DB, "Found a self-hosted site with no XML-RPC URL - skipping it.");
                c.moveToNext();
                continue;
            }
            SiteModel siteModel = new SiteModel();
            siteModel.setUsername(username);
            // Decrypt password before migrating since we no longer encrypt passwords in FluxC
            siteModel.setPassword(decryptPassword(encryptedPwd));
            siteModel.setXmlRpcUrl(xmlrpcUrl);
            String url = c.getString(3);
            if (!TextUtils.isEmpty(url)) {
                siteModel.setUrl(url);
            }
            siteModel.setSelfHostedSiteId(c.getLong(4));
            siteModel.setIsSelfHostedAdmin(SqlUtils.sqlToBool(c.getInt(6)));
            siteList.add(siteModel);
            c.moveToNext();
        }
        c.close();
    } catch (SQLException e) {
    // DB doesn't exist
    }
    return siteList;
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) SQLException(android.database.SQLException) ArrayList(java.util.ArrayList) SiteModel(org.wordpress.android.fluxc.model.SiteModel) Cursor(android.database.Cursor)

Example 34 with SiteModel

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

the class PlansActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ((WordPress) getApplication()).component().inject(this);
    setContentView(R.layout.plans_activity);
    if (savedInstanceState != null) {
        mSelectedSite = (SiteModel) savedInstanceState.getSerializable(WordPress.SITE);
        Serializable serializable = savedInstanceState.getSerializable(ARG_LOCAL_AVAILABLE_PLANS);
        if (serializable instanceof Plan[]) {
            mAvailablePlans = (Plan[]) serializable;
        }
    } else if (getIntent() != null && getIntent().getExtras() != null) {
        mSelectedSite = (SiteModel) getIntent().getExtras().getSerializable(WordPress.SITE);
    }
    if (mSelectedSite == null) {
        AppLog.e(T.PLANS, "Selected site is null");
        Toast.makeText(this, R.string.plans_loading_error, Toast.LENGTH_LONG).show();
        finish();
        return;
    }
    mViewPager = (WPViewPager) findViewById(R.id.viewpager);
    mTabLayout = (TabLayout) findViewById(R.id.tab_layout);
    mManageBar = (ViewGroup) findViewById(R.id.frame_manage);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            onBackPressed();
        }
    });
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        // Shadow removed on Activities with a tab toolbar
        actionBar.setTitle(getString(R.string.plans));
        actionBar.setElevation(0.0f);
        actionBar.setDisplayShowTitleEnabled(true);
        actionBar.setDisplayHomeAsUpEnabled(true);
    }
    // Download plans if not already available
    if (mAvailablePlans == null) {
        if (!NetworkUtils.checkConnection(this)) {
            finish();
            return;
        }
        showProgress();
        PlanUpdateService.startService(this, mSelectedSite);
    } else {
        setupPlansUI();
    }
    // navigate to the "manage plans" page for this blog when the user clicks the manage bar
    mManageBar.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            String domain = UrlUtils.getHost(mSelectedSite.getUrl());
            String managePlansUrl = "https://wordpress.com/plans/" + domain;
            ReaderActivityLauncher.openUrl(view.getContext(), managePlansUrl, OpenUrlType.EXTERNAL);
        }
    });
}
Also used : Serializable(java.io.Serializable) SiteModel(org.wordpress.android.fluxc.model.SiteModel) Plan(org.wordpress.android.ui.plans.models.Plan) View(android.view.View) ActionBar(android.support.v7.app.ActionBar) Toolbar(android.support.v7.widget.Toolbar)

Example 35 with SiteModel

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

the class PersonDetailFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.person_detail_fragment, container, false);
    mCurrentUserId = getArguments().getLong(ARG_CURRENT_USER_ID);
    mPersonId = getArguments().getLong(ARG_PERSON_ID);
    mLocalTableBlogId = getArguments().getInt(ARG_LOCAL_TABLE_BLOG_ID);
    mPersonType = (Person.PersonType) getArguments().getSerializable(ARG_PERSON_TYPE);
    mAvatarImageView = (WPNetworkImageView) rootView.findViewById(R.id.person_avatar);
    mDisplayNameTextView = (TextView) rootView.findViewById(R.id.person_display_name);
    mUsernameTextView = (TextView) rootView.findViewById(R.id.person_username);
    mRoleContainer = (LinearLayout) rootView.findViewById(R.id.person_role_container);
    mRoleTextView = (TextView) rootView.findViewById(R.id.person_role);
    mSubscribedDateContainer = (LinearLayout) rootView.findViewById(R.id.subscribed_date_container);
    mSubscribedDateTitleView = (TextView) rootView.findViewById(R.id.subscribed_date_title);
    mSubscribedDateTextView = (TextView) rootView.findViewById(R.id.subscribed_date_text);
    boolean isCurrentUser = mCurrentUserId == mPersonId;
    SiteModel site = mSiteStore.getSiteByLocalId(mLocalTableBlogId);
    if (!isCurrentUser && site != null && site.getHasCapabilityRemoveUsers()) {
        setHasOptionsMenu(true);
    }
    return rootView;
}
Also used : ViewGroup(android.view.ViewGroup) SiteModel(org.wordpress.android.fluxc.model.SiteModel) Person(org.wordpress.android.models.Person)

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