Search in sources :

Example 21 with IConversation

use of com.waz.api.IConversation in project wire-android by wireapp.

the class ConversationListFragment method onConversationListUpdated.

//////////////////////////////////////////////////////////////////////////////////////////
//
//  Notifications
//
//////////////////////////////////////////////////////////////////////////////////////////
@Override
public void onConversationListUpdated(@NonNull final ConversationsList conversationsList) {
    ConversationsList conversations = mode == Mode.SHARING ? conversationsList.getEstablishedConversations() : conversationsList;
    conversationsListAdapter.setConversationList(conversations);
    // We post this to notify that we are ready after the items are instantiated
    swipeListView.post(new Runnable() {

        @Override
        public void run() {
            if (getContainer() == null) {
                return;
            }
        }
    });
    if (pendingCurrentConversation != null) {
        final int pos = getStoreFactory().getConversationStore().getPositionInList(pendingCurrentConversation);
        if (pos > 0) {
            // set selection after updating the conversationlist
            new Handler().post(new Runnable() {

                @SuppressLint("NewApi")
                @Override
                public void run() {
                    int selectionPos = pos - LIST_VIEW_POSITION_OFFSET < 0 ? 0 : pos - LIST_VIEW_POSITION_OFFSET;
                    swipeListView.setSelectionFromTop(selectionPos, 0);
                    pendingCurrentConversation = null;
                }
            });
        }
    }
    // sync state
    onConversationSyncingStateHasChanged(getStoreFactory().getConversationStore().getConversationSyncingState());
    CoreList<IConversation> archivedConversations = conversationsList.getArchivedConversations();
    if (archivedConversations != null && archivedConversations.size() > 0) {
        archiveBox.setAlpha(1f);
    } else {
        archiveBox.setAlpha(0f);
    }
    if (conversationsList.isReady()) {
        maybeShowNoContactsLabel(conversationsList.size() == 0);
    }
}
Also used : Handler(android.os.Handler) ExceptionHandler(net.hockeyapp.android.ExceptionHandler) SuppressLint(android.annotation.SuppressLint) IConversation(com.waz.api.IConversation) ConversationsList(com.waz.api.ConversationsList) SuppressLint(android.annotation.SuppressLint)

Example 22 with IConversation

use of com.waz.api.IConversation in project wire-android by wireapp.

the class ConversationListFragment method onCurrentConversationHasChanged.

@Override
public void onCurrentConversationHasChanged(IConversation fromConversation, IConversation toConversation, ConversationChangeRequester conversationChangerSender) {
    if (toConversation == null || conversationsListAdapter == null) {
        return;
    }
    if (fromConversation != null && fromConversation.getId().equals(toConversation.getId())) {
        return;
    }
    switch(conversationChangerSender) {
        case CONVERSATION_LIST_SELECT_TO_SHARE:
        case CONVERSATION_LIST:
            break;
        default:
            if (toConversation.isArchived()) {
                pendingCurrentConversation = toConversation;
            } else {
                // Don't autoscroll to selected conversation if list is just loaded
                if (conversationChangerSender == ConversationChangeRequester.FIRST_LOAD) {
                    break;
                } else if (conversationChangerSender == ConversationChangeRequester.UPDATER && !scrollToConversation) {
                    break;
                }
                // set selection after updating the conversationlist
                final IConversation finalToConversation = toConversation;
                new Handler().post(new Runnable() {

                    @Override
                    public void run() {
                        if (swipeListView == null || getStoreFactory().isTornDown()) {
                            return;
                        }
                        int pos = getStoreFactory().getConversationStore().getPositionInList(finalToConversation);
                        int selectionPos = pos - LIST_VIEW_POSITION_OFFSET < 0 ? 0 : pos - LIST_VIEW_POSITION_OFFSET;
                        swipeListView.setSelectionFromTop(selectionPos, 0);
                    }
                });
            }
            break;
    }
}
Also used : Handler(android.os.Handler) ExceptionHandler(net.hockeyapp.android.ExceptionHandler) IConversation(com.waz.api.IConversation)

Example 23 with IConversation

use of com.waz.api.IConversation in project wire-android by wireapp.

the class ConversationListManagerFragment method onSelectedUsers.

