Kotlin高仿微信-第19篇-单聊-删除全部
实现代码:
//长按
adapter.setOnItemLongClickInterface(object : WcOnItemLongClickInterface{
override fun onItemLongClick(position: Int) {
showDeleteDialog(position)
}
})
private var baseDialogUtils : BaseDialogUtils? = null
//显示删除对话框
fun showDeleteDialog(position : Int){
var view = LayoutInflater.from(this.requireActivity()).inflate(R.layout.wc_chat_delete_tip, null)
baseDialogUtils = BaseDialogUtils(this.requireActivity())
baseDialogUtils!!.builder()
.showView(view)
.setCancelable(false)
.setOnLoadingClick(object : BaseDialogUtils.OnLoadingClick{
override fun onClickCancel() {
}
override fun onClickConfirm() {
var chatTempBean = adapter.getItemObject(position)
if(chatTempBean!=null){
chatViewModel.deleteChatByFromAndToAccount(account, chatTempBean.account)
}
adapter.remove(position)
}
})
baseDialogUtils?.show()
}
//清空我和该朋友的所有聊天记录
fun deleteChatByFromAndToAccount(fromAccount: String, toAccount: String) {
CoroutineScope(Dispatchers.IO).launch {
ChatRepository.deleteChatByFromAndToAccount(fromAccount, toAccount)
}
}
上一篇:
uniapp开发微信小程序-2.页面制作
