@消息界面删除逻辑补充

This commit is contained in:
18401019693 2022-10-08 18:24:05 +08:00
parent 8cf76a13e0
commit e2095f6e46

View File

@ -7,7 +7,6 @@ import android.text.SpannableStringBuilder;
import android.text.TextUtils; import android.text.TextUtils;
import android.text.TextWatcher; import android.text.TextWatcher;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.View;
import android.widget.EditText; import android.widget.EditText;
import com.yunbao.common.bean.OlineUserlistModel; import com.yunbao.common.bean.OlineUserlistModel;
@ -30,7 +29,7 @@ public class AtTextWatcher implements TextWatcher {
public void insertTextForAt(OlineUserlistModel model, EditText input) { public void insertTextForAt(OlineUserlistModel model, EditText input) {
this.input = input; this.input = input;
if (!spanMap.containsKey(model.getId())) { if (!spanMap.containsKey(model.getId())) {
if (!TextUtils.isEmpty(input.getText())){ if (!TextUtils.isEmpty(input.getText())) {
spannableStringBuilder = new SpannableStringBuilder(input.getText()); spannableStringBuilder = new SpannableStringBuilder(input.getText());
} }
String nameStr = model.getUserNicename(); String nameStr = model.getUserNicename();
@ -38,11 +37,16 @@ public class AtTextWatcher implements TextWatcher {
int endIndex = startIndex + nameStr.length();//字符结束的位置 int endIndex = startIndex + nameStr.length();//字符结束的位置
spanMap.put(model.getId(), model); spanMap.put(model.getId(), model);
//插入要添加的字符此处是为了给span占位 //插入要添加的字符此处是为了给span占位
input.getText().insert(startIndex, "@" + nameStr); input.getText().insert(startIndex, "@" + nameStr + " ");
//1使用mEditText构造一个SpannableString //1使用mEditText构造一个SpannableString
StringBuffer atName = new StringBuffer(); StringBuffer atName = new StringBuffer();
atName.append("@").append(nameStr); atName.append("@").append(nameStr).append(" ");
if (spannableStringBuilder.length() > 0) {
spannableStringBuilder.insert(startIndex, atName.toString());
} else {
spannableStringBuilder.append(atName.toString()); spannableStringBuilder.append(atName.toString());
}
AtUserForegroundColorSpan span = new AtUserForegroundColorSpan(Color.parseColor("#2a92f7")); AtUserForegroundColorSpan span = new AtUserForegroundColorSpan(Color.parseColor("#2a92f7"));
span.setAtContent(atName.toString()); span.setAtContent(atName.toString());
span.setUid(model.getId()); span.setUid(model.getId());