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); } } } } }
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; } }
@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; }
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) {} }); } } } }