Exemplo n.º 1
0
 public boolean isDownloading(BookSection currentSection2) {
   return currentSection.getBookId().equals(currentSection2.getBookId())
       && currentSection.getSectionNumber() == currentSection2.getSectionNumber();
 }
Exemplo n.º 2
0
  private void calculateAndDisplayBookDurationAndSize() {
    LogHelper.info("BookView", "start calculate size and duration");
    int position = sectionsCursor.getPosition();
    boolean any = sectionsCursor.moveToFirst();

    final List<BookSection> sections = new ArrayList<BookSection>();
    if (any) {
      do {
        BookSection section = BookSection.fromCursor(sectionsCursor);
        sections.add(section);
      } while (sectionsCursor.moveToNext());
    }
    sectionsCursor.move(position);

    AsyncTask<Void, Void, Void> task =
        new AsyncTask<Void, Void, Void>() {
          @Override
          protected Void doInBackground(Void... params) {
            Duration dur = new Duration(0, 0, 0);
            long size = 0;
            long diskUsage = 0;

            book.refresh(getContentResolver());
            for (BookSection each : sections) {
              dur = dur.add(each.getDuration());
              size += each.getSize();
              long sectionNum = each.getSectionNumber();

              File file =
                  FileHelper.getFile(
                      getContentResolver(),
                      book.getId(),
                      sectionNum,
                      false,
                      book.getTitle(),
                      book.getLibrivoxId());
              diskUsage += file.length();
            }

            final Duration finalDur = dur;
            final long finalSize = size;
            final long finalDiskUsage = diskUsage;
            runOnUiThread(
                new Runnable() {
                  @Override
                  public void run() {
                    TextView durationTextView = (TextView) findViewById(R.id.duration);
                    durationTextView.setText(finalDur.toString());

                    TextView sizeTextView = (TextView) findViewById(R.id.size);
                    sizeTextView.setText(ByteSizeHelper.getDisplayable(finalSize));

                    TextView diskUsageView = (TextView) findViewById(R.id.diskUsage);
                    diskUsageView.setText(ByteSizeHelper.getDisplayable(finalDiskUsage));
                  }
                });
            LogHelper.info("BookView", "Done calculate size and duration");
            return null;
          }
        };
    task.execute((Void[]) null);
  }