|
1 | 1 | package org.schabi.newpipe.info_list.holder; |
2 | 2 |
|
| 3 | +import static android.text.TextUtils.isEmpty; |
| 4 | + |
3 | 5 | import android.graphics.Paint; |
4 | 6 | import android.text.Layout; |
5 | | -import android.text.TextUtils; |
6 | 7 | import android.text.method.LinkMovementMethod; |
7 | 8 | import android.text.style.URLSpan; |
8 | 9 | import android.util.Log; |
@@ -59,9 +60,9 @@ public class CommentsMiniInfoItemHolder extends InfoItemHolder { |
59 | 60 | private final TextView itemPublishedTime; |
60 | 61 |
|
61 | 62 | private final CompositeDisposable disposables = new CompositeDisposable(); |
62 | | - private Description commentText; |
63 | | - private StreamingService streamService; |
64 | | - private String streamUrl; |
| 63 | + @Nullable private Description commentText; |
| 64 | + @Nullable private StreamingService streamService; |
| 65 | + @Nullable private String streamUrl; |
65 | 66 |
|
66 | 67 | CommentsMiniInfoItemHolder(final InfoItemBuilder infoItemBuilder, final int layoutId, |
67 | 68 | final ViewGroup parent) { |
@@ -153,15 +154,17 @@ public void updateFromItem(final InfoItem infoItem, |
153 | 154 | if (DeviceUtils.isTv(itemBuilder.getContext())) { |
154 | 155 | openCommentAuthor(item); |
155 | 156 | } else { |
156 | | - ShareUtils.copyToClipboard(itemBuilder.getContext(), |
157 | | - itemContentView.getText().toString()); |
| 157 | + final CharSequence text = itemContentView.getText(); |
| 158 | + if (text != null) { |
| 159 | + ShareUtils.copyToClipboard(itemBuilder.getContext(), text.toString()); |
| 160 | + } |
158 | 161 | } |
159 | 162 | return true; |
160 | 163 | }); |
161 | 164 | } |
162 | 165 |
|
163 | 166 | private void openCommentAuthor(final CommentsInfoItem item) { |
164 | | - if (TextUtils.isEmpty(item.getUploaderUrl())) { |
| 167 | + if (isEmpty(item.getUploaderUrl())) { |
165 | 168 | return; |
166 | 169 | } |
167 | 170 | final AppCompatActivity activity = (AppCompatActivity) itemBuilder.getContext(); |
@@ -207,11 +210,12 @@ private void ellipsize() { |
207 | 210 | linkifyCommentContentView(v -> { |
208 | 211 | boolean hasEllipsis = false; |
209 | 212 |
|
210 | | - if (itemContentView.getLineCount() > COMMENT_DEFAULT_LINES) { |
| 213 | + final CharSequence charSeqText = itemContentView.getText(); |
| 214 | + if (charSeqText != null && itemContentView.getLineCount() > COMMENT_DEFAULT_LINES) { |
211 | 215 | // Note that converting to String removes spans (i.e. links), but that's something |
212 | 216 | // we actually want since when the text is ellipsized we want all clicks on the |
213 | 217 | // comment to expand the comment, not to open links. |
214 | | - final String text = itemContentView.getText().toString(); |
| 218 | + final String text = charSeqText.toString(); |
215 | 219 |
|
216 | 220 | final Layout layout = itemContentView.getLayout(); |
217 | 221 | final float lineWidth = layout.getLineWidth(COMMENT_DEFAULT_LINES - 1); |
@@ -252,7 +256,7 @@ private void ellipsize() { |
252 | 256 |
|
253 | 257 | private void toggleEllipsize() { |
254 | 258 | final CharSequence text = itemContentView.getText(); |
255 | | - if (text.charAt(text.length() - 1) == ELLIPSIS.charAt(0)) { |
| 259 | + if (!isEmpty(text) && text.charAt(text.length() - 1) == ELLIPSIS.charAt(0)) { |
256 | 260 | expand(); |
257 | 261 | } else if (itemContentView.getLineCount() > COMMENT_DEFAULT_LINES) { |
258 | 262 | ellipsize(); |
|
0 commit comments