diff --git a/res/layout/edit.xml b/res/layout/edit.xml index 4a5ca068f585..4b49875977b4 100644 --- a/res/layout/edit.xml +++ b/res/layout/edit.xml @@ -31,17 +31,29 @@ android:layout_marginTop="4dp" android:hint="@string/title" android:inputType="textCapSentences|textAutoCorrect" /> - - + + Title Tap to add text and media + Post excerpt Are you sure you want to cancel editing this page? diff --git a/src/org/wordpress/android/WordPressDB.java b/src/org/wordpress/android/WordPressDB.java index 0c05451f2796..6f0871285e3c 100644 --- a/src/org/wordpress/android/WordPressDB.java +++ b/src/org/wordpress/android/WordPressDB.java @@ -1274,6 +1274,7 @@ public long savePost(Post post, int blogID) { values.put("latitude", post.getLatitude()); values.put("longitude", post.getLongitude()); values.put("isLocalChange", post.isLocalChange()); + values.put("mt_excerpt", post.getMt_excerpt()); returnValue = db.insert(POSTS_TABLE, null, values); @@ -1312,6 +1313,7 @@ public int updatePost(Post post, int blogID) { values.put("isPage", post.isPage()); values.put("wp_post_format", post.getWP_post_format()); values.put("isLocalChange", post.isLocalChange()); + values.put("mt_excerpt", post.getMt_excerpt()); int pageInt = 0; if (post.isPage()) diff --git a/src/org/wordpress/android/models/Post.java b/src/org/wordpress/android/models/Post.java index 71f058f652ba..1069aae8da00 100644 --- a/src/org/wordpress/android/models/Post.java +++ b/src/org/wordpress/android/models/Post.java @@ -121,6 +121,34 @@ public Post(int blog_id, String title, String content, String picturePaths, long this.longitude = longitude; this.isLocalChange = isLocalChange; } + + public Post(int blog_id, String title, String content, String excerpt, String picturePaths, long date, String categories, String tags, String status, + String password, double latitude, double longitude, boolean isPage, String postFormat, + boolean createBlogReference, boolean isLocalChange) { + // create a new post + if (createBlogReference) { + try { + this.blog = new Blog(blog_id); + } catch (Exception e) { + e.printStackTrace(); + } + } + this.blogID = blog_id; + this.title = title; + this.description = content; + this.mt_excerpt = excerpt; + this.mediaPaths = picturePaths; + this.date_created_gmt = date; + this.categories = categories; + this.mt_keywords = tags; + this.post_status = status; + this.wp_password = password; + this.isPage = isPage; + this.wp_post_format = postFormat; + this.latitude = latitude; + this.longitude = longitude; + this.isLocalChange = isLocalChange; + } public long getId() { return id; diff --git a/src/org/wordpress/android/ui/posts/EditPostActivity.java b/src/org/wordpress/android/ui/posts/EditPostActivity.java index 6ee2ccb277e7..4b5e4b3834d6 100644 --- a/src/org/wordpress/android/ui/posts/EditPostActivity.java +++ b/src/org/wordpress/android/ui/posts/EditPostActivity.java @@ -46,14 +46,34 @@ import android.text.style.StrikethroughSpan; import android.text.style.StyleSpan; import android.text.style.URLSpan; -import android.view.*; +import android.view.ContextMenu; +import android.view.Display; +import android.view.LayoutInflater; +import android.view.MenuItem; +import android.view.MotionEvent; +import android.view.View; import android.view.View.OnClickListener; import android.view.View.OnFocusChangeListener; import android.view.View.OnTouchListener; +import android.view.ViewGroup; +import android.view.WindowManager; import android.view.animation.AlphaAnimation; -import android.widget.*; +import android.widget.ArrayAdapter; +import android.widget.Button; +import android.widget.CheckBox; +import android.widget.CompoundButton; import android.widget.CompoundButton.OnCheckedChangeListener; +import android.widget.DatePicker; +import android.widget.EditText; +import android.widget.ImageButton; +import android.widget.RelativeLayout; +import android.widget.SeekBar; import android.widget.SeekBar.OnSeekBarChangeListener; +import android.widget.Spinner; +import android.widget.TextView; +import android.widget.TimePicker; +import android.widget.Toast; +import android.widget.ToggleButton; import com.actionbarsherlock.app.ActionBar; import com.actionbarsherlock.app.SherlockActivity; @@ -62,7 +82,6 @@ import com.google.gson.reflect.TypeToken; import org.json.JSONArray; -import org.wordpress.android.util.*; import org.xmlrpc.android.ApiHelper; import org.wordpress.android.Constants; @@ -72,7 +91,18 @@ import org.wordpress.android.models.MediaFile; import org.wordpress.android.models.Post; import org.wordpress.android.ui.accounts.NewAccountActivity; +import org.wordpress.android.util.DeviceUtils; +import org.wordpress.android.util.EscapeUtils; +import org.wordpress.android.util.ImageHelper; +import org.wordpress.android.util.JSONUtil; +import org.wordpress.android.util.LocationHelper; import org.wordpress.android.util.LocationHelper.LocationResult; +import org.wordpress.android.util.PostUploadService; +import org.wordpress.android.util.StringUtils; +import org.wordpress.android.util.WPEditText; +import org.wordpress.android.util.WPHtml; +import org.wordpress.android.util.WPImageSpan; +import org.wordpress.android.util.WPUnderlineSpan; public class EditPostActivity extends SherlockActivity implements OnClickListener, OnTouchListener, TextWatcher, WPEditText.OnSelectionChangedListener, OnFocusChangeListener, WPEditText.EditTextImeBackListener { @@ -98,7 +128,7 @@ public class EditPostActivity extends SherlockActivity implements OnClickListene private WPEditText mContentEditText; private ImageButton mAddPictureButton; private Spinner mStatusSpinner; - private EditText mTitleEditText, mPasswordEditText, mTagsEditText; + private EditText mTitleEditText, mPasswordEditText, mTagsEditText, mExcerptEditText; private TextView mLocationText, mPubDateText; private ToggleButton mBoldToggleButton, mEmToggleButton, mBquoteToggleButton; private ToggleButton mUnderlineToggleButton, mStrikeToggleButton; @@ -224,6 +254,7 @@ public void onCreate(Bundle savedInstanceState) { setContentView(R.layout.edit); mContentEditText = (WPEditText) findViewById(R.id.postContent); mTitleEditText = (EditText) findViewById(R.id.title); + mExcerptEditText= (EditText) findViewById(R.id.postExcerpt); mPasswordEditText = (EditText) findViewById(R.id.post_password); mLocationText = (TextView) findViewById(R.id.locationText); mBoldToggleButton = (ToggleButton) findViewById(R.id.bold); @@ -327,6 +358,7 @@ else if (mQuickMediaType == Constants.QUICK_POST_VIDEO_LIBRARY) } } else { mTitleEditText.setText(mPost.getTitle()); + mExcerptEditText.setText(mPost.getMt_excerpt()); if (mPost.isUploaded()) { items = new String[] { @@ -1394,7 +1426,12 @@ private boolean savePost(boolean isAutoSave, boolean isDraftSave) { String title = mTitleEditText.getText().toString(); String password = mPasswordEditText.getText().toString(); String pubDate = mPubDateText.getText().toString(); + String excerpt = mExcerptEditText.getText().toString(); String content = ""; + + if(excerpt.matches("")){ + excerpt=""; + } if (mLocalDraft || mIsNew && !isAutoSave) { Editable e = mContentEditText.getText(); @@ -1521,7 +1558,7 @@ public void onClick(DialogInterface dialog, int whichButton) { } if (mIsNew) { - mPost = new Post(mBlogID, title, content, images, pubDateTimestamp, mCategories.toString(), tags, status, password, + mPost = new Post(mBlogID, title, content, excerpt, images, pubDateTimestamp, mCategories.toString(), tags, status, password, latitude, longitude, mIsPage, postFormat, true, false); mPost.setLocalDraft(true); @@ -1575,6 +1612,7 @@ public void onClick(DialogInterface dialog, int whichButton) { } mPost.setTitle(title); + mPost.setMt_excerpt(excerpt); // split up the post content if there's a more tag if (mLocalDraft && content.indexOf(moreTag) >= 0) { mPost.setDescription(content.substring(0, content.indexOf(moreTag))); @@ -1592,6 +1630,7 @@ public void onClick(DialogInterface dialog, int whichButton) { mPost.setLatitude(latitude); mPost.setLongitude(longitude); mPost.setWP_post_form(postFormat); + if (!mPost.isLocalDraft()) mPost.setLocalChange(true); success = mPost.update(); @@ -1638,6 +1677,7 @@ protected void setContent() { Intent intent = getIntent(); String text = intent.getStringExtra(Intent.EXTRA_TEXT); String title = intent.getStringExtra(Intent.EXTRA_SUBJECT); + if (text != null) { if (title != null) {