public DebugApplicationInstrumentation(
      @NonNull LeakTracing leakTracing, @NonNull Instrumentation instrumentation) {

    Preconditions.checkNotNull(leakTracing, "Leak Tracing cannot be null.");
    Preconditions.checkNotNull(instrumentation, "Instrumentation cannot be null.");

    this.leakTracing = leakTracing;
    this.instrumentation = instrumentation;
  }
Exemplo n.º 2
0
  public RepositoryViewModel(
      @NonNull DataLayer.GetUserSettings getUserSettings,
      @NonNull DataLayer.FetchAndGetGitHubRepository fetchAndGetGitHubRepository) {
    Preconditions.checkNotNull(getUserSettings, "Gey User Settings cannot be null.");
    Preconditions.checkNotNull(
        fetchAndGetGitHubRepository, "Fetch And Get GitHub Repository cannot be null.");

    this.getUserSettings = getUserSettings;
    this.fetchAndGetGitHubRepository = fetchAndGetGitHubRepository;
    Log.v(TAG, "RepositoryViewModel");
  }
  public GitHubRepositorySearchFetcher(
      @NonNull NetworkApi networkApi,
      @NonNull Action1<NetworkRequestStatus> updateNetworkRequestStatus,
      @NonNull GitHubRepositoryStore gitHubRepositoryStore,
      @NonNull GitHubRepositorySearchStore gitHubRepositorySearchStore) {
    super(networkApi, updateNetworkRequestStatus);

    Preconditions.checkNotNull(gitHubRepositoryStore, "GitHub Repository Store cannot be null.");
    Preconditions.checkNotNull(
        gitHubRepositorySearchStore, "" + "GitHub Repository Search Store cannot be null.");

    this.gitHubRepositoryStore = gitHubRepositoryStore;
    this.gitHubRepositorySearchStore = gitHubRepositorySearchStore;
  }
  @NonNull
  private Observable<List<GitHubRepository>> createNetworkObservable(
      @NonNull final String searchString) {
    Preconditions.checkNotNull(searchString, "Search String cannot be null.");

    return networkApi.search(Collections.singletonMap("q", searchString));
  }
  private void fetchGitHubSearch(@NonNull final String searchString) {
    Preconditions.checkNotNull(searchString, "Search String cannot be null.");

    Log.d(TAG, "fetchGitHubSearch(" + searchString + ")");
    if (requestMap.containsKey(searchString.hashCode())
        && !requestMap.get(searchString.hashCode()).isUnsubscribed()) {
      Log.d(TAG, "Found an ongoing request for repository " + searchString);
      return;
    }
    final String uri = gitHubRepositorySearchStore.getUriForKey(searchString).toString();
    Subscription subscription =
        createNetworkObservable(searchString)
            .subscribeOn(Schedulers.computation())
            .map(
                (repositories) -> {
                  final List<Integer> repositoryIds = new ArrayList<>();
                  for (GitHubRepository repository : repositories) {
                    gitHubRepositoryStore.put(repository);
                    repositoryIds.add(repository.getId());
                  }
                  return new GitHubRepositorySearch(searchString, repositoryIds);
                })
            .doOnCompleted(() -> completeRequest(uri))
            .doOnError(doOnError(uri))
            .subscribe(
                gitHubRepositorySearchStore::put,
                e ->
                    Log.e(
                        TAG,
                        "Error fetching GitHub repository search for '" + searchString + "'",
                        e));
    requestMap.put(searchString.hashCode(), subscription);
    startRequest(uri);
  }