[go: nahoru, domu]

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 Swipe feature with onPostSwipeListener in Posts Activity and bug Fix #456 #12

Closed
wants to merge 5 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
3 changes: 2 additions & 1 deletion res/layout/viewpost.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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">

<LinearLayout
android:id="@+id/postBar"
Expand Down
2 changes: 2 additions & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@
<string name="delete">Delete</string>
<string name="approve">Approve</string>
<string name="unapprove">Unapprove</string>
<string name="confirm_delete">Confirm Deletion</string>
<string name="confirm_delete_data">Are you sure you want to delete this comment?</string>

<!-- new account view -->
<string name="account_setup">Account Setup</string>
Expand Down
54 changes: 42 additions & 12 deletions src/org/wordpress/android/ui/comments/CommentsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
19 changes: 17 additions & 2 deletions src/org/wordpress/android/ui/posts/PostsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,15 @@
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;
import org.wordpress.android.ui.reader.ReaderActivity;
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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -839,4 +854,4 @@ public void onBlogChanged() {
postList.loadPosts(false);
new ApiHelper.RefreshBlogContentTask(this, WordPress.currentBlog).execute(false);
}
}
}
70 changes: 67 additions & 3 deletions src/org/wordpress/android/ui/posts/ViewPostFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -129,25 +135,53 @@ public void onAttach(Activity activity) {
try {
// check that the containing activity implements our callback
activity;
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(
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -209,5 +271,7 @@ public void onSaveInstanceState(Bundle outState) {
}
super.onSaveInstanceState(outState);
}



}
}
37 changes: 35 additions & 2 deletions src/org/wordpress/android/ui/posts/ViewPostsFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}

}

}