|
|
package com.br_technology.securitytrain_master.ui.view.mine.activity
|
|
|
|
|
|
import com.br_technology.securitytrain_master.databinding.ActivityChatRecordBinding
|
|
|
import android.os.Handler
|
|
|
import android.os.Looper
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager
|
|
|
import com.br_technology.securitytrain_master.databinding.ActivityChatBinding
|
|
|
import com.br_technology.securitytrain_master.expand.hideSoftInputFromWindow
|
|
|
import com.br_technology.securitytrain_master.ui.view.mine.adapter.ChatAdapter
|
|
|
import com.br_technology.securitytrain_master.ui.view.mine.bean.ChatDetailBean
|
|
|
import com.br_technology.securitytrain_master.ui.view.mine.viewmodel.ChatRecordViewModel
|
|
|
import com.gyf.immersionbar.ImmersionBar
|
|
|
import com.scwang.smart.refresh.header.ClassicsHeader
|
|
|
import com.wjx.android.wanandroidmvvm.base.view.BaseLifeCycleActivity
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -11,15 +19,80 @@ import com.wjx.android.wanandroidmvvm.base.view.BaseLifeCycleActivity |
|
|
* updateInfo:
|
|
|
*/
|
|
|
class ChatActivity :
|
|
|
BaseLifeCycleActivity<ChatRecordViewModel, ActivityChatRecordBinding>(ActivityChatRecordBinding::inflate) {
|
|
|
BaseLifeCycleActivity<ChatRecordViewModel, ActivityChatBinding>(ActivityChatBinding::inflate) {
|
|
|
|
|
|
companion object {
|
|
|
init {
|
|
|
ClassicsHeader.REFRESH_HEADER_PULLING = "下拉可以加载...";
|
|
|
ClassicsHeader.REFRESH_HEADER_REFRESHING = "正在加载...";
|
|
|
ClassicsHeader.REFRESH_HEADER_RELEASE = "释放立即加载";
|
|
|
ClassicsHeader.REFRESH_HEADER_FINISH = "加载完成";
|
|
|
ClassicsHeader.REFRESH_HEADER_FAILED = "加载失败";
|
|
|
}
|
|
|
}
|
|
|
|
|
|
val adapter: ChatAdapter by lazy {
|
|
|
ChatAdapter()
|
|
|
}
|
|
|
private var page = 1
|
|
|
private var teacherId = -1
|
|
|
|
|
|
override fun initDataObserver() {
|
|
|
mViewModel.detailLiveData.observe(this) {
|
|
|
it.data.detail.data.forEach { bean ->
|
|
|
bean.itemType = if (bean.from_id_type == "1") 0 else 1
|
|
|
}
|
|
|
|
|
|
if (it.data.detail.data.size < 10) {
|
|
|
binding.smartRefresh.finishRefreshWithNoMoreData()
|
|
|
}
|
|
|
if (page == 1) {
|
|
|
binding.chatRv.scrollToPosition(0)
|
|
|
adapter.setNewInstance(it.data.detail.data as MutableList<ChatDetailBean>)
|
|
|
} else {
|
|
|
adapter.addData(it.data.detail.data)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
mViewModel.sendLiveData.observe(this) {
|
|
|
showTip("发送成功")
|
|
|
binding.root.hideSoftInputFromWindow()
|
|
|
binding.chatSend.isClickable = true
|
|
|
binding.chatContent.setText("")
|
|
|
page = 1
|
|
|
// 请求网络
|
|
|
mViewModel.msgDetail(page, teacherId)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
override fun initData() {
|
|
|
super.initData()
|
|
|
ImmersionBar.with(this).transparentStatusBar().keyboardEnable(true).statusBarDarkFont(true)
|
|
|
.init()
|
|
|
|
|
|
// 教师id
|
|
|
teacherId = intent.getIntExtra("id", -1)
|
|
|
// 请求网络
|
|
|
mViewModel.msgDetail(page, teacherId)
|
|
|
binding.apply {
|
|
|
// chatRv.adapter=
|
|
|
|
|
|
smartRefresh.setOnRefreshListener {
|
|
|
++page
|
|
|
mViewModel.msgDetail(page, teacherId)
|
|
|
smartRefresh.finishRefresh()
|
|
|
}
|
|
|
// 倒叙显示
|
|
|
val manager = LinearLayoutManager(baseContext, LinearLayoutManager.VERTICAL, true)
|
|
|
manager.stackFromEnd = true
|
|
|
chatRv.layoutManager = manager
|
|
|
// 设置适配器
|
|
|
chatRv.adapter = adapter
|
|
|
// 发送评论
|
|
|
chatSend.setOnClickListener {
|
|
|
chatSend.isClickable = false
|
|
|
val content = chatContent.text.toString()
|
|
|
mViewModel.sendMsg(content, teacherId)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
} |
|
|
\ No newline at end of file |
...
|
...
|
|