Search in sources :

Example 1 with NetworkAction

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

the class MockHelper method setupParticipantsMocks.

public static void setupParticipantsMocks(final IConversation mockConversation, final TestActivity activity) {
    IParticipantsStore mockParticipantsStore = activity.getStoreFactory().getParticipantsStore();
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) {
            Object[] args = invocation.getArguments();
            UpdateListener u = (UpdateListener) args[0];
            u.updated();
            return null;
        }
    }).when(mockConversation).addUpdateListener(any(UpdateListener.class));
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) {
            Object[] args = invocation.getArguments();
            ParticipantsStoreObserver o = (ParticipantsStoreObserver) args[0];
            o.conversationUpdated(mockConversation);
            return null;
        }
    }).when(mockParticipantsStore).addParticipantsStoreObserver(any(ParticipantsStoreObserver.class));
    INetworkStore mockNetworkStore = activity.getStoreFactory().getNetworkStore();
    when(mockNetworkStore.hasInternetConnection()).thenReturn(true);
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) {
            Object[] args = invocation.getArguments();
            NetworkAction a = (NetworkAction) args[0];
            a.execute(NetworkMode.WIFI);
            return null;
        }
    }).when(mockNetworkStore).doIfHasInternetOrNotifyUser(any(NetworkAction.class));
}
Also used : ParticipantsStoreObserver(com.waz.zclient.core.stores.participants.ParticipantsStoreObserver) InvocationOnMock(org.mockito.invocation.InvocationOnMock) IParticipantsStore(com.waz.zclient.core.stores.participants.IParticipantsStore) INetworkStore(com.waz.zclient.core.stores.network.INetworkStore) UpdateListener(com.waz.api.UpdateListener) NetworkAction(com.waz.zclient.core.stores.network.NetworkAction)

Example 2 with NetworkAction

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

the class SingleParticipantFragment method onUserUpdated.

//////////////////////////////////////////////////////////////////////////////////////////
//
//  SingleParticipantStoreObserver
//
//////////////////////////////////////////////////////////////////////////////////////////
@Override
public void onUserUpdated(final User user) {
    if (user == null) {
        return;
    }
    imageAssetImageViewProfile.connectImageAsset(user.getPicture());
    header.setText(user.getDisplayName());
    userDetailsView.setUser(user);
    shieldView.setVisibility(user.getVerified() == Verification.VERIFIED ? View.VISIBLE : View.GONE);
    // Show footer if profile is not for self user
    if (!user.isMe()) {
        if (!otherUserProfileScreenWasTracked) {
            otherUserProfileScreenWasTracked = true;
        }
        final boolean showingCommonUser = getArguments().getBoolean(ARGUMENT_SHOWING_COMMON_USER);
        final boolean ignoreRightClick = getArguments().getSerializable(ARGUMENT_USER_REQUESTER) == IConnectStore.UserRequester.CALL;
        if (ignoreRightClick) {
            footerMenu.setRightActionText("");
        } else if (showingCommonUser) {
            footerMenu.setRightActionText(getResources().getString(R.string.glyph__block));
        }
        footerMenu.setCallback(new FooterMenuCallback() {

            @Override
            public void onLeftActionClicked() {
                getControllerFactory().getConversationScreenController().hideParticipants(true, false);
                // Go to conversation with this user
                goToConversationWithUser = true;
                getContainer().dismissUserProfile();
                getStoreFactory().getConversationStore().setCurrentConversation(user.getConversation(), ConversationChangeRequester.START_CONVERSATION);
            }

            @Override
            public void onRightActionClicked() {
                if (ignoreRightClick) {
                    return;
                }
                if (showingCommonUser) {
                    showBlockConfirmation(user);
                } else {
                    getStoreFactory().getNetworkStore().doIfHasInternetOrNotifyUser(new NetworkAction() {

                        @Override
                        public void execute(NetworkMode networkMode) {
                            getContainer().showRemoveConfirmation(user);
                        }

                        @Override
                        public void onNoNetwork() {
                            ViewUtils.showAlertDialog(getActivity(), R.string.alert_dialog__no_network__header, R.string.remove_from_conversation__no_network__message, R.string.alert_dialog__confirmation, null, true);
                        }
                    });
                }
            }
        });
        if (getArguments().getSerializable(ARGUMENT_USER_REQUESTER) != IConnectStore.UserRequester.PARTICIPANTS) {
            footerMenu.setVisibility(View.VISIBLE);
        }
    }
}
Also used : FooterMenuCallback(com.waz.zclient.views.menus.FooterMenuCallback) NetworkMode(com.waz.api.NetworkMode) NetworkAction(com.waz.zclient.core.stores.network.NetworkAction)

