コード例 #1
0
  /**
   * @param childView 要删除的视图
   * @param isDeleteFolder 是否删除只剩一本书的文件夹
   */
  public void removeChildView(View childView, boolean isDeleteFolder) {
    childView.setTag(null);

    if (childViews.contains(childView)) {
      childViews.remove(childView);
    }

    View bookThumbnailView = (View) childView.getTag(R.id.bookThumbnailView);
    int bookFaceIndex = gridLayout.indexOfChild(bookThumbnailView);
    gridLayout.removeView(bookThumbnailView); // 删除文件夹封面上显示的书籍缩略图

    /** 如果删除的是前4本书中的其中一本,且删除后文件夹内至少还有4本书,则需要更新文件夹封面,将第4本书的缩略图进行补位 */
    if (bookFaceIndex >= 0 && childViews.size() >= 4) {
      View bookFaceImageView = (View) childViews.get(3).getTag(R.id.bookThumbnailView);
      if (bookFaceImageView.getParent() != null) {
        ((ViewGroup) bookFaceImageView.getParent()).removeView(bookFaceImageView);
      }

      MyGridLayout.LayoutParams layoutParams = new MyGridLayout.LayoutParams();
      layoutParams.width = (int) getResources().getDimension(R.dimen.book_cell_width) / 3;
      layoutParams.height = (int) getResources().getDimension(R.dimen.book_image_height) / 3;
      layoutParams.topMargin = 4;
      layoutParams.leftMargin = 4;
      layoutParams.rightMargin = 4;
      layoutParams.bottomMargin = 4;

      gridLayout.addView(bookFaceImageView, 3, layoutParams);
    }

    if (null != childView.getParent()) {
      ((ViewGroup) childView.getParent()).removeView(childView);
    }

    // 结构层操作
    bookFile.getListFiles().remove(((DragView) childView).getBookFile());

    // 如果不需要自动删除只剩一本书籍的文件夹则在此处直接返回,终止方法体
    if (!isDeleteFolder) {
      return;
    }

    updateFrontCover(); // 刷新封面

    /** 该文件夹没有书籍时,则删除该文件夹 */
    if (0 == childViews.size()) {
      ViewGroup viewGroup = (ViewGroup) this.getParent();
      BookFile rootBookFile = GlobalDataCacheForMemorySingleton.getInstance.getRootDirectory();
      viewGroup.removeView(this);
      // 结构层操作
      rootBookFile.getListFiles().remove(bookFile);
    }
  }
コード例 #2
0
  public void setBookFile(BookFile bookFile) {
    this.bookFile = bookFile;

    folderName.setText(bookFile.getDirectoryName());
  }