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/PostsActivity.java b/src/org/wordpress/android/ui/posts/PostsActivity.java index ce5d77332455..01b67a1eb731 100644 --- a/src/org/wordpress/android/ui/posts/PostsActivity.java +++ b/src/org/wordpress/android/ui/posts/PostsActivity.java @@ -39,6 +39,7 @@ import org.wordpress.android.ui.comments.AddCommentActivity; import org.wordpress.android.ui.comments.CommentsActivity; import org.wordpress.android.ui.posts.ViewPostFragment.OnDetailPostActionListener; +import org.wordpress.android.ui.posts.ViewPostFragment.OnPostSwipeListener; import org.wordpress.android.ui.posts.ViewPostsFragment.OnPostActionListener; import org.wordpress.android.ui.posts.ViewPostsFragment.OnPostSelectedListener; import org.wordpress.android.ui.posts.ViewPostsFragment.OnRefreshListener; @@ -46,7 +47,7 @@ import org.wordpress.android.util.WPAlertDialogFragment.OnDialogConfirmListener; public class PostsActivity extends WPActionBarActivity implements OnPostSelectedListener, - OnRefreshListener, OnPostActionListener, OnDetailPostActionListener, OnDialogConfirmListener { + OnRefreshListener, OnPostActionListener, OnDetailPostActionListener, OnDialogConfirmListener, OnPostSwipeListener { private ViewPostsFragment postList; private int ID_DIALOG_DELETING = 1, ID_DIALOG_SHARE = 2, ID_DIALOG_COMMENT = 3; @@ -356,6 +357,20 @@ public void onPostSelected(Post post) { } } + @Override + public Post onPostSwipe(int action){ + Post p; + if(action==1){ + p = postList.loadNextPost(); + + } + else{ + p=postList.loadPrevPost(); + + } + return p; + } + @Override public void onRefresh(boolean start) { if (start) { @@ -839,4 +854,4 @@ public void onBlogChanged() { postList.loadPosts(false); new ApiHelper.RefreshBlogContentTask(this, WordPress.currentBlog).execute(false); } -} +} \ No newline at end of file diff --git a/src/org/wordpress/android/ui/posts/ViewPostFragment.java b/src/org/wordpress/android/ui/posts/ViewPostFragment.java index aff01a3e11bb..9b50096e3eca 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; @@ -21,6 +26,7 @@ public class ViewPostFragment extends Fragment { /** Called when the activity is first created. */ private OnDetailPostActionListener onDetailPostActionListener; + private OnPostSwipeListener onPostSwipeListener; PostsActivity parentActivity; @Override @@ -129,25 +135,53 @@ public void onAttach(Activity activity) { try { // check that the containing activity implements our callback onDetailPostActionListener = (OnDetailPostActionListener) activity; + onPostSwipeListener = (OnPostSwipeListener) activity; } catch (ClassCastException e) { activity.finish(); throw new ClassCastException(activity.toString() + " 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 + Post p= onPostSwipeListener.onPostSwipe(1); + loadPost(p); //Pass 1 for nextpost + return true; + } + else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) { + // Left to right + Post p = onPostSwipeListener.onPostSwipe(0); + loadPost(p); //Pass 0 for prevpost + return true; + } + + return false; + } + } + + + 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 +192,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); @@ -188,6 +246,10 @@ public void loadPost(Post post) { public interface OnDetailPostActionListener { public void onDetailPostAction(int action, Post post); } + + public interface OnPostSwipeListener { + public Post onPostSwipe(int action); + } public void clearContent() { TextView title = (TextView) getActivity().findViewById(R.id.postTitle); @@ -209,5 +271,7 @@ public void onSaveInstanceState(Bundle outState) { } super.onSaveInstanceState(outState); } + + -} +} \ No newline at end of file diff --git a/src/org/wordpress/android/ui/posts/ViewPostsFragment.java b/src/org/wordpress/android/ui/posts/ViewPostsFragment.java index e8c3be8da055..11a302829497 100644 --- a/src/org/wordpress/android/ui/posts/ViewPostsFragment.java +++ b/src/org/wordpress/android/ui/posts/ViewPostsFragment.java @@ -30,6 +30,7 @@ import android.widget.Button; import android.widget.ListView; import android.widget.TextView; +import android.widget.Toast; import android.widget.ViewSwitcher; import org.xmlrpc.android.XMLRPCClient; @@ -64,7 +65,8 @@ public class ViewPostsFragment extends ListFragment { public int numRecords = 20; public ViewSwitcher switcher; public getRecentPostsTask getPostsTask; - + public int curr_position=0; + @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); @@ -273,6 +275,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 { @@ -713,4 +716,34 @@ public interface OnPostActionListener { public void onPostAction(int action, Post post); } -} + public Post loadNextPost() { + if(curr_position+1>=mPostIDs.length){ + Toast.makeText(getActivity(), "Reached the end of the posts list", Toast.LENGTH_SHORT).show(); + return WordPress.currentPost; + } + else{ + curr_position++; + long nextid= Integer.parseInt(mPostIDs[curr_position]); + Post post = new Post(WordPress.currentBlog.getId(),nextid, isPage); + WordPress.currentPost=post; + return post; + } + + } + + public Post loadPrevPost(){ + if(curr_position-1<0){ + Toast.makeText(getActivity(), "Reached first Post", Toast.LENGTH_SHORT).show(); + return WordPress.currentPost; + } + else{ + curr_position--; + long prev_id= Integer.parseInt(mPostIDs[curr_position]); + Post post = new Post(WordPress.currentBlog.getId(),prev_id, isPage); + WordPress.currentPost=post; + return post; + } + + } + +} \ No newline at end of file