Search in sources :

Example 1 with CallService

use of cx.ring.services.CallService in project ring-client-android by savoirfairelinux.

the class DRingService method update.

@Override
public void update(Observable observable, ServiceEvent arg) {
    if (observable instanceof PreferencesService) {
        refreshContacts();
        updateConnectivityState();
    } else if (observable instanceof AccountService && arg != null) {
        switch(arg.getEventType()) {
            case ACCOUNTS_CHANGED:
                SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(DRingService.this);
                sharedPreferences.edit().putBoolean(OutgoingCallHandler.KEY_CACHE_HAVE_RINGACCOUNT, mAccountService.hasRingAccount()).putBoolean(OutgoingCallHandler.KEY_CACHE_HAVE_SIPACCOUNT, mAccountService.hasSipAccount()).apply();
                refreshContacts();
                break;
            case CONTACT_ADDED:
            case CONTACT_REMOVED:
                refreshContacts();
                break;
        }
    } else if (observable instanceof CallService && arg != null) {
        switch(arg.getEventType()) {
            case INCOMING_CALL:
                SipCall call = arg.getEventInput(ServiceEvent.EventInput.CALL, SipCall.class);
                if (call != null) {
                    Log.d(TAG, "call id : " + call.getCallId());
                    Bundle extras = new Bundle();
                    extras.putString("account", mAccountService.getCurrentAccount().getAccountID());
                    extras.putString("callId", call.getCallId());
                    startActivity(new Intent(Intent.ACTION_VIEW).putExtras(extras).setClass(getApplicationContext(), DeviceUtils.isTv(this) ? TVCallActivity.class : CallActivity.class).setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK));
                }
                break;
        }
    }
}
Also used : SipCall(cx.ring.model.SipCall) SharedPreferences(android.content.SharedPreferences) Bundle(android.os.Bundle) Intent(android.content.Intent) CallActivity(cx.ring.client.CallActivity) TVCallActivity(cx.ring.tv.call.TVCallActivity) AccountService(cx.ring.services.AccountService) TVCallActivity(cx.ring.tv.call.TVCallActivity) PreferencesService(cx.ring.services.PreferencesService) CallService(cx.ring.services.CallService)

Example 2 with CallService

use of cx.ring.services.CallService in project ring-client-android by savoirfairelinux.

the class ServiceInjectionModule method provideCallService.

@Provides
@Singleton
CallService provideCallService() {
    CallService callService = new CallService();
    mRingApplication.getRingInjectionComponent().inject(callService);
    return callService;
}
Also used : CallService(cx.ring.services.CallService) Singleton(javax.inject.Singleton) Provides(dagger.Provides)

Example 3 with CallService

use of cx.ring.services.CallService in project ring-client-android by savoirfairelinux.

the class ConversationFacade method update.