//////////////////////////////////////////////////////////////////////////////////////////
//
//  PickUserFragment.Container
//
//////////////////////////////////////////////////////////////////////////////////////////
@Override
public void onSelectedUsers(List<User> users, ConversationChangeRequester requester) {
    // TODO https://wearezeta.atlassian.net/browse/AN-3730
    getControllerFactory().getPickUserController().hidePickUser(getCurrentPickerDestination(), true);
    if (users.size() == 1) {
        User user = users.get(0);
        IConversation conversation = user.getConversation();
        if (conversation != null) {
            getStoreFactory().getConversationStore().setCurrentConversation(conversation, requester);
        }
        ((BaseScalaActivity) getActivity()).injectJava(GlobalTrackingController.class).tagEvent(new OpenedConversationEvent(ConversationType.ONE_TO_ONE_CONVERSATION.name()));
    } else {
        getStoreFactory().getConversationStore().createGroupConversation(users, requester);
        ((BaseScalaActivity) getActivity()).injectJava(GlobalTrackingController.class).tagEvent(new CreatedGroupConversationEvent(false, (users.size() + 1)));
        ((BaseScalaActivity) getActivity()).injectJava(GlobalTrackingController.class).tagEvent(new OpenedConversationEvent(ConversationType.GROUP_CONVERSATION.name()));
    }
}
Also used : CreatedGroupConversationEvent(com.waz.zclient.controllers.tracking.events.group.CreatedGroupConversationEvent) User(com.waz.api.User) GlobalTrackingController(com.waz.zclient.tracking.GlobalTrackingController) OpenedConversationEvent(com.waz.zclient.controllers.tracking.events.connect.OpenedConversationEvent) IConversation(com.waz.api.IConversation)

Example 24 with IConversation

use of com.waz.api.IConversation in project wire-android by wireapp.

the class ConversationFragment method onShowMediaBar.

//////////////////////////////////////////////////////////////////////////////////////////
//
//  StreamMediaBar
//
//////////////////////////////////////////////////////////////////////////////////////////
@Override
public void onShowMediaBar(String conversationId) {
    IConversation currentConversation = getStoreFactory().getConversationStore().getCurrentConversation();
    if (currentConversation == null || !conversationId.equals(currentConversation.getId())) {
        return;
    }
    if (streamMediaBarFragment != null) {
        streamMediaBarFragment.show();
        return;
    }
    try {
        FragmentManager fragmentManager = getChildFragmentManager();
        streamMediaBarFragment = StreamMediaPlayerBarFragment.newInstance();
        fragmentManager.beginTransaction().setCustomAnimations(R.anim.fade_in, R.anim.fade_out, R.anim.fade_in, R.anim.fade_out).add(R.id.fl__conversation__mediabar_container, streamMediaBarFragment, StreamMediaPlayerBarFragment.TAG).commit();
    } catch (IllegalStateException e) {
        Timber.e(e, "onShowMediaBar failed");
    }
}
Also used : FragmentManager(android.support.v4.app.FragmentManager) IConversation(com.waz.api.IConversation)

Example 25 with IConversation

use of com.waz.api.IConversation in project wire-android by wireapp.

the class ConversationFragment method onCursorButtonClicked.

