Search in sources :

Example 6 with OtrClient

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

Example 7 with OtrClient

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

the class SingleOtrClientFragmentTest method setupMocksForCurrentOtrClient.

private void setupMocksForCurrentOtrClient(Self mockSelf, Fingerprint mockFingerprint) {
    IZMessagingApiStore mockZMessagingApiStore = activity.getStoreFactory().getZMessagingApiStore();
    ZMessagingApi mockZMessagingApi = mock(ZMessagingApi.class);
    when(mockZMessagingApiStore.getApi()).thenReturn(mockZMessagingApi);
    when(mockZMessagingApi.getSelf()).thenReturn(mockSelf);
    UiSignal<OtrClient> otrClientUiSignal = MockHelper.mockUiSignal();
    when(mockSelf.getOtrClient()).thenReturn(otrClientUiSignal);
    final OtrClient mockOtrClient = mock(OtrClient.class);
    MockHelper.mockSubscription(otrClientUiSignal, mockOtrClient);
    UiSignal<Fingerprint> fingerprintUiSignal = MockHelper.mockUiSignal();
    when(mockOtrClient.getFingerprint()).thenReturn(fingerprintUiSignal);
    MockHelper.mockSubscription(fingerprintUiSignal, mockFingerprint);
    when(mockFingerprint.getRawBytes()).thenReturn(DEFAULT_FINGERPRINT.getBytes());
    // Not really needed, as user is not used for current device
    IProfileStore mockProfileStore = activity.getStoreFactory().getProfileStore();
    User mockUser = mock(User.class);
    when(mockProfileStore.getSelfUser()).thenReturn(mockUser);
}
Also used : Fingerprint(com.waz.api.Fingerprint) ZMessagingApi(com.waz.api.ZMessagingApi) IProfileStore(com.waz.zclient.core.stores.profile.IProfileStore) User(com.waz.api.User) OtrClient(com.waz.api.OtrClient) IZMessagingApiStore(com.waz.zclient.core.stores.api.IZMessagingApiStore)

Example 8 with OtrClient

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

the class SingleOtrClientFragmentTest method launchFragmentWithParametersAndClickBack_shouldCallController.

@Test
public void launchFragmentWithParametersAndClickBack_shouldCallController() {
    User mockUser = mock(User.class);
    OtrClient mockOtrClient = mock(OtrClient.class);
    setupMocksForOtherOtrClient(mockUser, mockOtrClient);
    when(mockOtrClient.getVerified()).thenReturn(Verification.UNVERIFIED);
    attachFragment(SingleOtrClientFragment.newInstance(mockOtrClient, mockUser), SingleOtrClientFragment.TAG);
    onView(withId(R.id.gtv__single_otr_client__back)).perform(click());
    verify(activity.getControllerFactory().getConversationScreenController()).hideOtrClient();
}
Also used : User(com.waz.api.User) OtrClient(com.waz.api.OtrClient) FragmentTest(com.waz.zclient.testutils.FragmentTest) Test(org.junit.Test)

Example 9 with OtrClient

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

the class SingleOtrClientFragmentTest method launchFragmentWithParameters_shouldDisplayOtherOtrClient.

@Test
public void launchFragmentWithParameters_shouldDisplayOtherOtrClient() {
    User mockUser = mock(User.class);
    OtrClient mockOtrClient = mock(OtrClient.class);
    setupMocksForOtherOtrClient(mockUser, mockOtrClient);
    attachFragment(SingleOtrClientFragment.newInstance(mockOtrClient, mockUser), SingleOtrClientFragment.TAG);
    onView(withId(R.id.os__single_otr_client__verify)).check(isVisible());
    onView(withId(R.id.gtv__single_otr_client__back)).check(isVisible());
    onView(withId(R.id.ttv__single_otr_client__my_fingerprint)).check(isVisible());
    onView(withId(R.id.gtv__single_otr_client__close)).check(isGone());
    onView(withId(R.id.ttv__single_otr_client__my_devices)).check(isGone());
}
Also used : User(com.waz.api.User) OtrClient(com.waz.api.OtrClient) FragmentTest(com.waz.zclient.testutils.FragmentTest) Test(org.junit.Test)

Example 10 with OtrClient

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

the class RootPreferences method onCreatePreferences2.

