Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added add/edit Post excerpt #22

Closed
wants to merge 4 commits into from
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
18 changes: 15 additions & 3 deletions res/layout/edit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,29 @@
android:layout_marginTop="4dp"
android:hint="@string/title"
android:inputType="textCapSentences|textAutoCorrect" />

<org.wordpress.android.util.WPEditText
<org.wordpress.android.util.WPEditText
android:id="@+id/postContent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/content_edit_padding"
android:layout_marginTop="8dp"
android:gravity="top"
android:hint="@string/post_content"
android:inputType="textMultiLine|textCapSentences|textAutoCorrect"
android:minLines="@integer/content_editor_min_lines"
android:textColorLink="#21759b" />
<EditText
android:id="@+id/postExcerpt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/content_edit_padding"
android:layout_marginTop="8dp"
android:gravity="top"
android:hint="@string/post_excerpt"
android:inputType="textCapSentences|textAutoCorrect"
android:minLines="1"
android:textColorLink="#21759b" />

</LinearLayout>

<LinearLayout
Expand Down
1 change: 1 addition & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
<!-- page view -->
<string name="title">Title</string>
<string name="content">Tap to add text and media</string>
<string name="post_excerpt">Post excerpt</string>
<string name="sure_to_cancel_edit_page">Are you sure you want to cancel editing this page?</string>

<!-- posts tab -->
Expand Down
2 changes: 2 additions & 0 deletions src/org/wordpress/android/WordPressDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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())
Expand Down
28 changes: 28 additions & 0 deletions src/org/wordpress/android/models/Post.java
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
Expand Down
50 changes: 45 additions & 5 deletions src/org/wordpress/android/ui/posts/EditPostActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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 {
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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[] {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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)));
Expand All @@ -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();
Expand Down Expand Up @@ -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) {
Expand Down