@消息界面删除逻辑

This commit is contained in:
18401019693 2022-10-08 18:09:37 +08:00
parent 80655a8662
commit 8cf76a13e0
17 changed files with 355 additions and 33 deletions

View File

@ -66,6 +66,7 @@ repositories {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
api files('libs/jcc-bate-0.7.3.jar')
compileOnly fileTree(dir: '../libs', include: ['*.aar'])
api rootProject.ext.dependencies["appcompat-androidx"]
api rootProject.ext.dependencies["recyclerview-androidx"]

View File

@ -0,0 +1,17 @@
package com.yunbao.common.event;
import com.yunbao.common.bean.BaseModel;
import com.yunbao.common.bean.OlineUserlistModel;
public class LiveInputEvent extends BaseModel {
private OlineUserlistModel model;
public OlineUserlistModel getModel() {
return model;
}
public LiveInputEvent setModel(OlineUserlistModel model) {
this.model = model;
return this;
}
}

View File

@ -0,0 +1,17 @@
package com.yunbao.common.event;
import com.yunbao.common.bean.BaseModel;
import com.yunbao.common.bean.OlineUserlistModel;
public class OlineEvent extends BaseModel {
private OlineUserlistModel model;
public OlineUserlistModel getModel() {
return model;
}
public OlineEvent setModel(OlineUserlistModel model) {
this.model = model;
return this;
}
}

View File

@ -1,4 +1,4 @@
package com.yunbao.main.utils;
package com.yunbao.common.utils;
import java.io.IOException;

View File

@ -0,0 +1,111 @@
package com.yunbao.common.views.weight;
import android.graphics.Color;
import android.text.Editable;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.KeyEvent;
import android.view.View;
import android.widget.EditText;
import com.yunbao.common.bean.OlineUserlistModel;
import java.util.HashMap;
import java.util.Map;
//输入监听
public class AtTextWatcher implements TextWatcher {
private Map<String, OlineUserlistModel> spanMap = new HashMap<>();
private EditText input;
private SpannableStringBuilder spannableStringBuilder;
private SpannableStringBuilder beforeStr, afterText;
private boolean removeListener = true;
public AtTextWatcher() {
spannableStringBuilder = new SpannableStringBuilder();
}
public void insertTextForAt(OlineUserlistModel model, EditText input) {
this.input = input;
if (!spanMap.containsKey(model.getId())) {
if (!TextUtils.isEmpty(input.getText())){
spannableStringBuilder = new SpannableStringBuilder(input.getText());
}
String nameStr = model.getUserNicename();
int startIndex = input.getSelectionStart();//光标的位置
int endIndex = startIndex + nameStr.length();//字符结束的位置
spanMap.put(model.getId(), model);
//插入要添加的字符此处是为了给span占位
input.getText().insert(startIndex, "@" + nameStr);
//1使用mEditText构造一个SpannableString
StringBuffer atName = new StringBuffer();
atName.append("@").append(nameStr);
spannableStringBuilder.append(atName.toString());
AtUserForegroundColorSpan span = new AtUserForegroundColorSpan(Color.parseColor("#2a92f7"));
span.setAtContent(atName.toString());
span.setUid(model.getId());
span.setName(nameStr);
spannableStringBuilder.setSpan(span,
startIndex, endIndex + 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
input.setTextKeepState(spannableStringBuilder);
input.setOnKeyListener((v, keyCode, event) -> {
if (keyCode == KeyEvent.KEYCODE_DEL && event.getAction() == KeyEvent.ACTION_DOWN) {
if (removeListener) {
input.addTextChangedListener(AtTextWatcher.this);
removeListener = false;
}
}
return false;
});
}
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
beforeStr = new SpannableStringBuilder(s);
}
@Override
public void onTextChanged(CharSequence afterStr, int start, int before, int count) {
afterText = new SpannableStringBuilder(afterStr);
}
@Override
public void afterTextChanged(Editable s) {
boolean change = false;
if (!TextUtils.isEmpty(beforeStr)) {
if (afterText.length() < beforeStr.length()) {//删除内容的操作
SpannableStringBuilder beforeSp = beforeStr;
AtUserForegroundColorSpan[] beforeSpans = beforeSp.getSpans(0, beforeSp.length(), AtUserForegroundColorSpan.class);
for (AtUserForegroundColorSpan span : beforeSpans) {
if (!s.toString().contains(span.getAtContent())) {
beforeSp.replace(beforeSp.getSpanStart(span), beforeSp.getSpanEnd(span), "");
beforeSp.removeSpan(span);
spanMap.remove(span.getUid());
input.removeTextChangedListener(this);
removeListener = true;
change = true;
}
}
beforeStr = null;
if (change) {
input.setTextKeepState(beforeSp);
spannableStringBuilder = beforeSp;
} else {
input.setTextKeepState(afterText);
spannableStringBuilder = afterText;
}
}
}
}
}

View File

@ -0,0 +1,40 @@
package com.yunbao.common.views.weight;
import android.text.style.ForegroundColorSpan;
public class AtUserForegroundColorSpan extends ForegroundColorSpan {
public String name;
public String uid;
public String atContent;
public AtUserForegroundColorSpan(int color) {
super(color);
}
public String getUid() {
return uid;
}
public AtUserForegroundColorSpan setUid(String uid) {
this.uid = uid;
return this;
}
public String getName() {
return name;
}
public AtUserForegroundColorSpan setName(String name) {
this.name = name;
return this;
}
public String getAtContent() {
return atContent;
}
public AtUserForegroundColorSpan setAtContent(String atContent) {
this.atContent = atContent;
return this;
}
}

View File

@ -10,9 +10,9 @@ ext {
manifestPlaceholders = [
//
serverHost : "https://napi.yaoulive.com",
// serverHost : "https://napi.yaoulive.com",
//
// serverHost : "https://ceshi.yaoulive.com",
serverHost : "https://ceshi.yaoulive.com",
//
txMapAppKey : "EOZBZ-ASLCU-4XPV3-BDCHZ-4E3Q7-H4BWB",

View File

@ -31,6 +31,7 @@ public class OlineListAdapter extends RecyclerView.Adapter {
}
public void addAll(List<Map<Integer, List<OlineUserlistModel>>> models) {
mapList.clear();
mapList.addAll(models);
notifyDataSetChanged();
}

View File

@ -19,6 +19,7 @@ public class OlineListItemAdapter extends RecyclerView.Adapter {
private List<OlineUserlistModel> models = new ArrayList<>();
public void addAll(List<OlineUserlistModel> userlistModels) {
models.clear();
models.addAll(userlistModels);
notifyDataSetChanged();
}

View File

@ -31,17 +31,23 @@ import com.yunbao.common.bean.BaseModel;
import com.yunbao.common.bean.NobleTrumpetModel;
import com.yunbao.common.custom.MyRadioButton;
import com.yunbao.common.dialog.AbsDialogFragment;
import com.yunbao.common.event.LiveInputEvent;
import com.yunbao.common.http.base.HttpCallback;
import com.yunbao.common.http.live.LiveNetManager;
import com.yunbao.common.utils.Bus;
import com.yunbao.common.utils.DpUtil;
import com.yunbao.common.utils.ToastUtil;
import com.yunbao.common.utils.WordUtil;
import com.yunbao.common.views.weight.AtTextWatcher;
import com.yunbao.common.views.weight.ViewClicksAntiShake;
import com.yunbao.live.R;
import com.yunbao.live.activity.LiveActivity;
import com.yunbao.live.activity.LiveRyAnchorActivity;
import com.yunbao.live.views.OlineListActivity;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import java.util.ArrayList;
import java.util.List;
@ -69,7 +75,7 @@ public class LiveInputDialogFragment extends AbsDialogFragment implements View.O
private long nobleId;//贵族等级
private long trumpetNum;//喇叭数量
private String mLiveUid;//主播ID
private AtTextWatcher atTextWatcher;
@Override
protected int getLayoutId() {
@ -100,7 +106,7 @@ public class LiveInputDialogFragment extends AbsDialogFragment implements View.O
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
Bus.getOn(this);
imm = (InputMethodManager) mContext.getSystemService(INPUT_METHOD_SERVICE);
mInput = (EditText) mRootView.findViewById(R.id.input);
radioHornType = mRootView.findViewById(R.id.radio_horn_type);
@ -185,7 +191,8 @@ public class LiveInputDialogFragment extends AbsDialogFragment implements View.O
getActivity().startActivity(intent);
}
});
;
atTextWatcher = new AtTextWatcher();
}
@Override
@ -247,6 +254,7 @@ public class LiveInputDialogFragment extends AbsDialogFragment implements View.O
@Override
public void onDestroy() {
super.onDestroy();
Bus.getOff(this);
mContext = null;
}
@ -356,4 +364,10 @@ public class LiveInputDialogFragment extends AbsDialogFragment implements View.O
}
};
@Subscribe(threadMode = ThreadMode.MAIN)
public void onLiveInputEvent(LiveInputEvent event) {
atTextWatcher.insertTextForAt(event.getModel(), mInput);
}
}

