Search in sources :

Example 6 with ServiceUiRequest

use of com.vodafone360.people.service.ServiceUiRequest in project 360-Engine-for-Android by 360.

the class IdentityEngine method pushIdentitiesToUi.

/**
     * 
     * Pushes the identities retrieved by get my identities or by get available identities
     * to the ui.
     * 
     * @param request The request type: either get my identities, or get available identities.
     */
private void pushIdentitiesToUi(ServiceUiRequest request) {
    String requestKey = null;
    ArrayList<Identity> idBundle = null;
    if (request == ServiceUiRequest.GET_AVAILABLE_IDENTITIES) {
        requestKey = KEY_AVAILABLE_IDS;
        synchronized (mAvailableIdentityList) {
            // provide a shallow copy
            idBundle = new ArrayList<Identity>(mAvailableIdentityList);
        }
    } else {
        requestKey = KEY_MY_IDS;
        synchronized (mMyIdentityList) {
            // provide a shallow copy
            idBundle = new ArrayList<Identity>(mMyIdentityList);
        }
    }
    // send update to 3rd party identities ui if it is up
    Bundle b = new Bundle();
    b.putParcelableArrayList(requestKey, idBundle);
    UiAgent uiAgent = mEventCallback.getUiAgent();
    if (uiAgent != null && uiAgent.isSubscribed()) {
        uiAgent.sendUnsolicitedUiEvent(request, b);
    }
// end: send update to 3rd party identities ui if it is up
}
Also used : UiAgent(com.vodafone360.people.service.agent.UiAgent) Bundle(android.os.Bundle) Identity(com.vodafone360.people.datatypes.Identity)

Example 7 with ServiceUiRequest

use of com.vodafone360.people.service.ServiceUiRequest in project 360-Engine-for-Android by 360.

the class ContactSyncEngine method processDbMessage.

/**
     * Called when a database change event is received from the DatabaseHelper.
     * Only internal database change events are processed, external change
     * events are generated by the contact sync engine.
     * 
     * @param msg The message indicating the type of event
     */
private void processDbMessage(Message message) {
    final ServiceUiRequest event = ServiceUiRequest.getUiEvent(message.what);
    switch(event) {
        case DATABASE_CHANGED_EVENT:
            if (message.arg1 == DatabaseHelper.DatabaseChangeType.CONTACTS.ordinal() && message.arg2 == 0) {
                LogUtils.logV("ContactSyncEngine.processDbMessage - Contacts have changed");
                // startMeProfileSyncTimer();
                startServerContactSyncTimer(SERVER_CONTACT_SYNC_TIMEOUT_MS);
                startUpdateNativeContactSyncTimer();
            }
            break;
        default:
            // Do nothing.
            break;
    }
}
Also used : ServiceUiRequest(com.vodafone360.people.service.ServiceUiRequest)

Example 8 with ServiceUiRequest

use of com.vodafone360.people.service.ServiceUiRequest in project 360-Engine-for-Android by 360.

the class PresenceEngine method processUiRequest.

@Override
protected void processUiRequest(ServiceUiRequest requestId, Object data) {
    if (!isFirstTimeSyncComplete()) {
        LogUtils.logE("PresenceEngine.processUIRequest():" + " Can't run PresenceEngine before the contact list is downloaded:1");
        return;
    }
    LogUtils.logW("PresenceEngine.processUiRequest() requestId.name[" + requestId.name() + "]");
    if (data == null && requestId != ServiceUiRequest.GET_PRESENCE_LIST) {
        LogUtils.logW("PresenceEngine.processUiRequest() skipping processing for request with no data!");
        return;
    }
    switch(requestId) {
        case SET_MY_AVAILABILITY:
            Hashtable<String, String> presenceHash = (Hashtable<String, String>) data;
            notifyUiAgentOfRequest(Presence.setMyAvailability(presenceHash), presenceHash);
            break;
        case GET_PRESENCE_LIST:
            Presence.getPresenceList(EngineId.PRESENCE_ENGINE, null);
            break;
        case CREATE_CONVERSATION:
            List<String> tos = ((ChatMessage) data).getTos();
            LogUtils.logW("PresenceEngine processUiRequest() CREATE_CONVERSATION with: " + tos);
            Chat.startChat(tos);
            break;
        case SEND_CHAT_MESSAGE:
            ChatMessage msg = (ChatMessage) data;
            updateChatDatabase(msg, TimelineSummaryItem.Type.OUTGOING);
            //cache the message (necessary for failed message sending failures)
            mSendMessagesHash.put(msg.getTos().get(0), msg);
            Chat.sendChatMessage(msg);
            break;
        default:
            LogUtils.logE("PresenceEngine processUiRequest() Unhandled UI request [" + requestId.name() + "]");
            // don't complete with success and schedule the next runtime
            return;
    }
    completeUiRequest(ServiceStatus.SUCCESS, null);
    setTimeout(CHECK_FREQUENCY);
}
Also used : ChatMessage(com.vodafone360.people.datatypes.ChatMessage) Hashtable(java.util.Hashtable)

Example 9 with ServiceUiRequest

use of com.vodafone360.people.service.ServiceUiRequest in project 360-Engine-for-Android by 360.

