use of java.util.concurrent.TimeUnit.MILLISECONDS in project sbt-android by scala-android.
the class DebugView method setupNetworkSection.
private void setupNetworkSection() {
final ApiEndpoints currentEndpoint = ApiEndpoints.from(networkEndpoint.get());
final EnumAdapter<ApiEndpoints> endpointAdapter = new EnumAdapter<>(getContext(), ApiEndpoints.class);
endpointView.setAdapter(endpointAdapter);
endpointView.setSelection(currentEndpoint.ordinal());
RxAdapterView.itemSelections(endpointView).map(endpointAdapter::getItem).filter(item -> item != currentEndpoint).subscribe(selected -> {
if (selected == ApiEndpoints.CUSTOM) {
Timber.d("Custom network endpoint selected. Prompting for URL.");
showCustomEndpointDialog(currentEndpoint.ordinal(), "http://");
} else {
setEndpointAndRelaunch(selected.url);
}
});
final NetworkDelayAdapter delayAdapter = new NetworkDelayAdapter(getContext());
networkDelayView.setAdapter(delayAdapter);
networkDelayView.setSelection(NetworkDelayAdapter.getPositionForValue(behavior.delay(MILLISECONDS)));
RxAdapterView.itemSelections(networkDelayView).map(delayAdapter::getItem).filter(item -> item != behavior.delay(MILLISECONDS)).subscribe(selected -> {
Timber.d("Setting network delay to %sms", selected);
behavior.setDelay(selected, MILLISECONDS);
networkDelay.set(selected);
});
final NetworkVarianceAdapter varianceAdapter = new NetworkVarianceAdapter(getContext());
networkVarianceView.setAdapter(varianceAdapter);
networkVarianceView.setSelection(NetworkVarianceAdapter.getPositionForValue(behavior.variancePercent()));
RxAdapterView.itemSelections(networkVarianceView).map(varianceAdapter::getItem).filter(item -> item != behavior.variancePercent()).subscribe(selected -> {
Timber.d("Setting network variance to %s%%", selected);
behavior.setVariancePercent(selected);
networkVariancePercent.set(selected);
});
final NetworkErrorAdapter errorAdapter = new NetworkErrorAdapter(getContext());
networkErrorView.setAdapter(errorAdapter);
networkErrorView.setSelection(NetworkErrorAdapter.getPositionForValue(behavior.failurePercent()));
RxAdapterView.itemSelections(networkErrorView).map(errorAdapter::getItem).filter(item -> item != behavior.failurePercent()).subscribe(selected -> {
Timber.d("Setting network error to %s%%", selected);
behavior.setFailurePercent(selected);
networkFailurePercent.set(selected);
});
int currentProxyPosition = networkProxyAddress.isSet() ? ProxyAdapter.PROXY : ProxyAdapter.NONE;
final ProxyAdapter proxyAdapter = new ProxyAdapter(getContext(), networkProxyAddress);
networkProxyView.setAdapter(proxyAdapter);
networkProxyView.setSelection(currentProxyPosition);
RxAdapterView.itemSelections(networkProxyView).filter(position -> !networkProxyAddress.isSet() || position != ProxyAdapter.PROXY).subscribe(position -> {
if (position == ProxyAdapter.NONE) {
Timber.d("Clearing network proxy");
// TODO: Keep the custom proxy around so you can easily switch back and forth.
networkProxyAddress.delete();
client.setProxy(null);
apiClient.setProxy(null);
} else if (networkProxyAddress.isSet() && position == ProxyAdapter.PROXY) {
Timber.d("Ignoring re-selection of network proxy %s", networkProxyAddress.get());
} else {
Timber.d("New network proxy selected. Prompting for host.");
showNewNetworkProxyDialog(proxyAdapter);
}
});
// Only show the endpoint editor when a custom endpoint is in use.
endpointEditView.setVisibility(currentEndpoint == ApiEndpoints.CUSTOM ? VISIBLE : GONE);
if (currentEndpoint == ApiEndpoints.MOCK_MODE) {
// Disable network proxy if we are in mock mode.
networkProxyView.setEnabled(false);
networkLoggingView.setEnabled(false);
} else {
// Disable network controls if we are not in mock mode.
networkDelayView.setEnabled(false);
networkVarianceView.setEnabled(false);
networkErrorView.setEnabled(false);
}
// We use the JSON rest adapter as the source of truth for the log level.
// final EnumAdapter<RestAdapter.LogLevel> loggingAdapter =
// new EnumAdapter<>(getContext(), RestAdapter.LogLevel.class);
// networkLoggingView.setAdapter(loggingAdapter);
// networkLoggingView.setSelection(retrofit.getLogLevel().ordinal());
// networkLoggingView.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
// @Override
// public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id) {
// RestAdapter.LogLevel selected = loggingAdapter.getItem(position);
// if (selected != retrofit.getLogLevel()) {
// Timber.d("Setting logging level to %s", selected);
// retrofit.setLogLevel(selected);
// } else {
// Timber.d("Ignoring re-selection of logging level " + selected);
// }
// }
//
// @Override public void onNothingSelected(AdapterView<?> adapterView) {
// }
// });
}
Aggregations