Example 3 with NetworkAction

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

the class ZetaPreferencesActivity method onBitmapSelected.

@Override
public void onBitmapSelected(final ImageAsset imageAsset, boolean imageFromCamera, CameraContext cameraContext) {
    if (cameraContext != CameraContext.SETTINGS) {
        return;
    }
    getStoreFactory().getNetworkStore().doIfHasInternetOrNotifyUser(new NetworkAction() {

        @Override
        public void execute(NetworkMode networkMode) {
            getStoreFactory().getProfileStore().setUserPicture(imageAsset);
            getControllerFactory().getBackgroundController().setImageAsset(imageAsset);
            injectJava(GlobalTrackingController.class).tagEvent(new ChangedProfilePictureEvent());
        }

        @Override
        public void onNoNetwork() {
            ViewUtils.showAlertDialog(ZetaPreferencesActivity.this, R.string.alert_dialog__no_network__header, R.string.profile_pic__no_network__message, R.string.alert_dialog__confirmation, null, true);
        }
    });
    getSupportFragmentManager().popBackStack(CameraFragment.TAG, FragmentManager.POP_BACK_STACK_INCLUSIVE);
}
Also used : ChangedProfilePictureEvent(com.waz.zclient.core.controllers.tracking.events.settings.ChangedProfilePictureEvent) NetworkMode(com.waz.api.NetworkMode) NetworkAction(com.waz.zclient.core.stores.network.NetworkAction)

Example 4 with NetworkAction

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

the class DeviceDetailPreferences method updateOtrClientDetails.

