Search in sources :

Example 1 with OngoingRtpSession

use of eu.siacs.conversations.xmpp.jingle.OngoingRtpSession in project Conversations by siacs.

the class ConversationFragment method returnToOngoingCall.

private void returnToOngoingCall() {
    final Optional<OngoingRtpSession> ongoingRtpSession = activity.xmppConnectionService.getJingleConnectionManager().getOngoingRtpConnection(conversation.getContact());
    if (ongoingRtpSession.isPresent()) {
        final OngoingRtpSession id = ongoingRtpSession.get();
        final Intent intent = new Intent(getActivity(), RtpSessionActivity.class);
        intent.putExtra(RtpSessionActivity.EXTRA_ACCOUNT, id.getAccount().getJid().asBareJid().toEscapedString());
        intent.putExtra(RtpSessionActivity.EXTRA_WITH, id.getWith().toEscapedString());
        if (id instanceof AbstractJingleConnection.Id) {
            intent.setAction(Intent.ACTION_VIEW);
            intent.putExtra(RtpSessionActivity.EXTRA_SESSION_ID, id.getSessionId());
        } else if (id instanceof JingleConnectionManager.RtpSessionProposal) {
            if (((JingleConnectionManager.RtpSessionProposal) id).media.contains(Media.VIDEO)) {
                intent.setAction(RtpSessionActivity.ACTION_MAKE_VIDEO_CALL);
            } else {
                intent.setAction(RtpSessionActivity.ACTION_MAKE_VOICE_CALL);
            }
        }
        startActivity(intent);
    }
}
Also used : OngoingRtpSession(eu.siacs.conversations.xmpp.jingle.OngoingRtpSession) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) JingleConnectionManager(eu.siacs.conversations.xmpp.jingle.JingleConnectionManager)

Example 2 with OngoingRtpSession

use of eu.siacs.conversations.xmpp.jingle.OngoingRtpSession in project Conversations by siacs.

