Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/org/wordpress/android/WordPress.java
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public static void postUploaded() {
* select the first one.
*/
public static Blog getCurrentBlog() {
if (currentBlog == null || !wpDB.isDotComAccountVisible(currentBlog.getBlogId())) {
if (currentBlog == null || !wpDB.isDotComAccountVisible(currentBlog.getRemoteBlogId())) {
// attempt to restore the last active blog
setCurrentBlogToLastActive();

Expand Down Expand Up @@ -304,12 +304,12 @@ public static Blog setCurrentBlog(int id) {
/*
* returns the blogID of the current blog
*/
public static int getCurrentBlogId() {
return (currentBlog != null ? currentBlog.getBlogId() : -1);
public static int getCurrentRemoteBlogId() {
return (currentBlog != null ? currentBlog.getRemoteBlogId() : -1);
}

public static int getCurrentBlogAccountId() {
return (currentBlog != null ? currentBlog.getId() : -1);
public static int getCurrentLocalTableBlogId() {
return (currentBlog != null ? currentBlog.getLocalTableBlogId() : -1);
}

/**
Expand Down
66 changes: 19 additions & 47 deletions src/org/wordpress/android/WordPressDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ public boolean addBlog(Blog blog) {
values.put("maxImageWidth", blog.getMaxImageWidth());
values.put("maxImageWidthId", blog.getMaxImageWidthId());
values.put("runService", false);
values.put("blogId", blog.getBlogId());
values.put("blogId", blog.getRemoteBlogId());
values.put("dotcomFlag", blog.isDotcomFlag());
values.put("wpVersion", blog.getWpVersion());
values.put("isAdmin", blog.isAdmin());
Expand Down Expand Up @@ -432,9 +432,9 @@ public boolean isBlogInDatabase(int blogId, String xmlRpcUrl) {
return result;
}

public boolean isBlogIdInDatabase(int blogId) {
String[] args = {Integer.toString(blogId)};
return SqlUtils.boolForQuery(db, "SELECT 1 FROM " + SETTINGS_TABLE + " WHERE blogId=?", args);
public boolean isLocalBlogIdInDatabase(int localBlogId) {
String[] args = {Integer.toString(localBlogId)};
return SqlUtils.boolForQuery(db, "SELECT 1 FROM " + SETTINGS_TABLE + " WHERE id=?", args);
}

public boolean saveBlog(Blog blog) {
Expand Down Expand Up @@ -463,7 +463,7 @@ public boolean saveBlog(Blog blog) {
values.put("blogName", blog.getBlogName());
values.put("isAdmin", blog.isAdmin());

boolean returnValue = db.update(SETTINGS_TABLE, values, "id=" + blog.getId(),
boolean returnValue = db.update(SETTINGS_TABLE, values, "id=" + blog.getLocalTableBlogId(),
null) > 0;
if (blog.isDotcomFlag()) {
returnValue = updateWPComCredentials(blog.getUsername(), blog.getPassword());
Expand Down Expand Up @@ -663,30 +663,13 @@ public List<Integer> getNotificationAccounts() {
return returnVector;
}

public String getAccountName(String accountID) {

String accountName = "";
Cursor c = db.query(SETTINGS_TABLE, new String[]{"blogName"}, "id="
+ accountID, null, null, null, null);
c.moveToFirst();
if (c.getString(0) != null) {
accountName = c.getString(0);
}
c.close();

return accountName;
public int getLocalTableBlogIdForRemoteBlogId(int remoteBlogId) {
return SqlUtils.intForQuery(db, "SELECT id FROM accounts WHERE blogId=?", new String[]{Integer.toString(remoteBlogId)});
}

/*
* nbradbury 11/14/13
*/
public int getAccountIdForBlogId(int blogId) {
return SqlUtils.intForQuery(db, "SELECT id FROM accounts WHERE blogId=?", new String[]{Integer.toString(blogId)});
}

public int getAccountIdForBlogIdAndXmlRpcUrl(int blogId, String xmlRpcUrl) {
public int getLocalTableBlogIdForRemoteBlogIdAndXmlRpcUrl(int remoteBlogId, String xmlRpcUrl) {
return SqlUtils.intForQuery(db, "SELECT id FROM accounts WHERE blogId=? AND url=?",
new String[]{Integer.toString(blogId), xmlRpcUrl});
new String[]{Integer.toString(remoteBlogId), xmlRpcUrl});
}

public void updateNotificationFlag(int id, boolean flag) {
Expand Down Expand Up @@ -946,17 +929,6 @@ public long savePost(Post post, int blogID) {
return (returnValue);
}

/**
* nbradbury 11/15/13 - get the title of a specific post
* @param accountId - - unique id in account table for this blog
* @param postId - id of the desired post
* @return title if exists, empty string otherwise
*/
public String getPostTitle(int accountId, String postId) {
String[] args = {Integer.toString(accountId), StringUtils.notNullStr(postId)};
return SqlUtils.stringForQuery(db, "SELECT TITLE FROM " + POSTS_TABLE + " WHERE blogID=? AND postid=?", args);
}

public int updatePost(Post post, int blogID) {
int success = 0;
if (post != null) {
Expand Down Expand Up @@ -1103,19 +1075,19 @@ public List<Object> loadPost(int blogID, boolean isPage, long id) {

/**
* nbradbury 11/15/13 - add a single comment
* @param accountId - unique id in account table for the blog the comment is from
* @param localBlogId - unique id in account table for the blog the comment is from
* @param comment - comment object to store
*/
public void addComment(int accountId, Comment comment) {
public void addComment(int localBlogId, Comment comment) {
if (comment == null)
return;

// first delete existing comment (necessary since there's no primary key or indexes
// on this table, which means we can't rely on using CONFLICT_REPLACE below)
deleteComment(accountId, comment.commentID);
deleteComment(localBlogId, comment.commentID);

ContentValues values = new ContentValues();
values.put("blogID", accountId);
values.put("blogID", localBlogId);
values.put("postID", StringUtils.notNullStr(comment.postID));
values.put("iCommentID", comment.commentID);
values.put("author", StringUtils.notNullStr(comment.name));
Expand All @@ -1132,11 +1104,11 @@ public void addComment(int accountId, Comment comment) {

/**
* nbradbury 11/11/13 - retrieve a single comment
* @param accountId - unique id in account table for the blog the comment is from
* @param localBlogId - unique id in account table for the blog the comment is from
* @param commentId - commentId of the actual comment
* @return Comment if found, null otherwise
*/
public Comment getComment(int accountId, int commentId) {
public Comment getComment(int localBlogId, int commentId) {
String[] cols = {"author",
"comment",
"commentDateFormatted",
Expand All @@ -1145,7 +1117,7 @@ public Comment getComment(int accountId, int commentId) {
"email",
"postTitle",
"postID"};
String[] args = {Integer.toString(accountId),
String[] args = {Integer.toString(localBlogId),
Integer.toString(commentId)};
Cursor c = db.query(COMMENTS_TABLE,
cols,
Expand Down Expand Up @@ -1180,12 +1152,12 @@ public Comment getComment(int accountId, int commentId) {

/**
* nbradbury 11/12/13 - delete a single comment
* @param accountId - unique id in account table for this blog
* @param localBlogId - unique id in account table for this blog
* @param commentId - commentId of the actual comment
* @return true if comment deleted, false otherwise
*/
public boolean deleteComment(int accountId, int commentId) {
String[] args = {Integer.toString(accountId),
public boolean deleteComment(int localBlogId, int commentId) {
String[] args = {Integer.toString(localBlogId),
Integer.toString(commentId)};
int count = db.delete(COMMENTS_TABLE, "blogID=? AND iCommentID=?", args);
return (count > 0);
Expand Down
32 changes: 16 additions & 16 deletions src/org/wordpress/android/models/Blog.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import java.util.Map;

public class Blog {
private int id;
private int localTableBlogId;
private String url;
private String homeURL;
private String blogName;
Expand All @@ -33,7 +33,7 @@ public class Blog {
private int maxImageWidthId;
private int lastCommentId;
private boolean runService;
private int blogId;
private int remoteBlogId;
private boolean location;
private String dotcom_username;
private String dotcom_password;
Expand All @@ -52,15 +52,15 @@ public Blog(String url, String username, String password) {
this.url = url;
this.username = username;
this.password = password;
this.id = -1;
this.localTableBlogId = -1;
}

public Blog(int blog_id) throws Exception {
// Instantiate an existing blog
List<Object> blogVals = WordPress.wpDB.getBlog(blog_id);

if (blogVals != null) {
this.id = blog_id;
this.localTableBlogId = blog_id;
this.url = blogVals.get(0).toString();
this.blogName = blogVals.get(1).toString();
this.username = blogVals.get(2).toString();
Expand All @@ -73,7 +73,7 @@ public Blog(int blog_id) throws Exception {
this.maxImageWidth = blogVals.get(9).toString();
this.maxImageWidthId = (Integer) blogVals.get(10);
this.runService = (Integer)blogVals.get(11)>0;
this.blogId = (Integer) blogVals.get(12);
this.remoteBlogId = (Integer) blogVals.get(12);
this.location = (Integer)blogVals.get(13)>0;
this.dotcomFlag = (Integer)blogVals.get(14)>0;
//these were accidentally set up to contain null values :(
Expand Down Expand Up @@ -107,12 +107,12 @@ public Blog(int blog_id) throws Exception {
}
}

public int getId() {
return id;
public int getLocalTableBlogId() {
return localTableBlogId;
}

public void setId(int id) {
this.id = id;
public void setLocalTableBlogId(int id) {
this.localTableBlogId = id;
}

public String getUrl() {
Expand Down Expand Up @@ -219,12 +219,12 @@ public void setRunService(boolean runService) {
this.runService = runService;
}

public int getBlogId() {
return blogId;
public int getRemoteBlogId() {
return remoteBlogId;
}

public void setBlogId(int blogId) {
this.blogId = blogId;
public void setRemoteBlogId(int blogId) {
this.remoteBlogId = blogId;
}

public boolean isLocation() {
Expand Down Expand Up @@ -317,7 +317,7 @@ public void setHidden(boolean isHidden) {

public boolean save() {
// Insert new blog to db
if (this.id == -1) {
if (this.localTableBlogId == -1) {
return WordPress.wpDB.addBlog(this);
} else {
return WordPress.wpDB.saveBlog(this);
Expand All @@ -341,7 +341,7 @@ public boolean bsetPostFormats(String postFormats) {
}

public int getUnmoderatedCommentCount() {
return WordPress.wpDB.getUnmoderatedCommentCount(this.id);
return WordPress.wpDB.getUnmoderatedCommentCount(this.localTableBlogId);
}

public boolean isScaledImage() {
Expand Down Expand Up @@ -463,7 +463,7 @@ public boolean hasValidJetpackCredentials() {
*/
public String getDotComBlogId() {
if (isDotcomFlag())
return String.valueOf(getBlogId());
return String.valueOf(getRemoteBlogId());
else
return getApi_blogid();
}
Expand Down
2 changes: 1 addition & 1 deletion src/org/wordpress/android/models/Theme.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public static Theme fromJSON(JSONObject object) throws JSONException {

// if the theme is free, set the blogId to be empty
// if the theme is not free, set the blogId to the current blog
String blogId = String.valueOf(WordPress.getCurrentBlog().getBlogId());
String blogId = String.valueOf(WordPress.getCurrentBlog().getRemoteBlogId());

String features = "";
JSONArray tags = object.getJSONArray("tags");
Expand Down
6 changes: 3 additions & 3 deletions src/org/wordpress/android/ui/ShareIntentReceiverActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ private boolean selectBlog(int blogId) {
if (WordPress.currentBlog.isHidden()) {
return false;
}
WordPress.wpDB.updateLastBlogId(WordPress.currentBlog.getId());
WordPress.wpDB.updateLastBlogId(WordPress.currentBlog.getLocalTableBlogId());
return true;
}

Expand Down Expand Up @@ -279,9 +279,9 @@ private void savePreferences() {
SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(this)
.edit();
if (isSharingText()) {
editor.putInt(SHARE_TEXT_BLOG_ID_KEY, WordPress.currentBlog.getId());
editor.putInt(SHARE_TEXT_BLOG_ID_KEY, WordPress.currentBlog.getLocalTableBlogId());
} else {
editor.putInt(SHARE_IMAGE_BLOG_ID_KEY, WordPress.currentBlog.getId());
editor.putInt(SHARE_IMAGE_BLOG_ID_KEY, WordPress.currentBlog.getLocalTableBlogId());
editor.putInt(SHARE_IMAGE_ADDTO_KEY, mActionIndex); // Add to new post or media
}
editor.commit();
Expand Down
10 changes: 5 additions & 5 deletions src/org/wordpress/android/ui/WPActionBarActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ protected void refreshMenuDrawer(){

if (currentBlog != null && mListView != null && mListView.getHeaderViewsCount() > 0) {
for (int i = 0; i < blogIDs.length; i++) {
if (blogIDs[i] == currentBlog.getId()) {
if (blogIDs[i] == currentBlog.getLocalTableBlogId()) {
if (mBlogSpinner != null) {
mBlogSpinner.setSelection(i);
}
Expand Down Expand Up @@ -622,7 +622,7 @@ public void onClick(DialogInterface dialog,
* This method is called when the user changes the active blog.
*/
public void onBlogChanged() {
WordPress.wpDB.updateLastBlogId(WordPress.currentBlog.getId());
WordPress.wpDB.updateLastBlogId(WordPress.currentBlog.getLocalTableBlogId());
// the menu may have changed, we need to change the selection if the selected item
// is not available in the menu anymore
Iterator<MenuDrawerItem> itemIterator = mMenuItems.iterator();
Expand Down Expand Up @@ -781,7 +781,7 @@ public void onSelectItem(){
if (!(WPActionBarActivity.this instanceof PagesActivity))
mShouldFinish = true;
Intent intent = new Intent(WPActionBarActivity.this, PagesActivity.class);
intent.putExtra("id", WordPress.currentBlog.getId());
intent.putExtra("id", WordPress.currentBlog.getLocalTableBlogId());
intent.putExtra("isNew", true);
intent.putExtra("viewPages", true);
intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
Expand All @@ -806,7 +806,7 @@ public void onSelectItem(){
if (!(WPActionBarActivity.this instanceof CommentsActivity))
mShouldFinish = true;
Intent intent = new Intent(WPActionBarActivity.this, CommentsActivity.class);
intent.putExtra("id", WordPress.currentBlog.getId());
intent.putExtra("id", WordPress.currentBlog.getLocalTableBlogId());
intent.putExtra("isNew",
true);
intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
Expand Down Expand Up @@ -872,7 +872,7 @@ public void onSelectItem(){
mShouldFinish = true;

Intent intent = new Intent(WPActionBarActivity.this, StatsActivity.class);
intent.putExtra("id", WordPress.currentBlog.getId());
intent.putExtra("id", WordPress.currentBlog.getLocalTableBlogId());
intent.putExtra("isNew", true);
intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivityWithDelay(intent);
Expand Down
8 changes: 4 additions & 4 deletions src/org/wordpress/android/ui/accounts/SetupBlog.java
Original file line number Diff line number Diff line change
Expand Up @@ -225,23 +225,23 @@ public Blog addBlog(String blogName, String xmlRpcUrl, String homeUrl, String bl
blog.setMaxImageWidth(DEFAULT_IMAGE_SIZE);
blog.setMaxImageWidthId(0); //deprecated
blog.setRunService(false); //deprecated
blog.setBlogId(Integer.parseInt(blogId));
blog.setRemoteBlogId(Integer.parseInt(blogId));
blog.setDotcomFlag(xmlRpcUrl.contains("wordpress.com"));
blog.setWpVersion(""); // assigned later in getOptions call
blog.setAdmin(isAdmin);
blog.save();
} else {
// Update blog name
int accountId = WordPress.wpDB.getAccountIdForBlogIdAndXmlRpcUrl(
int localTableBlogId = WordPress.wpDB.getLocalTableBlogIdForRemoteBlogIdAndXmlRpcUrl(
Integer.parseInt(blogId), xmlRpcUrl);
try {
blog = new Blog(accountId);
blog = new Blog(localTableBlogId);
if (!blogName.equals(blog.getBlogName())) {
blog.setBlogName(blogName);
blog.save();
}
} catch (Exception e) {
Log.e(WordPress.TAG, "accountId: " + accountId + " not found");
Log.e(WordPress.TAG, "localTableBlogId: " + localTableBlogId + " not found");
}
}
return blog;
Expand Down
Loading