Search in sources :

Example 1 with NetworkMode

use of com.waz.api.NetworkMode 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)

Example 2 with NetworkMode

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

the class PickUserFragment method onContactListContactClicked.

@Override
public void onContactListContactClicked(final ContactDetails contactDetails) {
    getStoreFactory().getNetworkStore().doIfHasInternetOrNotifyUser(new DefaultNetworkAction() {

        @Override
        public void execute(NetworkMode networkMode) {
            final int contactMethodsCount = contactDetails.getContactMethods().size();
            final ContactMethod[] contactMethods = contactDetails.getContactMethods().toArray(new ContactMethod[contactMethodsCount]);
            if (contactMethodsCount == 1 && contactMethods[0].getKind() == ContactMethod.Kind.SMS) {
                // Launch SMS app directly if contact only has phone numner
                final String number = contactMethods[0].getStringRepresentation();
                sendSMSInvite(number);
                ((BaseScalaActivity) getActivity()).injectJava(GlobalTrackingController.class).tagEvent(new OpenedGenericInviteMenuEvent(OpenedGenericInviteMenuEvent.EventContext.ADDRESSBOOK));
                return;
            }
            final CharSequence[] itemNames = new CharSequence[contactMethodsCount];
            for (int i = 0; i < contactMethodsCount; i++) {
                ContactMethod contactMethod = contactMethods[i];
                itemNames[i] = contactMethod.getStringRepresentation();
            }
            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
            builder.setTitle(getResources().getString(R.string.people_picker__contact_list__invite_dialog__title)).setPositiveButton(getResources().getText(R.string.confirmation_menu__confirm_done), new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    ListView lv = dialog.getListView();
                    int selected = lv.getCheckedItemPosition();
                    ContactMethod selectedContactMethod = null;
                    if (selected >= 0) {
                        selectedContactMethod = contactMethods[selected];
                    }
                    if (selectedContactMethod == null) {
                        return;
                    }
                    if (selectedContactMethod.getKind() == ContactMethod.Kind.SMS) {
                        final String number = String.valueOf(itemNames[selected]);
                        sendSMSInvite(number);
                        ((BaseScalaActivity) getActivity()).injectJava(GlobalTrackingController.class).tagEvent(new OpenedGenericInviteMenuEvent(OpenedGenericInviteMenuEvent.EventContext.ADDRESSBOOK));
                    } else {
                        selectedContactMethod.invite(" ", null);
                        Toast.makeText(getActivity(), getResources().getString(R.string.people_picker__invite__sent_feedback), Toast.LENGTH_LONG).show();
                        boolean fromSearch = TextUtils.isEmpty(getControllerFactory().getPickUserController().getSearchFilter());
                        TrackingUtils.tagSentInviteToContactEvent(((BaseScalaActivity) getActivity()).injectJava(GlobalTrackingController.class), selectedContactMethod.getKind(), contactDetails.hasBeenInvited(), fromSearch);
                    }
                }
            }).setNegativeButton(getResources().getText(R.string.confirmation_menu__cancel), new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    dialogInterface.cancel();
                }
            }).setSingleChoiceItems(itemNames, DEFAULT_SELECTED_INVITE_METHOD, null);
            dialog = builder.create();
            dialog.show();
            ((BaseScalaActivity) getActivity()).injectJava(GlobalTrackingController.class).onApplicationScreen(ApplicationScreen.SEND_PERSONAL_INVITE_MENU);
        }
    });
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) BaseScalaActivity(com.waz.zclient.BaseScalaActivity) GlobalTrackingController(com.waz.zclient.tracking.GlobalTrackingController) DialogInterface(android.content.DialogInterface) NetworkMode(com.waz.api.NetworkMode) ListView(android.widget.ListView) OpenedGenericInviteMenuEvent(com.waz.zclient.controllers.tracking.events.connect.OpenedGenericInviteMenuEvent) DefaultNetworkAction(com.waz.zclient.core.stores.network.DefaultNetworkAction) ContactMethod(com.waz.api.ContactMethod)

Example 3 with NetworkMode

use of com.waz.api.NetworkMode 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 4 with NetworkMode

use of com.waz.api.NetworkMode 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 5 with NetworkMode

use of com.waz.api.NetworkMode 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)

Aggregations

NetworkMode (com.waz.api.NetworkMode)7 NetworkAction (com.waz.zclient.core.stores.network.NetworkAction)5 BaseScalaActivity (com.waz.zclient.BaseScalaActivity)3 FooterMenuCallback (com.waz.zclient.views.menus.FooterMenuCallback)3 IConversation (com.waz.api.IConversation)2 OpenedGroupActionEvent (com.waz.zclient.controllers.tracking.events.group.OpenedGroupActionEvent)2 DefaultNetworkAction (com.waz.zclient.core.stores.network.DefaultNetworkAction)2 GlobalTrackingController (com.waz.zclient.tracking.GlobalTrackingController)2 SuppressLint (android.annotation.SuppressLint)1 DialogInterface (android.content.DialogInterface)1 AlertDialog (android.support.v7.app.AlertDialog)1 Preference (android.support.v7.preference.Preference)1 PreferenceScreen (android.support.v7.preference.PreferenceScreen)1 ListView (android.widget.ListView)1 ContactMethod (com.waz.api.ContactMethod)1 Fingerprint (com.waz.api.Fingerprint)1 Subscriber (com.waz.api.Subscriber)1 User (com.waz.api.User)1 OpenedGenericInviteMenuEvent (com.waz.zclient.controllers.tracking.events.connect.OpenedGenericInviteMenuEvent)1 OpenedMoreActionsEvent (com.waz.zclient.controllers.tracking.events.navigation.OpenedMoreActionsEvent)1