[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 1 commit
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
Prev Previous commit
added onPostSwipe Listener
  • Loading branch information
aagam-shah committed May 15, 2013
commit b1daf2d19fa55dcdb14297daa786ad094cefbd31
13 changes: 8 additions & 5 deletions src/org/wordpress/android/ui/posts/PostsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -358,14 +358,17 @@ public void onPostSelected(Post post) {
}

@Override
public void onPostSwipe(int action, Post post){
public Post onPostSwipe(int action){
Post p;
if(action==1){
postList.loadNextPost();
p = postList.loadNextPost();

}
else{
postList.loadPrevPost();
p=postList.loadPrevPost();

}

return p;
}

@Override
Expand Down Expand Up @@ -851,4 +854,4 @@ public void onBlogChanged() {
postList.loadPosts(false);
new ApiHelper.RefreshBlogContentTask(this, WordPress.currentBlog).execute(false);
}
}
}
46 changes: 24 additions & 22 deletions src/org/wordpress/android/ui/posts/ViewPostFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,21 +150,23 @@ private class GestureListener extends GestureDetector.SimpleOnGestureListener {

@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
onPostSwipeListener.onPostSwipe(1, WordPress.currentPost);
if(e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
// Right to left
onPostSwipeListener.onPostSwipe(1, WordPress.currentPost); //Pass 1 for nextpost
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
onPostSwipeListener.onPostSwipe(0, WordPress.currentPost); //Pass 0 for prevpost
return true;
Post p = onPostSwipeListener.onPostSwipe(0);
loadPost(p); //Pass 0 for prevpost
return true;
}

return false;
return false;
}
}
}


public GestureDetector gesturedetector;

Expand All @@ -173,13 +175,13 @@ 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());
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);
RelativeLayout layout = (RelativeLayout)getActivity().findViewById(R.id.postHead);
WebView webView = (WebView) getActivity().findViewById(
R.id.viewPostWebView);
TextView tv = (TextView) getActivity().findViewById(
Expand All @@ -192,12 +194,12 @@ public void loadPost(Post post) {
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;
}
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
gesturedetector.onTouchEvent(event);
return true;
}


});
Expand All @@ -206,14 +208,14 @@ public boolean onTouch(View v, MotionEvent event) {
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
gesturedetector.onTouchEvent(event);
return true;
}
gesturedetector.onTouchEvent(event);
return true;
}


});


});



tv.setVisibility(View.GONE);
webView.setVisibility(View.VISIBLE);
Expand Down Expand Up @@ -246,7 +248,7 @@ public interface OnDetailPostActionListener {
}

public interface OnPostSwipeListener {
public void onPostSwipe(int action, Post post);
public Post onPostSwipe(int action);
}

public void clearContent() {
Expand All @@ -272,4 +274,4 @@ public void onSaveInstanceState(Bundle outState) {



}
}
43 changes: 20 additions & 23 deletions src/org/wordpress/android/ui/posts/ViewPostsFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public class ViewPostsFragment extends ListFragment {
public int numRecords = 20;
public ViewSwitcher switcher;
public getRecentPostsTask getPostsTask;
public static int curr_position=0;
public int curr_position=0;

@Override
public void onCreate(Bundle icicle) {
Expand Down Expand Up @@ -716,37 +716,34 @@ public interface OnPostActionListener {
public void onPostAction(int action, Post post);
}

public void loadNextPost() {
// TODO Auto-generated method stub
Post post;
if(curr_position+1>=mPostIDs.length)
{
Toast.makeText(getActivity(), "Reached the end of the posts loaded", Toast.LENGTH_SHORT).show();
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=curr_position+1;
int nextid= Integer.parseInt(mPostIDs[curr_position]);
long newid=(long)nextid;
post = new Post(WordPress.currentBlog.getId(),newid, false);
mOnPostSelectedListener.onPostSelected(post);
curr_position++;
long nextid= Integer.parseInt(mPostIDs[curr_position]);
Post post = new Post(WordPress.currentBlog.getId(),nextid, isPage);
WordPress.currentPost=post;
return post;
}

}

public void loadPrevPost(){
Post post;
public Post loadPrevPost(){
if(curr_position-1<0){
Toast.makeText(getActivity(), "Reached first post", Toast.LENGTH_SHORT).show();
Toast.makeText(getActivity(), "Reached first Post", Toast.LENGTH_SHORT).show();
return WordPress.currentPost;
}
else{
curr_position=curr_position-1;
int nextid= Integer.parseInt(mPostIDs[curr_position]);
long newid=(long)nextid;
post = new Post(WordPress.currentBlog.getId(),newid, false);
mOnPostSelectedListener.onPostSelected(post);
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;
}

}

}
}