Skip to content

Commit

Permalink
Merge pull request #1587 from wordpress-mobile/issue/1491-reader-bloc…
Browse files Browse the repository at this point in the history
…k-blog

issue/1491-reader-block-blog
  • Loading branch information
maxme committed Jul 16, 2014
2 parents 3df615a + b6c7374 commit 4a5cd32
Show file tree
Hide file tree
Showing 20 changed files with 336 additions and 37 deletions.
1 change: 1 addition & 0 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,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
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ android {
compile 'net.simonvt.menudrawer:menudrawer:3.0.6'
compile 'com.helpshift:android-aar:3.4.1'
compile 'com.mcxiaoke.volley:library:1.0.+'
compile 'com.cocosw:undobar:1.+@aar'

androidTestCompile 'com.jayway.android.robotium:robotium-solo:5.+'
androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.0'
Expand Down
File renamed without changes.
File renamed without changes.
14 changes: 14 additions & 0 deletions res/anim/reader_listitem_shrink.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>

<!-- used when a blog is blocked in the reader -->
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_shortAnimTime"
android:interpolator="@android:anim/accelerate_interpolator">
<scale
android:fromXScale="1.0"
android:fromYScale="1.0"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="0.0"
android:toYScale="0.0" />
</set>
8 changes: 0 additions & 8 deletions res/anim/reader_listview_row.xml

This file was deleted.

Binary file added res/drawable-hdpi/reader_arrow_dropdown.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-mdpi/reader_arrow_dropdown.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-xhdpi/reader_arrow_dropdown.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-xxhdpi/reader_arrow_dropdown.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 26 additions & 9 deletions res/layout/reader_listitem_post_excerpt.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/layout_container"
android:background="@drawable/reader_postlist_selector"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:background="@drawable/reader_postlist_selector">

<RelativeLayout
android:id="@+id/layout_post_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/margin_large"
android:background="@drawable/reader_transparent_selector">
android:background="@drawable/reader_transparent_selector"
android:paddingBottom="@dimen/margin_large">

<org.wordpress.android.widgets.WPNetworkImageView
android:id="@+id/image_avatar"
Expand All @@ -31,19 +31,36 @@
android:layout_height="wrap_content"
android:layout_marginRight="@dimen/margin_large"
android:layout_marginTop="@dimen/margin_large"
android:layout_toLeftOf="@+id/image_dropdown"
android:layout_toRightOf="@+id/image_avatar"
android:ellipsize="end"
android:maxLines="1"
tools:text="text_blog_name"
android:textColor="@color/grey_dark"
android:textSize="@dimen/text_sz_medium" />
android:textSize="@dimen/text_sz_medium"
tools:text="text_blog_name" />

<org.wordpress.android.widgets.WPTextView
android:id="@+id/text_follow"
style="@style/ReaderTextView.Follow"
android:layout_below="@+id/text_blog_name"
android:layout_marginTop="@dimen/margin_small"
android:layout_toRightOf="@+id/image_avatar" />

<ImageView
android:id="@+id/image_dropdown"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginLeft="@dimen/margin_small"
android:layout_marginRight="@dimen/margin_small"
android:background="@drawable/reader_transparent_selector"
android:paddingBottom="@dimen/margin_large"
android:paddingLeft="@dimen/margin_large"
android:paddingRight="@dimen/margin_large"
android:paddingTop="@dimen/margin_large"
android:src="@drawable/reader_arrow_dropdown" />

</RelativeLayout>

<org.wordpress.android.widgets.WPNetworkImageView
Expand All @@ -55,9 +72,9 @@
android:id="@+id/text_title"
style="@style/ReaderTextView.Post.Title"
android:layout_below="@+id/image_featured"
android:layout_marginTop="@dimen/margin_large"
android:layout_marginLeft="@dimen/margin_large"
android:layout_marginRight="@dimen/margin_large"
android:layout_marginTop="@dimen/margin_large"
tools:text="text_title" />

<org.wordpress.android.widgets.WPTextView
Expand All @@ -73,12 +90,12 @@
<org.wordpress.android.widgets.WPTextView
android:id="@+id/text_tag"
style="@style/ReaderTextView.Post.Tag"
android:layout_below="@+id/text_excerpt"
android:layout_marginLeft="@dimen/margin_large"
android:layout_marginTop="@dimen/margin_small"
android:paddingTop="@dimen/margin_small"
android:paddingBottom="@dimen/margin_small"
android:paddingRight="@dimen/margin_small"
android:layout_below="@+id/text_excerpt"
android:paddingTop="@dimen/margin_small"
tools:text="text_tag" />

<View
Expand Down
4 changes: 3 additions & 1 deletion res/values/reader_styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
-->
<resources>
<!-- activity themes -->
<style name="ReaderTheme" parent="@style/WordPress" />
<style name="ReaderTheme" parent="@style/WordPress">
<item name="android:popupMenuStyle">@android:style/Widget.Holo.Light.PopupMenu</item>
</style>
<style name="ReaderTheme.PopupPanel" parent="@android:style/Theme.Holo.Light.Panel">
<item name="android:windowAnimationStyle">@style/ReaderAnimation.ReaderPopup</item>
<item name="android:backgroundDimEnabled">true</item>
Expand Down
4 changes: 4 additions & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,7 @@

<!-- menu text-->
<string name="reader_menu_tags">Tags</string>
<string name="reader_menu_block_blog">Block this blog</string>

<!-- button text -->
<string name="reader_btn_share">Share</string>
Expand Down Expand Up @@ -650,6 +651,9 @@
<string name="reader_toast_err_already_follow_blog">You already follow this blog</string>
<string name="reader_toast_err_follow_blog">Unable to follow this blog</string>
<string name="reader_toast_err_unfollow_blog">Unable to unfollow this blog</string>
<string name="reader_toast_blog_blocked">Posts from this blog will no longer be shown</string>
<string name="reader_toast_err_block_blog">Unable to block this blog</string>
<string name="reader_toast_err_generic">Unable to perform this action</string>

<!-- empty list/grid text -->
<string name="reader_empty_posts_in_tag">No posts with this&#160;tag</string>
Expand Down
8 changes: 6 additions & 2 deletions src/org/wordpress/android/datasets/ReaderPostTable.java
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
31 changes: 28 additions & 3 deletions src/org/wordpress/android/ui/reader/ReaderAnim.java
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
102 changes: 102 additions & 0 deletions src/org/wordpress/android/ui/reader/ReaderPostListFragment.java
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 @@ -72,8 +77,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 @@ -425,6 +435,7 @@ public void onActivityCreated(Bundle savedInstanceState) {
}

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

@Override
Expand All @@ -448,6 +459,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 @@ -708,6 +809,7 @@ && getPostAdapter().isCurrentTag(tag)) {

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

Expand Down
5 changes: 3 additions & 2 deletions src/org/wordpress/android/ui/reader/ReaderTagFragment.java
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
Loading

0 comments on commit 4a5cd32

Please sign in to comment.