Skip to content
Closed
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
21 changes: 21 additions & 0 deletions src/org/wordpress/android/models/Post.java
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,27 @@ public String getQuickPostType() {
return quickPostType;
}

/**
* Checks if this post currently has data differing from another post.
*
* @param otherPost The post to compare to this post's editable data.
* @return True if this post's data differs from otherPost's data, False otherwise.
*/
public boolean hasChanges(Post otherPost) {
return(!(this.title.equals(otherPost.title) &&
this.description.equals(otherPost.description) &&
this.mt_excerpt.equals(otherPost.mt_excerpt) &&
this.date_created_gmt == otherPost.date_created_gmt &&
this.categories.equals(otherPost.categories) &&
this.mt_keywords.equals(otherPost.mt_keywords) &&
this.post_status.equals(otherPost.post_status) &&
this.wp_password.equals(otherPost.wp_password) &&
this.wp_post_format.equals(otherPost.wp_post_format) &&
this.latitude == otherPost.latitude &&
this.longitude == otherPost.longitude)
);
}

@Override
public int hashCode() {
final int prime = 31;
Expand Down
12 changes: 12 additions & 0 deletions src/org/wordpress/android/ui/posts/EditPostActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,18 @@ private void showCancelAlert(final boolean isUpPress) {
return;
}

// Save the current Post
savePost(false, true);

// Compare the current Post to the original and if no changes have been made,
// set the Post back to the original and go back to the previous view
if (mOriginalPost != null && !mPost.hasChanges(mOriginalPost)) {
mOriginalPost.update();
WordPress.currentPost = mOriginalPost;
finish();
return;
}

AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(EditPostActivity.this);
dialogBuilder.setTitle(getString((mIsPage) ? R.string.edit_page : R.string.edit_post));
dialogBuilder.setMessage(getString(R.string.prompt_save_changes));
Expand Down