Search in sources :

Example 1 with IStoreFactory

use of com.waz.zclient.core.stores.IStoreFactory in project wire-android by wireapp.

the class ConversationFragment method onCurrentConversationHasChanged.

@Override
public void onCurrentConversationHasChanged(final IConversation fromConversation, final IConversation toConversation, final ConversationChangeRequester conversationChangeRequester) {
    if (toConversation == null) {
        return;
    }
    if (LayoutSpec.isPhone(getContext())) {
        conversationModelObserver.setAndUpdate(toConversation);
    }
    if (isPreviewShown && fromConversation != null && !toConversation.getId().equals(fromConversation.getId())) {
        onCancelPreview();
    }
    extendedCursorContainer.close(true);
    getControllerFactory().getConversationScreenController().setSingleConversation(toConversation.getType() == IConversation.Type.ONE_TO_ONE);
    if (BuildConfig.SHOW_MENTIONING) {
        getControllerFactory().getMentioningController().setCurrentConversation(toConversation);
    }
    int duration = getResources().getInteger(R.integer.framework_animation_duration_short);
    // post to give the RootFragment the chance to drive its animations first
    new Handler().postDelayed(new Runnable() {

        @Override
        public void run() {
            if (cursorLayout == null) {
                return;
            }
            final boolean changeToDifferentConversation = fromConversation == null || !fromConversation.getId().equals(toConversation.getId());
            // handle draft
            if (fromConversation != null && changeToDifferentConversation && !cursorLayout.isEditingMessage()) {
                getStoreFactory().getDraftStore().setDraft(fromConversation, cursorLayout.getText().trim());
            }
            if (toConversation.getType() == IConversation.Type.WAIT_FOR_CONNECTION) {
                return;
            }
            KeyboardUtils.hideKeyboard(getActivity());
            conversationLoadingIndicatorViewView.hide();
            cursorLayout.enableMessageWriting();
            if (changeToDifferentConversation) {
                getControllerFactory().getConversationScreenController().setConversationStreamUiReady(false);
                toConversationType = toConversation.getType();
                //                    messagesListModelObserver.setAndUpdate(toConversation.getMessages());
                getControllerFactory().getSharingController().maybeResetSharedText(fromConversation);
                getControllerFactory().getSharingController().maybeResetSharedUris(fromConversation);
                cursorLayout.setVisibility(toConversation.isActive() ? View.VISIBLE : View.GONE);
                if (!inSplitPortraitMode()) {
                    resetCursor();
                }
                final String draftText = getStoreFactory().getDraftStore().getDraft(toConversation);
                if (TextUtils.isEmpty(draftText)) {
                    resetCursor();
                } else {
                    cursorLayout.setText(draftText);
                }
                cursorLayout.setConversation(toConversation);
                hideAudioMessageRecording();
            }
            final boolean isSharing = getControllerFactory().getSharingController().isSharedConversation(toConversation);
            final boolean isSharingText = !TextUtils.isEmpty(getControllerFactory().getSharingController().getSharedText()) && isSharing;
            final List<Uri> sharedFileUris = getControllerFactory().getSharingController().getSharedFileUris();
            final boolean isSharingFiles = !(sharedFileUris == null || sharedFileUris.isEmpty()) && isSharing;
            if (isSharing) {
                if (isSharingText) {
                    final String draftText = getControllerFactory().getSharingController().getSharedText();
                    if (TextUtils.isEmpty(draftText)) {
                        resetCursor();
                    } else {
                        cursorLayout.setText(draftText);
                    }
                    cursorLayout.enableMessageWriting();
                    KeyboardUtils.showKeyboard(getActivity());
                    getControllerFactory().getSharingController().maybeResetSharedText(toConversation);
                } else if (isSharingFiles) {
                    if (PermissionUtils.hasSelfPermissions(getActivity(), FILE_SHARING_PERMISSION)) {
                        for (Uri uri : sharedFileUris) {
                            getStoreFactory().getConversationStore().sendMessage(AssetFactory.fromContentUri(uri), assetErrorHandler);
                        }
                    } else {
                        sharingUris.addAll(sharedFileUris);
                        ActivityCompat.requestPermissions(getActivity(), FILE_SHARING_PERMISSION, FILE_SHARING_PERMISSION_REQUEST_ID);
                    }
                    getControllerFactory().getSharingController().maybeResetSharedUris(toConversation);
                }
            }
            if (!getControllerFactory().getStreamMediaPlayerController().isSelectedConversation(toConversation.getId())) {
                onHideMediaBar();
            }
            if (inputStateIndicator != null) {
                inputStateIndicator.getTypingUsers().removeUpdateListener(typingListener);
            }
            inputStateIndicator = toConversation.getInputStateIndicator();
            typingIndicatorView.setInputStateIndicator(inputStateIndicator);
            if (inputStateIndicator != null) {
                inputStateIndicator.getTypingUsers().addUpdateListener(typingListener);
            }
        }
    }, duration);
    // Saving factories since this fragment may be re-created before the runnable is done,
    // but we still want runnable to work.
    final IStoreFactory storeFactory = getStoreFactory();
    final IControllerFactory controllerFactory = getControllerFactory();
    // TODO: Remove when call issue is resolved with https://wearezeta.atlassian.net/browse/CM-645
    // And also why do we use the ConversationFragment to start a call from somewhere else....
    new Handler().postDelayed(new Runnable() {

        @Override
        public void run() {
            if (storeFactory == null || storeFactory.isTornDown() || controllerFactory == null || controllerFactory.isTornDown()) {
                return;
            }
            switch(conversationChangeRequester) {
                case START_CONVERSATION_FOR_VIDEO_CALL:
                    controllerFactory.getCallingController().startCall(true);
                    break;
                case START_CONVERSATION_FOR_CALL:
                    controllerFactory.getCallingController().startCall(false);
                    break;
                case START_CONVERSATION_FOR_CAMERA:
                    controllerFactory.getCameraController().openCamera(CameraContext.MESSAGE);
                    break;
            }
        }
    }, 1000);
}
Also used : IStoreFactory(com.waz.zclient.core.stores.IStoreFactory) IControllerFactory(com.waz.zclient.controllers.IControllerFactory) Handler(android.os.Handler) ErrorsList(com.waz.api.ErrorsList) MessagesList(com.waz.api.MessagesList) ArrayList(java.util.ArrayList) List(java.util.List) UsersList(com.waz.api.UsersList) ConversationsList(com.waz.api.ConversationsList) Uri(android.net.Uri) SuppressLint(android.annotation.SuppressLint)