private void updateOtrClientDetails() {
    // Name
    Preference preference = findPreference(getString(R.string.pref_device_details_device_key));
    preference.setTitle(DevicesPreferencesUtil.getTitle(getActivity(), otrClient));
    preference.setSummary(DevicesPreferencesUtil.getSummary(getActivity(), otrClient, true));
    // Fingerprint
    final FingerprintPreference fingerPrintPreference = (FingerprintPreference) findPreference(getString(R.string.pref_device_details_fingerprint_key));
    if (fingerprint == null) {
        fingerprint = otrClient.getFingerprint();
        fingerprintSubscription = fingerprint.subscribe(new Subscriber<Fingerprint>() {

            @Override
            public void next(Fingerprint fingerprint) {
                fingerPrintPreference.setFingerprint(fingerprint);
            }
        });
    }
    //Trust
    final SwitchPreference verifySwitchPreference = (SwitchPreference) findPreference(getString(R.string.pref_device_details_trust_key));
    if (currentDevice) {
        PreferenceCategory group = (PreferenceCategory) findPreference(getString(R.string.pref_device_details_fingerprint_category_key));
        group.removePreference(verifySwitchPreference);
    } else {
        verifySwitchPreference.setChecked(otrClient.getVerified() == Verification.VERIFIED);
        // Note: Using OnPreferenceClickListener as it was some issues with getting
        //       OnPreferenceChangeListener to work.
        verifySwitchPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

            @Override
            public boolean onPreferenceClick(Preference preference) {
                boolean newVerifiredValue = otrClient.getVerified() != Verification.VERIFIED;
                otrClient.setVerified(newVerifiredValue);
                verifySwitchPreference.setChecked(newVerifiredValue);
                trackVerified(newVerifiredValue);
                return true;
            }
        });
    }
    // Remove
    if (currentDevice) {
        Preference actionsPreference = findPreference(getString(R.string.pref_device_details_actions_category_key));
        PreferenceScreen screen = (PreferenceScreen) findPreference(getString(R.string.pref_device_details_screen_key));
        screen.removePreference(actionsPreference);
    } else {
        Preference resetSessionPreference = findPreference(getString(R.string.pref_device_details_reset_session_key));
        resetSessionPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

            @Override
            public boolean onPreferenceClick(Preference preference) {
                resetSession();
                return true;
            }
        });
        preference = findPreference(getString(R.string.pref_device_details_remove_key));
        preference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

            @Override
            public boolean onPreferenceClick(Preference preference) {
                getStoreFactory().getNetworkStore().doIfHasInternetOrNotifyUser(new NetworkAction() {

                    @Override
                    public void execute(NetworkMode networkMode) {
                        if (getControllerFactory().getPasswordController().hasPassword()) {
                            deleteCurrentDevice();
                        } else {
                            showRemoveDeviceDialog();
                        }
                    }

                    @Override
                    public void onNoNetwork() {
                        ViewUtils.showAlertDialog(DeviceDetailPreferences.this.getActivity(), R.string.otr__remove_device__no_internet__title, R.string.otr__remove_device__no_internet__message, R.string.otr__remove_device__no_internet__button, null, true);
                    }
                });
                return true;
            }
        });
    }
}
Also used : Fingerprint(com.waz.api.Fingerprint) PreferenceScreen(android.support.v7.preference.PreferenceScreen) SwitchPreference(net.xpece.android.support.preference.SwitchPreference) Preference(android.support.v7.preference.Preference) Subscriber(com.waz.api.Subscriber) SwitchPreference(net.xpece.android.support.preference.SwitchPreference) PreferenceCategory(net.xpece.android.support.preference.PreferenceCategory) NetworkMode(com.waz.api.NetworkMode) NetworkAction(com.waz.zclient.core.stores.network.NetworkAction)

Example 5 with NetworkAction

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

the class ParticipantBodyFragment method onConnectUserUpdated.

