Skip to content

Commit

Permalink
Merge branch 'develop' into feature/modularization
Browse files Browse the repository at this point in the history
Conflicts:
	WordPress/src/main/res/anim/reader_listview_row.xml
	WordPress/src/main/res/anim/reader_tag_add.xml
	WordPress/src/main/res/anim/reader_tag_delete.xml
	build.gradle
	res/anim/reader_listitem_add.xml
	res/anim/reader_listitem_remove.xml
	res/anim/reader_tag_add.xml
	res/anim/reader_tag_delete.xml
	src/org/wordpress/android/util/ImageUtils.java
  • Loading branch information
maxme committed Jul 16, 2014
2 parents dfb62b4 + 4a5cd32 commit 80014b7
Show file tree
Hide file tree
Showing 19 changed files with 308 additions and 33 deletions.
1 change: 1 addition & 0 deletions WordPress/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ dependencies {
compile 'com.github.chrisbanes.photoview:library:1.2.3'
compile 'com.helpshift:android-aar:3.4.1'
compile 'commons-lang:commons-lang:2.6'
compile 'com.cocosw:undobar:1.+@aar'

compile('org.apache.httpcomponents:httpmime:4.1.+') {
exclude group: 'commons-logging', module: 'commons-logging'
Expand Down
1 change: 1 addition & 0 deletions WordPress/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@
<!-- Reader Activities -->
<activity
android:name=".ui.reader.ReaderPostListActivity"
android:theme="@style/ReaderTheme"
android:label="@string/reader" />
<activity
android:name=".ui.reader.ReaderPostPagerActivity"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,11 @@ public static int deletePostsWithTag(final ReaderTag tag) {
return numDeleted;
}

public static int deletePostsInBlog(long blogId) {
String[] args = {Long.toString(blogId)};
return ReaderDatabase.getWritableDb().delete("tbl_posts", "blog_id = ?", args);
}

/*
* returns the iso8601 published date of the oldest post with the passed tag
*/
Expand Down Expand Up @@ -407,8 +412,7 @@ public static void addOrUpdatePosts(final ReaderTag tag, ReaderPostList posts) {
stmtPosts.clearBindings();
}

// now add to tbl_post_tags - note that tagName will be null when updating a single
// post, in which case we skip it here
// now add to tbl_post_tags if a tag was passed
if (tag != null) {
String tagName = tag.getTagName();
int tagType = tag.tagType.toInt();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import android.view.animation.LinearInterpolator;
import android.widget.ListView;

import org.wordpress.android.R;

public class ReaderAnim {

public static enum Duration {
Expand Down Expand Up @@ -169,10 +171,17 @@ private static void animateButton(final View target, ReaderButton button) {
set.start();
}

/*
* called when adding or removing an item from a listView
*/
public static enum AnimateListItemStyle {
ADD,
REMOVE,
SHRINK }
public static void animateListItem(ListView listView,
int positionAbsolute,
Animation.AnimationListener listener,
int animResId) {
int positionAbsolute,
AnimateListItemStyle style,
Animation.AnimationListener listener) {
if (listView == null) {
return;
}
Expand All @@ -187,7 +196,23 @@ public static void animateListItem(ListView listView,
return;
}

final int animResId;
switch (style) {
case ADD:
animResId = R.anim.reader_listitem_add;
break;
case REMOVE:
animResId = R.anim.reader_listitem_remove;
break;
case SHRINK:
animResId = R.anim.reader_listitem_shrink;
break;
default:
return;
}

Animation animation = AnimationUtils.loadAnimation(listView.getContext(), animResId);

if (listener != null) {
animation.setAnimationListener(listener);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,18 @@
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.PopupMenu;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.cocosw.undobar.UndoBarController;

import org.wordpress.android.R;
import org.wordpress.android.datasets.ReaderPostTable;
import org.wordpress.android.datasets.ReaderTagTable;
import org.wordpress.android.models.ReaderPost;
import org.wordpress.android.models.ReaderPostList;
import org.wordpress.android.models.ReaderTag;
import org.wordpress.android.models.ReaderTagType;
import org.wordpress.android.ui.PullToRefreshHelper;
Expand All @@ -37,6 +41,7 @@
import org.wordpress.android.ui.reader.ReaderTypes.ReaderPostListType;
import org.wordpress.android.ui.reader.actions.ReaderActions;
import org.wordpress.android.ui.reader.actions.ReaderActions.RequestDataAction;
import org.wordpress.android.ui.reader.actions.ReaderBlogActions;
import org.wordpress.android.ui.reader.actions.ReaderPostActions;
import org.wordpress.android.ui.reader.actions.ReaderTagActions;
import org.wordpress.android.ui.reader.actions.ReaderTagActions.TagAction;
Expand Down Expand Up @@ -73,8 +78,13 @@ public static interface OnTagSelectedListener {
public void onTagSelected(String tagName);
}

public static interface OnPostPopupListener {
public void onShowPostPopup(View view, ReaderPost post, int position);
}

private ReaderActionBarTagAdapter mActionBarAdapter;
private ReaderPostAdapter mPostAdapter;

private OnPostSelectedListener mPostSelectedListener;
private OnTagSelectedListener mOnTagSelectedListener;

Expand Down Expand Up @@ -426,6 +436,7 @@ public void onActivityCreated(Bundle savedInstanceState) {
}

getPostAdapter().setOnTagSelectedListener(mOnTagSelectedListener);
getPostAdapter().setOnPostPopupListener(mOnPostPopupListener);
}

@Override
Expand All @@ -449,6 +460,96 @@ public boolean onOptionsItemSelected(MenuItem item) {
}
}

/*
* called when user taps dropdown arrow icon next to a post - shows a popup menu
* that enables blocking the blog the post is in
*/
private final OnPostPopupListener mOnPostPopupListener = new OnPostPopupListener() {
@Override
public void onShowPostPopup(View view, final ReaderPost post, final int position) {
if (view == null || post == null) {
return;
}

PopupMenu popup = new PopupMenu(getActivity(), view);
MenuItem menuItem = popup.getMenu().add(getString(R.string.reader_menu_block_blog));
menuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
blockBlogForPost(post, position);
return true;
}
});
popup.show();
}
};

/*
* blocks the blog associated with the passed post and removes all posts in that blog
* from the adapter - passed position is the index of the post in the adapter
*/
private void blockBlogForPost(final ReaderPost post, final int position) {
if (!NetworkUtils.checkConnection(getActivity())) {
return;
}

ReaderActions.ActionListener actionListener = new ReaderActions.ActionListener() {
@Override
public void onActionResult(boolean succeeded) {
if (!succeeded && hasActivity()) {
hideUndoBar();
ToastUtils.showToast(getActivity(), R.string.reader_toast_err_block_blog, ToastUtils.Duration.LONG);
}
}
};

// perform call to block this blog - returns list of posts deleted by blocking so
// they can be restored if the user undoes the block
final ReaderPostList postsToRestore =
ReaderBlogActions.blockBlogFromReader(post.blogId, actionListener);

// animate out the post the user chose to block from, then remove the post from the adapter
Animation.AnimationListener aniListener = new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) { }
@Override
public void onAnimationRepeat(Animation animation) { }
@Override
public void onAnimationEnd(Animation animation) {
if (hasActivity()) {
// remove this specific post, then refresh the adapter so other posts in this
// blog no long appear
getPostAdapter().removePost(position);
getPostAdapter().refresh();
}
}
};
ReaderAnim.animateListItem(mListView,
position,
ReaderAnim.AnimateListItemStyle.SHRINK,
aniListener);

// show the undo bar enabling the user to undo the block
UndoBarController.UndoListener undoListener = new UndoBarController.UndoListener() {
@Override
public void onUndo(Parcelable parcelable) {
ReaderBlogActions.unblockBlogFromReader(post.blogId, postsToRestore);
refreshPosts();
}
};
new UndoBarController.UndoBar(getActivity())
.message(getString(R.string.reader_toast_blog_blocked))
.listener(undoListener)
.translucent(true)
.show();
}