the class ContactSyncEngine method clearCurrentSyncAndPatchBaseEngine.

/**
     * Clears the current sync and make sure that if we cancel a previous sync,
     * it doesn't notify a wrong UI request. TODO: Find another way to not have
     * to hack the BaseEngine!
     */
private void clearCurrentSyncAndPatchBaseEngine() {
    // Cancel background sync
    if (mActiveProcessor != null) {
        // the mActiveUiRequest is already the new one so if
        // onCompleteUiRequest(Error) is called,
        // this will reset it to null even if we didn't start to process it.
        ServiceUiRequest newActiveUiRequest = mActiveUiRequest;
        mActiveUiRequest = mActiveUiRequestBackup;
        mActiveProcessor.cancel();
        //            cancelSync();
        // restore the active UI request...
        mActiveUiRequest = newActiveUiRequest;
        mActiveProcessor = null;
    }
    newState(State.IDLE);
}
Also used : ServiceUiRequest(com.vodafone360.people.service.ServiceUiRequest)

Example 10 with ServiceUiRequest

use of com.vodafone360.people.service.ServiceUiRequest in project 360-Engine-for-Android by 360.

the class ContactSyncEngineTest method testUiRequestCompleteEvent_fullSync.

/**
     * Verifies that events are fired after UI requests.
     */
@Suppress
public // Breaks tests.
void testUiRequestCompleteEvent_fullSync() {
    Log.i(LOG_TAG, "**** testUiRequestCompleteEvent_fullSync() begin ****");
    final UiEventCall uiEventCall = new UiEventCall();
    final IEngineEventCallback engineEventCallback = new HelperClasses.EngineCallbackBase() {

        @Override
        public void onUiEvent(ServiceUiRequest event, int request, int status, Object data) {
            Log.i(LOG_TAG, "onUiEvent: " + event + ", " + request + ", " + status + ", " + data);
            uiEventCall.event = event.ordinal();
            uiEventCall.request = request;
            uiEventCall.status = status;
            uiEventCall.data = data;
        }
    };
    final ProcessorFactory factory = new ProcessorFactory() {

        @Override
        public BaseSyncProcessor create(int type, IContactSyncCallback callback, DatabaseHelper dbHelper) {
            Log.i(LOG_TAG, "create(), type=" + type);
            return new DummySyncProcessor(mContactSyncEngine, null);
        }
    };
    minimalEngineSetup(engineEventCallback, factory);
    NetworkAgent.setAgentState(NetworkAgent.AgentState.CONNECTED);
    long nextRuntime = mContactSyncEngine.getNextRunTime();
    // should be equal to -1 because first time sync has not been yet
    // started
    assertEquals(-1, nextRuntime);
    // set the connection to be fine
    NetworkAgent.setAgentState(AgentState.CONNECTED);
    // ask for a full sync
    mContactSyncEngine.addUiStartFullSync();
    nextRuntime = mContactSyncEngine.getNextRunTime();
    assertEquals(0, nextRuntime);
    mContactSyncEngine.run();
    // check that first time sync is completed
    assertEquals(ServiceUiRequest.UI_REQUEST_COMPLETE.ordinal(), uiEventCall.event);
    assertEquals(uiEventCall.status, ServiceStatus.SUCCESS.ordinal());
    Log.i(LOG_TAG, "**** testUiRequestCompleteEvent_fullSync() end ****");
}
Also used : DatabaseHelper(com.vodafone360.people.database.DatabaseHelper) ServiceUiRequest(com.vodafone360.people.service.ServiceUiRequest) ProcessorFactory(com.vodafone360.people.engine.contactsync.ProcessorFactory) IContactSyncCallback(com.vodafone360.people.engine.contactsync.IContactSyncCallback) IEngineEventCallback(com.vodafone360.people.engine.IEngineEventCallback) Suppress(android.test.suitebuilder.annotation.Suppress)

Aggregations

ServiceUiRequest (com.vodafone360.people.service.ServiceUiRequest)11 Suppress (android.test.suitebuilder.annotation.Suppress)9 DatabaseHelper (com.vodafone360.people.database.DatabaseHelper)9 IEngineEventCallback (com.vodafone360.people.engine.IEngineEventCallback)9 IContactSyncCallback (com.vodafone360.people.engine.contactsync.IContactSyncCallback)9 ProcessorFactory (com.vodafone360.people.engine.contactsync.ProcessorFactory)9 ArrayList (java.util.ArrayList)5 Bundle (android.os.Bundle)1 Handler (android.os.Handler)1 Looper (android.os.Looper)1 Message (android.os.Message)1 MessageQueue (android.os.MessageQueue)1 ChatMessage (com.vodafone360.people.datatypes.ChatMessage)1 Identity (com.vodafone360.people.datatypes.Identity)1 BaseSyncProcessor (com.vodafone360.people.engine.contactsync.BaseSyncProcessor)1 IContactSyncObserver (com.vodafone360.people.engine.contactsync.ContactSyncEngine.IContactSyncObserver)1 UiAgent (com.vodafone360.people.service.agent.UiAgent)1 DecodedResponse (com.vodafone360.people.service.io.ResponseQueue.DecodedResponse)1 Hashtable (java.util.Hashtable)1