@Override
public void onConnectUserUpdated(final User user, IConnectStore.UserRequester usertype) {
    if (usertype != userRequester || user == null) {
        return;
    }
    imageAssetImageView.setVisibility(View.VISIBLE);
    imageAssetImageView.connectImageAsset(user.getPicture());
    footerMenu.setVisibility(View.VISIBLE);
    topBorder.setVisibility(View.INVISIBLE);
    final IConversation conversation = getStoreFactory().getConversationStore().getCurrentConversation();
    if (conversation.getType() == IConversation.Type.ONE_TO_ONE) {
        if (user.isMe()) {
            footerMenu.setLeftActionText(getString(R.string.glyph__profile));
            footerMenu.setLeftActionLabelText(getString(R.string.popover__action__profile));
            footerMenu.setRightActionText("");
            footerMenu.setRightActionLabelText("");
        } else {
            footerMenu.setLeftActionText(getString(R.string.glyph__add_people));
            footerMenu.setLeftActionLabelText(getString(R.string.conversation__action__create_group));
            footerMenu.setRightActionText(getString(R.string.glyph__block));
            footerMenu.setRightActionLabelText(getString(R.string.popover__action__block));
        }
    } else {
        if (user.isMe()) {
            footerMenu.setLeftActionText(getString(R.string.glyph__profile));
            footerMenu.setLeftActionLabelText(getString(R.string.popover__action__profile));
            footerMenu.setRightActionText(getString(R.string.glyph__minus));
            footerMenu.setRightActionLabelText("");
        } else {
            footerMenu.setLeftActionText(getString(R.string.glyph__conversation));
            footerMenu.setLeftActionLabelText(getString(R.string.popover__action__open));
            footerMenu.setRightActionText(getString(R.string.glyph__minus));
            footerMenu.setRightActionLabelText(getString(R.string.popover__action__remove));
        }
    }
    footerMenu.setCallback(new FooterMenuCallback() {

        @Override
        public void onLeftActionClicked() {
            if (user.isMe() || conversation.getType() != IConversation.Type.ONE_TO_ONE) {
                getControllerFactory().getConversationScreenController().hideParticipants(true, false);
                // Go to conversation with this user
                getControllerFactory().getPickUserController().hidePickUserWithoutAnimations(getContainer().getCurrentPickerDestination());
                getStoreFactory().getConversationStore().setCurrentConversation(user.getConversation(), ConversationChangeRequester.START_CONVERSATION);
            } else {
                ((BaseScalaActivity) getActivity()).injectJava(GlobalTrackingController.class).tagEvent(new OpenedGroupActionEvent());
                getControllerFactory().getConversationScreenController().addPeopleToConversation();
            }
        }

        @Override
        public void onRightActionClicked() {
            if (conversation.getType() == IConversation.Type.ONE_TO_ONE) {
                if (!user.isMe()) {
                    getContainer().toggleBlockUser(user, user.getConnectionStatus() != User.ConnectionStatus.BLOCKED);
                }
            } else {
                getStoreFactory().getNetworkStore().doIfHasInternetOrNotifyUser(new NetworkAction() {

                    @Override
                    public void execute(NetworkMode networkMode) {
                        if (user.isMe()) {
                            showLeaveConfirmation(getStoreFactory().getConversationStore().getCurrentConversation());
                        } else {
                            getContainer().showRemoveConfirmation(user);
                        }
                    }

                    @Override
                    public void onNoNetwork() {
                        if (user.isMe()) {
                            ViewUtils.showAlertDialog(getActivity(), R.string.alert_dialog__no_network__header, R.string.leave_conversation_failed__message, R.string.alert_dialog__confirmation, null, true);
                        } else {
                            ViewUtils.showAlertDialog(getActivity(), R.string.alert_dialog__no_network__header, R.string.remove_from_conversation__no_network__message, R.string.alert_dialog__confirmation, null, true);
                        }
                    }
                });
            }
        }
    });
}
Also used : BaseScalaActivity(com.waz.zclient.BaseScalaActivity) OpenedGroupActionEvent(com.waz.zclient.controllers.tracking.events.group.OpenedGroupActionEvent) IConversation(com.waz.api.IConversation) FooterMenuCallback(com.waz.zclient.views.menus.FooterMenuCallback) NetworkMode(com.waz.api.NetworkMode) NetworkAction(com.waz.zclient.core.stores.network.NetworkAction)

Aggregations

NetworkAction (com.waz.zclient.core.stores.network.NetworkAction)6 NetworkMode (com.waz.api.NetworkMode)5 FooterMenuCallback (com.waz.zclient.views.menus.FooterMenuCallback)3 BaseScalaActivity (com.waz.zclient.BaseScalaActivity)2 OpenedGroupActionEvent (com.waz.zclient.controllers.tracking.events.group.OpenedGroupActionEvent)2 Preference (android.support.v7.preference.Preference)1 PreferenceScreen (android.support.v7.preference.PreferenceScreen)1 Fingerprint (com.waz.api.Fingerprint)1 IConversation (com.waz.api.IConversation)1 Subscriber (com.waz.api.Subscriber)1 UpdateListener (com.waz.api.UpdateListener)1 User (com.waz.api.User)1 ChangedProfilePictureEvent (com.waz.zclient.core.controllers.tracking.events.settings.ChangedProfilePictureEvent)1 INetworkStore (com.waz.zclient.core.stores.network.INetworkStore)1 IParticipantsStore (com.waz.zclient.core.stores.participants.IParticipantsStore)1 ParticipantsStoreObserver (com.waz.zclient.core.stores.participants.ParticipantsStoreObserver)1 PreferenceCategory (net.xpece.android.support.preference.PreferenceCategory)1 SwitchPreference (net.xpece.android.support.preference.SwitchPreference)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1