private void hideUndoBar() {
if (hasActivity()) {
UndoBarController.clear(getActivity());
}
}

/*
* show/hide progress bar which appears at the bottom of the activity when loading more posts
*/
Expand Down Expand Up @@ -709,6 +810,7 @@ && getPostAdapter().isCurrentTag(tag)) {

getPostAdapter().setCurrentTag(tag);
hideNewPostsBar();
hideUndoBar();
updateTagPreviewHeader();
hideLoadingProgress();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,9 @@ public void onAnimationEnd(Animation animation) {
refresh();
}
};
int aniResId = (action == TagAction.ADD ? R.anim.reader_tag_add : R.anim.reader_tag_delete);
ReaderAnim.animateListItem(mListView, index, aniListener, aniResId);
ReaderAnim.AnimateListItemStyle animStyle =
(action == TagAction.ADD ? ReaderAnim.AnimateListItemStyle.ADD : ReaderAnim.AnimateListItemStyle.REMOVE);
ReaderAnim.animateListItem(mListView, index, animStyle, aniListener);
} else {
refresh();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.wordpress.android.models.ReaderBlog;
import org.wordpress.android.models.ReaderBlogList;
import org.wordpress.android.models.ReaderPost;
import org.wordpress.android.models.ReaderPostList;
import org.wordpress.android.models.ReaderRecommendBlogList;
import org.wordpress.android.ui.reader.ReaderConstants;
import org.wordpress.android.ui.reader.actions.ReaderActions.UpdateBlogInfoListener;
Expand Down Expand Up @@ -373,12 +374,81 @@ public void onErrorResponse(VolleyError volleyError) {
}
};

