Esempio n. 1
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    ViewGroup rootView =
        (ViewGroup) inflater.inflate(R.layout.submission_albumcard, container, false);

    TextView title = (TextView) rootView.findViewById(R.id.title);
    TextView desc = (TextView) rootView.findViewById(R.id.desc);

    title.setText(s.getTitle());
    desc.setText(
        s.getAuthor() + " " + TimeUtils.getTimeAgo(s.getCreated().getTime(), getContext()));
    ContentType.ImageType type = ContentType.getImageType(s);

    String url = "";

    if (s.getUrl().contains("gallery")) {
      gallery = true;
    }

    list = rootView.findViewById(R.id.images);

    list.setVisibility(View.VISIBLE);
    String rawDat = cutEnds(s.getUrl());
    String rawdat2 = rawDat;
    if (rawdat2.substring(rawDat.lastIndexOf("/"), rawdat2.length()).length() < 4) {
      rawDat = rawDat.replace(rawDat.substring(rawDat.lastIndexOf("/"), rawdat2.length()), "");
    }
    if (!rawDat.isEmpty()) {

      new AsyncImageLoaderAlbum().execute(getHash(rawDat));
    }

    rootView
        .findViewById(R.id.base)
        .setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                if (Reddit.tabletUI
                    && getActivity().getResources().getConfiguration().orientation
                        == Configuration.ORIENTATION_LANDSCAPE) {
                  Intent i2 = new Intent(getActivity(), CommentsScreenPopup.class);
                  i2.putExtra("page", i);
                  (getActivity()).startActivity(i2);

                } else {
                  Intent i2 = new Intent(getActivity(), CommentsScreen.class);
                  i2.putExtra("page", i);
                  (getActivity()).startActivity(i2);
                }
              }
            });
    return rootView;
  }
Esempio n. 2
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);
          }
        }
      }
    }
  }
Esempio n. 3
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    rootView = (ViewGroup) inflater.inflate(R.layout.submission_imagecard, container, false);
    image = (SubsamplingScaleImageView) rootView.findViewById(R.id.image);

    PopulateShadowboxInfo.doActionbar(s, rootView, getActivity());

    (rootView.findViewById(R.id.thumbimage2)).setVisibility(View.GONE);

    type = ContentType.getImageType(s);

    if (type.toString().toLowerCase().contains("image")
        && type != ContentType.ImageType.IMAGE_LINK) {
      addClickFunctions(image, rootView, type, getActivity(), s);
      loadImage(s.getUrl());
    } else if (s.getDataNode().has("preview")
        && s.getDataNode().get("preview").get("images").get(0).get("source").has("height")
        && s.getDataNode().get("preview").get("images").get(0).get("source").get("height").asInt()
            > 200) {
      loadImage(
          s.getDataNode().get("preview").get("images").get(0).get("source").get("url").asText());
    } else {
      image.recycle();
      (rootView.findViewById(R.id.thumbimage2)).setVisibility(View.VISIBLE);
      ((ImageView) rootView.findViewById(R.id.thumbimage2)).setImageResource(R.drawable.web);
      addClickFunctions(
          (rootView.findViewById(R.id.thumbimage2)), rootView, type, getActivity(), s);

      (rootView.findViewById(R.id.progress)).setVisibility(View.GONE);
    }

    rootView
        .findViewById(R.id.base)
        .setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {

                Intent i2 = new Intent(getActivity(), CommentsScreen.class);
                i2.putExtra(CommentsScreen.EXTRA_PAGE, i);
                i2.putExtra(CommentsScreen.EXTRA_SUBREDDIT, sub);
                (getActivity()).startActivity(i2);
              }
            });
    return rootView;
  }
