コード例 #1
0
  private void startBookGet() {
    mContentView.setVisibility(View.GONE);
    mProgressWheel.setVisibility(View.VISIBLE);
    mProgressWheel.spin();

    new BookGetTask().execute(book.bookId);
  }
コード例 #2
0
  private void updateDetailsContent() {
    mProgressWheel.setVisibility(View.GONE);
    mContentView.setVisibility(View.VISIBLE);
    mContentView.animate().alphaBy(0f).alpha(1f).setDuration(1500).start();
    mTitleText.setText(TextUtils.isEmpty(book.titleJP) ? book.title : book.titleJP);
    if (isFromExternal) {
      new CoverTask().execute(book);
    }

    checkIsDownloaded();
    setUpShareAction();
    updatePreviewList();
    updateTagsContent();
  }
コード例 #3
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_book_details);

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    collapsingToolbar = $(R.id.collapsing_toolbar);

    Intent intent = getIntent();
    if (Intent.ACTION_VIEW.equals(intent.getAction())) {
      book = new Book();
      String url = intent.getData().toString();
      if (url.endsWith("/")) url = url.substring(0, url.length() - 1);
      String bid = url.substring(url.lastIndexOf("/") + 1, url.length());
      Log.i("TAG", "url get id:" + bid);
      book.bookId = bid;
      fromPosition = -1;
      isFromExternal = true;
    } else {
      book = Book.toBookFromJson(intent.getStringExtra(EXTRA_BOOK_DATA));
      fromPosition = intent.getIntExtra(EXTRA_POSITION, 0);

      collapsingToolbar.setTitle(book.title);
    }

    mFileCacheManager = FileCacheManager.getInstance(getApplicationContext());

    isFavorite =
        originFavorite =
            FavoritesManager.getInstance(getApplicationContext()).contains(book.bookId);

    mImageView = $(R.id.app_bar_background);
    ViewCompat.setTransitionName(mImageView, TRANSITION_NAME_IMAGE);

    mFAB = $(R.id.fab);
    mTitleText = $(R.id.tv_title);
    mTagsLayout = $(R.id.book_tags_layout);
    mContentView = $(R.id.book_content);
    mProgressWheel = $(R.id.wheel_progress);
    mPreviewList = $(R.id.preview_list);

    mPreviewList.setHasFixedSize(true);
    mPreviewList.setLayoutManager(
        new GridLayoutManager(getApplicationContext(), 2, LinearLayoutManager.HORIZONTAL, false));

    FileCacheManager cm = FileCacheManager.getInstance(getApplicationContext());
    if (book.galleryId != null) {
      if (cm.cacheExistsUrl(Constants.CACHE_COVER, book.bigCoverImageUrl)) {
        if (cm.cacheExistsUrl(
            Constants.CACHE_PAGE_IMG, NHentaiUrl.getOriginPictureUrl(book.galleryId, "1"))) {
          Picasso.with(getApplicationContext())
              .load(
                  cm.getBitmapUrlFile(
                      Constants.CACHE_PAGE_IMG,
                      NHentaiUrl.getOriginPictureUrl(book.galleryId, "1")))
              .fit()
              .centerCrop()
              .into(mImageView);
        } else {
          Picasso.with(getApplicationContext())
              .load(cm.getBitmapUrlFile(Constants.CACHE_COVER, book.bigCoverImageUrl))
              .fit()
              .centerCrop()
              .into(mImageView);
        }
      } else {
        if (cm.cacheExistsUrl(Constants.CACHE_THUMB, book.previewImageUrl)) {
          Picasso.with(getApplicationContext())
              .load(cm.getBitmapUrlFile(Constants.CACHE_THUMB, book.previewImageUrl))
              .fit()
              .centerCrop()
              .into(mImageView);
        } else {
          int color = ColorGenerator.MATERIAL.getColor(book.title);
          TextDrawable drawable =
              TextDrawable.builder().buildRect(book.title.substring(0, 1), color);
          mImageView.setImageDrawable(drawable);
        }
        new CoverTask().execute(book);
      }
    }

    if (book.pageCount != 0) {
      mContentView.setVisibility(View.GONE);
      mProgressWheel.setVisibility(View.VISIBLE);
      mProgressWheel.spin();
      new Thread() {
        @Override
        public void run() {
          try {
            Thread.sleep(250);
          } catch (InterruptedException e) {
            e.printStackTrace();
          }
          runOnUiThread(
              new Runnable() {
                @Override
                public void run() {
                  updateUIContent();
                }
              });
        }
      }.start();
    } else {
      startBookGet();
    }

    if (!isFromExternal) checkIsDownloaded();
  }