the class ConversationAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(@NonNull ConversationViewHolder viewHolder, int position) {
    Conversation conversation = conversations.get(position);
    if (conversation == null) {
        return;
    }
    CharSequence name = conversation.getName();
    if (name instanceof Jid) {
        viewHolder.binding.conversationName.setText(IrregularUnicodeDetector.style(activity, (Jid) name));
    } else {
        viewHolder.binding.conversationName.setText(EmojiWrapper.transform(name));
    }
    if (conversation == ConversationFragment.getConversation(activity)) {
        viewHolder.binding.frame.setBackgroundColor(StyledAttributes.getColor(activity, R.attr.color_background_tertiary));
    } else {
        viewHolder.binding.frame.setBackgroundColor(StyledAttributes.getColor(activity, R.attr.color_background_primary));
    }
    Message message = conversation.getLatestMessage();
    final int unreadCount = conversation.unreadCount();
    final boolean isRead = conversation.isRead();
    final Conversation.Draft draft = isRead ? conversation.getDraft() : null;
    if (unreadCount > 0) {
        viewHolder.binding.unreadCount.setVisibility(View.VISIBLE);
        viewHolder.binding.unreadCount.setUnreadCount(unreadCount);
    } else {
        viewHolder.binding.unreadCount.setVisibility(View.GONE);
    }
    if (isRead) {
        viewHolder.binding.conversationName.setTypeface(null, Typeface.NORMAL);
    } else {
        viewHolder.binding.conversationName.setTypeface(null, Typeface.BOLD);
    }
    if (draft != null) {
        viewHolder.binding.conversationLastmsgImg.setVisibility(View.GONE);
        viewHolder.binding.conversationLastmsg.setText(EmojiWrapper.transform(draft.getMessage()));
        viewHolder.binding.senderName.setText(R.string.draft);
        viewHolder.binding.senderName.setVisibility(View.VISIBLE);
        viewHolder.binding.conversationLastmsg.setTypeface(null, Typeface.NORMAL);
        viewHolder.binding.senderName.setTypeface(null, Typeface.ITALIC);
    } else {
        final boolean fileAvailable = !message.isDeleted();
        final boolean showPreviewText;
        if (fileAvailable && (message.isFileOrImage() || message.treatAsDownloadable() || message.isGeoUri())) {
            final int imageResource;
            if (message.isGeoUri()) {
                imageResource = activity.getThemeResource(R.attr.ic_attach_location, R.drawable.ic_attach_location);
                showPreviewText = false;
            } else {
                // TODO move this into static MediaPreview method and use same icons as in MediaAdapter
                final String mime = message.getMimeType();
                switch(mime == null ? "" : mime.split("/")[0]) {
                    case "image":
                        imageResource = activity.getThemeResource(R.attr.ic_attach_photo, R.drawable.ic_attach_photo);
                        showPreviewText = false;
                        break;
                    case "video":
                        imageResource = activity.getThemeResource(R.attr.ic_attach_videocam, R.drawable.ic_attach_videocam);
                        showPreviewText = false;
                        break;
                    case "audio":
                        imageResource = activity.getThemeResource(R.attr.ic_attach_record, R.drawable.ic_attach_record);
                        showPreviewText = false;
                        break;
                    default:
                        imageResource = activity.getThemeResource(R.attr.ic_attach_document, R.drawable.ic_attach_document);
                        showPreviewText = true;
                        break;
                }
            }
            viewHolder.binding.conversationLastmsgImg.setImageResource(imageResource);
            viewHolder.binding.conversationLastmsgImg.setVisibility(View.VISIBLE);
        } else {
            viewHolder.binding.conversationLastmsgImg.setVisibility(View.GONE);
            showPreviewText = true;
        }
        final Pair<CharSequence, Boolean> preview = UIHelper.getMessagePreview(activity, message, viewHolder.binding.conversationLastmsg.getCurrentTextColor());
        if (showPreviewText) {
            viewHolder.binding.conversationLastmsg.setText(EmojiWrapper.transform(UIHelper.shorten(preview.first)));
        } else {
            viewHolder.binding.conversationLastmsgImg.setContentDescription(preview.first);
        }
        viewHolder.binding.conversationLastmsg.setVisibility(showPreviewText ? View.VISIBLE : View.GONE);
        if (preview.second) {
            if (isRead) {
                viewHolder.binding.conversationLastmsg.setTypeface(null, Typeface.ITALIC);
                viewHolder.binding.senderName.setTypeface(null, Typeface.NORMAL);
            } else {
                viewHolder.binding.conversationLastmsg.setTypeface(null, Typeface.BOLD_ITALIC);
                viewHolder.binding.senderName.setTypeface(null, Typeface.BOLD);
            }
        } else {
            if (isRead) {
                viewHolder.binding.conversationLastmsg.setTypeface(null, Typeface.NORMAL);
                viewHolder.binding.senderName.setTypeface(null, Typeface.NORMAL);
            } else {
                viewHolder.binding.conversationLastmsg.setTypeface(null, Typeface.BOLD);
                viewHolder.binding.senderName.setTypeface(null, Typeface.BOLD);
            }
        }
        if (message.getStatus() == Message.STATUS_RECEIVED) {
            if (conversation.getMode() == Conversation.MODE_MULTI) {
                viewHolder.binding.senderName.setVisibility(View.VISIBLE);
                viewHolder.binding.senderName.setText(UIHelper.getMessageDisplayName(message).split("\\s+")[0] + ':');
            } else {
                viewHolder.binding.senderName.setVisibility(View.GONE);
            }
        } else if (message.getType() != Message.TYPE_STATUS) {
            viewHolder.binding.senderName.setVisibility(View.VISIBLE);
            viewHolder.binding.senderName.setText(activity.getString(R.string.me) + ':');
        } else {
            viewHolder.binding.senderName.setVisibility(View.GONE);
        }
    }
    final Optional<OngoingRtpSession> ongoingCall;
    if (conversation.getMode() == Conversational.MODE_MULTI) {
        ongoingCall = Optional.absent();
    } else {
        ongoingCall = activity.xmppConnectionService.getJingleConnectionManager().getOngoingRtpConnection(conversation.getContact());
    }
    if (ongoingCall.isPresent()) {
        viewHolder.binding.notificationStatus.setVisibility(View.VISIBLE);
        final int ic_ongoing_call = activity.getThemeResource(R.attr.ic_ongoing_call_hint, R.drawable.ic_phone_in_talk_black_18dp);
        viewHolder.binding.notificationStatus.setImageResource(ic_ongoing_call);
    } else {
        final long muted_till = conversation.getLongAttribute(Conversation.ATTRIBUTE_MUTED_TILL, 0);
        if (muted_till == Long.MAX_VALUE) {
            viewHolder.binding.notificationStatus.setVisibility(View.VISIBLE);
            int ic_notifications_off = activity.getThemeResource(R.attr.icon_notifications_off, R.drawable.ic_notifications_off_black_24dp);
            viewHolder.binding.notificationStatus.setImageResource(ic_notifications_off);
        } else if (muted_till >= System.currentTimeMillis()) {
            viewHolder.binding.notificationStatus.setVisibility(View.VISIBLE);
            int ic_notifications_paused = activity.getThemeResource(R.attr.icon_notifications_paused, R.drawable.ic_notifications_paused_black_24dp);
            viewHolder.binding.notificationStatus.setImageResource(ic_notifications_paused);
        } else if (conversation.alwaysNotify()) {
            viewHolder.binding.notificationStatus.setVisibility(View.GONE);
        } else {
            viewHolder.binding.notificationStatus.setVisibility(View.VISIBLE);
            int ic_notifications_none = activity.getThemeResource(R.attr.icon_notifications_none, R.drawable.ic_notifications_none_black_24dp);
            viewHolder.binding.notificationStatus.setImageResource(ic_notifications_none);
        }
    }
    long timestamp;
    if (draft != null) {
        timestamp = draft.getTimestamp();
    } else {
        timestamp = conversation.getLatestMessage().getTimeSent();
    }
    viewHolder.binding.pinnedOnTop.setVisibility(conversation.getBooleanAttribute(Conversation.ATTRIBUTE_PINNED_ON_TOP, false) ? View.VISIBLE : View.GONE);
    viewHolder.binding.conversationLastupdate.setText(UIHelper.readableTimeDifference(activity, timestamp));
    AvatarWorkerTask.loadAvatar(conversation, viewHolder.binding.conversationImage, R.dimen.avatar_on_conversation_overview);
    viewHolder.itemView.setOnClickListener(v -> listener.onConversationClick(v, conversation));
}
Also used : Jid(eu.siacs.conversations.xmpp.Jid) Message(eu.siacs.conversations.entities.Message) Conversation(eu.siacs.conversations.entities.Conversation) OngoingRtpSession(eu.siacs.conversations.xmpp.jingle.OngoingRtpSession)