Esempio n. 4
0
  public void doLoad(final String contentUrl) {
    switch (ContentType.getContentType(contentUrl)) {
      case DEVIANTART:
        if (!imageShown) {
          Ion.with(this)
              .load("http://backend.deviantart.com/oembed?url=" + contentUrl)
              .asJsonObject()
              .setCallback(
                  new FutureCallback<JsonObject>() {
                    @Override
                    public void onCompleted(Exception e, JsonObject result) {
                      if (result != null
                          && !result.isJsonNull()
                          && (result.has("fullsize_url") || result.has("url"))) {

                        String url;
                        if (result.has("fullsize_url")) {
                          url = result.get("fullsize_url").getAsString();
                        } else {
                          url = result.get("url").getAsString();
                        }
                        doLoadImage(url);
                      } else {
                        Intent i = new Intent(getActivity(), Website.class);
                        i.putExtra(Website.EXTRA_URL, contentUrl);
                        getActivity().startActivity(i);
                      }
                    }
                  });
        }
        break;
      case IMAGE:
        doLoadImage(contentUrl);
        break;
      case IMGUR:
        doLoadImgur(contentUrl);
        break;
      case VID_ME:
      case STREAMABLE:
      case GIF:
        doLoadGif(contentUrl);
        break;
    }
  }
Esempio n. 5
0
    @Override
    public Fragment getItem(int i) {

      Fragment f;
      ContentType.ImageType t = ContentType.getImageType(subredditPosts.getPosts().get(i));

      if (subredditPosts.getPosts().size() - 2 <= i && subredditPosts.hasMore()) {
        subredditPosts.loadMore(Shadowbox.this.getApplicationContext(), Shadowbox.this, false);
      }
      switch (t) {
        case NSFW_IMAGE:
        case NSFW_GIF:
        case NSFW_GFY:
        case GFY:
        case GIF:
        case IMAGE:
        case NONE_GFY:
        case NONE_GIF:
        case NONE_IMAGE:
          {
            f = new MediaFragment();
            Bundle args = new Bundle();
            Submission submission = OfflineSubreddit.getSubreddit(subreddit).submissions.get(i);
            String previewUrl = "";
            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
              previewUrl =
                  submission
                      .getDataNode()
                      .get("preview")
                      .get("images")
                      .get(0)
                      .get("source")
                      .get("url")
                      .asText();
            }
            args.putString("contentUrl", submission.getUrl());
            args.putString("firstUrl", previewUrl);
            args.putInt("page", i);
            args.putString("sub", subreddit);
            f.setArguments(args);
          }
          break;
        case REDDIT:
          {
            f = new ImageFull();
            Bundle args = new Bundle();
            args.putInt("page", i);
            args.putString("sub", subreddit);

            f.setArguments(args);
          }
          break;
        case EMBEDDED:
          {
            f = new ImageFull();
            Bundle args = new Bundle();
            args.putInt("page", i);
            args.putString("sub", subreddit);

            f.setArguments(args);
          }
          break;
        case LINK:
          {
            f = new ImageFull();
            Bundle args = new Bundle();
            args.putInt("page", i);
            args.putString("sub", subreddit);

            f.setArguments(args);
          }
          break;
        case IMAGE_LINK:
          {
            f = new ImageFull();
            Bundle args = new Bundle();
            args.putInt("page", i);
            args.putString("sub", subreddit);

            f.setArguments(args);
          }
          break;
        case NSFW_LINK:
          {
            f = new ImageFull();
            Bundle args = new Bundle();
            args.putInt("page", i);
            args.putString("sub", subreddit);

            f.setArguments(args);
          }
          break;
        case SELF:
          {
            if (subredditPosts.getPosts().get(i).getSelftext().isEmpty()) {
              f = new TitleFull();
              Bundle args = new Bundle();
              args.putInt("page", i);
              args.putString("sub", subreddit);

              f.setArguments(args);
            } else {
              f = new SelftextFull();
              Bundle args = new Bundle();
              args.putInt("page", i);
              args.putString("sub", subreddit);

              f.setArguments(args);
            }
          }
          break;
        case ALBUM:
          {
            f = new AlbumFull();
            Bundle args = new Bundle();
            args.putInt("page", i);
            args.putString("sub", subreddit);

            f.setArguments(args);
          }
          break;
        case VID_ME:
        case STREAMABLE:
          {
            f = new Gif();
            Bundle args = new Bundle();
            args.putInt("page", i);
            args.putString("sub", subreddit);

            f.setArguments(args);
          }
          break;
        case NONE:
          {
            if (subredditPosts.getPosts().get(i).getSelftext().isEmpty()) {
              f = new TitleFull();
              Bundle args = new Bundle();
              args.putInt("page", i);
              args.putString("sub", subreddit);

              f.setArguments(args);
            } else {
              f = new SelftextFull();
              Bundle args = new Bundle();
              args.putInt("page", i);
              args.putString("sub", subreddit);

              f.setArguments(args);
            }
          }
          break;
        case VIDEO:
          {
            f = new ImageFull();
            Bundle args = new Bundle();
            args.putInt("page", i);
            args.putString("sub", subreddit);

            f.setArguments(args);
          }
          break;
        case NONE_URL:
          {
            f = new ImageFull();
            Bundle args = new Bundle();
            args.putInt("page", i);
            args.putString("sub", subreddit);

            f.setArguments(args);
          }
          break;
        default:
          {
            f = new ImageFull();
            Bundle args = new Bundle();
            args.putInt("page", i);
            args.putString("sub", subreddit);

            f.setArguments(args);
          }
          break;
      }

      return f;
    }
