diff --git a/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/ConversationActivity.java b/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/ConversationActivity.java index 1487995d0..72b92d9f3 100644 --- a/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/ConversationActivity.java +++ b/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/ConversationActivity.java @@ -79,6 +79,9 @@ private void showConversationInfo() { protected void onNewIntent(Intent intent) { super.onNewIntent(intent); conversation = intent.getParcelableExtra("conversation"); + if (conversation == null) { + finish(); + } long initialFocusedMessageId = intent.getLongExtra("toFocusMessageId", -1); String channelPrivateChatUser = intent.getStringExtra("channelPrivateChatUser"); conversationFragment.setupConversation(conversation, null, initialFocusedMessageId, channelPrivateChatUser); diff --git a/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/ConversationFragment.java b/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/ConversationFragment.java index 40d94b3ae..d76c79fab 100644 --- a/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/ConversationFragment.java +++ b/chat/kit/src/main/java/cn/wildfire/chat/kit/conversation/ConversationFragment.java @@ -300,23 +300,22 @@ public void onScrollStateChanged(RecyclerView recyclerView, int newState) { inputPanel.init(this, rootLinearLayout); inputPanel.setOnConversationInputPanelStateChangeListener(this); + + settingViewModel = ViewModelProviders.of(this).get(SettingViewModel.class); + conversationViewModel = WfcUIKit.getAppScopeViewModel(ConversationViewModel.class); + conversationViewModel.clearConversationMessageLiveData().observeForever(clearConversationMessageObserver); + messageViewModel = ViewModelProviders.of(this).get(MessageViewModel.class); + + messageViewModel.messageLiveData().observeForever(messageLiveDataObserver); + messageViewModel.messageUpdateLiveData().observeForever(messageUpdateLiveDatObserver); + messageViewModel.messageRemovedLiveData().observeForever(messageRemovedLiveDataObserver); + messageViewModel.mediaUpdateLiveData().observeForever(mediaUploadedLiveDataObserver); + + userViewModel = ViewModelProviders.of(this).get(UserViewModel.class); + userViewModel.userInfoLiveData().observeForever(userInfoUpdateLiveDataObserver); } private void setupConversation(Conversation conversation) { - if (conversationViewModel == null) { - settingViewModel = ViewModelProviders.of(this).get(SettingViewModel.class); - conversationViewModel = WfcUIKit.getAppScopeViewModel(ConversationViewModel.class); - conversationViewModel.clearConversationMessageLiveData().observeForever(clearConversationMessageObserver); - messageViewModel = ViewModelProviders.of(this).get(MessageViewModel.class); - - messageViewModel.messageLiveData().observeForever(messageLiveDataObserver); - messageViewModel.messageUpdateLiveData().observeForever(messageUpdateLiveDatObserver); - messageViewModel.messageRemovedLiveData().observeForever(messageRemovedLiveDataObserver); - messageViewModel.mediaUpdateLiveData().observeForever(mediaUploadedLiveDataObserver); - - userViewModel = ViewModelProviders.of(this).get(UserViewModel.class); - userViewModel.userInfoLiveData().observeForever(userInfoUpdateLiveDataObserver); - } if (conversation.type == Conversation.ConversationType.Group) { GroupViewModel groupViewModel = ViewModelProviders.of(this).get(GroupViewModel.class); @@ -680,6 +679,9 @@ private void updateTypingStatusTitle(TypingMessageContent typingMessageContent) private Runnable resetConversationTitleRunnable = this::resetConversationTitle; private void resetConversationTitle() { + if (getActivity() == null || getActivity().isFinishing()) { + return; + } if (!TextUtils.equals(conversationTitle, getActivity().getTitle())) { setActivityTitle(conversationTitle); handler.removeCallbacks(resetConversationTitleRunnable);