Example 3 with OngoingRtpSession

use of eu.siacs.conversations.xmpp.jingle.OngoingRtpSession in project Conversations by siacs.

the class ConversationFragment method onCreateOptionsMenu.

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater menuInflater) {
    menuInflater.inflate(R.menu.fragment_conversation, menu);
    final MenuItem menuMucDetails = menu.findItem(R.id.action_muc_details);
    final MenuItem menuContactDetails = menu.findItem(R.id.action_contact_details);
    final MenuItem menuInviteContact = menu.findItem(R.id.action_invite);
    final MenuItem menuMute = menu.findItem(R.id.action_mute);
    final MenuItem menuUnmute = menu.findItem(R.id.action_unmute);
    final MenuItem menuCall = menu.findItem(R.id.action_call);
    final MenuItem menuOngoingCall = menu.findItem(R.id.action_ongoing_call);
    final MenuItem menuVideoCall = menu.findItem(R.id.action_video_call);
    final MenuItem menuTogglePinned = menu.findItem(R.id.action_toggle_pinned);
    if (conversation != null) {
        if (conversation.getMode() == Conversation.MODE_MULTI) {
            menuContactDetails.setVisible(false);
            menuInviteContact.setVisible(conversation.getMucOptions().canInvite());
            menuMucDetails.setTitle(conversation.getMucOptions().isPrivateAndNonAnonymous() ? R.string.action_muc_details : R.string.channel_details);
            menuCall.setVisible(false);
            menuOngoingCall.setVisible(false);
        } else {
            final XmppConnectionService service = activity == null ? null : activity.xmppConnectionService;
            final Optional<OngoingRtpSession> ongoingRtpSession = service == null ? Optional.absent() : service.getJingleConnectionManager().getOngoingRtpConnection(conversation.getContact());
            if (ongoingRtpSession.isPresent()) {
                menuOngoingCall.setVisible(true);
                menuCall.setVisible(false);
            } else {
                menuOngoingCall.setVisible(false);
                final RtpCapability.Capability rtpCapability = RtpCapability.check(conversation.getContact());
                final boolean cameraAvailable = activity != null && activity.isCameraFeatureAvailable();
                menuCall.setVisible(rtpCapability != RtpCapability.Capability.NONE);
                menuVideoCall.setVisible(rtpCapability == RtpCapability.Capability.VIDEO && cameraAvailable);
            }
            menuContactDetails.setVisible(!this.conversation.withSelf());
            menuMucDetails.setVisible(false);
            menuInviteContact.setVisible(service != null && service.findConferenceServer(conversation.getAccount()) != null);
        }
        if (conversation.isMuted()) {
            menuMute.setVisible(false);
        } else {
            menuUnmute.setVisible(false);
        }
        ConversationMenuConfigurator.configureAttachmentMenu(conversation, menu);
        ConversationMenuConfigurator.configureEncryptionMenu(conversation, menu);
        if (conversation.getBooleanAttribute(Conversation.ATTRIBUTE_PINNED_ON_TOP, false)) {
            menuTogglePinned.setTitle(R.string.remove_from_favorites);
        } else {
            menuTogglePinned.setTitle(R.string.add_to_favorites);
        }
    }
    super.onCreateOptionsMenu(menu, menuInflater);
}
Also used : XmppConnectionService(eu.siacs.conversations.services.XmppConnectionService) OngoingRtpSession(eu.siacs.conversations.xmpp.jingle.OngoingRtpSession) RtpCapability(eu.siacs.conversations.xmpp.jingle.RtpCapability) MenuItem(android.view.MenuItem)

Aggregations

OngoingRtpSession (eu.siacs.conversations.xmpp.jingle.OngoingRtpSession)3 PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 MenuItem (android.view.MenuItem)1 Conversation (eu.siacs.conversations.entities.Conversation)1 Message (eu.siacs.conversations.entities.Message)1 XmppConnectionService (eu.siacs.conversations.services.XmppConnectionService)1 Jid (eu.siacs.conversations.xmpp.Jid)1 JingleConnectionManager (eu.siacs.conversations.xmpp.jingle.JingleConnectionManager)1 RtpCapability (eu.siacs.conversations.xmpp.jingle.RtpCapability)1