Search in sources :

Example 1 with SwitchPreference

use of net.xpece.android.support.preference.SwitchPreference 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 SwitchPreference

use of net.xpece.android.support.preference.SwitchPreference in project wire-android by wireapp.

the class OptionsPreferences method onCreatePreferences2.

@Override
public void onCreatePreferences2(Bundle savedInstanceState, String rootKey) {
    super.onCreatePreferences2(savedInstanceState, rootKey);
    addPreferencesFromResource(R.xml.preferences_options);
    ringtonePreference = (RingtonePreference) findPreference(getString(R.string.pref_options_ringtones_ringtone_key));
    textTonePreference = (RingtonePreference) findPreference(getString(R.string.pref_options_ringtones_text_key));
    pingPreference = (RingtonePreference) findPreference(getString(R.string.pref_options_ringtones_ping_key));
    ringtonePreference.setShowSilent(true);
    textTonePreference.setShowSilent(true);
    pingPreference.setShowSilent(true);
    setDefaultRingtones();
    bindPreferenceSummaryToValue(ringtonePreference);
    bindPreferenceSummaryToValue(textTonePreference);
    bindPreferenceSummaryToValue(pingPreference);
    spotifyPreference = findPreference(getString(R.string.pref_options_spotify_key));
    if (getControllerFactory().getSpotifyController().isLoggedIn()) {
        spotifyPreference.setTitle(R.string.pref_options_spotify_logout_title);
        spotifyPreference.setSummary("");
    } else {
        spotifyPreference.setTitle(R.string.pref_options_spotify_title);
        spotifyPreference.setSummary(R.string.pref_options_spotify_summary);
    }
    spotifyPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            if (getControllerFactory().getSpotifyController().isLoggedIn()) {
                getControllerFactory().getSpotifyController().logout();
            } else {
                getControllerFactory().getSpotifyController().login(getActivity());
            }
            return true;
        }
    });
    themePreference = (SwitchPreference) findPreference(getString(R.string.pref_options_theme_switch_key));
    themePreference.setChecked(getControllerFactory().getThemeController().isDarkTheme());
    if (LayoutSpec.isTablet(getActivity())) {
        PreferenceCategory requestedOptionsCategory = (PreferenceCategory) findPreference(getString(R.string.pref_options_requested_category_key));
        if (requestedOptionsCategory != null) {
            requestedOptionsCategory.removePreference(themePreference);
        }
    }
}
Also used : SwitchPreference(net.xpece.android.support.preference.SwitchPreference) RingtonePreference(net.xpece.android.support.preference.RingtonePreference) Preference(android.support.v7.preference.Preference) PreferenceCategory(android.support.v7.preference.PreferenceCategory)

Aggregations

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