Search in sources :

Example 1 with Fingerprint

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

the class SingleOtrClientFragmentTest method launchFragmentWithoutParameters_shouldDisplayDefaultText.

@Test
public void launchFragmentWithoutParameters_shouldDisplayDefaultText() {
    Self mockSelf = mock(Self.class);
    Fingerprint mockFingerprint = mock(Fingerprint.class);
    setupMocksForCurrentOtrClient(mockSelf, mockFingerprint);
    attachFragment(SingleOtrClientFragment.newInstance(), SingleOtrClientFragment.TAG);
    String text = activity.getString(R.string.otr__participant__my_device__description);
    onView(withId(R.id.ttv__single_otr_client__description)).check(hasText(text));
}
Also used : Fingerprint(com.waz.api.Fingerprint) Self(com.waz.api.Self) FragmentTest(com.waz.zclient.testutils.FragmentTest) Test(org.junit.Test)

Example 2 with Fingerprint

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

the class SingleOtrClientFragmentTest method setupMocksForOtherOtrClient.

private static void setupMocksForOtherOtrClient(User mockUser, OtrClient mockOtrClient) {
    when(mockUser.getDisplayName()).thenReturn(DEFAULT_DISPLAY_NAME);
    Fingerprint mockFingerprint = mock(Fingerprint.class);
    UiSignal<Fingerprint> fingerprintUiSignal = MockHelper.mockUiSignal();
    when(mockOtrClient.getFingerprint()).thenReturn(fingerprintUiSignal);
    MockHelper.mockSubscription(fingerprintUiSignal, mockFingerprint);
    when(mockFingerprint.getRawBytes()).thenReturn(DEFAULT_FINGERPRINT.getBytes());
}
Also used : Fingerprint(com.waz.api.Fingerprint)

Example 3 with Fingerprint

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

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

the class SingleOtrClientFragmentTest method launchFragmentWithoutParameters_shouldShowFormatterFingerprint.

@Test
public void launchFragmentWithoutParameters_shouldShowFormatterFingerprint() {
    Self mockSelf = mock(Self.class);
    Fingerprint mockFingerprint = mock(Fingerprint.class);
    setupMocksForCurrentOtrClient(mockSelf, mockFingerprint);
    attachFragment(SingleOtrClientFragment.newInstance(), SingleOtrClientFragment.TAG);
    onView(withId(R.id.ttv__single_otr_client__fingerprint)).check(hasText("aa bb cc dd 11 22 33 44"));
}
Also used : Fingerprint(com.waz.api.Fingerprint) Self(com.waz.api.Self) FragmentTest(com.waz.zclient.testutils.FragmentTest) Test(org.junit.Test)

Example 5 with Fingerprint

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

Aggregations

Fingerprint (com.waz.api.Fingerprint)6 Self (com.waz.api.Self)3 FragmentTest (com.waz.zclient.testutils.FragmentTest)3 Test (org.junit.Test)3 Preference (android.support.v7.preference.Preference)1 PreferenceScreen (android.support.v7.preference.PreferenceScreen)1 NetworkMode (com.waz.api.NetworkMode)1 OtrClient (com.waz.api.OtrClient)1 Subscriber (com.waz.api.Subscriber)1 User (com.waz.api.User)1 ZMessagingApi (com.waz.api.ZMessagingApi)1 IZMessagingApiStore (com.waz.zclient.core.stores.api.IZMessagingApiStore)1 NetworkAction (com.waz.zclient.core.stores.network.NetworkAction)1 IProfileStore (com.waz.zclient.core.stores.profile.IProfileStore)1 PreferenceCategory (net.xpece.android.support.preference.PreferenceCategory)1 SwitchPreference (net.xpece.android.support.preference.SwitchPreference)1