Beispiel #1
0
  // 取下载图片列表
  private List<ImageEntity> getDownImage(ListEntity listEntity) {
    List<ImageEntity> imageList = imageAccess.queryNotDownById(listEntity.listId);
    if (imageList.size() <= 0) {
      // 获取图片资源
      List<String> result = HtmlHelper.getImagePageHtml(listEntity);
      for (int i = 0; i < result.size(); i++) {
        if (!downFlag) break;
        String link = result.get(i);
        int imageId = i + 1;
        ImageEntity imageEntity = new ImageEntity();
        imageEntity.imageId = imageId;
        imageEntity.imageLink = link;
        imageEntity.listId = listEntity.listId;
        imageEntity.siteId = listEntity.siteId;
        imageEntity.isDown = 0;
        imageEntity.imageName = ImageHelper.getNewFileName(link, imageId);

        imageAccess.insert(imageEntity);
        imageList.add(imageEntity);
      }

      MyLog.setLog(
          "保存图片 -> SiteID("
              + listEntity.siteId
              + "), ListID("
              + listEntity.listId
              + ") -> "
              + result.size()
              + "p "
              + listEntity.listTitle
              + " -> "
              + listEntity.listLink);
    }

    return imageList;
  }
Beispiel #2
0
  // 下载方法
  public void download(ListEntity listEntity, int position) {
    downFlag = true;
    listEntity.loadNum = 0;
    listEntity.isDowning = 1;
    listAccess.update(listEntity);

    downList.add(String.valueOf(position));
    doMessage(position, 3);

    String success = "";
    int count = 0;
    List<ImageEntity> imageList = getDownImage(listEntity);
    if (imageList.size() > 0) {
      listEntity.loadNum = imageList.size();
      doMessage(position, 2);

      // 创建.nomedia文件,禁止系统图库搜索图片。
      ImageHelper.saveNoMedia(listEntity.siteId, listEntity.listId);

      // 开始下载图片
      for (ImageEntity imageEntity : imageList) {
        if (!downFlag) break;
        boolean bool = ImageHelper.saveImage(imageEntity);
        if (bool) {
          count++;
          imageEntity.isDown = 1;
          imageAccess.update(imageEntity);
          success += "1";

          listEntity.listPicture = imageEntity.imageName;
          listAccess.update(listEntity);
        } else {
          success += "0";
          continue;
        }

        listEntity.loadNum--;
        doMessage(position, 2);
      }
    }

    MyLog.setLog(
        "下载完成 -> SiteID("
            + listEntity.siteId
            + "), ListID("
            + listEntity.listId
            + ") -> "
            + count
            + "p "
            + listEntity.listTitle
            + " "
            + success
            + " -> "
            + listEntity.listLink);

    if (count > 0 && imageList.size() == count) {
      listEntity.isDown = 1;
    } else {
      if (success.contains("1")) {
        listEntity.isDown = 2;
      } else if (listEntity.reDown != 1) {
        listEntity.isDown = 0;
      }
    }
    listEntity.reDown = 0;
    listEntity.loadNum = 0;
    listEntity.isDowning = 0;
    listAccess.update(listEntity);

    downList.remove(String.valueOf(position));
    doMessage(position, 4);
  }