View File

@ -1,5 +1,9 @@
package com.yunbao.live.views;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.widget.EditText;
import android.widget.TextView;
import androidx.recyclerview.widget.LinearLayoutManager;
@ -9,11 +13,18 @@ import com.blankj.utilcode.util.GsonUtils;
import com.yunbao.common.activity.AbsActivity;
import com.yunbao.common.bean.OlineModel;
import com.yunbao.common.bean.OlineUserlistModel;
import com.yunbao.common.event.LiveInputEvent;
import com.yunbao.common.event.OlineEvent;
import com.yunbao.common.http.HttpCallback;
import com.yunbao.common.utils.Bus;
import com.yunbao.common.utils.WordsTypeUtil;
import com.yunbao.live.R;
import com.yunbao.live.adapter.OlineListAdapter;
import com.yunbao.live.http.LiveHttpUtil;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@ -22,6 +33,8 @@ import java.util.Map;
public class OlineListActivity extends AbsActivity {
private RecyclerView audienceList;
private OlineListAdapter itemAdapter;
private EditText edit;
private List<OlineUserlistModel> userlistModels = null;
@Override
@ -32,6 +45,7 @@ public class OlineListActivity extends AbsActivity {
@Override
protected void main() {
super.main();
Bus.getOn(this);
initView();
initData();
}
@ -47,40 +61,140 @@ public class OlineListActivity extends AbsActivity {
@Override
public void onSuccess(int code, String msg, String[] info) {
OlineModel responseData = GsonUtils.fromJson(info[0], OlineModel.class);
List<OlineUserlistModel> userlistModels = responseData.getUserlist();
List<OlineUserlistModel> noblelistModels = new ArrayList<>();
List<OlineUserlistModel> audiencelistModels = new ArrayList<>();
List<Map<Integer, List<OlineUserlistModel>>> mapList = new ArrayList<>();
//讲贵族前置顺序
for (OlineUserlistModel model : userlistModels) {
int nobleId = Integer.parseInt(model.getNobleId());
if (nobleId > 0) {
noblelistModels.add(model);
} else {
audiencelistModels.add(model);
}
}
Map<Integer, List<OlineUserlistModel>> noblerMap = new HashMap<>();
noblerMap.put(0, noblelistModels);
Map<Integer, List<OlineUserlistModel>> audienceMap = new HashMap<>();
audienceMap.put(1,audiencelistModels);
mapList.add(0,noblerMap);
mapList.add(1, audienceMap);
itemAdapter.addAll(mapList);
userlistModels = responseData.getUserlist();
starData();
}
});
}
/**
* 原始数据
*/
private void starData() {
List<OlineUserlistModel> noblelistModels = new ArrayList<>();
List<OlineUserlistModel> audiencelistModels = new ArrayList<>();
List<Map<Integer, List<OlineUserlistModel>>> mapList = new ArrayList<>();
//讲贵族前置顺序
for (OlineUserlistModel model : userlistModels) {
int nobleId = Integer.parseInt(model.getNobleId());
if (nobleId > 0) {
noblelistModels.add(model);
} else {
audiencelistModels.add(model);
}
}
Map<Integer, List<OlineUserlistModel>> noblerMap = new HashMap<>();
noblerMap.put(0, noblelistModels);
Map<Integer, List<OlineUserlistModel>> audienceMap = new HashMap<>();
audienceMap.put(1, audiencelistModels);
mapList.add(0, noblerMap);
mapList.add(1, audienceMap);
itemAdapter.addAll(mapList);
}
/**
* 初始化控件
*/
private void initView() {
itemAdapter = new OlineListAdapter(mContext);
audienceList = findViewById(R.id.audience_list);
TextView titleView = findViewById(R.id.titleView);
TextView titleView = findViewById(R.id.titleView);
titleView.setText(R.string.online_audience);
audienceList.setLayoutManager(new LinearLayoutManager(mContext, LinearLayoutManager.VERTICAL, false));
audienceList.setAdapter(itemAdapter);
edit = findViewById(R.id.edit);
edit.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (!TextUtils.isEmpty(s.toString().trim())) {
//繁体转成简体
String simplified = WordsTypeUtil.changeSimplified(s.toString());
//简体转繁体
String traditional = WordsTypeUtil.changeTraditional(s.toString());
if (TextUtils.equals(simplified, traditional)) {
searchList(simplified, null);
} else {
searchList(simplified, traditional);
}
} else {
starData();
}
}
@Override
public void afterTextChanged(Editable s) {
}
});
}
private void searchList(String keyWorld, String keyWorld2) {
if (userlistModels == null) return;
if (TextUtils.isEmpty(keyWorld2)) {
List<OlineUserlistModel> noblelistModels = new ArrayList<>();
List<OlineUserlistModel> audiencelistModels = new ArrayList<>();
List<Map<Integer, List<OlineUserlistModel>>> mapList = new ArrayList<>();
//讲贵族前置顺序
for (OlineUserlistModel model : userlistModels) {
int nobleId = Integer.parseInt(model.getNobleId());
if (nobleId > 0 && model.getUserNicename().contains(keyWorld)) {
noblelistModels.add(model);
} else if (nobleId == 0 && model.getUserNicename().contains(keyWorld)) {
audiencelistModels.add(model);
}
}
Map<Integer, List<OlineUserlistModel>> noblerMap = new HashMap<>();
noblerMap.put(0, noblelistModels);
Map<Integer, List<OlineUserlistModel>> audienceMap = new HashMap<>();
audienceMap.put(1, audiencelistModels);
mapList.add(0, noblerMap);
mapList.add(1, audienceMap);
itemAdapter.addAll(mapList);
} else {
List<OlineUserlistModel> noblelistModels = new ArrayList<>();
List<OlineUserlistModel> audiencelistModels = new ArrayList<>();
List<Map<Integer, List<OlineUserlistModel>>> mapList = new ArrayList<>();
//讲贵族前置顺序
for (OlineUserlistModel model : userlistModels) {
int nobleId = Integer.parseInt(model.getNobleId());
if (nobleId > 0 && model.getUserNicename().contains(keyWorld)) {
noblelistModels.add(model);
} else if (nobleId == 0 && model.getUserNicename().contains(keyWorld)) {
audiencelistModels.add(model);
} else if (nobleId > 0 && model.getUserNicename().contains(keyWorld2)) {
noblelistModels.add(model);
} else if (nobleId == 0 && model.getUserNicename().contains(keyWorld2)) {
audiencelistModels.add(model);
}
}
Map<Integer, List<OlineUserlistModel>> noblerMap = new HashMap<>();
noblerMap.put(0, noblelistModels);
Map<Integer, List<OlineUserlistModel>> audienceMap = new HashMap<>();
audienceMap.put(1, audiencelistModels);
mapList.add(0, noblerMap);
mapList.add(1, audienceMap);
itemAdapter.addAll(mapList);
}
}
@Override
protected void onDestroy() {
super.onDestroy();
Bus.getOff(this);
}
@Subscribe(threadMode = ThreadMode.MAIN)
public void onOlineEvent(OlineEvent event) {
Bus.get().post(new LiveInputEvent().setModel(event.getModel()));
finish();
}
}

