diff options
Diffstat (limited to 'WordPress/src/main/java/org/wordpress')
5 files changed, 139 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); } |