@SuppressLint("NewApi")
@Override
public void onCursorButtonClicked(CursorMenuItem cursorMenuItem) {
    final IConversation conversation = getStoreFactory().getConversationStore().getCurrentConversation();
    switch(cursorMenuItem) {
        case AUDIO_MESSAGE:
            if (PermissionUtils.hasSelfPermissions(getActivity(), AUDIO_PERMISSION)) {
                openExtendedCursor(ExtendedCursorContainer.Type.VOICE_FILTER_RECORDING);
            } else {
                ActivityCompat.requestPermissions(getActivity(), AUDIO_PERMISSION, AUDIO_FILTER_PERMISSION_REQUEST_ID);
            }
            break;
        case CAMERA:
            if (LayoutSpec.isTablet(getContext())) {
                KeyboardUtils.closeKeyboardIfShown(getActivity());
                getControllerFactory().getCameraController().openCamera(CameraContext.MESSAGE);
                ((BaseScalaActivity) getActivity()).injectJava(GlobalTrackingController.class).tagEvent(OpenedMediaActionEvent.cursorAction(OpenedMediaAction.PHOTO, conversation));
            } else {
                if (PermissionUtils.hasSelfPermissions(getContext(), EXTENDED_CURSOR_PERMISSIONS)) {
                    openExtendedCursor(ExtendedCursorContainer.Type.IMAGES);
                } else {
                    ActivityCompat.requestPermissions(getActivity(), EXTENDED_CURSOR_PERMISSIONS, OPEN_EXTENDED_CURSOR_IMAGES);
                }
            }
            break;
        case PING:
            getStoreFactory().getNetworkStore().doIfHasInternetOrNotifyUser(new DefaultNetworkAction() {

                @Override
                public void execute(NetworkMode networkMode) {
                    getStoreFactory().getConversationStore().knockCurrentConversation();
                    SoundController ctrl = inject(SoundController.class);
                    if (ctrl != null) {
                        ctrl.playPingFromMe();
                    }
                }
            });
            TrackingUtils.onSentPingMessage(((BaseScalaActivity) getActivity()).injectJava(GlobalTrackingController.class), getStoreFactory().getConversationStore().getCurrentConversation());
            break;
        case SKETCH:
            getControllerFactory().getDrawingController().showDrawing(null, IDrawingController.DrawingDestination.SKETCH_BUTTON);
            ((BaseScalaActivity) getActivity()).injectJava(GlobalTrackingController.class).tagEvent(OpenedMediaActionEvent.cursorAction(OpenedMediaAction.SKETCH, conversation));
            break;
        case FILE:
            assetIntentsManager.openFileSharing();
            ((BaseScalaActivity) getActivity()).injectJava(GlobalTrackingController.class).tagEvent(OpenedMediaActionEvent.cursorAction(OpenedMediaAction.FILE, conversation));
            break;
        case VIDEO_MESSAGE:
            ((BaseScalaActivity) getActivity()).injectJava(GlobalTrackingController.class).tagEvent(OpenedMediaActionEvent.cursorAction(OpenedMediaAction.VIDEO_MESSAGE, conversation));
            isVideoMessageButtonClicked = true;
            getCameraController().releaseCamera(new Callback<Void>() {

                @Override
                public void callback(Void v) {
                    if (!isVideoMessageButtonClicked || assetIntentsManager == null) {
                        return;
                    }
                    isVideoMessageButtonClicked = false;
                    assetIntentsManager.maybeCaptureVideo(getActivity(), AssetIntentsManager.IntentType.VIDEO_CURSOR_BUTTON);
                }
            });
            break;
        case LOCATION:
            if (ConnectionResult.SUCCESS == GooglePlayServicesUtil.isGooglePlayServicesAvailable(getContext())) {
                KeyboardUtils.hideKeyboard(getActivity());
                getControllerFactory().getLocationController().showShareLocation();
                ((BaseScalaActivity) getActivity()).injectJava(GlobalTrackingController.class).tagEvent(OpenedMediaActionEvent.cursorAction(OpenedMediaAction.LOCATION, conversation));
            } else {
                Toast.makeText(getContext(), R.string.location_sharing__missing_play_services, Toast.LENGTH_LONG).show();
            }
            break;
        case MORE:
        case LESS:
            ((BaseScalaActivity) getActivity()).injectJava(GlobalTrackingController.class).tagEvent(new OpenedMoreActionsEvent(getConversationTypeString()));
            break;
        case GIF:
            getControllerFactory().getGiphyController().handleInput(cursorLayout.getText());
            ((BaseScalaActivity) getActivity()).injectJava(GlobalTrackingController.class).tagEvent(OpenedMediaActionEvent.cursorAction(OpenedMediaAction.GIPHY, conversation));
            break;
    }
}
Also used : SoundController(com.waz.zclient.media.SoundController) GlobalTrackingController(com.waz.zclient.tracking.GlobalTrackingController) DefaultNetworkAction(com.waz.zclient.core.stores.network.DefaultNetworkAction) IConversation(com.waz.api.IConversation) NetworkMode(com.waz.api.NetworkMode) OpenedMoreActionsEvent(com.waz.zclient.controllers.tracking.events.navigation.OpenedMoreActionsEvent) SuppressLint(android.annotation.SuppressLint)

Aggregations

IConversation (com.waz.api.IConversation)69 FragmentTest (com.waz.zclient.testutils.FragmentTest)25 Test (org.junit.Test)25 GlobalTrackingController (com.waz.zclient.tracking.GlobalTrackingController)14 View (android.view.View)10 User (com.waz.api.User)9 ArrayList (java.util.ArrayList)6 SuppressLint (android.annotation.SuppressLint)5 Intent (android.content.Intent)4 Handler (android.os.Handler)4 AbsListView (android.widget.AbsListView)4 CreatedGroupConversationEvent (com.waz.zclient.controllers.tracking.events.group.CreatedGroupConversationEvent)4 FooterMenuCallback (com.waz.zclient.views.menus.FooterMenuCallback)4 Instrumentation (android.app.Instrumentation)3 TextView (android.widget.TextView)3 BaseScalaActivity (com.waz.zclient.BaseScalaActivity)3 AddedMemberToGroupEvent (com.waz.zclient.controllers.tracking.events.group.AddedMemberToGroupEvent)3 ExceptionHandler (net.hockeyapp.android.ExceptionHandler)3 Animator (android.animation.Animator)2 AnimatorSet (android.animation.AnimatorSet)2