机器人自动发言
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
package com.yunbao.common.adapter;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.yunbao.common.R;
|
||||
import com.yunbao.common.bean.LiveAiRobotBean;
|
||||
import com.yunbao.common.views.RobotSayHelloViewHoler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class RobotSayHelloAdapter extends RecyclerView.Adapter {
|
||||
private List<LiveAiRobotBean.Message> messageList = new ArrayList<>();
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View robotSayHelloView = LayoutInflater.from(parent.getContext()).inflate(R.layout.view_robot_message, parent, false);
|
||||
return new RobotSayHelloViewHoler(robotSayHelloView);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
|
||||
RobotSayHelloViewHoler robotSayHelloViewHoler = (RobotSayHelloViewHoler) holder;
|
||||
robotSayHelloViewHoler.setData(messageList.get(position), position + 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return messageList.size();
|
||||
}
|
||||
|
||||
|
||||
public void setDataAll(List<LiveAiRobotBean.Message> messages) {
|
||||
messageList.clear();
|
||||
messageList.addAll(messages);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
// 删除数据
|
||||
public void removeData(int position) {
|
||||
messageList.remove(position);
|
||||
//删除动画
|
||||
notifyItemRemoved(position);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.yunbao.common.event;
|
||||
|
||||
import com.yunbao.common.bean.BaseModel;
|
||||
|
||||
public class LiveRobotSayHelloEvent extends BaseModel {
|
||||
private int index = -1;
|
||||
|
||||
public int getIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
public LiveRobotSayHelloEvent setIndex(int index) {
|
||||
this.index = index;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
package com.yunbao.common.views;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.lxj.xpopup.XPopup;
|
||||
import com.lxj.xpopup.core.BottomPopupView;
|
||||
import com.yunbao.common.R;
|
||||
import com.yunbao.common.adapter.RobotSayHelloAdapter;
|
||||
import com.yunbao.common.bean.HttpCallbackModel;
|
||||
import com.yunbao.common.bean.LiveAiRobotBean;
|
||||
import com.yunbao.common.event.LiveRobotSayHelloEvent;
|
||||
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.ToastUtil;
|
||||
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class LiveRobotSayHelloCustomPopup extends BottomPopupView {
|
||||
private RecyclerView robotMessages;
|
||||
private RobotSayHelloAdapter robotMessageAdapter;
|
||||
private static String TAG = "AI机器人";
|
||||
|
||||
public LiveRobotSayHelloCustomPopup(@NonNull Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
|
||||
// 返回自定义弹窗的布局
|
||||
@Override
|
||||
protected int getImplLayoutId() {
|
||||
return R.layout.dialog_live_robot_say_hello;
|
||||
}
|
||||
|
||||
// 执行初始化操作,比如:findView,设置点击,或者任何你弹窗内的业务逻辑
|
||||
@Override
|
||||
protected void onCreate() {
|
||||
super.onCreate();
|
||||
Bus.getOn(this);
|
||||
initView();
|
||||
initDate();
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onLiveRobotSayHelloEvent(LiveRobotSayHelloEvent event) {
|
||||
if (event.getIndex() > 0) {
|
||||
robotMessageAdapter.removeData(event.getIndex());
|
||||
} else {
|
||||
initDate();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
Bus.getOff(this);
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
robotMessages = (RecyclerView) findViewById(R.id.robot_messages);
|
||||
robotMessageAdapter = new RobotSayHelloAdapter();
|
||||
robotMessages.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false));
|
||||
robotMessages.setAdapter(robotMessageAdapter);
|
||||
findViewById(R.id.bt_cancel).setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dismiss();
|
||||
}
|
||||
});
|
||||
//添加消息语
|
||||
findViewById(R.id.robot_add_content).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
new XPopup.Builder(getContext())
|
||||
.asCustom(new InputCustomPopup(getContext()).setListener(new InputCustomPopup.InputCustomListener() {
|
||||
@Override
|
||||
public void onConfirm(String text) {
|
||||
//添加消息语
|
||||
LiveNetManager.get(getContext())
|
||||
.addAiRobotBody(LiveAiRobotBean.Message.TYPE_SAY_HI, text, new HttpCallback<HttpCallbackModel>() {
|
||||
@Override
|
||||
public void onSuccess(HttpCallbackModel data) {
|
||||
initDate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(String error) {
|
||||
ToastUtil.show(error);
|
||||
}
|
||||
});
|
||||
}
|
||||
}))
|
||||
.show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private void initDate() {
|
||||
LiveNetManager.get(getContext())
|
||||
.getAiRobotBody(LiveAiRobotBean.Message.TYPE_SAY_HI, new HttpCallback<List<LiveAiRobotBean.Message>>() {
|
||||
@Override
|
||||
public void onSuccess(List<LiveAiRobotBean.Message> data) {
|
||||
Log.i(TAG, "onSuccess 自动打招呼 : " + data.size());
|
||||
for (LiveAiRobotBean.Message message : data) {
|
||||
Log.i(TAG, "onSuccess: message=" + message.toString());
|
||||
}
|
||||
robotMessageAdapter.setDataAll(data);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(String error) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -61,6 +61,7 @@ public class LiveRobotSettingCustomPopup extends BottomPopupView implements View
|
||||
automaticGreetingNumber = findViewById(R.id.automatic_greeting_number);
|
||||
automaticMessageNumber = findViewById(R.id.automatic_message_number);
|
||||
findViewById(R.id.automatic_message_sending).setOnClickListener(this);
|
||||
findViewById(R.id.automatic_greeting_setting).setOnClickListener(this);
|
||||
robotNameText.setOnClickListener(this);
|
||||
robotState.setOnClickListener(this);
|
||||
|
||||
@@ -167,10 +168,10 @@ public class LiveRobotSettingCustomPopup extends BottomPopupView implements View
|
||||
public void onSuccess(HttpCallbackModel data) {
|
||||
if (finalState == 1) {
|
||||
robotState.setImageResource(R.mipmap.special_icon_on);
|
||||
robotStateInt=1;
|
||||
robotStateInt = 1;
|
||||
} else {
|
||||
robotState.setImageResource(R.mipmap.special_icon_off);
|
||||
robotStateInt=0;
|
||||
robotStateInt = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -179,6 +180,56 @@ public class LiveRobotSettingCustomPopup extends BottomPopupView implements View
|
||||
ToastUtil.show(error);
|
||||
}
|
||||
});
|
||||
} else if (viewID == R.id.automatic_greeting_setting) {
|
||||
new XPopup.Builder(getContext())
|
||||
.setPopupCallback(new XPopupCallback() {
|
||||
@Override
|
||||
public void onCreated(BasePopupView popupView) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeShow(BasePopupView popupView) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onShow(BasePopupView popupView) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDismiss(BasePopupView popupView) {
|
||||
initDate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeDismiss(BasePopupView popupView) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBackPressed(BasePopupView popupView) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onKeyBoardStateChanged(BasePopupView popupView, int height) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDrag(BasePopupView popupView, int value, float percent, boolean upOrLeft) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClickOutside(BasePopupView popupView) {
|
||||
|
||||
}
|
||||
})
|
||||
.asCustom(new LiveRobotSayHelloCustomPopup(getContext()))
|
||||
.show();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -209,23 +260,7 @@ public class LiveRobotSettingCustomPopup extends BottomPopupView implements View
|
||||
|
||||
|
||||
private void initListType1() {
|
||||
LiveNetManager.get(getContext())
|
||||
.getAiRobotBody(LiveAiRobotBean.Message.TYPE_SAY_HI, new HttpCallback<List<LiveAiRobotBean.Message>>() {
|
||||
@Override
|
||||
public void onSuccess(List<LiveAiRobotBean.Message> data) {
|
||||
Log.i(TAG, "onSuccess 自动打招呼 : " + data.size());
|
||||
for (LiveAiRobotBean.Message message : data) {
|
||||
Log.i(TAG, "onSuccess: message=" + message.toString());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(String error) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void initListType2() {
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
package com.yunbao.common.views;
|
||||
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.lxj.xpopup.XPopup;
|
||||
import com.yunbao.common.R;
|
||||
import com.yunbao.common.bean.HttpCallbackModel;
|
||||
import com.yunbao.common.bean.LiveAiRobotBean;
|
||||
import com.yunbao.common.event.LiveRobotSayHelloEvent;
|
||||
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.ToastUtil;
|
||||
|
||||
public class RobotSayHelloViewHoler extends RecyclerView.ViewHolder {
|
||||
private TextView serialNumber, messageText;
|
||||
private ImageView btnDelete;
|
||||
|
||||
public RobotSayHelloViewHoler(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
serialNumber = itemView.findViewById(R.id.serial_number);
|
||||
messageText = itemView.findViewById(R.id.message_text);
|
||||
btnDelete = itemView.findViewById(R.id.btn_delete);
|
||||
}
|
||||
|
||||
|
||||
public void setData(LiveAiRobotBean.Message message, int index) {
|
||||
serialNumber.setText(String.valueOf(index));
|
||||
messageText.setText(message.getContent());
|
||||
btnDelete.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
LiveNetManager.get(itemView.getContext())
|
||||
.delAiRobotBody(LiveAiRobotBean.Message.TYPE_SAY_HI, message.getId(), new HttpCallback<HttpCallbackModel>() {
|
||||
@Override
|
||||
public void onSuccess(HttpCallbackModel data) {
|
||||
Bus.get().post(new LiveRobotSayHelloEvent().setIndex(index - 1));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(String error) {
|
||||
ToastUtil.show(error);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
messageText.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
new XPopup.Builder(itemView.getContext())
|
||||
.asCustom(new InputCustomPopup(itemView.getContext(), message.getContent()).setListener(new InputCustomPopup.InputCustomListener() {
|
||||
@Override
|
||||
public void onConfirm(String text) {
|
||||
LiveNetManager.get(itemView.getContext())
|
||||
.updateAiRobotBody(LiveAiRobotBean.Message.TYPE_SAY_HI, message.getId(), text, new HttpCallback<HttpCallbackModel>() {
|
||||
@Override
|
||||
public void onSuccess(HttpCallbackModel data) {
|
||||
Bus.get().post(new LiveRobotSayHelloEvent());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(String error) {
|
||||
ToastUtil.show(error);
|
||||
}
|
||||
});
|
||||
}
|
||||
}))
|
||||
.show();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user