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);
}
});
}
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);
}
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();
}
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());
}
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);
}
}
}
Aggregations