feat:完善公聊页细节实现
feat:对接公聊ID、发布头条、获取头条接口
This commit is contained in:
@@ -880,7 +880,11 @@
|
||||
|
||||
<activity android:name=".ui.language.LanguageActivity" />
|
||||
|
||||
<activity android:name=".public_chat.ui.message.PublicChatRoomMessageActivity"/>
|
||||
<activity android:name=".public_chat.ui.message.PublicChatRoomMessageActivity"
|
||||
android:configChanges="keyboardHidden|orientation"
|
||||
android:screenOrientation="portrait"
|
||||
android:theme="@style/AppTheme.NoActionBar"
|
||||
android:windowSoftInputMode="stateHidden|adjustResize" />
|
||||
</application>
|
||||
|
||||
</manifest>
|
@@ -19,7 +19,7 @@ open class BaseViewModel : ViewModel() {
|
||||
|
||||
fun safeLaunch(
|
||||
needLoading: Boolean = false,
|
||||
onError: (e: Throwable) -> Unit = {
|
||||
onError: suspend(e: Throwable) -> Unit = {
|
||||
if (it.message != "Job was cancelled") {
|
||||
val message = ExceptionHandle.handleException(it)
|
||||
message.toast()
|
||||
|
@@ -215,8 +215,7 @@ class SettingActivity : BaseViewBindingActivity<ActivitySettingBinding>(), View.
|
||||
|
||||
private fun debug() {
|
||||
// CommonWebViewActivity.start(this,"https://api.molistar.xyz/molistar/activity/2024-invitationFission/index.html")
|
||||
startActivity(Intent(this, PublicChatRoomMessageActivity::class.java))
|
||||
|
||||
PublicChatRoomMessageActivity.start(this)
|
||||
// MyDecorationActivity.start(this,0)
|
||||
}
|
||||
}
|
@@ -1,59 +0,0 @@
|
||||
package com.chwl.app.public_chat
|
||||
|
||||
import com.example.lib_utils.log.ILog
|
||||
import com.netease.nimlib.sdk.NIMChatRoomSDK
|
||||
import com.netease.nimlib.sdk.NIMClient
|
||||
import com.netease.nimlib.sdk.RequestCallback
|
||||
import com.netease.nimlib.sdk.chatroom.ChatRoomService
|
||||
import com.netease.nimlib.sdk.chatroom.model.ChatRoomMessage
|
||||
import com.netease.nimlib.sdk.chatroom.model.EnterChatRoomData
|
||||
import com.netease.nimlib.sdk.chatroom.model.EnterChatRoomResultData
|
||||
|
||||
class PublicChatManager : ILog {
|
||||
|
||||
fun enterChatRoom(sessionId: String) {
|
||||
logD("enterChatRoom() sessionId:$sessionId")
|
||||
val enterChatRoomData = EnterChatRoomData(sessionId)
|
||||
val enterChatRoomEx =
|
||||
NIMChatRoomSDK.getChatRoomService().enterChatRoomEx(enterChatRoomData, 3)
|
||||
enterChatRoomEx.setCallback(object : RequestCallback<EnterChatRoomResultData?> {
|
||||
override fun onSuccess(param: EnterChatRoomResultData?) {
|
||||
logD("enterChatRoom() onSuccess roomId:${param?.roomId}")
|
||||
}
|
||||
|
||||
override fun onFailed(code: Int) {
|
||||
logD("enterChatRoom() onFailed code:${code}")
|
||||
}
|
||||
|
||||
override fun onException(exception: Throwable?) {
|
||||
exception?.printStackTrace()
|
||||
logD("enterChatRoom() onException exception:${exception}")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fun exitChatRoom(sessionId: String) {
|
||||
logD("exitChatRoom() sessionId:${sessionId}")
|
||||
NIMChatRoomSDK.getChatRoomService().exitChatRoom(sessionId)
|
||||
}
|
||||
|
||||
fun sendMessage(message: ChatRoomMessage) {
|
||||
logD("sendMessage() message:${message}")
|
||||
NIMClient.getService<ChatRoomService>(ChatRoomService::class.java)
|
||||
.sendMessage(message, false)
|
||||
.setCallback(object : RequestCallback<Void?> {
|
||||
override fun onSuccess(param: Void?) {
|
||||
logD("sendMessage() onSuccess")
|
||||
}
|
||||
|
||||
override fun onFailed(code: Int) {
|
||||
logD("sendMessage() onFailed code:$code")
|
||||
}
|
||||
|
||||
override fun onException(exception: Throwable) {
|
||||
exception.printStackTrace()
|
||||
logD("sendMessage() onException exception:$exception")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
@@ -1,29 +1,56 @@
|
||||
package com.chwl.app.public_chat
|
||||
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import com.chwl.app.base.BaseViewModel
|
||||
import com.chwl.app.public_chat.core.ChatRoomClient
|
||||
import com.chwl.app.public_chat.core.ChatRoomClientManager
|
||||
import com.chwl.core.bean.response.BeanResult
|
||||
import com.chwl.core.public_chat_hall.bean.HeadlineBean
|
||||
import com.chwl.core.public_chat_hall.model.PublicChatModel
|
||||
import com.chwl.core.vip.bean.VipRebateInfo
|
||||
import com.netease.nimlib.sdk.chatroom.model.ChatRoomMessage
|
||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
|
||||
class PublicChatViewModel : ViewModel() {
|
||||
class PublicChatViewModel : BaseViewModel() {
|
||||
|
||||
val model = PublicChatManager()
|
||||
var chatRoomClient: ChatRoomClient? = null
|
||||
|
||||
private var sessionId: String = "-1"
|
||||
val headlineLiveData = MutableLiveData<HeadlineBean?>()
|
||||
|
||||
fun enterChatRoom(sessionId: String) {
|
||||
this.sessionId = sessionId
|
||||
model.enterChatRoom(sessionId)
|
||||
}
|
||||
|
||||
fun exitChatRoom(sessionId: String) {
|
||||
model.exitChatRoom(sessionId)
|
||||
val sendHeadlineFlow = MutableSharedFlow<BeanResult<Any>>()
|
||||
fun init(sessionId: String) {
|
||||
chatRoomClient = ChatRoomClientManager.getClient(sessionId)
|
||||
}
|
||||
|
||||
fun sendMessage(message: ChatRoomMessage) {
|
||||
model.sendMessage(message)
|
||||
chatRoomClient?.sendMessage(message)?.doOnError {
|
||||
it.printStackTrace()
|
||||
}?.subscribe({}, {})
|
||||
}
|
||||
|
||||
fun getCurrentHeadline() {
|
||||
safeLaunch(needLoading = false, onError = {
|
||||
}) {
|
||||
val value = PublicChatModel.getCurrentHeadline()
|
||||
updateHeadline(value)
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateHeadline(headline: HeadlineBean?) {
|
||||
headlineLiveData.postValue(headline)
|
||||
}
|
||||
|
||||
fun sendHeadline(message: String) {
|
||||
safeLaunch(needLoading = true, onError = {
|
||||
sendHeadlineFlow.emit(BeanResult.failed(it))
|
||||
}) {
|
||||
PublicChatModel.sendHeadline(message)
|
||||
sendHeadlineFlow.emit(BeanResult.success(true))
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCleared() {
|
||||
super.onCleared()
|
||||
exitChatRoom(sessionId)
|
||||
}
|
||||
}
|
@@ -0,0 +1,125 @@
|
||||
package com.chwl.app.public_chat.core
|
||||
|
||||
import com.chwl.core.utils.net.RxHelper
|
||||
import com.example.lib_utils.ICleared
|
||||
import com.example.lib_utils.log.ILog
|
||||
import com.netease.nim.uikit.api.model.NimException
|
||||
import com.netease.nimlib.sdk.NIMChatRoomSDK
|
||||
import com.netease.nimlib.sdk.NIMClient
|
||||
import com.netease.nimlib.sdk.Observer
|
||||
import com.netease.nimlib.sdk.RequestCallback
|
||||
import com.netease.nimlib.sdk.StatusCode
|
||||
import com.netease.nimlib.sdk.chatroom.ChatRoomService
|
||||
import com.netease.nimlib.sdk.chatroom.model.ChatRoomMessage
|
||||
import com.netease.nimlib.sdk.chatroom.model.ChatRoomStatusChangeData
|
||||
import com.netease.nimlib.sdk.chatroom.model.EnterChatRoomData
|
||||
import com.netease.nimlib.sdk.chatroom.model.EnterChatRoomResultData
|
||||
import io.reactivex.Single
|
||||
import io.reactivex.subjects.PublishSubject
|
||||
|
||||
open class ChatRoomClient(val sessionId: String) : ICleared, ILog {
|
||||
|
||||
private var isLogin = false
|
||||
private var loginData: EnterChatRoomResultData? = null
|
||||
val messageObservable: PublishSubject<List<ChatRoomMessage>> = PublishSubject.create()
|
||||
|
||||
private val receiveMessageObserver = Observer<List<ChatRoomMessage>> {
|
||||
val list = it.filter { item ->
|
||||
item.sessionId == sessionId
|
||||
}
|
||||
messageObservable.onNext(list)
|
||||
}
|
||||
|
||||
private val onlineStatusObserver = Observer<ChatRoomStatusChangeData> {
|
||||
if (it.status == StatusCode.LOGINED) {
|
||||
isLogin = true
|
||||
} else {
|
||||
isLogin = false
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
registerOnlineStatus(true)
|
||||
registerReceiveMessage(true)
|
||||
}
|
||||
|
||||
fun enterChatRoom(): Single<EnterChatRoomResultData> {
|
||||
logD("enterChatRoom() sessionId:$sessionId")
|
||||
if (loginData != null && isLogin) {
|
||||
logD("enterChatRoom() isLogin")
|
||||
return Single.just(loginData)
|
||||
}
|
||||
return Single.create<EnterChatRoomResultData?> {
|
||||
logD("enterChatRoom() sessionId:$sessionId run")
|
||||
val enterChatRoomData = EnterChatRoomData(sessionId)
|
||||
val enterChatRoomEx =
|
||||
NIMChatRoomSDK.getChatRoomService().enterChatRoomEx(enterChatRoomData, 3)
|
||||
enterChatRoomEx.setCallback(object : RequestCallback<EnterChatRoomResultData> {
|
||||
override fun onSuccess(param: EnterChatRoomResultData) {
|
||||
logD("enterChatRoom() onSuccess roomId:${param.roomId}")
|
||||
loginData = param
|
||||
it.onSuccess(param)
|
||||
}
|
||||
|
||||
override fun onFailed(code: Int) {
|
||||
logD("enterChatRoom() onFailed code:${code}")
|
||||
it.onError(NimException(code))
|
||||
}
|
||||
|
||||
override fun onException(exception: Throwable) {
|
||||
logD("enterChatRoom() onException exception:${exception}")
|
||||
exception.printStackTrace()
|
||||
it.onError(exception)
|
||||
}
|
||||
})
|
||||
}.compose(RxHelper.handleSchedulers())
|
||||
}
|
||||
|
||||
fun exitChatRoom(sessionId: String) {
|
||||
logD("exitChatRoom() sessionId:${sessionId}")
|
||||
NIMChatRoomSDK.getChatRoomService().exitChatRoom(sessionId)
|
||||
}
|
||||
|
||||
fun sendMessage(message: ChatRoomMessage): Single<Any> {
|
||||
return Single.create<Any> {
|
||||
logD("sendMessage() message:${message}")
|
||||
NIMClient.getService<ChatRoomService>(ChatRoomService::class.java)
|
||||
.sendMessage(message, false)
|
||||
.setCallback(object : RequestCallback<Void?> {
|
||||
override fun onSuccess(param: Void?) {
|
||||
logD("sendMessage() onSuccess")
|
||||
it.onSuccess(Any())
|
||||
}
|
||||
|
||||
override fun onFailed(code: Int) {
|
||||
logD("sendMessage() onFailed code:$code")
|
||||
it.onError(NimException(code))
|
||||
}
|
||||
|
||||
override fun onException(exception: Throwable) {
|
||||
logD("sendMessage() onException exception:$exception")
|
||||
exception.printStackTrace()
|
||||
it.onError(exception)
|
||||
}
|
||||
})
|
||||
}.compose(RxHelper.handleSchedulers())
|
||||
}
|
||||
|
||||
private fun registerReceiveMessage(register: Boolean) {
|
||||
NIMChatRoomSDK.getChatRoomServiceObserve()
|
||||
.observeReceiveMessage(receiveMessageObserver, register)
|
||||
}
|
||||
|
||||
private fun registerOnlineStatus(register: Boolean) {
|
||||
NIMChatRoomSDK.getChatRoomServiceObserve()
|
||||
.observeOnlineStatus(onlineStatusObserver, register)
|
||||
}
|
||||
|
||||
override fun onCleared() {
|
||||
super.onCleared()
|
||||
ChatRoomClientManager.onClientCleared(this)
|
||||
registerReceiveMessage(false)
|
||||
registerOnlineStatus(false)
|
||||
exitChatRoom(sessionId)
|
||||
}
|
||||
}
|
@@ -0,0 +1,20 @@
|
||||
package com.chwl.app.public_chat.core
|
||||
|
||||
object ChatRoomClientManager {
|
||||
|
||||
private val clients = HashMap<String, ChatRoomClient>()
|
||||
|
||||
fun getClient(sessionId: String): ChatRoomClient {
|
||||
var finalClient = clients[sessionId]
|
||||
if (finalClient?.sessionId == sessionId) {
|
||||
return finalClient
|
||||
}
|
||||
finalClient = ChatRoomClient(sessionId)
|
||||
clients[sessionId] = finalClient
|
||||
return finalClient
|
||||
}
|
||||
|
||||
fun onClientCleared(client: ChatRoomClient) {
|
||||
clients.remove(client.sessionId)
|
||||
}
|
||||
}
|
@@ -1,6 +1,7 @@
|
||||
package com.chwl.app.public_chat.core.viewholder;
|
||||
|
||||
import com.netease.nimlib.sdk.chatroom.model.ChatRoomMessage;
|
||||
import com.netease.nimlib.sdk.chatroom.model.ChatRoomNotificationAttachment;
|
||||
import com.netease.nimlib.sdk.msg.attachment.AudioAttachment;
|
||||
import com.netease.nimlib.sdk.msg.attachment.ImageAttachment;
|
||||
import com.netease.nimlib.sdk.msg.attachment.MsgAttachment;
|
||||
@@ -23,6 +24,7 @@ public class ChatRoomMessageViewHolderFactory {
|
||||
// built in
|
||||
register(ImageAttachment.class, ChatRoomMessageViewHolderPicture.class);
|
||||
register(AudioAttachment.class, ChatRoomMessageViewHolderAudio.class);
|
||||
register(ChatRoomNotificationAttachment.class, ChatRoomMessageViewHolderNotification.class);
|
||||
}
|
||||
|
||||
public static void register(Class<? extends MsgAttachment> attach, Class<? extends ChatRoomMessageViewHolderBase> viewHolder) {
|
||||
@@ -75,7 +77,6 @@ public class ChatRoomMessageViewHolderFactory {
|
||||
}
|
||||
list.add(ChatRoomMessageViewHolderUnknown.class);
|
||||
list.add(ChatRoomMessageViewHolderText.class);
|
||||
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,44 @@
|
||||
package com.chwl.app.public_chat.core.viewholder;
|
||||
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.netease.nim.uikit.R;
|
||||
import com.netease.nim.uikit.business.chatroom.helper.ChatRoomNotificationHelper;
|
||||
import com.netease.nim.uikit.business.chatroom.viewholder.ChatRoomMsgViewHolderBase;
|
||||
import com.netease.nim.uikit.common.ui.recyclerview.adapter.BaseMultiItemFetchLoadAdapter;
|
||||
import com.netease.nimlib.sdk.chatroom.model.ChatRoomNotificationAttachment;
|
||||
|
||||
public class ChatRoomMessageViewHolderNotification extends ChatRoomMessageViewHolderBase {
|
||||
|
||||
protected TextView notificationTextView;
|
||||
|
||||
public ChatRoomMessageViewHolderNotification(BaseMultiItemFetchLoadAdapter adapter) {
|
||||
super(adapter);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getContentResId() {
|
||||
return R.layout.nim_message_item_notification;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean shouldDisplayNick() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void inflateContentView() {
|
||||
notificationTextView = (TextView) view.findViewById(R.id.message_item_notification_label);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void bindContentView() {
|
||||
notificationTextView.setText(ChatRoomNotificationHelper.getNotificationText((ChatRoomNotificationAttachment) message.getAttachment()));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isMiddleItem() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@@ -1,15 +1,82 @@
|
||||
package com.chwl.app.public_chat.ui.message
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import androidx.activity.viewModels
|
||||
import androidx.core.view.isVisible
|
||||
import com.chwl.app.R
|
||||
import com.chwl.app.base.BaseBindingActivity
|
||||
import com.chwl.app.databinding.PublicChatMessageActivityBinding
|
||||
import com.chwl.app.public_chat.PublicChatViewModel
|
||||
import com.chwl.app.public_chat.ui.message.headline.HeadlineSendDialog
|
||||
import com.chwl.core.initial.InitialModel
|
||||
import com.chwl.core.user.UserModel
|
||||
import com.chwl.library.annatation.ActLayoutRes
|
||||
import com.chwl.library.utils.ResUtil
|
||||
import com.chwl.library.utils.SingleToastUtil
|
||||
import com.example.lib_utils.ktx.singleClick
|
||||
import com.example.lib_utils.log.ILog
|
||||
import com.netease.nim.uikit.StatusBarUtil
|
||||
|
||||
@ActLayoutRes(R.layout.public_chat_message_activity)
|
||||
class PublicChatRoomMessageActivity : BaseBindingActivity<PublicChatMessageActivityBinding>() {
|
||||
class PublicChatRoomMessageActivity : BaseBindingActivity<PublicChatMessageActivityBinding>(),
|
||||
ILog {
|
||||
|
||||
private val viewModel by viewModels<PublicChatViewModel>()
|
||||
|
||||
companion object {
|
||||
fun start(context: Context): Boolean {
|
||||
val partitionId = UserModel.get().partitionId.toString()
|
||||
val sessionId =
|
||||
InitialModel.get().cacheInitInfo?.publicChatRoomIdMap?.get(partitionId)
|
||||
if (sessionId.isNullOrEmpty()) {
|
||||
SingleToastUtil.showToast(R.string.public_chat_not_found)
|
||||
return false
|
||||
} else {
|
||||
val intent = Intent(context, PublicChatRoomMessageActivity::class.java)
|
||||
intent.putExtra("sessionId", sessionId)
|
||||
context.startActivity(intent)
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun init() {
|
||||
val fragment = PublicChatRoomMessageFragment()
|
||||
supportFragmentManager.beginTransaction().add(R.id.fragment_message, fragment).commit()
|
||||
val sessionId = intent.getStringExtra("sessionId")
|
||||
if (sessionId.isNullOrEmpty()) {
|
||||
finish()
|
||||
return
|
||||
}
|
||||
initView(sessionId)
|
||||
initEvent()
|
||||
initObserve()
|
||||
}
|
||||
|
||||
private fun initView(sessionId: String) {
|
||||
initWhiteTitleBar(ResUtil.getString(R.string.public_chat))
|
||||
val fragment = PublicChatRoomMessageFragment.newInstance(sessionId)
|
||||
supportFragmentManager.beginTransaction().add(R.id.fragment_message, fragment)
|
||||
.commitAllowingStateLoss()
|
||||
}
|
||||
|
||||
private fun initEvent() {
|
||||
mBinding?.ivHeadline?.singleClick {
|
||||
HeadlineSendDialog().show(supportFragmentManager, "HEADLINE_SEND")
|
||||
}
|
||||
}
|
||||
|
||||
private fun initObserve() {
|
||||
viewModel.headlineLiveData.observe(this) {
|
||||
logD("headlineLiveData:${it}")
|
||||
val content = it?.content
|
||||
mBinding.tvHeadline.text = content
|
||||
if (content.isNullOrEmpty()) {
|
||||
mBinding.tvHeadline.isVisible = false
|
||||
} else {
|
||||
mBinding.tvHeadline.isVisible = true
|
||||
}
|
||||
}
|
||||
viewModel.getCurrentHeadline()
|
||||
}
|
||||
|
||||
override fun onBackPressed() {
|
||||
|
@@ -1,7 +1,9 @@
|
||||
package com.chwl.app.public_chat.ui.message
|
||||
|
||||
import android.Manifest
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import com.chwl.app.R
|
||||
import com.chwl.app.base.BaseBindingFragment
|
||||
@@ -9,36 +11,48 @@ import com.chwl.app.databinding.PublicChatMessageFragmentBinding
|
||||
import com.chwl.app.public_chat.PublicChatViewModel
|
||||
import com.chwl.library.annatation.ActLayoutRes
|
||||
import com.chwl.library.utils.SingleToastUtil
|
||||
import com.example.lib_utils.log.ILog
|
||||
import com.netease.nim.uikit.api.model.NimException
|
||||
import com.netease.nim.uikit.business.session.actions.BaseAction
|
||||
import com.netease.nim.uikit.business.session.actions.ImageAction
|
||||
import com.netease.nim.uikit.business.session.module.Container
|
||||
import com.netease.nim.uikit.business.session.module.ModuleProxy
|
||||
import com.netease.nimlib.sdk.NIMChatRoomSDK
|
||||
import com.netease.nimlib.sdk.NIMClient
|
||||
import com.netease.nimlib.sdk.Observer
|
||||
import com.netease.nimlib.sdk.chatroom.model.ChatRoomMessage
|
||||
import com.netease.nimlib.sdk.msg.MsgService
|
||||
import com.netease.nimlib.sdk.chatroom.model.ChatRoomStatusChangeData
|
||||
import com.netease.nimlib.sdk.msg.constant.SessionTypeEnum
|
||||
import com.netease.nimlib.sdk.msg.model.IMMessage
|
||||
|
||||
@ActLayoutRes(R.layout.public_chat_message_fragment)
|
||||
class PublicChatRoomMessageFragment : BaseBindingFragment<PublicChatMessageFragmentBinding>(),
|
||||
ModuleProxy {
|
||||
ModuleProxy, ILog {
|
||||
private val viewModel by activityViewModels<PublicChatViewModel>()
|
||||
private val chatRoomClient get() = viewModel.chatRoomClient
|
||||
private var sessionId = "-1"
|
||||
|
||||
private var inputPanel: PublicChatRoomInputPanel? = null
|
||||
private var messageListPanel: PublicChatRoomMessageListPanel? = null
|
||||
|
||||
override fun initiate() {
|
||||
val sessionId = arguments?.getString("sessionId")
|
||||
// init(sessionId ?: "-1")
|
||||
init("6050893381")
|
||||
companion object {
|
||||
fun newInstance(sessionId: String): PublicChatRoomMessageFragment {
|
||||
return PublicChatRoomMessageFragment().apply {
|
||||
arguments = Bundle().apply {
|
||||
putString("sessionId", sessionId)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun initiate() {
|
||||
val sessionId = arguments?.getString("sessionId")
|
||||
init(sessionId ?: "-1")
|
||||
}
|
||||
|
||||
@SuppressLint("CheckResult")
|
||||
private fun init(sessionId: String) {
|
||||
this.sessionId = sessionId
|
||||
viewModel.enterChatRoom(sessionId)
|
||||
viewModel.init(sessionId)
|
||||
val container = Container(activity, sessionId, SessionTypeEnum.ChatRoom, this)
|
||||
messageListPanel =
|
||||
PublicChatRoomMessageListPanel(
|
||||
@@ -53,22 +67,25 @@ class PublicChatRoomMessageFragment : BaseBindingFragment<PublicChatMessageFragm
|
||||
)
|
||||
inputPanel?.setLimitLevel(true, "")
|
||||
registerObservers(true)
|
||||
chatRoomClient?.enterChatRoom()?.compose(bindToLifecycle())
|
||||
?.subscribe({ messageListPanel?.requestHistory() },
|
||||
{
|
||||
if (it is NimException) {
|
||||
toast(getString(R.string.avroom_fragment_homepartyroomfragment_011) + "(${it.code})")
|
||||
} else {
|
||||
toast(R.string.avroom_fragment_homepartyroomfragment_011)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
messageListPanel?.onPause()
|
||||
NIMClient.getService(MsgService::class.java).setChattingAccount(
|
||||
MsgService.MSG_CHATTING_ACCOUNT_NONE,
|
||||
SessionTypeEnum.None
|
||||
)
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
messageListPanel?.onResume()
|
||||
NIMClient.getService<MsgService>(MsgService::class.java)
|
||||
.setChattingAccount(sessionId, SessionTypeEnum.ChatRoom)
|
||||
}
|
||||
|
||||
override fun sendMessage(msg: IMMessage?): Boolean {
|
||||
@@ -121,6 +138,8 @@ class PublicChatRoomMessageFragment : BaseBindingFragment<PublicChatMessageFragm
|
||||
private fun registerObservers(register: Boolean) {
|
||||
NIMChatRoomSDK.getChatRoomServiceObserve()
|
||||
.observeReceiveMessage(incomingMessageObserver, register)
|
||||
NIMChatRoomSDK.getChatRoomServiceObserve()
|
||||
.observeOnlineStatus(onlineStatusObserver, register)
|
||||
}
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
@@ -145,4 +164,15 @@ class PublicChatRoomMessageFragment : BaseBindingFragment<PublicChatMessageFragm
|
||||
}
|
||||
messageListPanel?.onIncomingMessage(messages)
|
||||
}
|
||||
|
||||
private val onlineStatusObserver: Observer<ChatRoomStatusChangeData> =
|
||||
Observer<ChatRoomStatusChangeData>
|
||||
{
|
||||
logI("onlineStatusObserver roomId:${it.roomId} status:${it.status}")
|
||||
if (it.roomId == sessionId) {
|
||||
if (it.status.wontAutoLogin()) {
|
||||
toast(R.string.xchat_android_core_manager_imneteasemanager_012)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -85,6 +85,7 @@ public class PublicChatRoomMessageListPanel {
|
||||
private Handler uiHandler;
|
||||
// 语音转文字
|
||||
private VoiceTrans voiceTrans;
|
||||
private MessageLoader messageLoader;
|
||||
|
||||
private OnItemClickListener listener = new OnItemClickListener() {
|
||||
@Override
|
||||
@@ -220,8 +221,14 @@ public class PublicChatRoomMessageListPanel {
|
||||
}
|
||||
|
||||
private void initFetchLoadListener() {
|
||||
MessageLoader loader = new MessageLoader();
|
||||
adapter.setOnFetchMoreListener(loader);
|
||||
this.messageLoader = new MessageLoader();
|
||||
adapter.setOnFetchMoreListener(messageLoader);
|
||||
}
|
||||
|
||||
public void requestHistory(){
|
||||
if (messageLoader != null) {
|
||||
messageLoader.loadFromRemote();
|
||||
}
|
||||
}
|
||||
|
||||
// 刷新消息列表
|
||||
@@ -499,10 +506,9 @@ public class PublicChatRoomMessageListPanel {
|
||||
};
|
||||
|
||||
public MessageLoader() {
|
||||
loadFromRemote();
|
||||
}
|
||||
|
||||
private synchronized void loadFromRemote() {
|
||||
public synchronized void loadFromRemote() {
|
||||
if (fetching) {
|
||||
return;
|
||||
}
|
||||
|
@@ -0,0 +1,37 @@
|
||||
package com.chwl.app.public_chat.ui.message.headline
|
||||
|
||||
import android.view.Gravity
|
||||
import android.view.WindowManager
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.chwl.app.base.BaseDialog
|
||||
import com.chwl.app.databinding.HeadlineSendDialogBinding
|
||||
import com.chwl.app.public_chat.PublicChatViewModel
|
||||
import com.chwl.library.utils.SingleToastUtil
|
||||
import com.example.lib_utils.ktx.singleClick
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class HeadlineSendDialog : BaseDialog<HeadlineSendDialogBinding>() {
|
||||
private val viewModel by activityViewModels<PublicChatViewModel>()
|
||||
|
||||
override var width = WindowManager.LayoutParams.MATCH_PARENT
|
||||
override var height = WindowManager.LayoutParams.WRAP_CONTENT
|
||||
override var gravity = Gravity.BOTTOM
|
||||
override fun init() {
|
||||
lifecycleScope.launch(Dispatchers.Main) {
|
||||
viewModel.sendHeadlineFlow.collect {
|
||||
if (it.isSuccess) {
|
||||
SingleToastUtil.showToast("success")
|
||||
dismissAllowingStateLoss()
|
||||
} else {
|
||||
SingleToastUtil.showToast(it.message)
|
||||
}
|
||||
}
|
||||
}
|
||||
binding.tvBuy.singleClick {
|
||||
val message = binding.etContent.text?.trim()?.toString() ?: ""
|
||||
viewModel.sendHeadline(message)
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/et_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/dp_200"
|
||||
android:background="@drawable/shape_white_10dp_round"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_buy"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/shape_518eff_20dp_round"
|
||||
android:padding="@dimen/dp_10"
|
||||
android:text="上头条"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/et_content" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
@@ -1,14 +1,39 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layout>
|
||||
<layout xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<com.chwl.app.base.TitleBar
|
||||
android:id="@+id/title_bar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_headline"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/dp_50"
|
||||
android:background="@drawable/shape_99727272_7dp"
|
||||
android:gravity="center"
|
||||
app:layout_constraintTop_toTopOf="@id/fragment_message" />
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/fragment_message"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"/>
|
||||
android:layout_height="0dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/title_bar" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/iv_headline"
|
||||
android:layout_width="@dimen/dp_50"
|
||||
android:layout_height="@dimen/dp_50"
|
||||
android:src="@drawable/default_cover"
|
||||
app:layout_constraintBottom_toBottomOf="@id/fragment_message"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="@id/fragment_message" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
</layout>
|
@@ -1,3 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="public_chat">公聊廳</string>
|
||||
<string name="want_top_message">我要上頭條~</string>
|
||||
<string name="public_chat_not_found">獲取公聊廳信息失敗</string>
|
||||
</resources>
|
@@ -1,3 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<string name="public_chat">公聊廳</string>
|
||||
<string name="want_top_message">我要上頭條~</string>
|
||||
<string name="public_chat_not_found">獲取公聊廳信息失敗</string>
|
||||
</resources>
|
@@ -1,3 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="public_chat">公聊廳</string>
|
||||
<string name="want_top_message">我要上頭條~</string>
|
||||
<string name="public_chat_not_found">獲取公聊廳信息失敗</string>
|
||||
</resources>
|
@@ -1,11 +1,13 @@
|
||||
package com.chwl.core.initial.bean;
|
||||
|
||||
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import com.chwl.core.monsterhunting.bean.MonsterInitInfo;
|
||||
import com.chwl.core.noble.bean.NobleRight;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import lombok.Data;
|
||||
@@ -154,6 +156,11 @@ public class InitInfo implements Serializable {
|
||||
*/
|
||||
private String trtcAppId;
|
||||
|
||||
/**
|
||||
* 公聊ID
|
||||
*/
|
||||
private HashMap<String, String> publicChatRoomIdMap;
|
||||
|
||||
@Data
|
||||
public class AppUpgradePackageAddress implements Serializable{
|
||||
private String androidUrl;
|
||||
|
@@ -246,4 +246,6 @@ public interface IUserModel extends IModel {
|
||||
Single<String> saveArea(String area);
|
||||
|
||||
boolean isSamePartition(long partitionId);
|
||||
|
||||
long getPartitionId();
|
||||
}
|
||||
|
@@ -846,6 +846,11 @@ public final class UserModel extends BaseModel implements IUserModel {
|
||||
return currentUserInfo.partitionId == partitionId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getPartitionId() {
|
||||
return currentUserInfo.partitionId;
|
||||
}
|
||||
|
||||
private interface Api {
|
||||
/**
|
||||
* 获取某个用户的用户信息
|
||||
|
@@ -0,0 +1,10 @@
|
||||
package com.chwl.core.public_chat_hall.bean
|
||||
|
||||
import androidx.annotation.Keep
|
||||
|
||||
@Keep
|
||||
class HeadlineBean {
|
||||
val content: String? = null
|
||||
val id: Long? = null
|
||||
val uid: Long? = null
|
||||
}
|
@@ -0,0 +1,44 @@
|
||||
package com.chwl.core.public_chat_hall.model
|
||||
|
||||
import com.chwl.core.base.BaseModel
|
||||
import com.chwl.core.bean.response.ServiceResult
|
||||
import com.chwl.core.public_chat_hall.bean.HeadlineBean
|
||||
import com.chwl.core.utils.net.launchRequest
|
||||
import com.chwl.core.vip.bean.VipPageInfo
|
||||
import com.chwl.library.net.rxnet.RxNet
|
||||
import retrofit2.http.Field
|
||||
import retrofit2.http.FormUrlEncoded
|
||||
import retrofit2.http.GET
|
||||
import retrofit2.http.POST
|
||||
|
||||
object PublicChatModel : BaseModel() {
|
||||
private val api = RxNet.create(PublicChatModel.Api::class.java)
|
||||
|
||||
suspend fun getCurrentHeadline(): HeadlineBean? =
|
||||
launchRequest {
|
||||
api.getCurrentHeadline()
|
||||
}
|
||||
|
||||
suspend fun sendHeadline(message: String): Any? =
|
||||
launchRequest {
|
||||
api.sendHeadline(message)
|
||||
}
|
||||
|
||||
interface Api {
|
||||
|
||||
/**
|
||||
* 获取头条
|
||||
*/
|
||||
@GET("publicChatTopRecord/getTop")
|
||||
suspend fun getCurrentHeadline(): ServiceResult<HeadlineBean>
|
||||
|
||||
/**
|
||||
* 发送头条
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@FormUrlEncoded
|
||||
@POST("publicChatTopRecord/send")
|
||||
suspend fun sendHeadline(@Field("content") content: String): ServiceResult<Any>
|
||||
}
|
||||
}
|
@@ -10,8 +10,8 @@
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/switchLayout"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_marginStart="@dimen/bottom_component_margin_horizontal"
|
||||
android:layout_marginEnd="@dimen/bottom_component_margin_horizontal">
|
||||
|
@@ -0,0 +1,15 @@
|
||||
package com.netease.nim.uikit.api.model
|
||||
|
||||
import java.lang.Exception
|
||||
|
||||
class NimException : Exception {
|
||||
var code: Int = 0
|
||||
|
||||
constructor(code: Int) : super() {
|
||||
this.code = code
|
||||
}
|
||||
|
||||
constructor(message: String?) : super(message)
|
||||
constructor(message: String?, cause: Throwable?) : super(message, cause)
|
||||
constructor(cause: Throwable?) : super(cause)
|
||||
}
|
Reference in New Issue
Block a user