Search in sources :

Example 1 with Subscriber

use of com.waz.api.Subscriber 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 2 with Subscriber

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

the class DevicesPreferences method setupOtrDevices.

private void setupOtrDevices() {
    if (getStoreFactory() == null || getStoreFactory().isTornDown()) {
        return;
    }
    Self self = getStoreFactory().getZMessagingApiStore().getApi().getSelf();
    if (otrClient == null) {
        otrClient = self.getOtrClient();
    }
    if (otherClients == null) {
        otherClients = self.getOtherOtrClients();
        otherClients.addUpdateListener(otrClientsUpdateListener);
    }
    updateOtrDevices();
    final PreferenceGroup currentOtrClientPreferenceGroup = (PreferenceGroup) findPreference(getString(R.string.pref_devices_current_device_category_key));
    otrClientSubscription = otrClient.subscribe(new Subscriber<OtrClient>() {

        @Override
        public void next(OtrClient value) {
            if (getActivity() == null) {
                return;
            }
            currentOtrClientPreferenceGroup.setTitle(getString(R.string.pref_devices_current_device_category_title));
            currentOtrClientPreferenceGroup.removeAll();
            net.xpece.android.support.preference.Preference preference = new net.xpece.android.support.preference.Preference(getContext());
            preference.setTitle(DevicesPreferencesUtil.getTitle(getActivity(), value));
            preference.setSummary(DevicesPreferencesUtil.getSummary(getActivity(), value, false));
            preference.setKey(getString(R.string.pref_device_details_screen_key));
            final PreferenceScreen preferenceScreen = new PreferenceScreen(getContext(), null);
            preferenceScreen.getExtras().putParcelable(DeviceDetailPreferences.PREFS_OTR_CLIENT, value);
            preferenceScreen.getExtras().putBoolean(DeviceDetailPreferences.PREFS_CURRENT_DEVICE, true);
            preferenceScreen.setTitle(preference.getTitle());
            preferenceScreen.setKey(preference.getKey());
            preference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

                @Override
                public boolean onPreferenceClick(Preference preference) {
                    PreferenceManager preferenceManager = getPreferenceManager();
                    if (preferenceManager != null) {
                        PreferenceManager.OnNavigateToScreenListener listener = preferenceManager.getOnNavigateToScreenListener();
                        if (listener != null) {
                            listener.onNavigateToScreen(preferenceScreen);
                            return true;
                        }
                    }
                    return false;
                }
            });
            currentOtrClientPreferenceGroup.addPreference(preference);
        }
    });
}
Also used : PreferenceScreen(android.support.v7.preference.PreferenceScreen) Self(com.waz.api.Self) PreferenceManager(android.support.v7.preference.PreferenceManager) Subscriber(com.waz.api.Subscriber) Preference(android.support.v7.preference.Preference) PreferenceGroup(android.support.v7.preference.PreferenceGroup) OtrClient(com.waz.api.OtrClient)

Aggregations

Preference (android.support.v7.preference.Preference)2 PreferenceScreen (android.support.v7.preference.PreferenceScreen)2 Subscriber (com.waz.api.Subscriber)2 PreferenceGroup (android.support.v7.preference.PreferenceGroup)1 PreferenceManager (android.support.v7.preference.PreferenceManager)1 Fingerprint (com.waz.api.Fingerprint)1 NetworkMode (com.waz.api.NetworkMode)1 OtrClient (com.waz.api.OtrClient)1 Self (com.waz.api.Self)1 NetworkAction (com.waz.zclient.core.stores.network.NetworkAction)1 PreferenceCategory (net.xpece.android.support.preference.PreferenceCategory)1 SwitchPreference (net.xpece.android.support.preference.SwitchPreference)1