@Override
public void update(Observable observable, ServiceEvent event) {
    if (event == null) {
        return;
    }
    ServiceEvent mEvent;
    if (observable instanceof HistoryService) {
        switch(event.getEventType()) {
            case INCOMING_MESSAGE:
                {
                    TextMessage txt = event.getEventInput(ServiceEvent.EventInput.MESSAGE, TextMessage.class);
                    if (txt == null) {
                        Log.d(TAG, "Received a null text message");
                        return;
                    }
                    parseNewMessage(txt);
                    updateTextNotifications();
                    setChanged();
                    mEvent = new ServiceEvent(ServiceEvent.EventType.INCOMING_MESSAGE);
                    notifyObservers(mEvent);
                    break;
                }
            case ACCOUNT_MESSAGE_STATUS_CHANGED:
                {
                    TextMessage newMsg = event.getEventInput(ServiceEvent.EventInput.MESSAGE, TextMessage.class);
                    Conversation conv = getConversationByContact(mContactService.findContactByNumber(newMsg.getNumber()));
                    if (conv != null) {
                        conv.updateTextMessage(newMsg);
                    }
                    setChanged();
                    mEvent = new ServiceEvent(ServiceEvent.EventType.INCOMING_MESSAGE);
                    notifyObservers(mEvent);
                    break;
                }
            case HISTORY_LOADED:
                Account account = mAccountService.getCurrentAccount();
                if (account != null) {
                    boolean acceptAllMessages = account.getDetailBoolean(ConfigKey.DHT_PUBLIC_IN);
                    mConversationMap.clear();
                    addContacts(acceptAllMessages);
                    List<HistoryCall> historyCalls = (List<HistoryCall>) event.getEventInput(ServiceEvent.EventInput.HISTORY_CALLS, ArrayList.class);
                    parseHistoryCalls(historyCalls, acceptAllMessages);
                    List<HistoryText> historyTexts = (List<HistoryText>) event.getEventInput(ServiceEvent.EventInput.HISTORY_TEXTS, ArrayList.class);
                    parseHistoryTexts(historyTexts, acceptAllMessages);
                    List<DataTransfer> historyTransfers = (List<DataTransfer>) event.getEventInput(ServiceEvent.EventInput.HISTORY_TRANSFERS, ArrayList.class);
                    parseHistoryTransfers(historyTransfers, acceptAllMessages);
                    aggregateHistory();
                    searchForRingIdInBlockchain();
                }
                setChanged();
                mEvent = new ServiceEvent(ServiceEvent.EventType.CONVERSATIONS_CHANGED);
                notifyObservers(mEvent);
                break;
            case HISTORY_MODIFIED:
                refreshConversations();
                break;
        }
    } else if (observable instanceof CallService) {
        Conversation conversation = null;
        Conference conference = null;
        SipCall call;
        switch(event.getEventType()) {
            case CALL_STATE_CHANGED:
                call = event.getEventInput(ServiceEvent.EventInput.CALL, SipCall.class);
                if (call == null) {
                    Log.w(TAG, "CALL_STATE_CHANGED : call is null");
                    return;
                }
                int newState = call.getCallState();
                mHardwareService.updateAudioState(newState == SipCall.State.RINGING && call.isIncoming(), call.isOnGoing() && !call.isAudioOnly());
                for (Conversation conv : mConversationMap.values()) {
                    conference = conv.getConference(call.getCallId());
                    if (conference != null) {
                        conversation = conv;
                        Log.w(TAG, "CALL_STATE_CHANGED : found conversation " + call.getCallId());
                        break;
                    }
                }
                if (conversation == null) {
                    conversation = startConversation(call.getContact());
                    conference = new Conference(call);
                    conversation.addConference(conference);
                }
                Log.w(TAG, "CALL_STATE_CHANGED : updating call state to " + newState);
                if ((call.isRinging() || newState == SipCall.State.CURRENT) && call.getTimestampStart() == 0) {
                    call.setTimestampStart(System.currentTimeMillis());
                }
                if ((newState == SipCall.State.CURRENT && call.isIncoming()) || newState == SipCall.State.RINGING && call.isOutGoing()) {
                    mAccountService.sendProfile(call.getCallId(), call.getAccount());
                } else if (newState == SipCall.State.HUNGUP || newState == SipCall.State.BUSY || newState == SipCall.State.FAILURE || newState == SipCall.State.OVER) {
                    mNotificationService.cancelCallNotification(call.getCallId().hashCode());
                    mHardwareService.closeAudioState();
                    if (newState == SipCall.State.HUNGUP) {
                        call.setTimestampEnd(System.currentTimeMillis());
                    }
                    if (call.getTimestampStart() == 0) {
                        call.setTimestampStart(System.currentTimeMillis());
                    }
                    if (call.getTimestampEnd() == 0) {
                        call.setTimestampEnd(System.currentTimeMillis());
                    }
                    mHistoryService.insertNewEntry(conference);
                    conference.removeParticipant(call);
                    conversation.addHistoryCall(new HistoryCall(call));
                    mCallService.removeCallForId(call.getCallId());
                }
                if (conference.getParticipants().isEmpty()) {
                    conversation.removeConference(conference);
                }
                setChanged();
                mEvent = new ServiceEvent(ServiceEvent.EventType.CALL_STATE_CHANGED);
                notifyObservers(mEvent);
                break;
            case INCOMING_CALL:
                call = event.getEventInput(ServiceEvent.EventInput.CALL, SipCall.class);
                conversation = startConversation(call.getContact());
                conference = new Conference(call);
                conversation.addConference(conference);
                mNotificationService.showCallNotification(conference);
                mHardwareService.setPreviewSettings();
                Conference currenConf = getCurrentCallingConf();
                mHardwareService.updateAudioState(currenConf.getState() == SipCall.State.RINGING && currenConf.isIncoming(), false);
                setChanged();
                ServiceEvent serviceEvent = new ServiceEvent(ServiceEvent.EventType.INCOMING_CALL);
                notifyObservers(serviceEvent);
                break;
        }
    } else if (observable instanceof ContactService) {
        switch(event.getEventType()) {
            case CONTACTS_CHANGED:
                refreshConversations();
                break;
        }
    } else if (observable instanceof AccountService) {
        switch(event.getEventType()) {
            case REGISTERED_NAME_FOUND:
                {
                    int state = event.getEventInput(ServiceEvent.EventInput.STATE, Integer.class);
                    if (state != 0) {
                        break;
                    }
                    String accountId = event.getEventInput(ServiceEvent.EventInput.ACCOUNT_ID, String.class);
                    String name = event.getEventInput(ServiceEvent.EventInput.NAME, String.class);
                    Uri address = new Uri(event.getEventInput(ServiceEvent.EventInput.ADDRESS, String.class));
                    if (mContactService.setRingContactName(accountId, address, name)) {
                        setChanged();
                        notifyObservers(new ServiceEvent(ServiceEvent.EventType.USERNAME_CHANGED));
                    }
                    break;
                }
            case DATA_TRANSFER:
                {
                    DataTransferEventCode transferEventCode = event.getEventInput(ServiceEvent.EventInput.TRANSFER_EVENT_CODE, DataTransferEventCode.class);
                    DataTransfer transfer = event.getEventInput(ServiceEvent.EventInput.TRANSFER_INFO, DataTransfer.class);
                    handleDataTransferEvent(transfer, transferEventCode);
                    break;
                }
        }
    }
}
Also used : Account(cx.ring.model.Account) SipCall(cx.ring.model.SipCall) SecureSipCall(cx.ring.model.SecureSipCall) HistoryText(cx.ring.model.HistoryText) ArrayList(java.util.ArrayList) HistoryService(cx.ring.services.HistoryService) Conversation(cx.ring.model.Conversation) Conference(cx.ring.model.Conference) Uri(cx.ring.model.Uri) HistoryCall(cx.ring.model.HistoryCall) ContactService(cx.ring.services.ContactService) DataTransfer(cx.ring.model.DataTransfer) ServiceEvent(cx.ring.model.ServiceEvent) ArrayList(java.util.ArrayList) List(java.util.List) AccountService(cx.ring.services.AccountService) TextMessage(cx.ring.model.TextMessage) DataTransferEventCode(cx.ring.model.DataTransferEventCode) CallService(cx.ring.services.CallService)