Esempio n. 6
0
  public void doLoadImage(String contentUrl) {
    if (contentUrl != null && contentUrl.contains("bildgur.de"))
      contentUrl = contentUrl.replace("b.bildgur.de", "i.imgur.com");
    if (contentUrl != null && ContentType.isImgurLink(contentUrl)) {
      contentUrl = contentUrl + ".png";
    }

    rootView.findViewById(R.id.gifprogress).setVisibility(View.GONE);

    if (contentUrl != null && contentUrl.contains("m.imgur.com"))
      contentUrl = contentUrl.replace("m.imgur.com", "i.imgur.com");

    if ((contentUrl != null
        && !contentUrl.startsWith("https://i.redditmedia.com")
        && !contentUrl.startsWith("https://i.reddituploads.com")
        && !contentUrl.contains(
            "imgur.com"))) { // we can assume redditmedia and imgur links are to direct images and
                             // not websites
      rootView.findViewById(R.id.progress).setVisibility(View.VISIBLE);
      ((ProgressBar) rootView.findViewById(R.id.progress)).setIndeterminate(true);

      final String finalUrl2 = contentUrl;
      new AsyncTask<Void, Void, Void>() {
        @Override
        protected Void doInBackground(Void... params) {
          try {
            URL obj = new URL(finalUrl2);
            URLConnection conn = obj.openConnection();
            final String type = conn.getHeaderField("Content-Type");
            getActivity()
                .runOnUiThread(
                    new Runnable() {
                      @Override
                      public void run() {
                        if (!imageShown
                            && type != null
                            && !type.isEmpty()
                            && type.startsWith("image/")) {
                          // is image
                          if (type.contains("gif")) {
                            doLoadGif(finalUrl2.replace(".jpg", ".gif").replace(".png", ".gif"));
                          } else if (!imageShown) {
                            displayImage(finalUrl2);
                          }
                          actuallyLoaded = finalUrl2;
                        } else if (!imageShown) {
                          Intent i = new Intent(getActivity(), Website.class);
                          i.putExtra(Website.EXTRA_URL, finalUrl2);
                          getActivity().startActivity(i);
                        }
                      }
                    });

          } catch (IOException e) {
            e.printStackTrace();
          }
          return null;
        }

        @Override
        protected void onPostExecute(Void aVoid) {
          rootView.findViewById(R.id.progress).setVisibility(View.GONE);
        }
      }.execute();

    } else {
      displayImage(contentUrl);
    }

    actuallyLoaded = contentUrl;
  }
