Skip to content

Commit 671dd4a

Browse files
authored
Merge pull request #9777 from pratyaksh1610/branch-9774
[Bug] Crash fix when click on empty comment
2 parents e0cb289 + 624ad6a commit 671dd4a

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

app/src/main/java/org/schabi/newpipe/info_list/holder/CommentsMiniInfoItemHolder.java

+14-10
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package org.schabi.newpipe.info_list.holder;
22

3+
import static android.text.TextUtils.isEmpty;
4+
35
import android.graphics.Paint;
46
import android.text.Layout;
5-
import android.text.TextUtils;
67
import android.text.method.LinkMovementMethod;
78
import android.text.style.URLSpan;
89
import android.util.Log;
@@ -59,9 +60,9 @@ public class CommentsMiniInfoItemHolder extends InfoItemHolder {
5960
private final TextView itemPublishedTime;
6061

6162
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;
6566

6667
CommentsMiniInfoItemHolder(final InfoItemBuilder infoItemBuilder, final int layoutId,
6768
final ViewGroup parent) {
@@ -153,15 +154,17 @@ public void updateFromItem(final InfoItem infoItem,
153154
if (DeviceUtils.isTv(itemBuilder.getContext())) {
154155
openCommentAuthor(item);
155156
} 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+
}
158161
}
159162
return true;
160163
});
161164
}
162165

163166
private void openCommentAuthor(final CommentsInfoItem item) {
164-
if (TextUtils.isEmpty(item.getUploaderUrl())) {
167+
if (isEmpty(item.getUploaderUrl())) {
165168
return;
166169
}
167170
final AppCompatActivity activity = (AppCompatActivity) itemBuilder.getContext();
@@ -207,11 +210,12 @@ private void ellipsize() {
207210
linkifyCommentContentView(v -> {
208211
boolean hasEllipsis = false;
209212

210-
if (itemContentView.getLineCount() > COMMENT_DEFAULT_LINES) {
213+
final CharSequence charSeqText = itemContentView.getText();
214+
if (charSeqText != null && itemContentView.getLineCount() > COMMENT_DEFAULT_LINES) {
211215
// Note that converting to String removes spans (i.e. links), but that's something
212216
// we actually want since when the text is ellipsized we want all clicks on the
213217
// comment to expand the comment, not to open links.
214-
final String text = itemContentView.getText().toString();
218+
final String text = charSeqText.toString();
215219

216220
final Layout layout = itemContentView.getLayout();
217221
final float lineWidth = layout.getLineWidth(COMMENT_DEFAULT_LINES - 1);
@@ -252,7 +256,7 @@ private void ellipsize() {
252256

253257
private void toggleEllipsize() {
254258
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)) {
256260
expand();
257261
} else if (itemContentView.getLineCount() > COMMENT_DEFAULT_LINES) {
258262
ellipsize();

0 commit comments

Comments
 (0)