Fix NPE in ComposeText.
This commit is contained in:
parent
e27089157d
commit
8d6d8019fe
1 changed files with 19 additions and 10 deletions
|
@ -40,6 +40,7 @@ import org.thoughtcrime.securesms.util.StringUtil;
|
|||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import static org.thoughtcrime.securesms.database.MentionUtil.MENTION_STARTER;
|
||||
|
||||
|
@ -84,13 +85,13 @@ public class ComposeText extends EmojiEditText {
|
|||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
|
||||
if (!TextUtils.isEmpty(hint)) {
|
||||
if (getLayout() != null && !TextUtils.isEmpty(hint)) {
|
||||
if (!TextUtils.isEmpty(subHint)) {
|
||||
setHint(new SpannableStringBuilder().append(ellipsizeToWidth(hint))
|
||||
setHintWithChecks(new SpannableStringBuilder().append(ellipsizeToWidth(hint))
|
||||
.append("\n")
|
||||
.append(ellipsizeToWidth(subHint)));
|
||||
} else {
|
||||
setHint(ellipsizeToWidth(hint));
|
||||
setHintWithChecks(ellipsizeToWidth(hint));
|
||||
}
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
}
|
||||
|
@ -160,14 +161,14 @@ public class ComposeText extends EmojiEditText {
|
|||
}
|
||||
|
||||
if (this.subHint != null) {
|
||||
super.setHint(new SpannableStringBuilder().append(ellipsizeToWidth(this.hint))
|
||||
setHintWithChecks(new SpannableStringBuilder().append(ellipsizeToWidth(this.hint))
|
||||
.append("\n")
|
||||
.append(ellipsizeToWidth(this.subHint)));
|
||||
} else {
|
||||
super.setHint(ellipsizeToWidth(this.hint));
|
||||
setHintWithChecks(ellipsizeToWidth(this.hint));
|
||||
}
|
||||
|
||||
super.setHint(hint);
|
||||
setHintWithChecks(hint);
|
||||
}
|
||||
|
||||
public void appendInvite(String invite) {
|
||||
|
@ -264,6 +265,14 @@ public class ComposeText extends EmojiEditText {
|
|||
addTextChangedListener(mentionValidatorWatcher);
|
||||
}
|
||||
|
||||
private void setHintWithChecks(@Nullable CharSequence newHint) {
|
||||
if (getLayout() == null || Objects.equals(getHint(), newHint)) {
|
||||
return;
|
||||
}
|
||||
|
||||
setHint(newHint);
|
||||
}
|
||||
|
||||
private boolean changeSelectionForPartialMentions(@NonNull Spanned spanned, int selectionStart, int selectionEnd) {
|
||||
Annotation[] annotations = spanned.getSpans(0, spanned.length(), Annotation.class);
|
||||
for (Annotation annotation : annotations) {
|
||||
|
|
Loading…
Add table
Reference in a new issue