Esempio n. 7
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    rootView = (ViewGroup) inflater.inflate(R.layout.submission_mediacard, container, false);
    if (savedInstanceState != null && savedInstanceState.containsKey("position"))
      stopPosition = savedInstanceState.getInt("position");
    if (!firstUrl.isEmpty()) {
      displayImage(firstUrl);
    }

    PopulateShadowboxInfo.doActionbar(s, rootView, getActivity(), true);

    (rootView.findViewById(R.id.thumbimage2)).setVisibility(View.GONE);

    ContentType.Type type = ContentType.getContentType(s);

    if (!ContentType.fullImage(type)) {
      if (!s.getDataNode().has("preview")
          || !s.getDataNode().get("preview").get("images").get(0).get("source").has("height")) {
        (rootView.findViewById(R.id.thumbimage2)).setVisibility(View.VISIBLE);
        ((ImageView) rootView.findViewById(R.id.thumbimage2)).setImageResource(R.drawable.web);
        addClickFunctions(
            (rootView.findViewById(R.id.thumbimage2)), rootView, type, getActivity(), s);
        (rootView.findViewById(R.id.progress)).setVisibility(View.GONE);
      } else {
        addClickFunctions(
            (rootView.findViewById(R.id.submission_image)), rootView, type, getActivity(), s);
      }
    } else {
      (rootView.findViewById(R.id.thumbimage2)).setVisibility(View.GONE);
      addClickFunctions(
          (rootView.findViewById(R.id.submission_image)), rootView, type, getActivity(), s);
    }
    doLoad(contentUrl);

    rootView
        .findViewById(R.id.base)
        .setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {

                Intent i2 = new Intent(getActivity(), CommentsScreen.class);
                i2.putExtra(CommentsScreen.EXTRA_PAGE, i);
                i2.putExtra(CommentsScreen.EXTRA_SUBREDDIT, sub);
                getActivity().startActivity(i2);
              }
            });
    final View.OnClickListener openClick =
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            ((SlidingUpPanelLayout) rootView.findViewById(R.id.sliding_layout))
                .setPanelState(SlidingUpPanelLayout.PanelState.EXPANDED);
          }
        };
    rootView.findViewById(R.id.base).setOnClickListener(openClick);
    final View title = rootView.findViewById(R.id.title);
    title
        .getViewTreeObserver()
        .addOnGlobalLayoutListener(
            new ViewTreeObserver.OnGlobalLayoutListener() {
              @Override
              public void onGlobalLayout() {
                ((SlidingUpPanelLayout) rootView.findViewById(R.id.sliding_layout))
                    .setPanelHeight(title.getMeasuredHeight());
                title.getViewTreeObserver().removeOnGlobalLayoutListener(this);
              }
            });
    ((SlidingUpPanelLayout) rootView.findViewById(R.id.sliding_layout))
        .addPanelSlideListener(
            new SlidingUpPanelLayout.PanelSlideListener() {
              @Override
              public void onPanelSlide(View panel, float slideOffset) {}

              @Override
              public void onPanelStateChanged(
                  View panel,
                  SlidingUpPanelLayout.PanelState previousState,
                  SlidingUpPanelLayout.PanelState newState) {
                if (newState == SlidingUpPanelLayout.PanelState.EXPANDED) {
                  rootView
                      .findViewById(R.id.base)
                      .setOnClickListener(
                          new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                              Intent i2 = new Intent(getActivity(), CommentsScreen.class);
                              i2.putExtra(CommentsScreen.EXTRA_PAGE, i);
                              i2.putExtra(CommentsScreen.EXTRA_SUBREDDIT, sub);
                              getActivity().startActivity(i2);
                            }
                          });
                } else {
                  rootView.findViewById(R.id.base).setOnClickListener(openClick);
                }
              }
            });
    return rootView;
  }