View File

@ -7,8 +7,11 @@ import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.yunbao.common.bean.OlineUserlistModel;
import com.yunbao.common.event.OlineEvent;
import com.yunbao.common.glide.ImgLoader;
import com.yunbao.common.utils.Bus;
import com.yunbao.common.views.weight.ClipPathCircleImage;
import com.yunbao.common.views.weight.ViewClicksAntiShake;
import com.yunbao.live.R;
public class OlineListItemViewHolder extends RecyclerView.ViewHolder {
@ -29,5 +32,11 @@ public class OlineListItemViewHolder extends RecyclerView.ViewHolder {
public void setData(OlineUserlistModel model) {
ImgLoader.displayAvatar(itemView.getContext(), model.getAvatar(), avatar);
userName.setText(model.getUserNicename());
ViewClicksAntiShake.clicksAntiShake(itemView, new ViewClicksAntiShake.ViewClicksCallBack() {
@Override
public void onViewClicks() {
Bus.get().post(new OlineEvent().setModel(model));
}
});
}
}

View File

@ -82,8 +82,6 @@ dependencies {
implementation 'com.justkiddingbaby:slidemenu:1.3.0'
implementation 'com.xj.marqueeView:marqueeView:0.1.20'
implementation 'com.google.android.gms:play-services-auth:15.0.0'
//Google
implementation files('libs/jcc-bate-0.7.3.jar')
//
implementation 'com.binioter:guideview:1.0.0'
}

View File

@ -26,12 +26,11 @@ import com.yunbao.common.utils.RouteUtil;
import com.yunbao.live.activity.LiveAudienceActivity;
import com.yunbao.live.bean.LiveBean;
import com.yunbao.live.http.LiveHttpUtil;
import com.yunbao.live.presenter.LiveRoomCheckLivePresenter;
import com.yunbao.main.R;
import com.yunbao.main.event.JumpUserHomeEvent;
import com.yunbao.main.fragment.SearchRecommendFragment;
import com.yunbao.main.fragment.SearchResultsFragment;
import com.yunbao.main.utils.WordsTypeUtil;
import com.yunbao.common.utils.WordsTypeUtil;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

View File

@ -20,7 +20,7 @@ import com.yunbao.common.views.weight.OnRecyclerViewScrollListener;
import com.yunbao.main.R;
import com.yunbao.main.adapter.SearchRecommendBodyAdapter;
import com.yunbao.main.adapter.SearchResultsItemAdapter;
import com.yunbao.main.utils.WordsTypeUtil;
import com.yunbao.common.utils.WordsTypeUtil;
import java.util.ArrayList;
import java.util.List;

View File

@ -21,7 +21,7 @@ import com.yunbao.common.utils.Bus;
import com.yunbao.common.views.weight.ViewClicksAntiShake;
import com.yunbao.main.R;
import com.yunbao.main.event.JumpUserHomeEvent;
import com.yunbao.main.utils.WordsTypeUtil;
import com.yunbao.common.utils.WordsTypeUtil;
public class SearchResultsViewHolder extends RecyclerView.ViewHolder {
private ImageView avatar, isLive, sex, focusOn, contribute;