[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
Next Next commit
added onPostSwipe listener
  • Loading branch information
aagam-shah committed May 14, 2013
commit 2d94200e571a0f3426b32b9df9d2c213795759ba
14 changes: 13 additions & 1 deletion 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,17 @@ public void onPostSelected(Post post) {
}
}

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

}

@Override
public void onRefresh(boolean start) {
if (start) {
Expand Down
37 changes: 12 additions & 25 deletions src/org/wordpress/android/ui/posts/ViewPostFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,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 @@ -134,6 +135,7 @@ 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()
Expand All @@ -148,42 +150,21 @@ 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
swipePost(1); //Pass 1 for nextpost
onPostSwipeListener.onPostSwipe(1, WordPress.currentPost); //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
onPostSwipeListener.onPostSwipe(0, WordPress.currentPost); //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;

Expand Down Expand Up @@ -263,6 +244,10 @@ public boolean onTouch(View v, MotionEvent event) {
public interface OnDetailPostActionListener {
public void onDetailPostAction(int action, Post post);
}

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

public void clearContent() {
TextView title = (TextView) getActivity().findViewById(R.id.postTitle);
Expand All @@ -284,5 +269,7 @@ public void onSaveInstanceState(Bundle outState) {
}
super.onSaveInstanceState(outState);
}



}
57 changes: 35 additions & 22 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 All @@ -45,7 +46,7 @@

public class ViewPostsFragment extends ListFragment {
/** Called when the activity is first created. */
private static String[] mPostIDs, mTitles, mDateCreated, mDateCreatedFormatted,
private String[] mPostIDs, mTitles, mDateCreated, mDateCreatedFormatted,
mDraftIDs, mDraftTitles, mDraftDateCreated, mStatuses, mDraftStatuses;
private int[] mUploaded;
private int mRowID = 0;
Expand All @@ -66,27 +67,6 @@ public class ViewPostsFragment extends ListFragment {
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) {
super.onCreate(icicle);
Expand Down Expand Up @@ -736,4 +716,37 @@ 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();
}

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);
}

}

public void loadPrevPost(){
Post post;
if(curr_position-1<0){
Toast.makeText(getActivity(), "Reached first post", Toast.LENGTH_SHORT).show();
}
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);
}

}

}