Esempio n. 8
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) {}
                  });
        }
      }
    }
  }
    /**
     * @param url the url link (e.g. #s for some spoilers)
     * @param xOffset the last index of the url text (not the link)
     */
    public void onLinkClick(String url, int xOffset) {
      if (url == null) {
        return;
      }

      ContentType.ImageType type = ContentType.getImageType(url);
      switch (type) {
        case IMGUR:
          Intent intent2 = new Intent(c, Imgur.class);
          intent2.putExtra(Imgur.EXTRA_URL, url);
          c.startActivity(intent2);
          break;
        case NSFW_IMAGE:
          openImage(c, url);
          break;
        case NSFW_GIF:
          openGif(false, c, url);
          break;
        case NSFW_GFY:
          openGif(true, c, url);
          break;
        case REDDIT:
          new OpenRedditLink(c, url);
          break;
        case LINK:
        case IMAGE_LINK:
        case NSFW_LINK:
          CustomTabUtil.openUrl(url, Palette.getColor(subreddit), c);
          break;
        case SELF:
          break;

        case GFY:
          openGif(true, c, url);
          break;
        case ALBUM:
          if (SettingValues.album) {
            Intent i = new Intent(c, Album.class);
            i.putExtra(Album.EXTRA_URL, url);
            c.startActivity(i);
          } else {
            Reddit.defaultShare(url, c);
          }
          break;
        case IMAGE:
          openImage(c, url);
          break;
        case GIF:
          openGif(false, c, url);
          break;
        case NONE_GFY:
          openGif(true, c, url);
          break;
        case NONE_GIF:
          openGif(false, c, url);
          break;
        case NONE:
          break;
        case NONE_IMAGE:
          openImage(c, url);
          break;
        case NONE_URL:
          CustomTabUtil.openUrl(url, Palette.getColor(subreddit), c);
          break;
        case VIDEO:
          if (SettingValues.video) {
            Intent intent = new Intent(c, FullscreenVideo.class);
            intent.putExtra(FullscreenVideo.EXTRA_HTML, url);
            c.startActivity(intent);
          } else {
            Reddit.defaultShare(url, c);
          }
        case SPOILER:
          comm.spoilerClicked = true;

          setOrRemoveSpoilerSpans(comm, (Spannable) sequence, xOffset);
          break;
      }
    }
Esempio n. 10
0
  private void loadImage(String url) {
    final ProgressBar bar = (ProgressBar) rootView.findViewById(R.id.progress);
    bar.setIndeterminate(false);
    bar.setProgress(0);
    if (url != null && ContentType.isImgurLink(url)) {
      url = url + ".png";
    }
    ImageView fakeImage = new ImageView(getActivity());
    fakeImage.setLayoutParams(new LinearLayout.LayoutParams(image.getWidth(), image.getHeight()));
    fakeImage.setScaleType(ImageView.ScaleType.CENTER_CROP);

    ((Reddit) getActivity().getApplication())
        .getImageLoader()
        .displayImage(
            url,
            new ImageViewAware(fakeImage),
            ImageLoaderUtils.options,
            new ImageLoadingListener() {
              private View mView;

              @Override
              public void onLoadingStarted(String imageUri, View view) {
                mView = view;
              }

              @Override
              public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
                Log.v(LogUtil.getTag(), "LOADING FAILED");
              }

              @Override
              public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
                image.setImage(ImageSource.bitmap(loadedImage));
                (rootView.findViewById(R.id.progress)).setVisibility(View.GONE);

                if (type == ContentType.ImageType.IMAGE || type == ContentType.ImageType.IMGUR) {
                  image.setMinimumDpi(30);
                  previous = image.scale;
                  final float base = image.scale;
                  image.setOnZoomChangedListener(
                      new SubsamplingScaleImageView.OnZoomChangedListener() {
                        @Override
                        public void onZoomLevelChanged(float zoom) {
                          if (zoom > previous && !hidden && zoom > base) {
                            hidden = true;
                            final View base = rootView.findViewById(R.id.base);

                            ValueAnimator va = ValueAnimator.ofFloat(1.0f, 0.2f);
                            int mDuration = 250; // in millis
                            va.setDuration(mDuration);
                            va.addUpdateListener(
                                new ValueAnimator.AnimatorUpdateListener() {
                                  public void onAnimationUpdate(ValueAnimator animation) {
                                    Float value = (Float) animation.getAnimatedValue();
                                    base.setAlpha(value);
                                  }
                                });

                            va.start();

                            // hide
                          } else if (zoom <= previous && hidden) {
                            hidden = false;
                            final View base = rootView.findViewById(R.id.base);

                            ValueAnimator va = ValueAnimator.ofFloat(0.2f, 1.0f);
                            int mDuration = 250; // in millis
                            va.setDuration(mDuration);
                            va.addUpdateListener(
                                new ValueAnimator.AnimatorUpdateListener() {
                                  public void onAnimationUpdate(ValueAnimator animation) {
                                    Float value = (Float) animation.getAnimatedValue();
                                    base.setAlpha(value);
                                  }
                                });

                            va.start();

                            // unhide
                          }
                          previous = zoom;
                        }
                      });
                }
              }

              @Override
              public void onLoadingCancelled(String imageUri, View view) {
                Log.v(LogUtil.getTag(), "LOADING CANCELLED");
              }
            },
            new ImageLoadingProgressListener() {
              @Override
              public void onProgressUpdate(String imageUri, View view, int current, int total) {
                ((ProgressBar) rootView.findViewById(R.id.progress))
                    .setProgress(Math.round(100.0f * current / total));
              }
            });
  }
