예제 #1
0
  /**
   * Pushes data into list adapter.
   *
   * @param data the data to push
   */
  @UiThread
  protected void updateListView(PaginatedList<Artist> data) {
    if (loadingProgressBar.getVisibility() == View.VISIBLE)
      loadingProgressBar.setVisibility(View.INVISIBLE);

    if (data.getCount() <= 0) {
      Toast.makeText(this, "No singer was found", Toast.LENGTH_LONG).show();
      this.finish();
      return;
    }

    if (artistsFound == null) artistsFound = new PaginatedList<Artist>(data);
    else artistsFound.addItems(data.getItems());

    list = (ListView) findViewById(android.R.id.list);

    // If the adapter doesn't exist, we create one with the initial data.
    // If it exists, we update it.
    int currentPosition = -1;
    if (adapter == null) {
      adapter = new ArtistsListAdapter(this, data.getItems());
    } else {
      currentPosition = list.getFirstVisiblePosition();
      adapter.addItems(data.getItems());
    }
    list.setAdapter(adapter);

    list.setSelectionFromTop(currentPosition + 1, 0);

    if (artistsFound.getPaging().isLast()) list.removeFooterView(loadMoreProgress);

    this.isLoading = false;
  }
예제 #2
0
  @Background
  protected void loadMore() {
    this.isLoading = true;
    PaginatedList<Artist> searchResult = PaginatedList.empty();

    try {
      if (!artistsFound.getPaging().isLast()) {
        searchResult =
            artistService.search(query, 50, artistsFound.getPaging().getActualPage() + 1);
        artistsFound.getPaging().setActualPage(artistsFound.getPaging().getActualPage() + 1);
      }
    } catch (NoInternetConnectionException e) {
      showNoInternetMessage();
      e.printStackTrace();
    } catch (LazyInternetConnectionException e) {
      showLazyInternetMessage();
      e.printStackTrace();
    } catch (Exception e) {
      this.alert(e.getMessage());
      e.printStackTrace();
    }
    updateListView(searchResult);
  }
예제 #3
0
  @Background
  protected void listArtists(String query) {
    this.isLoading = true;
    PaginatedList<Artist> searchResult = PaginatedList.empty();

    this.query = query;

    try {
      searchResult = artistService.search(query);
    } catch (NoInternetConnectionException e) {
      showNoInternetMessage();
      e.printStackTrace();
    } catch (LazyInternetConnectionException e) {
      showLazyInternetMessage();
      e.printStackTrace();
    } catch (Exception e) {
      this.alert(e.getMessage());
      e.printStackTrace();
    }
    updateListView(searchResult);
  }
예제 #4
0
  @Override
  protected void onListEndAchieved() {
    if (artistsFound == null) return;

    if (!artistsFound.getPaging().isLast() && !this.isLoading) this.loadMore();
  }