Example 4 with CallService

use of cx.ring.services.CallService in project ring-client-android by savoirfairelinux.

the class SmartListPresenter method update.

@Override
public void update(Observable observable, ServiceEvent event) {
    if (event == null) {
        return;
    }
    switch(event.getEventType()) {
        case REGISTERED_NAME_FOUND:
            String name = event.getEventInput(ServiceEvent.EventInput.NAME, String.class);
            if (mLastBlockchainQuery != null && (mLastBlockchainQuery.equals("") || !mLastBlockchainQuery.equals(name))) {
                return;
            }
            String address = event.getEventInput(ServiceEvent.EventInput.ADDRESS, String.class);
            int state = event.getEventInput(ServiceEvent.EventInput.STATE, Integer.class);
            parseEventState(name, address, state);
            break;
        case REGISTRATION_STATE_CHANGED:
            refreshConnectivity();
            break;
        case CONTACTS_CHANGED:
            loadConversations();
            break;
    }
    if (observable instanceof HistoryService) {
        switch(event.getEventType()) {
            case INCOMING_MESSAGE:
                TextMessage txt = event.getEventInput(ServiceEvent.EventInput.MESSAGE, TextMessage.class);
                if (txt.getAccount().equals(mAccountService.getCurrentAccount().getAccountID())) {
                    loadConversations();
                    getView().scrollToTop();
                }
                return;
            case HISTORY_MODIFIED:
                loadConversations();
                getView().scrollToTop();
                return;
        }
    }
    if (observable instanceof CallService) {
        switch(event.getEventType()) {
            case INCOMING_CALL:
                SipCall call = event.getEventInput(ServiceEvent.EventInput.CALL, SipCall.class);
                updateIncomingCall(call.getNumber());
                return;
        }
    }
    if (observable instanceof PresenceService) {
        switch(event.getEventType()) {
            case NEW_BUDDY_NOTIFICATION:
                updatePresence();
                return;
            default:
        }
    }
}
Also used : SipCall(cx.ring.model.SipCall) HistoryService(cx.ring.services.HistoryService) PresenceService(cx.ring.services.PresenceService) TextMessage(cx.ring.model.TextMessage) CallService(cx.ring.services.CallService)

