Exemplo n.º 1
0
  private void setProducts(final int searchId, Iterable<ProductHeader> headers) {
    clear();
    for (final ProductHeader header : headers) {
      if (header.imageUrl == null) {
        continue;
      }
      atlas.lookupProduct(
          header.id,
          new Callback<ProductDetail>() {
            @Override
            public void success(ProductDetail detail) {
              if (searchId != currentSearchId) {
                return;
              }
              Product product = new Product(header, detail);
              addProduct(product);
            }

            @Override
            public void error(Exception e) {
              if (searchId != currentSearchId) {
                return;
              }
              // suppress errors because ATLAS does not contain detailed info
              // for all products
              Log.w("ProductList", e);
            }
          });
    }
  }
Exemplo n.º 2
0
  public void doSearch(Search search) {
    Preconditions.checkState(listener != null, "Listener not initialised");
    final int searchId = ++currentSearchId;
    listener.onSearching();
    atlas.search(
        search,
        new Callback<List<ProductHeader>>() {
          @Override
          public void success(List<ProductHeader> result) {
            if (searchId != currentSearchId) {
              return;
            }

            setProducts(searchId, result);
          }

          @Override
          public void error(Exception e) {
            if (searchId != currentSearchId) {
              return;
            }

            listener.onError(e);
          }
        });
  }