[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
Next Next commit
added swipe featured and bug fix #456
  • Loading branch information
aagam-shah committed May 14, 2013
commit 2c64848fc6ad6db317980746bceb00adce8fd304
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 to delete the 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
79 changes: 77 additions & 2 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 Down Expand Up @@ -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(
Expand All @@ -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);
Expand Down
25 changes: 24 additions & 1 deletion src/org/wordpress/android/ui/posts/ViewPostsFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down