[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 in Posts Activity and bug fix #456 #9

Closed
wants to merge 3 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
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>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about "Are you sure you want to delete this comment?"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes will update that...


<!-- 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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of making these static, you could create a listener that works similarly to the 'onCommentStatusChangeListener' in ViewPostFragment.java. When the user swipes, you can call the listener which will tell the CommentsActivity to move to the next post.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have created methods getNextId/getPrevId which acts similiar to a listener

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but you shouldn't need to have those variables be static. The PostsActivity is the container for the two fragments. If one fragment wants to communicate a change, it should tell PostsActivity and it will communicate with the other fragment. I suggest you read up on http://developer.android.com/guide/components/fragments.html.

In this case you could change the getNextId to something like 'loadNextPost' which would tell the list fragment to load the next item in the list, which would select the next row and load the post in the ViewPostFragment.

Thanks for working on this. Fragments are kind of weird :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok..will update that
@roundhill - Have you ran the code and any improvement in that??

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