// TODO: this should be a HEAD rather than GET request, but Volley doesn't support HEAD
// TODO: may be a leak here - http://stackoverflow.com/a/23549486/1673548
StringRequest request = new StringRequest(
Request.Method.GET,
Request.Method.HEAD,
blogUrl,
listener,
errorListener);
WordPress.requestQueue.add(request);
}

/*
* block a blog - returns the list of posts that were deleted by the block so they can
* be restored if the user undoes the block
*/
public static ReaderPostList blockBlogFromReader(final long blogId,
final ReaderActions.ActionListener actionListener) {
final ReaderPostList deletedPosts = ReaderPostTable.getPostsInBlog(blogId, 0);
ReaderPostTable.deletePostsInBlog(blogId);

com.wordpress.rest.RestRequest.Listener listener = new RestRequest.Listener() {
@Override
public void onResponse(JSONObject jsonObject) {
boolean success = (jsonObject != null && jsonObject.optBoolean("success"));
if (!success) {
AppLog.w(T.READER, "failed to block blog " + blogId);
ReaderPostTable.addOrUpdatePosts(null, deletedPosts);
}
if (actionListener != null) {
actionListener.onActionResult(success);
}

}
};
RestRequest.ErrorListener errorListener = new RestRequest.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
AppLog.e(T.READER, volleyError);
ReaderPostTable.addOrUpdatePosts(null, deletedPosts);
if (actionListener != null) {
actionListener.onActionResult(false);
}
}
};

AppLog.i(T.READER, "blocking blog " + blogId);
String path = "/me/block/sites/" + Long.toString(blogId) + "/new";
WordPress.getRestClientUtils().post(path, listener, errorListener);

return deletedPosts;
}

public static void unblockBlogFromReader(final long blogId,
final ReaderPostList postsToRestore) {
if (postsToRestore != null) {
ReaderPostTable.addOrUpdatePosts(null, postsToRestore);
}

com.wordpress.rest.RestRequest.Listener listener = new RestRequest.Listener() {
@Override
public void onResponse(JSONObject jsonObject) {
boolean success = (jsonObject != null && jsonObject.optBoolean("success"));
if (!success) {
AppLog.w(T.READER, "failed to unblock blog " + blogId);
}

}
};
RestRequest.ErrorListener errorListener = new RestRequest.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
AppLog.e(T.READER, volleyError);
}
};

AppLog.i(T.READER, "unblocking blog " + blogId);
String path = "/me/block/sites/" + Long.toString(blogId) + "/delete";
WordPress.getRestClientUtils().post(path, listener, errorListener);
}
}
Loading

0 comments on commit 80014b7

Please sign in to comment.