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