blob: b4664643fe94419323b3587579d317f1affd61d9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
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.util.JSONUtils;
public class FooterNoteBlock extends NoteBlock {
private NoteBlockClickableSpan mClickableSpan;
public FooterNoteBlock(JSONObject noteObject, OnNoteBlockTextClickListener onNoteBlockTextClickListener) {
super(noteObject, onNoteBlockTextClickListener);
}
public void setClickableSpan(JSONObject rangeObject, String noteType) {
if (rangeObject == null) return;
mClickableSpan = new NoteBlockClickableSpan(
WordPress.getContext(),
rangeObject,
false,
true
);
mClickableSpan.setCustomType(noteType);
}
@Override
public BlockType getBlockType() {
return BlockType.FOOTER;
}
@Override
public int getLayoutResourceId() {
return R.layout.note_block_footer;
}
@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);
} else {
noteBlockHolder.getTextView().setVisibility(View.GONE);
}
String noticonGlyph = getNoticonGlyph();
if (!TextUtils.isEmpty(noticonGlyph)) {
noteBlockHolder.getNoticonView().setVisibility(View.VISIBLE);
noteBlockHolder.getNoticonView().setText(noticonGlyph);
} else {
noteBlockHolder.getNoticonView().setVisibility(View.GONE);
}
return view;
}
private String getNoticonGlyph() {
if (getNoteData() == null) return "";
return JSONUtils.queryJSON(getNoteData(), "ranges[first].value", "");
}
@Override
public Spannable getNoteText() {
return NotificationsUtils.getSpannableContentForRanges(getNoteData(), null,
getOnNoteBlockTextClickListener(), true);
}
public Object getViewHolder(View view) {
return new FooterNoteBlockHolder(view);
}
class FooterNoteBlockHolder {
private final View mFooterView;
private final TextView mTextView;
private final TextView mNoticonView;
FooterNoteBlockHolder(View view) {
mFooterView = view.findViewById(R.id.note_footer);
mFooterView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onRangeClick();
}
});
mTextView = (TextView) view.findViewById(R.id.note_footer_text);
mNoticonView = (TextView) view.findViewById(R.id.note_footer_noticon);
}
public TextView getTextView() {
return mTextView;
}
public TextView getNoticonView() {
return mNoticonView;
}
}
public void onRangeClick() {
if (mClickableSpan == null || getOnNoteBlockTextClickListener() == null) {
return;
}
getOnNoteBlockTextClickListener().onNoteBlockTextClicked(mClickableSpan);
}
}
|