@Provides @Singleton OkHttpClient provideOkHttpClient( Application app, Preference<InetSocketAddress> networkProxyAddress) { return DataModule.createOkHttpClient(app) .sslSocketFactory(createBadSslSocketFactory()) .proxy(InetSocketAddressPreferenceAdapter.createProxy(networkProxyAddress.get())) .build(); }
private void showNewNetworkProxyDialog(final ProxyAdapter proxyAdapter) { final int originalSelection = networkProxyAddress.isSet() ? ProxyAdapter.PROXY : ProxyAdapter.NONE; View view = LayoutInflater.from(app).inflate(R.layout.debug_drawer_network_proxy, null); final EditText hostView = findById(view, R.id.debug_drawer_network_proxy_host); if (networkProxyAddress.isSet()) { String host = networkProxyAddress.get().getHostName(); hostView.setText(host); // Set the current host. hostView.setSelection(0, host.length()); // Pre-select it for editing. // Show the keyboard. Post this to the next frame when the dialog has been attached. hostView.post(() -> Keyboards.showKeyboard(hostView)); } new AlertDialog.Builder(getContext()) // .setTitle("Set Network Proxy") .setView(view) .setNegativeButton( "Cancel", (dialog, i) -> { networkProxyView.setSelection(originalSelection); dialog.cancel(); }) .setPositiveButton( "Use", (dialog, i) -> { String in = hostView.getText().toString(); InetSocketAddress address = InetSocketAddressPreferenceAdapter.parse(in); if (address != null) { networkProxyAddress.set(address); // Persist across restarts. proxyAdapter.notifyDataSetChanged(); // Tell the spinner to update. networkProxyView.setSelection(ProxyAdapter.PROXY); // And show the proxy. Proxy proxy = InetSocketAddressPreferenceAdapter.createProxy(address); client.setProxy(proxy); apiClient.setProxy(proxy); } else { networkProxyView.setSelection(originalSelection); } }) .setOnCancelListener(dialogInterface -> networkProxyView.setSelection(originalSelection)) .show(); }