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);
}
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();
}
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;
}
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);
}
});
}
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;
}
Aggregations