diff --git a/.classpath b/.classpath index ff3e5f766521..8a71707d9f30 100644 --- a/.classpath +++ b/.classpath @@ -8,8 +8,8 @@ + - diff --git a/project.properties b/project.properties index fef3618e9755..01e59565e057 100644 --- a/project.properties +++ b/project.properties @@ -16,5 +16,5 @@ split.density=false target=android-17 apk-configurations= android.library=false -android.library.reference.1=../ActionBarSherlock/library -android.library.reference.2=../../../Downloads/android-menudrawer-master/library +android.library.reference.1=../adt-bundle-linux-x86_64/android/java-libs/ActionBarSherlock +android.library.reference.2=../adt-bundle-linux-x86_64/android-menudrawer-master/library diff --git a/res/layout/viewpost.xml b/res/layout/viewpost.xml index 847e200f8575..28bdb384de43 100644 --- a/res/layout/viewpost.xml +++ b/res/layout/viewpost.xml @@ -1,5 +1,6 @@ Confirm Deletion +> Are you sure to delete the Comment ? diff --git a/res/values/strings.xml b/res/values/strings.xml index 42dcb36d41f6..d241ed95b541 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -391,5 +391,7 @@ Add media + Confirm Deletion + Are you sure to delete the Comment ? diff --git a/res/values/strings1.xml b/res/values/strings1.xml new file mode 100644 index 000000000000..42dcb36d41f6 --- /dev/null +++ b/res/values/strings1.xml @@ -0,0 +1,395 @@ + + + + + Required Fields + Required Field + Please fill in all of the fields before submitting. + Could not connect. Please enter the full path to xmlrpc.php on your site and try again. + No Blogs Found + No %s blogs were found for that account. + additional + Add All + Add Selected + Select Blogs + Enable blogs + No network available + There is no network available. Please connect to a network and try again. + + + Select Categories + Tags & Categories + Tags (separate tags with commas) + Content (tap to add text and media) + Don\'t yet have a blog? + Default image width + Password + Get a free blog at WordPress.com + Start blogging in seconds. + Add blog hosted at WordPress.com + Add self-hosted WordPress blog + Start a new blog at WordPress.com + Blogs + Account Details + Status + + + Comment Content + Anonymous + + + Post + Page + Posts + Pages + About + Username + Cancel + Save + Add + Selected categories: + Publish? + Add Blog + Play notification sound + Vibrate + Blink notification light + Are you sure you want to remove this blog? + Yes + No + Error + Could not remove blog. + Edit Page + Edit Post + Add Comment + Refreshing Categories + Attempting to refresh categories + Connection Error + A connection error has occurred. Please try again later. + Categories refreshed + Category refresh error + Incorrect username or password. + No Content Found + Please enter some post content or attach a media item. + Cancel Edit + Are you sure you want to cancel editing this post? + New Account + Upload and link to full image + Upload and link to scaled image + Please enter a valid scaled width value + Scaled image width + Load More + Load settings now? + Immediately + Uploading + Uploading media item # + Sorry, the media item could not be retrieved from the Gallery. + Refresh + Home + More + Sorry, an error occurred when attempting to access this blog. + Sorry, an error occurred when attempting to load the post. Please refresh your posts and try again. + + + Comments + Posts + Pages + Stats + + + + URL + Link Text (optional) + Create a Link + + + Title + Tap to add text and media + Are you sure you want to cancel editing this page? + + + Untitled + Local Draft + + Local Drafts + + + Post + Upload Failed + Password (optional) + Caption (optional) + Horizontal Alignment + Width + Use as featured image + Include image in post content + Device out of memory. + Could not find the media file for upload. Was it deleted or moved? + + + Page + + + Enter comment: + Send Comment + Write Comment + Required Field + Please enter something in the comment field. + Enter a reply: + Send Reply + Reply to Comment + Please enter something in the reply field. + + + Loading… + + + on + Approved + Unapproved + Spam + Moderating comment + Moderating comments + Replying to comment + Deleting comment + Deleting comments + Comment Moderated Successfully + Comments Moderated Successfully + Reply Added Successfully + Comment from + Edit Comment + + + Name + E-mail + URL + Update Comment + Saving Changes + Are you sure you want to cancel editing this comment? + The comment body is required. + + + Remove Blog + Blog Removed Successfully + + + Draft Actions + Edit Draft + Delete Draft + Are you sure you want to delete the draft + + + Page Actions + View Page + Delete Page + Page Deleted Successfully + Are you sure you want to delete the page + Attempting to delete page + + + Post Actions + View Post + Delete Post + Post Deleted Successfully + Comment Added Successfully + Attempting to post comment + Are you sure you want to delete the post + Attempting to delete post + Share Post + Share Page + Share Link + Attempting to fetch URL + Post status is not published + Page status is not published + View in Browser + Post signature + Add a signature to new posts + Posted from WordPress for Android + Posted from WordPress for BlackBerry + Preview + + + Comment Actions + Mark Approved + Mark Unapproved + Spam + Reply + Delete + Approve + Unapprove + + + Account Setup + Logging in… + Sorry, could not connect to the WordPress site. Please try again later. + + + Cancel Draft + + + Comment Notifications + Update interval + + + Select a photo from gallery + Take a new photo + Select a video from gallery + Take a new video + Media + + + Add New Category + Category Name + Category Slug (optional) + Category Description (optional) + Category Parent (optional): + None + Adding category failed. + Please check your settings and try again. + Category added successfully. + The Category Name field is required. + Adding Category + Attempting to add category + + + Select a Blog + No WordPress account found, please add an account and try again. + + + An error occurred while setting up the captured media. + Could not create temp file for media upload. Please make sure there is enough free space on your device. + + + SD Card Required + A mounted SD card is required to upload media. + + + Location + Geotag Posts + Location data not yet available, please wait. + View Map + Update + Unknown Location + Remove + + + Preferences + Open Source Licenses + + + Username and Password are required fields. + Need help? + Username + Password + Incorrect Login + Incorrect login, or blog is not linked to this WordPress.com account. + or site not found. + Sorry. There was an error trying to connect to your stats. Please try again. + + + ABC + link + U + + + Invalid blog URL + Please check that the blog URL entered is valid. + + + + Publish + Pending Review + Draft + Private + Published + Scheduled + + + Select blog for QuickPress shortcut + Shortcut name can\'t be empty + Set shortcut name + + + HTTP username + HTTP password + Settings + Optional Settings + HTTP Credentials (optional) + + + Publish + Edit + Post Format + Log In + + + Reader + Topics + + + + Aside + Audio + Chat + Gallery + Image + Link + Quote + Standard + Status + Video + + + + New Post + New Page + Quick Photo + Quick Video + Dashboard + View Site + View Admin + + + Alignment + + None + Left + Center + Right + + + + WordPress for Android + WordPress for BlackBerry + Publisher: Automattic, Inc + ©2013 Automattic, Inc + Version + Terms of Service + Privacy Policy + www.automattic.com + + + Local Changes + You\'ve made changes to an uploaded post that haven\'t been saved yet. Proceed with the refresh and overwrite local changes? + + OK + Image Settings + Blog URL + WordPress Blog + blogusername + Column 1 + Column 2 + + + Sorry, an error occurred while attempting to delete the %s. + Sorry, %s could not be refreshed at this time. Please try again later. + Sorry, an error occurred. Please try again later. + Sorry, an error occurred while attempting to moderate. Please try again later. + Sorry, an error occurred while editing the comment. Please try again later. + Sorry, an error occurred while uploading the %s. + An error occurred while uploading media + You have exceeded the login limit. Please ensure your login credentials are correct and try again in a few minutes. + So sorry, but an error occurred while attempting to create the app database. Please try reinstalling the app. + + + Add media + + diff --git a/src/org/wordpress/android/ui/comments/CommentsActivity.java b/src/org/wordpress/android/ui/comments/CommentsActivity.java index 4fcf7bf66fbb..f7eb95bd970a 100644 --- a/src/org/wordpress/android/ui/comments/CommentsActivity.java +++ b/src/org/wordpress/android/ui/comments/CommentsActivity.java @@ -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); diff --git a/src/org/wordpress/android/ui/comments/CommentsActivity1.java b/src/org/wordpress/android/ui/comments/CommentsActivity1.java new file mode 100644 index 000000000000..4fcf7bf66fbb --- /dev/null +++ b/src/org/wordpress/android/ui/comments/CommentsActivity1.java @@ -0,0 +1,550 @@ +package org.wordpress.android.ui.comments; + +import java.util.HashMap; +import java.util.Map; + +import android.app.AlertDialog; +import android.app.Dialog; +import android.app.ProgressDialog; +import android.content.DialogInterface; +import android.content.Intent; +import android.content.res.Configuration; +import android.os.Bundle; +import android.os.Looper; +import android.support.v4.app.FragmentManager; +import android.support.v4.app.FragmentTransaction; +import android.view.KeyEvent; +import android.widget.Toast; + +import com.actionbarsherlock.app.ActionBar; +import com.actionbarsherlock.view.Menu; +import com.actionbarsherlock.view.MenuInflater; +import com.actionbarsherlock.view.MenuItem; + +import org.xmlrpc.android.XMLRPCClient; +import org.xmlrpc.android.XMLRPCException; + +import org.wordpress.android.R; +import org.wordpress.android.WordPress; +import org.wordpress.android.models.Blog; +import org.wordpress.android.models.Comment; +import org.wordpress.android.ui.WPActionBarActivity; +import org.wordpress.android.ui.comments.CommentFragment.OnCommentStatusChangeListener; +import org.wordpress.android.ui.comments.CommentsListFragment.OnAnimateRefreshButtonListener; +import org.wordpress.android.ui.comments.CommentsListFragment.OnCommentSelectedListener; +import org.wordpress.android.ui.comments.CommentsListFragment.OnContextCommentStatusChangeListener; + +public class CommentsActivity extends WPActionBarActivity implements + OnCommentSelectedListener, OnCommentStatusChangeListener, + OnAnimateRefreshButtonListener, OnContextCommentStatusChangeListener { + + protected int id; + public int ID_DIALOG_MODERATING = 1; + public int ID_DIALOG_REPLYING = 2; + public int ID_DIALOG_DELETING = 3; + private XMLRPCClient client; + public ProgressDialog pd; + private CommentsListFragment commentList; + private boolean fromNotification = false; + private MenuItem refreshMenuItem; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + createMenuDrawer(R.layout.comments); + + ActionBar actionBar = getSupportActionBar(); + actionBar.setDisplayShowTitleEnabled(true); + setTitle(getString(R.string.tab_comments)); + + Bundle extras = getIntent().getExtras(); + if (extras != null) { + fromNotification = extras.getBoolean("fromNotification"); + if (fromNotification) { + try { + WordPress.currentBlog = new Blog(extras.getInt("id")); + } catch (Exception e) { + Toast.makeText(this, getResources().getText(R.string.blog_not_found), Toast.LENGTH_SHORT).show(); + finish(); + } + } + } + + FragmentManager fm = getSupportFragmentManager(); + commentList = (CommentsListFragment) fm.findFragmentById(R.id.commentList); + + WordPress.currentComment = null; + + attemptToSelectComment(); + if (fromNotification) + commentList.refreshComments(false, false, false); + + } + + @Override + public void onBlogChanged() { + super.onBlogChanged(); + commentList.refreshComments(false, false, false); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + super.onCreateOptionsMenu(menu); + MenuInflater inflater = getSupportMenuInflater(); + inflater.inflate(R.menu.refresh_only, menu); + refreshMenuItem = menu.findItem(R.id.menu_refresh); + if (shouldAnimateRefreshButton) { + shouldAnimateRefreshButton = false; + startAnimatingRefreshButton(refreshMenuItem); + } + return true; + } + + @Override + public boolean onOptionsItemSelected(final MenuItem item) { + int itemId = item.getItemId(); + if (itemId == R.id.menu_refresh) { + popCommentDetail(); + attemptToSelectComment(); + commentList.refreshComments(false, false, false); + return true; + } else if (itemId == android.R.id.home) { + FragmentManager fm = getSupportFragmentManager(); + if (fm.getBackStackEntryCount() > 0) { + popCommentDetail(); + return true; + } + } + + return super.onOptionsItemSelected(item); + } + + protected void popCommentDetail() { + FragmentManager fm = getSupportFragmentManager(); + CommentFragment f = (CommentFragment) fm + .findFragmentById(R.id.commentDetail); + if (f == null) { + fm.popBackStack(); + } + } + + @Override + protected void onPostResume() { + super.onPostResume(); + if (WordPress.currentBlog != null) { + boolean commentsLoaded = commentList.loadComments(false, false); + if (!commentsLoaded) + commentList.refreshComments(false, false, false); + } + } + + @Override + protected void onPause() { + super.onPause(); + + } + + @Override + protected void onStop() { + super.onStop(); + if (commentList.getCommentsTask != null) + commentList.getCommentsTask.cancel(true); + } + + @Override + protected void onNewIntent(Intent intent) { + super.onNewIntent(intent); + Bundle extras = intent.getExtras(); + if (extras != null) { + boolean fromNotification = false; + fromNotification = extras.getBoolean("fromNotification"); + if (fromNotification) { + try { + WordPress.currentBlog = new Blog(extras.getInt("id")); + } catch (Exception e) { + Toast.makeText(this, getResources().getText(R.string.blog_not_found), Toast.LENGTH_SHORT).show(); + finish(); + } + //titleBar.refreshBlog(); + } + } + + } + + @Override + public void onCommentSelected(Comment comment) { + + FragmentManager fm = getSupportFragmentManager(); + CommentFragment f = (CommentFragment) fm + .findFragmentById(R.id.commentDetail); + + if (comment != null) { + + if (f == null || !f.isInLayout()) { + WordPress.currentComment = comment; + FragmentTransaction ft = fm.beginTransaction(); + ft.hide(commentList); + f = new CommentFragment(); + ft.add(R.id.commentDetailFragmentContainer, f); + ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); + ft.addToBackStack(null); + ft.commit(); + } else { + f.loadComment(comment); + } + } + } + + @Override + public void onCommentStatusChanged(final String status) { + + if (WordPress.currentComment != null) { + + final int commentID = WordPress.currentComment.commentID; + + if (status.equals("approve") || status.equals("hold") + || status.equals("spam")) { + showDialog(ID_DIALOG_MODERATING); + new Thread() { + public void run() { + Looper.prepare(); + changeCommentStatus(status, commentID); + } + }.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() { + public void run() { + deleteComment(commentID); + } + }.start(); + } else if (status.equals("reply")) { + + Intent i = new Intent(CommentsActivity.this, AddCommentActivity.class); + i.putExtra("commentID", commentID); + i.putExtra("postID", WordPress.currentComment.postID); + startActivityForResult(i, 0); + } else if (status.equals("clear")) { + FragmentManager fm = getSupportFragmentManager(); + CommentFragment f = (CommentFragment) fm + .findFragmentById(R.id.commentDetail); + if (f != null) { + f.clearContent(); + } + } + + } + } + + @SuppressWarnings("unchecked") + private void changeCommentStatus(final String newStatus, + final int selCommentID) { + // for individual comment moderation + client = new XMLRPCClient(WordPress.currentBlog.getUrl(), + WordPress.currentBlog.getHttpuser(), + WordPress.currentBlog.getHttppassword()); + + Map contentHash, postHash = new HashMap(); + contentHash = (Map) commentList.allComments.get(selCommentID); + postHash.put("status", newStatus); + postHash.put("content", contentHash.get("comment")); + postHash.put("author", contentHash.get("author")); + postHash.put("author_url", contentHash.get("url")); + postHash.put("author_email", contentHash.get("email")); + + Object[] params = { WordPress.currentBlog.getBlogId(), + WordPress.currentBlog.getUsername(), + WordPress.currentBlog.getPassword(), selCommentID, postHash }; + + Object result = null; + try { + result = (Object) client.call("wp.editComment", params); + boolean bResult = Boolean.parseBoolean(result.toString()); + if (bResult) { + WordPress.currentComment.status = newStatus; + commentList.model.set(WordPress.currentComment.position, + WordPress.currentComment); + WordPress.wpDB.updateCommentStatus(id, WordPress.currentComment.commentID, + newStatus); + } + dismissDialog(ID_DIALOG_MODERATING); + Thread action = new Thread() { + public void run() { + Toast.makeText(CommentsActivity.this, + getResources().getText(R.string.comment_moderated), + Toast.LENGTH_SHORT).show(); + } + }; + runOnUiThread(action); + Thread action2 = new Thread() { + public void run() { + commentList.thumbs.notifyDataSetChanged(); + } + }; + runOnUiThread(action2); + + } catch (final XMLRPCException e) { + dismissDialog(ID_DIALOG_MODERATING); + Thread action3 = new Thread() { + public void run() { + AlertDialog.Builder dialogBuilder = new AlertDialog.Builder( + CommentsActivity.this); + dialogBuilder.setTitle(getResources().getText( + R.string.connection_error)); + dialogBuilder.setMessage(getResources().getText(R.string.error_moderate_comment)); + dialogBuilder.setPositiveButton("OK", + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, + int whichButton) { + // Just close the window. + + } + }); + dialogBuilder.setCancelable(true); + if (!isFinishing()) { + dialogBuilder.create().show(); + } + } + }; + runOnUiThread(action3); + } + } + + private void deleteComment(int selCommentID) { + // delete individual comment + + client = new XMLRPCClient(WordPress.currentBlog.getUrl(), + WordPress.currentBlog.getHttpuser(), + WordPress.currentBlog.getHttppassword()); + + Object[] params = { WordPress.currentBlog.getBlogId(), + WordPress.currentBlog.getUsername(), + WordPress.currentBlog.getPassword(), selCommentID }; + + try { + client.call("wp.deleteComment", params); + dismissDialog(ID_DIALOG_DELETING); + attemptToSelectComment(); + Thread action = new Thread() { + public void run() { + Toast.makeText(CommentsActivity.this, + getResources().getText(R.string.comment_moderated), + Toast.LENGTH_SHORT).show(); + } + }; + runOnUiThread(action); + Thread action2 = new Thread() { + public void run() { + pd = new ProgressDialog(CommentsActivity.this); + commentList.refreshComments(false, true, false); + } + }; + runOnUiThread(action2); + + } catch (final XMLRPCException e) { + dismissDialog(ID_DIALOG_DELETING); + Thread action3 = new Thread() { + public void run() { + AlertDialog.Builder dialogBuilder = new AlertDialog.Builder( + CommentsActivity.this); + dialogBuilder.setTitle(getResources().getText( + R.string.connection_error)); + dialogBuilder.setMessage(getResources().getText(R.string.error_moderate_comment)); + dialogBuilder.setPositiveButton("OK", + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, + int whichButton) { + // Just close the window. + + } + }); + dialogBuilder.setCancelable(true); + if (!isFinishing()) { + dialogBuilder.create().show(); + } + } + }; + runOnUiThread(action3); + } + } + + private void replyToComment(final String postID, final int commentID, + final String comment) { + // reply to individual comment + client = new XMLRPCClient(WordPress.currentBlog.getUrl(), + WordPress.currentBlog.getHttpuser(), + WordPress.currentBlog.getHttppassword()); + + Map replyHash = new HashMap(); + replyHash.put("comment_parent", commentID); + replyHash.put("content", comment); + replyHash.put("author", ""); + replyHash.put("author_url", ""); + replyHash.put("author_email", ""); + + Object[] params = { WordPress.currentBlog.getBlogId(), + WordPress.currentBlog.getUsername(), + WordPress.currentBlog.getPassword(), Integer.valueOf(postID), + replyHash }; + + try { + int newCommentID = (Integer) client.call("wp.newComment", params); + if (newCommentID >= 0) + { + WordPress.wpDB.updateLatestCommentID(WordPress.currentBlog.getId(), newCommentID); + } + dismissDialog(ID_DIALOG_REPLYING); + Thread action = new Thread() { + public void run() { + Toast.makeText(CommentsActivity.this, + getResources().getText(R.string.reply_added), + Toast.LENGTH_SHORT).show(); + } + }; + runOnUiThread(action); + Thread action2 = new Thread() { + public void run() { + pd = new ProgressDialog(CommentsActivity.this); // to avoid + // crash + commentList.refreshComments(false, true, false); + } + }; + runOnUiThread(action2); + + } catch (final XMLRPCException e) { + dismissDialog(ID_DIALOG_REPLYING); + Thread action3 = new Thread() { + public void run() { + + Toast.makeText(CommentsActivity.this, getResources().getText(R.string.connection_error), Toast.LENGTH_SHORT).show(); + + Intent i = new Intent(CommentsActivity.this, AddCommentActivity.class); + i.putExtra("commentID", commentID); + i.putExtra("postID", WordPress.currentComment.postID); + i.putExtra("comment", comment); + startActivityForResult(i, 0); + } + }; + runOnUiThread(action3); + + } + + } + + @Override + public void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + if (data != null) { + + Bundle extras = data.getExtras(); + + switch (requestCode) { + case 0: + final String returnText = extras.getString("commentText"); + + if (!returnText.equals("CANCEL")) { + final String postID = extras.getString("postID"); + final int commentID = extras.getInt("commentID"); + showDialog(ID_DIALOG_REPLYING); + + new Thread(new Runnable() { + public void run() { + Looper.prepare(); + pd = new ProgressDialog(CommentsActivity.this); + replyToComment(postID, commentID, returnText); + } + }).start(); + } + + break; + } + } + } + + @Override + protected Dialog onCreateDialog(int id) { + if (id == ID_DIALOG_MODERATING) { + ProgressDialog loadingDialog = new ProgressDialog(CommentsActivity.this); + if (commentList.checkedCommentTotal <= 1) { + loadingDialog.setMessage(getResources().getText( + R.string.moderating_comment)); + } else { + loadingDialog.setMessage(getResources().getText( + R.string.moderating_comments)); + } + loadingDialog.setIndeterminate(true); + loadingDialog.setCancelable(false); + return loadingDialog; + } else if (id == ID_DIALOG_REPLYING) { + ProgressDialog loadingDialog = new ProgressDialog(CommentsActivity.this); + loadingDialog.setMessage(getResources().getText( + R.string.replying_comment)); + loadingDialog.setIndeterminate(true); + loadingDialog.setCancelable(false); + return loadingDialog; + } else if (id == ID_DIALOG_DELETING) { + ProgressDialog loadingDialog = new ProgressDialog(CommentsActivity.this); + if (commentList.checkedCommentTotal <= 1) { + loadingDialog.setMessage(getResources().getText( + R.string.deleting_comment)); + } else { + loadingDialog.setMessage(getResources().getText( + R.string.deleting_comments)); + } + loadingDialog.setIndeterminate(true); + loadingDialog.setCancelable(false); + return loadingDialog; + } + + return super.onCreateDialog(id); + } + + @Override + public boolean onKeyDown(int keyCode, KeyEvent event) { + /*if (keyCode == KeyEvent.KEYCODE_BACK && titleBar.isShowingDashboard) { + titleBar.hideDashboardOverlay(); + return false; + }*/ + + return super.onKeyDown(keyCode, event); + } + + @Override + public void onAnimateRefreshButton(boolean start) { + + if (start) { + shouldAnimateRefreshButton = true; + this.startAnimatingRefreshButton(refreshMenuItem); + } else { + this.stopAnimatingRefreshButton(refreshMenuItem); + } + + } + + private void attemptToSelectComment() { + + FragmentManager fm = getSupportFragmentManager(); + CommentFragment f = (CommentFragment) fm + .findFragmentById(R.id.commentDetail); + + if (f != null && f.isInLayout()) { + commentList.shouldSelectAfterLoad = true; + } + + } + + @Override + public void onConfigurationChanged(Configuration newConfig) { + super.onConfigurationChanged(newConfig); + + //titleBar.switchDashboardLayout(newConfig.orientation); + + } +} diff --git a/src/org/wordpress/android/ui/comments/comments.patch b/src/org/wordpress/android/ui/comments/comments.patch new file mode 100644 index 000000000000..e4def100c57a --- /dev/null +++ b/src/org/wordpress/android/ui/comments/comments.patch @@ -0,0 +1,60 @@ +215,223c215,216 +< 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() { +225c218,254 +< 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(); +> } +227,228c256,258 +< }.start(); +< } else if (status.equals("reply")) { +--- +> }; +> runOnUiThread(action3); +> } else if (status.equals("reply")) { diff --git a/src/org/wordpress/android/ui/posts/ViewPostFragment.java b/src/org/wordpress/android/ui/posts/ViewPostFragment.java index aff01a3e11bb..30d8d95a3a14 100644 --- a/src/org/wordpress/android/ui/posts/ViewPostFragment.java +++ b/src/org/wordpress/android/ui/posts/ViewPostFragment.java @@ -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; @@ -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( @@ -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); diff --git a/src/org/wordpress/android/ui/posts/ViewPostsFragment.java b/src/org/wordpress/android/ui/posts/ViewPostsFragment.java index e8c3be8da055..a9ab20f102ea 100644 --- a/src/org/wordpress/android/ui/posts/ViewPostsFragment.java +++ b/src/org/wordpress/android/ui/posts/ViewPostsFragment.java @@ -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; @@ -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) { @@ -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 {