Example 2 with IStoreFactory

use of com.waz.zclient.core.stores.IStoreFactory in project wire-android by wireapp.

the class SpotifyController method setActivity.

@Override
public void setActivity(Activity activity) {
    final IStoreFactory storeFactory = ZApplication.from(activity).getStoreFactory();
    if (storeFactory == null || storeFactory.isTornDown()) {
        return;
    }
    final IZMessagingApiStore zMessagingApiStore = storeFactory.getZMessagingApiStore();
    final ZMessagingApi api = zMessagingApiStore.getApi();
    this.spotify = api.getSpotify();
}
Also used : IStoreFactory(com.waz.zclient.core.stores.IStoreFactory) ZMessagingApi(com.waz.api.ZMessagingApi) IZMessagingApiStore(com.waz.zclient.core.stores.api.IZMessagingApiStore)

Aggregations

IStoreFactory (com.waz.zclient.core.stores.IStoreFactory)2 SuppressLint (android.annotation.SuppressLint)1 Uri (android.net.Uri)1 Handler (android.os.Handler)1 ConversationsList (com.waz.api.ConversationsList)1 ErrorsList (com.waz.api.ErrorsList)1 MessagesList (com.waz.api.MessagesList)1 UsersList (com.waz.api.UsersList)1 ZMessagingApi (com.waz.api.ZMessagingApi)1 IControllerFactory (com.waz.zclient.controllers.IControllerFactory)1 IZMessagingApiStore (com.waz.zclient.core.stores.api.IZMessagingApiStore)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1