aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Roundhill <dan@automattic.com>2015-04-29 11:57:38 -0700
committerDan Roundhill <dan@automattic.com>2015-04-29 11:57:38 -0700
commit9741a033846bae1229a296d08d2325f460bf54ca (patch)
tree4a4041fac19dfef5ddd91382a1ad7f620d975be0
parent9c2f5dec7f307ac7aa5bc833bc72b9630bba802c (diff)
downloadgradle-perf-android-medium-9741a033846bae1229a296d08d2325f460bf54ca.tar.gz
New footer note block for handling footers in certain note types.
-rw-r--r--WordPress/src/main/java/org/wordpress/android/models/Note.java6
-rw-r--r--WordPress/src/main/java/org/wordpress/android/ui/notifications/NotificationsDetailListFragment.java19
-rw-r--r--WordPress/src/main/java/org/wordpress/android/ui/notifications/blocks/BlockType.java24
-rw-r--r--WordPress/src/main/java/org/wordpress/android/ui/notifications/blocks/FooterNoteBlock.java92
-rw-r--r--WordPress/src/main/java/org/wordpress/android/ui/notifications/blocks/NoteBlock.java2
-rw-r--r--WordPress/src/main/res/layout/note_block_footer.xml37
6 files changed, 176 insertions, 4 deletions
diff --git a/WordPress/src/main/java/org/wordpress/android/models/Note.java b/WordPress/src/main/java/org/wordpress/android/models/Note.java
index 5bd78cc15..2d4f4089a 100644
--- a/WordPress/src/main/java/org/wordpress/android/models/Note.java
+++ b/WordPress/src/main/java/org/wordpress/android/models/Note.java
@@ -188,6 +188,10 @@ public class Note extends Syncable {
return "";
}
+ public long getCommentReplyId() {
+ return queryJSON("meta.ids.reply_comment", 0);
+ }
+
/**
* Compare note timestamp to now and return a time grouping
*/
@@ -459,7 +463,7 @@ public class Note extends Syncable {
*/
public static class Schema extends BucketSchema<Note> {
- static public final String NAME = "note20";
+ static public final String NAME = "note20test";
static public final String TIMESTAMP_INDEX = "timestamp";
static public final String SUBJECT_INDEX = "subject";
static public final String SNIPPET_INDEX = "snippet";
diff --git a/WordPress/src/main/java/org/wordpress/android/ui/notifications/NotificationsDetailListFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/notifications/NotificationsDetailListFragment.java
index e72aa9721..6fe200967 100644
--- a/WordPress/src/main/java/org/wordpress/android/ui/notifications/NotificationsDetailListFragment.java
+++ b/WordPress/src/main/java/org/wordpress/android/ui/notifications/NotificationsDetailListFragment.java
@@ -24,7 +24,9 @@ import org.wordpress.android.R;
import org.wordpress.android.models.CommentStatus;
import org.wordpress.android.models.Note;
import org.wordpress.android.ui.notifications.adapters.NoteBlockAdapter;
+import org.wordpress.android.ui.notifications.blocks.BlockType;
import org.wordpress.android.ui.notifications.blocks.CommentUserNoteBlock;
+import org.wordpress.android.ui.notifications.blocks.FooterNoteBlock;
import org.wordpress.android.ui.notifications.blocks.HeaderNoteBlock;
import org.wordpress.android.ui.notifications.blocks.NoteBlock;
import org.wordpress.android.ui.notifications.blocks.NoteBlockClickableSpan;
@@ -268,7 +270,7 @@ public class NotificationsDetailListFragment extends ListFragment implements Not
NoteBlock noteBlock;
String noteBlockTypeString = JSONUtils.queryJSON(noteObject, "type", "");
- if (NoteBlockRangeType.fromString(noteBlockTypeString) == NoteBlockRangeType.USER) {
+ if (BlockType.fromString(noteBlockTypeString) == BlockType.USER) {
if (mNote.isCommentType()) {
// Set comment position so we can target it later
// See refreshBlocksForCommentStatus()
@@ -304,6 +306,10 @@ public class NotificationsDetailListFragment extends ListFragment implements Not
mOnGravatarClickedListener
);
}
+ } else if (isFooterBlock(noteObject)) {
+ noteBlock = new FooterNoteBlock(noteObject, mOnNoteBlockTextClickListener);
+ ((FooterNoteBlock)noteBlock).setClickableSpan(
+ JSONUtils.queryJSON(noteObject, "body[last].ranges[1]", new JSONObject()));
} else {
noteBlock = new NoteBlock(noteObject, mOnNoteBlockTextClickListener);
}
@@ -350,6 +356,17 @@ public class NotificationsDetailListFragment extends ListFragment implements Not
}
}
+ private boolean isFooterBlock(JSONObject blockObject) {
+ if (mNote == null || blockObject == null) return false;
+
+ if (mNote.isCommentType()) {
+ return (TextUtils.isEmpty(JSONUtils.queryJSON(blockObject, "type", "")) &&
+ mNote.getCommentReplyId() == JSONUtils.queryJSON(blockObject, "ranges[1].id", 0));
+ }
+
+ return false;
+ }
+
public void refreshBlocksForCommentStatus(CommentStatus newStatus) {
if (mOnCommentStatusChangeListener != null) {
mOnCommentStatusChangeListener.onCommentStatusChanged(newStatus);
diff --git a/WordPress/src/main/java/org/wordpress/android/ui/notifications/blocks/BlockType.java b/WordPress/src/main/java/org/wordpress/android/ui/notifications/blocks/BlockType.java
index fc95f9869..688979255 100644
--- a/WordPress/src/main/java/org/wordpress/android/ui/notifications/blocks/BlockType.java
+++ b/WordPress/src/main/java/org/wordpress/android/ui/notifications/blocks/BlockType.java
@@ -1,5 +1,7 @@
package org.wordpress.android.ui.notifications.blocks;
+import android.text.TextUtils;
+
/** BlockTypes that we know about
* Unknown blocks will still be displayed using the rules for BASIC blocks
*/
@@ -8,5 +10,25 @@ public enum BlockType {
BASIC,
USER,
USER_HEADER,
- USER_COMMENT
+ USER_COMMENT,
+ FOOTER;
+
+ public static BlockType fromString(String blockType) {
+ if (TextUtils.isEmpty(blockType)) return UNKNOWN;
+
+ switch (blockType) {
+ case "basic":
+ return BASIC;
+ case "user":
+ return USER;
+ case "user_header":
+ return USER_HEADER;
+ case "user_comment":
+ return USER_COMMENT;
+ case "footer":
+ return FOOTER;
+ default:
+ return UNKNOWN;
+ }
+ }
}
diff --git a/WordPress/src/main/java/org/wordpress/android/ui/notifications/blocks/FooterNoteBlock.java b/WordPress/src/main/java/org/wordpress/android/ui/notifications/blocks/FooterNoteBlock.java
new file mode 100644
index 000000000..0993af88f
--- /dev/null
+++ b/WordPress/src/main/java/org/wordpress/android/ui/notifications/blocks/FooterNoteBlock.java
@@ -0,0 +1,92 @@
+package org.wordpress.android.ui.notifications.blocks;
+
+import android.text.Spannable;
+import android.text.TextUtils;
+import android.view.View;
+import android.widget.TextView;
+
+import org.json.JSONObject;
+import org.wordpress.android.R;
+import org.wordpress.android.WordPress;
+import org.wordpress.android.ui.notifications.utils.NotificationsUtils;
+import org.wordpress.android.widgets.WPTextView;
+
+// Note header, displayed at top of detail view
+public class FooterNoteBlock extends NoteBlock {
+ private NoteBlockClickableSpan mClickableSpan;
+
+ public FooterNoteBlock(JSONObject noteObject, OnNoteBlockTextClickListener onNoteBlockTextClickListener) {
+ super(noteObject, onNoteBlockTextClickListener);
+ }
+
+ public void setClickableSpan(JSONObject rangeObject) {
+ if (rangeObject == null) return;
+
+ mClickableSpan = new NoteBlockClickableSpan(
+ WordPress.getContext(),
+ rangeObject,
+ false
+ );
+ }
+
+ @Override
+ public BlockType getBlockType() {
+ return BlockType.FOOTER;
+ }
+
+ @Override
+ public int getLayoutResourceId() {
+ return R.layout.note_block_footer;
+ }
+
+ @Override
+ public Spannable getNoteText() {
+ return NotificationsUtils.getSpannableContentForRanges(getNoteData(), null, getOnNoteBlockTextClickListener());
+ }
+
+ @Override
+ public View configureView(final View view) {
+ final FooterNoteBlockHolder noteBlockHolder = (FooterNoteBlockHolder)view.getTag();
+
+ // Note text
+ if (!TextUtils.isEmpty(getNoteText())) {
+ noteBlockHolder.getTextView().setText(getNoteText());
+ noteBlockHolder.getTextView().setVisibility(View.VISIBLE);
+ }
+
+ return view;
+ }
+
+ public Object getViewHolder(View view) {
+ return new FooterNoteBlockHolder(view);
+ }
+
+ class FooterNoteBlockHolder {
+ private final View mFooterView;
+ private final TextView mTextView;
+
+ FooterNoteBlockHolder(View view) {
+ mFooterView = view.findViewById(R.id.note_footer);
+ mFooterView.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ onRangeClick();
+ }
+ });
+ mTextView = (WPTextView) view.findViewById(R.id.note_text);
+ }
+
+ public TextView getTextView() {
+ return mTextView;
+ }
+ }
+
+ public void onRangeClick() {
+ if (mClickableSpan == null || getOnNoteBlockTextClickListener() == null) {
+ return;
+ }
+
+ getOnNoteBlockTextClickListener().onNoteBlockTextClicked(mClickableSpan);
+ }
+
+}
diff --git a/WordPress/src/main/java/org/wordpress/android/ui/notifications/blocks/NoteBlock.java b/WordPress/src/main/java/org/wordpress/android/ui/notifications/blocks/NoteBlock.java
index 10ac32ca8..311c71b3d 100644
--- a/WordPress/src/main/java/org/wordpress/android/ui/notifications/blocks/NoteBlock.java
+++ b/WordPress/src/main/java/org/wordpress/android/ui/notifications/blocks/NoteBlock.java
@@ -67,7 +67,7 @@ public class NoteBlock {
return mNoteData;
}
- Spannable getNoteText() {
+ public Spannable getNoteText() {
return NotificationsUtils.getSpannableContentForRanges(mNoteData, null, mOnNoteBlockTextClickListener);
}
diff --git a/WordPress/src/main/res/layout/note_block_footer.xml b/WordPress/src/main/res/layout/note_block_footer.xml
new file mode 100644
index 000000000..bbf406649
--- /dev/null
+++ b/WordPress/src/main/res/layout/note_block_footer.xml
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical">
+
+ <LinearLayout
+ android:id="@+id/note_footer"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center"
+ android:paddingBottom="@dimen/margin_medium"
+ android:paddingLeft="@dimen/margin_extra_large"
+ android:paddingRight="@dimen/margin_extra_large"
+ android:paddingTop="@dimen/margin_medium"
+ android:orientation="vertical"
+ android:background="@drawable/selectable_background_wordpress"
+ android:clickable="true">
+
+ <org.wordpress.android.widgets.WPTextView
+ android:id="@+id/note_text"
+ android:layout_width="wrap_content"
+ android:layout_height="match_parent"
+ android:textColor="@color/grey"
+ android:textColorLink="@color/grey_dark"
+ android:textSize="@dimen/text_sz_large"
+ app:fixWidowWords="true" />
+
+ </LinearLayout>
+
+ <View
+ android:id="@+id/divider_view"
+ android:layout_width="match_parent"
+ android:layout_height="1dp"
+ android:background="@drawable/notifications_list_divider" />
+</LinearLayout> \ No newline at end of file