Esempio n. 11
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    ViewGroup rootView =
        (ViewGroup) inflater.inflate(R.layout.submission_imagecard, container, false);

    final SubsamplingScaleImageView image =
        (SubsamplingScaleImageView) rootView.findViewById(R.id.image);
    TextView title = (TextView) rootView.findViewById(R.id.title);
    TextView desc = (TextView) rootView.findViewById(R.id.desc);

    title.setText(s.getTitle());
    desc.setText(s.getAuthor() + " " + TimeUtils.getTimeAgo(s.getCreatedUtc().getTime()));
    ContentType.ImageType type = ContentType.getImageType(s);

    String url;

    if (type.toString().toLowerCase().contains("image")) {
      addClickFunctions(image, rootView, type, getActivity(), s);

      url = ContentType.getFixedUrl(s.getUrl());
      ((Reddit) getContext().getApplicationContext())
          .getImageLoader()
          .loadImage(
              url,
              new SimpleImageLoadingListener() {

                @Override
                public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
                  image.setImage(ImageSource.bitmap(loadedImage));
                }
              });
    } else if (s.getDataNode().has("preview")
        && s.getDataNode().get("preview").get("images").get(0).get("source").has("height")
        && s.getDataNode().get("preview").get("images").get(0).get("source").get("height").asInt()
            > 200) {

      url = s.getDataNode().get("preview").get("images").get(0).get("source").get("url").asText();
      ((Reddit) getContext().getApplicationContext())
          .getImageLoader()
          .loadImage(
              url,
              new SimpleImageLoadingListener() {

                @Override
                public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
                  image.setImage(ImageSource.bitmap(loadedImage));
                }
              });

    } else {
      addClickFunctions(image, rootView, type, getActivity(), s);
      Log.v("Slide", "NO IMAGE");
      image.recycle();
    }

    rootView
        .findViewById(R.id.base)
        .setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                if (Reddit.tabletUI
                    && getActivity().getResources().getConfiguration().orientation
                        == Configuration.ORIENTATION_LANDSCAPE) {
                  Intent i2 = new Intent(getActivity(), CommentsScreenPopup.class);
                  i2.putExtra("page", i);
                  (getActivity()).startActivity(i2);

                } else {
                  Intent i2 = new Intent(getActivity(), CommentsScreen.class);
                  i2.putExtra("page", i);
                  (getActivity()).startActivity(i2);
                }
              }
            });
    return rootView;
  }