use of cn.wildfire.chat.kit.viewmodel.MessageViewModel in project android-chat by wildfirechat.
the class DeleteMultiMessageAction method onClick.
@Override
public void onClick(List<UiMessage> messages) {
MessageViewModel messageViewModel = new ViewModelProvider(fragment).get(MessageViewModel.class);
new MaterialDialog.Builder(fragment.getContext()).items("删除本地消息", "删除远程消息").itemsCallback(new MaterialDialog.ListCallback() {
@Override
public void onSelection(MaterialDialog dialog, View itemView, int position, CharSequence text) {
if (position == 0) {
for (UiMessage message : messages) {
messageViewModel.deleteMessage(message.message);
}
} else {
for (UiMessage message : messages) {
messageViewModel.deleteRemoteMessage(message.message);
}
}
}
}).show();
}
use of cn.wildfire.chat.kit.viewmodel.MessageViewModel in project android-chat by wildfirechat.
the class FavAudioContentViewHolder method playAudio.
@OnClick(R2.id.audioContentLayout)
void playAudio() {
Message message = favoriteItem.toMessage();
uiMessage = new UiMessage(message);
MessageViewModel messageViewModel = ViewModelProviders.of(fragment).get(MessageViewModel.class);
File file = messageViewModel.mediaMessageContentFile(message);
if (file == null) {
return;
}
if (file.exists()) {
messageViewModel.playAudioMessage(uiMessage);
} else {
if (uiMessage.isDownloading) {
return;
}
messageViewModel.downloadMedia(uiMessage, file);
}
}
use of cn.wildfire.chat.kit.viewmodel.MessageViewModel in project android-chat by wildfirechat.
the class MainActivity method afterViews.
@Override
protected void afterViews() {
bottomNavigationView.setItemIconTintList(null);
IMServiceStatusViewModel imServiceStatusViewModel = ViewModelProviders.of(this).get(IMServiceStatusViewModel.class);
imServiceStatusViewModel.imServiceStatusLiveData().observe(this, imStatusLiveDataObserver);
IMConnectionStatusViewModel connectionStatusViewModel = ViewModelProviders.of(this).get(IMConnectionStatusViewModel.class);
connectionStatusViewModel.connectionStatusLiveData().observe(this, status -> {
if (status == ConnectionStatus.ConnectionStatusTokenIncorrect || status == ConnectionStatus.ConnectionStatusSecretKeyMismatch || status == ConnectionStatus.ConnectionStatusRejected || status == ConnectionStatus.ConnectionStatusLogout || status == ConnectionStatus.ConnectionStatusKickedoff) {
SharedPreferences sp = getSharedPreferences(Config.SP_CONFIG_FILE_NAME, Context.MODE_PRIVATE);
sp.edit().clear().apply();
OKHttpHelper.clearCookies();
if (status == ConnectionStatus.ConnectionStatusLogout) {
reLogin(false);
} else {
ChatManager.Instance().disconnect(true, false);
if (status == ConnectionStatus.ConnectionStatusKickedoff) {
reLogin(true);
}
}
}
});
MessageViewModel messageViewModel = ViewModelProviders.of(this).get(MessageViewModel.class);
messageViewModel.messageLiveData().observe(this, uiMessage -> {
if (uiMessage.message.content.getMessageContentType() == MessageContentType.MESSAGE_CONTENT_TYPE_FEED || uiMessage.message.content.getMessageContentType() == MessageContentType.MESSAGE_CONTENT_TYPE_FEED_COMMENT) {
updateMomentBadgeView();
}
});
Intent intent = getIntent();
String action = intent.getAction();
String type = intent.getType();
if (Intent.ACTION_SEND.equals(action)) {
if ("text/plain".equals(type)) {
handleSend(intent);
}
}
}
use of cn.wildfire.chat.kit.viewmodel.MessageViewModel in project android-chat by wildfirechat.
the class DiscoveryFragment method initMoment.
private void initMoment() {
if (!WfcUIKit.getWfcUIKit().isSupportMoment()) {
momentOptionItemView.setVisibility(View.GONE);
return;
}
MessageViewModel messageViewModel = ViewModelProviders.of(this).get(MessageViewModel.class);
messageViewModel.messageLiveData().observe(getViewLifecycleOwner(), uiMessage -> updateMomentBadgeView());
messageViewModel.clearMessageLiveData().observe(getViewLifecycleOwner(), o -> updateMomentBadgeView());
}
use of cn.wildfire.chat.kit.viewmodel.MessageViewModel in project android-chat by wildfirechat.
the class ConversationInputPanel method init.
public void init(Fragment fragment, InputAwareLayout rootInputAwareLayout) {
LayoutInflater.from(getContext()).inflate(R.layout.conversation_input_panel, this, true);
ButterKnife.bind(this, this);
this.activity = fragment.getActivity();
this.fragment = fragment;
this.rootLinearLayout = rootInputAwareLayout;
this.extension = new ConversationExtension(fragment, this, extViewPager);
sharedPreferences = getContext().getSharedPreferences("sticker", Context.MODE_PRIVATE);
// emotion
emotionLayout.setEmotionAddVisiable(true);
emotionLayout.setEmotionSettingVisiable(true);
// audio record panel
audioRecorderPanel = new AudioRecorderPanel(getContext());
audioRecorderPanel.setRecordListener(new AudioRecorderPanel.OnRecordListener() {
@Override
public void onRecordSuccess(String audioFile, int duration) {
// 发送文件
File file = new File(audioFile);
if (file.exists()) {
messageViewModel.sendAudioFile(conversation, Uri.parse(audioFile), duration);
}
}
@Override
public void onRecordFail(String reason) {
Toast.makeText(activity, reason, Toast.LENGTH_SHORT).show();
}
@Override
public void onRecordStateChanged(AudioRecorderPanel.RecordState state) {
if (state == AudioRecorderPanel.RecordState.START) {
TypingMessageContent content = new TypingMessageContent(TypingMessageContent.TYPING_VOICE);
messageViewModel.sendMessage(conversation, content);
}
}
});
SharedPreferences sp = fragment.getContext().getSharedPreferences(Config.SP_CONFIG_FILE_NAME, Context.MODE_PRIVATE);
boolean pttEnabled = sp.getBoolean("pttEnabled", true);
if (pttEnabled && PTTClient.checkAddress(ChatManager.Instance().getHost())) {
pttImageView.setVisibility(View.VISIBLE);
pttPanel = new PttPanel(getContext());
}
// emotion
emotionLayout.setEmotionSelectedListener(this);
emotionLayout.setEmotionExtClickListener(new IEmotionExtClickListener() {
@Override
public void onEmotionAddClick(View view) {
Toast.makeText(activity, "add", Toast.LENGTH_SHORT).show();
}
@Override
public void onEmotionSettingClick(View view) {
Toast.makeText(activity, "setting", Toast.LENGTH_SHORT).show();
}
});
messageViewModel = ViewModelProviders.of(fragment).get(MessageViewModel.class);
conversationViewModel = ViewModelProviders.of(fragment).get(ConversationViewModel.class);
}
Aggregations