Example 5 with CallService

use of cx.ring.services.CallService in project ring-client-android by savoirfairelinux.

the class CallPresenter method update.

@Override
public void update(Observable observable, ServiceEvent event) {
    if (event == null) {
        return;
    }
    if (observable instanceof CallService) {
        switch(event.getEventType()) {
            case CALL_STATE_CHANGED:
                SipCall call = event.getEventInput(ServiceEvent.EventInput.CALL, SipCall.class);
                int state = call.getCallState();
                Log.d(TAG, "CALL_STATE_CHANGED: " + call.getCallId() + " " + state);
                parseCall(call, state);
                confUpdate();
                break;
        }
    } else if (observable instanceof AccountService) {
        switch(event.getEventType()) {
            case REGISTERED_NAME_FOUND:
                if (mSipCall != null && mSipCall.getContact() != null) {
                    getView().updateContactBubble(mSipCall.getContact());
                }
                break;
        }
    } else if (observable instanceof HardwareService) {
        switch(event.getEventType()) {
            case VIDEO_EVENT:
                boolean videoStart = event.getEventInput(ServiceEvent.EventInput.VIDEO_START, Boolean.class, false);
                String callId = event.getEventInput(ServiceEvent.EventInput.VIDEO_CALL, String.class);
                Log.d(TAG, "VIDEO_EVENT: " + videoStart + " " + callId);
                previewHeight = event.getEventInput(ServiceEvent.EventInput.VIDEO_WIDTH, Integer.class, 0);
                previewWidth = event.getEventInput(ServiceEvent.EventInput.VIDEO_HEIGHT, Integer.class, 0);
                if (videoStart) {
                    getView().displayVideoSurface(true);
                } else if (mSipCall != null && callId != null && mSipCall.getCallId().equals(callId)) {
                    boolean videoStarted = event.getEventInput(ServiceEvent.EventInput.VIDEO_STARTED, Boolean.class, false);
                    getView().displayVideoSurface(videoStarted);
                    if (videoStarted) {
                        videoWidth = event.getEventInput(ServiceEvent.EventInput.VIDEO_WIDTH, Integer.class, 0);
                        videoHeight = event.getEventInput(ServiceEvent.EventInput.VIDEO_HEIGHT, Integer.class, 0);
                    }
                }
                getView().resetVideoSize(videoWidth, videoHeight, previewWidth, previewHeight);
                break;
        }
    }
}
Also used : HardwareService(cx.ring.services.HardwareService) SipCall(cx.ring.model.SipCall) AccountService(cx.ring.services.AccountService) CallService(cx.ring.services.CallService)

Aggregations

CallService (cx.ring.services.CallService)5 SipCall (cx.ring.model.SipCall)4 AccountService (cx.ring.services.AccountService)3 TextMessage (cx.ring.model.TextMessage)2 HistoryService (cx.ring.services.HistoryService)2 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1 Bundle (android.os.Bundle)1 CallActivity (cx.ring.client.CallActivity)1 Account (cx.ring.model.Account)1 Conference (cx.ring.model.Conference)1 Conversation (cx.ring.model.Conversation)1 DataTransfer (cx.ring.model.DataTransfer)1 DataTransferEventCode (cx.ring.model.DataTransferEventCode)1 HistoryCall (cx.ring.model.HistoryCall)1 HistoryText (cx.ring.model.HistoryText)1 SecureSipCall (cx.ring.model.SecureSipCall)1 ServiceEvent (cx.ring.model.ServiceEvent)1 Uri (cx.ring.model.Uri)1 ContactService (cx.ring.services.ContactService)1