diff --git a/res/layout/viewpost.xml b/res/layout/viewpost.xml index 847e200f8575..fdd981e47afa 100644 --- a/res/layout/viewpost.xml +++ b/res/layout/viewpost.xml @@ -3,7 +3,8 @@ android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" - android:background="#FFFFFF" > + android:background="#FFFFFF" + android:id="@+id/postHead"> Delete Approve Unapprove + Confirm Deletion + Are you sure you want to delete this comment? Account Setup diff --git a/src/org/wordpress/android/ui/comments/CommentsActivity.java b/src/org/wordpress/android/ui/comments/CommentsActivity.java index 4fcf7bf66fbb..f7eb95bd970a 100644 --- a/src/org/wordpress/android/ui/comments/CommentsActivity.java +++ b/src/org/wordpress/android/ui/comments/CommentsActivity.java @@ -212,20 +212,50 @@ public void run() { } }.start(); } else if (status.equals("delete")) { - showDialog(ID_DIALOG_DELETING); - // pop out of the detail view if on a smaller screen - FragmentManager fm = getSupportFragmentManager(); - CommentFragment f = (CommentFragment) fm - .findFragmentById(R.id.commentDetail); - if (f == null) { - fm.popBackStack(); - } - new Thread() { + + Thread action3 = new Thread() { public void run() { - deleteComment(commentID); + AlertDialog.Builder dialogBuilder = new AlertDialog.Builder( + CommentsActivity.this); + dialogBuilder.setTitle(getResources().getText( + R.string.confirm_delete)); + dialogBuilder.setMessage(getResources().getText(R.string.confirm_delete_data)); + dialogBuilder.setPositiveButton("Yes", + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, + int whichButton) { + showDialog(ID_DIALOG_DELETING); + // pop out of the detail view if on a smaller screen + FragmentManager fm = getSupportFragmentManager(); + CommentFragment f = (CommentFragment) fm + .findFragmentById(R.id.commentDetail); + if (f == null) { + fm.popBackStack(); + } + new Thread() { + public void run() { + deleteComment(commentID); + } + }.start(); + + + } + }); + dialogBuilder.setNegativeButton("No", + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, + int whichButton) { + //Don't delete Comment + } + }); + dialogBuilder.setCancelable(true); + if (!isFinishing()) { + dialogBuilder.create().show(); + } } - }.start(); - } else if (status.equals("reply")) { + }; + runOnUiThread(action3); + } else if (status.equals("reply")) { Intent i = new Intent(CommentsActivity.this, AddCommentActivity.class); i.putExtra("commentID", commentID); diff --git a/src/org/wordpress/android/ui/posts/ViewPostFragment.java b/src/org/wordpress/android/ui/posts/ViewPostFragment.java index aff01a3e11bb..30d8d95a3a14 100644 --- a/src/org/wordpress/android/ui/posts/ViewPostFragment.java +++ b/src/org/wordpress/android/ui/posts/ViewPostFragment.java @@ -4,11 +4,16 @@ import android.content.Intent; import android.os.Bundle; import android.support.v4.app.Fragment; +import android.view.GestureDetector; import android.view.LayoutInflater; +import android.view.MotionEvent; import android.view.View; +import android.view.View.OnTouchListener; import android.view.ViewGroup; import android.webkit.WebView; import android.widget.ImageButton; +import android.widget.RelativeLayout; +import android.widget.ScrollView; import android.widget.TextView; import org.wordpress.android.R; @@ -135,19 +140,65 @@ public void onAttach(Activity activity) { + " must implement Callback"); } } + + private class GestureListener extends GestureDetector.SimpleOnGestureListener { + + private final int SWIPE_MIN_DISTANCE = 50; + private final int SWIPE_THRESHOLD_VELOCITY = 60; + + @Override + public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { + if(e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) { + // Right to left + swipePost(1); //Pass 1 for nextpost + return true; + } + else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) { + // Left to right + swipePost(0); //Pass 0 for prevpost + return true; + } + + return false; + } + } + + + public void swipePost(int motionEvent){ + ViewPostsFragment vpf = new ViewPostsFragment(); + String prevpostid,nextpostid; + long newid; + + if(motionEvent==0){ + prevpostid = vpf.getprevID(); + int previd= Integer.parseInt(prevpostid); + newid = (long)previd; + } + else{ + nextpostid = vpf.getnextID(); + int nextid= Integer.parseInt(nextpostid); + newid=(long)nextid; + } + Post post = new Post(WordPress.currentBlog.getId(),newid + , false); + loadPost(post); + } + + + public GestureDetector gesturedetector; public void loadPost(Post post) { // Don't load if the Post object of title are null, see #395 if (post == null || post.getTitle() == null) return; - + gesturedetector = new GestureDetector(new GestureListener()); TextView title = (TextView) getActivity().findViewById(R.id.postTitle); if (post.getTitle().equals("")) title.setText("(" + getResources().getText(R.string.untitled) + ")"); else title.setText(EscapeUtils.unescapeHtml(post.getTitle())); - + RelativeLayout layout = (RelativeLayout)getActivity().findViewById(R.id.postHead); WebView webView = (WebView) getActivity().findViewById( R.id.viewPostWebView); TextView tv = (TextView) getActivity().findViewById( @@ -158,6 +209,30 @@ public void loadPost(Post post) { R.id.viewPost); ImageButton addCommentButton = (ImageButton) getActivity().findViewById( R.id.addComment); + layout.setOnTouchListener(new OnTouchListener() { + + @Override + public boolean onTouch(View v, MotionEvent event) { + // TODO Auto-generated method stub + gesturedetector.onTouchEvent(event); + return true; + } + + + }); + webView.setOnTouchListener(new OnTouchListener() { + + @Override + public boolean onTouch(View v, MotionEvent event) { + // TODO Auto-generated method stub + gesturedetector.onTouchEvent(event); + return true; + } + + + }); + + tv.setVisibility(View.GONE); webView.setVisibility(View.VISIBLE); diff --git a/src/org/wordpress/android/ui/posts/ViewPostsFragment.java b/src/org/wordpress/android/ui/posts/ViewPostsFragment.java index e8c3be8da055..a9ab20f102ea 100644 --- a/src/org/wordpress/android/ui/posts/ViewPostsFragment.java +++ b/src/org/wordpress/android/ui/posts/ViewPostsFragment.java @@ -45,7 +45,7 @@ public class ViewPostsFragment extends ListFragment { /** Called when the activity is first created. */ - private String[] mPostIDs, mTitles, mDateCreated, mDateCreatedFormatted, + private static String[] mPostIDs, mTitles, mDateCreated, mDateCreatedFormatted, mDraftIDs, mDraftTitles, mDraftDateCreated, mStatuses, mDraftStatuses; private int[] mUploaded; private int mRowID = 0; @@ -64,6 +64,28 @@ public class ViewPostsFragment extends ListFragment { public int numRecords = 20; public ViewSwitcher switcher; public getRecentPostsTask getPostsTask; + public static int curr_position=0; + + public String getnextID(){ + if(curr_position+1>=mPostIDs.length) + return mPostIDs[curr_position]; + + else{ + curr_position=curr_position+1; + return mPostIDs[curr_position]; + } + } + + public String getprevID(){ + if(curr_position-1<0) + return mPostIDs[curr_position]; + + else{ + curr_position=curr_position-1; + return mPostIDs[curr_position]; + } + + } @Override public void onCreate(Bundle icicle) { @@ -273,6 +295,7 @@ public void onItemClick(AdapterView arg0, View v, .getId(), mSelectedID, isPage); if (post.getId() >= 0) { WordPress.currentPost = post; + curr_position=position; mOnPostSelectedListener.onPostSelected(post); mPostListAdapter.notifyDataSetChanged(); } else {