2025-10-20 10:16:44 +08:00
|
|
|
package com.xscm.moduleutil.widget;
|
|
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
import android.os.CountDownTimer;
|
|
|
|
|
import android.text.TextUtils;
|
|
|
|
|
import android.util.AttributeSet;
|
|
|
|
|
import android.view.LayoutInflater;
|
|
|
|
|
import android.view.View;
|
|
|
|
|
import android.widget.Button;
|
|
|
|
|
import android.widget.EditText;
|
|
|
|
|
|
|
|
|
|
import androidx.constraintlayout.widget.ConstraintLayout;
|
|
|
|
|
|
|
|
|
|
import com.blankj.utilcode.util.KeyboardUtils;
|
|
|
|
|
import com.hjq.toast.ToastUtils;
|
|
|
|
|
import com.xscm.moduleutil.R;
|
|
|
|
|
import com.xscm.moduleutil.bean.RoomInputEvent;
|
|
|
|
|
import com.xscm.moduleutil.event.RoomInputHideEvent;
|
|
|
|
|
|
|
|
|
|
import org.greenrobot.eventbus.EventBus;
|
|
|
|
|
|
|
|
|
|
public class RoomMessageInputMenu extends ConstraintLayout {
|
|
|
|
|
EditText etContent;
|
|
|
|
|
Button tvSend;
|
|
|
|
|
private View rootView;
|
|
|
|
|
private int screenHeight;
|
|
|
|
|
public RoomMessageInputMenu(Context context) {
|
|
|
|
|
this(context, null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public RoomMessageInputMenu(Context context, AttributeSet attrs) {
|
|
|
|
|
super(context, attrs);
|
|
|
|
|
LayoutInflater.from(context).inflate(R.layout.room_message_input_menu, this);
|
|
|
|
|
etContent = findViewById(R.id.et_content);
|
|
|
|
|
tvSend = findViewById(R.id.tv_send);
|
|
|
|
|
tvSend.setOnClickListener(new OnClickListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onClick(View v) {
|
|
|
|
|
onViewClicked(v);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
setVisibility(GONE);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
private void moveInputMenuAboveKeyboard(int keypadHeight) {
|
|
|
|
|
// 调整输入框的位置
|
|
|
|
|
ConstraintLayout.LayoutParams params = (ConstraintLayout.LayoutParams) this.getLayoutParams();
|
|
|
|
|
params.bottomMargin = keypadHeight;
|
|
|
|
|
this.setLayoutParams(params);
|
|
|
|
|
}
|
|
|
|
|
public void setText(String text) {
|
|
|
|
|
etContent.setText(text);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void onViewClicked(View view) {
|
|
|
|
|
if (!canSend) {
|
|
|
|
|
ToastUtils.show("消息发送较频繁~");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
String text = etContent.getText().toString();
|
|
|
|
|
if (TextUtils.isEmpty(text)) {
|
2025-10-24 17:52:11 +08:00
|
|
|
ToastUtils.show("请输入内容");
|
2025-10-20 10:16:44 +08:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// ApiClient.getInstance().sendTxtFilter(text,new BaseObserver<String>() {
|
|
|
|
|
// @Override
|
|
|
|
|
// public void onSubscribe(Disposable d) {
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// @Override
|
|
|
|
|
// public void onNext(String s) {
|
|
|
|
|
// EventBus.getDefault().post(new RoomInputEvent(text));
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// @Override
|
|
|
|
|
// public void onComplete() {
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
// });
|
|
|
|
|
sendInput(text);
|
|
|
|
|
dismiss();
|
|
|
|
|
etContent.setText("");
|
|
|
|
|
countDownTimer();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
private void sendInput(String text) {
|
|
|
|
|
EventBus.getDefault().post(new RoomInputEvent(text));
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 下面的内容为发送消息逻辑
|
|
|
|
|
*/
|
|
|
|
|
private CountDownTimer mCountDownTimer;
|
|
|
|
|
private boolean canSend = true;
|
|
|
|
|
|
|
|
|
|
private void countDownTimer() {
|
|
|
|
|
releaseCountDownTimer();
|
|
|
|
|
mCountDownTimer = new CountDownTimer(3 * 1000L, 1000L) {
|
|
|
|
|
@Override
|
|
|
|
|
public void onTick(long millisUntilFinished) {
|
|
|
|
|
canSend = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onFinish() {
|
|
|
|
|
canSend = true;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
mCountDownTimer.start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onDetachedFromWindow() {
|
|
|
|
|
releaseCountDownTimer();
|
|
|
|
|
super.onDetachedFromWindow();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void releaseCountDownTimer() {
|
|
|
|
|
if (mCountDownTimer != null) {
|
|
|
|
|
mCountDownTimer.cancel();
|
|
|
|
|
mCountDownTimer = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void show() {
|
|
|
|
|
setVisibility(VISIBLE);
|
|
|
|
|
etContent.requestFocus();
|
|
|
|
|
KeyboardUtils.showSoftInput(etContent);
|
|
|
|
|
EventBus.getDefault().post(new RoomInputHideEvent(false));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void dismiss() {
|
|
|
|
|
setVisibility(GONE);
|
|
|
|
|
KeyboardUtils.hideSoftInput(etContent);
|
|
|
|
|
EventBus.getDefault().post(new RoomInputHideEvent(true));
|
|
|
|
|
}
|
|
|
|
|
}
|