@Override
public void onCreatePreferences2(Bundle savedInstanceState, String rootKey) {
    super.onCreatePreferences2(savedInstanceState, rootKey);
    if (BuildConfig.SHOW_DEVELOPER_OPTIONS) {
        addPreferencesFromResource(R.xml.preference_root__developer);
        findPreference(getString(R.string.pref_dev_avs_screen_key)).setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

            @Override
            public boolean onPreferenceClick(Preference preference) {
                getChildFragmentManager().beginTransaction().setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE).add(AvsOptionsDialogFragment.newInstance(), AvsOptionsDialogFragment.TAG).addToBackStack(AvsOptionsDialogFragment.TAG).commit();
                return true;
            }
        });
    } else {
        addPreferencesFromResource(R.xml.preference_root);
    }
    inviteButtonPreference = (ButtonPreference) findPreference(getString(R.string.pref_invite_key));
    inviteButtonPreference.setAccentColor(getControllerFactory().getAccentColorController().getColor());
    inviteButtonPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            sendGenericInvite();
            return true;
        }
    });
    devicesPreferenceScreenLike = (BadgeablePreferenceScreenLike) findPreference(getString(R.string.pref_devices_screen_key));
    devicesPreferenceScreenLike.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            if (otrClients != null) {
                for (OtrClient client : otrClients) {
                    client.setVerified(false);
                }
            }
            return false;
        }
    });
    getStoreFactory().getZMessagingApiStore().getApi().onInit(new InitListener() {

        @Override
        public void onInitialized(Self user) {
            otrClientsObserver.setAndUpdate(getStoreFactory().getZMessagingApiStore().getApi().getSelf().getIncomingOtrClients());
        }
    });
    if (savedInstanceState == null) {
        boolean showSpotifyLogin = getArguments().getBoolean(ZetaPreferencesActivity.SHOW_SPOTIFY_LOGIN, false);
        boolean showOtrDevices = getArguments().getBoolean(ZetaPreferencesActivity.SHOW_OTR_DEVICES, false);
        boolean showAccount = getArguments().getBoolean(ZetaPreferencesActivity.SHOW_ACCOUNT, false);
        boolean showUsernameEdit = getArguments().getBoolean(ZetaPreferencesActivity.SHOW_USERNAME_EDIT);
        final PreferenceManager.OnNavigateToScreenListener navigateToScreenListener = getPreferenceManager().getOnNavigateToScreenListener();
        PreferenceScreen preference = null;
        if (showAccount) {
            preference = (PreferenceScreen) findPreference(getString(R.string.pref_account_screen_key));
        } else if (showSpotifyLogin) {
            preference = (PreferenceScreen) findPreference(getString(R.string.pref_options_screen_key));
            getControllerFactory().getSpotifyController().login(getActivity());
        } else if (showOtrDevices) {
            preference = devicesPreferenceScreenLike.getPreferenceScreen();
        } else if (showUsernameEdit) {
            preference = ((BadgeablePreferenceScreenLike) findPreference(getString(R.string.pref_account_screen_key))).getPreferenceScreen();
        }
        if (preference != null) {
            preference.getExtras().putAll(getArguments());
            navigateToScreenListener.onNavigateToScreen(preference);
        }
    }
}
Also used : InitListener(com.waz.api.InitListener) PreferenceScreen(android.support.v7.preference.PreferenceScreen) Preference(android.support.v7.preference.Preference) Self(com.waz.api.Self) OtrClient(com.waz.api.OtrClient) PreferenceManager(android.support.v7.preference.PreferenceManager)

Aggregations

OtrClient (com.waz.api.OtrClient)11 User (com.waz.api.User)8 FragmentTest (com.waz.zclient.testutils.FragmentTest)5 Test (org.junit.Test)5 Preference (android.support.v7.preference.Preference)2 PreferenceGroup (android.support.v7.preference.PreferenceGroup)2 PreferenceManager (android.support.v7.preference.PreferenceManager)2 PreferenceScreen (android.support.v7.preference.PreferenceScreen)2 Self (com.waz.api.Self)2 SuppressLint (android.annotation.SuppressLint)1 ActionMenuView (android.support.v7.widget.ActionMenuView)1 View (android.view.View)1 AbsListView (android.widget.AbsListView)1 TextView (android.widget.TextView)1 Fingerprint (com.waz.api.Fingerprint)1 IConversation (com.waz.api.IConversation)1 InitListener (com.waz.api.InitListener)1 Message (com.waz.api.Message)1 Subscriber (com.waz.api.Subscriber)1 ZMessagingApi (com.waz.api.ZMessagingApi)1