示例#1
0
  private void setupMockBehaviorSection() {
    captureIntentsView.setEnabled(isMockMode);
    captureIntentsView.setChecked(captureIntents.get());
    captureIntentsView.setOnCheckedChangeListener(
        (compoundButton, b) -> {
          Timber.d("Capture intents set to %s", b);
          captureIntents.set(b);
        });

    configureResponseSpinner(repositoriesResponseView, MockRepositoriesResponse.class);
  }
示例#2
0
  private void setupPicassoSection() {
    boolean picassoDebuggingValue = picassoDebugging.get();
    picasso.setIndicatorsEnabled(picassoDebuggingValue);
    picassoIndicatorView.setChecked(picassoDebuggingValue);
    picassoIndicatorView.setOnCheckedChangeListener(
        (button, isChecked) -> {
          Timber.d("Setting Picasso debugging to " + isChecked);
          picasso.setIndicatorsEnabled(isChecked);
          picassoDebugging.set(isChecked);
        });

    refreshPicassoStats();
  }
示例#3
0
 @Provides
 @Singleton
 @AccessToken
 Preference<String> provideAccessToken(
     RxSharedPreferences prefs, @ApiEndpoint Preference<String> endpoint) {
   // Return an endpoint-specific preference.
   return prefs.getString("access-token-" + endpoint.get());
 }
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) {
    // Inflate the layout for this fragment
    View view = inflater.inflate(R.layout.fragment_library_category, container, false);
    ButterKnife.bind(this, view);

    adapter = new LibraryCategoryAdapter(this);
    recycler.setHasFixedSize(true);
    recycler.setAdapter(adapter);

    if (getLibraryFragment().getActionMode() != null) {
      setMode(FlexibleAdapter.MODE_MULTI);
    }

    Preference<Integer> columnsPref =
        getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT
            ? getLibraryPresenter().preferences.portraitColumns()
            : getLibraryPresenter().preferences.landscapeColumns();

    numColumnsSubscription =
        columnsPref
            .asObservable()
            .doOnNext(recycler::setSpanCount)
            .skip(1)
            // Set again the adapter to recalculate the covers height
            .subscribe(count -> recycler.setAdapter(adapter));

    if (savedState != null) {
      adapter.onRestoreInstanceState(savedState);

      if (adapter.getMode() == FlexibleAdapter.MODE_SINGLE) {
        adapter.clearSelection();
      }
    }

    searchSubscription =
        getLibraryPresenter()
            .searchSubject
            .subscribe(
                text -> {
                  adapter.setSearchText(text);
                  adapter.updateDataSet();
                });

    return view;
  }
示例#5
0
  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();
  }
示例#6
0
 @Provides
 @Singleton
 @IsMockMode
 boolean provideIsMockMode(
     @ApiEndpoint Preference<String> endpoint,
     @IsInstrumentationTest boolean isInstrumentationTest) {
   // Running in an instrumentation forces mock mode.
   return isInstrumentationTest || ApiEndpoints.isMockMode(endpoint.get());
 }
示例#7
0
 @Provides
 @Singleton
 OkHttpClient provideOkHttpClient(
     Application app, Preference<InetSocketAddress> networkProxyAddress) {
   return DataModule.createOkHttpClient(app)
       .sslSocketFactory(createBadSslSocketFactory())
       .proxy(InetSocketAddressPreferenceAdapter.createProxy(networkProxyAddress.get()))
       .build();
 }
 private void subscribeToChanges() {
   RxSharedPreferences prefs =
       RxSharedPreferences.create(PreferenceManager.getDefaultSharedPreferences(mAppContext));
   Preference<Integer> lastPage = prefs.getInteger(Constants.PREF_LAST_PAGE);
   Observable.merge(
           mBookmarkModel.tagsObservable(),
           mBookmarkModel.bookmarksObservable(),
           lastPage.asObservable())
       .observeOn(AndroidSchedulers.mainThread())
       .subscribe(
           new Action1<Object>() {
             @Override
             public void call(Object o) {
               if (mFragment != null) {
                 requestData(false);
               } else {
                 mCachedData = null;
               }
             }
           });
 }
示例#9
0
  private void setEndpointAndRelaunch(String endpoint) {
    Timber.d("Setting network endpoint to %s", endpoint);
    networkEndpoint.set(endpoint);

    ProcessPhoenix.triggerRebirth(getContext());
  }
示例#10
0
  private void setupUserInterfaceSection() {
    final AnimationSpeedAdapter speedAdapter = new AnimationSpeedAdapter(getContext());
    uiAnimationSpeedView.setAdapter(speedAdapter);
    final int animationSpeedValue = animationSpeed.get();
    uiAnimationSpeedView.setSelection(
        AnimationSpeedAdapter.getPositionForValue(animationSpeedValue));

    RxAdapterView.itemSelections(uiAnimationSpeedView)
        .map(speedAdapter::getItem)
        .filter(item -> item != animationSpeed.get())
        .subscribe(
            selected -> {
              Timber.d("Setting animation speed to %sx", selected);
              animationSpeed.set(selected);
              applyAnimationSpeed(selected);
            });
    // Ensure the animation speed value is always applied across app restarts.
    post(() -> applyAnimationSpeed(animationSpeedValue));

    boolean gridEnabled = pixelGridEnabled.get();
    uiPixelGridView.setChecked(gridEnabled);
    uiPixelRatioView.setEnabled(gridEnabled);
    uiPixelGridView.setOnCheckedChangeListener(
        (buttonView, isChecked) -> {
          Timber.d("Setting pixel grid overlay enabled to " + isChecked);
          pixelGridEnabled.set(isChecked);
          uiPixelRatioView.setEnabled(isChecked);
        });

    uiPixelRatioView.setChecked(pixelRatioEnabled.get());
    uiPixelRatioView.setOnCheckedChangeListener(
        (buttonView, isChecked) -> {
          Timber.d("Setting pixel scale overlay enabled to " + isChecked);
          pixelRatioEnabled.set(isChecked);
        });

    uiScalpelView.setChecked(scalpelEnabled.get());
    uiScalpelWireframeView.setEnabled(scalpelEnabled.get());
    uiScalpelView.setOnCheckedChangeListener(
        (buttonView, isChecked) -> {
          Timber.d("Setting scalpel interaction enabled to " + isChecked);
          scalpelEnabled.set(isChecked);
          uiScalpelWireframeView.setEnabled(isChecked);
        });

    uiScalpelWireframeView.setChecked(scalpelWireframeEnabled.get());
    uiScalpelWireframeView.setOnCheckedChangeListener(
        (buttonView, isChecked) -> {
          Timber.d("Setting scalpel wireframe enabled to " + isChecked);
          scalpelWireframeEnabled.set(isChecked);
        });
  }
示例#11
0
 @OnClick(R.id.debug_network_endpoint_edit)
 void onEditEndpointClicked() {
   Timber.d("Prompting to edit custom endpoint URL.");
   // Pass in the currently selected position since we are merely editing.
   showCustomEndpointDialog(endpointView.getSelectedItemPosition(), networkEndpoint.get());
 }
示例#12
0
  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) {
    //  }
    // });
  }
示例#13
0
 /**
  * 从返回的结果中提取Jwt的token值
  *
  * @param returnIntent
  */
 public void handleResult(Intent returnIntent) {
   String token = returnIntent.getStringExtra("token");
   accessToken.set(token);
 }