예제 #1
0
  private void loadImages(List<Submission> submissions) {
    for (Submission s : submissions) {
      ContentType.Type type = ContentType.getContentType(s);

      String url = "";

      ImageLoadingListener l = new SimpleImageLoadingListener();

      if (type == ContentType.Type.IMAGE) {
        url = s.getUrl();
        if (SettingValues.bigPicEnabled) {
          ((Reddit) mSwipeRefreshLayout.getContext().getApplicationContext())
              .getImageLoader()
              .loadImage(url, l);
        } else {
          if (s.getThumbnailType() != Submission.ThumbnailType.NONE) {
            ((Reddit) mSwipeRefreshLayout.getContext().getApplicationContext())
                .getImageLoader()
                .loadImage(s.getThumbnail(), l);
          }
        }
      } else if (s.getDataNode().has("preview")
          && s.getDataNode().get("preview").get("images").get(0).get("source").has("height")) {
        url = s.getDataNode().get("preview").get("images").get(0).get("source").get("url").asText();
        if (SettingValues.bigPicEnabled) {
          ((Reddit) mSwipeRefreshLayout.getContext().getApplicationContext())
              .getImageLoader()
              .loadImage(url, l);
        } else if (s.getThumbnailType() != Submission.ThumbnailType.NONE) {
          ((Reddit) mSwipeRefreshLayout.getContext().getApplicationContext())
              .getImageLoader()
              .loadImage(s.getThumbnail(), l);
        }
      } else if (s.getThumbnail() != null
          && (s.getThumbnailType() == Submission.ThumbnailType.URL
              || s.getThumbnailType() == Submission.ThumbnailType.NSFW)) {
        if ((s.getThumbnailType() == Submission.ThumbnailType.NSFW)
            || s.getThumbnailType() == Submission.ThumbnailType.URL) {
          if (SettingValues.bigPicEnabled) {
            ((Reddit) mSwipeRefreshLayout.getContext().getApplicationContext())
                .getImageLoader()
                .loadImage(url, l);
          } else if (s.getThumbnailType() != Submission.ThumbnailType.NONE) {
            ((Reddit) mSwipeRefreshLayout.getContext().getApplicationContext())
                .getImageLoader()
                .loadImage(s.getThumbnail(), l);
          }
        }
      }
    }
  }
예제 #2
0
  public void loadPhotos(List<Submission> submissions) {
    for (Submission submission : submissions) {
      boolean forceThumb = false;
      String url;
      ContentType.Type type = ContentType.getContentType(submission);
      if (submission.getThumbnails() != null) {

        int height = submission.getThumbnails().getSource().getHeight();
        int width = submission.getThumbnails().getSource().getWidth();

        if (type != ContentType.Type.IMAGE
            && type != ContentType.Type.SELF
            && (submission.getThumbnailType() != Submission.ThumbnailType.URL)) {

        } else if (type == ContentType.Type.IMAGE) {
          if (((!NetworkUtil.isConnectedWifi(c) && SettingValues.lowResMobile)
                  || SettingValues.lowResAlways)
              && submission.getThumbnails() != null
              && submission.getThumbnails().getVariations() != null) {

            int length = submission.getThumbnails().getVariations().length;
            url =
                Html.fromHtml(submission.getThumbnails().getVariations()[length / 2].getUrl())
                    .toString(); // unescape url characters

          } else {
            if (submission.getDataNode().has("preview")
                && submission
                    .getDataNode()
                    .get("preview")
                    .get("images")
                    .get(0)
                    .get("source")
                    .has(
                        "height")) { // Load the preview image which has probably already been
                                     // cached in memory instead of the direct link
              url =
                  submission
                      .getDataNode()
                      .get("preview")
                      .get("images")
                      .get(0)
                      .get("source")
                      .get("url")
                      .asText();
            } else {
              url = submission.getUrl();
            }
          }

          ((Reddit) c.getApplicationContext())
              .getImageLoader()
              .loadImage(
                  url,
                  new ImageLoadingListener() {
                    @Override
                    public void onLoadingStarted(String imageUri, View view) {}

                    @Override
                    public void onLoadingFailed(
                        String imageUri, View view, FailReason failReason) {}

                    @Override
                    public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {}

                    @Override
                    public void onLoadingCancelled(String imageUri, View view) {}
                  });

        } else if (submission.getThumbnails() != null) {

          if (((!NetworkUtil.isConnectedWifi(c) && SettingValues.lowResMobile)
                  || SettingValues.lowResAlways)
              && submission.getThumbnails().getVariations().length != 0) {

            int length = submission.getThumbnails().getVariations().length;
            url =
                Html.fromHtml(submission.getThumbnails().getVariations()[length / 2].getUrl())
                    .toString(); // unescape url characters

          } else {
            url =
                Html.fromHtml(submission.getThumbnails().getSource().getUrl())
                    .toString(); // unescape url characters
          }

          ((Reddit) c.getApplicationContext())
              .getImageLoader()
              .loadImage(
                  url,
                  new ImageLoadingListener() {
                    @Override
                    public void onLoadingStarted(String imageUri, View view) {}

                    @Override
                    public void onLoadingFailed(
                        String imageUri, View view, FailReason failReason) {}

                    @Override
                    public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {}

                    @Override
                    public void onLoadingCancelled(String imageUri, View view) {}
                  });

        } else if (submission.getThumbnail() != null
            && (submission.getThumbnailType() == Submission.ThumbnailType.URL
                || submission.getThumbnailType() == Submission.ThumbnailType.NSFW)) {

          ((Reddit) c.getApplicationContext())
              .getImageLoader()
              .loadImage(
                  submission.getUrl(),
                  new ImageLoadingListener() {
                    @Override
                    public void onLoadingStarted(String imageUri, View view) {}

                    @Override
                    public void onLoadingFailed(
                        String imageUri, View view, FailReason failReason) {}

                    @Override
                    public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {}

                    @Override
                    public void onLoadingCancelled(String imageUri, View view) {}
                  });
        }
      }
    }
  }