Search in sources :

Example 1 with MessageViewModel

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();
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) UiMessage(cn.wildfire.chat.kit.conversation.message.model.UiMessage) MessageViewModel(cn.wildfire.chat.kit.viewmodel.MessageViewModel) View(android.view.View) ViewModelProvider(androidx.lifecycle.ViewModelProvider)

Example 2 with MessageViewModel

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);
    }
}
Also used : Message(cn.wildfirechat.message.Message) UiMessage(cn.wildfire.chat.kit.conversation.message.model.UiMessage) UiMessage(cn.wildfire.chat.kit.conversation.message.model.UiMessage) MessageViewModel(cn.wildfire.chat.kit.viewmodel.MessageViewModel) File(java.io.File) OnClick(butterknife.OnClick)

Example 3 with MessageViewModel

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);
        }
    }
}
Also used : SharedPreferences(android.content.SharedPreferences) MessageViewModel(cn.wildfire.chat.kit.viewmodel.MessageViewModel) IMServiceStatusViewModel(cn.wildfire.chat.kit.IMServiceStatusViewModel) IMConnectionStatusViewModel(cn.wildfire.chat.kit.IMConnectionStatusViewModel) Intent(android.content.Intent)

Example 4 with MessageViewModel

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());
}
Also used : MessageViewModel(cn.wildfire.chat.kit.viewmodel.MessageViewModel)

Example 5 with MessageViewModel

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);
}
Also used : ConversationExtension(cn.wildfire.chat.kit.conversation.ext.core.ConversationExtension) TypingMessageContent(cn.wildfirechat.message.TypingMessageContent) SharedPreferences(android.content.SharedPreferences) PttPanel(cn.wildfire.chat.kit.audio.PttPanel) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) TextView(android.widget.TextView) MessageViewModel(cn.wildfire.chat.kit.viewmodel.MessageViewModel) AudioRecorderPanel(cn.wildfire.chat.kit.audio.AudioRecorderPanel) IEmotionExtClickListener(com.lqr.emoji.IEmotionExtClickListener) File(java.io.File)

Aggregations

MessageViewModel (cn.wildfire.chat.kit.viewmodel.MessageViewModel)6 SharedPreferences (android.content.SharedPreferences)2 View (android.view.View)2 UiMessage (cn.wildfire.chat.kit.conversation.message.model.UiMessage)2 File (java.io.File)2 Intent (android.content.Intent)1 Handler (android.os.Handler)1 SpannableString (android.text.SpannableString)1 Pair (android.util.Pair)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 ViewModelProvider (androidx.lifecycle.ViewModelProvider)1 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 SimpleItemAnimator (androidx.recyclerview.widget.SimpleItemAnimator)1 BindView (butterknife.BindView)1 OnClick (butterknife.OnClick)1 IMConnectionStatusViewModel (cn.wildfire.chat.kit.IMConnectionStatusViewModel)1 IMServiceStatusViewModel (cn.wildfire.chat.kit.IMServiceStatusViewModel)1 AudioRecorderPanel (cn.wildfire.chat.kit.audio.AudioRecorderPanel)1